]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - filter/raster.c
Merge changes from CUPS 1.4svn-r7961.
[thirdparty/cups.git] / filter / raster.c
index 32155073bfdd49a45babe4be201820f10f914891..c19db7256ce15087e630bc298c918662764d0035 100644 (file)
@@ -1,27 +1,18 @@
 /*
- * "$Id: raster.c 6274 2007-02-13 21:05:28Z mike $"
+ * "$Id: raster.c 7720 2008-07-11 22:46:21Z mike $"
  *
  *   Raster file routines for the Common UNIX Printing System (CUPS).
  *
+ *   Copyright 2007-2008 by Apple Inc.
  *   Copyright 1997-2006 by Easy Software Products.
  *
  *   This file is part of the CUPS Imaging library.
  *
  *   These coded instructions, statements, and computer programs are the
- *   property of Easy Software Products and are protected by Federal
- *   copyright law.  Distribution and use rights are outlined in the file
- *   "LICENSE.txt" which should have been included with this file.  If this
- *   file is missing or damaged please contact Easy Software Products
- *   at:
- *
- *       Attn: CUPS Licensing Information
- *       Easy Software Products
- *       44141 Airport View Drive, Suite 204
- *       Hollywood, Maryland 20636 USA
- *
- *       Voice: (301) 373-9600
- *       EMail: cups-info@cups.org
- *         WWW: http://www.cups.org
+ *   property of Apple Inc. and are protected by Federal copyright
+ *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
+ *   which should have been included with this file.  If this file is
+ *   file is missing or damaged, see the license at "http://www.cups.org/".
  *
  *   This file is subject to the Apple OS-Developed Software exception.
  *
  *   cupsRasterClose()         - Close a raster stream.
  *   cupsRasterOpen()          - Open a raster stream.
  *   cupsRasterReadHeader()    - Read a raster page header and store it in a
- *                               V1 page header structure.
+ *                               version 1 page header structure.
  *   cupsRasterReadHeader2()   - Read a raster page header and store it in a
- *                               V2 page header structure.
+ *                               version 2 page header structure.
  *   cupsRasterReadPixels()    - Read raster pixels.
- *   cupsRasterWriteHeader()   - Write a raster page header from a V1 page
- *                               header structure.
- *   cupsRasterWriteHeader2()  - Write a raster page header from a V2 page
- *                               header structure.
+ *   cupsRasterWriteHeader()   - Write a raster page header from a version 1
+ *                               page header structure.
+ *   cupsRasterWriteHeader2()  - Write a raster page header from a version 2
+ *                               page header structure.
  *   cupsRasterWritePixels()   - Write raster pixels.
  *   cups_raster_read()        - Read through the raster buffer.
  *   cups_raster_read_header() - Read a raster page header.
@@ -107,6 +98,9 @@ static int   cups_write(int fd, const unsigned char *buf, int bytes);
 
 /*
  * 'cupsRasterClose()' - Close a raster stream.
+ *
+ * The file descriptor associated with the raster stream must be closed
+ * separately as needed.
  */
 
 void
