ref: fcc43c7fb7d236c2c30a2b9eba5fdd52bb84f56a
parent: 468a9f35baa5c64f3be49f60ba800f72dba501ef
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Mon Jun 24 11:51:57 EDT 2002
checkpointing work on text region decoder. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@88 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/jbig2_generic.c
+++ b/jbig2_generic.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_generic.c,v 1.8 2002/06/22 16:05:45 giles Exp $
+ $Id: jbig2_generic.c,v 1.9 2002/06/24 15:51:57 giles Exp $
*/
/**
@@ -437,7 +437,8 @@
/* todo: free ws, as */
- jbig2_image_compose(ctx, ctx->pages[ctx->current_page].image, image, rsi.x, rsi.y);
+ jbig2_image_compose(ctx, ctx->pages[ctx->current_page].image, image,
+ rsi.x, rsi.y, JBIG2_COMPOSE_OR);
jbig2_image_free(ctx, image);
jbig2_free(ctx->allocator, GB_stats);
--- a/jbig2_image.c
+++ b/jbig2_image.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.c,v 1.6 2002/06/21 19:10:02 giles Exp $
+ $Id: jbig2_image.c,v 1.7 2002/06/24 15:51:57 giles Exp $
*/
#include <stdio.h>
@@ -58,8 +58,8 @@
}
/* composite one jbig2_image onto another */
-// FIXME: need to add a drawing mode argument
-int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y)
+int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src,
+ int x, int y, Jbig2ComposeOp op)
{
/* special case complete replacement */
if ((x == 0) && (y == 0) && (src->width == dst->width) && (src->height == dst->height)) {
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_priv.h,v 1.8 2002/06/22 16:05:45 giles Exp $
+ $Id: jbig2_priv.h,v 1.9 2002/06/24 15:51:57 giles Exp $
shared library internals
*/
@@ -109,7 +109,14 @@
int jbig2_read_page_info (Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data);
int jbig2_complete_page (Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data);
-int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y);
+typedef enum {
+ JBIG2_COMPOSE_OR,
+ JBIG2_COMPOSE_AND,
+ JBIG2_COMPOSE_XOR,
+ JBIG2_COMPOSE_XNOR
+} Jbig2ComposeOp;
+
+int jbig2_image_compose(Jbig2Ctx *ctx, Jbig2Image *dst, Jbig2Image *src, int x, int y, Jbig2ComposeOp op);
/* region segment info */
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_symbol_dict.c,v 1.11 2002/06/22 21:20:38 giles Exp $
+ $Id: jbig2_symbol_dict.c,v 1.12 2002/06/24 15:51:57 giles Exp $
symbol dictionary segment decode and support
*/
@@ -290,7 +290,7 @@
segment->data_length - offset,
GB_stats);
#ifdef HAVE_LIBPNG
- jbig2_dump_symbol_dict(segment->result);
+// jbig2_dump_symbol_dict(segment->result);
#endif
return 0;
--- a/jbig2_text.c
+++ b/jbig2_text.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_text.c,v 1.2 2002/06/22 16:05:45 giles Exp $
+ $Id: jbig2_text.c,v 1.3 2002/06/24 15:51:57 giles Exp $
*/
#include <stddef.h>
@@ -21,6 +21,49 @@
#include "jbig2_generic.h"
#include "jbig2_symbol_dict.h"
+typedef enum {
+ JBIG2_CORNER_BOTTOMLEFT = 0,
+ JBIG2_CORNER_TOPLEFT = 1,
+ JBIG2_CORNER_BOTTOMRIGHT = 2,
+ JBIG2_CORNER_TOPRIGHT = 3
+} Jbig2RefCorner;
+
+typedef struct {
+ bool SBHUFF;
+ bool SBREFINE;
+ bool SBDEFPIXEL;
+ Jbig2ComposeOp SBCOMBOP;
+ bool TRANSPOSED;
+ Jbig2RefCorner REFCORNER;
+ int SBDOFFSET;
+ /* SBW */
+ /* SBH */
+ uint32_t SBNUMINSTANCES;
+ int SBSTRIPS;
+ /* SBNUMSYMS */
+ int *SBSYMCODES;
+ /* SBSYMCODELEN */
+ /* SBSYMS */
+ int SBHUFFFS;
+ int SBHUFFDS;
+ int SBHUFFDT;
+ int SBHUFFRDW;
+ int SBHUFFRDH;
+ int SBHUFFRDX;
+ int SBHUFFRDY;
+ bool SBHUFFRSIZE;
+ bool SBRTEMPLATE;
+ int8_t sbrat[4];
+} Jbig2TextRegionParams;
+
+int jbig2_decode_text_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
+ const Jbig2TextRegionParams *params,
+ const Jbig2RegionSegmentInfo *info,
+ Jbig2Image *image,
+ const byte *data, size_t size)
+{
+}
+
/**
* jbig2_read_text_info: read a text region segment header
**/
@@ -29,12 +72,17 @@
{
int offset = 0;
Jbig2RegionSegmentInfo region_info;
+ Jbig2TextRegionParams params;
+ Jbig2Image *image, *page_image;
+ int code;
uint32_t num_instances;
uint16_t segment_flags;
uint16_t huffman_flags;
- int8_t sbrat[4]; /* FIXME: needs to be explicitly signed? */
+ int8_t sbrat[4];
/* 7.4.1 */
+ if (segment->data_length < 17)
+ goto too_short;
jbig2_get_region_segment_info(®ion_info, segment_data);
offset += 17;
@@ -42,7 +90,7 @@
segment_flags = jbig2_get_int16(segment_data + offset);
offset += 2;
- if (segment_flags & 1) /* Huffman coding */
+ if (segment_flags & 0x01) /* Huffman coding */
{
/* 7.4.3.1.2 */
huffman_flags = jbig2_get_int16(segment_data + offset);
@@ -75,4 +123,24 @@
region_info.width, region_info.height,
region_info.x, region_info.y, num_instances);
}
+
+ page_image = ctx->pages[ctx->current_page].image;
+ image = jbig2_image_new(ctx, region_info.width, region_info.height);
+
+ code = jbig2_decode_text_region(ctx, segment, ¶ms,
+ ®ion_info, image,
+ segment_data + offset, segment->data_length - offset);
+
+ /* todo: check errors */
+
+ jbig2_image_compose(ctx, page_image, image, region_info.x, region_info.y, JBIG2_COMPOSE_OR);
+ if (image != page_image)
+ jbig2_image_free(ctx, image);
+
+ /* success */
+ return 0;
+
+ too_short:
+ return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
+ "Segment too short");
}
\ No newline at end of file