]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fixed bug when loading image files with different X and Y resolutions.
authormike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 18 Jul 2000 19:45:53 +0000 (19:45 +0000)
committermike <mike@7a7537e8-13f0-0310-91df-b6672ffda945>
Tue, 18 Jul 2000 19:45:53 +0000 (19:45 +0000)
The default colorspace for imagetoraster is now black, matching
pstoraster.

Properly handle reading of binary data in PS files.

git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@1223 7a7537e8-13f0-0310-91df-b6672ffda945

filter/image-tiff.c
filter/imagetops.c
filter/imagetoraster.c
filter/pstops.c

index 95e9c2943d636f8758f75b3a0d6e756c12e7a9da..79bde792d0b88cfda74ea273f2997a688627059a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: image-tiff.c,v 1.14 2000/07/17 20:28:52 mike Exp $"
+ * "$Id: image-tiff.c,v 1.15 2000/07/18 19:45:52 mike Exp $"
  *
  *   TIFF file routines for the Common UNIX Printing System (CUPS).
  *
@@ -54,6 +54,7 @@ ImageReadTIFF(image_t    *img,                /* IO - Image */
   TIFF         *tif;                   /* TIFF file */
   uint32       width, height;          /* Size of image */
   uint16       photometric,            /* Colorspace */
+               compression,            /* Type of compression */
                orientation,            /* Orientation */
                resunit,                /* Units for resolution */
                samples,                /* Number of samples/pixel */
@@ -101,6 +102,7 @@ ImageReadTIFF(image_t    *img,              /* IO - Image */
   if (!TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &width) ||
       !TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &height) ||
       !TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &photometric) ||
