Lines Matching refs:bmp

75 static bmp_result bmp_info_header_parse(bmp_image *bmp, uint8_t *data)  in bmp_info_header_parse()  argument
85 if (bmp->buffer_size < (BMP_FILE_HEADER_SIZE + BITMAPCOREHEADER)) { in bmp_info_header_parse()
92 if ((bmp->buffer_size - BMP_FILE_HEADER_SIZE) < header_size) { in bmp_info_header_parse()
113 bmp->reversed = true; in bmp_info_header_parse()
122 if (bmp->ico) { in bmp_info_header_parse()
126 bmp->width = width; in bmp_info_header_parse()
127 bmp->height = height / 2; in bmp_info_header_parse()
130 bmp->width = width; in bmp_info_header_parse()
131 bmp->height = height; in bmp_info_header_parse()
135 bmp->bpp = read_uint16(data, 10); in bmp_info_header_parse()
141 if ((bmp->bpp != 1) && (bmp->bpp != 4) && in bmp_info_header_parse()
142 (bmp->bpp != 8) && in bmp_info_header_parse()
143 (bmp->bpp != 16) && in bmp_info_header_parse()
144 (bmp->bpp != 24) && in bmp_info_header_parse()
145 (bmp->bpp != 32)) in bmp_info_header_parse()
147 if (bmp->bpp < 16) in bmp_info_header_parse()
148 bmp->colours = (1 << bmp->bpp); in bmp_info_header_parse()
190 bmp->reversed = true; in bmp_info_header_parse()
203 if (bmp->ico) { in bmp_info_header_parse()
207 bmp->width = width; in bmp_info_header_parse()
208 bmp->height = height / 2; in bmp_info_header_parse()
211 bmp->width = width; in bmp_info_header_parse()
212 bmp->height = height; in bmp_info_header_parse()
216 bmp->bpp = read_uint16(data, 14); in bmp_info_header_parse()
217 if (bmp->bpp == 0) in bmp_info_header_parse()
218 bmp->bpp = 8; in bmp_info_header_parse()
219 bmp->encoding = read_uint32(data, 16); in bmp_info_header_parse()
228 switch (bmp->encoding) { in bmp_info_header_parse()
230 if ((bmp->bpp != 1) && (bmp->bpp != 4) && in bmp_info_header_parse()
231 (bmp->bpp != 8) && in bmp_info_header_parse()
232 (bmp->bpp != 16) && in bmp_info_header_parse()
233 (bmp->bpp != 24) && in bmp_info_header_parse()
234 (bmp->bpp != 32)) in bmp_info_header_parse()
238 if (bmp->bpp != 8) in bmp_info_header_parse()
242 if (bmp->bpp != 4) in bmp_info_header_parse()
246 if ((bmp->bpp != 16) && (bmp->bpp != 32)) in bmp_info_header_parse()
258 if (bmp->encoding == BMP_ENCODING_BITFIELDS) { in bmp_info_header_parse()
261 if (bmp->buffer_size < (14 + header_size)) in bmp_info_header_parse()
264 bmp->mask[i] = read_uint32(data, 40 + (i << 2)); in bmp_info_header_parse()
269 bmp->mask[i] = read_uint32(data, 40 + (i << 2)); in bmp_info_header_parse()
272 if (bmp->mask[i] == 0) in bmp_info_header_parse()
275 if (bmp->mask[i] & ((unsigned)1 << j)) { in bmp_info_header_parse()
277 bmp->mask[i] &= (unsigned)0xff << (j - 7); in bmp_info_header_parse()
279 bmp->mask[i] &= 0xff >> (-(j - 7)); in bmp_info_header_parse()
280 bmp->shift[i] = (i << 3) - (j - 7); in bmp_info_header_parse()
285 bmp->colours = read_uint32(data, 32); in bmp_info_header_parse()
286 if (bmp->colours == 0 && bmp->bpp < 16) in bmp_info_header_parse()
287 bmp->colours = (1 << bmp->bpp); in bmp_info_header_parse()
293 if ((!bmp->ico) && (bmp->mask[3] == 0)) { in bmp_info_header_parse()
295 bmp->opaque = true; in bmp_info_header_parse()
299 if (bmp->bpp < 16) { in bmp_info_header_parse()
311 if (bmp->buffer_size < (14 + header_size + ((uint64_t)4 * bmp->colours))) in bmp_info_header_parse()
315 bmp->colour_table = (uint32_t *)malloc(bmp->colours * 4); in bmp_info_header_parse()
316 if (!bmp->colour_table) in bmp_info_header_parse()
318 for (i = 0; i < bmp->colours; i++) { in bmp_info_header_parse()
320 if (bmp->opaque) in bmp_info_header_parse()
323 bmp->colour_table[i] = read_uint32((uint8_t *)&colour,0); in bmp_info_header_parse()
331 if ((bmp->bitmap_offset < (uint32_t)(data - bmp->bmp_data)) && in bmp_info_header_parse()
332 ((bmp->buffer_size - (data - bmp->bmp_data)) > 0)) { in bmp_info_header_parse()
333 bmp->bitmap_offset = data - bmp->bmp_data; in bmp_info_header_parse()
339 bmp->bitmap = bmp->bitmap_callbacks.bitmap_create(bmp->width, bmp->height, flags); in bmp_info_header_parse()
340 if (!bmp->bitmap) { in bmp_info_header_parse()
341 if (bmp->colour_table) in bmp_info_header_parse()
342 free(bmp->colour_table); in bmp_info_header_parse()
343 bmp->colour_table = NULL; in bmp_info_header_parse()
349 if (bmp->ico) in bmp_info_header_parse()
350 bmp->bitmap_offset = (uintptr_t)data - (uintptr_t)bmp->bmp_data; in bmp_info_header_parse()
362 static bmp_result bmp_file_header_parse(bmp_image *bmp, uint8_t *data) in bmp_file_header_parse() argument
372 if (bmp->buffer_size < BMP_FILE_HEADER_SIZE) in bmp_file_header_parse()
378 bmp->bitmap_offset = read_uint32(data, 10); in bmp_file_header_parse()
381 if (bmp->bitmap_offset >= bmp->buffer_size) { in bmp_file_header_parse()
398 bmp_create(&image->bmp, &ico->bitmap_callbacks); in next_ico_image()
460 image->bmp.width = read_uint8(data, 0); in ico_header_parse()
461 if (image->bmp.width == 0) in ico_header_parse()
462 image->bmp.width = 256; in ico_header_parse()
463 image->bmp.height = read_uint8(data, 1); in ico_header_parse()
464 if (image->bmp.height == 0) in ico_header_parse()
465 image->bmp.height = 256; in ico_header_parse()
466 image->bmp.buffer_size = read_uint32(data, 8); in ico_header_parse()
467 image->bmp.bmp_data = ico->ico_data + read_uint32(data, 12); in ico_header_parse()
468 if (image->bmp.bmp_data + image->bmp.buffer_size > in ico_header_parse()
471 image->bmp.ico = true; in ico_header_parse()
475 if (image->bmp.bmp_data - ico->ico_data >= 0 && in ico_header_parse()
476 (uint32_t)(image->bmp.bmp_data - in ico_header_parse()
481 if (image->bmp.buffer_size - ICO_DIR_ENTRY_SIZE >= in ico_header_parse()
485 result = bmp_info_header_parse(&image->bmp, in ico_header_parse()
486 image->bmp.bmp_data); in ico_header_parse()
491 area = image->bmp.width * image->bmp.height; in ico_header_parse()
493 ico->width = image->bmp.width; in ico_header_parse()
494 ico->height = image->bmp.height; in ico_header_parse()
512 static bmp_result bmp_decode_rgb32(bmp_image *bmp, uint8_t **start, int bytes) in bmp_decode_rgb32() argument
522 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_rgb32()
523 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_rgb32()
526 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_rgb32()
528 bmp->decoded = true; in bmp_decode_rgb32()
531 if (bmp->limited_trans) { in bmp_decode_rgb32()
534 if (bmp->encoding == BMP_ENCODING_BITFIELDS) in bmp_decode_rgb32()
535 bmp->transparent_index = read_uint32(data, 0); in bmp_decode_rgb32()
537 bmp->transparent_index = data[2] | (data[1] << 8) | (data[0] << 16); in bmp_decode_rgb32()
540 for (y = 0; y < bmp->height; y++) { in bmp_decode_rgb32()
541 if ((data + (4 * bmp->width)) > end) in bmp_decode_rgb32()
543 if (bmp->reversed) in bmp_decode_rgb32()
547 if (bmp->encoding == BMP_ENCODING_BITFIELDS) { in bmp_decode_rgb32()
548 for (x = 0; x < bmp->width; x++) { in bmp_decode_rgb32()
551 if (bmp->shift[i] > 0) in bmp_decode_rgb32()
552 … scanline[x] |= ((word & bmp->mask[i]) << bmp->shift[i]); in bmp_decode_rgb32()
554 … scanline[x] |= ((word & bmp->mask[i]) >> (-bmp->shift[i])); in bmp_decode_rgb32()
556 if (bmp->opaque) in bmp_decode_rgb32()
562 for (x = 0; x < bmp->width; x++) { in bmp_decode_rgb32()
564 … if ((bmp->limited_trans) && (scanline[x] == bmp->transparent_index)) { in bmp_decode_rgb32()
565 scanline[x] = bmp->trans_colour; in bmp_decode_rgb32()
567 if (bmp->opaque) { in bmp_decode_rgb32()
592 static bmp_result bmp_decode_rgb24(bmp_image *bmp, uint8_t **start, int bytes) in bmp_decode_rgb24() argument
601 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_rgb24()
602 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_rgb24()
607 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_rgb24()
610 bmp->decoded = true; in bmp_decode_rgb24()
613 if (bmp->limited_trans) { in bmp_decode_rgb24()
618 bmp->transparent_index = data[2] | (data[1] << 8) | (data[0] << 16); in bmp_decode_rgb24()
621 for (y = 0; y < bmp->height; y++) { in bmp_decode_rgb24()
622 if ((data + (3 * bmp->width)) > end) { in bmp_decode_rgb24()
626 if (bmp->reversed) { in bmp_decode_rgb24()
632 for (x = 0; x < bmp->width; x++) { in bmp_decode_rgb24()
634 if ((bmp->limited_trans) && (scanline[x] == bmp->transparent_index)) { in bmp_decode_rgb24()
635 scanline[x] = bmp->trans_colour; in bmp_decode_rgb24()
662 static bmp_result bmp_decode_rgb16(bmp_image *bmp, uint8_t **start, int bytes) in bmp_decode_rgb16() argument
672 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_rgb16()
673 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_rgb16()
676 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_rgb16()
679 bmp->decoded = true; in bmp_decode_rgb16()
682 if (bmp->limited_trans) { in bmp_decode_rgb16()
685 bmp->transparent_index = read_uint16(data, 0); in bmp_decode_rgb16()
688 for (y = 0; y < bmp->height; y++) { in bmp_decode_rgb16()
689 if ((data + (2 * bmp->width)) > end) in bmp_decode_rgb16()
691 if (bmp->reversed) in bmp_decode_rgb16()
695 if (bmp->encoding == BMP_ENCODING_BITFIELDS) { in bmp_decode_rgb16()
696 for (x = 0; x < bmp->width; x++) { in bmp_decode_rgb16()
698 if ((bmp->limited_trans) && (word == bmp->transparent_index)) in bmp_decode_rgb16()
699 scanline[x] = bmp->trans_colour; in bmp_decode_rgb16()
703 if (bmp->shift[i] > 0) in bmp_decode_rgb16()
704 … scanline[x] |= ((word & bmp->mask[i]) << bmp->shift[i]); in bmp_decode_rgb16()
706 … scanline[x] |= ((word & bmp->mask[i]) >> (-bmp->shift[i])); in bmp_decode_rgb16()
707 if (bmp->opaque) in bmp_decode_rgb16()
714 for (x = 0; x < bmp->width; x++) { in bmp_decode_rgb16()
716 if ((bmp->limited_trans) && (word == bmp->transparent_index)) in bmp_decode_rgb16()
717 scanline[x] = bmp->trans_colour; in bmp_decode_rgb16()
724 if (bmp->opaque) in bmp_decode_rgb16()
748 static bmp_result bmp_decode_rgb(bmp_image *bmp, uint8_t **start, int bytes) in bmp_decode_rgb() argument
755 uint8_t ppb = 8 / bmp->bpp; in bmp_decode_rgb()
756 uint8_t bit_mask = (1 << bmp->bpp) - 1; in bmp_decode_rgb()
760 bit_shifts[i] = 8 - ((i + 1) * bmp->bpp); in bmp_decode_rgb()
763 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_rgb()
764 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_rgb()
767 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_rgb()
770 bmp->decoded = true; in bmp_decode_rgb()
773 if (bmp->limited_trans) { in bmp_decode_rgb()
775 if (idx >= bmp->colours) in bmp_decode_rgb()
777 bmp->transparent_index = bmp->colour_table[idx]; in bmp_decode_rgb()
780 for (y = 0; y < bmp->height; y++) { in bmp_decode_rgb()
782 if ((data + ((bmp->width + ppb - 1) / ppb)) > end) in bmp_decode_rgb()
784 if (bmp->reversed) in bmp_decode_rgb()
788 for (x = 0; x < bmp->width; x++) { in bmp_decode_rgb()
795 if (idx < bmp->colours) { in bmp_decode_rgb()
797 scanline[x] = bmp->colour_table[idx]; in bmp_decode_rgb()
798 if ((bmp->limited_trans) && in bmp_decode_rgb()
799 (scanline[x] == bmp->transparent_index)) { in bmp_decode_rgb()
800 scanline[x] = bmp->trans_colour; in bmp_decode_rgb()
820 static bmp_result bmp_decode_mask(bmp_image *bmp, uint8_t *data, int bytes) in bmp_decode_mask() argument
828 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_mask()
829 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_mask()
832 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_mask()
837 for (y = 0; y < bmp->height; y++) { in bmp_decode_mask()
838 if ((data + (bmp->width >> 3)) > end) in bmp_decode_mask()
841 for (x = 0; x < bmp->width; x++) { in bmp_decode_mask()
871 bmp_decode_rle8(bmp_image *bmp, uint8_t *data, int bytes) in bmp_decode_rle8() argument
880 if (bmp->ico) in bmp_decode_rle8()
883 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_rle8()
884 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_rle8()
887 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_rle8()
889 bmp->decoded = true; in bmp_decode_rle8()
903 if (y >= bmp->height) in bmp_decode_rle8()
918 if (x >= bmp->width) in bmp_decode_rle8()
921 if (y >= bmp->height) in bmp_decode_rle8()
927 if (bmp->reversed) { in bmp_decode_rle8()
928 pixels_left = (bmp->height - y) * bmp->width - x; in bmp_decode_rle8()
931 pixels_left = (y + 1) * bmp->width - x; in bmp_decode_rle8()
945 if (x >= bmp->width) { in bmp_decode_rle8()
948 if (y >= bmp->height) in bmp_decode_rle8()
950 if (bmp->reversed) { in bmp_decode_rle8()
951 scanline += bmp->width; in bmp_decode_rle8()
953 scanline -= bmp->width; in bmp_decode_rle8()
956 if (idx >= bmp->colours) in bmp_decode_rle8()
958 scanline[x++] = bmp->colour_table[idx]; in bmp_decode_rle8()
970 if (bmp->reversed) { in bmp_decode_rle8()
971 pixels_left = (bmp->height - y) * bmp->width - x; in bmp_decode_rle8()
974 pixels_left = (y + 1) * bmp->width - x; in bmp_decode_rle8()
989 if (idx >= bmp->colours) in bmp_decode_rle8()
992 pixel = bmp->colour_table[idx]; in bmp_decode_rle8()
994 if (x >= bmp->width) { in bmp_decode_rle8()
997 if (y >= bmp->height) in bmp_decode_rle8()
999 if (bmp->reversed) { in bmp_decode_rle8()
1000 scanline += bmp->width; in bmp_decode_rle8()
1002 scanline -= bmp->width; in bmp_decode_rle8()
1025 bmp_decode_rle4(bmp_image *bmp, uint8_t *data, int bytes) in bmp_decode_rle4() argument
1034 if (bmp->ico) in bmp_decode_rle4()
1037 swidth = sizeof(uint32_t) * bmp->width; in bmp_decode_rle4()
1038 top = bmp->bitmap_callbacks.bitmap_get_buffer(bmp->bitmap); in bmp_decode_rle4()
1041 bottom = top + (uint64_t)swidth * (bmp->height - 1); in bmp_decode_rle4()
1043 bmp->decoded = true; in bmp_decode_rle4()
1057 if (y >= bmp->height) in bmp_decode_rle4()
1072 if (x >= bmp->width) in bmp_decode_rle4()
1075 if (y >= bmp->height) in bmp_decode_rle4()
1081 if (bmp->reversed) { in bmp_decode_rle4()
1082 pixels_left = (bmp->height - y) * bmp->width - x; in bmp_decode_rle4()
1085 pixels_left = (y + 1) * bmp->width - x; in bmp_decode_rle4()
1099 if (x >= bmp->width) { in bmp_decode_rle4()
1102 if (y >= bmp->height) in bmp_decode_rle4()
1104 if (bmp->reversed) { in bmp_decode_rle4()
1105 scanline += bmp->width; in bmp_decode_rle4()
1107 scanline -= bmp->width; in bmp_decode_rle4()
1113 if ((pixel >> 4) >= bmp->colours) in bmp_decode_rle4()
1115 scanline[x++] = bmp->colour_table in bmp_decode_rle4()
1118 if ((pixel & 0xf) >= bmp->colours) in bmp_decode_rle4()
1120 scanline[x++] = bmp->colour_table in bmp_decode_rle4()
1133 if (bmp->reversed) { in bmp_decode_rle4()
1134 pixels_left = (bmp->height - y) * bmp->width - x; in bmp_decode_rle4()
1137 pixels_left = (y + 1) * bmp->width - x; in bmp_decode_rle4()
1153 if ((pixel2 >> 4) >= bmp->colours || in bmp_decode_rle4()
1154 (pixel2 & 0xf) >= bmp->colours) in bmp_decode_rle4()
1156 pixel = bmp->colour_table[pixel2 >> 4]; in bmp_decode_rle4()
1157 pixel2 = bmp->colour_table[pixel2 & 0xf]; in bmp_decode_rle4()
1159 if (x >= bmp->width) { in bmp_decode_rle4()
1162 if (y >= bmp->height) in bmp_decode_rle4()
1164 if (bmp->reversed) { in bmp_decode_rle4()
1165 scanline += bmp->width; in bmp_decode_rle4()
1167 scanline -= bmp->width; in bmp_decode_rle4()
1185 bmp_create(bmp_image *bmp, in bmp_create() argument
1188 memset(bmp, 0, sizeof(bmp_image)); in bmp_create()
1189 bmp->bitmap_callbacks = *bitmap_callbacks; in bmp_create()
1209 bmp_result bmp_analyse(bmp_image *bmp, size_t size, uint8_t *data) in bmp_analyse() argument
1214 if (bmp->bitmap) { in bmp_analyse()
1219 bmp->buffer_size = size; in bmp_analyse()
1220 bmp->bmp_data = data; in bmp_analyse()
1222 res = bmp_file_header_parse(bmp, data); in bmp_analyse()
1224 res = bmp_info_header_parse(bmp, data + BMP_FILE_HEADER_SIZE); in bmp_analyse()
1246 bmp_result bmp_decode(bmp_image *bmp) in bmp_decode() argument
1252 data = bmp->bmp_data + bmp->bitmap_offset; in bmp_decode()
1253 bytes = bmp->buffer_size - bmp->bitmap_offset; in bmp_decode()
1255 switch (bmp->encoding) { in bmp_decode()
1257 switch (bmp->bpp) { in bmp_decode()
1259 result = bmp_decode_rgb32(bmp, &data, bytes); in bmp_decode()
1263 result = bmp_decode_rgb24(bmp, &data, bytes); in bmp_decode()
1267 result = bmp_decode_rgb16(bmp, &data, bytes); in bmp_decode()
1271 result = bmp_decode_rgb(bmp, &data, bytes); in bmp_decode()
1277 result = bmp_decode_rle8(bmp, data, bytes); in bmp_decode()
1281 result = bmp_decode_rle4(bmp, data, bytes); in bmp_decode()
1285 switch (bmp->bpp) { in bmp_decode()
1287 result = bmp_decode_rgb32(bmp, &data, bytes); in bmp_decode()
1291 result = bmp_decode_rgb16(bmp, &data, bytes); in bmp_decode()
1302 if ((result == BMP_OK) && (bmp->ico) && (bmp->bpp != 32)) { in bmp_decode()
1303 bytes = (uintptr_t)bmp->bmp_data + bmp->buffer_size - (uintptr_t)data; in bmp_decode()
1304 result = bmp_decode_mask(bmp, data, bytes); in bmp_decode()
1311 bmp_result bmp_decode_trans(bmp_image *bmp, uint32_t colour) in bmp_decode_trans() argument
1313 bmp->limited_trans = true; in bmp_decode_trans()
1314 bmp->trans_colour = colour; in bmp_decode_trans()
1315 return bmp_decode(bmp); in bmp_decode_trans()
1322 bmp_image *bmp = NULL; in ico_find() local
1331 if ((image->bmp.width == width) && (image->bmp.height == height)) in ico_find()
1332 return &image->bmp; in ico_find()
1333 x = image->bmp.width - width; in ico_find()
1334 y = image->bmp.height - height; in ico_find()
1338 bmp = &image->bmp; in ico_find()
1341 return bmp; in ico_find()
1346 void bmp_finalise(bmp_image *bmp) in bmp_finalise() argument
1348 if (bmp->bitmap) in bmp_finalise()
1349 bmp->bitmap_callbacks.bitmap_destroy(bmp->bitmap); in bmp_finalise()
1350 bmp->bitmap = NULL; in bmp_finalise()
1351 if (bmp->colour_table) in bmp_finalise()
1352 free(bmp->colour_table); in bmp_finalise()
1353 bmp->colour_table = NULL; in bmp_finalise()
1363 bmp_finalise(&image->bmp); in ico_finalise()