34 int w, h, i, bfSize, biSizeImage, bfOffBits, biClrUsed, inbpp, inpitch, outpitch,
color;
36 unsigned int *
palette = (
unsigned int *)pal, *paltmp = 0;
41 w = put_header->
width;
44 inbpp = put_header->
bpp;
45 inpitch = put_header->
pitch;
48 w = put_header->
old.width;
49 h = put_header->
old.height;
50 s = (
unsigned char *)src + 4;
63 if (w <= 0 || h <= 0 || s == 0 || inpitch < w * inbpp) {
94 outpitch = ( (w + 3) & ~3 );
95 biSizeImage = outpitch * h;
96 bfOffBits = 54 + 256*4;
97 bfSize = bfOffBits + biSizeImage;
101 outpitch = ( ((w * 3) + 3) & ~3 );
102 biSizeImage = outpitch * h;
104 bfSize = bfOffBits + biSizeImage;
111 biSizeImage = outpitch * h;
113 bfSize = bfOffBits + biSizeImage;
132 if (!fwrite(&header, 54, 1, f))
140 paltmp = (
unsigned int *)calloc(
sizeof(
unsigned int), 256);
144 for (i = 0; i < 256; i++) {
145 paltmp[i] = (palette[i] & 0x3f0000) >> (16 - 2)
146 | (palette[i] & 0x003f00) << 2
147 | (palette[i] & 0x00003f) << (16 + 2);
153 for (i = 0; i < 256; i++) {
154 fputc(((palette[i] >> 16) & 0xFF), f);
155 fputc(((palette[i] >> 8) & 0xFF), f);
156 fputc((palette[i] & 0xFF), f);
162 buffer = (
unsigned char *)calloc(1, outpitch + 15);
164 if (paltmp) free(paltmp);
168 s += (h - 1) * inpitch;
178 for (i = 0; i < w; i++) {
179 color = palette[((
unsigned char *)s)[i]];
180 *p++ = (color & 0xFF0000) >> 16;
181 *p++ = (color & 0xFF00) >> 8;
182 *p++ = (color & 0xFF);
188 for (i = 0; i < w; i++) {
189 color = ((
unsigned short *)s)[i];
190 *p++ = ((color & 0x001F) << 3) | ((color & 0x001F) >> 2);
191 *p++ = ((color & 0x07E0) >> 3) | ((color & 0x07E0) >> 9);
192 *p++ = ((color & 0xF800) >> 8) | ((color & 0xF800) >> 13);
199 for (i = 0; i < w; i++) {
200 *(
unsigned int *)p = ((
unsigned int *)s)[i];
205 if (!fwrite(buffer, outpitch, 1, f))
211 if (paltmp) free(paltmp);
230 f = fopen(buffer,
"wb");
239 p = strrchr(filename->
data,
'.');
240 if ((p) && (!strcasecmp(p + 1,
"bmp")))
241 result =
save_bmp(context, f, src, pal, bitsperpixel);
243 if ((size == 0) && src) {
250 fputc(size & 0xFF, f);
251 fputc((size >> 8) & 0xFF, f);
252 fputc((size >> 16) & 0xFF, f);
253 fputc(size >> 24, f);
258 if (!fwrite(context->
line[0], size, 1, f))
267 fputc(color & 0xFF, f);
268 fputc((color >> 8) & 0xFF, f);
269 fputc((color >> 16) & 0xFF, f);
273 else if (!fwrite(src, size, 1, f))