/*
- * "$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.
/*
* 'cupsRasterClose()' - Close a raster stream.
+ *
+ * The file descriptor associated with the raster stream must be closed
+ * separately as needed.
*/
void
/*
* '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 */
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
{
/*
* '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 */
/*
* '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 */
/*
* '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 */
/*
- * '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 */
/*
- * '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 */
/*
* '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 */
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);
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)
*/
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...
*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...
plast = pend - bpp;
wptr = r->buffer;
*wptr++ = r->count - 1;
- maxrun = 128 * bpp;
/*
* Write using a modified TIFF "packbits" compression...
/*
- * 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 $".
*/