pdf_g4.c

changeset 91
e63762afae80
parent 78
74b6b230f85d
child 100
5916a95e2b92
     1.1 diff -r 4830f4d7ba7a -r e63762afae80 pdf_g4.c
     1.2 --- a/pdf_g4.c	Sat Mar 08 10:02:13 2003 +0000
     1.3 +++ b/pdf_g4.c	Mon Mar 10 09:49:50 2003 +0000
     1.4 @@ -4,7 +4,7 @@
     1.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.6   *
     1.7   * PDF routines
     1.8 - * $Id: pdf_g4.c,v 1.8 2003/03/05 12:44:33 eric Exp $
     1.9 + * $Id: pdf_g4.c,v 1.9 2003/03/10 01:49:50 eric Exp $
    1.10   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    1.11   *
    1.12   * This program is free software; you can redistribute it and/or modify
    1.13 @@ -38,9 +38,6 @@
    1.14  #include "pdf_private.h"
    1.15  
    1.16  
    1.17 -#include "pdf_g4_tables.h"
    1.18 -
    1.19 -
    1.20  #define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0)
    1.21  
    1.22  
    1.23 @@ -95,130 +92,13 @@
    1.24  }
    1.25  
    1.26  
    1.27 -static void pdf_g4_encode_horizontal_run (pdf_file_handle pdf_file,
    1.28 -					  struct pdf_obj *stream,
    1.29 -					  bool black,
    1.30 -					  uint32_t run_length)
    1.31 -{
    1.32 -  uint32_t i;
    1.33 -
    1.34 -  while (run_length >= 2560)
    1.35 -    {
    1.36 -      pdf_stream_write_bits (pdf_file, stream, 12, 0x01f);
    1.37 -      run_length -= 2560;
    1.38 -    }
    1.39 -
    1.40 -  if (run_length >= 1792)
    1.41 -    {
    1.42 -      i = (run_length - 1792) >> 6;
    1.43 -      pdf_stream_write_bits (pdf_file, stream,
    1.44 -			     g4_long_makeup_code [i].count,
    1.45 -			     g4_long_makeup_code [i].bits);
    1.46 -      run_length -= (1792 + (i << 6));
    1.47 -    }
    1.48 -  else if (run_length >= 64)
    1.49 -    {
    1.50 -      i = (run_length >> 6) - 1;
    1.51 -      pdf_stream_write_bits (pdf_file, stream,
    1.52 -			     g4_makeup_code [black] [i].count,
    1.53 -			     g4_makeup_code [black] [i].bits);
    1.54 -      run_length -= (i + 1) << 6;
    1.55 -    }
    1.56 -
    1.57 -  pdf_stream_write_bits (pdf_file, stream,
    1.58 -			 g4_h_code [black] [run_length].count,
    1.59 -			 g4_h_code [black] [run_length].bits);
    1.60 -}
    1.61 -
    1.62 -
    1.63 -uint32_t find_transition (uint8_t *data,
    1.64 -			  uint32_t pos,
    1.65 -			  uint32_t width)
    1.66 -{
    1.67 -  if (! data)
    1.68 -    return (width);
    1.69 -  return (0);  /* $$$ */
    1.70 -}
    1.71 -
    1.72 -
    1.73 -static void pdf_g4_encode_row (pdf_file_handle pdf_file,
    1.74 -			       struct pdf_obj *stream,
    1.75 -			       uint32_t width,
    1.76 -			       uint8_t *ref,
    1.77 -			       uint8_t *row)
    1.78 -{
    1.79 -  int a0, a1, a2;
    1.80 -  int b1, b2;
    1.81 -
    1.82 -  a0 = -1;
    1.83 -  
    1.84 -  while (a0 < width)
    1.85 -    {
    1.86 -      /* find a1, a2 */
    1.87 -      a1 = find_transition (row, a0, width);
    1.88 -      a2 = find_transition (row, a1, width);
    1.89 -
    1.90 -      /* find b1, b2 */
    1.91 -      b1 = find_transition (ref, a0, width);
    1.92 -      if (0) /* $$$ b1 color = a0 color */
    1.93 -	b1 = find_transition (ref, b1, width);
    1.94 -      b2 = find_transition (ref, b2, width);
    1.95 -
    1.96 -      if (b2 < a1)
    1.97 -	{
    1.98 -	  /* pass mode - 0001 */
    1.99 -	  pdf_stream_write_bits (pdf_file, stream, 4, 0x1);
   1.100 -	  a0 = b2;
   1.101 -	}
   1.102 -      else if (abs (a1 - b1) <= 3)
   1.103 -	{
   1.104 -	  /* vertical mode */
   1.105 -	  pdf_stream_write_bits (pdf_file, stream,
   1.106 -				 g4_vert_code [3 + a1 - b1].count,
   1.107 -				 g4_vert_code [3 + a1 - b1].bits);
   1.108 -	  a0 = a1;
   1.109 -	}
   1.110 -      else
   1.111 -	{
   1.112 -	  /* horizontal mode - 001 */
   1.113 -	  pdf_stream_write_bits (pdf_file, stream, 3, 0x1);
   1.114 -	  pdf_g4_encode_horizontal_run (pdf_file, stream,
   1.115 -					0 /* $$$ color (a0) */, a1 - a0);
   1.116 -	  pdf_g4_encode_horizontal_run (pdf_file, stream,
   1.117 -					1 /* $$$ color (a1) */, a2 - a1);
   1.118 -	  a0 = a2;
   1.119 -	}
   1.120 -    }
   1.121 -}
   1.122 -
   1.123 -
   1.124  void pdf_write_g4_fax_image_callback (pdf_file_handle pdf_file,
   1.125  				      struct pdf_obj *stream,
   1.126  				      void *app_data)
   1.127  {
   1.128    struct pdf_g4_image *image = app_data;
   1.129  
   1.130 -  uint32_t row;
   1.131 -
   1.132 -  word_type *ref_line = NULL;  /* reference (previous) row */
   1.133 -  word_type *line = image->bitmap->bits;
   1.134 -
   1.135 -  for (row = image->bitmap->rect.min.y;
   1.136 -       row < image->bitmap->rect.max.y;
   1.137 -       row++)
   1.138 -    {
   1.139 -      pdf_g4_encode_row (pdf_file, stream, image->Columns,
   1.140 -			 (uint8_t *) ref_line,
   1.141 -			 (uint8_t *) line);
   1.142 -      ref_line = line;
   1.143 -      line += image->bitmap->row_words;
   1.144 -    }
   1.145 -
   1.146 -  
   1.147 -  /* write EOFB code */
   1.148 -  pdf_stream_write_bits (pdf_file, stream, 24, 0x001001);
   1.149 -
   1.150 -  pdf_stream_flush_bits (pdf_file, stream);
   1.151 +  bitblt_write_g4 (image->bitmap, pdf_file->f);
   1.152  }
   1.153  
   1.154