bitblt_g4.c

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