shithub: jbig2

Download patch

ref: e22ae8f124c9ed5a3ccadbad3a302285d94ffc4c
parent: 43bf50d093b48ad481fc24656b66d34422ac07dc
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Sat Jun 15 10:12:50 EDT 2002

minor code rearrangement and comments


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

--- a/jbig2.c
+++ b/jbig2.c
@@ -1,7 +1,21 @@
+/*
+    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.c,v 1.6 2002/06/15 14:12:50 giles Exp $
+*/
+
 #include <stdint.h>
 #include <stdlib.h>
 #include <stdarg.h>
 #include <stdio.h>
+
 #include "jbig2.h"
 #include "jbig2_priv.h"
 #include "jbig2_arith.h"
@@ -382,22 +396,6 @@
   jbig2_ctx_free((Jbig2Ctx *)global_ctx);
 }
 
-int jbig2_write_segment (Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
-			 const uint8_t *segment_data)
-{
-  jbig2_error(ctx, JBIG2_SEVERITY_INFO, sh->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)
-    {
-    case 0:
-      return jbig2_symbol_dictionary(ctx, sh, segment_data);
-    case 38:
-      return jbig2_immediate_generic_region(ctx, sh, segment_data);
-    }
-  return 0;
-}
 
 const Jbig2Result *
 jbig2_get_result(Jbig2Ctx *ctx, int32_t segment_number)
--- a/jbig2_symbol_dict.c
+++ b/jbig2_symbol_dict.c
@@ -1,5 +1,19 @@
+/*
+    jbig2dec
+    
+    Copyright (C) 2001-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_symbol_dict.c,v 1.4 2002/06/15 14:12:50 giles Exp $
+*/
+
 #include <stddef.h>
 #include <stdint.h>
+
 #include "jbig2.h"
 #include "jbig2_priv.h"
 #include "jbig2_arith.h"
@@ -85,7 +99,7 @@
   return result;
 }
 
-#endif /* Giles */
+#endif /* GILES */
 
 /* Table 13 */
 typedef struct {
--- a/jbig2_symbol_dict.h
+++ b/jbig2_symbol_dict.h
@@ -1,3 +1,16 @@
+/*
+    jbig2dec
+    
+    Copyright (C) 2001-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_symbol_dict.h,v 1.2 2002/06/15 14:12:50 giles Exp $
+*/
+
 int
 jbig2_symbol_dictionary(Jbig2Ctx *ctx, Jbig2SegmentHeader *sh,
 			const byte *segment_data);
--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -8,7 +8,7 @@
     the Free Software Foundation; either version 2 of the License, or
     (at your option) any later version.
 
-    $Id: jbig2dec.c,v 1.18 2002/06/04 16:47:09 giles Exp $
+    $Id: jbig2dec.c,v 1.19 2002/06/15 14:12:50 giles Exp $
 */
 
 #include <stdio.h>
@@ -16,6 +16,10 @@
 #include <stdint.h>
 #include <string.h>
 
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
 #ifdef HAVE_GETOPT_H
 # include <getopt.h>
 #else
@@ -38,18 +42,6 @@
 #ifdef DEAD_CODE
 
 
-int32
-get_bytes (Jbig2Ctx_foo *ctx, byte *buf, int size, int off)
-{
-  int n_bytes;
-
-  fseek(ctx->f, off, SEEK_SET);
-  n_bytes = fread(buf, 1, size, ctx->f);
-  if (n_bytes < size)
-    ctx->eof = TRUE;
-  return n_bytes;
-}
-
 static Jbig2Ctx_foo *
 jbig2_open (FILE *f)
 {
@@ -240,8 +232,19 @@
 error_callback(void *error_callback_data, const char *buf, Jbig2Severity severity,
 	       int32_t seg_idx)
 {
-  fprintf(stderr, "%s\n", buf);
-  return 0;
+    char *string;
+    
+    switch (severity) {
+        case JBIG2_SEVERITY_DEBUG: string = "DEBUG"; break;;
+        case JBIG2_SEVERITY_INFO: string = "info"; break;;
+        case JBIG2_SEVERITY_WARNING: string = "warning"; break;;
+        case JBIG2_SEVERITY_FATAL: string = "fatal error"; break;;
+        default: string = "unknown message"; break;;
+    }
+    
+    fprintf(stderr, "jbig2dec %s %s (segment 0x%0x)\n", string, buf, seg_idx);
+
+    return 0;
 }
 
 int
@@ -256,6 +259,7 @@
   filearg = parse_options(argc, argv, &params);
 
   if ((argc - filearg) == 1)
+  // only one argument--open as a jbig2 file
     {
       char *fn = argv[filearg];
 
@@ -267,6 +271,7 @@
 	}
     }
   else if ((argc - filearg) == 2)
+  // two arguments open as separate global and page streams
     {
       char *fn = argv[filearg];
       char *fn_page = argv[filearg+1];
@@ -285,12 +290,15 @@
 	  return 1;
 	}
     }
-  else    
+  else
+  // any other number of arguments
     return print_usage();
     
   ctx = jbig2_ctx_new(NULL, f_page != NULL ? JBIG2_OPTIONS_EMBEDDED : 0,
 		      NULL,
 		      error_callback, NULL);
+
+  // pull the whole file/global stream into memory
   for (;;)
     {
       int n_bytes = fread(buf, 1, sizeof(buf), f);
@@ -300,6 +308,7 @@
     }
   fclose(f);
 
+  // if there's a local page stream read that in its entirety
   if (f_page != NULL)
     {
       Jbig2GlobalCtx *global_ctx = jbig2_make_global_ctx(ctx);
@@ -318,5 +327,6 @@
 
   jbig2_ctx_free(ctx);
 
+  // fin
   return 0;
 }