pdf_jpeg.c

changeset 139
ec2a06d8a2a6
parent 125
e2ef1c2f9eca
child 145
3ed3f7f32837
     1.1 --- a/pdf_jpeg.c	Sun Mar 16 15:40:00 2003 +0000
     1.2 +++ b/pdf_jpeg.c	Wed Mar 19 15:39:55 2003 +0000
     1.3 @@ -2,7 +2,7 @@
     1.4   * tumble: build a PDF file from image files
     1.5   *
     1.6   * PDF routines
     1.7 - * $Id: pdf_jpeg.c,v 1.2 2003/03/13 00:57:05 eric Exp $
     1.8 + * $Id: pdf_jpeg.c,v 1.3 2003/03/19 07:39:55 eric Exp $
     1.9   * Copyright 2003 Eric Smith <eric@brouhaha.com>
    1.10   *
    1.11   * This program is free software; you can redistribute it and/or modify
    1.12 @@ -40,9 +40,9 @@
    1.13  {
    1.14    double width, height;
    1.15    double x, y;
    1.16 +  bool color;  /* false for grayscale */
    1.17 +  uint32_t width_samples, height_samples;
    1.18    FILE *f;
    1.19 -  unsigned long Columns;
    1.20 -  unsigned long Rows;
    1.21    char XObject_name [4];
    1.22  };
    1.23  
    1.24 @@ -69,14 +69,13 @@
    1.25  					   void *app_data)
    1.26  {
    1.27    struct pdf_jpeg_image *image = app_data;
    1.28 -  FILE *f;
    1.29    int rlen, wlen;
    1.30    uint8_t *wp;
    1.31    uint8_t buffer [8192];
    1.32  
    1.33    while (! feof (image->f))
    1.34      {
    1.35 -      rlen = fread (& buffer [0], 1, JPEG_BUFFER_SIZE, f);
    1.36 +      rlen = fread (& buffer [0], 1, JPEG_BUFFER_SIZE, image->f);
    1.37        wp = & buffer [0];
    1.38        while (rlen)
    1.39  	{
    1.40 @@ -88,9 +87,11 @@
    1.41  	  rlen -= wlen;
    1.42  	  wp += wlen;
    1.43  	}
    1.44 -      if (ferror (f))
    1.45 +      if (ferror (image->f))
    1.46  	pdf_fatal ("error on input file\n");
    1.47      }
    1.48 +
    1.49 +  pdf_stream_printf (pdf_file, stream, "\r\n");
    1.50  }
    1.51  
    1.52  
    1.53 @@ -105,7 +106,6 @@
    1.54  
    1.55    struct pdf_obj *stream;
    1.56    struct pdf_obj *stream_dict;
    1.57 -  struct pdf_obj *decode_parms;
    1.58  
    1.59    struct pdf_obj *content_stream;
    1.60  
    1.61 @@ -117,10 +117,14 @@
    1.62    image->y = y;
    1.63  
    1.64    image->f = f;
    1.65 -#if 0
    1.66 -  image->Columns = bitmap->rect.max.x - bitmap->rect.min.x;
    1.67 -  image->Rows = bitmap->rect.max.y - bitmap->rect.min.y;
    1.68 -#endif
    1.69 +
    1.70 +  /* $$$ quick hack, should read these from file! */
    1.71 +  image->color = 1;
    1.72 +  image->width_samples = 71;
    1.73 +  image->height_samples = 88;
    1.74 +
    1.75 +  pdf_add_array_elem_unique (pdf_page->procset,
    1.76 +			     pdf_new_name (image->color ? "ImageC" : "ImageB"));
    1.77  
    1.78    stream_dict = pdf_new_obj (PT_DICTIONARY);
    1.79  
    1.80 @@ -135,26 +139,14 @@
    1.81  
    1.82    pdf_set_dict_entry (stream_dict, "Type",    pdf_new_name ("XObject"));
    1.83    pdf_set_dict_entry (stream_dict, "Subtype", pdf_new_name ("Image"));
    1.84 -  pdf_set_dict_entry (stream_dict, "Name",    pdf_new_name (& image->XObject_name [0]));
    1.85 -  pdf_set_dict_entry (stream_dict, "Width",   pdf_new_integer (image->Columns));
    1.86 -  pdf_set_dict_entry (stream_dict, "Height",  pdf_new_integer (image->Rows));
    1.87 +// Name is required in PDF 1.0 but obsoleted in later PDF versions
    1.88 +//  pdf_set_dict_entry (stream_dict, "Name",    pdf_new_name (& image->XObject_name [0]));
    1.89 +  pdf_set_dict_entry (stream_dict, "Width",   pdf_new_integer (image->width_samples));
    1.90 +  pdf_set_dict_entry (stream_dict, "Height",  pdf_new_integer (image->height_samples));
    1.91 +  pdf_set_dict_entry (stream_dict, "ColorSpace", pdf_new_name (image->color ? "DeviceRGB" : "DeviceGray"));
    1.92    pdf_set_dict_entry (stream_dict, "BitsPerComponent", pdf_new_integer (8));
    1.93  
    1.94 -  decode_parms = pdf_new_obj (PT_DICTIONARY);
    1.95 -
    1.96 -  pdf_set_dict_entry (decode_parms,
    1.97 -		      "K",
    1.98 -		      pdf_new_integer (-1));
    1.99 -
   1.100 -  pdf_set_dict_entry (decode_parms,
   1.101 -		      "Columns",
   1.102 -		      pdf_new_integer (image->Columns));
   1.103 -
   1.104 -  pdf_set_dict_entry (decode_parms,
   1.105 -		      "Rows",
   1.106 -		      pdf_new_integer (image->Rows));
   1.107 -
   1.108 -  pdf_stream_add_filter (stream, "DCTDecode", decode_parms);
   1.109 +  pdf_stream_add_filter (stream, "DCTDecode", NULL);
   1.110  
   1.111    /* the following will write the stream, using our callback function to
   1.112       get the actual data */
   1.113 @@ -170,4 +162,3 @@
   1.114  
   1.115    pdf_write_ind_obj (pdf_page->pdf_file, content_stream);
   1.116  }
   1.117 -