ref: 678523a15572456b68612fafc422d4dee29ca59c
parent: 47a138b6362c314be4cfd91977ac61b3cf772e0f
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Jun 25 20:30:00 EDT 2001
move the huffman tables to a separate header git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@30 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_huffman.c,v 1.5 2001/06/12 09:09:04 giles Exp $
+ $Id: jbig2_huffman.c,v 1.6 2001/06/26 00:30:00 giles Exp $
*/
/* Huffman table decoding procedures
@@ -18,28 +18,14 @@
#include "jbig2dec.h"
#include "jbig2_huffman.h"
+#include "jbig2_hufftab.h"
#define JBIG2_HUFFMAN_FLAGS_ISOOB 1
#define JBIG2_HUFFMAN_FLAGS_ISLOW 2
#define JBIG2_HUFFMAN_FLAGS_ISEXT 4
-typedef struct _Jbig2HuffmanEntry Jbig2HuffmanEntry;
-struct _Jbig2HuffmanEntry {
- union {
- int32 RANGELOW;
- Jbig2HuffmanTable *ext_table;
- } u;
- byte PREFLEN;
- byte RANGELEN;
- byte flags;
-};
-struct _Jbig2HuffmanTable {
- int log_table_size;
- Jbig2HuffmanEntry *entries;
-};
-
struct _Jbig2HuffmanState {
/* The current bit offset is equal to (offset * 8) + offset_bits.
The MSB of this_word is the current bit offset. The MSB of next_word
@@ -145,96 +131,6 @@
return result;
}
-
-typedef struct _Jbig2HuffmanLine Jbig2HuffmanLine;
-
-struct _Jbig2HuffmanLine {
- int PREFLEN;
- int RANGELEN;
- int RANGELOW;
-};
-
-struct _Jbig2HuffmanParams {
- bool HTOOB;
- int n_lines;
- const Jbig2HuffmanLine *lines;
-};
-
-/* Table B.1 */
-const Jbig2HuffmanLine
-jbig_huffman_lines_A[] = {
- { 1, 4, 0 },
- { 2, 8, 16 },
- { 3, 16, 272 },
- { 0, 32, -1 }, /* low */
- { 3, 32, 65808 } /* high */
-};
-
-const Jbig2HuffmanParams
-jbig_huffman_params_A = { FALSE, 5, jbig_huffman_lines_A };
-
-/* Table B.2 */
-const Jbig2HuffmanLine
-jbig_huffman_lines_B[] = {
- { 1, 0, 0 },
- { 2, 0, 1 },
- { 3, 0, 2 },
- { 4, 3, 3 },
- { 5, 6, 11 },
- { 0, 32, -1 }, /* low */
- { 6, 32, 75 }, /* high */
- { 6, 0, 0 }
-};
-
-const Jbig2HuffmanParams
-jbig_huffman_params_B = { TRUE, 8, jbig_huffman_lines_B };
-
-/* Table B.3 */
-const Jbig2HuffmanLine
-jbig_huffman_lines_C[] = {
- { 8, 8, -256 },
- { 1, 0, 0 },
- { 2, 0, 1 },
- { 3, 0, 2 },
- { 4, 3, 3 },
- { 5, 6, 11 },
- { 8, 32, -257 }, /* low */
- { 7, 32, 75 }, /* high */
- { 6, 0, 0 } /* OOB */
-};
-
-const Jbig2HuffmanParams
-jbig_huffman_params_C = { TRUE, 9, jbig_huffman_lines_C };
-
-/* Table B.4 */
-const Jbig2HuffmanLine
-jbig_huffman_lines_D[] = {
- { 1, 0, 1 },
- { 2, 0, 2 },
- { 3, 0, 3 },
- { 4, 3, 4 },
- { 5, 6, 12 },
- { 0, 32, -1 }, /* low */
- { 5, 32, 76 }, /* high */
-};
-
-const Jbig2HuffmanParams
-jbig_huffman_params_D = { FALSE, 7, jbig_huffman_lines_D };
-
-/* Table B.14 */
-const Jbig2HuffmanLine
-jbig_huffman_lines_N[] = {
- { 3, 0, -2 },
- { 3, 0, -1 },
- { 1, 0, 0 },
- { 3, 3, 1 },
- { 3, 6, 2 },
- { 0, 32, -1 }, /* low */
- { 0, 32, 3 }, /* high */
-};
-
-const Jbig2HuffmanParams
-jbig_huffman_params_N = { FALSE, 7, jbig_huffman_lines_N };
#define LOG_TABLE_SIZE_MAX 8
--- a/jbig2_huffman.h
+++ b/jbig2_huffman.h
@@ -8,12 +8,10 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_huffman.h,v 1.2 2001/06/10 07:09:18 giles Exp $
+ $Id: jbig2_huffman.h,v 1.3 2001/06/26 00:30:00 giles Exp $
*/
-typedef struct _Jbig2HuffmanState Jbig2HuffmanState;
-typedef struct _Jbig2HuffmanTable Jbig2HuffmanTable;
-typedef struct _Jbig2HuffmanParams Jbig2HuffmanParams;
+#include "jbig2_hufftab.h"
Jbig2HuffmanState *
jbig2_huffman_new (Jbig2WordStream *ws);
--- /dev/null
+++ b/jbig2_hufftab.h
@@ -1,0 +1,131 @@
+/*
+ jbig2dec
+
+ Copyright (c) 2001 artofcode LLC.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ $Id: jbig2_hufftab.h,v 1.1 2001/06/26 00:30:00 giles Exp $
+*/
+
+/* predefined Huffman table definitions
+ -- See Annex B of the JBIG2 draft spec */
+
+#ifndef JBIG2_HUFFTAB_H
+#define JBIG2_HUFFTAB_H
+
+typedef struct _Jbig2HuffmanEntry Jbig2HuffmanEntry;
+typedef struct _Jbig2HuffmanState Jbig2HuffmanState;
+typedef struct _Jbig2HuffmanTable Jbig2HuffmanTable;
+typedef struct _Jbig2HuffmanParams Jbig2HuffmanParams;
+
+struct _Jbig2HuffmanEntry {
+ union {
+ int32 RANGELOW;
+ Jbig2HuffmanTable *ext_table;
+ } u;
+ byte PREFLEN;
+ byte RANGELEN;
+ byte flags;
+};
+
+struct _Jbig2HuffmanTable {
+ int log_table_size;
+ Jbig2HuffmanEntry *entries;
+};
+
+typedef struct _Jbig2HuffmanLine Jbig2HuffmanLine;
+
+struct _Jbig2HuffmanLine {
+ int PREFLEN;
+ int RANGELEN;
+ int RANGELOW;
+};
+
+struct _Jbig2HuffmanParams {
+ bool HTOOB;
+ int n_lines;
+ const Jbig2HuffmanLine *lines;
+};
+
+/* Table B.1 */
+const Jbig2HuffmanLine
+jbig_huffman_lines_A[] = {
+ { 1, 4, 0 },
+ { 2, 8, 16 },
+ { 3, 16, 272 },
+ { 0, 32, -1 }, /* low */
+ { 3, 32, 65808 } /* high */
+};
+
+const Jbig2HuffmanParams
+jbig_huffman_params_A = { FALSE, 5, jbig_huffman_lines_A };
+
+/* Table B.2 */
+const Jbig2HuffmanLine
+jbig_huffman_lines_B[] = {
+ { 1, 0, 0 },
+ { 2, 0, 1 },
+ { 3, 0, 2 },
+ { 4, 3, 3 },
+ { 5, 6, 11 },
+ { 0, 32, -1 }, /* low */
+ { 6, 32, 75 }, /* high */
+ { 6, 0, 0 }
+};
+
+const Jbig2HuffmanParams
+jbig_huffman_params_B = { TRUE, 8, jbig_huffman_lines_B };
+
+/* Table B.3 */
+const Jbig2HuffmanLine
+jbig_huffman_lines_C[] = {
+ { 8, 8, -256 },
+ { 1, 0, 0 },
+ { 2, 0, 1 },
+ { 3, 0, 2 },
+ { 4, 3, 3 },
+ { 5, 6, 11 },
+ { 8, 32, -257 }, /* low */
+ { 7, 32, 75 }, /* high */
+ { 6, 0, 0 } /* OOB */
+};
+
+const Jbig2HuffmanParams
+jbig_huffman_params_C = { TRUE, 9, jbig_huffman_lines_C };
+
+/* Table B.4 */
+const Jbig2HuffmanLine
+jbig_huffman_lines_D[] = {
+ { 1, 0, 1 },
+ { 2, 0, 2 },
+ { 3, 0, 3 },
+ { 4, 3, 4 },
+ { 5, 6, 12 },
+ { 0, 32, -1 }, /* low */
+ { 5, 32, 76 }, /* high */
+};
+
+const Jbig2HuffmanParams
+jbig_huffman_params_D = { FALSE, 7, jbig_huffman_lines_D };
+
+/* Table B.14 */
+const Jbig2HuffmanLine
+jbig_huffman_lines_N[] = {
+ { 3, 0, -2 },
+ { 3, 0, -1 },
+ { 1, 0, 0 },
+ { 3, 3, 1 },
+ { 3, 6, 2 },
+ { 0, 32, -1 }, /* low */
+ { 0, 32, 3 }, /* high */
+};
+
+const Jbig2HuffmanParams
+jbig_huffman_params_N = { FALSE, 7, jbig_huffman_lines_N };
+
+
+#endif /* JBIG2_HUFFTAB_H */
--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2dec.c,v 1.8 2001/06/14 23:09:23 giles Exp $
+ $Id: jbig2dec.c,v 1.9 2001/06/26 00:30:00 giles Exp $
*/
#include <stdio.h>
@@ -206,7 +206,16 @@
SDREFAGG = (result->flags >> 1) & 1;
SDRTEMPLATE = (result->flags >> 12) & 1;
- /* 7.4.2.1.2 */
+ /* FIXME: there are quite a few of these conditions to check */
+ /* maybe #ifdef CONFORMANCE and a separate routine */
+ if(!SDHUFF && !(result->flags & 0x0006)) {
+ printf("warning: SDHUFF is zero, but contrary to spec SDHUFFDH is not.\n");
+ }
+ if(!SDHUFF && !(result->flags & 0x0018)) {
+ printf("warning: SDHUFF is zero, but contrary to spec SDHUFFDW is not.\n");
+ }
+
+ /* 7.4.2.1.2 - Symbol dictionary AT flags */
if (!SDHUFF)
{
int SDTEMPLATE = (result->flags >> 10) & 3;
@@ -221,7 +230,7 @@
memset (&result->SDAT_flags + sdat_bytes, 0, 8 - sdat_bytes);
offset += sdat_bytes;
- /* 7.4.2.1.3 */
+ /* 7.4.2.1.3 - Symbol dictionary refinement AT flags */
if (SDREFAGG && !SDRTEMPLATE)
{
get_bytes (ctx, result->SDRAT_flags, 4, offset);
@@ -235,6 +244,8 @@
result->SDNUMNEWSYMS = get_int32 (ctx, offset + 4);
offset += 8;
+ /* hardwire for the first annex-h example */
+
return result;
}