implemented ImageMask fill color arguments to pdf_write_g4_fax_image().

Fri, 21 Feb 2003 09:25:47 +0000

author
eric
date
Fri, 21 Feb 2003 09:25:47 +0000
changeset 66
6e0551b59dba
parent 65
5acb5b549729
child 67
7add7411c1c2

implemented ImageMask fill color arguments to pdf_write_g4_fax_image().

TODO file | annotate | diff | revisions
bitblt_g4.c file | annotate | diff | revisions
pdf.h file | annotate | diff | revisions
pdf_g4.c file | annotate | diff | revisions
pdf_prim.c file | annotate | diff | revisions
pdf_prim.h file | annotate | diff | revisions
t2p.c file | annotate | diff | revisions
tumble.c file | annotate | diff | revisions
     1.1 diff -r 5acb5b549729 -r 6e0551b59dba TODO
     1.2 --- a/TODO	Fri Feb 21 09:12:05 2003 +0000
     1.3 +++ b/TODO	Fri Feb 21 09:25:47 2003 +0000
     1.4 @@ -1,5 +1,5 @@
     1.5  t2p TODO list
     1.6 -$Id: TODO,v 1.8 2003/02/21 01:12:05 eric Exp $
     1.7 +$Id: TODO,v 1.9 2003/02/21 01:25:47 eric Exp $
     1.8  
     1.9  No particular order.
    1.10  
    1.11 @@ -78,8 +78,6 @@
    1.12  * balance pages tree - currently a degenerate single-level tree, but the
    1.13    PDF spec recommends max. of 6 children per parent
    1.14  
    1.15 -* ImageMask (p. 79) using fill color (g, k, or rg operator, p. 95)
    1.16 -
    1.17  * thumbnails
    1.18  
    1.19  * PDF Page rotate attribute (p. 53)?
     2.1 diff -r 5acb5b549729 -r 6e0551b59dba bitblt_g4.c
     2.2 --- a/bitblt_g4.c	Fri Feb 21 09:12:05 2003 +0000
     2.3 +++ b/bitblt_g4.c	Fri Feb 21 09:25:47 2003 +0000
     2.4 @@ -4,7 +4,7 @@
     2.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     2.6   *
     2.7   * PDF routines
     2.8 - * $Id: bitblt_g4.c,v 1.4 2003/02/21 01:01:33 eric Exp $
     2.9 + * $Id: bitblt_g4.c,v 1.5 2003/02/21 01:25:47 eric Exp $
    2.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    2.11   *
    2.12   * This program is free software; you can redistribute it and/or modify
    2.13 @@ -41,9 +41,11 @@
    2.14  {
    2.15    double width, height;
    2.16    double x, y;
    2.17 +  double r, g, b;  /* fill color, only for ImageMask */
    2.18    unsigned long Columns;
    2.19    unsigned long Rows;
    2.20 -  int BlackIs1;
    2.21 +  bool ImageMask;
    2.22 +  bool BlackIs1;
    2.23    Bitmap *bitmap;
    2.24    char XObject_name [4];
    2.25  };
    2.26 @@ -73,20 +75,16 @@
    2.27  {
    2.28    struct pdf_g4_image *image = app_data;
    2.29  
    2.30 -  char str1 [100];
    2.31 -  char *str2 = "/";
    2.32 -  char *str3 = " Do Q\r\n";
    2.33 +  /* transformation matrix is: width 0 0 height x y cm */
    2.34 +  pdf_stream_printf (pdf_file, stream, "q %g 0 0 %g %g %g cm ",
    2.35 +		     image->width, image->height,
    2.36 +		     image->x, image->y);
    2.37 +  if (image->ImageMask)
    2.38 +    pdf_stream_printf (pdf_file, stream, "%g %g %g rg ",
    2.39 +		       image->r, image->g, image->b);
    2.40  
    2.41 -  /* width 0 0 height x y cm */
    2.42 -  sprintf (str1, "q %g 0 0 %g %g %g cm\r\n",
    2.43 -	   image->width, image->height,
    2.44 -	   image->x, image->y);
    2.45 -
    2.46 -  pdf_stream_write_data (pdf_file, stream, str1, strlen (str1));
    2.47 -  pdf_stream_write_data (pdf_file, stream, str2, strlen (str2));
    2.48 -  pdf_stream_write_data (pdf_file, stream, & image->XObject_name [0],
    2.49 -			 strlen (& image->XObject_name [0]));
    2.50 -  pdf_stream_write_data (pdf_file, stream, str3, strlen (str3));
    2.51 +  pdf_stream_printf (pdf_file, stream, "/%s Do Q\r\n",
    2.52 +		     image->XObject_name);
    2.53  }
    2.54  
    2.55  
    2.56 @@ -127,8 +125,11 @@
    2.57  			     double width,
    2.58  			     double height,
    2.59  			     Bitmap *bitmap,
    2.60 -			     int ImageMask,
    2.61 -			     int BlackIs1)          /* boolean, typ. false */
    2.62 +			     bool ImageMask,
    2.63 +			     double r, /* RGB fill color, only for ImageMask */
    2.64 +			     double g,
    2.65 +			     double b,
    2.66 +			     bool BlackIs1)          /* boolean, typ. false */
    2.67  {
    2.68    struct pdf_g4_image *image;
    2.69  
    2.70 @@ -144,10 +145,14 @@
    2.71    image->height = height;
    2.72    image->x = x;
    2.73    image->y = y;
    2.74 +  image->r = r;
    2.75 +  image->g = g;
    2.76 +  image->b = b;
    2.77  
    2.78    image->bitmap = bitmap;
    2.79    image->Columns = bitmap->rect.max.x - bitmap->rect.min.x;
    2.80    image->Rows = bitmap->rect.max.y - bitmap->rect.min.y;
    2.81 +  image->ImageMask = ImageMask;
    2.82    image->BlackIs1 = BlackIs1;
    2.83  
    2.84    stream_dict = pdf_new_obj (PT_DICTIONARY);
     3.1 diff -r 5acb5b549729 -r 6e0551b59dba pdf.h
     3.2 --- a/pdf.h	Fri Feb 21 09:12:05 2003 +0000
     3.3 +++ b/pdf.h	Fri Feb 21 09:25:47 2003 +0000
     3.4 @@ -4,7 +4,7 @@
     3.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     3.6   *
     3.7   * PDF routines
     3.8 - * $Id: pdf.h,v 1.3 2003/02/21 01:01:33 eric Exp $
     3.9 + * $Id: pdf.h,v 1.4 2003/02/21 01:25:47 eric Exp $
    3.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    3.11   *
    3.12   * This program is free software; you can redistribute it and/or modify
    3.13 @@ -59,8 +59,11 @@
    3.14  			     double width,
    3.15  			     double height,
    3.16  			     Bitmap *bitmap,
    3.17 -			     int ImageMask,
    3.18 -			     int BlackIs1);    /* boolean, typ. false */
    3.19 +			     bool ImageMask,
    3.20 +			     double r, /* RGB fill color, only for ImageMask */
    3.21 +			     double g,
    3.22 +			     double b,
    3.23 +			     bool BlackIs1);    /* boolean, typ. false */
    3.24  
    3.25  
    3.26  void pdf_set_page_number (pdf_page_handle pdf_page, char *page_number);
     4.1 diff -r 5acb5b549729 -r 6e0551b59dba pdf_g4.c
     4.2 --- a/pdf_g4.c	Fri Feb 21 09:12:05 2003 +0000
     4.3 +++ b/pdf_g4.c	Fri Feb 21 09:25:47 2003 +0000
     4.4 @@ -4,7 +4,7 @@
     4.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     4.6   *
     4.7   * PDF routines
     4.8 - * $Id: pdf_g4.c,v 1.4 2003/02/21 01:01:33 eric Exp $
     4.9 + * $Id: pdf_g4.c,v 1.5 2003/02/21 01:25:47 eric Exp $
    4.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    4.11   *
    4.12   * This program is free software; you can redistribute it and/or modify
    4.13 @@ -41,9 +41,11 @@
    4.14  {
    4.15    double width, height;
    4.16    double x, y;
    4.17 +  double r, g, b;  /* fill color, only for ImageMask */
    4.18    unsigned long Columns;
    4.19    unsigned long Rows;
    4.20 -  int BlackIs1;
    4.21 +  bool ImageMask;
    4.22 +  bool BlackIs1;
    4.23    Bitmap *bitmap;
    4.24    char XObject_name [4];
    4.25  };
    4.26 @@ -73,20 +75,16 @@
    4.27  {
    4.28    struct pdf_g4_image *image = app_data;
    4.29  
    4.30 -  char str1 [100];
    4.31 -  char *str2 = "/";
    4.32 -  char *str3 = " Do Q\r\n";
    4.33 +  /* transformation matrix is: width 0 0 height x y cm */
    4.34 +  pdf_stream_printf (pdf_file, stream, "q %g 0 0 %g %g %g cm ",
    4.35 +		     image->width, image->height,
    4.36 +		     image->x, image->y);
    4.37 +  if (image->ImageMask)
    4.38 +    pdf_stream_printf (pdf_file, stream, "%g %g %g rg ",
    4.39 +		       image->r, image->g, image->b);
    4.40  
    4.41 -  /* width 0 0 height x y cm */
    4.42 -  sprintf (str1, "q %g 0 0 %g %g %g cm\r\n",
    4.43 -	   image->width, image->height,
    4.44 -	   image->x, image->y);
    4.45 -
    4.46 -  pdf_stream_write_data (pdf_file, stream, str1, strlen (str1));
    4.47 -  pdf_stream_write_data (pdf_file, stream, str2, strlen (str2));
    4.48 -  pdf_stream_write_data (pdf_file, stream, & image->XObject_name [0],
    4.49 -			 strlen (& image->XObject_name [0]));
    4.50 -  pdf_stream_write_data (pdf_file, stream, str3, strlen (str3));
    4.51 +  pdf_stream_printf (pdf_file, stream, "/%s Do Q\r\n",
    4.52 +		     image->XObject_name);
    4.53  }
    4.54  
    4.55  
    4.56 @@ -127,8 +125,11 @@
    4.57  			     double width,
    4.58  			     double height,
    4.59  			     Bitmap *bitmap,
    4.60 -			     int ImageMask,
    4.61 -			     int BlackIs1)          /* boolean, typ. false */
    4.62 +			     bool ImageMask,
    4.63 +			     double r, /* RGB fill color, only for ImageMask */
    4.64 +			     double g,
    4.65 +			     double b,
    4.66 +			     bool BlackIs1)          /* boolean, typ. false */
    4.67  {
    4.68    struct pdf_g4_image *image;
    4.69  
    4.70 @@ -144,10 +145,14 @@
    4.71    image->height = height;
    4.72    image->x = x;
    4.73    image->y = y;
    4.74 +  image->r = r;
    4.75 +  image->g = g;
    4.76 +  image->b = b;
    4.77  
    4.78    image->bitmap = bitmap;
    4.79    image->Columns = bitmap->rect.max.x - bitmap->rect.min.x;
    4.80    image->Rows = bitmap->rect.max.y - bitmap->rect.min.y;
    4.81 +  image->ImageMask = ImageMask;
    4.82    image->BlackIs1 = BlackIs1;
    4.83  
    4.84    stream_dict = pdf_new_obj (PT_DICTIONARY);
     5.1 diff -r 5acb5b549729 -r 6e0551b59dba pdf_prim.c
     5.2 --- a/pdf_prim.c	Fri Feb 21 09:12:05 2003 +0000
     5.3 +++ b/pdf_prim.c	Fri Feb 21 09:25:47 2003 +0000
     5.4 @@ -4,7 +4,7 @@
     5.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     5.6   *
     5.7   * PDF routines
     5.8 - * $Id: pdf_prim.c,v 1.3 2003/02/20 04:44:17 eric Exp $
     5.9 + * $Id: pdf_prim.c,v 1.4 2003/02/21 01:25:47 eric Exp $
    5.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    5.11   *
    5.12   * This program is free software; you can redistribute it and/or modify
    5.13 @@ -24,6 +24,7 @@
    5.14   */
    5.15  
    5.16  
    5.17 +#include <stdarg.h>
    5.18  #include <stdbool.h>
    5.19  #include <stdint.h>
    5.20  #include <stdio.h>
    5.21 @@ -452,6 +453,18 @@
    5.22  }
    5.23  
    5.24  
    5.25 +void pdf_stream_printf (pdf_file_handle pdf_file,
    5.26 +			struct pdf_obj *stream,
    5.27 +			char *fmt, ...)
    5.28 +{
    5.29 +  va_list ap;
    5.30 +
    5.31 +  va_start (ap, fmt);
    5.32 +  vfprintf (pdf_file->f, fmt, ap);
    5.33 +  va_end (ap);
    5.34 +}
    5.35 +
    5.36 +
    5.37  void pdf_write_stream (pdf_file_handle pdf_file, struct pdf_obj *stream)
    5.38  {
    5.39    unsigned long begin_pos, end_pos;
     6.1 diff -r 5acb5b549729 -r 6e0551b59dba pdf_prim.h
     6.2 --- a/pdf_prim.h	Fri Feb 21 09:12:05 2003 +0000
     6.3 +++ b/pdf_prim.h	Fri Feb 21 09:25:47 2003 +0000
     6.4 @@ -4,7 +4,7 @@
     6.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     6.6   *
     6.7   * PDF routines
     6.8 - * $Id: pdf_prim.h,v 1.2 2003/02/20 04:44:17 eric Exp $
     6.9 + * $Id: pdf_prim.h,v 1.3 2003/02/21 01:25:47 eric Exp $
    6.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    6.11   *
    6.12   * This program is free software; you can redistribute it and/or modify
    6.13 @@ -95,13 +95,18 @@
    6.14  				pdf_stream_write_callback callback,
    6.15  				void *app_data);
    6.16  
    6.17 -/* The callback should call pdf_stream_write_data to write the actual
    6.18 -   stream data. */
    6.19 +/* The callback should call pdf_stream_write_data or pdf_stream_printf
    6.20 +   to write the actual stream data. */
    6.21  void pdf_stream_write_data (pdf_file_handle pdf_file,
    6.22  			    struct pdf_obj *stream,
    6.23  			    char *data,
    6.24  			    unsigned long len);
    6.25  
    6.26 +void pdf_stream_printf (pdf_file_handle pdf_file,
    6.27 +			struct pdf_obj *stream,
    6.28 +			char *fmt, ...);
    6.29 +
    6.30 +
    6.31  void pdf_stream_add_filter (struct pdf_obj *stream,
    6.32  			    char *filter_name,
    6.33  			    struct pdf_obj *decode_parms);
     7.1 diff -r 5acb5b549729 -r 6e0551b59dba t2p.c
     7.2 --- a/t2p.c	Fri Feb 21 09:12:05 2003 +0000
     7.3 +++ b/t2p.c	Fri Feb 21 09:25:47 2003 +0000
     7.4 @@ -4,7 +4,7 @@
     7.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     7.6   *
     7.7   * Main program
     7.8 - * $Id: t2p.c,v 1.23 2003/02/21 01:01:33 eric Exp $
     7.9 + * $Id: t2p.c,v 1.24 2003/02/21 01:25:47 eric Exp $
    7.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    7.11   *
    7.12   * This program is free software; you can redistribute it and/or modify
    7.13 @@ -465,12 +465,11 @@
    7.14    page = pdf_new_page (out->pdf, width_points, height_points);
    7.15  
    7.16    pdf_write_g4_fax_image (page,
    7.17 -			  0,  /* x */
    7.18 -			  0,  /* y */
    7.19 -			  width_points,
    7.20 -			  height_points,
    7.21 +			  0, 0,  /* x, y */
    7.22 +			  width_points, height_points,
    7.23  			  bitmap,
    7.24  			  0, /* ImageMask */
    7.25 +			  0, 0, 0,  /* r, g, b */
    7.26  			  0); /* BlackIs1 */
    7.27  
    7.28    free_bitmap (bitmap);
     8.1 diff -r 5acb5b549729 -r 6e0551b59dba tumble.c
     8.2 --- a/tumble.c	Fri Feb 21 09:12:05 2003 +0000
     8.3 +++ b/tumble.c	Fri Feb 21 09:25:47 2003 +0000
     8.4 @@ -4,7 +4,7 @@
     8.5   *      will be compressed using ITU-T T.6 (G4) fax encoding.
     8.6   *
     8.7   * Main program
     8.8 - * $Id: tumble.c,v 1.23 2003/02/21 01:01:33 eric Exp $
     8.9 + * $Id: tumble.c,v 1.24 2003/02/21 01:25:47 eric Exp $
    8.10   * Copyright 2001, 2002, 2003 Eric Smith <eric@brouhaha.com>
    8.11   *
    8.12   * This program is free software; you can redistribute it and/or modify
    8.13 @@ -465,12 +465,11 @@
    8.14    page = pdf_new_page (out->pdf, width_points, height_points);
    8.15  
    8.16    pdf_write_g4_fax_image (page,
    8.17 -			  0,  /* x */
    8.18 -			  0,  /* y */
    8.19 -			  width_points,
    8.20 -			  height_points,
    8.21 +			  0, 0,  /* x, y */
    8.22 +			  width_points, height_points,
    8.23  			  bitmap,
    8.24  			  0, /* ImageMask */
    8.25 +			  0, 0, 0,  /* r, g, b */
    8.26  			  0); /* BlackIs1 */
    8.27  
    8.28    free_bitmap (bitmap);