Wed, 02 Jan 2002 10:18:13 +0000
bug fixes.
semantics.c | file | annotate | diff | revisions | |
t2p.c | file | annotate | diff | revisions | |
t2p.h | file | annotate | diff | revisions | |
tumble.c | file | annotate | diff | revisions | |
tumble.h | file | annotate | diff | revisions |
1.1 diff -r 41804cc569ab -r a338db73c6f4 semantics.c 1.2 --- a/semantics.c Wed Jan 02 10:17:48 2002 +0000 1.3 +++ b/semantics.c Wed Jan 02 10:18:13 2002 +0000 1.4 @@ -71,7 +71,8 @@ 1.5 } output_page_t; 1.6 1.7 1.8 -#define SEMANTIC_DEBUG 1.9 +#undef SEMANTIC_DEBUG 1.10 + 1.11 #ifdef SEMANTIC_DEBUG 1.12 #define SDBG(x) printf x 1.13 #else 1.14 @@ -188,7 +189,6 @@ 1.15 { 1.16 last_input_context->modifiers [current_modifier_context].has_page_size = 1; 1.17 last_input_context->modifiers [current_modifier_context].page_size = size; 1.18 - printf ("page size %f, %f\n", size.width, size.height); 1.19 SDBG(("page size %f, %f\n", size.width, size.height)); 1.20 } 1.21
2.1 diff -r 41804cc569ab -r a338db73c6f4 t2p.c 2.2 --- a/t2p.c Wed Jan 02 10:17:48 2002 +0000 2.3 +++ b/t2p.c Wed Jan 02 10:18:13 2002 +0000 2.4 @@ -5,7 +5,7 @@ 2.5 * encoding. 2.6 * 2.7 * Main program 2.8 - * $Id: t2p.c,v 1.12 2002/01/01 02:16:50 eric Exp $ 2.9 + * $Id: t2p.c,v 1.13 2002/01/02 02:18:13 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 @@ -179,21 +179,37 @@ 2.14 } 2.15 2.16 2.17 -static Bitmap *rotate_bitmap (Bitmap *src, int rotation) 2.18 +static Bitmap *rotate_bitmap (Bitmap *src, 2.19 + float x_resolution, 2.20 + float y_resolution, 2.21 + input_attributes_t input_attributes) 2.22 { 2.23 Rect src_rect; 2.24 Point dest_upper_left; 2.25 int scan; 2.26 2.27 - src_rect.upper_left.x = 0; 2.28 - src_rect.upper_left.y = 0; 2.29 - src_rect.lower_right.x = src->width; 2.30 - src_rect.lower_right.y = src->height; 2.31 + if (input_attributes.has_page_size) 2.32 + { 2.33 + int width_pixels = input_attributes.page_size.width * x_resolution; 2.34 + int height_pixels = input_attributes.page_size.height * y_resolution; 2.35 + 2.36 + src_rect.upper_left.x = (src->width - width_pixels) / 2; 2.37 + src_rect.upper_left.y = (src->height - height_pixels) / 2; 2.38 + src_rect.lower_right.x = src_rect.upper_left.x + width_pixels; 2.39 + src_rect.lower_right.y = src_rect.upper_left.y + height_pixels; 2.40 + } 2.41 + else 2.42 + { 2.43 + src_rect.upper_left.x = 0; 2.44 + src_rect.upper_left.y = 0; 2.45 + src_rect.lower_right.x = src->width; 2.46 + src_rect.lower_right.y = src->height; 2.47 + } 2.48 2.49 dest_upper_left.x = 0; 2.50 dest_upper_left.y = 0; 2.51 2.52 - switch (rotation) 2.53 + switch (input_attributes.rotation) 2.54 { 2.55 case 0: scan = ROT_0; break; 2.56 case 90: scan = ROT_90; break; 2.57 @@ -293,17 +309,6 @@ 2.58 if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) 2.59 planar_config = 1; 2.60 2.61 - printf ("image length %u width %u, " 2.62 -#ifdef CHECK_DEPTH 2.63 - "depth %u, " 2.64 -#endif 2.65 - "planar config %u\n", 2.66 - image_length, image_width, 2.67 -#ifdef CHECK_DEPTH 2.68 - image_depth, 2.69 -#endif 2.70 - planar_config); 2.71 - 2.72 if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) 2.73 resolution_unit = 2; 2.74 if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) 2.75 @@ -311,9 +316,6 @@ 2.76 if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) 2.77 y_resolution = 300; 2.78 2.79 - printf ("resolution unit %u, x resolution %f, y resolution %f\n", 2.80 - resolution_unit, x_resolution, y_resolution); 2.81 - 2.82 if (samples_per_pixel != 1) 2.83 { 2.84 fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel); 2.85 @@ -340,33 +342,12 @@ 2.86 goto fail; 2.87 } 2.88 2.89 - width_points = (image_width / x_resolution) * POINTS_PER_INCH; 2.90 - height_points = (image_length / y_resolution) * POINTS_PER_INCH; 2.91 - 2.92 - if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 2.93 + if (input_attributes.has_resolution) 2.94 { 2.95 - fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 2.96 - goto fail; 2.97 + x_resolution = input_attributes.x_resolution; 2.98 + y_resolution = input_attributes.y_resolution; 2.99 } 2.100 2.101 - printf ("height_points %d, width_points %d\n", height_points, width_points); 2.102 - 2.103 - tiff_temp_fd = mkstemp (tiff_temp_fn); 2.104 - if (tiff_temp_fd < 0) 2.105 - { 2.106 - fprintf (stderr, "can't create temporary TIFF file\n"); 2.107 - goto fail; 2.108 - } 2.109 - 2.110 - tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 2.111 - if (! out) 2.112 - { 2.113 - fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 2.114 - goto fail; 2.115 - } 2.116 - 2.117 - printf ("rotation %d\n", input_attributes.rotation); 2.118 - 2.119 if ((input_attributes.rotation == 90) || (input_attributes.rotation == 270)) 2.120 { 2.121 dest_image_width = image_length; 2.122 @@ -383,21 +364,6 @@ 2.123 dest_y_resolution = y_resolution; 2.124 } 2.125 2.126 - TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, dest_image_length); 2.127 - TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, dest_image_width); 2.128 - TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 2.129 - 2.130 - TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, dest_image_length); 2.131 - 2.132 - TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 2.133 - TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); 2.134 - TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); 2.135 - 2.136 - TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); 2.137 - TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 2.138 - TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 2.139 - TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 2.140 - 2.141 scanline_size = TIFFScanlineSize (in); 2.142 2.143 src_bitmap = create_bitmap (image_width, image_length); 2.144 @@ -430,13 +396,45 @@ 2.145 goto fail; 2.146 } 2.147 2.148 - dest_bitmap = rotate_bitmap (src_bitmap, input_attributes.rotation); 2.149 + dest_bitmap = rotate_bitmap (src_bitmap, 2.150 + x_resolution, 2.151 + y_resolution, 2.152 + input_attributes); 2.153 if (! dest_bitmap) 2.154 { 2.155 fprintf (stderr, "can't allocate bitmap\n"); 2.156 goto fail; 2.157 } 2.158 2.159 + tiff_temp_fd = mkstemp (tiff_temp_fn); 2.160 + if (tiff_temp_fd < 0) 2.161 + { 2.162 + fprintf (stderr, "can't create temporary TIFF file\n"); 2.163 + goto fail; 2.164 + } 2.165 + 2.166 + tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 2.167 + if (! out) 2.168 + { 2.169 + fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 2.170 + goto fail; 2.171 + } 2.172 + 2.173 + TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, dest_bitmap->height); 2.174 + TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, dest_bitmap->width); 2.175 + TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 2.176 + 2.177 + TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, dest_bitmap->height); 2.178 + 2.179 + TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 2.180 + TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); 2.181 + TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); 2.182 + 2.183 + TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); 2.184 + TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 2.185 + TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 2.186 + TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 2.187 + 2.188 for (row = 0; row < dest_bitmap->height; row++) 2.189 if (1 != TIFFWriteScanline (tiff_temp, 2.190 dest_bitmap->bits + row * dest_bitmap->rowbytes, 2.191 @@ -449,9 +447,18 @@ 2.192 2.193 TIFFClose (tiff_temp); 2.194 2.195 + width_points = (dest_bitmap->width / dest_x_resolution) * POINTS_PER_INCH; 2.196 + height_points = (dest_bitmap->height / dest_y_resolution) * POINTS_PER_INCH; 2.197 + 2.198 free_bitmap (dest_bitmap); 2.199 free_bitmap (src_bitmap); 2.200 2.201 + if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 2.202 + { 2.203 + fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 2.204 + goto fail; 2.205 + } 2.206 + 2.207 sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); 2.208 2.209 page = panda_newpage (out->pdf, pagesize);
3.1 diff -r 41804cc569ab -r a338db73c6f4 t2p.h 3.2 --- a/t2p.h Wed Jan 02 10:17:48 2002 +0000 3.3 +++ b/t2p.h Wed Jan 02 10:18:13 2002 +0000 3.4 @@ -1,5 +1,9 @@ 3.5 typedef struct 3.6 { 3.7 + boolean has_resolution; 3.8 + double x_resolution; 3.9 + double y_resolution; 3.10 + 3.11 boolean has_page_size; 3.12 page_size_t page_size; 3.13
4.1 diff -r 41804cc569ab -r a338db73c6f4 tumble.c 4.2 --- a/tumble.c Wed Jan 02 10:17:48 2002 +0000 4.3 +++ b/tumble.c Wed Jan 02 10:18:13 2002 +0000 4.4 @@ -5,7 +5,7 @@ 4.5 * encoding. 4.6 * 4.7 * Main program 4.8 - * $Id: tumble.c,v 1.12 2002/01/01 02:16:50 eric Exp $ 4.9 + * $Id: tumble.c,v 1.13 2002/01/02 02:18:13 eric Exp $ 4.10 * Copyright 2001 Eric Smith <eric@brouhaha.com> 4.11 * 4.12 * This program is free software; you can redistribute it and/or modify 4.13 @@ -179,21 +179,37 @@ 4.14 } 4.15 4.16 4.17 -static Bitmap *rotate_bitmap (Bitmap *src, int rotation) 4.18 +static Bitmap *rotate_bitmap (Bitmap *src, 4.19 + float x_resolution, 4.20 + float y_resolution, 4.21 + input_attributes_t input_attributes) 4.22 { 4.23 Rect src_rect; 4.24 Point dest_upper_left; 4.25 int scan; 4.26 4.27 - src_rect.upper_left.x = 0; 4.28 - src_rect.upper_left.y = 0; 4.29 - src_rect.lower_right.x = src->width; 4.30 - src_rect.lower_right.y = src->height; 4.31 + if (input_attributes.has_page_size) 4.32 + { 4.33 + int width_pixels = input_attributes.page_size.width * x_resolution; 4.34 + int height_pixels = input_attributes.page_size.height * y_resolution; 4.35 + 4.36 + src_rect.upper_left.x = (src->width - width_pixels) / 2; 4.37 + src_rect.upper_left.y = (src->height - height_pixels) / 2; 4.38 + src_rect.lower_right.x = src_rect.upper_left.x + width_pixels; 4.39 + src_rect.lower_right.y = src_rect.upper_left.y + height_pixels; 4.40 + } 4.41 + else 4.42 + { 4.43 + src_rect.upper_left.x = 0; 4.44 + src_rect.upper_left.y = 0; 4.45 + src_rect.lower_right.x = src->width; 4.46 + src_rect.lower_right.y = src->height; 4.47 + } 4.48 4.49 dest_upper_left.x = 0; 4.50 dest_upper_left.y = 0; 4.51 4.52 - switch (rotation) 4.53 + switch (input_attributes.rotation) 4.54 { 4.55 case 0: scan = ROT_0; break; 4.56 case 90: scan = ROT_90; break; 4.57 @@ -293,17 +309,6 @@ 4.58 if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) 4.59 planar_config = 1; 4.60 4.61 - printf ("image length %u width %u, " 4.62 -#ifdef CHECK_DEPTH 4.63 - "depth %u, " 4.64 -#endif 4.65 - "planar config %u\n", 4.66 - image_length, image_width, 4.67 -#ifdef CHECK_DEPTH 4.68 - image_depth, 4.69 -#endif 4.70 - planar_config); 4.71 - 4.72 if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) 4.73 resolution_unit = 2; 4.74 if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) 4.75 @@ -311,9 +316,6 @@ 4.76 if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) 4.77 y_resolution = 300; 4.78 4.79 - printf ("resolution unit %u, x resolution %f, y resolution %f\n", 4.80 - resolution_unit, x_resolution, y_resolution); 4.81 - 4.82 if (samples_per_pixel != 1) 4.83 { 4.84 fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel); 4.85 @@ -340,33 +342,12 @@ 4.86 goto fail; 4.87 } 4.88 4.89 - width_points = (image_width / x_resolution) * POINTS_PER_INCH; 4.90 - height_points = (image_length / y_resolution) * POINTS_PER_INCH; 4.91 - 4.92 - if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 4.93 + if (input_attributes.has_resolution) 4.94 { 4.95 - fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 4.96 - goto fail; 4.97 + x_resolution = input_attributes.x_resolution; 4.98 + y_resolution = input_attributes.y_resolution; 4.99 } 4.100 4.101 - printf ("height_points %d, width_points %d\n", height_points, width_points); 4.102 - 4.103 - tiff_temp_fd = mkstemp (tiff_temp_fn); 4.104 - if (tiff_temp_fd < 0) 4.105 - { 4.106 - fprintf (stderr, "can't create temporary TIFF file\n"); 4.107 - goto fail; 4.108 - } 4.109 - 4.110 - tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 4.111 - if (! out) 4.112 - { 4.113 - fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 4.114 - goto fail; 4.115 - } 4.116 - 4.117 - printf ("rotation %d\n", input_attributes.rotation); 4.118 - 4.119 if ((input_attributes.rotation == 90) || (input_attributes.rotation == 270)) 4.120 { 4.121 dest_image_width = image_length; 4.122 @@ -383,21 +364,6 @@ 4.123 dest_y_resolution = y_resolution; 4.124 } 4.125 4.126 - TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, dest_image_length); 4.127 - TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, dest_image_width); 4.128 - TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 4.129 - 4.130 - TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, dest_image_length); 4.131 - 4.132 - TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 4.133 - TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); 4.134 - TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); 4.135 - 4.136 - TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); 4.137 - TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 4.138 - TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 4.139 - TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 4.140 - 4.141 scanline_size = TIFFScanlineSize (in); 4.142 4.143 src_bitmap = create_bitmap (image_width, image_length); 4.144 @@ -430,13 +396,45 @@ 4.145 goto fail; 4.146 } 4.147 4.148 - dest_bitmap = rotate_bitmap (src_bitmap, input_attributes.rotation); 4.149 + dest_bitmap = rotate_bitmap (src_bitmap, 4.150 + x_resolution, 4.151 + y_resolution, 4.152 + input_attributes); 4.153 if (! dest_bitmap) 4.154 { 4.155 fprintf (stderr, "can't allocate bitmap\n"); 4.156 goto fail; 4.157 } 4.158 4.159 + tiff_temp_fd = mkstemp (tiff_temp_fn); 4.160 + if (tiff_temp_fd < 0) 4.161 + { 4.162 + fprintf (stderr, "can't create temporary TIFF file\n"); 4.163 + goto fail; 4.164 + } 4.165 + 4.166 + tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); 4.167 + if (! out) 4.168 + { 4.169 + fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); 4.170 + goto fail; 4.171 + } 4.172 + 4.173 + TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, dest_bitmap->height); 4.174 + TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, dest_bitmap->width); 4.175 + TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); 4.176 + 4.177 + TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, dest_bitmap->height); 4.178 + 4.179 + TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); 4.180 + TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); 4.181 + TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); 4.182 + 4.183 + TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); 4.184 + TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); 4.185 + TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); 4.186 + TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); 4.187 + 4.188 for (row = 0; row < dest_bitmap->height; row++) 4.189 if (1 != TIFFWriteScanline (tiff_temp, 4.190 dest_bitmap->bits + row * dest_bitmap->rowbytes, 4.191 @@ -449,9 +447,18 @@ 4.192 4.193 TIFFClose (tiff_temp); 4.194 4.195 + width_points = (dest_bitmap->width / dest_x_resolution) * POINTS_PER_INCH; 4.196 + height_points = (dest_bitmap->height / dest_y_resolution) * POINTS_PER_INCH; 4.197 + 4.198 free_bitmap (dest_bitmap); 4.199 free_bitmap (src_bitmap); 4.200 4.201 + if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) 4.202 + { 4.203 + fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); 4.204 + goto fail; 4.205 + } 4.206 + 4.207 sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); 4.208 4.209 page = panda_newpage (out->pdf, pagesize);
5.1 diff -r 41804cc569ab -r a338db73c6f4 tumble.h 5.2 --- a/tumble.h Wed Jan 02 10:17:48 2002 +0000 5.3 +++ b/tumble.h Wed Jan 02 10:18:13 2002 +0000 5.4 @@ -1,5 +1,9 @@ 5.5 typedef struct 5.6 { 5.7 + boolean has_resolution; 5.8 + double x_resolution; 5.9 + double y_resolution; 5.10 + 5.11 boolean has_page_size; 5.12 page_size_t page_size; 5.13