pdf_jpeg.c

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