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