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