static void do_read_bitmap(deark *c, lctx *d, de_int64 pos) { de_int64 ver_num; dbuf *unc_pixels = NULL; ver_num = de_getui32be(pos); de_dbg(c, "version number: %u\n", (unsigned int)ver_num); if(ver_num!=0 && ver_num!=2 && ver_num!=3) { de_warn(c, "Unrecognized version number: %u\n", (unsigned int)ver_num); } pos += 512; unc_pixels = dbuf_create_membuf(c, MACPAINT_IMAGE_BYTES, 1); de_fmtutil_uncompress_packbits(c->infile, pos, c->infile->len - pos, unc_pixels, NULL); if(unc_pixels->len < MACPAINT_IMAGE_BYTES) { de_warn(c, "Image decompressed to %d bytes, expected %d.\n", (int)unc_pixels->len, (int)MACPAINT_IMAGE_BYTES); } de_convert_and_write_image_bilevel(unc_pixels, 0, MACPAINT_WIDTH, MACPAINT_HEIGHT, MACPAINT_WIDTH/8, DE_CVTF_WHITEISZERO, NULL, 0); dbuf_close(unc_pixels); }
static int do_uncompress_image(deark *c, lctx *d, i64 pos1, dbuf *unc_pixels) { i64 bytes_in_this_line; i64 pos = pos1; i64 j; int ret; de_dbg(c, "decompressing bitmap"); // Each line is compressed independently, using PackBits. for(j=0; j<d->h; j++) { bytes_in_this_line = de_getu16le(pos); pos += 2; ret = de_fmtutil_uncompress_packbits(c->infile, pos, bytes_in_this_line, unc_pixels, NULL); if(!ret) return 0; pos += bytes_in_this_line; } de_dbg(c, "decompressed %d bytes to %d bytes", (int)(pos-pos1), (int)unc_pixels->len); return 1; }