Wed, 02 Jan 2002 10:18:13 +0000
bug fixes.
eric@10 | 1 | /* |
eric@29 | 2 | * tiff2pdf: Create a PDF file from the contents of one or more |
eric@29 | 3 | * TIFF bilevel image files. The images in the resulting |
eric@29 | 4 | * PDF file will be compressed using ITU-T T.6 (G4) fax |
eric@29 | 5 | * encoding. |
eric@29 | 6 | * |
eric@10 | 7 | * Main program |
eric@36 | 8 | * $Id: t2p.c,v 1.13 2002/01/02 02:18:13 eric Exp $ |
eric@10 | 9 | * Copyright 2001 Eric Smith <eric@brouhaha.com> |
eric@10 | 10 | * |
eric@10 | 11 | * This program is free software; you can redistribute it and/or modify |
eric@10 | 12 | * it under the terms of the GNU General Public License version 2 as |
eric@10 | 13 | * published by the Free Software Foundation. Note that permission is |
eric@10 | 14 | * not granted to redistribute this program under the terms of any |
eric@10 | 15 | * other version of the General Public License. |
eric@10 | 16 | * |
eric@10 | 17 | * This program is distributed in the hope that it will be useful, |
eric@10 | 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
eric@10 | 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
eric@10 | 20 | * GNU General Public License for more details. |
eric@10 | 21 | * |
eric@10 | 22 | * You should have received a copy of the GNU General Public License |
eric@10 | 23 | * along with this program; if not, write to the Free Software |
eric@10 | 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA |
eric@10 | 25 | */ |
eric@10 | 26 | |
eric@10 | 27 | |
eric@10 | 28 | #include <stdio.h> |
eric@28 | 29 | #include <stdlib.h> |
eric@28 | 30 | #include <unistd.h> |
eric@10 | 31 | #include <tiffio.h> |
eric@10 | 32 | #include <panda/functions.h> |
eric@10 | 33 | #include <panda/constants.h> |
eric@10 | 34 | |
eric@10 | 35 | #include "type.h" |
eric@10 | 36 | #include "bitblt.h" |
eric@18 | 37 | #include "semantics.h" |
eric@10 | 38 | #include "parser.tab.h" |
eric@10 | 39 | #include "tiff2pdf.h" |
eric@10 | 40 | |
eric@10 | 41 | |
eric@28 | 42 | #define POINTS_PER_INCH 72 |
eric@28 | 43 | |
eric@28 | 44 | /* page size limited by Acrobat Reader to 45 inches on a side */ |
eric@28 | 45 | #define PAGE_MAX_INCHES 45 |
eric@28 | 46 | #define PAGE_MAX_POINTS (PAGE_MAX_INCHES * POINTS_PER_INCH) |
eric@28 | 47 | |
eric@28 | 48 | |
eric@26 | 49 | typedef struct output_file_t |
eric@26 | 50 | { |
eric@26 | 51 | struct output_file_t *next; |
eric@26 | 52 | char *name; |
eric@26 | 53 | panda_pdf *pdf; |
eric@26 | 54 | } output_file_t; |
eric@26 | 55 | |
eric@26 | 56 | |
eric@26 | 57 | char *in_filename; |
eric@10 | 58 | TIFF *in; |
eric@26 | 59 | output_file_t *output_files; |
eric@26 | 60 | output_file_t *out; |
eric@26 | 61 | /* panda_pdf *out; */ |
eric@10 | 62 | |
eric@10 | 63 | |
eric@10 | 64 | boolean close_tiff_input_file (void) |
eric@10 | 65 | { |
eric@10 | 66 | if (in) |
eric@26 | 67 | { |
eric@26 | 68 | free (in_filename); |
eric@26 | 69 | TIFFClose (in); |
eric@26 | 70 | } |
eric@10 | 71 | in = NULL; |
eric@26 | 72 | in_filename = NULL; |
eric@10 | 73 | return (1); |
eric@10 | 74 | } |
eric@10 | 75 | |
eric@10 | 76 | boolean open_tiff_input_file (char *name) |
eric@10 | 77 | { |
eric@10 | 78 | if (in) |
eric@26 | 79 | { |
eric@26 | 80 | if (strcmp (name, in_filename) == 0) |
eric@26 | 81 | return (1); |
eric@26 | 82 | close_tiff_input_file (); |
eric@26 | 83 | } |
eric@26 | 84 | in_filename = strdup (name); |
eric@26 | 85 | if (! in_filename) |
eric@26 | 86 | { |
eric@26 | 87 | fprintf (stderr, "can't strdup input filename '%s'\n", name); |
eric@26 | 88 | return (0); |
eric@26 | 89 | } |
eric@10 | 90 | in = TIFFOpen (name, "r"); |
eric@10 | 91 | if (! in) |
eric@10 | 92 | { |
eric@10 | 93 | fprintf (stderr, "can't open input file '%s'\n", name); |
eric@26 | 94 | free (in_filename); |
eric@10 | 95 | return (0); |
eric@10 | 96 | } |
eric@10 | 97 | return (1); |
eric@10 | 98 | } |
eric@10 | 99 | |
eric@10 | 100 | |
eric@26 | 101 | boolean close_pdf_output_files (void) |
eric@10 | 102 | { |
eric@26 | 103 | output_file_t *o, *n; |
eric@26 | 104 | |
eric@26 | 105 | for (o = output_files; o; o = n) |
eric@26 | 106 | { |
eric@26 | 107 | n = o->next; |
eric@26 | 108 | panda_close (o->pdf); |
eric@26 | 109 | free (o->name); |
eric@26 | 110 | free (o); |
eric@26 | 111 | } |
eric@10 | 112 | out = NULL; |
eric@26 | 113 | output_files = NULL; |
eric@10 | 114 | return (1); |
eric@10 | 115 | } |
eric@10 | 116 | |
eric@30 | 117 | boolean open_pdf_output_file (char *name, |
eric@30 | 118 | pdf_file_attributes_t *attributes) |
eric@10 | 119 | { |
eric@26 | 120 | output_file_t *o; |
eric@26 | 121 | |
eric@26 | 122 | if (out && (strcmp (name, out->name) == 0)) |
eric@26 | 123 | return (1); |
eric@26 | 124 | for (o = output_files; o; o = o->next) |
eric@26 | 125 | if (strcmp (name, o->name) == 0) |
eric@26 | 126 | { |
eric@26 | 127 | out = o; |
eric@26 | 128 | return (1); |
eric@26 | 129 | } |
eric@26 | 130 | o = calloc (1, sizeof (output_file_t)); |
eric@29 | 131 | if (! o) |
eric@10 | 132 | { |
eric@26 | 133 | fprintf (stderr, "can't calloc output file struct for '%s'\n", name); |
eric@26 | 134 | return (0); |
eric@26 | 135 | } |
eric@26 | 136 | |
eric@26 | 137 | o->name = strdup (name); |
eric@26 | 138 | if (! o->name) |
eric@26 | 139 | { |
eric@26 | 140 | fprintf (stderr, "can't strdup output filename '%s'\n", name); |
eric@26 | 141 | free (o); |
eric@10 | 142 | return (0); |
eric@10 | 143 | } |
eric@26 | 144 | |
eric@26 | 145 | o->pdf = panda_open (name, "w"); |
eric@26 | 146 | if (! o->pdf) |
eric@26 | 147 | { |
eric@26 | 148 | fprintf (stderr, "can't open output file '%s'\n", name); |
eric@26 | 149 | free (o->name); |
eric@26 | 150 | free (o); |
eric@26 | 151 | return (0); |
eric@26 | 152 | } |
eric@26 | 153 | |
eric@30 | 154 | if (attributes->author) |
eric@30 | 155 | panda_setauthor (o->pdf, attributes->author); |
eric@30 | 156 | if (attributes->creator) |
eric@30 | 157 | panda_setcreator (o->pdf, attributes->creator); |
eric@30 | 158 | if (attributes->title) |
eric@30 | 159 | panda_settitle (o->pdf, attributes->title); |
eric@30 | 160 | if (attributes->subject) |
eric@30 | 161 | panda_setsubject (o->pdf, attributes->subject); |
eric@30 | 162 | if (attributes->keywords) |
eric@30 | 163 | panda_setkeywords (o->pdf, attributes->keywords); |
eric@30 | 164 | |
eric@26 | 165 | /* prepend new output file onto list */ |
eric@26 | 166 | o->next = output_files; |
eric@26 | 167 | output_files = o; |
eric@26 | 168 | |
eric@26 | 169 | out = o; |
eric@10 | 170 | return (1); |
eric@10 | 171 | } |
eric@10 | 172 | |
eric@10 | 173 | |
eric@25 | 174 | void process_page_numbers (int page_index, |
eric@25 | 175 | int count, |
eric@25 | 176 | int base, |
eric@25 | 177 | page_label_t *page_label) |
eric@25 | 178 | { |
eric@25 | 179 | } |
eric@25 | 180 | |
eric@25 | 181 | |
eric@36 | 182 | static Bitmap *rotate_bitmap (Bitmap *src, |
eric@36 | 183 | float x_resolution, |
eric@36 | 184 | float y_resolution, |
eric@36 | 185 | input_attributes_t input_attributes) |
eric@32 | 186 | { |
eric@32 | 187 | Rect src_rect; |
eric@32 | 188 | Point dest_upper_left; |
eric@32 | 189 | int scan; |
eric@32 | 190 | |
eric@36 | 191 | if (input_attributes.has_page_size) |
eric@36 | 192 | { |
eric@36 | 193 | int width_pixels = input_attributes.page_size.width * x_resolution; |
eric@36 | 194 | int height_pixels = input_attributes.page_size.height * y_resolution; |
eric@36 | 195 | |
eric@36 | 196 | src_rect.upper_left.x = (src->width - width_pixels) / 2; |
eric@36 | 197 | src_rect.upper_left.y = (src->height - height_pixels) / 2; |
eric@36 | 198 | src_rect.lower_right.x = src_rect.upper_left.x + width_pixels; |
eric@36 | 199 | src_rect.lower_right.y = src_rect.upper_left.y + height_pixels; |
eric@36 | 200 | } |
eric@36 | 201 | else |
eric@36 | 202 | { |
eric@36 | 203 | src_rect.upper_left.x = 0; |
eric@36 | 204 | src_rect.upper_left.y = 0; |
eric@36 | 205 | src_rect.lower_right.x = src->width; |
eric@36 | 206 | src_rect.lower_right.y = src->height; |
eric@36 | 207 | } |
eric@32 | 208 | |
eric@32 | 209 | dest_upper_left.x = 0; |
eric@32 | 210 | dest_upper_left.y = 0; |
eric@32 | 211 | |
eric@36 | 212 | switch (input_attributes.rotation) |
eric@32 | 213 | { |
eric@32 | 214 | case 0: scan = ROT_0; break; |
eric@32 | 215 | case 90: scan = ROT_90; break; |
eric@32 | 216 | case 180: scan = ROT_180; break; |
eric@32 | 217 | case 270: scan = ROT_270; break; |
eric@32 | 218 | default: |
eric@32 | 219 | fprintf (stderr, "rotation must be 0, 90, 180, or 270\n"); |
eric@32 | 220 | return (NULL); |
eric@32 | 221 | } |
eric@32 | 222 | |
eric@32 | 223 | return (bitblt (src, |
eric@32 | 224 | src_rect, |
eric@32 | 225 | NULL, /* dest_bitmap */ |
eric@32 | 226 | dest_upper_left, |
eric@32 | 227 | scan, |
eric@32 | 228 | TF_SRC)); |
eric@32 | 229 | } |
eric@32 | 230 | |
eric@32 | 231 | |
eric@32 | 232 | #define SWAP(type,a,b) do { type temp; temp = a; a = b; b = temp; } while (0) |
eric@32 | 233 | |
eric@23 | 234 | boolean process_page (int image, /* range 1 .. n */ |
eric@23 | 235 | input_attributes_t input_attributes, |
eric@25 | 236 | bookmark_t *bookmarks) |
eric@10 | 237 | { |
eric@29 | 238 | int result = 0; |
eric@29 | 239 | |
eric@10 | 240 | u32 image_length, image_width; |
eric@32 | 241 | u32 dest_image_length, dest_image_width; |
eric@10 | 242 | #ifdef CHECK_DEPTH |
eric@10 | 243 | u32 image_depth; |
eric@10 | 244 | #endif |
eric@29 | 245 | |
eric@29 | 246 | u16 samples_per_pixel; |
eric@10 | 247 | u16 bits_per_sample; |
eric@10 | 248 | u16 planar_config; |
eric@32 | 249 | |
eric@10 | 250 | u16 resolution_unit; |
eric@10 | 251 | float x_resolution, y_resolution; |
eric@32 | 252 | float dest_x_resolution, dest_y_resolution; |
eric@32 | 253 | |
eric@32 | 254 | int scanline_size; |
eric@32 | 255 | |
eric@28 | 256 | int width_points, height_points; /* really 1/72 inch units rather than |
eric@28 | 257 | points */ |
eric@28 | 258 | |
eric@32 | 259 | Bitmap *src_bitmap; |
eric@32 | 260 | Bitmap *dest_bitmap; |
eric@32 | 261 | int row; |
eric@10 | 262 | |
eric@28 | 263 | panda_page *page; |
eric@28 | 264 | |
eric@28 | 265 | int tiff_temp_fd; |
eric@28 | 266 | char tiff_temp_fn [] = "/var/tmp/tiff2pdf-XXXXXX\0"; |
eric@28 | 267 | TIFF *tiff_temp; |
eric@28 | 268 | |
eric@28 | 269 | char pagesize [26]; /* Needs to hold two ints of four characters (0..3420), |
eric@28 | 270 | two zeros, three spaces, two brackets, and a NULL. |
eric@28 | 271 | Added an extra ten characters just in case. */ |
eric@28 | 272 | |
eric@10 | 273 | if (! TIFFSetDirectory (in, image - 1)) |
eric@10 | 274 | { |
eric@10 | 275 | fprintf (stderr, "can't find page %d of input file\n", image); |
eric@10 | 276 | goto fail; |
eric@10 | 277 | } |
eric@10 | 278 | if (1 != TIFFGetField (in, TIFFTAG_IMAGELENGTH, & image_length)) |
eric@10 | 279 | { |
eric@10 | 280 | fprintf (stderr, "can't get image length\n"); |
eric@10 | 281 | goto fail; |
eric@10 | 282 | } |
eric@10 | 283 | if (1 != TIFFGetField (in, TIFFTAG_IMAGEWIDTH, & image_width)) |
eric@10 | 284 | { |
eric@10 | 285 | fprintf (stderr, "can't get image width\n"); |
eric@10 | 286 | goto fail; |
eric@10 | 287 | } |
eric@29 | 288 | |
eric@29 | 289 | if (1 != TIFFGetField (in, TIFFTAG_SAMPLESPERPIXEL, & samples_per_pixel)) |
eric@29 | 290 | { |
eric@29 | 291 | fprintf (stderr, "can't get samples per pixel\n"); |
eric@29 | 292 | goto fail; |
eric@29 | 293 | } |
eric@29 | 294 | |
eric@10 | 295 | #ifdef CHECK_DEPTH |
eric@10 | 296 | if (1 != TIFFGetField (in, TIFFTAG_IMAGEDEPTH, & image_depth)) |
eric@10 | 297 | { |
eric@10 | 298 | fprintf (stderr, "can't get image depth\n"); |
eric@10 | 299 | goto fail; |
eric@10 | 300 | } |
eric@10 | 301 | #endif |
eric@10 | 302 | |
eric@10 | 303 | if (1 != TIFFGetField (in, TIFFTAG_BITSPERSAMPLE, & bits_per_sample)) |
eric@10 | 304 | { |
eric@10 | 305 | fprintf (stderr, "can't get bits per sample\n"); |
eric@10 | 306 | goto fail; |
eric@10 | 307 | } |
eric@10 | 308 | |
eric@10 | 309 | if (1 != TIFFGetField (in, TIFFTAG_PLANARCONFIG, & planar_config)) |
eric@10 | 310 | planar_config = 1; |
eric@10 | 311 | |
eric@10 | 312 | if (1 != TIFFGetField (in, TIFFTAG_RESOLUTIONUNIT, & resolution_unit)) |
eric@10 | 313 | resolution_unit = 2; |
eric@10 | 314 | if (1 != TIFFGetField (in, TIFFTAG_XRESOLUTION, & x_resolution)) |
eric@10 | 315 | x_resolution = 300; |
eric@10 | 316 | if (1 != TIFFGetField (in, TIFFTAG_YRESOLUTION, & y_resolution)) |
eric@10 | 317 | y_resolution = 300; |
eric@10 | 318 | |
eric@29 | 319 | if (samples_per_pixel != 1) |
eric@29 | 320 | { |
eric@29 | 321 | fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel); |
eric@29 | 322 | goto fail; |
eric@29 | 323 | } |
eric@29 | 324 | |
eric@10 | 325 | #ifdef CHECK_DEPTH |
eric@10 | 326 | if (image_depth != 1) |
eric@10 | 327 | { |
eric@10 | 328 | fprintf (stderr, "image depth %u, must be 1\n", image_depth); |
eric@10 | 329 | goto fail; |
eric@10 | 330 | } |
eric@10 | 331 | #endif |
eric@10 | 332 | |
eric@10 | 333 | if (bits_per_sample != 1) |
eric@10 | 334 | { |
eric@10 | 335 | fprintf (stderr, "bits per sample %u, must be 1\n", bits_per_sample); |
eric@10 | 336 | goto fail; |
eric@10 | 337 | } |
eric@10 | 338 | |
eric@10 | 339 | if (planar_config != 1) |
eric@10 | 340 | { |
eric@10 | 341 | fprintf (stderr, "planar config %u, must be 1\n", planar_config); |
eric@10 | 342 | goto fail; |
eric@10 | 343 | } |
eric@10 | 344 | |
eric@36 | 345 | if (input_attributes.has_resolution) |
eric@32 | 346 | { |
eric@36 | 347 | x_resolution = input_attributes.x_resolution; |
eric@36 | 348 | y_resolution = input_attributes.y_resolution; |
eric@32 | 349 | } |
eric@32 | 350 | |
eric@32 | 351 | if ((input_attributes.rotation == 90) || (input_attributes.rotation == 270)) |
eric@32 | 352 | { |
eric@32 | 353 | dest_image_width = image_length; |
eric@32 | 354 | dest_image_length = image_width; |
eric@32 | 355 | dest_x_resolution = y_resolution; |
eric@32 | 356 | dest_y_resolution = x_resolution; |
eric@32 | 357 | SWAP (int, width_points, height_points); |
eric@32 | 358 | } |
eric@32 | 359 | else |
eric@32 | 360 | { |
eric@32 | 361 | dest_image_width = image_width; |
eric@32 | 362 | dest_image_length = image_length; |
eric@32 | 363 | dest_x_resolution = x_resolution; |
eric@32 | 364 | dest_y_resolution = y_resolution; |
eric@32 | 365 | } |
eric@32 | 366 | |
eric@32 | 367 | scanline_size = TIFFScanlineSize (in); |
eric@32 | 368 | |
eric@32 | 369 | src_bitmap = create_bitmap (image_width, image_length); |
eric@32 | 370 | if (! src_bitmap) |
eric@10 | 371 | { |
eric@32 | 372 | fprintf (stderr, "can't allocate bitmap\n"); |
eric@10 | 373 | goto fail; |
eric@10 | 374 | } |
eric@10 | 375 | |
eric@32 | 376 | if (src_bitmap->rowbytes != scanline_size) |
eric@32 | 377 | { |
eric@32 | 378 | printf ("image_width %d\n", image_width); |
eric@32 | 379 | printf ("rowbytes %d\n", src_bitmap->rowbytes); |
eric@32 | 380 | printf ("TIFFScanlineSize %d\n", scanline_size); |
eric@32 | 381 | } |
eric@32 | 382 | |
eric@10 | 383 | for (row = 0; row < image_length; row++) |
eric@32 | 384 | TIFFReadScanline (in, |
eric@32 | 385 | src_bitmap->bits + row * src_bitmap->rowbytes, |
eric@32 | 386 | row, |
eric@32 | 387 | 0); |
eric@10 | 388 | |
eric@32 | 389 | for (row = 0; row < dest_image_length; row++) |
eric@32 | 390 | if (1 != TIFFReadScanline (in, |
eric@32 | 391 | src_bitmap->bits + row * src_bitmap->rowbytes, |
eric@32 | 392 | row, |
eric@32 | 393 | 0)) |
eric@32 | 394 | { |
eric@32 | 395 | fprintf (stderr, "can't read TIFF scanline\n"); |
eric@32 | 396 | goto fail; |
eric@32 | 397 | } |
eric@28 | 398 | |
eric@36 | 399 | dest_bitmap = rotate_bitmap (src_bitmap, |
eric@36 | 400 | x_resolution, |
eric@36 | 401 | y_resolution, |
eric@36 | 402 | input_attributes); |
eric@32 | 403 | if (! dest_bitmap) |
eric@28 | 404 | { |
eric@32 | 405 | fprintf (stderr, "can't allocate bitmap\n"); |
eric@28 | 406 | goto fail; |
eric@28 | 407 | } |
eric@28 | 408 | |
eric@36 | 409 | tiff_temp_fd = mkstemp (tiff_temp_fn); |
eric@36 | 410 | if (tiff_temp_fd < 0) |
eric@36 | 411 | { |
eric@36 | 412 | fprintf (stderr, "can't create temporary TIFF file\n"); |
eric@36 | 413 | goto fail; |
eric@36 | 414 | } |
eric@36 | 415 | |
eric@36 | 416 | tiff_temp = TIFFFdOpen (tiff_temp_fd, tiff_temp_fn, "w"); |
eric@36 | 417 | if (! out) |
eric@36 | 418 | { |
eric@36 | 419 | fprintf (stderr, "can't open temporary TIFF file '%s'\n", tiff_temp_fn); |
eric@36 | 420 | goto fail; |
eric@36 | 421 | } |
eric@36 | 422 | |
eric@36 | 423 | TIFFSetField (tiff_temp, TIFFTAG_IMAGELENGTH, dest_bitmap->height); |
eric@36 | 424 | TIFFSetField (tiff_temp, TIFFTAG_IMAGEWIDTH, dest_bitmap->width); |
eric@36 | 425 | TIFFSetField (tiff_temp, TIFFTAG_PLANARCONFIG, planar_config); |
eric@36 | 426 | |
eric@36 | 427 | TIFFSetField (tiff_temp, TIFFTAG_ROWSPERSTRIP, dest_bitmap->height); |
eric@36 | 428 | |
eric@36 | 429 | TIFFSetField (tiff_temp, TIFFTAG_RESOLUTIONUNIT, resolution_unit); |
eric@36 | 430 | TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, dest_x_resolution); |
eric@36 | 431 | TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, dest_y_resolution); |
eric@36 | 432 | |
eric@36 | 433 | TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel); |
eric@36 | 434 | TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample); |
eric@36 | 435 | TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4); |
eric@36 | 436 | TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE); |
eric@36 | 437 | |
eric@32 | 438 | for (row = 0; row < dest_bitmap->height; row++) |
eric@32 | 439 | if (1 != TIFFWriteScanline (tiff_temp, |
eric@32 | 440 | dest_bitmap->bits + row * dest_bitmap->rowbytes, |
eric@32 | 441 | row, |
eric@32 | 442 | 0)) |
eric@32 | 443 | { |
eric@32 | 444 | fprintf (stderr, "can't write TIFF scanline\n"); |
eric@32 | 445 | goto fail; |
eric@32 | 446 | } |
eric@32 | 447 | |
eric@32 | 448 | TIFFClose (tiff_temp); |
eric@32 | 449 | |
eric@36 | 450 | width_points = (dest_bitmap->width / dest_x_resolution) * POINTS_PER_INCH; |
eric@36 | 451 | height_points = (dest_bitmap->height / dest_y_resolution) * POINTS_PER_INCH; |
eric@36 | 452 | |
eric@32 | 453 | free_bitmap (dest_bitmap); |
eric@32 | 454 | free_bitmap (src_bitmap); |
eric@28 | 455 | |
eric@36 | 456 | if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS)) |
eric@36 | 457 | { |
eric@36 | 458 | fprintf (stdout, "image too large (max %d inches on a side\n", PAGE_MAX_INCHES); |
eric@36 | 459 | goto fail; |
eric@36 | 460 | } |
eric@36 | 461 | |
eric@28 | 462 | sprintf (pagesize, "[0 0 %d %d]", width_points, height_points); |
eric@28 | 463 | |
eric@28 | 464 | page = panda_newpage (out->pdf, pagesize); |
eric@28 | 465 | panda_imagebox (out->pdf, |
eric@28 | 466 | page, |
eric@28 | 467 | 0, /* top */ |
eric@28 | 468 | 0, /* left */ |
eric@28 | 469 | height_points, /* bottom */ |
eric@28 | 470 | width_points, /* right */ |
eric@28 | 471 | tiff_temp_fn, |
eric@28 | 472 | panda_image_tiff); |
eric@28 | 473 | |
eric@29 | 474 | result = 1; |
eric@10 | 475 | |
eric@10 | 476 | fail: |
eric@29 | 477 | if (tiff_temp_fd) |
eric@29 | 478 | unlink (tiff_temp_fn); |
eric@29 | 479 | return (result); |
eric@10 | 480 | } |
eric@10 | 481 | |
eric@10 | 482 | |
eric@10 | 483 | int main (int argc, char *argv[]) |
eric@10 | 484 | { |
eric@10 | 485 | int result = 0; |
eric@10 | 486 | |
eric@10 | 487 | panda_init (); |
eric@10 | 488 | |
eric@10 | 489 | if (argc != 2) |
eric@10 | 490 | { |
eric@10 | 491 | fprintf (stderr, "usage: %s spec\n", argv [0]); |
eric@10 | 492 | result = 1; |
eric@10 | 493 | goto fail; |
eric@10 | 494 | } |
eric@10 | 495 | |
eric@17 | 496 | if (! parse_spec_file (argv [1])) |
eric@26 | 497 | { |
eric@26 | 498 | result = 2; |
eric@26 | 499 | goto fail; |
eric@26 | 500 | } |
eric@26 | 501 | |
eric@26 | 502 | if (! process_specs ()) |
eric@26 | 503 | { |
eric@26 | 504 | result = 3; |
eric@26 | 505 | goto fail; |
eric@26 | 506 | } |
eric@17 | 507 | |
eric@10 | 508 | fail: |
eric@10 | 509 | close_tiff_input_file (); |
eric@26 | 510 | close_pdf_output_files (); |
eric@10 | 511 | return (result); |
eric@10 | 512 | } |