shithub: jbig2

Download patch

ref: f2ac7803db2d376bab0734f3e7629faea7bc7297
parent: 7fc72d14be2af5e15866a9124a99b6dafea65dcd
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Sat Jun 22 12:05:45 EDT 2002

Gratuitous renaming. Promote the segment header to Jbig2Segment and use it
to store intermediate results rather than the results objects raph had sketched.


git-svn-id: http://svn.ghostscript.com/jbig2dec/trunk@84 ded80894-8fb9-0310-811b-c03f3676ab4d

--- a/jbig2.c
+++ b/jbig2.c
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
         
-    $Id: jbig2.c,v 1.8 2002/06/18 13:40:29 giles Exp $
+    $Id: jbig2.c,v 1.9 2002/06/22 16:05:45 giles Exp $
 */
 
 #include <stdint.h>
@@ -109,17 +109,14 @@
     JBIG2_FILE_HEADER;
 
   result->buf = NULL;
-  result->sh_list = NULL;
-  result->n_sh = 0;
-  result->n_sh_max = 1;
-  result->sh_ix = 0;
+  
+  result->n_segments = 0;
+  result->n_segments_max = 16;
+  result->segments = (Jbig2Segment **)jbig2_alloc(allocator, result->n_segments_max * sizeof(Jbig2Segment *));
+  result->segment_index = 0;
 
-  result->n_results = 0;
-  result->n_results_max = 16;
-  result->results = (const Jbig2Result **)jbig2_alloc(allocator, result->n_results_max * sizeof(Jbig2Result *));
-
   result->current_page = 0;
