rev 403 - trunk
[email protected] Mon, 2 May 2005 19:25:09 -0700 (PDT)
| Newsgroups | gmane.comp.printing.ghostscript.jbig2dec.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: giles
Date: 2005-05-02 19:25:08 -0700 (Mon, 02 May 2005)
New Revision: 403
Modified:
trunk/jbig2_huffman.c
trunk/jbig2_huffman.h
trunk/jbig2_hufftab.h
Log:
Update the huffman decoder interface.
Move hufftab.h with the static table definitions to only be included once
from huffman.c.
Use the client-replaceable jbig2_alloc() instead of bare malloc().
Add a 'free' call for the huffman state. This just calls jbig2_free().
Modified: trunk/jbig2_huffman.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_huffman.c 2005-05-03 01:10:27 UTC (rev 402)
+++ trunk/jbig2_huffman.c 2005-05-03 02:25:08 UTC (rev 403)
@@ -1,7 +1,7 @@
/*
jbig2dec
=20
- Copyright (c) 2001 artofcode LLC.
+ Copyright (c) 2001-2005 artofcode LLC.
=20
This software is distributed under license and may not
be copied, modified or distributed except as expressly
@@ -13,7 +13,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
=20
- $Id: jbig2_huffman.c,v 1.11 2002/07/20 17:23:15 giles Exp $
+ $Id$
*/
=20
/* Huffman table decoding procedures=20
@@ -29,6 +29,7 @@
#include "jbig2.h"
#include "jbig2_priv.h"
#include "jbig2_huffman.h"
+#include "jbig2_hufftab.h"
=20
#define JBIG2_HUFFMAN_FLAGS_ISOOB 1
#define JBIG2_HUFFMAN_FLAGS_ISLOW 2
@@ -49,21 +50,40 @@
};
=20
=20
+/** Allocate and initialize a new huffman coding state
+ * the returned pointer can simply be freed; this does
+ * not affect the associated Jbig2WordStream.
+ */
Jbig2HuffmanState *
-jbig2_huffman_new (Jbig2WordStream *ws)
+jbig2_huffman_new (Jbig2Ctx *ctx, Jbig2WordStream *ws)
{
- Jbig2HuffmanState *result =3D (Jbig2HuffmanState *)malloc (sizeof(Jbig=
2HuffmanState));
+ Jbig2HuffmanState *result;
=20
- result->offset =3D 0;
- result->offset_bits =3D 0;
- result->this_word =3D ws->get_next_word (ws, 0);
- result->next_word =3D ws->get_next_word (ws, 4);
+ result =3D (Jbig2HuffmanState *)jbig2_alloc(ctx->allocator, =20
+ sizeof(Jbig2HuffmanState));
=20
- result->ws =3D ws;
+ if (result !=3D NULL) {
+ result->offset =3D 0;
+ result->offset_bits =3D 0;
+ result->this_word =3D ws->get_next_word (ws, 0);
+ result->next_word =3D ws->get_next_word (ws, 4);
=20
+ result->ws =3D ws;
+ }
+
return result;
}
=20
+/** Free an allocated huffman coding state.
+ * This just calls jbig2_free() if the pointer is not NULL
+ */
+void
+jbig2_huffman_free (Jbig2Ctx *ctx, Jbig2HuffmanState *hs)
+{
+ if (hs !=3D NULL) free(hs);
+ return;
+}
+
int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob)
@@ -145,7 +165,7 @@
#define LOG_TABLE_SIZE_MAX 8
=20
Jbig2HuffmanTable *
-jbig2_build_huffman_table (const Jbig2HuffmanParams *params)
+jbig2_build_huffman_table (Jbig2Ctx *ctx, const Jbig2HuffmanParams *para=
ms)
{
int LENCOUNT[256];
int LENMAX =3D -1;
@@ -180,9 +200,9 @@
if (lts <=3D LOG_TABLE_SIZE_MAX && log_table_size < lts)
log_table_size =3D lts;
}
- result =3D (Jbig2HuffmanTable *)malloc (sizeof(Jbig2HuffmanTable));
+ result =3D (Jbig2HuffmanTable *)jbig2_alloc(ctx->allocator, sizeof(Jbi=
g2HuffmanTable));
result->log_table_size =3D log_table_size;
- entries =3D (Jbig2HuffmanEntry *)malloc (sizeof(Jbig2HuffmanEntry) << =
log_table_size);
+ entries =3D (Jbig2HuffmanEntry *)jbig2_alloc(ctx->allocator, sizeof(Jb=
ig2HuffmanEntry) << log_table_size);
result->entries =3D entries;
=20
LENCOUNT[0] =3D 0;
Modified: trunk/jbig2_huffman.h
=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_huffman.h 2005-05-03 01:10:27 UTC (rev 402)
+++ trunk/jbig2_huffman.h 2005-05-03 02:25:08 UTC (rev 403)
@@ -1,7 +1,7 @@
/*
jbig2dec
=20
- Copyright (c) 2001 artofcode LLC.
+ Copyright (c) 2001-2005 artofcode LLC.
=20
This software is distributed under license and may not
be copied, modified or distributed except as expressly
@@ -13,17 +13,31 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
=20
- $Id: jbig2_huffman.h,v 1.4 2002/06/15 16:02:53 giles Exp $
+ $Id$
*/
=20
-#include "jbig2_hufftab.h"
+#ifndef JBIG2_HUFFMAN_H
+#define JBIG2_HUFFMAN_H
=20
+/* Huffman coder interface */
+
+typedef struct _Jbig2HuffmanEntry Jbig2HuffmanEntry;
+typedef struct _Jbig2HuffmanState Jbig2HuffmanState;
+typedef struct _Jbig2HuffmanTable Jbig2HuffmanTable;
+typedef struct _Jbig2HuffmanParams Jbig2HuffmanParams;
+
Jbig2HuffmanState *
-jbig2_huffman_new (Jbig2WordStream *ws);
+jbig2_huffman_new (Jbig2Ctx *ctx, Jbig2WordStream *ws);
=20
+void
+jbig2_huffman_free (Jbig2Ctx *ctx, Jbig2HuffmanState *hs);
+
int32_t
jbig2_huffman_get (Jbig2HuffmanState *hs,
const Jbig2HuffmanTable *table, bool *oob);
=20
Jbig2HuffmanTable *
-jbig2_build_huffman_table (const Jbig2HuffmanParams *params);
+jbig2_build_huffman_table (Jbig2Ctx *ctx,
+ const Jbig2HuffmanParams *params);
+
+#endif /* JBIG2_HUFFMAN_H */
Modified: trunk/jbig2_hufftab.h
=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_hufftab.h 2005-05-03 01:10:27 UTC (rev 402)
+++ trunk/jbig2_hufftab.h 2005-05-03 02:25:08 UTC (rev 403)
@@ -13,7 +13,7 @@
Artifex Software, Inc., 101 Lucas Valley Road #110,
San Rafael, CA 94903, U.S.A., +1(415)492-9861.
=20
- $Id: jbig2_hufftab.h,v 1.3 2002/06/15 16:02:54 giles Exp $
+ $Id$
*/
=20
/* predefined Huffman table definitions=20
@@ -22,10 +22,7 @@
#ifndef JBIG2_HUFFTAB_H
#define JBIG2_HUFFTAB_H
=20
-typedef struct _Jbig2HuffmanEntry Jbig2HuffmanEntry;
-typedef struct _Jbig2HuffmanState Jbig2HuffmanState;
-typedef struct _Jbig2HuffmanTable Jbig2HuffmanTable;
-typedef struct _Jbig2HuffmanParams Jbig2HuffmanParams;
+/* types are in jbig2_huffman.h, you must include that first */
=20
struct _Jbig2HuffmanEntry {
union {