shithub: jbig2

Download patch

ref: 2dea640032a72f9756cdccd54352c10b18348f56
parent: f125f9553a1e3c8088cf59df7c983aef3785641a
author: giles <giles@ded80894-8fb9-0310-811b-c03f3676ab4d>
date: Fri May 16 20:08:26 EDT 2008

More whitespace cleanup.


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

--- a/config_win32.h
+++ b/config_win32.h
@@ -7,7 +7,7 @@
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
@@ -28,7 +28,7 @@
   typedef short int               int16_t;
   typedef int                     int32_t;
   typedef __int64                 int64_t;
- 
+
   typedef unsigned char             uint8_t;
   typedef unsigned short int        uint16_t;
   typedef unsigned int              uint32_t;
--- a/jbig2_arith_iaid.c
+++ b/jbig2_arith_iaid.c
@@ -5,12 +5,12 @@
 
     This software is provided AS-IS with no warranty,
     either express or implied.
-                                                                                
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
@@ -23,7 +23,7 @@
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif 
+#endif
 #include "os_types.h"
 
 #include <stddef.h>
--- a/jbig2_halftone.c
+++ b/jbig2_halftone.c
@@ -1,13 +1,13 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2005 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
@@ -20,7 +20,7 @@
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif 
+#endif
 #include "os_types.h"
 
 #include <string.h> /* memset() */
@@ -170,7 +170,7 @@
   rparams.gbat[5] = -2;
   rparams.gbat[6] = -2;
   rparams.gbat[7] = -2;