-  result->max_page_index = 16;
+  result->max_page_index = 4;
   result->pages = (Jbig2Page *)jbig2_alloc(allocator, result->max_page_index * sizeof(Jbig2Page));
   {
     int index;
@@ -208,7 +205,7 @@
   for (;;)
     {
       const byte jbig2_id_string[8] = { 0x97, 0x4a, 0x42, 0x32, 0x0d, 0x0a, 0x1a, 0x0a };
-      Jbig2SegmentHeader *sh;
+      Jbig2Segment *segment;
       size_t header_size;
       int code;
 
@@ -224,7 +221,7 @@
           /* D.4.2 */
 	  ctx->file_header_flags = ctx->buf[ctx->buf_rd_ix + 8];
           /* D.4.3 */
-	  if (!(ctx->file_header_flags & 2))
+	  if (!(ctx->file_header_flags & 2)) /* number of pages is known */
 	    {
 	      if (ctx->buf_wr_ix - ctx->buf_rd_ix < 13)
 		return 0;
@@ -236,7 +233,10 @@
 	      ctx->buf_rd_ix += 13;
 	    }
 	  else
-	    ctx->buf_rd_ix += 9;
+            {
+              ctx->n_pages=0;
+	      ctx->buf_rd_ix += 9;
+            }
           /* determine the file organization based on the flags - D.4.2 again */
 	  if (ctx->file_header_flags & 1)
 	    {
@@ -245,32 +245,25 @@
 	  else
 	    {
 	      ctx->state = JBIG2_FILE_RANDOM_HEADERS;
-	      ctx->n_sh_max = 16;
-	    }
+            }
 	  break;
 	case JBIG2_FILE_SEQUENTIAL_HEADER:
 	case JBIG2_FILE_RANDOM_HEADERS:
-	  sh = jbig2_parse_segment_header(ctx, ctx->buf + ctx->buf_rd_ix,
+	  segment = jbig2_parse_segment_header(ctx, ctx->buf + ctx->buf_rd_ix,
 					  ctx->buf_wr_ix - ctx->buf_rd_ix,
 					  &header_size);
-	  if (sh == NULL)
+	  if (segment == NULL)
 	    return 0;
 	  ctx->buf_rd_ix += header_size;
 
-	  if (ctx->sh_list == NULL)
-	      ctx->sh_list = jbig2_alloc(ctx->allocator, ctx->n_sh_max *
-				     sizeof(Jbig2SegmentHeader *));
-	  else if (ctx->n_sh == ctx->n_sh_max)
-	    /* Note to rillian: I usually define a macro to make this
-	       less ungainly. */
-	    ctx->sh_list = (Jbig2SegmentHeader **)jbig2_realloc(ctx->allocator,
-								ctx->sh_list,
-								(ctx->n_sh_max <<= 2) * sizeof(Jbig2SegmentHeader *));
+	  if (ctx->n_segments == ctx->n_segments_max)
+	    ctx->segments = (Jbig2Segment **)jbig2_realloc(ctx->allocator,
+                ctx->segments, (ctx->n_segments_max <<= 2) * sizeof(Jbig2Segment *));
 
-	  ctx->sh_list[ctx->n_sh++] = sh;
+	  ctx->segments[ctx->n_segments++] = segment;
 	  if (ctx->state == JBIG2_FILE_RANDOM_HEADERS)
 	    {
-	      if ((sh->flags & 63) == 51) /* end of file */
+	      if ((segment->flags & 63) == 51) /* end of file */
 		ctx->state = JBIG2_FILE_RANDOM_BODIES;
 	    }
 	  else /* JBIG2_FILE_SEQUENTIAL_HEADER */
@@ -278,22 +271,22 @@
 	  break;
 	case JBIG2_FILE_SEQUENTIAL_BODY:
 	case JBIG2_FILE_RANDOM_BODIES:
-	  sh = ctx->sh_list[ctx->sh_ix];
-	  if (sh->data_length > ctx->buf_wr_ix - ctx->buf_rd_ix)
+	  segment = ctx->segments[ctx->segment_index];
+	  if (segment->data_length > ctx->buf_wr_ix - ctx->buf_rd_ix)
 	    return 0;
-	  code = jbig2_write_segment(ctx, sh, ctx->buf + ctx->buf_rd_ix);
-	  ctx->buf_rd_ix += sh->data_length;
-	  jbig2_free_segment_header(ctx, sh);
-	  ctx->sh_list[ctx->sh_ix] = NULL;
+	  code = jbig2_write_segment(ctx, segment, ctx->buf + ctx->buf_rd_ix);
+	  ctx->buf_rd_ix += segment->data_length;
+	  jbig2_free_segment(ctx, segment);
+	  ctx->segments[ctx->segment_index] = NULL;
 	  if (ctx->state == JBIG2_FILE_RANDOM_BODIES)
 	    {
-	      ctx->sh_ix++;
-	      if (ctx->sh_ix == ctx->n_sh)
+	      ctx->segment_index++;
+	      if (ctx->segment_index == ctx->n_segments)
 		ctx->state = JBIG2_FILE_EOF;
 	    }
 	  else /* JBIG2_FILE_SEQUENCIAL_BODY */
 	    {
-	      ctx->n_sh = 0;
+	      ctx->n_segments = 0;
 	      ctx->state = JBIG2_FILE_SEQUENTIAL_HEADER;
 	    }
 	  if (code < 0)
@@ -320,22 +313,15 @@
   uint32_t seg_ix;
 
   jbig2_free(ca, ctx->buf);
-  if (ctx->sh_list != NULL)
+  if (ctx->segments != NULL)
     {
-      for (i = ctx->sh_ix; i < ctx->n_sh; i++)
-	jbig2_free_segment_header(ctx, ctx->sh_list[i]);
-      jbig2_free(ca, ctx->sh_list);
+      for (i = ctx->segment_index; i < ctx->n_segments; i++)
+	jbig2_free_segment(ctx, ctx->segments[i]);
+      jbig2_free(ca, ctx->segments);
     }
 
-  for (seg_ix = 0; seg_ix < ctx->n_results; seg_ix++)
-    {
-      const Jbig2Result *result = ctx->results[seg_ix];
+  /* todo: free pages */
 
-      if (result)
-	result->free(result, ctx);
-    }
-  jbig2_free(ca, ctx->results);
-
   jbig2_free(ca, ctx);
 }
 
@@ -350,56 +336,16 @@
 }
 
 
-const Jbig2Result *
-jbig2_get_result(Jbig2Ctx *ctx, int32_t segment_number)
-{
-  if (segment_number < 0 || segment_number >= ctx->n_results)
-    {
-      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment_number,
-		  "Attempting to get invalid segment number");
-      return NULL;
-    }
-  return ctx->results[segment_number];
-}
+/* I'm not committed to keeping the word stream interface. It's handy
+   when you think you may be streaming your input, but if you're not
+   (as is currently the case), it just adds complexity.
+*/
 
-int
-jbig2_put_result(Jbig2Ctx *ctx, const Jbig2Result *result)
-{
-  int32_t segment_number = result->segment_number;
-  int32_t i;
-
-  if (ctx->n_results_max <= segment_number)
-    {
-      const Jbig2Result **new_results;
-      do
-	ctx->n_results_max <<= 1;
-      while (ctx->n_results_max <= segment_number);
-      new_results = (const Jbig2Result **)jbig2_realloc(ctx->allocator,
-							  ctx->results,
-							  ctx->n_results_max * sizeof(Jbig2Result *));
-      if (new_results == NULL)
-	return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment_number,
-			   "Allocation failure");
-      ctx->results = new_results;
-    }
-  for (i = ctx->n_results; i < segment_number; i++)
-    ctx->results[i] = NULL;
-  ctx->results[segment_number] = result;
-  if (ctx->n_results < segment_number + 1)
-    ctx->n_results = segment_number + 1;
-  return 0;
-}
-
 typedef struct {
   Jbig2WordStream super;
   const byte *data;
   size_t size;
 } Jbig2WordStreamBuf;
