ref: c47c3b08840eb8e709fad19c018845d2ec00087d
parent: 2dce5e044ea710e68b1716ca543800c64ad633aa
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Sat Jun 15 12:02:56 EDT 2002
add segment routines in a separate file. prune the semi-dead jbig2dec.h in favor of jbig2.h and jbig2_priv.h. Update to C99 fixed-width types. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@64 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.2 2002/05/08 02:36:04 giles Exp $
+# $Id: Makefile.am,v 1.3 2002/06/15 16:02:53 giles Exp $
## process this file with automake to generate Makefile.in
lib_LIBRARIES = libjbig2dec.a
@@ -5,6 +5,7 @@
libjbig2dec_a_SOURCES = jbig2.c \
jbig2_arith.c jbig2_arith_int.c jbig2_huffman.c \
+ jbig2_segment.c jbig2_page.c \
jbig2_symbol_dict.c \
jbig2_generic.c jbig2_mmr.c \
jbig2_image.c jbig2_image_pbm.c
@@ -14,5 +15,3 @@
jbig2dec_SOURCES = jbig2dec.c
jbig2dec_LDADD = libjbig2dec.a @LIBOBJS@
-
-
--- a/jbig2.h
+++ b/jbig2.h
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2.h,v 1.4 2002/02/19 07:09:16 giles Exp $
+ $Id: jbig2.h,v 1.5 2002/06/15 16:02:53 giles Exp $
*/
#ifdef __cplusplus
@@ -15,6 +15,8 @@
extern "C" {
#endif
+#include <stdint.h> // for C99 types -- need a more portable sol'n
+
typedef enum {
JBIG2_SEVERITY_DEBUG,
JBIG2_SEVERITY_INFO,
@@ -30,6 +32,8 @@
typedef struct _Jbig2Ctx Jbig2Ctx;
typedef struct _Jbig2GlobalCtx Jbig2GlobalCtx;
typedef struct _Jbig2SegmentHeader Jbig2SegmentHeader;
+typedef struct _Jbig2PageInfo Jbig2PageInfo;
+typedef struct _Jbig2SymbolDictionary Jbig2SymbolDictionary;
struct _Jbig2SegmentHeader {
int32_t segment_number;
@@ -37,6 +41,15 @@
int referred_to_segment_count;
int32_t page_association;
int data_length;
+};
+
+struct _Jbig2PageInfo {
+ uint32_t height, width; /* in pixels */
+ uint32_t x_resolution,
+ y_resolution; /* in pixels per meter */
+ uint16_t stripe_size;
+ int striped;
+ uint8_t flags;
};
typedef int (*Jbig2ErrorCallback) (void *data,
--- 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.7 2001/07/05 22:37:44 giles Exp $
+ $Id: jbig2_huffman.c,v 1.8 2002/06/15 16:02:53 giles Exp $
*/
/* Huffman table decoding procedures
@@ -16,7 +16,8 @@
#include <stdlib.h>
-#include "jbig2dec.h"
+#include "jbig2.h"
+#include "jbig2_priv.h"
#include "jbig2_huffman.h"
#define JBIG2_HUFFMAN_FLAGS_ISOOB 1
@@ -29,8 +30,8 @@
/* 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
is (offset + 4) * 8. */
- uint32 this_word;
- uint32 next_word;
+ uint32_t this_word;
+ uint32_t next_word;
int offset_bits;
int offset;
@@ -53,7 +54,7 @@
return result;
}
-int32
+int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob)
{
@@ -60,10 +61,10 @@
Jbig2HuffmanEntry *entry;
byte flags;
int offset_bits = hs->offset_bits;
- uint32 this_word = hs->this_word;
- uint32 next_word;
+ uint32_t this_word = hs->this_word;
+ uint32_t next_word;
int RANGELEN;
- int32 result;
+ int32_t result;
for (;;)
{
@@ -99,7 +100,7 @@
RANGELEN = entry->RANGELEN;
if (RANGELEN > 0)
{
- int32 HTOFFSET;
+ int32_t HTOFFSET;
HTOFFSET = this_word >> (32 - RANGELEN);
if (flags & JBIG2_HUFFMAN_FLAGS_ISLOW)
@@ -213,7 +214,7 @@
{
for (j = start_j; j < end_j; j++)
{
- int32 HTOFFSET = (j >> (shift - RANGELEN)) &
+ int32_t HTOFFSET = (j >> (shift - RANGELEN)) &
((1 << RANGELEN) - 1);
if (eflags & JBIG2_HUFFMAN_FLAGS_ISLOW)
entries[j].u.RANGELOW = lines[CURTEMP].RANGELOW -
@@ -244,7 +245,7 @@
const byte test_stream[] = { 0xe9, 0xcb, 0xf4, 0x00 };
const byte test_tabindex[] = { 4, 2, 2, 1 };
-static uint32
+static uint32_t
test_get_word (Jbig2WordStream *self, int offset)
{
/* assume test_stream[] is at least 4 bytes */
@@ -264,7 +265,7 @@
Jbig2HuffmanState *hs;
Jbig2WordStream ws;
bool oob;
- int32 code;
+ int32_t code;
tables[0] = NULL;
tables[1] = jbig2_build_huffman_table (&jbig_huffman_params_A);
--- a/jbig2_huffman.h
+++ b/jbig2_huffman.h
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_huffman.h,v 1.3 2001/06/26 00:30:00 giles Exp $
+ $Id: jbig2_huffman.h,v 1.4 2002/06/15 16:02:53 giles Exp $
*/
#include "jbig2_hufftab.h"
@@ -16,7 +16,7 @@
Jbig2HuffmanState *
jbig2_huffman_new (Jbig2WordStream *ws);
-int32
+int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob);
--- a/jbig2_hufftab.h
+++ b/jbig2_hufftab.h
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_hufftab.h,v 1.2 2001/08/13 19:50:52 giles Exp $
+ $Id: jbig2_hufftab.h,v 1.3 2002/06/15 16:02:54 giles Exp $
*/
/* predefined Huffman table definitions
@@ -24,7 +24,7 @@
struct _Jbig2HuffmanEntry {
union {
- int32 RANGELOW;
+ int32_t RANGELOW;
Jbig2HuffmanTable *ext_table;
} u;
byte PREFLEN;
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -8,13 +8,13 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_image.c,v 1.3 2002/05/08 02:36:04 giles Exp $
+ $Id: jbig2_image.c,v 1.4 2002/06/15 16:02:54 giles Exp $
*/
#include <stdio.h>
#include <stdlib.h>
-#include "jbig2dec.h"
+#include "jbig2.h"
#include "jbig2_image.h"
@@ -51,4 +51,4 @@
{
free (image->data);
free (image);
-}
\ No newline at end of file
+}
--- a/jbig2_image_pbm.c
+++ b/jbig2_image_pbm.c
@@ -8,12 +8,13 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_image_pbm.c,v 1.2 2002/06/04 16:51:02 giles Exp $
+ $Id: jbig2_image_pbm.c,v 1.3 2002/06/15 16:02:54 giles Exp $
*/
#include <stdio.h>
-#include "jbig2dec.h"
+#include "jbig2.h"
+#include "jbig2_priv.h"
#include "jbig2_image.h"
/* take an image structure and write it to a file in pbm format */
--- a/jbig2_image_png.c
+++ b/jbig2_image_png.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_image_png.c,v 1.1 2002/05/08 02:36:04 giles Exp $
+ $Id: jbig2_image_png.c,v 1.2 2002/06/15 16:02:54 giles Exp $
*/
#include <stdio.h>
@@ -15,7 +15,8 @@
#include <stdlib.h>
#include <png.h>
-#include "jbig2dec.h"
+#include "jbig2.h"
+#include "jbig2_priv.h"
#include "jbig2_image.h"
/* take an image structure and write it out in png format */
--- a/jbig2_page.c
+++ b/jbig2_page.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_page.c,v 1.1 2002/06/15 14:15:12 giles Exp $
+ $Id: jbig2_page.c,v 1.2 2002/06/15 16:02:55 giles Exp $
*/
#include <stdio.h>
@@ -16,7 +16,6 @@
#include "jbig2.h"
#include "jbig2_priv.h"
-#include "jbig2_page.h"
/* parse the page info segment data starting at ctx->offset
a pointer to a new Jbig2PageInfo struct is returned
@@ -28,7 +27,7 @@
static Jbig2PageInfo *
jbig2_read_page_info (Jbig2Ctx *ctx) {
Jbig2PageInfo *info = (Jbig2PageInfo *)jbig2_alloc(ctx->allocator, sizeof(Jbig2PageInfo));
- int offset = ctx->buf_rd_idx;
+ int offset = ctx->buf_rd_ix;
if (info == NULL) {
printf("unable to allocate memory to parse page info segment\n");
@@ -46,7 +45,7 @@
get_bytes(ctx, &(info->flags), 1, offset++);
{
- int16 striping = get_int16(ctx, offset);
+ int16_t striping = get_int16(ctx, offset);
if (striping & 0x8000) {
info->striped = TRUE;
info->stripe_size = striping & 0x7FFF;
@@ -79,4 +78,4 @@
} else {
fprintf(out, "\tno striping\n");
}
-}
\ No newline at end of file
+}
--- a/jbig2_page.h
+++ /dev/null
@@ -1,33 +1,0 @@
-/*
- 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_page.h,v 1.1 2002/06/15 14:15:12 giles Exp $
-*/
-
-#ifndef JBIG2_PAGE_H
-#define JBIG2_PAGE_H
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-
-#include "jbig2dec.h"
-
-
-struct _Jbig2PageInfo {
- uint32_t height, width; /* in pixels */
- uint32_t x_resolution,
- y_resolution; /* in pixels per meter */
- uint16_t stripe_size;
- bool striped;
- uint8_t flags;
-};
-
-#endif /* JBIG2_PAGE_H */
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -18,6 +18,9 @@
typedef uint8_t byte;
typedef int bool;
+#define TRUE 1
+#define FALSE 0
+
typedef struct _Jbig2Result Jbig2Result;
/* The result of decoding a segment. See 0.1.5 */
--- 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.19 2002/06/15 14:12:50 giles Exp $
+ $Id: jbig2dec.c,v 1.20 2002/06/15 16:02:55 giles Exp $
*/
#include <stdio.h>
@@ -40,7 +40,6 @@
#ifdef DEAD_CODE
-
static Jbig2Ctx_foo *
jbig2_open (FILE *f)
--- a/jbig2dec.h
+++ /dev/null
@@ -1,59 +1,0 @@
-/*
- jbig2dec
-
- Copyright (c) 2002 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: jbig2dec.h,v 1.6 2002/02/19 07:09:16 giles Exp $
-*/
-
-#ifndef JBIG2DEC_H
-#define JBIG2DEC_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-
-typedef unsigned char byte;
-typedef int bool;
-typedef unsigned int uint32;
-typedef int int32;
-typedef short int16;
-typedef signed char int8;
-
-#define TRUE 1
-#define FALSE 0
-
-typedef struct _Jbig2Ctx_foo Jbig2Ctx_foo;
-
-int32
-get_bytes (Jbig2Ctx_foo *ctx, byte *buf, int size, int off);
-
-int16
-get_int16 (Jbig2Ctx_foo *ctx, int off);
-
-int32
-get_int32 (Jbig2Ctx_foo *ctx, int off);
-
-/* The word stream design is a compromise between simplicity and
- trying to amortize the number of method calls. Each ::get_next_word
- invocation pulls 4 bytes from the stream, packed big-endian into a
- 32 bit word. The offset argument is provided as a convenience. It
- begins at 0 and increments by 4 for each successive invocation. */
-typedef struct _Jbig2WordStream Jbig2WordStream;
-
-struct _Jbig2WordStream {
- uint32 (*get_next_word) (Jbig2WordStream *self, int offset);
-};
-
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* JBIG2DEC_H */