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