-  
+
   if (params->HDMMR) {
     code = jbig2_decode_generic_mmr(ctx, segment, &rparams,
 		data, size, image);
@@ -258,7 +258,7 @@
  * jbig2_decode_halftone_region: decode a halftone region
  **/
 int
-jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment, 
+jbig2_decode_halftone_region(Jbig2Ctx *ctx, Jbig2Segment *segment,
 			     Jbig2HalftoneRegionParams *params,
 			     const byte *data, const size_t size,
 			     Jbig2Image *image,
--- a/jbig2_huffman.c
+++ b/jbig2_huffman.c
@@ -1,27 +1,27 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2001-2005 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
     San Rafael, CA  94903, U.S.A., +1(415)492-9861.
-    
+
     $Id$
 */
 
-/* Huffman table decoding procedures 
+/* Huffman table decoding procedures
     -- See Annex B of the JBIG2 specification */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif 
+#endif
 #include "os_types.h"
 
 #include <stdlib.h>
@@ -63,7 +63,7 @@
 {
   Jbig2HuffmanState *result;
 
-  result = (Jbig2HuffmanState *)jbig2_alloc(ctx->allocator,  
+  result = (Jbig2HuffmanState *)jbig2_alloc(ctx->allocator,
 	sizeof(Jbig2HuffmanState));
 
   if (result != NULL) {
@@ -94,7 +94,7 @@
 /** print current huffman state */
 void jbig2_dump_huffman_state(Jbig2HuffmanState *hs) {
   fprintf(stderr, "huffman state %08x %08x offset %d.%d\n",
-	hs->this_word, hs->next_word, hs->offset, hs->offset_bits); 
+	hs->this_word, hs->next_word, hs->offset, hs->offset_bits);
 }
 
 /** print the binary string we're reading from */
@@ -121,7 +121,7 @@
   if (bits) {
     bits = 8 - bits;
     hs->offset_bits += bits;
-    hs->this_word = (hs->this_word << bits) | 
+    hs->this_word = (hs->this_word << bits) |
 	(hs->next_word >> (32 - hs->offset_bits));
   }
 
@@ -160,7 +160,7 @@
 /* return the offset of the huffman decode pointer (in bytes)
  * from the beginning of the WordStream
  */
-int 
+int
 jbig2_huffman_offset(Jbig2HuffmanState *hs)
 {
   return hs->offset + (hs->offset_bits >> 3);
@@ -209,7 +209,7 @@
   int32_t result;
 
   for (;;)
-    { 
+    {
       int log_table_size = table->log_table_size;
       int PREFLEN;
 
@@ -276,7 +276,7 @@
   return result;
 }
 
-/* TODO: more than 8 bits here is wasteful of memory. We have support 
+/* TODO: more than 8 bits here is wasteful of memory. We have support
    for sub-trees in jbig2_huffman_get() above, but don't use it here.
    We should, and then revert to 8 bits */
 #define LOG_TABLE_SIZE_MAX 16
@@ -283,7 +283,7 @@
 
 /** Build an in-memory representation of a Huffman table from the
  *  set of template params provided by the spec or a table segment
- */ 
+ */
 Jbig2HuffmanTable *
 jbig2_build_huffman_table (Jbig2Ctx *ctx, const Jbig2HuffmanParams *params)
 {
@@ -436,7 +436,7 @@
   Jbig2WordStream ws;
   bool oob;
   int32_t code;
-  
+
   ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
 
   tables[0] = NULL;
@@ -449,11 +449,11 @@
 
   printf("testing jbig2 huffmann decoding...");
   printf("\t(should be 8 5 (oob) 8)\n");
-  
+
   {
 	int i;
 	int sequence_length = sizeof(test_tabindex);
-	
+
 	for (i = 0; i < sequence_length; i++) {
 		code = jbig2_huffman_get (hs, tables[test_tabindex[i]], &oob);
 		if (oob) printf("(oob) ");
@@ -460,11 +460,11 @@
 		else printf("%d ", code);
 	}
   }
-  
+
   printf("\n");
 
   jbig2_ctx_free(ctx);
-  
+
   return 0;
 }
 #endif
--- a/jbig2_hufftab.h
+++ b/jbig2_hufftab.h
@@ -1,22 +1,22 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2001-2005 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
     San Rafael, CA  94903, U.S.A., +1(415)492-9861.
-    
+
     $Id$
 */
 
-/* predefined Huffman table definitions 
+/* predefined Huffman table definitions
     -- See Annex B of the JBIG2 specification */
 
 #ifndef JBIG2_HUFFTAB_H
--- a/jbig2_metadata.c
+++ b/jbig2_metadata.c
@@ -1,13 +1,13 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2003 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
@@ -18,7 +18,7 @@
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif 
+#endif
 #include "os_types.h"
 
 #include <stdlib.h>
@@ -32,7 +32,7 @@
 Jbig2Metadata *jbig2_metadata_new(Jbig2Ctx *ctx, Jbig2Encoding encoding)
 {
     Jbig2Metadata *md = jbig2_alloc(ctx->allocator, sizeof(Jbig2Metadata));
-    
+
     if (md != NULL) {
         md->encoding = encoding;
         md->entries = 0;
@@ -82,7 +82,7 @@
                         const char *value, const int value_length)
 {
     char **keys, **values;
-    
+
     /* grow the array if necessary */
     if (md->entries == md->max_entries) {
         md->max_entries >>= 2;
@@ -96,12 +96,12 @@
         md->keys = keys;
         md->values = values;
     }
-    
+
     /* copy the passed key,value pair */
     md->keys[md->entries] = jbig2_strndup(ctx, key, key_length);
     md->values[md->entries] = jbig2_strndup(ctx, value, value_length);
     md->entries++;
-    
+
     return 0;
 }
 
@@ -115,10 +115,10 @@
     Jbig2Metadata *comment;
     char *key, *value;
     int key_length, value_length;
-    
+
     jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
         "ASCII comment data");
-        
+
     comment = jbig2_metadata_new(ctx, JBIG2_ENCODING_ASCII);
     if (comment == NULL) {
         jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
@@ -137,12 +137,12 @@
         jbig2_error(ctx, JBIG2_SEVERITY_INFO, segment->number,
             "'%s'\t'%s'", key, value);
     }
-    
+
     /* TODO: associate with ctx, page, or referred-to segment(s) */
     segment->result = comment;
-    
+
     return 0;
-    
+
 too_short:
     jbig2_metadata_free(ctx, comment);
     return jbig2_error(ctx, JBIG2_SEVERITY_WARNING, segment->number,
--- a/jbig2_priv.h
+++ b/jbig2_priv.h
@@ -1,20 +1,20 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2002 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
     San Rafael, CA  94903, U.S.A., +1(415)492-9861.
-        
+
     $Id$
-    
+
     shared library internals
 */
 
@@ -62,7 +62,7 @@
   Jbig2Segment **segments;
   int n_segments;	/* index of last segment header parsed */
   int segment_index;    /* index of last segment body parsed */
-  
+
   /* list of decoded pages, including the one in progress,
      currently stored as a contiguous, 0-indexed array. */
   int current_page;
@@ -155,7 +155,7 @@
 			       const uint8_t *segment_data);
 int jbig2_refinement_region(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
    invocation pulls 4 bytes from the stream, packed big-endian into a
--- a/jbig2dec.c
+++ b/jbig2dec.c
@@ -1,13 +1,13 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2001-2003 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
@@ -86,7 +86,7 @@
     unsigned char md[SHA1_DIGEST_SIZE];
     char digest[2*SHA1_DIGEST_SIZE + 1];
     int i;
-    
+
     SHA1_Final(params->hash_ctx, md);
     for (i = 0; i < SHA1_DIGEST_SIZE; i++) {
         snprintf(&(digest[2*i]), 3, "%02x", md[i]);
@@ -114,7 +114,7 @@
 #endif
     /* default to pbm */
     params->output_format=jbig2dec_format_pbm;
-    
+
     return 0;
 }
 
@@ -223,7 +223,7 @@
  #endif
     "\n"
   );
-  
+
   return 1;
 }
 
@@ -234,7 +234,7 @@
     const jbig2dec_params_t *params = error_callback_data;
     char *type;
     char segment[22];
-    
+
     switch (severity) {
         case JBIG2_SEVERITY_DEBUG:
             if (params->verbose < 3) return 0;
@@ -250,7 +250,7 @@
     }
     if (seg_idx == -1) segment[0] = '\0';
     else snprintf(segment, sizeof(segment), "(segment 0x%02x)", seg_idx);
-    
+
     fprintf(stderr, "jbig2dec %s %s %s\n", type, buf, segment);
 
     return 0;
@@ -262,15 +262,15 @@
     char *output_filename;
     const char *c, *e;
     int len;
-    
+
     if (extension == NULL) {
         fprintf(stderr, "make_output_filename called with no extension!\n");
         exit (1);
     }
-    
+
     if (input_filename == NULL)
       c = "out";
-    else {  
+    else {
       /* strip any leading path */
       c = strrchr(input_filename, '/'); /* *nix */
       if (c == NULL)
@@ -284,13 +284,13 @@
     /* make sure we haven't just stripped the last character */
     if (*c == '\0')
       c = "out";
-        
+
     /* strip the extension */
     len = strlen(c);
     e = strrchr(c, '.');
     if (e != NULL)
       len -= strlen(e);
-    
+
     /* allocate enough space for the base + ext */
     output_filename = malloc(len + strlen(extension) + 1);
     if (output_filename == NULL) {
@@ -297,11 +297,11 @@
         fprintf(stderr, "couldn't allocate memory for output_filename\n");
         exit (1);
     }
-    
+
     strncpy(output_filename, c, len);
     strncpy(output_filename + len, extension, strlen(extension));
     *(output_filename + len + strlen(extension)) = '\0';
-    
+
     /* return the new string */
     return (output_filename);
 }
@@ -343,7 +343,7 @@
               return 1;
           }
         }
-        
+
   return 0;
 }
 
@@ -351,17 +351,17 @@
 write_document_hash(jbig2dec_params_t *params)
 {
     FILE *out;
-    
+
     if (!strncmp(params->output_file, "-", 2)) {
         out = stderr;
     } else {
         out = stdout;
     }
-    
+
     fprintf(out, "Hash of decoded document: ");
     hash_print(params, out);
     fprintf(out, "\n");
-    
+
     return 0;
 }
 
@@ -373,7 +373,7 @@
   uint8_t buf[4096];
   jbig2dec_params_t params;
   int filearg;
-  
+
   /* set defaults */
   params.mode = render;
   params.verbose = 1;
@@ -380,11 +380,11 @@
   params.hash = 0;
   params.output_file = NULL;
   params.output_format = jbig2dec_format_none;
-  
+
   filearg = parse_options(argc, argv, &params);
 
   if (params.hash) hash_init(&params);
-  
+
   switch (params.mode) {
     case usage:
         print_usage();
@@ -394,7 +394,7 @@
         fprintf(stderr, "Sorry, segment dump not yet implemented\n");
         break;
     case render:
-    
+
   if ((argc - filearg) == 1)
   /* only one argument--open as a jbig2 file */
     {
@@ -430,7 +430,7 @@
   else
   /* any other number of arguments */
     return print_usage();
-    
+
   ctx = jbig2_ctx_new(NULL, f_page != NULL ? JBIG2_OPTIONS_EMBEDDED : 0,
 		      NULL,
 		      error_callback, &params);
@@ -469,7 +469,7 @@
     /* work around broken CVision embedded streams */
     if (f_page != NULL)
       jbig2_complete_page(ctx);
-    
+
     if (params.output_file == NULL)
       {
 #ifdef HAVE_LIBPNG
@@ -494,7 +494,7 @@
     }
     if (params.hash) write_document_hash(&params);
   }
-  
+
   jbig2_ctx_free(ctx);
 
   } /* end params.mode switch */
@@ -501,7 +501,7 @@
 
   if (params.output_file) free(params.output_file);
   if (params.hash) hash_free(&params);
-  
+
   /* fin */
   return 0;
 }
--- a/os_types.h
+++ b/os_types.h
@@ -1,18 +1,18 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2003 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
     San Rafael, CA  94903, U.S.A., +1(415)492-9861.
-        
+
     $Id$
 */
 
@@ -41,7 +41,7 @@
 #endif
 #elif defined(HAVE_CONFIG_H)
 # include "config_types.h"
-#elif defined(_WIN32) || defined(__WIN32__) 
+#elif defined(_WIN32) || defined(__WIN32__)
 # include "config_win32.h"
 #endif
 
--- a/pbm2png.c
+++ b/pbm2png.c
@@ -1,13 +1,13 @@
 /*
     jbig2dec
-    
+
     Copyright (C) 2002 Artifex Software, Inc.
-    
+
     This software is distributed under license and may not
     be copied, modified or distributed except as expressly
     authorized under the terms of the license contained in
     the file LICENSE in this distribution.
-                                                                                
+
     For information on commercial licensing, go to
     http://www.artifex.com/licensing/ or contact
     Artifex Software, Inc.,  101 Lucas Valley Road #110,
@@ -38,7 +38,7 @@
     Jbig2Ctx *ctx;
     Jbig2Image *image;
     int error;
-    
+
     /* we need a context for the allocators */
     ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
 
@@ -46,7 +46,7 @@
         fprintf(stderr, "usage: %s <in.pbm> <out.png>\n\n", argv[0]);
         return 1;
     }
-    
+
     image = jbig2_image_read_pbm_file(ctx, argv[1]);
     if(image == NULL) {
         fprintf(stderr, "error reading pbm file '%s'\n", argv[1]);
@@ -54,7 +54,7 @@
     } else {
         fprintf(stderr, "converting %dx%d image to png format\n", image->width, image->height);
     }
-    
+
     error = jbig2_image_write_png_file(image, argv[2]);
     if (error) {
         fprintf(stderr, "error writing png file '%s' error %d\n", argv[2], error);
--- a/sha1.c
+++ b/sha1.c
@@ -4,7 +4,7 @@
 100% Public Domain
 
 -----------------
-Modified 7/98 
+Modified 7/98
 By James H. Brown <jbrown@burgoyne.com>
 Still 100% Public Domain
 
@@ -26,7 +26,7 @@
 be guaranteed to generate the wrong hash (e.g. Test Vector #3, a million
 "a"s).
 
-I also changed the declaration of variables i & j in SHA1Update to 
+I also changed the declaration of variables i & j in SHA1Update to
 unsigned long from unsigned int for the same reason.
 
 These changes should make no difference to any 32 bit implementations since
@@ -53,7 +53,7 @@
 Modified 4/01
 By Saul Kravitz <Saul.Kravitz@celera.com>
 Still 100% PD
-Modified to run on Compaq Alpha hardware.  
+Modified to run on Compaq Alpha hardware.
 
 -----------------
 Modified 07/2002
@@ -116,7 +116,7 @@
 void SHAPrintContext(SHA1_CTX *context, char *msg){
   printf("%s (%d,%d) %x %x %x %x %x\n",
 	 msg,
-	 context->count[0], context->count[1], 
+	 context->count[0], context->count[1],
 	 context->state[0],
 	 context->state[1],
 	 context->state[2],
@@ -245,7 +245,7 @@
         digest[i] = (uint8_t)
          ((context->state[i>>2] >> ((3-(i & 3)) * 8) ) & 255);
     }
-    
+
     /* Wipe variables */
     i = 0;
     memset(context->buffer, 0, 64);
@@ -257,7 +257,7 @@
     SHA1_Transform(context->state, context->buffer);
 #endif
 }
-  
+
 /*************************************************************/
 
 #if 0
@@ -282,7 +282,7 @@
             fputs("Unable to open file.", stderr);
             return(-1);
         }
-    } 
+    }
     SHA1_Init(&context);
     while (!feof(file)) {  /* note: what if ferror(file) */
         i = fread(buffer, 1, 16384, file);
@@ -313,13 +313,13 @@
     "A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D",
     "84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1",
     "34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F"};
-    
 
+
 void digest_to_hex(const uint8_t digest[SHA1_DIGEST_SIZE], char *output)
 {
     int i,j;
     char *c = output;
-    
+
     for (i = 0; i < SHA1_DIGEST_SIZE/4; i++) {
         for (j = 0; j < 4; j++) {
             sprintf(c,"%02X", digest[i*4+j]);
@@ -330,7 +330,7 @@
     }
     *(c - 1) = '\0';
 }
-    
+
 int main(int argc, char** argv)
 {
     int k;
@@ -339,8 +339,8 @@
     char output[80];
 
     fprintf(stdout, "verifying SHA-1 implementation... ");
-    
-    for (k = 0; k < 2; k++){ 
+
+    for (k = 0; k < 2; k++){
         SHA1_Init(&context);
         SHA1_Update(&context, (uint8_t*)test_data[k], strlen(test_data[k]));
         SHA1_Final(&context, digest);
@@ -352,7 +352,7 @@
             fprintf(stderr,"\t%s returned\n", output);
             fprintf(stderr,"\t%s is correct\n", test_results[k]);
             return (1);
-        }    
+        }
     }
     /* million 'a' vector we feed separately */
     SHA1_Init(&context);