t2p.c

changeset 26
4368c5fd9242
parent 25
139b91f9a224
child 28
ba8313d18bd3
     1.1 diff -r 139b91f9a224 -r 4368c5fd9242 t2p.c
     1.2 --- a/t2p.c	Mon Dec 31 16:44:24 2001 +0000
     1.3 +++ b/t2p.c	Tue Jan 01 03:44:40 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.7 2001/12/31 08:44:24 eric Exp $
     1.9 + * $Id: t2p.c,v 1.8 2001/12/31 19:44:40 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 @@ -33,49 +33,115 @@
    1.14  #include "tiff2pdf.h"
    1.15  
    1.16  
    1.17 +typedef struct output_file_t
    1.18 +{
    1.19 +  struct output_file_t *next;
    1.20 +  char *name;
    1.21 +  panda_pdf *pdf;
    1.22 +} output_file_t;
    1.23 +
    1.24 +
    1.25 +char *in_filename;
    1.26  TIFF *in;
    1.27 -panda_pdf *out;
    1.28 +output_file_t *output_files;
    1.29 +output_file_t *out;
    1.30 +/* panda_pdf *out; */
    1.31  
    1.32  
    1.33  boolean close_tiff_input_file (void)
    1.34  {
    1.35    if (in)
    1.36 -    TIFFClose (in);
    1.37 +    {
    1.38 +      free (in_filename);
    1.39 +      TIFFClose (in);
    1.40 +    }
    1.41    in = NULL;
    1.42 +  in_filename = NULL;
    1.43    return (1);
    1.44  }
    1.45  
    1.46  boolean open_tiff_input_file (char *name)
    1.47  {
    1.48    if (in)
    1.49 -    close_tiff_input_file ();
    1.50 +    {
    1.51 +      if (strcmp (name, in_filename) == 0)
    1.52 +	return (1);
    1.53 +      close_tiff_input_file ();
    1.54 +    }
    1.55 +  in_filename = strdup (name);
    1.56 +  if (! in_filename)
    1.57 +    {
    1.58 +      fprintf (stderr, "can't strdup input filename '%s'\n", name);
    1.59 +      return (0);
    1.60 +    }
    1.61    in = TIFFOpen (name, "r");
    1.62    if (! in)
    1.63      {
    1.64        fprintf (stderr, "can't open input file '%s'\n", name);
    1.65 +      free (in_filename);
    1.66        return (0);
    1.67      }
    1.68    return (1);
    1.69  }
    1.70  
    1.71  
    1.72 -boolean close_pdf_output_file (void)
    1.73 +boolean close_pdf_output_files (void)
    1.74  {
    1.75 -  if (out)
    1.76 -    panda_close (out);
    1.77 +  output_file_t *o, *n;
    1.78 +
    1.79 +  for (o = output_files; o; o = n)
    1.80 +    {
    1.81 +      n = o->next;
    1.82 +      panda_close (o->pdf);
    1.83 +      free (o->name);
    1.84 +      free (o);
    1.85 +    }
    1.86    out = NULL;
    1.87 +  output_files = NULL;
    1.88    return (1);
    1.89  }
    1.90  
    1.91  boolean open_pdf_output_file (char *name)
    1.92  {
    1.93 -  if (out)
    1.94 -    close_pdf_output_file ();
    1.95 -  out = panda_open (name, "w");
    1.96 -  if (! out)
    1.97 +  output_file_t *o;
    1.98 +
    1.99 +  if (out && (strcmp (name, out->name) == 0))
   1.100 +    return (1);
   1.101 +  for (o = output_files; o; o = o->next)
   1.102 +    if (strcmp (name, o->name) == 0)
   1.103 +      {
   1.104 +	out = o;
   1.105 +	return (1);
   1.106 +      }
   1.107 +  o = calloc (1, sizeof (output_file_t));
   1.108 +  if (! 0)
   1.109      {
   1.110 +      fprintf (stderr, "can't calloc output file struct for '%s'\n", name);
   1.111 +      return (0);
   1.112 +   }
   1.113 +
   1.114 +  o->name = strdup (name);
   1.115 +  if (! o->name)
   1.116 +    {
   1.117 +      fprintf (stderr, "can't strdup output filename '%s'\n", name);
   1.118 +      free (o);
   1.119        return (0);
   1.120      }
   1.121 +
   1.122 +  o->pdf = panda_open (name, "w");
   1.123 +  if (! o->pdf)
   1.124 +    {
   1.125 +      fprintf (stderr, "can't open output file '%s'\n", name);
   1.126 +      free (o->name);
   1.127 +      free (o);
   1.128 +      return (0);
   1.129 +    }
   1.130 +
   1.131 +  /* prepend new output file onto list */
   1.132 +  o->next = output_files;
   1.133 +  output_files = o;
   1.134 +
   1.135 +  out = o;
   1.136    return (1);
   1.137  }
   1.138  
   1.139 @@ -178,19 +244,19 @@
   1.140      }
   1.141  
   1.142  #if 0
   1.143 -  TIFFSetField (out, TIFFTAG_IMAGELENGTH, image_length);
   1.144 -  TIFFSetField (out, TIFFTAG_IMAGEWIDTH, image_width);
   1.145 -  TIFFSetField (out, TIFFTAG_PLANARCONFIG, planar_config);
   1.146 +  TIFFSetField (out->pdf, TIFFTAG_IMAGELENGTH, image_length);
   1.147 +  TIFFSetField (out->pdf, TIFFTAG_IMAGEWIDTH, image_width);
   1.148 +  TIFFSetField (out->pdf, TIFFTAG_PLANARCONFIG, planar_config);
   1.149  
   1.150 -  TIFFSetField (out, TIFFTAG_ROWSPERSTRIP, image_length);
   1.151 +  TIFFSetField (out->pdf, TIFFTAG_ROWSPERSTRIP, image_length);
   1.152  
   1.153 -  TIFFSetField (out, TIFFTAG_RESOLUTIONUNIT, resolution_unit);
   1.154 -  TIFFSetField (out, TIFFTAG_XRESOLUTION, x_resolution);
   1.155 -  TIFFSetField (out, TIFFTAG_YRESOLUTION, y_resolution);
   1.156 +  TIFFSetField (out->pdf, TIFFTAG_RESOLUTIONUNIT, resolution_unit);
   1.157 +  TIFFSetField (out->pdf, TIFFTAG_XRESOLUTION, x_resolution);
   1.158 +  TIFFSetField (out->pdf, TIFFTAG_YRESOLUTION, y_resolution);
   1.159  
   1.160 -  TIFFSetField (out, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
   1.161 -  TIFFSetField (out, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
   1.162 -  TIFFSetField (out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
   1.163 +  TIFFSetField (out->pdf, TIFFTAG_BITSPERSAMPLE, bits_per_sample);
   1.164 +  TIFFSetField (out->pdf, TIFFTAG_COMPRESSION, COMPRESSION_CCITTFAX4);
   1.165 +  TIFFSetField (out->pdf, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISWHITE);
   1.166  #endif
   1.167  
   1.168    buffer = _TIFFmalloc (TIFFScanlineSize (in));
   1.169 @@ -204,7 +270,7 @@
   1.170      {
   1.171        TIFFReadScanline (in, buffer, row, 0);
   1.172  #if 0
   1.173 -      TIFFWriteScanline (out, buffer, row, 0);
   1.174 +      TIFFWriteScanline (out->pdf, buffer, row, 0);
   1.175  #endif
   1.176      }
   1.177  
   1.178 @@ -231,10 +297,19 @@
   1.179      }
   1.180  
   1.181    if (! parse_spec_file (argv [1]))
   1.182 -    goto fail;
   1.183 +    {
   1.184 +      result = 2;
   1.185 +      goto fail;
   1.186 +    }
   1.187 +
   1.188 +  if (! process_specs ())
   1.189 +    {
   1.190 +      result = 3;
   1.191 +      goto fail;
   1.192 +    }
   1.193    
   1.194   fail:
   1.195    close_tiff_input_file ();
   1.196 -  close_pdf_output_file ();
   1.197 +  close_pdf_output_files ();
   1.198    return (result);
   1.199  }