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