-
-/* I'm not committed to keeping the word stream interface. It's handy
-   when you think you may be streaming your input, but if you're not
-   (as is currently the case), it just adds complexity.
-*/
 
 static uint32_t
 jbig2_word_stream_buf_get_next_word(Jbig2WordStream *self, int offset)
--- 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.8 2002/06/21 19:10:02 giles Exp $
+    $Id: jbig2.h,v 1.9 2002/06/22 16:05:45 giles Exp $
 */
 
 #ifdef __cplusplus
@@ -33,7 +33,7 @@
 typedef struct _Jbig2Allocator Jbig2Allocator;
 typedef struct _Jbig2Ctx Jbig2Ctx;
 typedef struct _Jbig2GlobalCtx Jbig2GlobalCtx;
-typedef struct _Jbig2SegmentHeader Jbig2SegmentHeader;
+typedef struct _Jbig2Segment Jbig2Segment;
 typedef struct _Jbig2Image Jbig2Image;
 
 /* private structures */
@@ -90,19 +90,21 @@
 
 /* segment header routines */
 
-struct _Jbig2SegmentHeader {
-  int32_t segment_number;
+struct _Jbig2Segment {
+  uint32_t number;
   uint8_t flags;
-  int referred_to_segment_count;
-  int32_t page_association;
+  uint32_t page_association;
   int data_length;
+  int referred_to_segment_count;
+  int32_t *referred_to_segments;
+  void *result;
 };
 
-Jbig2SegmentHeader *jbig2_parse_segment_header (Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size,
+Jbig2Segment *jbig2_parse_segment_header (Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size,
 			    size_t *p_header_size);
-int jbig2_write_segment (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
+int jbig2_write_segment (Jbig2Ctx *ctx, Jbig2Segment *segment,
 			 const uint8_t *segment_data);
-void jbig2_free_segment_header (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh);
+void jbig2_free_segment (Jbig2Ctx *ctx, Jbig2Segment *segment);
 
 #ifdef __cplusplus
 }
--- 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.7 2002/06/22 09:47:31 giles Exp $
+    $Id: jbig2_generic.c,v 1.8 2002/06/22 16:05:45 giles Exp $
 */
 
 /**
@@ -28,7 +28,7 @@
 
 static int
 jbig2_decode_generic_template0(Jbig2Ctx *ctx,
-			       int32_t seg_number,
+			       Jbig2Segment *segment,
 			       const Jbig2GenericRegionParams *params,
 			       Jbig2ArithState *as,
 			       Jbig2Image *image,
@@ -97,7 +97,7 @@
 
 static int
 jbig2_decode_generic_template1(Jbig2Ctx *ctx,
-			       int32_t seg_number,
+			       Jbig2Segment *segment,
 			       const Jbig2GenericRegionParams *params,
 			       Jbig2ArithState *as,
 			       Jbig2Image *image,
@@ -166,7 +166,7 @@
 
 static int
 jbig2_decode_generic_template2(Jbig2Ctx *ctx,
-			       int32_t seg_number,
+			       Jbig2Segment *segment,
 			       const Jbig2GenericRegionParams *params,
 			       Jbig2ArithState *as,
 			       Jbig2Image *image,
@@ -235,7 +235,7 @@
 
 static int
 jbig2_decode_generic_template2a(Jbig2Ctx *ctx,
-			       int32_t seg_number,
+			       Jbig2Segment *segment,
 			       const Jbig2GenericRegionParams *params,
 			       Jbig2ArithState *as,
 			       Jbig2Image *image,
@@ -322,7 +322,7 @@
  **/
 int
 jbig2_decode_generic_region(Jbig2Ctx *ctx,
-			    int32_t seg_number,
+			    Jbig2Segment *segment,
 			    const Jbig2GenericRegionParams *params,
 			    Jbig2ArithState *as,
 			    Jbig2Image *image,
@@ -329,19 +329,19 @@
 			    Jbig2ArithCx *GB_stats)
 {
   if (!params->MMR && params->GBTEMPLATE == 0)
-    return jbig2_decode_generic_template0(ctx, seg_number,
-					  params, as, image, GB_stats);
+    return jbig2_decode_generic_template0(ctx, segment, params,
+                                          as, image, GB_stats);
   else if (!params->MMR && params->GBTEMPLATE == 1)
-    return jbig2_decode_generic_template1(ctx, seg_number,
-					  params, as, image, GB_stats);
+    return jbig2_decode_generic_template1(ctx, segment, params,
+					  as, image, GB_stats);
   else if (!params->MMR && params->GBTEMPLATE == 2)
     {
       if (params->gbat[0] == 3 && params->gbat[1] == 255)
-	return jbig2_decode_generic_template2a(ctx, seg_number,
-					       params, as, image, GB_stats);
+	return jbig2_decode_generic_template2a(ctx, segment, params,
+					       as, image, GB_stats);
       else
-	return jbig2_decode_generic_template2(ctx, seg_number,
-					       params, as, image, GB_stats);
+	return jbig2_decode_generic_template2(ctx, segment, params,
+                                              as, image, GB_stats);
     }
   {
     int i;
@@ -348,7 +348,7 @@
     for (i = 0; i < 8; i++)
       printf ("gbat[%d] = %d\n", i, params->gbat[i]);
   }
-  jbig2_error(ctx, JBIG2_SEVERITY_WARNING, seg_number,
+  jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
 	      "decode_generic_region: MMR=%d, GBTEMPLATE=%d NYI",
 	      params->MMR, params->GBTEMPLATE);
   return -1;
@@ -355,7 +355,7 @@
 }
 
 int
-jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
+jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
 			       const uint8_t *segment_data)
 {
   Jbig2RegionSegmentInfo rsi;
@@ -371,22 +371,21 @@
   Jbig2ArithCx *GB_stats = NULL;
 
   /* 7.4.6 */
-  if (sh->data_length < 18)
-    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, sh->segment_number,
+  if (segment->data_length < 18)
+    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 		       "Segment too short");
 
   jbig2_get_region_segment_info(&rsi, segment_data);
-  jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+  jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
 	      "generic region: %d x %d @ (%d, %d), flags = %02x",
 	      rsi.width, rsi.height, rsi.x, rsi.y, rsi.flags);
 
   /* 7.4.6.2 */
   seg_flags = segment_data[17];
