From 18f1a38c6a0cb2f1e696a9e688892cb83d4a4f81 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 6 Sep 2020 15:06:40 +0000 Subject: Return some error info to caller instead of writing to Standard Error git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3946 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- converter/other/jpeg2000/libjasper/jp2/jp2_dec.c | 74 ++++++++++++------------ 1 file changed, 37 insertions(+), 37 deletions(-) (limited to 'converter') diff --git a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c b/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c index 7ad591ed..e8d71b0a 100644 --- a/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c +++ b/converter/other/jpeg2000/libjasper/jp2/jp2_dec.c @@ -300,32 +300,34 @@ jp2_decode(jas_stream_t * const in, image = 0; if (!(dec = jp2_dec_create())) { - goto error; + pm_asprintf(errorP, "jp2_dec_create failed"); + goto cleanup; } /* Get the first box. This should be a JP box. */ if (!(box = jp2_box_get(in))) { - jas_eprintf("error: cannot get box\n"); - goto error; + pm_asprintf(errorP, "cannot get box"); + goto cleanup; } if (box->type != JP2_BOX_JP) { - jas_eprintf("error: expecting signature box\n"); - goto error; + pm_asprintf(errorP, "expecting signature box"); + goto cleanup; } if (box->data.jp.magic != JP2_JP_MAGIC) { - jas_eprintf("incorrect magic number\n"); - goto error; + pm_asprintf(errorP, "incorrect magic number"); + goto cleanup; } jp2_box_destroy(box); box = 0; /* Get the second box. This should be a FTYP box. */ if (!(box = jp2_box_get(in))) { - goto error; + pm_asprintf(errorP, "cannot get second box"); + goto cleanup; } if (box->type != JP2_BOX_FTYP) { - jas_eprintf("expecting file type box\n"); - goto error; + pm_asprintf(errorP, "expecting file type box"); + goto cleanup; } jp2_box_destroy(box); box = 0; @@ -334,7 +336,7 @@ jp2_decode(jas_stream_t * const in, found = 0; while ((box = jp2_box_get(in))) { if (jas_getdbglevel() >= 1) { - fprintf(stderr, "box type %s\n", box->info->name); + jas_eprintf("box type '%s'\n", box->info->name); } switch (box->type) { case JP2_BOX_JP2C: @@ -387,25 +389,24 @@ jp2_decode(jas_stream_t * const in, } if (!found) { - jas_eprintf("error: no code stream found\n"); - goto error; + pm_asprintf(errorP, "no code stream found"); + goto cleanup; } { const char * decodeError; jpc_decode(in, optstr, &dec->image, &decodeError); if (decodeError) { - jas_eprintf("error: cannot decode code stream. %s\n", - decodeError); + pm_asprintf(errorP, "cannot decode code stream. %s", decodeError); pm_strfree(decodeError); - goto error; + goto cleanup; } } /* An IHDR box must be present. */ if (!dec->ihdr) { - jas_eprintf("error: missing IHDR box\n"); - goto error; + pm_asprintf(errorP, "missing IHDR box"); + goto cleanup; } /* Does the number of components indicated in the IHDR box match @@ -416,8 +417,8 @@ jp2_decode(jas_stream_t * const in, /* At least one component must be present. */ if (!jas_image_numcmpts(dec->image)) { - jas_eprintf("error: no components\n"); - goto error; + pm_asprintf(errorP, "no components"); + goto cleanup; } /* Determine if all components have the same data type. */ @@ -439,15 +440,15 @@ jp2_decode(jas_stream_t * const in, /* Can we handle the compression type? */ if (dec->ihdr->data.ihdr.comptype != JP2_IHDR_COMPTYPE) { - jas_eprintf("error: not capable of this compression type\n"); - goto error; + pm_asprintf(errorP, "not capable of this compression type"); + goto cleanup; } if (dec->bpcc) { /* Is the number of components indicated in the BPCC box consistent with the code stream data? */ if (dec->bpcc->data.bpcc.numcmpts != jas_image_numcmpts( - dec->image)) { + dec->image)) { jas_eprintf("warning: number of components mismatch\n"); } /* Is the component data type information indicated in the BPCC @@ -466,8 +467,8 @@ jp2_decode(jas_stream_t * const in, /* A COLR box must be present. */ if (!dec->colr) { - jas_eprintf("error: no COLR box\n"); - goto error; + pm_asprintf(errorP, "no COLR box"); + goto cleanup; } switch (dec->colr->data.colr.method) { @@ -513,14 +514,14 @@ jp2_decode(jas_stream_t * const in, /* Is the component number reasonable? */ if (dec->cmap->data.cmap.ents[i].cmptno >= jas_image_numcmpts(dec->image)) { - jas_eprintf("error: invalid component number in CMAP box\n"); - goto error; + pm_asprintf(errorP, "invalid component number in CMAP box"); + goto cleanup; } /* Is the LUT index reasonable? */ if (dec->cmap->data.cmap.ents[i].pcol >= dec->pclr->data.pclr.numchans) { - jas_eprintf("error: invalid CMAP LUT index\n"); - goto error; + pm_asprintf(errorP, "invalid CMAP LUT index"); + goto cleanup; } } } @@ -528,8 +529,8 @@ jp2_decode(jas_stream_t * const in, /* Allocate space for the channel-number to component-number LUT. */ dec->chantocmptlut = jas_malloc(dec->numchans * sizeof(uint_fast16_t)); if (!dec->chantocmptlut) { - jas_eprintf("error: no memory\n"); - goto error; + pm_asprintf(errorP, "no memory"); + goto cleanup; } if (!dec->cmap) { @@ -575,8 +576,8 @@ jp2_decode(jas_stream_t * const in, } #endif } else { - jas_eprintf("error: invalid MTYP in CMAP box\n"); - goto error; + pm_asprintf(errorP, "invalid MTYP in CMAP box"); + goto cleanup; } } } @@ -615,8 +616,8 @@ jp2_decode(jas_stream_t * const in, /* Ensure that some components survived. */ if (!jas_image_numcmpts(dec->image)) { - jas_eprintf("error: no components\n"); - goto error; + pm_asprintf(errorP, "no components"); + goto cleanup; } /* Prevent the image from being destroyed later. */ @@ -629,14 +630,13 @@ jp2_decode(jas_stream_t * const in, *errorP = NULL; return; -error: +cleanup: if (box) { jp2_box_destroy(box); } if (dec) { jp2_dec_destroy(dec); } - pm_asprintf(errorP, "failed"); } -- cgit 1.4.1