Update of /cvsroot/jbig2dec/jbig2dec
In directory usw-pr-cvs1:/tmp/cvs-serv14513
Modified Files:
Makefile.am jbig2_generic.c jbig2_priv.h jbig2_segment.c
jbig2_symbol_dict.c
Added Files:
jbig2_text.c
Log Message:
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.
--- NEW FILE: jbig2_text.c ---
/*
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);
}
}
Index: Makefile.am
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/Makefile.am,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Makefile.am 15 Jun 2002 16:02:53 -0000 1.3
+++ Makefile.am 20 Jun 2002 15:42:47 -0000 1.4
@@ -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
Index: jbig2_generic.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_generic.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jbig2_generic.c 25 Apr 2002 23:24:08 -0000 1.4
+++ jbig2_generic.c 20 Jun 2002 15:42:47 -0000 1.5
@@ -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
Index: jbig2_priv.h
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_priv.h,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- jbig2_priv.h 18 Jun 2002 13:40:29 -0000 1.5
+++ jbig2_priv.h 20 Jun 2002 15:42:47 -0000 1.6
@@ -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
Index: jbig2_segment.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_segment.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jbig2_segment.c 18 Jun 2002 13:40:29 -0000 1.4
+++ jbig2_segment.c 20 Jun 2002 15:42:47 -0000 1.5
@@ -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'");
Index: jbig2_symbol_dict.c
===================================================================
RCS file: /cvsroot/jbig2dec/jbig2dec/jbig2_symbol_dict.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- jbig2_symbol_dict.c 15 Jun 2002 14:12:50 -0000 1.4
+++ jbig2_symbol_dict.c 20 Jun 2002 15:42:48 -0000 1.5
@@ -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,
|