summaryrefslogtreecommitdiff
path: root/jbig2dec/jbig2_generic.c
diff options
context:
space:
mode:
authorSebastian Rasmussen <sebras@gmail.com>2019-09-15 17:58:40 +0200
committerSebastian Rasmussen <sebras@gmail.com>2020-03-20 17:54:14 +0800
commit17e84cb1a4903fab26b5fc5d2e4805a1097f5a33 (patch)
tree364691f4f3e99ac0c198be76669bda659a634e96 /jbig2dec/jbig2_generic.c
parent716560bf5f2bc4b821ca6924ec648ca4949826bb (diff)
downloadghostpdl-17e84cb1a4903fab26b5fc5d2e4805a1097f5a33.tar.gz
jbig2dec: Let arithmetic decoder and the underlying stream report errors.
When a called function indicates an error, the caller should print warnings. Since the arithmetic decoder now uses the normal way of reporting errors, the callers of the decoder are changed to report warnings.
Diffstat (limited to 'jbig2dec/jbig2_generic.c')
-rw-r--r--jbig2dec/jbig2_generic.c72
1 files changed, 36 insertions, 36 deletions
diff --git a/jbig2dec/jbig2_generic.c b/jbig2dec/jbig2_generic.c
index 565fb9e56..844bd092b 100644
--- a/jbig2dec/jbig2_generic.c
+++ b/jbig2dec/jbig2_generic.c
@@ -408,9 +408,9 @@ jbig2_decode_generic_template0(Jbig2Ctx *ctx,
for (x_minor = 0; x_minor < minor_width; x_minor++) {
int bit;
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template0 optimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template0 optimized");
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x7bf7) << 1) | bit | ((line_m1 >> (7 - x_minor)) & 0x10) | ((line_m2 >> (7 - x_minor)) & 0x800);
}
@@ -477,9 +477,9 @@ jbig2_decode_generic_template0_unopt(Jbig2Ctx *ctx,
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[4], y + params->gbat[5]) << 11;
CONTEXT |= (ppd>>2) & 0x7000; /* Next 3 pixels */
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6], y + params->gbat[7]) << 15;
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template0 unoptimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template0 unoptimized");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -543,9 +543,9 @@ jbig2_decode_generic_template1_unopt(Jbig2Ctx *ctx,
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0], y + params->gbat[1]) << 3;
CONTEXT |= (pd>>9) & 0x01F0; /* Next 5 pixels */
CONTEXT |= (ppd>>4) & 0x1E00; /* Next 4 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template1 unoptimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template1 unoptimized");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -614,9 +614,9 @@ jbig2_decode_generic_template1(Jbig2Ctx *ctx,
for (x_minor = 0; x_minor < minor_width; x_minor++) {
int bit;
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template1 optimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template1 optimized");
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0xefb) << 1) | bit | ((line_m1 >> (8 - x_minor)) & 0x8) | ((line_m2 >> (8 - x_minor)) & 0x200);
}
@@ -674,9 +674,9 @@ jbig2_decode_generic_template2_unopt(Jbig2Ctx *ctx,
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0], y + params->gbat[1]) << 2;
CONTEXT |= (pd>>11) & 0x078; /* Next 4 pixels */
CONTEXT |= (ppd>>7) & 0x380; /* Next 3 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template2 unoptimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template2 unoptimized");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -746,9 +746,9 @@ jbig2_decode_generic_template2(Jbig2Ctx *ctx,
for (x_minor = 0; x_minor < minor_width; x_minor++) {
int bit;
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template2 optimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template2 optimized");
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1bd) << 1) | bit | ((line_m1 >> (10 - x_minor)) & 0x4) | ((line_m2 >> (10 - x_minor)) & 0x80);
}
@@ -805,9 +805,9 @@ jbig2_decode_generic_template3(Jbig2Ctx *ctx,
for (x_minor = 0; x_minor < minor_width; x_minor++) {
int bit;
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template3 optimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template3 optimized");
result |= bit << (7 - x_minor);
CONTEXT = ((CONTEXT & 0x1f7) << 1) | bit | ((line_m1 >> (8 - x_minor)) & 0x10);
}
@@ -856,9 +856,9 @@ jbig2_decode_generic_template3_unopt(Jbig2Ctx *ctx,
CONTEXT = out_byte & 0x00F; /* First 4 pixels */
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0], y + params->gbat[1]) << 4;
CONTEXT |= (pd>>9) & 0x3E0; /* Next 5 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template3 unoptimized");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template3 unoptimized");
}
pd = pd<<1;
out_byte = (out_byte<<1) | bit;
@@ -921,9 +921,9 @@ jbig2_decode_generic_template0_TPGDON(Jbig2Ctx *ctx,
params->gbat[6] == -2 && params->gbat[7] == -2)
{
for (y = 0; y < GBH; y++) {
- int bit = jbig2_arith_decode(as, &GB_stats[0x9B25]);
+ int bit = jbig2_arith_decode(ctx, as, &GB_stats[0x9B25]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON1");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON1");
LTP ^= bit;
if (!LTP) {
uint32_t out_byte = 0;
@@ -950,9 +950,9 @@ jbig2_decode_generic_template0_TPGDON(Jbig2Ctx *ctx,
CONTEXT = out_byte & 0x00F; /* First 4 pixels */
CONTEXT |= (pd>>8) & 0x7F0; /* Next 7 pixels */
CONTEXT |= (ppd>>2) & 0xF800; /* Final 5 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON2");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON2");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -1019,9 +1019,9 @@ jbig2_decode_generic_template0_TPGDON(Jbig2Ctx *ctx,
/* So 0 <= y < top needs bounds checking. */
for (y = 0; y < GBH; y++) {
- int bit = jbig2_arith_decode(as, &GB_stats[0x9B25]);
+ int bit = jbig2_arith_decode(ctx, as, &GB_stats[0x9B25]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON1");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON1");
LTP ^= bit;
if (!LTP) {
uint32_t out_byte = 0;
@@ -1062,9 +1062,9 @@ jbig2_decode_generic_template0_TPGDON(Jbig2Ctx *ctx,
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[4], y + params->gbat[5]) << 11;
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[6], y + params->gbat[7]) << 15;
}
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON2");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template0 TPGDON2");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -1107,9 +1107,9 @@ jbig2_decode_generic_template1_TPGDON(Jbig2Ctx *ctx,
"adaptive template pixel is out of field");
for (y = 0; y < GBH; y++) {
- int bit = jbig2_arith_decode(as, &GB_stats[0x0795]);
+ int bit = jbig2_arith_decode(ctx, as, &GB_stats[0x0795]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template1 TPGDON1");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template1 TPGDON1");
LTP ^= bit;
if (!LTP) {
uint32_t out_byte = 0;
@@ -1137,9 +1137,9 @@ jbig2_decode_generic_template1_TPGDON(Jbig2Ctx *ctx,
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0], y + params->gbat[1]) << 3;
CONTEXT |= (pd>>9) & 0x01F0; /* next 5 pixels */
CONTEXT |= (ppd>>4) & 0x1E00; /* next 4 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template1 TPGDON2");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template1 TPGDON2");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -1182,9 +1182,9 @@ jbig2_decode_generic_template2_TPGDON(Jbig2Ctx *ctx,
"adaptive template pixel is out of field");
for (y = 0; y < GBH; y++) {
- int bit = jbig2_arith_decode(as, &GB_stats[0xE5]);
+ int bit = jbig2_arith_decode(ctx, as, &GB_stats[0xE5]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template2 TPGDON1");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template2 TPGDON1");
LTP ^= bit;
if (!LTP) {
uint32_t out_byte = 0;
@@ -1212,9 +1212,9 @@ jbig2_decode_generic_template2_TPGDON(Jbig2Ctx *ctx,
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0], y + params->gbat[1]) << 2;
CONTEXT |= (pd>>11) & 0x078; /* next 4 pixels */
CONTEXT |= (ppd>>7) & 0x380; /* next 3 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template2 TPGDON2");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template2 TPGDON2");
}
pd = pd<<1;
ppd = ppd<<1;
@@ -1257,9 +1257,9 @@ jbig2_decode_generic_template3_TPGDON(Jbig2Ctx *ctx,
"adaptive template pixel is out of field");
for (y = 0; y < GBH; y++) {
- int bit = jbig2_arith_decode(as, &GB_stats[0x0195]);
+ int bit = jbig2_arith_decode(ctx, as, &GB_stats[0x0195]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template3 TPGDON1");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template3 TPGDON1");
LTP ^= bit;
if (!LTP) {
uint32_t out_byte = 0;
@@ -1279,9 +1279,9 @@ jbig2_decode_generic_template3_TPGDON(Jbig2Ctx *ctx,
CONTEXT = out_byte & 0x0F; /* First 4 pixels */
CONTEXT |= jbig2_image_get_pixel(image, x + params->gbat[0], y + params->gbat[1]) << 4;
CONTEXT |= (pd>>9) & 0x3E0; /* next 5 pixels */
- bit = jbig2_arith_decode(as, &GB_stats[CONTEXT]);
+ bit = jbig2_arith_decode(ctx, as, &GB_stats[CONTEXT]);
if (bit < 0)
- return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number, "failed to decode arithmetic code when handling generic template3 TPGDON2");
+ return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number, "failed to decode arithmetic code when handling generic template3 TPGDON2");
}
pd = pd<<1;
out_byte = (out_byte<<1) | bit;