-  jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
-	      "segment flags = %02x",
-	      seg_flags);
+  jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
+	      "segment flags = %02x", seg_flags);
   if ((seg_flags & 1) && (seg_flags & 6))
-    jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+    jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
 		"MMR is 1, but GBTEMPLATE is not 0");
 
   /* 7.4.6.3 */
@@ -393,11 +392,11 @@
   if (!(seg_flags & 1))
     {
       gbat_bytes = (seg_flags & 6) ? 2 : 8;
-      if (18 + gbat_bytes > sh->data_length)
-	return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, sh->segment_number,
+      if (18 + gbat_bytes > segment->data_length)
+	return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 			   "Segment too short");
       memcpy(gbat, segment_data + 18, gbat_bytes);
-      jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+      jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
 		  "gbat: %d, %d", gbat[0], gbat[1]);
     }
 
@@ -411,14 +410,14 @@
   memcpy (params.gbat, gbat, gbat_bytes);
 
   image = jbig2_image_new(ctx, rsi.width, rsi.height);
-  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, sh->segment_number,
+  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
     "allocated %d x %d image buffer for region decode results",
         rsi.width, rsi.height);
     
   if (params.MMR)
     {
-      code = jbig2_decode_generic_mmr(ctx, sh->segment_number, &params,
-				      segment_data + offset, sh->data_length - offset,
+      code = jbig2_decode_generic_mmr(ctx, segment, &params,
+				      segment_data + offset, segment->data_length - offset,
 				      image);
     }
   else
@@ -430,9 +429,9 @@
 
       ws = jbig2_word_stream_buf_new(ctx,
 				     segment_data + offset,
-				     sh->data_length - offset);
+				     segment->data_length - offset);
       as = jbig2_arith_new(ctx, ws);
-      code = jbig2_decode_generic_region(ctx, sh->segment_number, &params,
+      code = jbig2_decode_generic_region(ctx, segment, &params,
 					 as, image, GB_stats);
     }
 
--- a/jbig2_generic.h
+++ b/jbig2_generic.h
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
         
-    $Id: jbig2_generic.h,v 1.5 2002/06/22 09:47:31 giles Exp $
+    $Id: jbig2_generic.h,v 1.6 2002/06/22 16:05:45 giles Exp $
 */
 
 /* Table 2 */
@@ -26,7 +26,7 @@
 /* 6.2 */
 int
 jbig2_decode_generic_region(Jbig2Ctx *ctx,
-			    int32_t seg_number,
+			    Jbig2Segment *segment,
 			    const Jbig2GenericRegionParams *params,
 			    Jbig2ArithState *as,
 			    Jbig2Image *image,
@@ -34,6 +34,6 @@
 
 /* 7.4 */
 int
-jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
+jbig2_immediate_generic_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
 			       const uint8_t *segment_data);
 
