ref: ed23b26857f9d5324a52730e7504c1a14a2d3161
parent: 22320087293f0de716d1e214ee74e1e1da822234
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Thu Jun 20 11:42:48 EDT 2002
Beginnings of text segment handling. Parse (most of) the text region segment header. Move the region segment info parser to jbig2_segment.c and jbig2_priv.h since this is shared by all region segment types. git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@75 ded80894-8fb9-0310-811b-c03f3676ab4d
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,4 @@
-# $Id: Makefile.am,v 1.3 2002/06/15 16:02:53 giles Exp $
+# $Id: Makefile.am,v 1.4 2002/06/20 15:42:47 giles Exp $
## process this file with automake to generate Makefile.in
lib_LIBRARIES = libjbig2dec.a
@@ -6,7 +6,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_symbol_dict.c jbig2_text.c \
jbig2_generic.c jbig2_mmr.c \
jbig2_image.c jbig2_image_pbm.c
--- 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.4 2002/04/25 23:24:08 raph Exp $
+ $Id: jbig2_generic.c,v 1.5 2002/06/20 15:42:47 giles Exp $
*/
/**
@@ -28,14 +28,6 @@
#include "jbig2_generic.h"
#include "jbig2_mmr.h"
-typedef struct {
- int32_t width;
- int32_t height;
- int32_t x;
- int32_t y;
- byte flags;
-} Jbig2RegionSegmentInfo;
-
static int
jbig2_decode_generic_template0(Jbig2Ctx *ctx,
int32_t seg_number,
@@ -358,18 +350,6 @@
"decode_generic_region: MMR=%d, GBTEMPLATE=%d NYI",
params->MMR, params->GBTEMPLATE);
return -1;
-}
-
-void
-jbig2_get_region_segment_info(Jbig2RegionSegmentInfo *info,
- const byte *segment_data)
-{
- /* 7.4.1 */
- info->width = jbig2_get_int32(segment_data);
- info->height = jbig2_get_int32(segment_data + 4);
- info->x = jbig2_get_int32(segment_data + 8);
- info->y = jbig2_get_int32(segment_data + 12);
- info->flags = segment_data[16];
}
int
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -108,6 +108,18 @@
int jbig2_read_page_info (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data);
int jbig2_complete_page (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data);
+/* region segment info */
+
+typedef struct {
+ int32_t width;
+ int32_t height;
+ int32_t x;
+ int32_t y;
+ byte flags;
+} Jbig2RegionSegmentInfo;
+
+void jbig2_get_region_segment_info(Jbig2RegionSegmentInfo *info, const byte *segment_data);
+int jbig2_read_text_info(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data);
/* The word stream design is a compromise between simplicity and
trying to amortize the number of method calls. Each ::get_next_word
--- a/jbig2_segment.c
+++ b/jbig2_segment.c
@@ -8,7 +8,7 @@
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
- $Id: jbig2_segment.c,v 1.4 2002/06/18 13:40:29 giles Exp $
+ $Id: jbig2_segment.c,v 1.5 2002/06/20 15:42:47 giles Exp $
*/
#include <stdio.h>
@@ -96,6 +96,18 @@
jbig2_free (ctx->allocator, sh);
}
+void
+jbig2_get_region_segment_info(Jbig2RegionSegmentInfo *info,
+ const byte *segment_data)
+{
+ /* 7.4.1 */
+ info->width = jbig2_get_int32(segment_data);
+ info->height = jbig2_get_int32(segment_data + 4);
+ info->x = jbig2_get_int32(segment_data + 8);
+ info->y = jbig2_get_int32(segment_data + 12);
+ info->flags = segment_data[16];
+}
+
int jbig2_write_segment (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
const uint8_t *segment_data)
{
@@ -114,8 +126,7 @@
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
"unhandled segment type 'immediate text region'");
case 7:
- return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
- "unhandled segment type 'immediate lossless text region'");
+ return jbig2_read_text_info(ctx, sh, segment_data);
case 16:
return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
"unhandled segment type 'pattern dictionary'");
--- 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.4 2002/06/15 14:12:50 giles Exp $
+ $Id: jbig2_symbol_dict.c,v 1.5 2002/06/20 15:42:48 giles Exp $
*/
#include <stddef.h>
@@ -114,7 +114,7 @@
/* SDHUFFBMSIZE */
/* SDHUFFAGGINST */
int SDTEMPLATE;
- int8_t sdat[8];
+ int8_t sdat[8]; // FIXME: do these need to be explicitly signed?
bool SDRTEMPLATE;
int8_t sdrat[4];
} Jbig2SymbolDictParams;
@@ -259,8 +259,11 @@
params.SDTEMPLATE = (flags >> 10) & 3;
params.SDRTEMPLATE = (flags >> 12) & 1;
- if (params.SDHUFF)
+ if (params.SDHUFF) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+ "symbol dictionary uses the Huffman encoding variant (NYI)");
return 0;
+ }
/* FIXME: there are quite a few of these conditions to check */
/* maybe #ifdef CONFORMANCE and a separate routine */
@@ -275,6 +278,12 @@
"SDHUFF is zero, but contrary to spec SDHUFFDW is not.");
}
+ if (flags & 0x0080)
+ {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+ "bitmap coding context is used (NYI) symbol data likely to be garbage!");
+ }
+
/* 7.4.2.1.2 */
sdat_bytes = params.SDHUFF ? 0 : params.SDTEMPLATE == 0 ? 8 : 2;
memcpy(params.sdat, segment_data + 2, sdat_bytes);
@@ -309,6 +318,12 @@
params.SDTEMPLATE == 1 ? 8192 : 1024;
GB_stats = jbig2_alloc(ctx->allocator, stats_size);
memset(GB_stats, 0, stats_size);
+ }
+
+ if (flags & 0x0100)
+ {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+ "segment marks bitmap coding context as retained (NYI)");
}
return jbig2_decode_symbol_dict(ctx, sh->segment_number,
--- /dev/null
+++ b/jbig2_text.c
@@ -1,0 +1,78 @@
+/*
+ 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: jbig2_text.c,v 1.1 2002/06/20 15:42:48 giles Exp $
+*/
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "jbig2.h"
+#include "jbig2_priv.h"
+#include "jbig2_arith.h"
+#include "jbig2_arith_int.h"
+#include "jbig2_generic.h"
+#include "jbig2_symbol_dict.h"
+
+/**
+ * jbig2_read_text_info: read a text region segment header
+ **/
+int
+jbig2_read_text_info(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data)
+{
+ int offset = 0;
+ Jbig2RegionSegmentInfo region_info;
+ uint32_t num_instances;
+ uint16_t segment_flags;
+ uint16_t huffman_flags;
+ int8_t sbrat[4]; /* FIXME: needs to be explicitly signed? */
+
+ /* 7.4.1 */
+ jbig2_get_region_segment_info(®ion_info, segment_data);
+ offset += 17;
+
+ /* 7.4.3.1.1 */
+ segment_flags = jbig2_get_int16(segment_data + offset);
+ offset += 2;
+
+ if (segment_flags & 1) /* Huffman coding */
+ {
+ /* 7.4.3.1.2 */
+ huffman_flags = jbig2_get_int16(segment_data + offset);
+ offset += 2;
+ }
+ else /* arithmetic coding */
+ {
+ /* 7.4.3.1.3 */
+ if ((segment_flags & 0x02) && !(segment_flags & 0x80)) /* SBREFINE & !SBRTEMPLATE */
+ {
+ sbrat[0] = segment_data[offset];
+ sbrat[0] = segment_data[offset + 1];
+ sbrat[0] = segment_data[offset + 2];
+ sbrat[0] = segment_data[offset + 3];
+ offset += 4;
+ }
+
+ /* 7.4.3.1.4 */
+ num_instances = jbig2_get_int32(segment_data + offset);
+ offset += 4;
+
+ /* 7.4.3.1.7 */
+ if (segment_flags & 0x01) {
+ jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+ "symbol id huffman table decoding NYI");
+ }
+
+ jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+ "text region: %d x %d @ (%d,%d) %d symbols",
+ region_info.width, region_info.height,
+ region_info.x, region_info.y, num_instances);
+ }
+}
\ No newline at end of file