ref: ce3a7fe3d687598968a4f032b67f5f8fe5337565
parent: b3d5fd5a743c85e446adc78f6d6922fdba967467
author: Sebastian Rasmussen <sebras@gmail.com>
date: Wed May 23 19:12:43 EDT 2018
jbig2dec: Return jbig2_error(WARNING); they indicate errors. Because jbig2_error(ctx, JBIG2_SEVERITY_WARNING, ...) now returns -1, it can be immediately returned or assigned as a return code.
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -746,8 +746,7 @@
for (i = 0; i < 8; i++)
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "gbat[%d] = %d", i, params->gbat[i]);
}
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "decode_generic_region: MMR=%d, GBTEMPLATE=%d NYI", params->MMR, params->GBTEMPLATE);
- return -1;
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "decode_generic_region: MMR=%d, GBTEMPLATE=%d NYI", params->MMR, params->GBTEMPLATE);
}
/**
--- a/jbig2_halftone.c
+++ b/jbig2_halftone.c
@@ -221,10 +221,8 @@
int stats_size = jbig2_generic_stats_size(ctx, params.HDTEMPLATE);
GB_stats = jbig2_new(ctx, Jbig2ArithCx, stats_size);
- if (GB_stats == NULL) {
- jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to allocate GB_stats in pattern dictionary");
- return 0;
- }
+ if (GB_stats == NULL)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate GB_stats in pattern dictionary");
memset(GB_stats, 0, stats_size);
}
@@ -476,10 +474,8 @@
* get it from referred pattern dictionary */
HPATS = jbig2_decode_ht_region_get_hpats(ctx, segment);
- if (!HPATS) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "no pattern dictionary found, skipping halftone image");
- return -1;
- }
+ if (!HPATS)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "no pattern dictionary found, skipping halftone image");
HNUMPATS = HPATS->n_patterns;
/* calculate ceil(log2(HNUMPATS)) */
@@ -489,12 +485,9 @@
/* 6.6.5 point 4. decode gray-scale image as mentioned in annex C */
GI = jbig2_decode_gray_scale_image(ctx, segment, data, size,
params->HMMR, params->HGW, params->HGH, HBPP, params->HENABLESKIP, HSKIP, params->HTEMPLATE, GB_stats);
+ if (!GI)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to acquire gray-scale image, skipping halftone image");
- if (!GI) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to acquire gray-scale image, skipping halftone image");
- return -1;
- }
-
/* 6.6.5 point 5. place patterns with procedure mentioned in 6.6.5.2 */
for (mg = 0; mg < params->HGH; ++mg) {
for (ng = 0; ng < params->HGW; ++ng) {
@@ -509,10 +502,8 @@
gray_val = HNUMPATS - 1;
}
code = jbig2_image_compose(ctx, image, HPATS->patterns[gray_val], x, y, params->op);
- if (code < 0) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to compose pattern with gray-scale image");
- return -1;
- }
+ if (code < 0)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to compose pattern with gray-scale image");
}
}
--- a/jbig2_metadata.c
+++ b/jbig2_metadata.c
@@ -110,8 +110,7 @@
md->keys[md->entries] = jbig2_strndup(ctx, key, key_length);
md->values[md->entries] = jbig2_strndup(ctx, value, value_length);
if (md->keys[md->entries] == NULL || md->values[md->entries] == NULL) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "unable to accommodate more metadata");
- return -1;
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "unable to accommodate more metadata");
}
md->entries++;
@@ -131,10 +130,8 @@
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "ASCII comment data");
comment = jbig2_metadata_new(ctx, JBIG2_ENCODING_ASCII);
- if (comment == NULL) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate comment structure");
- return -1;
- }
+ if (comment == NULL)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to allocate comment structure");
/* loop over the segment data pulling out the key,value pairs */
while (s < end && *s) {
key = s;
@@ -147,10 +144,8 @@
goto too_short;
s++;
code = jbig2_metadata_add(ctx, comment, key, value - key, value, s - value);
- if (code < 0) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to add ascii comment data");
- return -1;
- }
+ if (code < 0)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "unable to add ascii comment data");
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "'%s'\t'%s'", key, value);
}
--- a/jbig2_mmr.c
+++ b/jbig2_mmr.c
@@ -1022,10 +1022,8 @@
for (y = 0; y < image->height; y++) {
memset(dst, 0, rowstride);
code = jbig2_decode_mmr_line(ctx, &mmr, ref, dst);
- if (code < 0) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode mmr line");
- return code;
- }
+ if (code < 0)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode mmr line");
ref = dst;
dst += rowstride;
}
@@ -1063,10 +1061,8 @@
for (y = 0; y < image->height; y++) {
memset(dst, 0, rowstride);
code = jbig2_decode_mmr_line(ctx, &mmr, ref, dst);
- if (code < 0) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode halftone mmr line");
- return code;
- }
+ if (code < 0)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to decode halftone mmr line");
ref = dst;
dst += rowstride;
}
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -257,10 +257,8 @@
int code;
/* ensure image exists first */
- if (page->image == NULL) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "page info possibly missing, no image defined");
- return 0;
- }
+ if (page->image == NULL)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "page info possibly missing, no image defined");
/* grow the page to accommodate a new stripe if necessary */
if (page->striped && page->height == 0xFFFFFFFF) {
@@ -279,10 +277,8 @@
}
code = jbig2_image_compose(ctx, page->image, image, x, y + page->end_row, op);
- if (code < 0) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to compose image with page");
- return -1;
- }
+ if (code < 0)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, -1, "failed to compose image with page");
return 0;
}
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -86,7 +86,7 @@
code = jbig2_image_write_pbm_file(dict->glyphs[index], filename);
#endif
if (code < 0)
- jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number, "failed to dump symbol %d/%d as '%s'", index, dict->n_symbols, filename);
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to dump symbol %d/%d as '%s'", index, dict->n_symbols, filename);
}
}
#endif /* DUMP_SYMDICT */
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -98,10 +98,8 @@
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number, "huffman coded text region");
hs = jbig2_huffman_new(ctx, ws);
- if (hs == NULL) {
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for text region");
- return -1;
- }
+ if (hs == NULL)
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to allocate storage for text region");
/* 7.4.3.1.7 - decode symbol ID Huffman table */
/* this is actually part of the segment header, but it is more