--- a/jbig2_mmr.c
+++ b/jbig2_mmr.c
@@ -792,7 +792,7 @@
 
 int
 jbig2_decode_generic_mmr(Jbig2Ctx *ctx,
-			 int32_t seg_number,
+			 Jbig2Segment *segment,
 			 const Jbig2GenericRegionParams *params,
 			 const byte *data, size_t size,
 			 Jbig2Image *image)
--- a/jbig2_mmr.h
+++ b/jbig2_mmr.h
@@ -1,6 +1,6 @@
 int
 jbig2_decode_generic_mmr(Jbig2Ctx *ctx,
-			 int32_t seg_number,
+			 Jbig2Segment *segment,
 			 const Jbig2GenericRegionParams *params,
 			 const byte *data, size_t size,
 			 Jbig2Image *image);
--- 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.5 2002/06/21 19:10:02 giles Exp $
+    $Id: jbig2_page.c,v 1.6 2002/06/22 16:05:45 giles Exp $
 */
 
 #include <stdio.h>
@@ -23,25 +23,25 @@
 
 /* dump the page struct info */
 static void
-dump_page_info(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, Jbig2Page *page)
+dump_page_info(Jbig2Ctx *ctx, Jbig2Segment *segment, Jbig2Page *page)
 {
     if (page->x_resolution == 0) {
-        jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
             "page %d image is %dx%d (unknown res)", page->number,
             page->width, page->height);
     } else if (page->x_resolution == page->y_resolution) {
-        jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
             "page %d image is %dx%d (%d ppm)", page->number,
             page->width, page->height,
             page->x_resolution);
     } else {
-        jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
             "page %d image is %dx%d (%dx%d ppm)", page->number,
             page->width, page->height,
             page->x_resolution, page->y_resolution);
     }
     if (page->striped) {
-        jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
             "\tmaximum stripe size: %d", page->stripe_size);
     }
 }
@@ -54,7 +54,7 @@
  * buffer for the page (or the first stripe)
  **/
 int
-jbig2_read_page_info (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data)
+jbig2_read_page_info (Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
 {
     Jbig2Page *page;
 
@@ -63,7 +63,7 @@
     if ((page->number != 0) &&
             ((page->state == JBIG2_PAGE_NEW) || (page->state == JBIG2_PAGE_FREE))) {
         page->state = JBIG2_PAGE_COMPLETE;
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
             "unexpected page info segment, marking previous page finished");
     }
         
@@ -88,12 +88,12 @@
         page = &(ctx->pages[index]);
         ctx->current_page = index;
         page->state = JBIG2_PAGE_NEW;
-        page->number = sh->page_association;
+        page->number = segment->page_association;
     }
     
     // FIXME: would be nice if we tried to work around this
-    if (sh->data_length < 19) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, sh->segment_number,
+    if (segment->data_length < 19) {
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
             "segment too short");
         return NULL;
     }
@@ -118,17 +118,17 @@
         }
     }
     if (page->height == 0xFFFFFFFF && page->striped == FALSE) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
             "height is unspecified but page is not markes as striped");
         page->striped = TRUE;
     }
     
-    if (sh->data_length > 19) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+    if (segment->data_length > 19) {
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
             "extra data in segment");
     }
     
-    dump_page_info(ctx, sh, page);
+    dump_page_info(ctx, segment, page);
 
     /* allocate an approprate page image buffer */
     /* 7.4.8.2 */
@@ -138,12 +138,12 @@
         page->image = jbig2_image_new(ctx, page->width, page->height);
     }
     if (page->image == NULL) {
-        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
             "failed to allocate buffer for page image");
         jbig2_free(ctx->allocator, page);
         return NULL;
     } else {
-        jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
             "allocated %dx%d page image (%d bytes)",
             page->image->width, page->image->height,
             page->image->stride*page->image->height);
@@ -160,18 +160,18 @@
  * of the page image will also happen from here (NYI)
  **/
 int
-jbig2_complete_page (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data)
+jbig2_complete_page (Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
 {
     uint32_t page_number = ctx->pages[ctx->current_page].number;
     
-    if (sh->page_association != page_number) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+    if (segment->page_association != page_number) {
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
             "end of page marker for page %d doesn't match current page number %d",
-            sh->page_association, page_number);
+            segment->page_association, page_number);
     }
     
     ctx->pages[ctx->current_page].state = JBIG2_PAGE_COMPLETE;
-    jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+    jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
         "end of page %d", page_number);
 
 #ifdef OUTPUT_PBM
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -1,20 +1,18 @@
-void *
-jbig2_alloc (Jbig2Allocator *allocator, size_t size);
+/*
+    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_priv.h,v 1.8 2002/06/22 16:05:45 giles Exp $
+    
+    shared library internals
+*/
 
