12 #define BI_BITFIELDS 3
18 rc = fread(buf,
sizeof(*buf), 1, f);
26 rc = fread(buf,
sizeof(*buf), 1, f);
31 typedef void (*
FBGFX_BLOAD_IMAGE_CONVERT)(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits);
33 static void convert_8to8(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
38 static void convert_8to16(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
43 static void convert_8to32(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
48 #define CONVERT_DEPTH(c, from, to) \
50 ((c) << (to - from)) | (c >> (from - (to - from))) \
53 static void convert_bf_16to16(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
56 uint16_t *s = (uint16_t *)src;
57 uint16_t *d = (uint16_t *)dest;
59 r = (*s >> shifts[0]) & masks[0];
60 g = (*s >> shifts[1]) & masks[1];
61 b = (*s >> shifts[2]) & masks[2];
65 *d = (r << 11) | (g << 5) | b;
71 static void convert_bf_16to32(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
74 uint16_t *s = (uint16_t *)src;
75 uint32_t *d = (uint32_t *)dest;
77 r = (*s >> shifts[0]) & masks[0];
78 g = (*s >> shifts[1]) & masks[1];
79 b = (*s >> shifts[2]) & masks[2];
83 *d = (255 << 24) | (r << 16) | (g << 8) | b;
89 static void convert_bf_24to16(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
94 uint16_t *d = (uint16_t *)dest;
96 c = src[0] | (src[1] << 8) | (src[2] << 16);
97 r = (c >> shifts[0]) & masks[0];
98 g = (c >> shifts[1]) & masks[1];
99 b = (c >> shifts[2]) & masks[2];
103 *d++ = (r << 11) | (g << 5) | b;
108 static void convert_bf_24to32(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
113 uint32_t *d = (uint32_t *)dest;
115 c = src[0] | (src[1] << 8) | (src[2] << 16);
116 r = (c >> shifts[0]) & masks[0];
117 g = (c >> shifts[1]) & masks[1];
118 b = (c >> shifts[2]) & masks[2];
122 *d++ = (255 << 24) | (r << 16) | (g << 8) | b;
127 static void convert_bf_32to16(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
130 uint32_t *s = (uint32_t *)src;
131 uint16_t *d = (uint16_t *)dest;
133 r = (*s >> shifts[0]) & masks[0];
134 g = (*s >> shifts[1]) & masks[1];
135 b = (*s >> shifts[2]) & masks[2];
139 *d++ = (r << 11) | (g << 5) | b;
144 static void convert_bf_32to32(
const unsigned char *src,
unsigned char *dest,
int w,
const uint32_t *masks,
const int *shifts,
const int *bits)
147 uint32_t *s = (uint32_t *)src;
148 uint32_t *d = (uint32_t *)dest;
150 r = (*s >> shifts[0]) & masks[0];
151 g = (*s >> shifts[1]) & masks[1];
152 b = (*s >> shifts[2]) & masks[2];
153 a = (*s >> shifts[3]) & masks[3];
158 *d++ = (a << 24) | (r << 16) | (g << 8) | b;
167 uint16_t bfReserved1;
168 uint16_t bfReserved2;
177 uint32_t biCompression =
BI_RGB;
178 uint32_t biSizeImage = 0;
184 int i, j, width, height, bpp,
color, expand,
size, padding,
palette[256], palette_entries;
185 int shifts[4] = {0, 0, 0, 0};
187 int bits[4] = {0, 0, 0, 0};
188 void *target_pal = pal;
213 }
else if (biSize >= 16) {
232 if ((fseek(f, 4*4, SEEK_CUR)) ||
247 if ((bfType != 19778) || (biPlanes > 1) || (biWidth <= 0) || (biHeight == 0) || (biCompression >
BI_BITFIELDS))
254 biHeight = -biHeight;
257 if (bfOffBits == 0) {
258 bfOffBits = biSize + 14;
259 if (biBitCount <= 8) {
260 bfOffBits += (1 << biBitCount);
264 fseek(f, biSize + 14, SEEK_SET);
266 if (biBitCount <= 8) {
268 int pal_entry_size = (biSize == 12 ? 3 : 4);
269 palette_entries = 1 << biBitCount;
270 for (i = 0; i < palette_entries; i++) {
271 palette[i] = (fgetc(f) << 16) | (fgetc(f) << 8) | fgetc(f);
273 palette[i] = (palette[i] >> 2) & 0x3F3F3F;
274 if (pal_entry_size == 4) {
288 width =
MIN(put_header->
width, biWidth);
289 height =
MIN(put_header->
height, biHeight);
290 bpp = put_header->
bpp;
292 bpp = put_header->
old.bpp;
293 if (bpp == 1 || bpp == 2 || bpp == 4) {
294 width =
MIN(put_header->
old.width, biWidth);
295 height =
MIN(put_header->
old.height, biHeight);
301 put_header->
width = biWidth;
302 put_header->
height = biHeight;
303 put_header->
pitch = ((put_header->
width * put_header->
bpp) + 0xF) & ~0xF;
305 width =
MIN(put_header->
width, biWidth);
306 height =
MIN(put_header->
height, biHeight);
307 bpp = put_header->
bpp;
311 put_header->
old.width = biWidth;
312 put_header->
old.height = biHeight;
313 put_header->
pitch = ((put_header->
width * put_header->
bpp) + 0xF) & ~0xF;
315 width =
MIN(put_header->
old.width, biWidth);
316 height =
MIN(put_header->
old.height, biHeight);
317 bpp = put_header->
old.bpp;
330 expand = (biBitCount < 8) ? biBitCount : 0;
333 if (!fread(rgba, 12, 1, f))
336 }
else if (biBitCount <= 16) {
344 rgba[3] = 0xFF000000;
346 if (biBitCount <= 8) {
354 else if (biBitCount <= 16) {
362 else if (biBitCount <= 24) {
370 else if (biBitCount <= 32) {
383 for (i = 0; i < 4; i++) {
386 while ((~masks[i]) & 1) {
394 masks[i] = rgba[i] >> shifts[i];
399 fb_hMemCpy(target_pal, palette, palette_entries *
sizeof(
int));
403 buffer = (
unsigned char *)malloc(size + 1);
405 case 1: padding = 4 - (((biWidth + 7) >> 3) & 0x3);
break;
406 case 4: padding = 4 - (((biWidth + 1) >> 1) & 0x3);
break;
407 default: padding = 4 - ((biWidth *
BYTES_PER_PIXEL(biBitCount)) & 0x3);
break;
410 fseek(f, bfOffBits, SEEK_SET);
411 for (i = flipped ? 0 : (biHeight - 1);
412 flipped ? (i < biHeight) : (i >= 0);
413 flipped ? i++ : i--) {
417 for (j = 0; j < biWidth; j++) {
418 if (j % (8 / expand) == 0) {
419 if ((color = fgetc(f)) < 0) {
424 buffer[j] = color >> (8 - expand);
425 color = (color << expand) & 0xFF;
427 for (j = 0; j < padding; j++)
430 else if (!fread(buffer, size, 1, f)) {
435 convert(buffer, ctx->
line[i], width, masks, shifts, bits);
463 f = fopen(buffer,
"rb");
478 fgetc(f); fgetc(f); fgetc(f); fgetc(f);
479 size = fgetc(f) | (fgetc(f) << 8);
484 size = fgetc(f) | (fgetc(f) << 8) | (fgetc(f) << 16) | (fgetc(f) << 24);
490 result =
load_bmp(context, f, dest, pal, usenewheader);
504 if ((!fread(context->
line[0], size, 1, f)) && (!feof(f)))
511 color = fgetc(f) | (fgetc(f) << 8) | (fgetc(f) << 16);
513 color = (color << 2) & 0xFCFCFC;
522 if ((!fread(dest, size, 1, f)) && (!feof(f)))