@@ -127,11 +121,20 @@ cupsRasterClose(cups_raster_t *r) /* I - Stream to close */
 
 /*
  * 'cupsRasterOpen()' - Open a raster stream.
+ *
+ * This function associates a raster stream with the given file descriptor.
+ * For most printer driver filters, "fd" will be 0 (stdin).  For most raster
+ * image processor (RIP) filters that generate raster data, "fd" will be 1
+ * (stdout).
+ *
+ * When writing raster data, the @code CUPS_RASTER_WRITE@ or
+ * @code CUPS_RASTER_WRITE_COMPRESS@ mode can be used - compressed output
+ * is generally 25-50% smaller but adds a 100-300% execution time overhead.
  */
 
 cups_raster_t *                                /* O - New stream */
 cupsRasterOpen(int         fd,         /* I - File descriptor */
-               cups_mode_t mode)       /* I - Mode */
+               cups_mode_t mode)       /* I - Mode - @code CUPS_RASTER_READ@, @code CUPS_RASTER_WRITE@, or @code CUPS_RASTER_WRITE_COMPRESSED@ */
 {
   cups_raster_t        *r;                     /* New stream */
 
@@ -182,6 +185,8 @@ cupsRasterOpen(int         fd,              /* I - File descriptor */
         r->sync == CUPS_RASTER_REVSYNCv1 ||
         r->sync == CUPS_RASTER_REVSYNCv2)
       r->swapped = 1;
+
+    DEBUG_printf(("r->swapped=%d, r->sync=%08x\n", r->swapped, r->sync));
   }
   else
   {
@@ -213,10 +218,18 @@ cupsRasterOpen(int         fd,            /* I - File descriptor */
 
 /*
  * 'cupsRasterReadHeader()' - Read a raster page header and store it in a
- *                            V1 page header structure.
+ *                            version 1 page header structure.
+ *
+ * This function is deprecated. Use @link cupsRasterReadHeader2@ instead.
+ *
+ * Version 1 page headers were used in CUPS 1.0 and 1.1 and contain a subset
+ * of the version 2 page header data. This function handles reading version 2
+ * page headers and copying only the version 1 data into the provided buffer.
+ *
+ * @deprecated@
  */
 
-unsigned                               /* O - 1 on success, 0 on fail */
+unsigned                               /* O - 1 on success, 0 on failure/end-of-file */
 cupsRasterReadHeader(
     cups_raster_t      *r,             /* I - Raster stream */
     cups_page_header_t *h)             /* I - Pointer to header data */
@@ -240,12 +253,12 @@ cupsRasterReadHeader(
 
 /*
  * 'cupsRasterReadHeader2()' - Read a raster page header and store it in a
- *                             V2 page header structure.
+ *                             version 2 page header structure.
  *
- * @since CUPS 1.2@
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
 
-unsigned                               /* O - 1 on success, 0 on fail */
+unsigned                               /* O - 1 on success, 0 on failure/end-of-file */
 cupsRasterReadHeader2(
     cups_raster_t       *r,            /* I - Raster stream */
     cups_page_header2_t *h)            /* I - Pointer to header data */
@@ -269,6 +282,10 @@ cupsRasterReadHeader2(
 
 /*
  * 'cupsRasterReadPixels()' - Read raster pixels.
+ *
+ * For best performance, filters should read one or more whole lines.
+ * The "cupsBytesPerLine" value from the page header can be used to allocate
+ * the line buffer and as the number of bytes to read.
  */
 
 unsigned                               /* O - Number of bytes read */
@@ -470,8 +487,12 @@ cupsRasterReadPixels(cups_raster_t *r,     /* I - Raster stream */
 
 
 /*
- * 'cupsRasterWriteHeader()' - Write a raster page header from a V1 page
+ * 'cupsRasterWriteHeader()' - Write a raster page header from a version 1 page
  *                             header structure.
+ *
+ * This function is deprecated. Use @link cupsRasterWriteHeader2@ instead.
+ *
+ * @deprecated@
  */
  
 unsigned                               /* O - 1 on success, 0 on failure */
@@ -502,10 +523,12 @@ cupsRasterWriteHeader(
 
 
 /*
- * 'cupsRasterWriteHeader2()' - Write a raster page header from a V2 page
- *                              header structure.
+ * 'cupsRasterWriteHeader2()' - Write a raster page header from a version 2
+ *                              page header structure.
  *
- * @since CUPS 1.2@
+ * The page header can be initialized using @link cupsRasterInterpretPPD@.
+ *
+ * @since CUPS 1.2/Mac OS X 10.5@
  */
  
 unsigned                               /* O - 1 on success, 0 on failure */
@@ -536,6 +559,10 @@ cupsRasterWriteHeader2(
 
 /*
  * 'cupsRasterWritePixels()' - Write raster pixels.
+ *
+ * For best performance, filters should write one or more whole lines.
+ * The "cupsBytesPerLine" value from the page header can be used to allocate
+ * the line buffer and as the number of bytes to write.
  */
 
 unsigned                               /* O - Number of bytes written */
@@ -547,10 +574,8 @@ cupsRasterWritePixels(cups_raster_t *r,    /* I - Raster stream */
   unsigned     remaining;              /* Bytes remaining */
 
 
-#ifdef DEBUG
-  fprintf(stderr, "cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u\n",
-          r, p, len, r->remaining);
-#endif /* DEBUG */
+  DEBUG_printf(("cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u\n",
+               r, p, len, r->remaining));
 
   if (r == NULL || r->mode != CUPS_RASTER_WRITE || r->remaining == 0)
     return (0);
@@ -673,12 +698,7 @@ static unsigned                            /* O - 1 on success, 0 on fail */
 cups_raster_read_header(
     cups_raster_t *r)                  /* I - Raster stream */
 {
-  int          len;                    /* Number of words to swap */
-  union swap_s                         /* Swapping structure */
-  {
-    unsigned char      b[4];
-    unsigned           v;
-  }            *s;
+  int  len;                            /* Length for read/swap */
 
 
   if (r == NULL || r->mode != CUPS_RASTER_READ)
@@ -707,10 +727,28 @@ cups_raster_read_header(
   */
 
   if (r->swapped)
-    for (len = 81, s = (union swap_s *)&(r->header.AdvanceDistance);
+  {
+    unsigned   *s,                     /* Current word */
+               temp;                   /* Temporary copy */
+
+
+    DEBUG_puts("Swapping header bytes...");
+
+    for (len = 81, s = &(r->header.AdvanceDistance);
         len > 0;
         len --, s ++)
-      s->v = (((((s->b[3] << 8) | s->b[2]) << 8) | s->b[1]) << 8) | s->b[0];
+    {
+      DEBUG_printf(("%08x =>", *s));
+
+      temp = *s;
+      *s   = ((temp & 0xff) << 24) |
+             ((temp & 0xff00) << 8) |
+             ((temp & 0xff0000) >> 8) |
+             ((temp & 0xff000000) >> 24);
+
+      DEBUG_printf((" %08x\n", *s));
+    }
+  }
 
  /*
   * Update the header and row count...
@@ -977,13 +1015,10 @@ cups_raster_write(
                        *plast;         /* Pointer to last pixel */
   unsigned char                *wptr;          /* Pointer into write buffer */
   int                  bpp,            /* Bytes per pixel */
-                       count,          /* Count */
-                       maxrun;         /* Maximum run of 128 * bpp */
+                       count;          /* Count */
 
 
-#ifdef DEBUG
-  fprintf(stderr, "cups_raster_write(r=%p, pixels=%p)\n", r, pixels);
-#endif /* DEBUG */
+  DEBUG_printf(("cups_raster_write(r=%p, pixels=%p)\n", r, pixels));
 
  /*
   * Allocate a write buffer as needed...
@@ -1013,7 +1048,6 @@ cups_raster_write(
   plast   = pend - bpp;
   wptr    = r->buffer;
   *wptr++ = r->count - 1;
-  maxrun  = 128 * bpp;
 
  /*
   * Write using a modified TIFF "packbits" compression...
@@ -1165,5 +1199,5 @@ cups_write(int                 fd,        /* I - File descriptor */
 
 
 /*
- * End of "$Id: raster.c 6274 2007-02-13 21:05:28Z mike $".
+ * End of "$Id: raster.c 7720 2008-07-11 22:46:21Z mike $".
  */