rev 429 - trunk
[email protected] Tue, 16 Aug 2005 16:57:25 -0700 (PDT)
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: giles
Date: 2005-08-16 16:57:25 -0700 (Tue, 16 Aug 2005)
New Revision: 429
Modified:
trunk/jbig2_text.c
Log:
Work-in-progress commit. Partial implementation of Huffman text region=20
support.
Modified: trunk/jbig2_text.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/jbig2_text.c 2005-08-16 21:41:38 UTC (rev 428)
+++ trunk/jbig2_text.c 2005-08-16 23:57:25 UTC (rev 429)
@@ -51,9 +51,10 @@
/* SBW */
/* SBH */
uint32_t SBNUMINSTANCES;
+ int LOGSBSTRIPS;
int SBSTRIPS;
/* SBNUMSYMS */
- int *SBSYMCODES;
+ Jbig2HuffmanTable *SBSYMCODES;
/* SBSYMCODELEN */
/* SBSYMS */
Jbig2HuffmanTable *SBHUFFFS;
@@ -63,7 +64,7 @@
Jbig2HuffmanTable *SBHUFFRDH;
Jbig2HuffmanTable *SBHUFFRDX;
Jbig2HuffmanTable *SBHUFFRDY;
- bool SBHUFFRSIZE;
+ Jbig2HuffmanTable *SBHUFFRSIZE;
bool SBRTEMPLATE;
int8_t sbrat[4];
} Jbig2TextRegionParams;
@@ -110,6 +111,7 @@
uint32_t index, max_id;
Jbig2Image *IB;
Jbig2WordStream *ws =3D NULL;
+ Jbig2HuffmanState *hs =3D NULL;
Jbig2ArithState *as =3D NULL;
Jbig2ArithIntCtx *IADT =3D NULL;
Jbig2ArithIntCtx *IAFS =3D NULL;
@@ -131,10 +133,10 @@
jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
"symbol list contains %d glyphs in %d dictionaries", max_id, n_d=
icts);
=20
+ ws =3D jbig2_word_stream_buf_new(ctx, data, size);
if (!params->SBHUFF) {
int SBSYMCODELEN;
=20
- ws =3D jbig2_word_stream_buf_new(ctx, data, size);
as =3D jbig2_arith_new(ctx, ws);
IADT =3D jbig2_arith_int_ctx_new(ctx);
IAFS =3D jbig2_arith_int_ctx_new(ctx);
@@ -148,14 +150,18 @@
IARDH =3D jbig2_arith_int_ctx_new(ctx);
IARDX =3D jbig2_arith_int_ctx_new(ctx);
IARDY =3D jbig2_arith_int_ctx_new(ctx);
+ } else {
+ jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
+ "huffman coded text region");
+ hs =3D jbig2_huffman_new(ctx, ws);
}
- =20
+
/* 6.4.5 (1) */
jbig2_image_clear(ctx, image, params->SBDEFPIXEL);
=20
/* 6.4.6 */
if (params->SBHUFF) {
- /* todo */
+ STRIPT =3D jbig2_huffman_get(hs, params->SBHUFFDT, &code);
} else {
code =3D jbig2_arith_int_decode(IADT, as, &STRIPT);
}
@@ -183,7 +189,7 @@
if (first_symbol) {
/* 6.4.7 */
if (params->SBHUFF) {
- /* todo */
+ DFS =3D jbig2_huffman_get(hs, params->SBHUFFFS, &code);
} else {
code =3D jbig2_arith_int_decode(IAFS, as, &DFS);
}
@@ -192,9 +198,9 @@
first_symbol =3D FALSE;
=20
} else {
- /* (3c.ii / 6.4.8) */
+ /* (3c.ii) / 6.4.8 */
if (params->SBHUFF) {
- /* todo */
+ IDS =3D jbig2_huffman_get(hs, params->SBHUFFDS, &code);
} else {
code =3D jbig2_arith_int_decode(IADS, as, &IDS);
}
@@ -204,19 +210,19 @@
CURS +=3D IDS + params->SBDSOFFSET;
}
=20
- /* (3c.iii / 6.4.9) */
+ /* (3c.iii) / 6.4.9 */
if (params->SBSTRIPS =3D=3D 1) {
CURT =3D 0;
} else if (params->SBHUFF) {
- /* todo */
+ CURT =3D jbig2_huffman_get_bits(hs, params->LOGSBSTRIPS);
} else {
code =3D jbig2_arith_int_decode(IAIT, as, &CURT);
}
T =3D STRIPT + CURT;
=20
- /* (3b.iv / 6.4.10) decode the symbol id */
+ /* (3b.iv) / 6.4.10 - decode the symbol id */
if (params->SBHUFF) {
- /* todo */
+ ID =3D jbig2_huffman_get(hs, params->SBSYMCODES, &code);
} else {
code =3D jbig2_arith_iaid_decode(IAID, as, (int *)&ID);
}
@@ -225,7 +231,7 @@
"symbol id out of range! (%d/%d)", ID, max_id);
}
=20
- /* (3c.v / 6.4.11) look up the symbol bitmap IB */
+ /* (3c.v) / 6.4.11 - look up the symbol bitmap IB */
{
uint32_t id =3D ID;
=20
@@ -235,7 +241,11 @@
IB =3D jbig2_image_clone(ctx, dicts[index]->glyphs[id]);
}
if (params->SBREFINE) {
+ if (params->SBHUFF) {
+ RI =3D jbig2_huffman_get_bits(hs, 1);
+ } else {
code =3D jbig2_arith_int_decode(IARI, as, &RI);
+ }
} else {
RI =3D 0;
}
@@ -244,14 +254,24 @@
Jbig2Image *IBO;
int32_t RDW, RDH, RDX, RDY;
Jbig2Image *image;
+ int BMSIZE =3D 0;
=20
- /* (6.4.11 (1, 2, 3, 4)) */
- code =3D jbig2_arith_int_decode(IARDW, as, &RDW);
- code =3D jbig2_arith_int_decode(IARDH, as, &RDH);
- code =3D jbig2_arith_int_decode(IARDX, as, &RDX);
- code =3D jbig2_arith_int_decode(IARDY, as, &RDY);
+ /* 6.4.11 (1, 2, 3, 4) */
+ if (!params->SBHUFF) {
+ code =3D jbig2_arith_int_decode(IARDW, as, &RDW);
+ code =3D jbig2_arith_int_decode(IARDH, as, &RDH);
+ code =3D jbig2_arith_int_decode(IARDX, as, &RDX);
+ code =3D jbig2_arith_int_decode(IARDY, as, &RDY);
+ } else {
+ RDW =3D jbig2_huffman_get(hs, params->SBHUFFRDW, &code);
+ RDH =3D jbig2_huffman_get(hs, params->SBHUFFRDH, &code);
+ RDX =3D jbig2_huffman_get(hs, params->SBHUFFRDX, &code);
+ RDY =3D jbig2_huffman_get(hs, params->SBHUFFRDY, &code);
+ BMSIZE =3D jbig2_huffman_get(hs, params->SBHUFFRSIZE, &code);
+ jbig2_huffman_skip(hs);
+ }
=20
- /* (6.4.11 (6)) */
+ /* 6.4.11 (6) */
IBO =3D IB;
image =3D jbig2_image_new(ctx, IBO->width + RDW,
IBO->height + RDH);
@@ -268,6 +288,12 @@
IB =3D image;
=20
jbig2_image_release(ctx, IBO);
+
+ /* 6.4.11 (7) */
+ if (params->SBHUFF) {
+ jbig2_huffman_advance(hs, BMSIZE);
+ }
+
}
=20
/* (3c.vi) */
@@ -369,7 +395,8 @@
=20
params.SBHUFF =3D flags & 0x0001;
params.SBREFINE =3D flags & 0x0002;
- params.SBSTRIPS =3D 1 << ((flags & 0x000c) >> 2);
+ params.LOGSBSTRIPS =3D (flags & 0x000c) >> 2;
+ params.SBSTRIPS =3D 1 << params.LOGSBSTRIPS;
params.REFCORNER =3D (flags & 0x0030) >> 4;
params.TRANSPOSED =3D flags & 0x0040;
params.SBCOMBOP =3D (flags & 0x0180) >> 7;
@@ -405,13 +432,10 @@
offset +=3D 4;
=20
if (params.SBHUFF) {
- /* 7.4.3.1.5 */
- /* todo: symbol ID huffman decoding table decoding */
- =20
- jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
- "symbol id huffman table decoding NYI");
- =20
- /* 7.4.3.1.6 */
+ /* 7.4.3.1.5 - Symbol ID Huffman table */
+ /* todo: write the bloody thing */=09
+
+ /* 7.4.3.1.6 - Other Huffman table selection */
switch (huffman_flags & 0x0003) {
case 0: /* Table B.6 */
params.SBHUFFFS =3D jbig2_build_huffman_table(ctx,
@@ -550,26 +574,33 @@
"text region specified invalid RDY huffman table");
break;
}
- /* todo: conformance */
- params.SBHUFFRSIZE =3D huffman_flags & 0x8000;
+ switch ((huffman_flags & 0x4000) >> 14) {
+ case 0: /* Table B.1 */
+ params.SBHUFFRSIZE =3D jbig2_build_huffman_table(ctx,
+ &jbig2_huffman_params_A);
+ break;
+ case 1: /* Custom table from referred segment */
+ /* We handle this case later by leaving the table as NULL */
+ return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "text region uses custom RSIZE huffman table (NYI)");
+ break;
+ }
+=09
+ if (huffman_flags & 0x8000) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
+ "text region huffman flags bit 15 is set, contrary to spec");
+ }
=20
/* 7.4.3.1.7 */
/* todo: symbol ID huffman table decoding */
}
=20
- /* 7.4.3.2 (3) */
- if (!params.SBHUFF && params.SBREFINE) {
- int stats_size =3D params.SBRTEMPLATE ? 1 << 10 : 1 << 13;
- GR_stats =3D jbig2_alloc(ctx->allocator, stats_size);
- memset(GR_stats, 0, stats_size);
- }
-
jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
"text region: %d x %d @ (%d,%d) %d symbols",
region_info.width, region_info.height,
region_info.x, region_info.y, params.SBNUMINSTANCES);
=20
- /* compose the list of symbol dictionaries */
+ /* 7.4.3.2 (2) - compose the list of symbol dictionaries */
n_dicts =3D jbig2_sd_count_referred(ctx, segment);
if (n_dicts !=3D 0) {
dicts =3D jbig2_sd_list_referred(ctx, segment);
@@ -596,6 +627,13 @@
}
}
=20
+ /* 7.4.3.2 (3) */
+ if (!params.SBHUFF && params.SBREFINE) {
+ int stats_size =3D params.SBRTEMPLATE ? 1 << 10 : 1 << 13;
+ GR_stats =3D jbig2_alloc(ctx->allocator, stats_size);
+ memset(GR_stats, 0, stats_size);
+ }
+
image =3D jbig2_image_new(ctx, region_info.width, region_info.height=
);
=20
code =3D jbig2_decode_text_region(ctx, segment, ¶ms,
@@ -603,6 +641,10 @@
segment_data + offset, segment->data_length - offset,
GR_stats);
=20
+ if (!params.SBHUFF && params.SBREFINE) {
+ jbig2_free(ctx->allocator, GR_stats);
+ }
+
if (params.SBHUFF) {
jbig2_release_huffman_table(ctx, params.SBHUFFFS);
jbig2_release_huffman_table(ctx, params.SBHUFFDS);
@@ -611,10 +653,7 @@
jbig2_release_huffman_table(ctx, params.SBHUFFRDY);
jbig2_release_huffman_table(ctx, params.SBHUFFRDW);
jbig2_release_huffman_table(ctx, params.SBHUFFRDH);
- }
-
- if (!params.SBHUFF && params.SBREFINE) {
- jbig2_free(ctx->allocator, GR_stats);
+ jbig2_release_huffman_table(ctx, params.SBHUFFRSIZE);
}
=20
jbig2_free(ctx->allocator, dicts);