-void
-jbig2_free (Jbig2Allocator *allocator, void *p);
-
-void *
-jbig2_realloc (Jbig2Allocator *allocator, void *p, size_t size);
-
-#define jbig2_new(ctx, t, size) ((t *)jbig2_alloc(ctx->allocator, (size) * sizeof(t)))
-
-#define jbig2_renew(ctx, p, t, size) ((t *)jbig2_realloc(ctx->allocator, (p), (size) * sizeof(t)))
-
-int
-jbig2_error (Jbig2Ctx *ctx, Jbig2Severity severity, int32_t seg_idx,
-	     const char *fmt, ...);
-
 typedef uint8_t byte;
 typedef int bool;
 
@@ -21,15 +19,6 @@
 #define TRUE 1
 #define FALSE 0
 
-typedef struct _Jbig2Result Jbig2Result;
-
-/* The result of decoding a segment. See 0.1.5 */
-struct _Jbig2Result {
-  int32_t segment_number;
-  int segment_type;
-  void (*free)(const Jbig2Result *self, Jbig2Ctx *ctx);
-};
-
 typedef enum {
   JBIG2_FILE_HEADER,
   JBIG2_FILE_SEQUENTIAL_HEADER,
@@ -56,16 +45,10 @@
   byte file_header_flags;
   int32_t n_pages;
 
-  int n_sh;
-  int n_sh_max;
-  Jbig2SegmentHeader **sh_list;
-  int sh_ix;
-
-  /* The map from segment numbers to decoding results, currently
-     stored as a contiguous, 0-indexed array. */
-  int n_results;
-  int n_results_max;
-  const Jbig2Result **results;
+  int n_segments;
+  int n_segments_max;
+  Jbig2Segment **segments;
+  int segment_index;
   
   /* list of decoded pages, including the one in progress,
      currently stored as a contiguous, 0-indexed array. */
@@ -80,12 +63,29 @@
 int16_t
 jbig2_get_int16 (const byte *buf);
 
+/* dynamic memory management */
+void *
+jbig2_alloc (Jbig2Allocator *allocator, size_t size);
+
+void
+jbig2_free (Jbig2Allocator *allocator, void *p);
+
+void *
+jbig2_realloc (Jbig2Allocator *allocator, void *p, size_t size);
+
+#define jbig2_new(ctx, t, size) ((t *)jbig2_alloc(ctx->allocator, (size) * sizeof(t)))
+
+#define jbig2_renew(ctx, p, t, size) ((t *)jbig2_realloc(ctx->allocator, (p), (size) * sizeof(t)))
+
+int
+jbig2_error (Jbig2Ctx *ctx, Jbig2Severity severity, int32_t seg_idx,
+	     const char *fmt, ...);
+
 /* the page structure handles decoded page
    results. it's allocated by a 'page info'
    segement and marked complete by an 'end of page'
    segment.
 */
-
 typedef enum {
     JBIG2_PAGE_FREE,
     JBIG2_PAGE_NEW,
@@ -106,8 +106,8 @@
     Jbig2Image *image;
 };
 
-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);
+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);
 
@@ -122,7 +122,7 @@
 } 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);
+int jbig2_read_text_info(Jbig2Ctx *ctx, Jbig2Segment *segment, 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
@@ -140,10 +140,3 @@
 
 void
 jbig2_word_stream_buf_free(Jbig2Ctx *ctx, Jbig2WordStream *ws);
-
-const Jbig2Result *
-jbig2_get_result(Jbig2Ctx *ctx, int32_t segment_number);
-
-int
-jbig2_put_result(Jbig2Ctx *ctx, const Jbig2Result *result);
-
--- 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.5 2002/06/20 15:42:47 giles Exp $
+    $Id: jbig2_segment.c,v 1.6 2002/06/22 16:05:45 giles Exp $
 */
 
 #include <stdio.h>
@@ -19,11 +19,11 @@
 #include "jbig2_priv.h"
 #include "jbig2_symbol_dict.h"
 
-Jbig2SegmentHeader *
+Jbig2Segment *
 jbig2_parse_segment_header (Jbig2Ctx *ctx, uint8_t *buf, size_t buf_size,
 			    size_t *p_header_size)
 {
-  Jbig2SegmentHeader *result;
+  Jbig2Segment *result;
   uint8_t rtscarf;
   uint32_t rtscarf_long;
   int referred_to_segment_count;
@@ -35,11 +35,11 @@
   if (buf_size < 11)
     return NULL;
 
-  result = (Jbig2SegmentHeader *)jbig2_alloc(ctx->allocator,
-					     sizeof(Jbig2SegmentHeader));
+  result = (Jbig2Segment *)jbig2_alloc(ctx->allocator,
+					     sizeof(Jbig2Segment));
 
   /* 7.2.2 */
-  result->segment_number = jbig2_get_int32 (buf);
+  result->number = jbig2_get_int32 (buf);
 
   /* 7.2.3 */
   result->flags = buf[4];
@@ -62,8 +62,8 @@
   /* 7.2.5 */
   /* todo: read referred to segment numbers */
   /* For now, we skip them. */
-  referred_to_segment_size = result->segment_number <= 256 ? 1:
-    result->segment_number <= 65536 ? 2:
+  referred_to_segment_size = result->number <= 256 ? 1:
+    result->number <= 65536 ? 2:
     4;
   offset += referred_to_segment_count * referred_to_segment_size;
 
@@ -91,9 +91,9 @@
 }
 
 void
-jbig2_free_segment_header (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh)
+jbig2_free_segment (Jbig2Ctx *ctx, Jbig2Segment *segment)
 {
-  jbig2_free (ctx->allocator, sh);
+  jbig2_free (ctx->allocator, segment);
 }
 
 void
@@ -108,77 +108,77 @@
   info->flags = segment_data[16];
 }
 
