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