t2p.c

changeset 29
c904ffd6a1cf
parent 28
ba8313d18bd3
child 30
35fad7ec7732
     1.1 --- a/t2p.c	Tue Jan 01 05:02:44 2002 +0000
     1.2 +++ b/t2p.c	Tue Jan 01 05:41:03 2002 +0000
     1.3 @@ -1,7 +1,11 @@
     1.4  /*
     1.5 - * tiffg4: reencode a bilevel TIFF file as a single-strip TIFF Class F Group 4
     1.6 + * tiff2pdf: Create a PDF file from the contents of one or more
     1.7 + *           TIFF bilevel image files.  The images in the resulting
     1.8 + *           PDF file will be compressed using ITU-T T.6 (G4) fax
     1.9 + *           encoding.
    1.10 + *
    1.11   * Main program
    1.12 - * $Id: t2p.c,v 1.9 2001/12/31 21:02:44 eric Exp $
    1.13 + * $Id: t2p.c,v 1.10 2001/12/31 21:41:03 eric Exp $
    1.14   * Copyright 2001 Eric Smith <eric@brouhaha.com>
    1.15   *
    1.16   * This program is free software; you can redistribute it and/or modify
    1.17 @@ -123,7 +127,7 @@
    1.18  	return (1);
    1.19        }
    1.20    o = calloc (1, sizeof (output_file_t));
    1.21 -  if (! 0)
    1.22 +  if (! o)
    1.23      {
    1.24        fprintf (stderr, "can't calloc output file struct for '%s'\n", name);
    1.25        return (0);
    1.26 @@ -167,10 +171,14 @@
    1.27  		      input_attributes_t input_attributes,
    1.28  		      bookmark_t *bookmarks)
    1.29  {
    1.30 +  int result = 0;
    1.31 +
    1.32    u32 image_length, image_width;
    1.33  #ifdef CHECK_DEPTH
    1.34    u32 image_depth;
    1.35  #endif
    1.36 +
    1.37 +  u16 samples_per_pixel;
    1.38    u16 bits_per_sample;
    1.39    u16 planar_config;
    1.40    u16 resolution_unit;
    1.41 @@ -207,6 +215,13 @@
    1.42        fprintf (stderr, "can't get image width\n");
    1.43        goto fail;
    1.44      }
    1.45 +
    1.46 +  if (1 != TIFFGetField (in, TIFFTAG_SAMPLESPERPIXEL, & samples_per_pixel))
    1.47 +    {
    1.48 +      fprintf (stderr, "can't get samples per pixel\n");
    1.49 +      goto fail;
    1.50 +    }
    1.51 +
    1.52  #ifdef CHECK_DEPTH
    1.53    if (1 != TIFFGetField (in, TIFFTAG_IMAGEDEPTH, & image_depth))
    1.54      {
    1.55 @@ -245,6 +260,12 @@
    1.56    printf ("resolution unit %u, x resolution %f, y resolution %f\n",
    1.57  	  resolution_unit, x_resolution, y_resolution);
    1.58  
    1.59 +  if (samples_per_pixel != 1)
    1.60 +    {
    1.61 +      fprintf (stderr, "samples per pixel %u, must be 1\n", samples_per_pixel);
    1.62 +      goto fail;
    1.63 +    }
    1.64 +
    1.65  #ifdef CHECK_DEPTH
    1.66    if (image_depth != 1)
    1.67      {
    1.68 @@ -289,6 +310,7 @@
    1.69    TIFFSetField (tiff_temp, TIFFTAG_XRESOLUTION, x_resolution);
    1.70    TIFFSetField (tiff_temp, TIFFTAG_YRESOLUTION, y_resolution);
    1.71  
    1.72 +  TIFFSetField (tiff_temp, TIFFTAG_SAMPLESPERPIXEL, samples_per_pixel);
    1.73    TIFFSetField (tiff_temp, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
    1.74    TIFFSetField (tiff_temp, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
    1.75    TIFFSetField (tiff_temp, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
    1.76 @@ -309,8 +331,8 @@
    1.77    _TIFFfree (buffer);
    1.78    TIFFClose (tiff_temp);
    1.79  
    1.80 -  height_points = (image_width / x_resolution) * POINTS_PER_INCH;
    1.81 -  width_points = (image_length / y_resolution) * POINTS_PER_INCH;
    1.82 +  width_points = (image_width / x_resolution) * POINTS_PER_INCH;
    1.83 +  height_points = (image_length / y_resolution) * POINTS_PER_INCH;
    1.84  
    1.85    if ((height_points > PAGE_MAX_POINTS) || (width_points > PAGE_MAX_POINTS))
    1.86      {
    1.87 @@ -332,12 +354,12 @@
    1.88  		  tiff_temp_fn,
    1.89  		  panda_image_tiff);
    1.90  
    1.91 -  unlink (tiff_temp_fn);
    1.92 -
    1.93 -  return (1);
    1.94 +  result = 1;
    1.95  
    1.96   fail:
    1.97 -  return (0);
    1.98 +  if (tiff_temp_fd)
    1.99 +    unlink (tiff_temp_fn);
   1.100 +  return (result);
   1.101  }
   1.102  
   1.103