diff options
Diffstat (limited to 'xps/xps_tiff.c')
-rw-r--r-- | xps/xps_tiff.c | 78 |
1 files changed, 37 insertions, 41 deletions
diff --git a/xps/xps_tiff.c b/xps/xps_tiff.c index 7496cb56..b9571465 100644 --- a/xps/xps_tiff.c +++ b/xps/xps_tiff.c @@ -56,7 +56,7 @@ struct tiff fz_colorspace *colorspace; byte *samples; int stride; - fz_context *doc; + fz_context *ctx; }; enum @@ -183,15 +183,15 @@ xps_decode_tiff_fax(struct tiff *tiff, int comp, fz_stream *chain, byte *wp, int fz_obj *params; fz_obj *columns, *rows, *black_is_1, *k, *encoded_byte_align; int n; - fz_context *doc = tiff->doc; + fz_context *ctx = tiff->ctx; - columns = fz_new_int(doc, tiff->imagewidth); - rows = fz_new_int(doc, tiff->imagelength); - black_is_1 = fz_new_bool(doc, tiff->photometric == 0); - k = fz_new_int(doc, comp == 4 ? -1 : 0); - encoded_byte_align = fz_new_bool(doc, comp == 2); + columns = fz_new_int(ctx, tiff->imagewidth); + rows = fz_new_int(ctx, tiff->imagelength); + black_is_1 = fz_new_bool(ctx, tiff->photometric == 0); + k = fz_new_int(ctx, comp == 4 ? -1 : 0); + encoded_byte_align = fz_new_bool(ctx, comp == 2); - params = fz_new_dict(doc, 5); + params = fz_new_dict(ctx, 5); fz_dict_puts(params, "Columns", columns); fz_dict_puts(params, "Rows", rows); fz_dict_puts(params, "BlackIs1", black_is_1); @@ -320,7 +320,7 @@ xps_expand_tiff_colormap(struct tiff *tiff) stride = tiff->imagewidth * (tiff->samplesperpixel + 2); - samples = fz_malloc(tiff->doc, stride * tiff->imagelength); + samples = fz_malloc(tiff->ctx, stride * tiff->imagelength); for (y = 0; y < tiff->imagelength; y++) { @@ -430,7 +430,7 @@ xps_decode_tiff_strips(struct tiff *tiff) tiff->yresolution = 96; } - tiff->samples = fz_malloc_array(tiff->doc, tiff->imagelength, tiff->stride); + tiff->samples = fz_malloc_array(tiff->ctx, tiff->imagelength, tiff->stride); memset(tiff->samples, 0x55, tiff->imagelength * tiff->stride); wp = tiff->samples; @@ -454,7 +454,7 @@ xps_decode_tiff_strips(struct tiff *tiff) rp[i] = bitrev[rp[i]]; /* the strip decoders will close this */ - stm = fz_open_memory(tiff->doc, rp, rlen); + stm = fz_open_memory(tiff->ctx, rp, rlen); switch (tiff->compression) { @@ -675,7 +675,7 @@ xps_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case ICCProfile: - tiff->profile = fz_malloc(tiff->doc, count); + tiff->profile = fz_malloc(tiff->ctx, count); /* ICC profile data type is set to UNDEFINED. * TBYTE reading not correct in xps_read_tiff_tag_value */ xps_read_tiff_bytes(tiff->profile, tiff, value, count); @@ -683,23 +683,23 @@ xps_read_tiff_tag(struct tiff *tiff, unsigned offset) break; case JPEGTables: - fz_warn(tiff->doc, "jpeg tables in tiff not implemented"); + fz_warn(tiff->ctx, "jpeg tables in tiff not implemented"); tiff->jpegtables = tiff->bp + value; tiff->jpegtableslen = count; break; case StripOffsets: - tiff->stripoffsets = fz_malloc_array(tiff->doc, count, sizeof(unsigned)); + tiff->stripoffsets = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); xps_read_tiff_tag_value(tiff->stripoffsets, tiff, type, value, count); break; case StripByteCounts: - tiff->stripbytecounts = fz_malloc_array(tiff->doc, count, sizeof(unsigned)); + tiff->stripbytecounts = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); xps_read_tiff_tag_value(tiff->stripbytecounts, tiff, type, value, count); break; case ColorMap: - tiff->colormap = fz_malloc_array(tiff->doc, count, sizeof(unsigned)); + tiff->colormap = fz_malloc_array(tiff->ctx, count, sizeof(unsigned)); xps_read_tiff_tag_value(tiff->colormap, tiff, type, value, count); break; @@ -795,26 +795,23 @@ xps_decode_tiff_header(struct tiff *tiff, byte *buf, int len) return fz_okay; } -int -xps_decode_tiff(fz_context *doc, fz_pixmap **imagep, byte *buf, int len) +fz_pixmap * +xps_decode_tiff(fz_context *ctx, byte *buf, int len) { - int error; fz_pixmap *image; struct tiff tiff; - tiff.doc = doc; - error = xps_decode_tiff_header(&tiff, buf, len); - if (error) - return fz_error_note(error, "cannot decode tiff header"); + tiff.ctx = ctx; + xps_decode_tiff_header(&tiff, buf, len); + /* RJW: "cannot decode tiff header" */ /* Decode the image strips */ if (tiff.rowsperstrip > tiff.imagelength) tiff.rowsperstrip = tiff.imagelength; - error = xps_decode_tiff_strips(&tiff); - if (error) - return fz_error_note(error, "cannot decode image data"); + xps_decode_tiff_strips(&tiff); + /* RJW: "cannot decode image data" */ /* Byte swap 16-bit images to big endian if necessary */ if (tiff.bitspersample == 16) @@ -825,14 +822,14 @@ xps_decode_tiff(fz_context *doc, fz_pixmap **imagep, byte *buf, int len) /* Expand into fz_pixmap struct */ - image = fz_new_pixmap_with_limit(tiff.doc, tiff.colorspace, tiff.imagewidth, tiff.imagelength); + image = fz_new_pixmap_with_limit(tiff.ctx, tiff.colorspace, tiff.imagewidth, tiff.imagelength); if (!image) { - if (tiff.colormap) fz_free(doc, tiff.colormap); - if (tiff.stripoffsets) fz_free(doc, tiff.stripoffsets); - if (tiff.stripbytecounts) fz_free(doc, tiff.stripbytecounts); - if (tiff.samples) fz_free(doc, tiff.samples); - return fz_error_make("out of memory"); + if (tiff.colormap) fz_free(ctx, tiff.colormap); + if (tiff.stripoffsets) fz_free(ctx, tiff.stripoffsets); + if (tiff.stripbytecounts) fz_free(ctx, tiff.stripbytecounts); + if (tiff.samples) fz_free(ctx, tiff.samples); + fz_throw(ctx, "out of memory"); } image->xres = tiff.xresolution; @@ -846,11 +843,11 @@ xps_decode_tiff(fz_context *doc, fz_pixmap **imagep, byte *buf, int len) /* CMYK is a subtractive colorspace, we want additive for premul alpha */ if (image->n == 5) { - fz_pixmap *rgb = fz_new_pixmap(tiff.doc, fz_device_rgb, image->w, image->h); - fz_convert_pixmap(tiff.doc, image, rgb); + fz_pixmap *rgb = fz_new_pixmap(tiff.ctx, fz_device_rgb, image->w, image->h); + fz_convert_pixmap(tiff.ctx, image, rgb); rgb->xres = image->xres; rgb->yres = image->yres; - fz_drop_pixmap(doc, image); + fz_drop_pixmap(ctx, image); image = rgb; } fz_premultiply_pixmap(image); @@ -858,11 +855,10 @@ xps_decode_tiff(fz_context *doc, fz_pixmap **imagep, byte *buf, int len) /* Clean up scratch memory */ - if (tiff.colormap) fz_free(doc, tiff.colormap); - if (tiff.stripoffsets) fz_free(doc, tiff.stripoffsets); - if (tiff.stripbytecounts) fz_free(doc, tiff.stripbytecounts); - if (tiff.samples) fz_free(doc, tiff.samples); + if (tiff.colormap) fz_free(ctx, tiff.colormap); + if (tiff.stripoffsets) fz_free(ctx, tiff.stripoffsets); + if (tiff.stripbytecounts) fz_free(ctx, tiff.stripbytecounts); + if (tiff.samples) fz_free(ctx, tiff.samples); - *imagep = image; - return fz_okay; + return image; } |