pdf_g4.c

changeset 62
9bd354b83e16
parent 60
ffb5b1e54eb2
child 64
151394412eba
     1.1 --- a/pdf_g4.c	Thu Feb 20 12:21:10 2003 +0000
     1.2 +++ b/pdf_g4.c	Thu Feb 20 12:44:17 2003 +0000
     1.3 @@ -1,7 +1,36 @@
     1.4 +/*
     1.5 + * t2p: Create a PDF file from the contents of one or more TIFF
     1.6 + *      bilevel image files.  The images in the resulting PDF file
     1.7 + *      will be compressed using ITU-T T.6 (G4) fax encoding.
     1.8 + *
     1.9 + * PDF routines
    1.10 + * $Id: pdf_g4.c,v 1.3 2003/02/20 04:44:17 eric Exp $
    1.11 + * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    1.12 + *
    1.13 + * This program is free software; you can redistribute it and/or modify
    1.14 + * it under the terms of the GNU General Public License version 2 as
    1.15 + * published by the Free Software Foundation.  Note that permission is
    1.16 + * not granted to redistribute this program under the terms of any
    1.17 + * other version of the General Public License.
    1.18 + *
    1.19 + * This program is distributed in the hope that it will be useful,
    1.20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.22 + * GNU General Public License for more details.
    1.23 + *
    1.24 + * You should have received a copy of the GNU General Public License
    1.25 + * along with this program; if not, write to the Free Software
    1.26 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA
    1.27 + */
    1.28 +
    1.29 +
    1.30 +#include <stdbool.h>
    1.31 +#include <stdint.h>
    1.32  #include <stdio.h>
    1.33  #include <string.h>
    1.34  
    1.35  
    1.36 +#include "bitblt.h"
    1.37  #include "pdf.h"
    1.38  #include "pdf_util.h"
    1.39  #include "pdf_prim.h"
    1.40 @@ -12,10 +41,8 @@
    1.41  {
    1.42    unsigned long Columns;
    1.43    unsigned long Rows;
    1.44 -  unsigned long rowbytes;
    1.45    int BlackIs1;
    1.46 -  unsigned char *data;
    1.47 -  unsigned long len;
    1.48 +  Bitmap *bitmap;
    1.49    char XObject_name [4];
    1.50  };
    1.51  
    1.52 @@ -69,23 +96,24 @@
    1.53  {
    1.54    struct pdf_g4_image *image = app_data;
    1.55  
    1.56 -#if 1
    1.57 +#if 0
    1.58    pdf_stream_write_data (pdf_file, stream, image->data, image->len);
    1.59  #else
    1.60    unsigned long row = 0;
    1.61 -  unsigned char *ref;
    1.62 -  unsigned char *raw;
    1.63 +  word_type *ref;
    1.64 +  word_type *raw;
    1.65  
    1.66    ref = NULL;
    1.67 -  raw = image->data;
    1.68 +  raw = image->bitmap->bits;
    1.69  
    1.70    while (row < image->Rows)
    1.71      {
    1.72 -      pdf_stream_write_data (pdf_file, stream, raw, image->rowbytes);
    1.73 +      pdf_stream_write_data (pdf_file, stream, raw,
    1.74 +			     image->bitmap->row_words * sizeof (word_type));
    1.75  
    1.76        row++;
    1.77        ref = raw;
    1.78 -      raw += image->rowbytes;
    1.79 +      raw += image->bitmap->row_words;
    1.80      }
    1.81    /* $$$ generate and write EOFB code */
    1.82    /* $$$ flush any remaining buffered bits */
    1.83 @@ -94,13 +122,9 @@
    1.84  
    1.85  
    1.86  void pdf_write_g4_fax_image (pdf_page_handle pdf_page,
    1.87 -			     unsigned long Columns,
    1.88 -			     unsigned long Rows,
    1.89 -			     unsigned long rowbytes,
    1.90 +			     Bitmap *bitmap,
    1.91  			     int ImageMask,
    1.92 -			     int BlackIs1,          /* boolean, typ. false */
    1.93 -			     unsigned char *data,
    1.94 -			     unsigned long len)
    1.95 +			     int BlackIs1)          /* boolean, typ. false */
    1.96  {
    1.97    struct pdf_g4_image *image;
    1.98  
    1.99 @@ -112,12 +136,10 @@
   1.100  
   1.101    image = pdf_calloc (sizeof (struct pdf_g4_image));
   1.102  
   1.103 -  image->Columns = Columns;
   1.104 -  image->Rows = Rows;
   1.105 -  image->rowbytes = rowbytes;
   1.106 +  image->bitmap = bitmap;
   1.107 +  image->Columns = bitmap->rect.max.x - bitmap->rect.min.x;
   1.108 +  image->Rows = bitmap->rect.max.y - bitmap->rect.min.y;
   1.109    image->BlackIs1 = BlackIs1;
   1.110 -  image->data = data;
   1.111 -  image->len = len;
   1.112  
   1.113    stream_dict = pdf_new_obj (PT_DICTIONARY);
   1.114  
   1.115 @@ -133,8 +155,8 @@
   1.116    pdf_set_dict_entry (stream_dict, "Type",    pdf_new_name ("XObject"));
   1.117    pdf_set_dict_entry (stream_dict, "Subtype", pdf_new_name ("Image"));
   1.118    pdf_set_dict_entry (stream_dict, "Name",    pdf_new_name (& image->XObject_name [0]));
   1.119 -  pdf_set_dict_entry (stream_dict, "Width",   pdf_new_integer (Columns));
   1.120 -  pdf_set_dict_entry (stream_dict, "Height",  pdf_new_integer (Rows));
   1.121 +  pdf_set_dict_entry (stream_dict, "Width",   pdf_new_integer (image->Columns));
   1.122 +  pdf_set_dict_entry (stream_dict, "Height",  pdf_new_integer (image->Rows));
   1.123    pdf_set_dict_entry (stream_dict, "BitsPerComponent", pdf_new_integer (1));
   1.124    if (ImageMask)
   1.125      pdf_set_dict_entry (stream_dict, "ImageMask", pdf_new_bool (ImageMask));
   1.126 @@ -149,11 +171,11 @@
   1.127  
   1.128    pdf_set_dict_entry (decode_parms,
   1.129  		      "Columns",
   1.130 -		      pdf_new_integer (Columns));
   1.131 +		      pdf_new_integer (image->Columns));
   1.132  
   1.133    pdf_set_dict_entry (decode_parms,
   1.134  		      "Rows",
   1.135 -		      pdf_new_integer (Rows));
   1.136 +		      pdf_new_integer (image->Rows));
   1.137  
   1.138    if (BlackIs1)
   1.139      pdf_set_dict_entry (decode_parms,