Tue, 01 Jan 2002 05:02:44 +0000
create temporary TIFF file.
t2p.c | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions |
1.1 --- a/t2p.c Tue Jan 01 03:46:08 2002 +0000 1.2 +++ b/t2p.c Tue Jan 01 05:02:44 2002 +0000 1.3 @@ -1,7 +1,7 @@ 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.8 2001/12/31 19:44:40 eric Exp $ 1.8 + * $Id: t2p.c,v 1.9 2001/12/31 21:02:44 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 @@ -22,6 +22,8 @@ 1.13 1.14 1.15 #include <stdio.h> 1.16 +#include <stdlib.h> 1.17 +#include <unistd.h> 1.18 #include <tiffio.h> 1.19 #include <panda/functions.h> 1.20 #include <panda/constants.h> 1.21 @@ -33,6 +35,13 @@ 1.22 #include "tiff2pdf.h" 1.23 1.24 1.25 +#define POINTS_PER_INCH 72 1.26 + 1.27 +/* page size limited by Acrobat Reader to 45 inches on a side */ 1.28 +#define PAGE_MAX_INCHES 45 1.29 +#define PAGE_MAX_POINTS (PAGE_MAX_INCHES * POINTS_PER_INCH) 1.30 + 1.31 + 1.32 typedef struct output_file_t 1.33 { 1.34 struct output_file_t *next; 1.35 @@ -166,10 +175,23 @@ 1.36 u16 planar_config; 1.37 u16 resolution_unit; 1.38 float x_resolution, y_resolution; 1.39 + int width_points, height_points; /* really 1/72 inch units rather than 1.40 + points */ 1.41 + 1.42 1.43 char *buffer; 1.44 u32 row; 1.45 1.46 + panda_page *page; 1.47 + 1.48 + int tiff_temp_fd; 1.49 + char tiff_temp_fn [] = "/var/tmp/tiff2pdf-XXXXXX\0"; 1.50 + TIFF *tiff_temp; 1.51 + 1.52 + char pagesize [26]; /* Needs to hold two ints of four characters (0..3420), 1.53 + two zeros, three spaces, two brackets, and a NULL. 1.54 + Added an extra ten characters just in case. */ 1.55 + 1.56 if (! TIFFSetDirectory (in, image - 1)) 1.57 { 1.58 fprintf (stderr, "can't find page %d of input file\n", image); 1.59 @@ -243,21 +265,33 @@ 1.60 goto fail; 1.61 } 1.62 1.63 -#if 0 1.64 - TIFFSetField (out->pdf, TIFFTAG_IMAGELENGTH, image_length); 1.65 - TIFFSetField (out->pdf, TIFFTAG_IMAGEWIDTH, image_width); 1.66 - TIFFSetField (out->pdf, TIFFTAG_PLANARCONFIG, planar_config); 1.67 + tiff_temp_fd = mkstemp (tiff_temp_fn); 1.68 + if (tiff_temp_fd < 0) 1.69 + { 1.70 + fprintf (stderr, "can't create temporary TIFF file\n"); 1.71 + goto fail; 1.72 + } 1.73 1.74 - TIFFSetField (out->pdf, TIFFTAG_ROWSPERSTRIP, image_length); 1.75 + tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 1.76 + if (! out) 1.77 + { 1.78 + fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 1.79 + goto fail; 1.80 + } 1.81 1.82 - TIFFSetField (out->pdf, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 1.83 - TIFFSetField (out->pdf, TIFFTAG_XRESOLUTION, x_resolution); 1.84 - TIFFSetField (out->pdf, TIFFTAG_YRESOLUTION, y_resolution); 1.85 + TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, image_length); 1.86 + TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, image_width); 1.87 + TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 1.88 + 1.89 + TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, image_length); 1.90 1.91 - TIFFSetField (out->pdf, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 1.92 - TIFFSetField (out->pdf, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 1.93 - TIFFSetField (out->pdf, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 1.94 -#endif 1.95 + TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 1.96 + TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, x_resolution); 1.97 + TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, y_resolution); 1.98 + 1.99 + TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 1.100 + TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 1.101 + TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 1.102 1.103 buffer = _TIFFmalloc (TIFFScanlineSize (in)); 1.104 if (! buffer) 1.105 @@ -269,12 +303,36 @@ 1.106 for (row = 0; row < image_length; row++) 1.107 { 1.108 TIFFReadScanline (in, buffer, row, 0); 1.109 -#if 0 1.110 - TIFFWriteScanline (out->pdf, buffer, row, 0); 1.111 -#endif 1.112 + TIFFWriteScanline (tiff_temp, buffer, row, 0); 1.113 } 1.114 1.115 _TIFFfree (buffer); 1.116 + TIFFClose (tiff_temp); 1.117 + 1.118 + height_points = (image_width / x_resolution) * POINTS_PER_INCH; 1.119 + width_points = (image_length / y_resolution) * POINTS_PER_INCH; 1.120 + 1.121 + if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 1.122 + { 1.123 + fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 1.124 + goto fail; 1.125 + } 1.126 + 1.127 + printf ("height_points %d, width_points %d\n", height_points, width_points); 1.128 + 1.129 + sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); 1.130 + 1.131 + page = panda_newpage (out->pdf, pagesize); 1.132 + panda_imagebox (out->pdf, 1.133 + page, 1.134 + 0, /* top */ 1.135 + 0, /* left */ 1.136 + height_points, /* bottom */ 1.137 + width_points, /* right */ 1.138 + tiff_temp_fn, 1.139 + panda_image_tiff); 1.140 + 1.141 + unlink (tiff_temp_fn); 1.142 1.143 return (1); 1.144
2.1 --- a/tumble.c Tue Jan 01 03:46:08 2002 +0000 2.2 +++ b/tumble.c Tue Jan 01 05:02:44 2002 +0000 2.3 @@ -1,7 +1,7 @@ 2.4 /* 2.5 * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4 2.6 * Main program 2.7 - * $Id: tumble.c,v 1.8 2001/12/31 19:44:40 eric Exp $ 2.8 + * $Id: tumble.c,v 1.9 2001/12/31 21:02:44 eric Exp $ 2.9 * Copyright 2001 Eric Smith <eric@brouhaha.com> 2.10 * 2.11 * This program is free software; you can redistribute it and/or modify 2.12 @@ -22,6 +22,8 @@ 2.13 2.14 2.15 #include <stdio.h> 2.16 +#include <stdlib.h> 2.17 +#include <unistd.h> 2.18 #include <tiffio.h> 2.19 #include <panda/functions.h> 2.20 #include <panda/constants.h> 2.21 @@ -33,6 +35,13 @@ 2.22 #include "tiff2pdf.h" 2.23 2.24 2.25 +#define POINTS_PER_INCH 72 2.26 + 2.27 +/* page size limited by Acrobat Reader to 45 inches on a side */ 2.28 +#define PAGE_MAX_INCHES 45 2.29 +#define PAGE_MAX_POINTS (PAGE_MAX_INCHES * POINTS_PER_INCH) 2.30 + 2.31 + 2.32 typedef struct output_file_t 2.33 { 2.34 struct output_file_t *next; 2.35 @@ -166,10 +175,23 @@ 2.36 u16 planar_config; 2.37 u16 resolution_unit; 2.38 float x_resolution, y_resolution; 2.39 + int width_points, height_points; /* really 1/72 inch units rather than 2.40 + points */ 2.41 + 2.42 2.43 char *buffer; 2.44 u32 row; 2.45 2.46 + panda_page *page; 2.47 + 2.48 + int tiff_temp_fd; 2.49 + char tiff_temp_fn [] = "/var/tmp/tiff2pdf-XXXXXX\0"; 2.50 + TIFF *tiff_temp; 2.51 + 2.52 + char pagesize [26]; /* Needs to hold two ints of four characters (0..3420), 2.53 + two zeros, three spaces, two brackets, and a NULL. 2.54 + Added an extra ten characters just in case. */ 2.55 + 2.56 if (! TIFFSetDirectory (in, image - 1)) 2.57 { 2.58 fprintf (stderr, "can't find page %d of input file\n", image); 2.59 @@ -243,21 +265,33 @@ 2.60 goto fail; 2.61 } 2.62 2.63 -#if 0 2.64 - TIFFSetField (out->pdf, TIFFTAG_IMAGELENGTH, image_length); 2.65 - TIFFSetField (out->pdf, TIFFTAG_IMAGEWIDTH, image_width); 2.66 - TIFFSetField (out->pdf, TIFFTAG_PLANARCONFIG, planar_config); 2.67 + tiff_temp_fd = mkstemp (tiff_temp_fn); 2.68 + if (tiff_temp_fd < 0) 2.69 + { 2.70 + fprintf (stderr, "can't create temporary TIFF file\n"); 2.71 + goto fail; 2.72 + } 2.73 2.74 - TIFFSetField (out->pdf, TIFFTAG_ROWSPERSTRIP, image_length); 2.75 + tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 2.76 + if (! out) 2.77 + { 2.78 + fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 2.79 + goto fail; 2.80 + } 2.81 2.82 - TIFFSetField (out->pdf, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 2.83 - TIFFSetField (out->pdf, TIFFTAG_XRESOLUTION, x_resolution); 2.84 - TIFFSetField (out->pdf, TIFFTAG_YRESOLUTION, y_resolution); 2.85 + TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, image_length); 2.86 + TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, image_width); 2.87 + TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 2.88 + 2.89 + TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, image_length); 2.90 2.91 - TIFFSetField (out->pdf, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 2.92 - TIFFSetField (out->pdf, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 2.93 - TIFFSetField (out->pdf, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 2.94 -#endif 2.95 + TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 2.96 + TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, x_resolution); 2.97 + TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, y_resolution); 2.98 + 2.99 + TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 2.100 + TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 2.101 + TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 2.102 2.103 buffer = _TIFFmalloc (TIFFScanlineSize (in)); 2.104 if (! buffer) 2.105 @@ -269,12 +303,36 @@ 2.106 for (row = 0; row < image_length; row++) 2.107 { 2.108 TIFFReadScanline (in, buffer, row, 0); 2.109 -#if 0 2.110 - TIFFWriteScanline (out->pdf, buffer, row, 0); 2.111 -#endif 2.112 + TIFFWriteScanline (tiff_temp, buffer, row, 0); 2.113 } 2.114 2.115 _TIFFfree (buffer); 2.116 + TIFFClose (tiff_temp); 2.117 + 2.118 + height_points = (image_width / x_resolution) * POINTS_PER_INCH; 2.119 + width_points = (image_length / y_resolution) * POINTS_PER_INCH; 2.120 + 2.121 + if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 2.122 + { 2.123 + fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 2.124 + goto fail; 2.125 + } 2.126 + 2.127 + printf ("height_points %d, width_points %d\n", height_points, width_points); 2.128 + 2.129 + sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); 2.130 + 2.131 + page = panda_newpage (out->pdf, pagesize); 2.132 + panda_imagebox (out->pdf, 2.133 + page, 2.134 + 0, /* top */ 2.135 + 0, /* left */ 2.136 + height_points, /* bottom */ 2.137 + width_points, /* right */ 2.138 + tiff_temp_fn, 2.139 + panda_image_tiff); 2.140 + 2.141 + unlink (tiff_temp_fn); 2.142 2.143 return (1); 2.144