aboutsummaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorPhilip P. Moltmann <moltmann@google.com>2017-05-11 09:37:47 -0700
committerPhilip P. Moltmann <moltmann@google.com>2017-05-11 09:39:41 -0700
commit2447373f182dbfeb47fb86c0f5a6ac5773c65ac2 (patch)
tree61c08d7f0c7e77cbfc67f07d6e5c2dbebd28ace5 /filter
parente78fa6dfe24e5677481967b8827478e9b8cbc5e8 (diff)
downloadlibcups-2447373f182dbfeb47fb86c0f5a6ac5773c65ac2.tar.gz
Bug: 38203442 Test: built Change-Id: I8f363c71c291363514100690ca7f8c463d98eb78
Diffstat (limited to 'filter')
-rw-r--r--filter/Makefile2
-rw-r--r--filter/api-raster.shtml6
-rw-r--r--filter/commandtops.c2
-rw-r--r--filter/common.c2
-rw-r--r--filter/common.h2
-rw-r--r--filter/error.c2
-rw-r--r--filter/gziptoany.c2
-rw-r--r--filter/interpret.c2
-rw-r--r--filter/pstops.c2
-rw-r--r--filter/raster.c327
-rw-r--r--filter/rasterbench.c2
-rw-r--r--filter/rastertoepson.c2
-rw-r--r--filter/rastertohp.c2
-rw-r--r--filter/rastertolabel.c21
-rw-r--r--filter/rastertopwg.c16
-rw-r--r--filter/testraster.c38
16 files changed, 354 insertions, 76 deletions
diff --git a/filter/Makefile b/filter/Makefile
index 152bc90c..7da764d3 100644
--- a/filter/Makefile
+++ b/filter/Makefile
@@ -8,7 +8,7 @@
# 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/".
+# missing or damaged, see the license at "http://www.cups.org/".
#
# This file is subject to the Apple OS-Developed Software exception.
#
diff --git a/filter/api-raster.shtml b/filter/api-raster.shtml
index 35996f6f..6d458a2e 100644
--- a/filter/api-raster.shtml
+++ b/filter/api-raster.shtml
@@ -34,7 +34,7 @@ function. For example, to read raster data from the standard input, open
file descriptor 0:</p>
<pre class="example">
-#include &lt;cups/raster.h&gt;>
+#include &lt;cups/raster.h&gt;
<a href="#cups_raster_t">cups_raster_t</a> *ras = <a href="#cupsRasterOpen">cupsRasterOpen</a>(0, CUPS_RASTER_READ);
</pre>
@@ -61,7 +61,7 @@ hardware resolution, and so forth used for the page.</p>
function:</p>
<pre class="example">
-#include &lt;cups/raster.h&gt;>
+#include &lt;cups/raster.h&gt;
<a href="#cups_raster_t">cups_raster_t</a> *ras = <a href="#cupsRasterOpen">cupsRasterOpen</a>(0, CUPS_RASTER_READ);
<a href="#cups_page_header2_t">cups_page_header2_t</a> header;
@@ -84,7 +84,7 @@ function. A <code>for</code> loop is normally used to read the page one line
at a time:</p>
<pre class="example">
-#include &lt;cups/raster.h&gt;>
+#include &lt;cups/raster.h&gt;
<a href="#cups_raster_t">cups_raster_t</a> *ras = <a href="#cupsRasterOpen">cupsRasterOpen</a>(0, CUPS_RASTER_READ);
<a href="#cups_page_header2_t">cups_page_header2_t</a> header;
diff --git a/filter/commandtops.c b/filter/commandtops.c
index 65dcd357..07979e03 100644
--- a/filter/commandtops.c
+++ b/filter/commandtops.c
@@ -7,7 +7,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*/
/*
diff --git a/filter/common.c b/filter/common.c
index bed4a53a..86b5f8ec 100644
--- a/filter/common.c
+++ b/filter/common.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/common.h b/filter/common.h
index 0dcb289f..e72b27fb 100644
--- a/filter/common.h
+++ b/filter/common.h
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/error.c b/filter/error.c
index dfbb5c90..3c552cb0 100644
--- a/filter/error.c
+++ b/filter/error.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/gziptoany.c b/filter/gziptoany.c
index b3f5dffc..0eae85ec 100644
--- a/filter/gziptoany.c
+++ b/filter/gziptoany.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/interpret.c b/filter/interpret.c
index f811d1a0..031b1d5a 100644
--- a/filter/interpret.c
+++ b/filter/interpret.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/pstops.c b/filter/pstops.c
index e9b44389..072356e2 100644
--- a/filter/pstops.c
+++ b/filter/pstops.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/raster.c b/filter/raster.c
index dee8eeca..bacf5ba7 100644
--- a/filter/raster.c
+++ b/filter/raster.c
@@ -10,7 +10,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
@@ -36,7 +36,8 @@ struct _cups_raster_s /**** Raster stream data ****/
cups_raster_iocb_t iocb; /* IO callback */
cups_mode_t mode; /* Read/write mode */
cups_page_header2_t header; /* Raster header for current page */
- unsigned count, /* Current row run-length count */
+ unsigned rowheight, /* Row height in lines */
+ count, /* Current row run-length count */
remaining, /* Remaining rows in page image */
bpp; /* Bytes per pixel/color */
unsigned char *pixels, /* Pixels for current row */
@@ -51,6 +52,7 @@ struct _cups_raster_s /**** Raster stream data ****/
#ifdef DEBUG
size_t iocount; /* Number of bytes read/written */
#endif /* DEBUG */
+ unsigned apple_page_count;/* Apple raster page count */
};
@@ -418,7 +420,9 @@ cupsRasterOpenIO(
r->sync != CUPS_RASTER_SYNCv1 &&
r->sync != CUPS_RASTER_REVSYNCv1 &&
r->sync != CUPS_RASTER_SYNCv2 &&
- r->sync != CUPS_RASTER_REVSYNCv2)
+ r->sync != CUPS_RASTER_REVSYNCv2 &&
+ r->sync != CUPS_RASTER_SYNCapple &&
+ r->sync != CUPS_RASTER_REVSYNCapple)
{
_cupsRasterAddError("Unknown raster format %08x!\n", r->sync);
free(r);
@@ -426,14 +430,33 @@ cupsRasterOpenIO(
}
if (r->sync == CUPS_RASTER_SYNCv2 ||
- r->sync == CUPS_RASTER_REVSYNCv2)
+ r->sync == CUPS_RASTER_REVSYNCv2 ||
+ r->sync == CUPS_RASTER_SYNCapple ||
+ r->sync == CUPS_RASTER_REVSYNCapple)
r->compressed = 1;
if (r->sync == CUPS_RASTER_REVSYNC ||
r->sync == CUPS_RASTER_REVSYNCv1 ||
- r->sync == CUPS_RASTER_REVSYNCv2)
+ r->sync == CUPS_RASTER_REVSYNCv2 ||
+ r->sync == CUPS_RASTER_REVSYNCapple)
r->swapped = 1;
+ if (r->sync == CUPS_RASTER_SYNCapple ||
+ r->sync == CUPS_RASTER_REVSYNCapple)
+ {
+ unsigned char header[8]; /* File header */
+
+ if (cups_raster_io(r, (unsigned char *)header, sizeof(header)) !=
+ sizeof(header))
+ {
+ _cupsRasterAddError("Unable to read header from raster stream: %s\n",
+ strerror(errno));
+ free(r);
+ return (NULL);
+ }
+
+ }
+
DEBUG_printf(("1cupsRasterOpenIO: r->swapped=%d, r->sync=%08x\n", r->swapped, r->sync));
}
else
@@ -459,6 +482,13 @@ cupsRasterOpenIO(
r->sync = htonl(CUPS_RASTER_SYNC_PWG);
r->swapped = r->sync != CUPS_RASTER_SYNC_PWG;
break;
+
+ case CUPS_RASTER_WRITE_APPLE :
+ r->compressed = 1;
+ r->sync = htonl(CUPS_RASTER_SYNCapple);
+ r->swapped = r->sync != CUPS_RASTER_SYNCapple;
+ r->apple_page_count = 0xffffffffU;
+ break;
}
if (cups_raster_io(r, (unsigned char *)&(r->sync), sizeof(r->sync)) < (ssize_t)sizeof(r->sync))
@@ -662,7 +692,31 @@ cupsRasterReadPixels(cups_raster_t *r, /* I - Raster stream */
return (0);
}
- if (byte & 128)
+ if (byte == 128)
+ {
+ /*
+ * Clear to end of line...
+ */
+
+ switch (r->header.cupsColorSpace)
+ {
+ case CUPS_CSPACE_W :
+ case CUPS_CSPACE_RGB :
+ case CUPS_CSPACE_SW :
+ case CUPS_CSPACE_SRGB :
+ case CUPS_CSPACE_RGBW :
+ case CUPS_CSPACE_ADOBERGB :
+ memset(temp, 0xff, (size_t)bytes);
+ break;
+ default :
+ memset(temp, 0x00, (size_t)bytes);
+ break;
+ }
+
+ temp += bytes;
+ bytes = 0;
+ }
+ else if (byte & 128)
{
/*
* Copy N literal pixels...
@@ -891,6 +945,60 @@ cupsRasterWriteHeader(
return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
}
+ else if (r->mode == CUPS_RASTER_WRITE_APPLE)
+ {
+ /*
+ * Raw raster data is always network byte order with most of the page header
+ * zeroed.
+ */
+
+ unsigned char appleheader[32]; /* Raw page header */
+
+ if (r->apple_page_count == 0xffffffffU)
+ {
+ /*
+ * Write raw page count from raster page header...
+ */
+
+ r->apple_page_count = r->header.cupsInteger[0];
+
+ appleheader[0] = 'A';
+ appleheader[1] = 'S';
+ appleheader[2] = 'T';
+ appleheader[3] = 0;
+ appleheader[4] = (unsigned char)(r->apple_page_count >> 24);
+ appleheader[5] = (unsigned char)(r->apple_page_count >> 16);
+ appleheader[6] = (unsigned char)(r->apple_page_count >> 8);
+ appleheader[7] = (unsigned char)(r->apple_page_count);
+
+ if (cups_raster_io(r, appleheader, 8) != 8)
+ return (0);
+ }
+
+ memset(appleheader, 0, sizeof(appleheader));
+
+ appleheader[0] = (unsigned char)r->header.cupsBitsPerPixel;
+ appleheader[1] = r->header.cupsColorSpace == CUPS_CSPACE_SRGB ? 1 :
+ r->header.cupsColorSpace == CUPS_CSPACE_RGBW ? 2 :
+ r->header.cupsColorSpace == CUPS_CSPACE_ADOBERGB ? 3 :
+ r->header.cupsColorSpace == CUPS_CSPACE_W ? 4 :
+ r->header.cupsColorSpace == CUPS_CSPACE_RGB ? 5 :
+ r->header.cupsColorSpace == CUPS_CSPACE_CMYK ? 6 : 0;
+ appleheader[12] = (unsigned char)(r->header.cupsWidth >> 24);
+ appleheader[13] = (unsigned char)(r->header.cupsWidth >> 16);
+ appleheader[14] = (unsigned char)(r->header.cupsWidth >> 8);
+ appleheader[15] = (unsigned char)(r->header.cupsWidth);
+ appleheader[16] = (unsigned char)(r->header.cupsHeight >> 24);
+ appleheader[17] = (unsigned char)(r->header.cupsHeight >> 16);
+ appleheader[18] = (unsigned char)(r->header.cupsHeight >> 8);
+ appleheader[19] = (unsigned char)(r->header.cupsHeight);
+ appleheader[20] = (unsigned char)(r->header.HWResolution[0] >> 24);
+ appleheader[21] = (unsigned char)(r->header.HWResolution[0] >> 16);
+ appleheader[22] = (unsigned char)(r->header.HWResolution[0] >> 8);
+ appleheader[23] = (unsigned char)(r->header.HWResolution[0]);
+
+ return (cups_raster_io(r, appleheader, sizeof(appleheader)) == sizeof(appleheader));
+ }
else
return (cups_raster_io(r, (unsigned char *)&(r->header), sizeof(r->header))
== sizeof(r->header));
@@ -901,7 +1009,7 @@ cupsRasterWriteHeader(
* 'cupsRasterWriteHeader2()' - Write a raster page header from a version 2
* page header structure.
*
- * The page header can be initialized using @link cupsRasterInterpretPPD@.
+ * The page header can be initialized using @link cupsRasterInitPWGHeader@.
*
* @since CUPS 1.2/macOS 10.5@
*/
@@ -924,6 +1032,16 @@ cupsRasterWriteHeader2(
if (!cups_raster_update(r))
return (0);
+ if (r->mode == CUPS_RASTER_WRITE_APPLE)
+ {
+ r->rowheight = h->HWResolution[0] / h->HWResolution[1];
+
+ if (h->HWResolution[0] != (r->rowheight * h->HWResolution[1]))
+ return (0);
+ }
+ else
+ r->rowheight = 1;
+
/*
* Write the raster header...
*/
@@ -985,6 +1103,62 @@ cupsRasterWriteHeader2(
return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
}
+ else if (r->mode == CUPS_RASTER_WRITE_APPLE)
+ {
+ /*
+ * Raw raster data is always network byte order with most of the page header
+ * zeroed.
+ */
+
+ unsigned char appleheader[32]; /* Raw page header */
+ unsigned height = r->header.cupsHeight * r->rowheight;
+ /* Computed page height */
+
+ if (r->apple_page_count == 0xffffffffU)
+ {
+ /*
+ * Write raw page count from raster page header...
+ */
+
+ r->apple_page_count = r->header.cupsInteger[0];
+
+ appleheader[0] = 'A';
+ appleheader[1] = 'S';
+ appleheader[2] = 'T';
+ appleheader[3] = 0;
+ appleheader[4] = (unsigned char)(r->apple_page_count >> 24);
+ appleheader[5] = (unsigned char)(r->apple_page_count >> 16);
+ appleheader[6] = (unsigned char)(r->apple_page_count >> 8);
+ appleheader[7] = (unsigned char)(r->apple_page_count);
+
+ if (cups_raster_io(r, appleheader, 8) != 8)
+ return (0);
+ }
+
+ memset(appleheader, 0, sizeof(appleheader));
+
+ appleheader[0] = (unsigned char)r->header.cupsBitsPerPixel;
+ appleheader[1] = r->header.cupsColorSpace == CUPS_CSPACE_SRGB ? 1 :
+ r->header.cupsColorSpace == CUPS_CSPACE_RGBW ? 2 :
+ r->header.cupsColorSpace == CUPS_CSPACE_ADOBERGB ? 3 :
+ r->header.cupsColorSpace == CUPS_CSPACE_W ? 4 :
+ r->header.cupsColorSpace == CUPS_CSPACE_RGB ? 5 :
+ r->header.cupsColorSpace == CUPS_CSPACE_CMYK ? 6 : 0;
+ appleheader[12] = (unsigned char)(r->header.cupsWidth >> 24);
+ appleheader[13] = (unsigned char)(r->header.cupsWidth >> 16);
+ appleheader[14] = (unsigned char)(r->header.cupsWidth >> 8);
+ appleheader[15] = (unsigned char)(r->header.cupsWidth);
+ appleheader[16] = (unsigned char)(height >> 24);
+ appleheader[17] = (unsigned char)(height >> 16);
+ appleheader[18] = (unsigned char)(height >> 8);
+ appleheader[19] = (unsigned char)(height);
+ appleheader[20] = (unsigned char)(r->header.HWResolution[0] >> 24);
+ appleheader[21] = (unsigned char)(r->header.HWResolution[0] >> 16);
+ appleheader[22] = (unsigned char)(r->header.HWResolution[0] >> 8);
+ appleheader[23] = (unsigned char)(r->header.HWResolution[0]);
+
+ return (cups_raster_io(r, appleheader, sizeof(appleheader)) == sizeof(appleheader));
+ }
else
return (cups_raster_io(r, (unsigned char *)&(r->header), sizeof(r->header))
== sizeof(r->header));
@@ -1116,7 +1290,7 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */
* Increase the repeat count...
*/
- r->count ++;
+ r->count += r->rowheight;
r->pcurrent = r->pixels;
/*
@@ -1132,7 +1306,7 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */
else
return (len);
}
- else if (r->count == 256)
+ else if (r->count > (256 - r->rowheight))
{
if (cups_raster_write(r, r->pixels) <= 0)
return (0);
@@ -1161,7 +1335,7 @@ cupsRasterWritePixels(cups_raster_t *r, /* I - Raster stream */
* Increase the repeat count...
*/
- r->count ++;
+ r->count += r->rowheight;
r->pcurrent = r->pixels;
/*
@@ -1201,53 +1375,118 @@ cups_raster_read_header(
DEBUG_printf(("4cups_raster_read_header: r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
+ memset(&(r->header), 0, sizeof(r->header));
+
/*
- * Get the length of the raster header...
+ * Read the header...
*/
- if (r->sync == CUPS_RASTER_SYNCv1 || r->sync == CUPS_RASTER_REVSYNCv1)
- len = sizeof(cups_page_header_t);
- else
- len = sizeof(cups_page_header2_t);
+ switch (r->sync)
+ {
+ default :
+ /*
+ * Get the length of the raster header...
+ */
- DEBUG_printf(("4cups_raster_read_header: len=%d", (int)len));
+ if (r->sync == CUPS_RASTER_SYNCv1 || r->sync == CUPS_RASTER_REVSYNCv1)
+ len = sizeof(cups_page_header_t);
+ else
+ len = sizeof(cups_page_header2_t);
- /*
- * Read the header...
- */
+ DEBUG_printf(("4cups_raster_read_header: len=%d", (int)len));
- memset(&(r->header), 0, sizeof(r->header));
+ /*
+ * Read it...
+ */
- if (cups_raster_read(r, (unsigned char *)&(r->header), len) < (ssize_t)len)
- {
- DEBUG_printf(("4cups_raster_read_header: EOF, r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
- return (0);
- }
+ if (cups_raster_read(r, (unsigned char *)&(r->header), len) < (ssize_t)len)
+ {
+ DEBUG_printf(("4cups_raster_read_header: EOF, r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
+ return (0);
+ }
- /*
- * Swap bytes as needed...
- */
+ /*
+ * Swap bytes as needed...
+ */
- if (r->swapped)
- {
- unsigned *s, /* Current word */
- temp; /* Temporary copy */
+ if (r->swapped)
+ {
+ unsigned *s, /* Current word */
+ temp; /* Temporary copy */
- DEBUG_puts("4cups_raster_read_header: Swapping header bytes.");
+ DEBUG_puts("4cups_raster_read_header: Swapping header bytes.");
- for (len = 81, s = &(r->header.AdvanceDistance);
- len > 0;
- len --, s ++)
- {
- temp = *s;
- *s = ((temp & 0xff) << 24) |
- ((temp & 0xff00) << 8) |
- ((temp & 0xff0000) >> 8) |
- ((temp & 0xff000000) >> 24);
+ for (len = 81, s = &(r->header.AdvanceDistance);
+ len > 0;
+ len --, s ++)
+ {
+ temp = *s;
+ *s = ((temp & 0xff) << 24) |
+ ((temp & 0xff00) << 8) |
+ ((temp & 0xff0000) >> 8) |
+ ((temp & 0xff000000) >> 24);
- DEBUG_printf(("4cups_raster_read_header: %08x => %08x", temp, *s));
- }
+ DEBUG_printf(("4cups_raster_read_header: %08x => %08x", temp, *s));
+ }
+ }
+ break;
+
+ case CUPS_RASTER_SYNCapple :
+ case CUPS_RASTER_REVSYNCapple :
+ {
+ unsigned char appleheader[32]; /* Raw header */
+ static const unsigned rawcspace[] =
+ {
+ CUPS_CSPACE_SW,
+ CUPS_CSPACE_SRGB,
+ CUPS_CSPACE_RGBW,
+ CUPS_CSPACE_ADOBERGB,
+ CUPS_CSPACE_W,
+ CUPS_CSPACE_RGB,
+ CUPS_CSPACE_CMYK
+ };
+ static const unsigned rawnumcolors[] =
+ {
+ 1,
+ 3,
+ 4,
+ 3,
+ 1,
+ 3,
+ 4
+ };
+
+ if (cups_raster_read(r, appleheader, sizeof(appleheader)) < (ssize_t)sizeof(appleheader))
+ {
+ DEBUG_printf(("4cups_raster_read_header: EOF, r->iocount=" CUPS_LLFMT, CUPS_LLCAST r->iocount));
+ return (0);
+ }
+
+ strlcpy(r->header.MediaClass, "PwgRaster", sizeof(r->header.MediaClass));
+ /* PwgRaster */
+ r->header.cupsBitsPerPixel = appleheader[0];
+ r->header.cupsColorSpace = appleheader[1] >= (sizeof(rawcspace) / sizeof(rawcspace[0])) ? CUPS_CSPACE_DEVICE1 : rawcspace[appleheader[1]];
+ r->header.cupsNumColors = appleheader[1] >= (sizeof(rawnumcolors) / sizeof(rawnumcolors[0])) ? 1 : rawnumcolors[appleheader[1]];
+ r->header.cupsBitsPerColor = r->header.cupsBitsPerPixel / r->header.cupsNumColors;
+ r->header.cupsWidth = ((((((unsigned)appleheader[12] << 8) | (unsigned)appleheader[13]) << 8) | (unsigned)appleheader[14]) << 8) | (unsigned)appleheader[15];
+ r->header.cupsHeight = ((((((unsigned)appleheader[16] << 8) | (unsigned)appleheader[17]) << 8) | (unsigned)appleheader[18]) << 8) | (unsigned)appleheader[19];
+ r->header.cupsBytesPerLine = r->header.cupsWidth * r->header.cupsBitsPerPixel / 8;
+ r->header.cupsColorOrder = CUPS_ORDER_CHUNKED;
+ r->header.HWResolution[0] = r->header.HWResolution[1] = ((((((unsigned)appleheader[20] << 8) | (unsigned)appleheader[21]) << 8) | (unsigned)appleheader[22]) << 8) | (unsigned)appleheader[23];
+
+ if (r->header.HWResolution[0] > 0)
+ {
+ r->header.PageSize[0] = (unsigned)(r->header.cupsWidth * 72 / r->header.HWResolution[0]);
+ r->header.PageSize[1] = (unsigned)(r->header.cupsHeight * 72 / r->header.HWResolution[1]);
+ r->header.cupsPageSize[0] = (float)(r->header.cupsWidth * 72.0 / r->header.HWResolution[0]);
+ r->header.cupsPageSize[1] = (float)(r->header.cupsHeight * 72.0 / r->header.HWResolution[1]);
+ }
+
+ r->header.cupsInteger[0] = r->apple_page_count;
+ r->header.cupsInteger[7] = 0xffffff;
+ }
+ break;
}
/*
diff --git a/filter/rasterbench.c b/filter/rasterbench.c
index 010fd9dd..8746f31e 100644
--- a/filter/rasterbench.c
+++ b/filter/rasterbench.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/rastertoepson.c b/filter/rastertoepson.c
index 74dc61c5..4efe6692 100644
--- a/filter/rastertoepson.c
+++ b/filter/rastertoepson.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/rastertohp.c b/filter/rastertohp.c
index 2994b803..eb11c8c1 100644
--- a/filter/rastertohp.c
+++ b/filter/rastertohp.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
diff --git a/filter/rastertolabel.c b/filter/rastertolabel.c
index a082831a..4e491811 100644
--- a/filter/rastertolabel.c
+++ b/filter/rastertolabel.c
@@ -1,14 +1,14 @@
/*
* Label printer filter for CUPS.
*
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
* Copyright 2001-2007 by Easy Software Products.
*
* These coded instructions, statements, and computer programs are the
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
@@ -438,7 +438,7 @@ StartPage(ppd_file_t *ppd, /* I - PPD file */
*/
void
-EndPage(ppd_file_t *ppd, /* I - PPD file */
+EndPage(ppd_file_t *ppd, /* I - PPD file */
cups_page_header2_t *header) /* I - Page header */
{
int val; /* Option value */
@@ -496,6 +496,19 @@ EndPage(ppd_file_t *ppd, /* I - PPD file */
puts("^XA");
/*
+ * Rotate 180 degrees so that the top of the label/page is at the
+ * leading edge...
+ */
+
+ puts("^POI");
+
+ /*
+ * Set print width...
+ */
+
+ printf("^PW%u\n", header->cupsWidth);
+
+ /*
* Set print rate...
*/
@@ -605,8 +618,8 @@ EndPage(ppd_file_t *ppd, /* I - PPD file */
* End the label and eject...
*/
- puts("^IDR:CUPS.GRF^FS");
puts("^XZ");
+ puts("^IDR:CUPS.GRF^FS");
/*
* Cut the label as needed...
diff --git a/filter/rastertopwg.c b/filter/rastertopwg.c
index f478ac58..5413df04 100644
--- a/filter/rastertopwg.c
+++ b/filter/rastertopwg.c
@@ -1,13 +1,13 @@
/*
* CUPS raster to PWG raster format filter for CUPS.
*
- * Copyright 2011, 2014-2016 Apple Inc.
+ * Copyright 2011, 2014-2017 Apple Inc.
*
* These coded instructions, statements, and computer programs are the
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
@@ -31,6 +31,8 @@ int /* O - Exit status */
main(int argc, /* I - Number of command-line args */
char *argv[]) /* I - Command-line arguments */
{
+ const char *final_content_type;
+ /* FINAL_CONTENT_TYPE env var */
int fd; /* Raster file */
cups_raster_t *inras, /* Input raster stream */
*outras; /* Output raster stream */
@@ -48,7 +50,7 @@ main(int argc, /* I - Number of command-line args */
lineoffset; /* Offset into line */
unsigned char white; /* White pixel */
ppd_file_t *ppd; /* PPD file */
- ppd_attr_t *back; /* cupsBackSize attribute */
+ ppd_attr_t *back; /* cupsBackSide attribute */
_ppd_cache_t *cache; /* PPD cache */
pwg_size_t *pwg_size; /* PWG media size */
pwg_media_t *pwg_media; /* PWG media name */
@@ -73,8 +75,11 @@ main(int argc, /* I - Number of command-line args */
else
fd = 0;
+ if ((final_content_type = getenv("FINAL_CONTENT_TYPE")) == NULL)
+ final_content_type = "image/pwg-raster";
+
inras = cupsRasterOpen(fd, CUPS_RASTER_READ);
- outras = cupsRasterOpen(1, CUPS_RASTER_WRITE_PWG);
+ outras = cupsRasterOpen(1, !strcmp(final_content_type, "image/pwg-raster") ? CUPS_RASTER_WRITE_PWG : CUPS_RASTER_WRITE_APPLE);
ppd = ppdOpenFile(getenv("PPD"));
back = ppdFindAttr(ppd, "cupsBackSide", NULL);
@@ -430,6 +435,9 @@ main(int argc, /* I - Number of command-line args */
if (linesize < inheader.cupsBytesPerLine)
linesize = inheader.cupsBytesPerLine;
+ if ((lineoffset + inheader.cupsBytesPerLine) > linesize)
+ lineoffset = linesize - inheader.cupsBytesPerLine;
+
line = malloc(linesize);
memset(line, white, linesize);
diff --git a/filter/testraster.c b/filter/testraster.c
index 9c3f7650..d5d63de2 100644
--- a/filter/testraster.c
+++ b/filter/testraster.c
@@ -8,7 +8,7 @@
* 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/".
+ * missing or damaged, see the license at "http://www.cups.org/".
*
* This file is subject to the Apple OS-Developed Software exception.
*/
@@ -208,6 +208,7 @@ main(int argc, /* I - Number of command-line args */
errors += do_raster_tests(CUPS_RASTER_WRITE);
errors += do_raster_tests(CUPS_RASTER_WRITE_COMPRESSED);
errors += do_raster_tests(CUPS_RASTER_WRITE_PWG);
+ errors += do_raster_tests(CUPS_RASTER_WRITE_APPLE);
}
else
{
@@ -526,8 +527,9 @@ do_raster_tests(cups_mode_t mode) /* O - Write mode */
printf("cupsRasterOpen(%s): ",
mode == CUPS_RASTER_WRITE ? "CUPS_RASTER_WRITE" :
- mode == CUPS_RASTER_WRITE ? "CUPS_RASTER_WRITE_COMPRESSED" :
- "CUPS_RASTER_WRITE_PWG");
+ mode == CUPS_RASTER_WRITE_COMPRESSED ? "CUPS_RASTER_WRITE_COMPRESSED" :
+ mode == CUPS_RASTER_WRITE_PWG ? "CUPS_RASTER_WRITE_PWG" :
+ "CUPS_RASTER_WRITE_APPLE");
fflush(stdout);
if ((fp = fopen("test.raster", "wb")) == NULL)
@@ -551,18 +553,24 @@ do_raster_tests(cups_mode_t mode) /* O - Write mode */
header.cupsWidth = 256;
header.cupsHeight = 256;
header.cupsBytesPerLine = 256;
+ header.HWResolution[0] = 64;
+ header.HWResolution[1] = 64;
+ header.PageSize[0] = 288;
+ header.PageSize[1] = 288;
+ header.cupsPageSize[0] = 288.0f;
+ header.cupsPageSize[1] = 288.0f;
if (page & 1)
{
- header.cupsBytesPerLine *= 2;
+ header.cupsBytesPerLine *= 4;
header.cupsColorSpace = CUPS_CSPACE_CMYK;
header.cupsColorOrder = CUPS_ORDER_CHUNKED;
header.cupsNumColors = 4;
}
else
{
- header.cupsColorSpace = CUPS_CSPACE_K;
- header.cupsColorOrder = CUPS_ORDER_BANDED;
+ header.cupsColorSpace = CUPS_CSPACE_W;
+ header.cupsColorOrder = CUPS_ORDER_CHUNKED;
header.cupsNumColors = 1;
}
@@ -677,8 +685,18 @@ do_raster_tests(cups_mode_t mode) /* O - Write mode */
expected.cupsWidth = 256;
expected.cupsHeight = 256;
expected.cupsBytesPerLine = 256;
+ expected.HWResolution[0] = 64;
+ expected.HWResolution[1] = 64;
+ expected.PageSize[0] = 288;
+ expected.PageSize[1] = 288;
- if (mode == CUPS_RASTER_WRITE_PWG)
+ if (mode != CUPS_RASTER_WRITE_PWG)
+ {
+ expected.cupsPageSize[0] = 288.0f;
+ expected.cupsPageSize[1] = 288.0f;
+ }
+
+ if (mode >= CUPS_RASTER_WRITE_PWG)
{
strlcpy(expected.MediaClass, "PwgRaster", sizeof(expected.MediaClass));
expected.cupsInteger[7] = 0xffffff;
@@ -686,15 +704,15 @@ do_raster_tests(cups_mode_t mode) /* O - Write mode */
if (page & 1)
{
- expected.cupsBytesPerLine *= 2;
+ expected.cupsBytesPerLine *= 4;
expected.cupsColorSpace = CUPS_CSPACE_CMYK;
expected.cupsColorOrder = CUPS_ORDER_CHUNKED;
expected.cupsNumColors = 4;
}
else
{
- expected.cupsColorSpace = CUPS_CSPACE_K;
- expected.cupsColorOrder = CUPS_ORDER_BANDED;
+ expected.cupsColorSpace = CUPS_CSPACE_W;
+ expected.cupsColorOrder = CUPS_ORDER_CHUNKED;
expected.cupsNumColors = 1;
}