-int jbig2_write_segment (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
+int jbig2_write_segment (Jbig2Ctx *ctx, Jbig2Segment *segment,
 			 const uint8_t *segment_data)
 {
-  jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+  jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
 	      "Segment %d, flags=%x, type=%d, data_length=%d",
-	      sh->segment_number, sh->flags, sh->flags & 63,
-	      sh->data_length);
-  switch (sh->flags & 63)
+	      segment->number, segment->flags, segment->flags & 63,
+	      segment->data_length);
+  switch (segment->flags & 63)
     {
     case 0:
-      return jbig2_symbol_dictionary(ctx, sh, segment_data);
+      return jbig2_symbol_dictionary(ctx, segment, segment_data);
     case 4:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'intermediate text region'");
     case 6:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'immediate text region'");
     case 7:
-      return jbig2_read_text_info(ctx, sh, segment_data);
+      return jbig2_read_text_info(ctx, segment, segment_data);
     case 16:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'pattern dictionary'");
     case 20:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'intermediate halftone region'");
     case 22:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'immediate halftone region'");
     case 23:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'immediate lossless halftone region'");
     case 36:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'intermediate generic region'");
     case 38:
-      return jbig2_immediate_generic_region(ctx, sh, segment_data);
+      return jbig2_immediate_generic_region(ctx, segment, segment_data);
     case 39:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'immediate lossless generic region'");
     case 40:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'intermediate generic refinement region'");
     case 42:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'immediate generic refinement region'");
     case 43:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'immediate lossless generic refinement region'");
     case 48:
-      return jbig2_read_page_info(ctx, sh, segment_data);
+      return jbig2_read_page_info(ctx, segment, segment_data);
     case 49:
-      return jbig2_complete_page(ctx, sh, segment_data);
+      return jbig2_complete_page(ctx, segment, segment_data);
     case 50:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'end of stripe'");
     case 51:
       ctx->state = JBIG2_FILE_EOF;
-      return jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
         "end of file");
     case 52:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled segment type 'profile'");
     case 53:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled table segment");
     case 62:
-      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "unhandled extension segment");
     default:
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
-          "unknown segment type %d", sh->flags & 63);
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
+          "unknown segment type %d", segment->flags & 63);
     }
   return 0;
 }
--- 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.9 2002/06/22 09:47:31 giles Exp $
+    $Id: jbig2_symbol_dict.c,v 1.10 2002/06/22 16:05:45 giles Exp $
 */
 
 #include <stddef.h>
@@ -48,7 +48,7 @@
 /* 6.5 */
 int
 jbig2_decode_symbol_dict(Jbig2Ctx *ctx,
-			 int32_t seg_number,
+			 Jbig2Segment *segment,
 			 const Jbig2SymbolDictParams *params,
 			 const byte *data, size_t size,
 			 Jbig2ArithCx *GB_stats)
@@ -95,10 +95,10 @@
 
       if (HCHEIGHT < 0)
 	/* todo: mem cleanup */
-	return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, seg_number,
+	return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 			   "Invalid HCHEIGHT value");
 
-      jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, seg_number,
+      jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
         "HCHEIGHT = %d", HCHEIGHT);
         
       for (;;)
@@ -118,9 +118,9 @@
 	  TOTWIDTH = TOTWIDTH + SYMWIDTH;
 	  if (SYMWIDTH < 0)
 	    /* todo: mem cleanup */
-	    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, seg_number,
+	    return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 			       "Invalid SYMWIDTH value");
-	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, seg_number,
+	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
             "SYMWIDTH = %d", SYMWIDTH);
 
 	  /* 6.5.5 (4c.ii) */
@@ -143,7 +143,7 @@
 
 		  image = jbig2_image_new(ctx, SYMWIDTH, HCHEIGHT);
 