+      !TIFFGetField(tif, TIFFTAG_COMPRESSION, &compression) ||
       !TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &samples) ||
       !TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &bits))
   {
@@ -246,19 +248,22 @@ ImageReadTIFF(image_t    *img,            /* IO - Image */
   * each which must be handled separately...
   */
 
+  fprintf(stderr, "DEBUG: photometric = %d\n", photometric);
+  fprintf(stderr, "DEBUG: compression = %d\n", compression);
+
   switch (photometric)
   {
     case PHOTOMETRIC_MINISWHITE :
     case PHOTOMETRIC_MINISBLACK :
-        if (photometric == PHOTOMETRIC_MINISBLACK)
+        if (photometric == PHOTOMETRIC_MINISWHITE)
         {
-          zero = 0;
-          one  = 255;
+          zero = 255;
+          one  = 0;
         }
         else
         {
-          zero = 255;
-          one  = 0;
+          zero = 0;
+          one  = 255;
         }
 
         if (orientation < ORIENTATION_LEFTTOP)
@@ -1622,5 +1627,5 @@ ImageReadTIFF(image_t    *img,            /* IO - Image */
 
 
 /*
- * End of "$Id: image-tiff.c,v 1.14 2000/07/17 20:28:52 mike Exp $".
+ * End of "$Id: image-tiff.c,v 1.15 2000/07/18 19:45:52 mike Exp $".
  */
index 67a2cd9950c64adff4babdca65fac4929bc6ca95..9697f8634edc219b94af938c84914b500aec26aa 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: imagetops.c,v 1.25 2000/06/27 19:01:58 mike Exp $"
+ * "$Id: imagetops.c,v 1.26 2000/07/18 19:45:52 mike Exp $"
  *
  *   Image file to PostScript filter for the Common UNIX Printing System (CUPS).
  *
@@ -73,6 +73,7 @@ main(int  argc,               /* I - Number of command-line arguments */
                ysize,
                xsize2,
                ysize2;
+  float                aspect;         /* Aspect ratio */
   int          xpages,         /* # x pages */
                ypages,         /* # y pages */
                xpage,          /* Current x page */
@@ -93,7 +94,7 @@ main(int  argc,               /* I - Number of command-line arguments */
   float                g;              /* Gamma correction value */
   float                b;              /* Brightness factor */
   float                zoom;           /* Zoom facter */
-  int          ppi;            /* Pixels-per-inch */
+  int          xppi, yppi;     /* Pixels-per-inch */
   int          hue, sat;       /* Hue and saturation adjustment */
   int          realcopies;     /* Real copies being printed */
   float                left, top;      /* Left and top of image */
@@ -110,7 +111,8 @@ main(int  argc,             /* I - Number of command-line arguments */
   */
 
   zoom = 0.0;
-  ppi  = 0;
+  xppi = 0;
+  yppi = 0;
   hue  = 0;
   sat  = 100;
   g    = 1.0;
@@ -151,7 +153,8 @@ main(int  argc,             /* I - Number of command-line arguments */
     zoom = atoi(val) * 0.01;
 
   if ((val = cupsGetOption("ppi", num_options, options)) != NULL)
-    ppi = atoi(val);
+    if (sscanf(val, "%dx%d", &xppi, &yppi) < 2)
+      yppi = xppi;
 
   if ((val = cupsGetOption("position", num_options, options)) != NULL)
   {
@@ -227,20 +230,26 @@ main(int  argc,           /* I - Number of command-line arguments */
   * Scale as necessary...
   */
 
-  if (zoom == 0.0 && ppi == 0)
-    ppi = img->xppi;
-
   xprint = (PageRight - PageLeft) / 72.0;
   yprint = (PageTop - PageBottom) / 72.0;
 
-  if (ppi > 0)
+  if (zoom == 0.0 && xppi == 0)
+  {
+    xppi = img->xppi;
+    yppi = img->yppi;
+  }
+
+  if (yppi == 0)
+    yppi = xppi;
+
+  if (xppi > 0)
   {
    /*
     * Scale the image as neccesary to match the desired pixels-per-inch.
     */
     
-    xinches = (float)img->xsize / (float)ppi;
-    yinches = (float)img->ysize / (float)ppi;
+    xinches = (float)img->xsize / (float)xppi;
+    yinches = (float)img->ysize / (float)yppi;
 
    /*
     * Rotate the image if it will fit landscape but not portrait...
@@ -275,24 +284,32 @@ main(int  argc,           /* I - Number of command-line arguments */
     * Scale percentage of page size...
     */
 
+    aspect = (float)img->yppi / (float)img->xppi;
+
+    fprintf(stderr, "DEBUG: img->xppi = %d, img->yppi = %d, aspect = %f\n",
+            img->xppi, img->yppi, aspect);
+
     xsize = xprint * zoom;
-    ysize = xsize * img->ysize / img->xsize;
+    ysize = xsize * img->ysize / img->xsize / aspect;
 
     if (ysize > (yprint * zoom))
     {
       ysize = yprint * zoom;
-      xsize = ysize * img->xsize / img->ysize;
+      xsize = ysize * img->xsize * aspect / img->ysize;
     }
 
     xsize2 = yprint * zoom;
-    ysize2 = xsize2 * img->ysize / img->xsize;
+    ysize2 = xsize2 * img->ysize / img->xsize / aspect;
 
     if (ysize2 > (xprint * zoom))
     {
       ysize2 = xprint * zoom;
-      xsize2 = ysize2 * img->xsize / img->ysize;
+      xsize2 = ysize2 * img->xsize * aspect / img->ysize;
     }
 
+    fprintf(stderr, "DEBUG: xsize = %.0f, ysize = %.0f\n", xsize, ysize);
+    fprintf(stderr, "DEBUG: xsize2 = %.0f, ysize2 = %.0f\n", xsize2, ysize2);
+
    /*
     * Choose the rotation with the largest area, but prefer
     * portrait if they are equal...
@@ -639,5 +656,5 @@ ps_ascii85(ib_t *data,              /* I - Data to print */
 
 
 /*
- * End of "$Id: imagetops.c,v 1.25 2000/06/27 19:01:58 mike Exp $".
+ * End of "$Id: imagetops.c,v 1.26 2000/07/18 19:45:52 mike Exp $".
  */
index 202c30dea3dfe913ac583470c73718a8a750b5df..6f8be28760bf1d7a2b3e664b2f10ec9d7e2cdbac 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: imagetoraster.c,v 1.45 2000/07/07 17:57:22 mike Exp $"
+ * "$Id: imagetoraster.c,v 1.46 2000/07/18 19:45:53 mike Exp $"
  *
  *   Image file to raster filter for the Common UNIX Printing System (CUPS).
  *
@@ -155,6 +155,7 @@ main(int  argc,             /* I - Number of command-line arguments */
                ysize,
                xsize2,
                ysize2;
+  float                aspect;         /* Aspect ratio */
   int          xpages,         /* # x pages */
                ypages,         /* # y pages */
                xpage,          /* Current x page */
@@ -180,7 +181,7 @@ main(int  argc,             /* I - Number of command-line arguments */
   float                g;              /* Gamma correction value */
   float                b;              /* Brightness factor */
   float                zoom;           /* Zoom facter */
-  int          ppi;            /* Pixels-per-inch */
+  int          xppi, yppi;     /* Pixels-per-inch */
   int          hue, sat;       /* Hue and saturation adjustment */
   izoom_t      *z;             /* ImageZoom buffer */
   int          primary,        /* Primary image colorspace */
@@ -213,7 +214,8 @@ main(int  argc,             /* I - Number of command-line arguments */
   */
 
   zoom = 0.0;
-  ppi  = 0;
+  xppi = 0;
+  yppi = 0;
   hue  = 0;
   sat  = 100;
   g    = 1.0;
@@ -254,7 +256,8 @@ main(int  argc,             /* I - Number of command-line arguments */
     zoom = atoi(val) * 0.01;
 
   if ((val = cupsGetOption("ppi", num_options, options)) != NULL)
-    ppi = atoi(val);
+    if (sscanf(val, "%dx%d", &xppi, &yppi) < 2)
+      yppi = xppi;
 
   if ((val = cupsGetOption("position", num_options, options)) != NULL)
   {
@@ -320,7 +323,7 @@ main(int  argc,             /* I - Number of command-line arguments */
   header.HWResolution[1]  = 100;
   header.cupsBitsPerColor = 1;
   header.cupsColorOrder   = CUPS_ORDER_CHUNKED;
-  header.cupsColorSpace   = CUPS_CSPACE_RGB;
+  header.cupsColorSpace   = CUPS_CSPACE_K;
 
   if ((choice = ppdFindMarkedChoice(ppd, "ColorModel")) != NULL)
     exec_choice(&header, choice);
@@ -391,7 +394,7 @@ main(int  argc,             /* I - Number of command-line arguments */
 
     default :
         primary   = IMAGE_CMYK;
-       secondary = IMAGE_CMYK;
+       secondary = IMAGE_BLACK;
 
        if (header.cupsColorOrder == CUPS_ORDER_CHUNKED)
           header.cupsBitsPerPixel = header.cupsBitsPerColor * 4;
@@ -419,7 +422,7 @@ main(int  argc,             /* I - Number of command-line arguments */
        if (header.cupsBitsPerPixel == 1)
        {
           primary   = IMAGE_CMY;
-         secondary = IMAGE_CMY;
+         secondary = IMAGE_BLACK;
 
          if (header.cupsColorOrder == CUPS_ORDER_CHUNKED)
            header.cupsBitsPerPixel = 8;
@@ -429,7 +432,7 @@ main(int  argc,             /* I - Number of command-line arguments */
        else
        {
           primary   = IMAGE_CMYK;
-         secondary = IMAGE_CMYK;
+         secondary = IMAGE_BLACK;
 
          if (header.cupsColorOrder == CUPS_ORDER_CHUNKED)
            header.cupsBitsPerPixel = header.cupsBitsPerColor * 4;
@@ -525,10 +528,16 @@ main(int  argc,           /* I - Number of command-line arguments */
   * Scale as necessary...
   */
 
-  if (zoom == 0.0 && ppi == 0)
-    ppi = img->xppi;
+  if (zoom == 0.0 && xppi == 0)
+  {
+    xppi = img->xppi;
+    yppi = img->yppi;
+  }
+
+  if (yppi == 0)
+    yppi = xppi;
 
-  if (ppi > 0)
+  if (xppi > 0)
   {
    /*
     * Scale the image as neccesary to match the desired pixels-per-inch.
@@ -545,8 +554,8 @@ main(int  argc,             /* I - Number of command-line arguments */
       yprint = (PageTop - PageBottom) / 72.0;
     }
 
-    xinches = (float)img->xsize / (float)ppi;
-    yinches = (float)img->ysize / (float)ppi;
+    xinches = (float)img->xsize / (float)xppi;
+    yinches = (float)img->ysize / (float)yppi;
 
    /*
     * Rotate the image if it will fit landscape but not portrait...
@@ -573,25 +582,32 @@ main(int  argc,           /* I - Number of command-line arguments */
 
     xprint = (PageRight - PageLeft) / 72.0;
     yprint = (PageTop - PageBottom) / 72.0;
+    aspect = (float)img->yppi / (float)img->xppi;
+
+    fprintf(stderr, "DEBUG: img->xppi = %d, img->yppi = %d, aspect = %f\n",
+            img->xppi, img->yppi, aspect);
 
     xsize = xprint * zoom;
-    ysize = xsize * img->ysize / img->xsize;
+    ysize = xsize * img->ysize / img->xsize / aspect;
 
     if (ysize > (yprint * zoom))
     {
       ysize = yprint * zoom;
-      xsize = ysize * img->xsize / img->ysize;
+      xsize = ysize * img->xsize * aspect / img->ysize;
     }
 
     xsize2 = yprint * zoom;
-    ysize2 = xsize2 * img->ysize / img->xsize;
+    ysize2 = xsize2 * img->ysize / img->xsize / aspect;
 
     if (ysize2 > (xprint * zoom))
     {
       ysize2 = xprint * zoom;
-      xsize2 = ysize2 * img->xsize / img->ysize;
+      xsize2 = ysize2 * img->xsize * aspect / img->ysize;
     }
 
+    fprintf(stderr, "DEBUG: xsize = %.0f, ysize = %.0f\n", xsize, ysize);
+    fprintf(stderr, "DEBUG: xsize2 = %.0f, ysize2 = %.0f\n", xsize2, ysize2);
+
    /*
     * Choose the rotation with the largest area, but prefer
     * portrait if they are equal...
@@ -624,6 +640,8 @@ main(int  argc,             /* I - Number of command-line arguments */
   xpages = ceil(xinches / xprint);
   ypages = ceil(yinches / yprint);
 
+  fprintf(stderr, "DEBUG: xpages = %d, ypages = %d\n", xpages, ypages);
+
  /*
   * Compute the bitmap size...
   */
@@ -4213,5 +4231,5 @@ make_lut(ib_t  *lut,              /* I - Lookup table */
 
 
 /*
- * End of "$Id: imagetoraster.c,v 1.45 2000/07/07 17:57:22 mike Exp $".
+ * End of "$Id: imagetoraster.c,v 1.46 2000/07/18 19:45:53 mike Exp $".
  */
index 4d77f001d8fe70752c8ec26915e03c1666335a4c..1887e5323b3504de42e3c684963bffd6e1d5d5b8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: pstops.c,v 1.38 2000/05/30 20:49:51 mike Exp $"
+ * "$Id: pstops.c,v 1.39 2000/07/18 19:45:53 mike Exp $"
  *
  *   PostScript filter for the Common UNIX Printing System (CUPS).
  *
@@ -379,7 +379,10 @@ main(int  argc,                    /* I - Number of command-line arguments */
         tbytes = atoi(strchr(line, ':') + 1);
        while (tbytes > 0)
        {
-         nbytes = fread(line, 1, sizeof(line), fp);
+         if (tbytes > sizeof(line))
+           nbytes = fread(line, 1, sizeof(line), fp);
+         else
+           nbytes = fread(line, 1, tbytes, fp);
 
           if (!sloworder)
            fwrite(line, 1, nbytes, stdout);
@@ -881,5 +884,5 @@ start_nup(int number)       /* I - Page number */
 
 
 /*
- * End of "$Id: pstops.c,v 1.38 2000/05/30 20:49:51 mike Exp $".
+ * End of "$Id: pstops.c,v 1.39 2000/07/18 19:45:53 mike Exp $".
  */