Sat, 29 Dec 2001 17:44:57 +0000
Initial revision
t2p.c | file | annotate | diff | revisions | |
t2p.h | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions | |
tumble.h | file | annotate | diff | revisions | |
type.h | file | annotate | diff | revisions |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/t2p.c Sat Dec 29 17:44:57 2001 +0000 1.3 @@ -0,0 +1,238 @@ 1.4 +/* 1.5 + * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 1.6 + * Main program 1.7 + * $Id: t2p.c,v 1.1 2001/12/29 09:44:24 eric Exp $ 1.8 + * Copyright 2001 Eric Smith <eric@brouhaha.com> 1.9 + * 1.10 + * This program is free software; you can redistribute it and/or modify 1.11 + * it under the terms of the GNU General Public License version 2 as 1.12 + * published by the Free Software Foundation. Note that permission is 1.13 + * not granted to redistribute this program under the terms of any 1.14 + * other version of the General Public License. 1.15 + * 1.16 + * This program is distributed in the hope that it will be useful, 1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.19 + * GNU General Public License for more details. 1.20 + * 1.21 + * You should have received a copy of the GNU General Public License 1.22 + * along with this program; if not, write to the Free Software 1.23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 1.24 + */ 1.25 + 1.26 + 1.27 +#include <stdio.h> 1.28 +#include <tiffio.h> 1.29 +#include <panda/functions.h> 1.30 +#include <panda/constants.h> 1.31 + 1.32 +#include "type.h" 1.33 +#include "bitblt.h" 1.34 +#include "parser.tab.h" 1.35 +#include "tiff2pdf.h" 1.36 + 1.37 + 1.38 +TIFF *in; 1.39 +panda_pdf *out; 1.40 + 1.41 + 1.42 +boolean close_tiff_input_file (void) 1.43 +{ 1.44 + if (in) 1.45 + TIFFClose (in); 1.46 + in = NULL; 1.47 + return (1); 1.48 +} 1.49 + 1.50 +boolean open_tiff_input_file (char *name) 1.51 +{ 1.52 + if (in) 1.53 + close_tiff_input_file (); 1.54 + in = TIFFOpen (name, "r"); 1.55 + if (! in) 1.56 + { 1.57 + fprintf (stderr, "can't open input file '%s'\n", name); 1.58 + return (0); 1.59 + } 1.60 + return (1); 1.61 +} 1.62 + 1.63 + 1.64 +boolean close_pdf_output_file (void) 1.65 +{ 1.66 + if (out) 1.67 + panda_close (out); 1.68 + out = NULL; 1.69 + return (1); 1.70 +} 1.71 + 1.72 +boolean open_pdf_output_file (char *name) 1.73 +{ 1.74 + if (out) 1.75 + close_pdf_output_file (); 1.76 + out = panda_open (name, "w"); 1.77 + if (! out) 1.78 + { 1.79 + return (0); 1.80 + } 1.81 + return (1); 1.82 +} 1.83 + 1.84 + 1.85 +boolean process_page (int image) /* range 1 .. n */ 1.86 +{ 1.87 + u32 image_length, image_width; 1.88 +#ifdef CHECK_DEPTH 1.89 + u32 image_depth; 1.90 +#endif 1.91 + u16 bits_per_sample; 1.92 + u16 planar_config; 1.93 + u16 resolution_unit; 1.94 + float x_resolution, y_resolution; 1.95 + 1.96 + char *buffer; 1.97 + u32 row; 1.98 + 1.99 + if (! TIFFSetDirectory (in, image - 1)) 1.100 + { 1.101 + fprintf (stderr, "can't find page %d of input file\n", image); 1.102 + goto fail; 1.103 + } 1.104 + if (1 != TIFFGetField (in, TIFFTAG_IMAGELENGTH, & image_length)) 1.105 + { 1.106 + fprintf (stderr, "can't get image length\n"); 1.107 + goto fail; 1.108 + } 1.109 + if (1 != TIFFGetField (in, TIFFTAG_IMAGEWIDTH, & image_width)) 1.110 + { 1.111 + fprintf (stderr, "can't get image width\n"); 1.112 + goto fail; 1.113 + } 1.114 +#ifdef CHECK_DEPTH 1.115 + if (1 != TIFFGetField (in, TIFFTAG_IMAGEDEPTH, & image_depth)) 1.116 + { 1.117 + fprintf (stderr, "can't get image depth\n"); 1.118 + goto fail; 1.119 + } 1.120 +#endif 1.121 + 1.122 + if (1 != TIFFGetField (in, TIFFTAG_BITSPERSAMPLE, & bits_per_sample)) 1.123 + { 1.124 + fprintf (stderr, "can't get bits per sample\n"); 1.125 + goto fail; 1.126 + } 1.127 + 1.128 + if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) 1.129 + planar_config = 1; 1.130 + 1.131 + printf ("image length %u width %u, " 1.132 +#ifdef CHECK_DEPTH 1.133 + "depth %u, " 1.134 +#endif 1.135 + "planar config %u\n", 1.136 + image_length, image_width, 1.137 +#ifdef CHECK_DEPTH 1.138 + image_depth, 1.139 +#endif 1.140 + planar_config); 1.141 + 1.142 + if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) 1.143 + resolution_unit = 2; 1.144 + if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) 1.145 + x_resolution = 300; 1.146 + if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) 1.147 + y_resolution = 300; 1.148 + 1.149 + printf ("resolution unit %u, x resolution %f, y resolution %f\n", 1.150 + resolution_unit, x_resolution, y_resolution); 1.151 + 1.152 +#ifdef CHECK_DEPTH 1.153 + if (image_depth != 1) 1.154 + { 1.155 + fprintf (stderr, "image depth %u, must be 1\n", image_depth); 1.156 + goto fail; 1.157 + } 1.158 +#endif 1.159 + 1.160 + if (bits_per_sample != 1) 1.161 + { 1.162 + fprintf (stderr, "bits per sample %u, must be 1\n", bits_per_sample); 1.163 + goto fail; 1.164 + } 1.165 + 1.166 + if (planar_config != 1) 1.167 + { 1.168 + fprintf (stderr, "planar config %u, must be 1\n", planar_config); 1.169 + goto fail; 1.170 + } 1.171 + 1.172 +#if 0 1.173 + TIFFSetField (out, TIFFTAG_IMAGELENGTH, image_length); 1.174 + TIFFSetField (out, TIFFTAG_IMAGEWIDTH, image_width); 1.175 + TIFFSetField (out, TIFFTAG_PLANARCONFIG, planar_config); 1.176 + 1.177 + TIFFSetField (out, TIFFTAG_ROWSPERSTRIP, image_length); 1.178 + 1.179 + TIFFSetField (out, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 1.180 + TIFFSetField (out, TIFFTAG_XRESOLUTION, x_resolution); 1.181 + TIFFSetField (out, TIFFTAG_YRESOLUTION, y_resolution); 1.182 + 1.183 + TIFFSetField (out, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 1.184 + TIFFSetField (out, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 1.185 + TIFFSetField (out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 1.186 +#endif 1.187 + 1.188 + buffer = _TIFFmalloc (TIFFScanlineSize (in)); 1.189 + if (! buffer) 1.190 + { 1.191 + fprintf (stderr, "failed to allocate buffer\n"); 1.192 + goto fail; 1.193 + } 1.194 + 1.195 + for (row = 0; row < image_length; row++) 1.196 + { 1.197 + TIFFReadScanline (in, buffer, row, 0); 1.198 +#if 0 1.199 + TIFFWriteScanline (out, buffer, row, 0); 1.200 +#endif 1.201 + } 1.202 + 1.203 + _TIFFfree (buffer); 1.204 + 1.205 + return (1); 1.206 + 1.207 + fail: 1.208 + return (0); 1.209 +} 1.210 + 1.211 + 1.212 + 1.213 +int main (int argc, char *argv[]) 1.214 +{ 1.215 + FILE *spec; 1.216 + int result = 0; 1.217 + 1.218 + panda_init (); 1.219 + 1.220 + if (argc != 2) 1.221 + { 1.222 + fprintf (stderr, "usage: %s spec\n", argv [0]); 1.223 + result = 1; 1.224 + goto fail; 1.225 + } 1.226 + 1.227 + spec = fopen (argv [2], "r"); 1.228 + if (! spec) 1.229 + { 1.230 + fprintf (stderr, "can't open spec file '%s'\n", argv [2]); 1.231 + result = 3; 1.232 + goto fail; 1.233 + } 1.234 + 1.235 + yyparse (); 1.236 + 1.237 + fail: 1.238 + close_tiff_input_file (); 1.239 + close_pdf_output_file (); 1.240 + return (result); 1.241 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/t2p.h Sat Dec 29 17:44:57 2001 +0000 2.3 @@ -0,0 +1,7 @@ 2.4 +boolean open_tiff_input_file (char *name); 2.5 +boolean close_tiff_input_file (void); 2.6 + 2.7 +boolean open_pdf_output_file (char *name); 2.8 +boolean close_pdf_output_file (void); 2.9 + 2.10 +boolean process_page (int image); /* range 1 .. n */
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 3.2 +++ b/tumble.c Sat Dec 29 17:44:57 2001 +0000 3.3 @@ -0,0 +1,238 @@ 3.4 +/* 3.5 + * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 3.6 + * Main program 3.7 + * $Id: tumble.c,v 1.1 2001/12/29 09:44:24 eric Exp $ 3.8 + * Copyright 2001 Eric Smith <eric@brouhaha.com> 3.9 + * 3.10 + * This program is free software; you can redistribute it and/or modify 3.11 + * it under the terms of the GNU General Public License version 2 as 3.12 + * published by the Free Software Foundation. Note that permission is 3.13 + * not granted to redistribute this program under the terms of any 3.14 + * other version of the General Public License. 3.15 + * 3.16 + * This program is distributed in the hope that it will be useful, 3.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 3.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 3.19 + * GNU General Public License for more details. 3.20 + * 3.21 + * You should have received a copy of the GNU General Public License 3.22 + * along with this program; if not, write to the Free Software 3.23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA 3.24 + */ 3.25 + 3.26 + 3.27 +#include <stdio.h> 3.28 +#include <tiffio.h> 3.29 +#include <panda/functions.h> 3.30 +#include <panda/constants.h> 3.31 + 3.32 +#include "type.h" 3.33 +#include "bitblt.h" 3.34 +#include "parser.tab.h" 3.35 +#include "tiff2pdf.h" 3.36 + 3.37 + 3.38 +TIFF *in; 3.39 +panda_pdf *out; 3.40 + 3.41 + 3.42 +boolean close_tiff_input_file (void) 3.43 +{ 3.44 + if (in) 3.45 + TIFFClose (in); 3.46 + in = NULL; 3.47 + return (1); 3.48 +} 3.49 + 3.50 +boolean open_tiff_input_file (char *name) 3.51 +{ 3.52 + if (in) 3.53 + close_tiff_input_file (); 3.54 + in = TIFFOpen (name, "r"); 3.55 + if (! in) 3.56 + { 3.57 + fprintf (stderr, "can't open input file '%s'\n", name); 3.58 + return (0); 3.59 + } 3.60 + return (1); 3.61 +} 3.62 + 3.63 + 3.64 +boolean close_pdf_output_file (void) 3.65 +{ 3.66 + if (out) 3.67 + panda_close (out); 3.68 + out = NULL; 3.69 + return (1); 3.70 +} 3.71 + 3.72 +boolean open_pdf_output_file (char *name) 3.73 +{ 3.74 + if (out) 3.75 + close_pdf_output_file (); 3.76 + out = panda_open (name, "w"); 3.77 + if (! out) 3.78 + { 3.79 + return (0); 3.80 + } 3.81 + return (1); 3.82 +} 3.83 + 3.84 + 3.85 +boolean process_page (int image) /* range 1 .. n */ 3.86 +{ 3.87 + u32 image_length, image_width; 3.88 +#ifdef CHECK_DEPTH 3.89 + u32 image_depth; 3.90 +#endif 3.91 + u16 bits_per_sample; 3.92 + u16 planar_config; 3.93 + u16 resolution_unit; 3.94 + float x_resolution, y_resolution; 3.95 + 3.96 + char *buffer; 3.97 + u32 row; 3.98 + 3.99 + if (! TIFFSetDirectory (in, image - 1)) 3.100 + { 3.101 + fprintf (stderr, "can't find page %d of input file\n", image); 3.102 + goto fail; 3.103 + } 3.104 + if (1 != TIFFGetField (in, TIFFTAG_IMAGELENGTH, & image_length)) 3.105 + { 3.106 + fprintf (stderr, "can't get image length\n"); 3.107 + goto fail; 3.108 + } 3.109 + if (1 != TIFFGetField (in, TIFFTAG_IMAGEWIDTH, & image_width)) 3.110 + { 3.111 + fprintf (stderr, "can't get image width\n"); 3.112 + goto fail; 3.113 + } 3.114 +#ifdef CHECK_DEPTH 3.115 + if (1 != TIFFGetField (in, TIFFTAG_IMAGEDEPTH, & image_depth)) 3.116 + { 3.117 + fprintf (stderr, "can't get image depth\n"); 3.118 + goto fail; 3.119 + } 3.120 +#endif 3.121 + 3.122 + if (1 != TIFFGetField (in, TIFFTAG_BITSPERSAMPLE, & bits_per_sample)) 3.123 + { 3.124 + fprintf (stderr, "can't get bits per sample\n"); 3.125 + goto fail; 3.126 + } 3.127 + 3.128 + if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) 3.129 + planar_config = 1; 3.130 + 3.131 + printf ("image length %u width %u, " 3.132 +#ifdef CHECK_DEPTH 3.133 + "depth %u, " 3.134 +#endif 3.135 + "planar config %u\n", 3.136 + image_length, image_width, 3.137 +#ifdef CHECK_DEPTH 3.138 + image_depth, 3.139 +#endif 3.140 + planar_config); 3.141 + 3.142 + if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) 3.143 + resolution_unit = 2; 3.144 + if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) 3.145 + x_resolution = 300; 3.146 + if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) 3.147 + y_resolution = 300; 3.148 + 3.149 + printf ("resolution unit %u, x resolution %f, y resolution %f\n", 3.150 + resolution_unit, x_resolution, y_resolution); 3.151 + 3.152 +#ifdef CHECK_DEPTH 3.153 + if (image_depth != 1) 3.154 + { 3.155 + fprintf (stderr, "image depth %u, must be 1\n", image_depth); 3.156 + goto fail; 3.157 + } 3.158 +#endif 3.159 + 3.160 + if (bits_per_sample != 1) 3.161 + { 3.162 + fprintf (stderr, "bits per sample %u, must be 1\n", bits_per_sample); 3.163 + goto fail; 3.164 + } 3.165 + 3.166 + if (planar_config != 1) 3.167 + { 3.168 + fprintf (stderr, "planar config %u, must be 1\n", planar_config); 3.169 + goto fail; 3.170 + } 3.171 + 3.172 +#if 0 3.173 + TIFFSetField (out, TIFFTAG_IMAGELENGTH, image_length); 3.174 + TIFFSetField (out, TIFFTAG_IMAGEWIDTH, image_width); 3.175 + TIFFSetField (out, TIFFTAG_PLANARCONFIG, planar_config); 3.176 + 3.177 + TIFFSetField (out, TIFFTAG_ROWSPERSTRIP, image_length); 3.178 + 3.179 + TIFFSetField (out, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 3.180 + TIFFSetField (out, TIFFTAG_XRESOLUTION, x_resolution); 3.181 + TIFFSetField (out, TIFFTAG_YRESOLUTION, y_resolution); 3.182 + 3.183 + TIFFSetField (out, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 3.184 + TIFFSetField (out, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 3.185 + TIFFSetField (out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 3.186 +#endif 3.187 + 3.188 + buffer = _TIFFmalloc (TIFFScanlineSize (in)); 3.189 + if (! buffer) 3.190 + { 3.191 + fprintf (stderr, "failed to allocate buffer\n"); 3.192 + goto fail; 3.193 + } 3.194 + 3.195 + for (row = 0; row < image_length; row++) 3.196 + { 3.197 + TIFFReadScanline (in, buffer, row, 0); 3.198 +#if 0 3.199 + TIFFWriteScanline (out, buffer, row, 0); 3.200 +#endif 3.201 + } 3.202 + 3.203 + _TIFFfree (buffer); 3.204 + 3.205 + return (1); 3.206 + 3.207 + fail: 3.208 + return (0); 3.209 +} 3.210 + 3.211 + 3.212 + 3.213 +int main (int argc, char *argv[]) 3.214 +{ 3.215 + FILE *spec; 3.216 + int result = 0; 3.217 + 3.218 + panda_init (); 3.219 + 3.220 + if (argc != 2) 3.221 + { 3.222 + fprintf (stderr, "usage: %s spec\n", argv [0]); 3.223 + result = 1; 3.224 + goto fail; 3.225 + } 3.226 + 3.227 + spec = fopen (argv [2], "r"); 3.228 + if (! spec) 3.229 + { 3.230 + fprintf (stderr, "can't open spec file '%s'\n", argv [2]); 3.231 + result = 3; 3.232 + goto fail; 3.233 + } 3.234 + 3.235 + yyparse (); 3.236 + 3.237 + fail: 3.238 + close_tiff_input_file (); 3.239 + close_pdf_output_file (); 3.240 + return (result); 3.241 +}
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/tumble.h Sat Dec 29 17:44:57 2001 +0000 4.3 @@ -0,0 +1,7 @@ 4.4 +boolean open_tiff_input_file (char *name); 4.5 +boolean close_tiff_input_file (void); 4.6 + 4.7 +boolean open_pdf_output_file (char *name); 4.8 +boolean close_pdf_output_file (void); 4.9 + 4.10 +boolean process_page (int image); /* range 1 .. n */
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/type.h Sat Dec 29 17:44:57 2001 +0000 5.3 @@ -0,0 +1,4 @@ 5.4 +typedef unsigned char u8; 5.5 +typedef unsigned short u16; 5.6 +typedef unsigned int u32; 5.7 +typedef int boolean;