Mon, 10 Mar 2003 13:08:25 +0000
Working on G4 encoding.
bitblt.h | file | annotate | diff | revisions | |
bitblt_g4.c | file | annotate | diff | revisions | |
pdf_util.c | file | annotate | diff | revisions | |
t2p.c | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions |
1.1 --- a/bitblt.h Mon Mar 10 09:58:34 2003 +0000 1.2 +++ b/bitblt.h Mon Mar 10 13:08:25 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 * bitblt routines 1.7 - * $Id: bitblt.h,v 1.13 2003/03/10 01:49:50 eric Exp $ 1.8 + * $Id: bitblt.h,v 1.14 2003/03/10 05:08:25 eric Exp $ 1.9 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 1.10 * 1.11 * This program is free software; you can redistribute it and/or modify 1.12 @@ -47,9 +47,12 @@ 1.13 } 1.14 1.15 1.16 +/* word_type should be the largest native type that can be handled 1.17 + efficiently, so it shouldn't be a 64-bit type on a processor that 1.18 + doesn't have native 64-bit operations. */ 1.19 typedef uint32_t word_type; 1.20 #define BITS_PER_WORD (8 * sizeof (word_type)) 1.21 -#define ALL_ONES (~ 0U) 1.22 +#define ALL_ONES (~ 0UL) 1.23 1.24 1.25 typedef struct Bitmap
2.1 --- a/bitblt_g4.c Mon Mar 10 09:58:34 2003 +0000 2.2 +++ b/bitblt_g4.c Mon Mar 10 13:08:25 2003 +0000 2.3 @@ -4,7 +4,7 @@ 2.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 2.5 * 2.6 * G4 compression 2.7 - * $Id: bitblt_g4.c,v 1.9 2003/03/10 01:49:50 eric Exp $ 2.8 + * $Id: bitblt_g4.c,v 1.10 2003/03/10 05:08:25 eric Exp $ 2.9 * Copyright 2003 Eric Smith <eric@brouhaha.com> 2.10 * 2.11 * This program is free software; you can redistribute it and/or modify 2.12 @@ -32,6 +32,7 @@ 2.13 2.14 2.15 #include "bitblt.h" 2.16 +#include "pdf_util.h" 2.17 2.18 2.19 #include "g4_tables.h" 2.20 @@ -134,13 +135,24 @@ 2.21 } 2.22 2.23 2.24 -static uint32_t find_transition (uint8_t *data, 2.25 - uint32_t pos, 2.26 - uint32_t width) 2.27 +static inline int g4_get_pixel (uint8_t *buf, uint32_t x) 2.28 { 2.29 - if (! data) 2.30 - return (width); 2.31 - return (0); /* $$$ */ 2.32 + return ((buf [x >> 3] >> (x & 7)) & 1); 2.33 +} 2.34 + 2.35 + 2.36 +static uint32_t g4_find_pixel (uint8_t *buf, 2.37 + uint32_t pos, 2.38 + uint32_t width, 2.39 + bool color) 2.40 +{ 2.41 + while (pos < width) 2.42 + { 2.43 + if (g4_get_pixel (buf, pos) == color) 2.44 + return (pos); 2.45 + pos++; 2.46 + } 2.47 + return (width); 2.48 } 2.49 2.50 2.51 @@ -149,22 +161,19 @@ 2.52 uint8_t *ref, 2.53 uint8_t *row) 2.54 { 2.55 - int a0, a1, a2; 2.56 - int b1, b2; 2.57 + uint32_t a0, a1, a2; 2.58 + uint32_t b1, b2; 2.59 + bool a0_c; 2.60 2.61 - a0 = -1; 2.62 + a0 = 0; 2.63 + a0_c = 0; 2.64 + 2.65 + a1 = g4_find_pixel (row, 0, width, 1); 2.66 + b1 = g4_find_pixel (ref, 0, width, 1); 2.67 2.68 while (a0 < width) 2.69 { 2.70 - /* find a1, a2 */ 2.71 - a1 = find_transition (row, a0, width); 2.72 - a2 = find_transition (row, a1, width); 2.73 - 2.74 - /* find b1, b2 */ 2.75 - b1 = find_transition (ref, a0, width); 2.76 - if (0) /* $$$ b1 color = a0 color */ 2.77 - b1 = find_transition (ref, b1, width); 2.78 - b2 = find_transition (ref, b2, width); 2.79 + b2 = g4_find_pixel (ref, b1 + 1, width, g4_get_pixel (ref, b1)); 2.80 2.81 if (b2 < a1) 2.82 { 2.83 @@ -183,22 +192,41 @@ 2.84 else 2.85 { 2.86 /* horizontal mode - 001 */ 2.87 + a2 = g4_find_pixel (row, a1, width, a0_c); 2.88 write_bits (buf, 3, 0x1); 2.89 - g4_encode_horizontal_run (buf, 0 /* $$$ color (a0) */, a1 - a0); 2.90 - g4_encode_horizontal_run (buf, 1 /* $$$ color (a1) */, a2 - a1); 2.91 + g4_encode_horizontal_run (buf, a0_c, a1 - a0); 2.92 + g4_encode_horizontal_run (buf, ! a0_c, a2 - a1); 2.93 a0 = a2; 2.94 } 2.95 + 2.96 + if (a0 >= width) 2.97 + break;; 2.98 + 2.99 + a0_c = g4_get_pixel (row, a0); 2.100 + 2.101 + a1 = g4_find_pixel (row, a0 + 1, width, ! a0_c); 2.102 + b1 = g4_find_pixel (ref, a0 + 1, width, a0_c); 2.103 + b1 = g4_find_pixel (ref, b1 + 1, width, ! a0_c); 2.104 } 2.105 } 2.106 2.107 2.108 void bitblt_write_g4 (Bitmap *bitmap, FILE *f) 2.109 { 2.110 + uint32_t width = (bitmap->rect.max.x - bitmap->rect.min.x) + 1; 2.111 uint32_t row; 2.112 struct bit_buffer bb; 2.113 2.114 - word_type *ref_line = NULL; /* reference (previous) row */ 2.115 - word_type *line = bitmap->bits; 2.116 + word_type *temp_buffer; 2.117 + 2.118 + word_type *cur_line; 2.119 + word_type *ref_line; /* reference (previous) row */ 2.120 + 2.121 + temp_buffer = pdf_calloc ((width + BITS_PER_WORD - 1) / BITS_PER_WORD, 2.122 + sizeof (word_type)); 2.123 + 2.124 + cur_line = bitmap->bits; 2.125 + ref_line = temp_buffer; 2.126 2.127 memset (& bb, 0, sizeof (bb)); 2.128 2.129 @@ -209,11 +237,11 @@ 2.130 row++) 2.131 { 2.132 g4_encode_row (& bb, 2.133 - (bitmap->rect.max.x - bitmap->rect.min.x) + 1, 2.134 + width, 2.135 (uint8_t *) ref_line, 2.136 - (uint8_t *) line); 2.137 - ref_line = line; 2.138 - line += bitmap->row_words; 2.139 + (uint8_t *) cur_line); 2.140 + ref_line = cur_line; 2.141 + cur_line += bitmap->row_words; 2.142 } 2.143 2.144 2.145 @@ -221,6 +249,8 @@ 2.146 write_bits (& bb, 24, 0x001001); 2.147 2.148 flush_bits (& bb); 2.149 + 2.150 + free (temp_buffer); 2.151 } 2.152 2.153
3.1 --- a/pdf_util.c Mon Mar 10 09:58:34 2003 +0000 3.2 +++ b/pdf_util.c Mon Mar 10 13:08:25 2003 +0000 3.3 @@ -4,7 +4,7 @@ 3.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 3.5 * 3.6 * PDF routines 3.7 - * $Id: pdf_util.c,v 1.4 2003/02/21 02:49:11 eric Exp $ 3.8 + * $Id: pdf_util.c,v 1.5 2003/03/10 05:08:25 eric Exp $ 3.9 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 3.10 * 3.11 * This program is free software; you can redistribute it and/or modify 3.12 @@ -32,7 +32,6 @@ 3.13 #include <string.h> 3.14 3.15 #include "bitblt.h" 3.16 -#include "pdf.h" 3.17 #include "pdf_util.h" 3.18 3.19
4.1 --- a/t2p.c Mon Mar 10 09:58:34 2003 +0000 4.2 +++ b/t2p.c Mon Mar 10 13:08:25 2003 +0000 4.3 @@ -4,7 +4,7 @@ 4.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 4.5 * 4.6 * Main program 4.7 - * $Id: t2p.c,v 1.27 2003/03/10 01:58:09 eric Exp $ 4.8 + * $Id: t2p.c,v 1.28 2003/03/10 05:08:25 eric Exp $ 4.9 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 4.10 * 4.11 * This program is free software; you can redistribute it and/or modify 4.12 @@ -304,7 +304,7 @@ 4.13 uint16_t planar_config; 4.14 4.15 uint16_t resolution_unit; 4.16 - double x_resolution, y_resolution; 4.17 + float x_resolution, y_resolution; 4.18 double dest_x_resolution, dest_y_resolution; 4.19 4.20 double width_points, height_points; /* really 1/72 inch units rather than 4.21 @@ -439,20 +439,17 @@ 4.22 image_length * bitmap->row_words * sizeof (word_type)); 4.23 #endif /* TIFF_REVERSE_BITS */ 4.24 4.25 +#if 0 4.26 if (input_attributes.has_page_size) 4.27 bitmap = resize_bitmap (bitmap, 4.28 x_resolution, 4.29 y_resolution, 4.30 input_attributes); 4.31 +#endif 4.32 4.33 rotate_bitmap (bitmap, 4.34 input_attributes); 4.35 4.36 -#ifdef TIFF_REVERSE_BITS 4.37 - reverse_bits ((uint8_t *) bitmap->bits, 4.38 - image_length * bitmap->row_words * sizeof (word_type)); 4.39 -#endif /* TIFF_REVERSE_BITS */ 4.40 - 4.41 width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; 4.42 height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; 4.43 4.44 @@ -464,7 +461,6 @@ 4.45 4.46 page = pdf_new_page (out->pdf, width_points, height_points); 4.47 4.48 -#if 0 4.49 pdf_write_g4_fax_image (page, 4.50 0, 0, /* x, y */ 4.51 width_points, height_points, 4.52 @@ -472,7 +468,6 @@ 4.53 0, /* ImageMask */ 4.54 0, 0, 0, /* r, g, b */ 4.55 0); /* BlackIs1 */ 4.56 -#endif 4.57 4.58 while (bookmarks) 4.59 {
5.1 --- a/tumble.c Mon Mar 10 09:58:34 2003 +0000 5.2 +++ b/tumble.c Mon Mar 10 13:08:25 2003 +0000 5.3 @@ -4,7 +4,7 @@ 5.4 * will be compressed using ITU-T T.6 (G4) fax encoding. 5.5 * 5.6 * Main program 5.7 - * $Id: tumble.c,v 1.27 2003/03/10 01:58:09 eric Exp $ 5.8 + * $Id: tumble.c,v 1.28 2003/03/10 05:08:25 eric Exp $ 5.9 * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com> 5.10 * 5.11 * This program is free software; you can redistribute it and/or modify 5.12 @@ -304,7 +304,7 @@ 5.13 uint16_t planar_config; 5.14 5.15 uint16_t resolution_unit; 5.16 - double x_resolution, y_resolution; 5.17 + float x_resolution, y_resolution; 5.18 double dest_x_resolution, dest_y_resolution; 5.19 5.20 double width_points, height_points; /* really 1/72 inch units rather than 5.21 @@ -439,20 +439,17 @@ 5.22 image_length * bitmap->row_words * sizeof (word_type)); 5.23 #endif /* TIFF_REVERSE_BITS */ 5.24 5.25 +#if 0 5.26 if (input_attributes.has_page_size) 5.27 bitmap = resize_bitmap (bitmap, 5.28 x_resolution, 5.29 y_resolution, 5.30 input_attributes); 5.31 +#endif 5.32 5.33 rotate_bitmap (bitmap, 5.34 input_attributes); 5.35 5.36 -#ifdef TIFF_REVERSE_BITS 5.37 - reverse_bits ((uint8_t *) bitmap->bits, 5.38 - image_length * bitmap->row_words * sizeof (word_type)); 5.39 -#endif /* TIFF_REVERSE_BITS */ 5.40 - 5.41 width_points = (rect_width (& bitmap->rect) / dest_x_resolution) * POINTS_PER_INCH; 5.42 height_points = (rect_height (& bitmap->rect) / dest_y_resolution) * POINTS_PER_INCH; 5.43 5.44 @@ -464,7 +461,6 @@ 5.45 5.46 page = pdf_new_page (out->pdf, width_points, height_points); 5.47 5.48 -#if 0 5.49 pdf_write_g4_fax_image (page, 5.50 0, 0, /* x, y */ 5.51 width_points, height_points, 5.52 @@ -472,7 +468,6 @@ 5.53 0, /* ImageMask */ 5.54 0, 0, 0, /* r, g, b */ 5.55 0); /* BlackIs1 */ 5.56 -#endif 5.57 5.58 while (bookmarks) 5.59 {