-		  code = jbig2_decode_generic_region(ctx, seg_number,
+		  code = jbig2_decode_generic_region(ctx, segment,
 						     &region_params,
 						     as,
 						     image, GB_stats);
@@ -157,7 +157,7 @@
 
 	  /* 6.5.5 (4c.iv) */
 	  NSYMSDECODED = NSYMSDECODED + 1;
-	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, seg_number,
+	  jbig2_error(ctx, JBIG2_SEVERITY_DEBUG, segment->number,
             "%d of %d decoded", NSYMSDECODED, params->SDNUMNEWSYMS);
 	}
     }
@@ -169,7 +169,7 @@
 
 /* 7.4.2 */
 int
-jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
+jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
 			const byte *segment_data)
 {
   Jbig2SymbolDictParams params;
@@ -178,7 +178,7 @@
   int offset;
   Jbig2ArithCx *GB_stats = NULL;
 
-  if (sh->data_length < 10)
+  if (segment->data_length < 10)
     goto too_short;
 
   /* 7.4.2.1.1 */
@@ -189,7 +189,7 @@
   params.SDRTEMPLATE = (flags >> 12) & 1;
 
   if (params.SDHUFF) {
-    jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+    jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "symbol dictionary uses the Huffman encoding variant (NYI)");
     return 0;
   }
@@ -198,18 +198,18 @@
   /* maybe #ifdef CONFORMANCE and a separate routine */
   if(!params.SDHUFF && (flags & 0x000c))
     {
-      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
 		  "SDHUFF is zero, but contrary to spec SDHUFFDH is not.");
     }
   if(!params.SDHUFF && (flags & 0x0030))
     {
-      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
 		  "SDHUFF is zero, but contrary to spec SDHUFFDW is not.");
     }
 
   if (flags & 0x0080)
     {
-      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "bitmap coding context is used (NYI) symbol data likely to be garbage!");
     }
 
@@ -221,13 +221,13 @@
   /* 7.4.2.1.3 */
   if (params.SDREFAGG && !params.SDRTEMPLATE)
     {
-      if (offset + 4 > sh->data_length)
+      if (offset + 4 > segment->data_length)
 	goto too_short;
       memcpy(params.sdrat, segment_data + offset, 4);
       offset += 4;
     }
 
-  if (offset + 8 > sh->data_length)
+  if (offset + 8 > segment->data_length)
     goto too_short;
 
   /* 7.4.2.1.4 */
@@ -236,7 +236,7 @@
   params.SDNUMNEWSYMS = jbig2_get_int32(segment_data + offset + 4);
   offset += 8;
 
-  jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+  jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
 	      "symbol dictionary, flags=%04x, %d exported syms, %d new syms",
 	      flags, params.SDNUMEXSYMS, params.SDNUMNEWSYMS);
 
@@ -251,19 +251,19 @@
 
   if (flags & 0x0100)
     {
-      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+      jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
         "segment marks bitmap coding context as retained (NYI)");
     }
 
-  return jbig2_decode_symbol_dict(ctx, sh->segment_number,
+  return jbig2_decode_symbol_dict(ctx, segment,
 				  &params,
 				  segment_data + offset,
-				  sh->data_length - offset,
+				  segment->data_length - offset,
 				  GB_stats);
 
   /* todo: retain or free GB_stats */
   
  too_short:
-  return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, sh->segment_number,
+  return jbig2_error(ctx, JBIG2_SEVERITY_FATAL, segment->number,
 		     "Segment too short");
 }
--- a/jbig2_symbol_dict.h
+++ b/jbig2_symbol_dict.h
@@ -8,9 +8,9 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    $Id: jbig2_symbol_dict.h,v 1.2 2002/06/15 14:12:50 giles Exp $
+    $Id: jbig2_symbol_dict.h,v 1.3 2002/06/22 16:05:45 giles Exp $
 */
 
 int
-jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
+jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2Segment *segment,
 			const byte *segment_data);
--- 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.1 2002/06/20 15:42:48 giles Exp $
+    $Id: jbig2_text.c,v 1.2 2002/06/22 16:05:45 giles Exp $
 */
 
 #include <stddef.h>
@@ -25,7 +25,7 @@
  * jbig2_read_text_info: read a text region segment header
  **/
 int
-jbig2_read_text_info(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh, const byte *segment_data)
+jbig2_read_text_info(Jbig2Ctx *ctx, Jbig2Segment *segment, const byte *segment_data)
 {
     int offset = 0;
     Jbig2RegionSegmentInfo region_info;
@@ -66,11 +66,11 @@
     
     /* 7.4.3.1.7 */
     if (segment_flags & 0x01) {
-        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, sh->segment_number,
+        jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
             "symbol id huffman table decoding NYI");
     }
     
-    jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->segment_number,
+    jbig2_error(ctx, JBIG2_SEVERITY_INFO, 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);