/*
- * "$Id: raster.c 7720 2008-07-11 22:46:21Z mike $"
+ * "$Id$"
*
- * Raster file routines for CUPS.
+ * Raster file routines for CUPS.
*
- * Copyright 2007-2011 by Apple Inc.
- * Copyright 1997-2006 by Easy Software Products.
+ * Copyright 2007-2014 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
*
- * This file is part of the CUPS Imaging library.
+ * This file is part of the CUPS Imaging library.
*
- * 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/".
+ * 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/".
*
- * This file is subject to the Apple OS-Developed Software exception.
- *
- * Contents:
- *
- * cupsRasterClose() - Close a raster stream.
- * cupsRasterOpen() - Open a raster stream using a file descriptor.
- * cupsRasterOpenIO() - Open a raster stream using a callback function.
- * cupsRasterReadHeader() - Read a raster page header and store it in a
- * version 1 page header structure.
- * cupsRasterReadHeader2() - Read a raster page header and store it in a
- * version 2 page header structure.
- * cupsRasterReadPixels() - Read raster pixels.
- * 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_header() - Read a raster page header.
- * cups_raster_read() - Read through the raster buffer.
- * cups_raster_update() - Update the raster header and row count for the
- * current page.
- * cups_raster_write() - Write a row of compressed raster data...
- * cups_read_fd() - Read bytes from a file.
- * cups_swap() - Swap bytes in raster data...
- * cups_write_fd() - Write bytes to a file.
+ * This file is subject to the Apple OS-Developed Software exception.
*/
/*
* Include necessary headers...
*/
-#include "image-private.h"
-#if defined(WIN32) || defined(__EMX__)
-# include <io.h>
-# include <winsock2.h> /* for htonl() definition */
-#else
-# include <unistd.h>
-#endif /* WIN32 || __EMX__ */
+#include <cups/raster-private.h>
+#ifdef HAVE_STDINT_H
+# include <stdint.h>
+#endif /* HAVE_STDINT_H */
/*
cups_raster_iocb_t iocb; /* IO callback */
cups_mode_t mode; /* Read/write mode */
cups_page_header2_t header; /* Raster header for current page */
- int count, /* Current row run-length count */
+ unsigned count, /* Current row run-length count */
remaining, /* Remaining rows in page image */
bpp; /* Bytes per pixel/color */
unsigned char *pixels, /* Pixels for current row */
* Local functions...
*/
-static int cups_raster_io(cups_raster_t *r, unsigned char *buf, int bytes);
+static ssize_t cups_raster_io(cups_raster_t *r, unsigned char *buf, size_t bytes);
static unsigned cups_raster_read_header(cups_raster_t *r);
-static int cups_raster_read(cups_raster_t *r, unsigned char *buf,
- int bytes);
+static ssize_t cups_raster_read(cups_raster_t *r, unsigned char *buf,
+ size_t bytes);
static void cups_raster_update(cups_raster_t *r);
-static int cups_raster_write(cups_raster_t *r,
+static ssize_t cups_raster_write(cups_raster_t *r,
const unsigned char *pixels);
static ssize_t cups_read_fd(void *ctx, unsigned char *buf, size_t bytes);
-static void cups_swap(unsigned char *buf, int bytes);
+static void cups_swap(unsigned char *buf, size_t bytes);
static ssize_t cups_write_fd(void *ctx, unsigned char *buf, size_t bytes);
break;
}
- if (cups_raster_io(r, (unsigned char *)&(r->sync), sizeof(r->sync))
- < sizeof(r->sync))
+ if (cups_raster_io(r, (unsigned char *)&(r->sync), sizeof(r->sync)) < (ssize_t)sizeof(r->sync))
{
_cupsRasterAddError("Unable to write raster stream header: %s\n",
strerror(errno));
* 'cupsRasterReadHeader2()' - Read a raster page header and store it in a
* version 2 page header structure.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
unsigned /* O - 1 on success, 0 on failure/end-of-file */
unsigned char *p, /* I - Pointer to pixel buffer */
unsigned len) /* I - Number of bytes to read */
{
- int bytes; /* Bytes read */
+ ssize_t bytes; /* Bytes read */
unsigned cupsBytesPerLine; /* cupsBytesPerLine value */
unsigned remaining; /* Bytes remaining */
unsigned char *ptr, /* Pointer to read buffer */
byte, /* Byte from file */
*temp; /* Pointer into buffer */
- int count; /* Repetition count */
+ unsigned count; /* Repetition count */
- if (r == NULL || r->mode != CUPS_RASTER_READ || r->remaining == 0)
+ if (r == NULL || r->mode != CUPS_RASTER_READ || r->remaining == 0 ||
+ r->header.cupsBytesPerLine == 0)
return (0);
if (!r->compressed)
ptr = r->pixels;
temp = ptr;
- bytes = cupsBytesPerLine;
+ bytes = (ssize_t)cupsBytesPerLine;
while (bytes > 0)
{
* Copy N literal pixels...
*/
- count = (257 - byte) * r->bpp;
+ count = (unsigned)(257 - byte) * r->bpp;
- if (count > bytes)
- count = bytes;
+ if (count > (unsigned)bytes)
+ count = (unsigned)bytes;
if (!cups_raster_read(r, temp, count))
return (0);
*/
count = (byte + 1) * r->bpp;
- if (count > bytes)
- count = bytes;
+ if (count > (unsigned)bytes)
+ count = (unsigned)bytes;
if (count < r->bpp)
break;
r->header.cupsBitsPerPixel == 12 ||
r->header.cupsBitsPerPixel == 16) &&
r->swapped)
- cups_swap(ptr, bytes);
+ cups_swap(ptr, (size_t)bytes);
/*
* Update pointers...
if (remaining >= cupsBytesPerLine)
{
- bytes = cupsBytesPerLine;
+ bytes = (ssize_t)cupsBytesPerLine;
r->pcurrent = r->pixels;
r->count --;
r->remaining --;
}
else
{
- bytes = remaining;
+ bytes = (ssize_t)remaining;
r->pcurrent = r->pixels + bytes;
}
*/
if (ptr != p)
- memcpy(p, ptr, bytes);
+ memcpy(p, ptr, (size_t)bytes);
}
else
{
* Copy fragment from buffer...
*/
- if ((unsigned)(bytes = r->pend - r->pcurrent) > remaining)
- bytes = remaining;
+ if ((unsigned)(bytes = (int)(r->pend - r->pcurrent)) > remaining)
+ bytes = (ssize_t)remaining;
- memcpy(p, r->pcurrent, bytes);
+ memcpy(p, r->pcurrent, (size_t)bytes);
r->pcurrent += bytes;
if (r->pcurrent >= r->pend)
}
}
- remaining -= bytes;
+ remaining -= (unsigned)bytes;
p += bytes;
}
if (r->mode == CUPS_RASTER_WRITE_PWG)
{
/*
- * PWG raster data is always network byte order with most of the page header
+ * PWG raster data is always network byte order with much of the page header
* zeroed.
*/
cups_page_header2_t fh; /* File page header */
memset(&fh, 0, sizeof(fh));
- fh.HWResolution[0] = htonl(r->header.HWResolution[0]);
- fh.HWResolution[1] = htonl(r->header.HWResolution[1]);
- fh.cupsWidth = htonl(r->header.cupsWidth);
- fh.cupsHeight = htonl(r->header.cupsHeight);
- fh.cupsBitsPerColor = htonl(r->header.cupsBitsPerColor);
- fh.cupsBitsPerPixel = htonl(r->header.cupsBitsPerPixel);
- fh.cupsBytesPerLine = htonl(r->header.cupsBytesPerLine);
- fh.cupsColorOrder = htonl(r->header.cupsColorOrder);
- fh.cupsColorSpace = htonl(r->header.cupsColorSpace);
+
+ strlcpy(fh.MediaClass, "PwgRaster", sizeof(fh.MediaClass));
+ /* PwgRaster */
+ strlcpy(fh.MediaColor, r->header.MediaColor, sizeof(fh.MediaColor));
+ strlcpy(fh.MediaType, r->header.MediaType, sizeof(fh.MediaType));
+ strlcpy(fh.OutputType, r->header.OutputType, sizeof(fh.OutputType));
+ /* PrintContentType */
+
+ fh.CutMedia = htonl(r->header.CutMedia);
+ fh.Duplex = htonl(r->header.Duplex);
+ fh.HWResolution[0] = htonl(r->header.HWResolution[0]);
+ fh.HWResolution[1] = htonl(r->header.HWResolution[1]);
+ fh.ImagingBoundingBox[0] = htonl(r->header.ImagingBoundingBox[0]);
+ fh.ImagingBoundingBox[1] = htonl(r->header.ImagingBoundingBox[1]);
+ fh.ImagingBoundingBox[2] = htonl(r->header.ImagingBoundingBox[2]);
+ fh.ImagingBoundingBox[3] = htonl(r->header.ImagingBoundingBox[3]);
+ fh.InsertSheet = htonl(r->header.InsertSheet);
+ fh.Jog = htonl(r->header.Jog);
+ fh.LeadingEdge = htonl(r->header.LeadingEdge);
+ fh.ManualFeed = htonl(r->header.ManualFeed);
+ fh.MediaPosition = htonl(r->header.MediaPosition);
+ fh.MediaWeight = htonl(r->header.MediaWeight);
+ fh.NumCopies = htonl(r->header.NumCopies);
+ fh.Orientation = htonl(r->header.Orientation);
+ fh.PageSize[0] = htonl(r->header.PageSize[0]);
+ fh.PageSize[1] = htonl(r->header.PageSize[1]);
+ fh.Tumble = htonl(r->header.Tumble);
+ fh.cupsWidth = htonl(r->header.cupsWidth);
+ fh.cupsHeight = htonl(r->header.cupsHeight);
+ fh.cupsBitsPerColor = htonl(r->header.cupsBitsPerColor);
+ fh.cupsBitsPerPixel = htonl(r->header.cupsBitsPerPixel);
+ fh.cupsBytesPerLine = htonl(r->header.cupsBytesPerLine);
+ fh.cupsColorOrder = htonl(r->header.cupsColorOrder);
+ fh.cupsColorSpace = htonl(r->header.cupsColorSpace);
+ fh.cupsNumColors = htonl(r->header.cupsNumColors);
+ fh.cupsInteger[0] = htonl(r->header.cupsInteger[0]);
+ /* TotalPageCount */
+ fh.cupsInteger[1] = htonl(r->header.cupsInteger[1]);
+ /* CrossFeedTransform */
+ fh.cupsInteger[2] = htonl(r->header.cupsInteger[2]);
+ /* FeedTransform */
+ fh.cupsInteger[3] = htonl(r->header.cupsInteger[3]);
+ /* ImageBoxLeft */
+ fh.cupsInteger[4] = htonl(r->header.cupsInteger[4]);
+ /* ImageBoxTop */
+ fh.cupsInteger[5] = htonl(r->header.cupsInteger[5]);
+ /* ImageBoxRight */
+ fh.cupsInteger[6] = htonl(r->header.cupsInteger[6]);
+ /* ImageBoxBottom */
+ fh.cupsInteger[7] = htonl(r->header.cupsInteger[7]);
+ /* BlackPrimary */
+ fh.cupsInteger[8] = htonl(r->header.cupsInteger[8]);
+ /* PrintQuality */
+ fh.cupsInteger[14] = htonl(r->header.cupsInteger[14]);
+ /* VendorIdentifier */
+ fh.cupsInteger[15] = htonl(r->header.cupsInteger[15]);
+ /* VendorLength */
+
+ memcpy(fh.cupsReal, r->header.cupsReal,
+ sizeof(fh.cupsReal) + sizeof(fh.cupsString));
+ /* VendorData */
+
+ strlcpy(fh.cupsRenderingIntent, r->header.cupsRenderingIntent,
+ sizeof(fh.cupsRenderingIntent));
+ strlcpy(fh.cupsPageSizeName, r->header.cupsPageSizeName,
+ sizeof(fh.cupsPageSizeName));
return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
}
*
* The page header can be initialized using @link cupsRasterInterpretPPD@.
*
- * @since CUPS 1.2/Mac OS X 10.5@
+ * @since CUPS 1.2/OS X 10.5@
*/
unsigned /* O - 1 on success, 0 on failure */
cups_page_header2_t fh; /* File page header */
memset(&fh, 0, sizeof(fh));
- fh.HWResolution[0] = htonl(r->header.HWResolution[0]);
- fh.HWResolution[1] = htonl(r->header.HWResolution[1]);
- fh.cupsWidth = htonl(r->header.cupsWidth);
- fh.cupsHeight = htonl(r->header.cupsHeight);
- fh.cupsBitsPerColor = htonl(r->header.cupsBitsPerColor);
- fh.cupsBitsPerPixel = htonl(r->header.cupsBitsPerPixel);
- fh.cupsBytesPerLine = htonl(r->header.cupsBytesPerLine);
- fh.cupsColorOrder = htonl(r->header.cupsColorOrder);
- fh.cupsColorSpace = htonl(r->header.cupsColorSpace);
- fh.cupsNumColors = htonl(r->header.cupsNumColors);
+ strlcpy(fh.MediaClass, "PwgRaster", sizeof(fh.MediaClass));
+ strlcpy(fh.MediaColor, r->header.MediaColor, sizeof(fh.MediaColor));
+ strlcpy(fh.MediaType, r->header.MediaType, sizeof(fh.MediaType));
+ strlcpy(fh.OutputType, r->header.OutputType, sizeof(fh.OutputType));
+ strlcpy(fh.cupsRenderingIntent, r->header.cupsRenderingIntent,
+ sizeof(fh.cupsRenderingIntent));
+ strlcpy(fh.cupsPageSizeName, r->header.cupsPageSizeName,
+ sizeof(fh.cupsPageSizeName));
+
+ fh.CutMedia = htonl(r->header.CutMedia);
+ fh.Duplex = htonl(r->header.Duplex);
+ fh.HWResolution[0] = htonl(r->header.HWResolution[0]);
+ fh.HWResolution[1] = htonl(r->header.HWResolution[1]);
+ fh.ImagingBoundingBox[0] = htonl(r->header.ImagingBoundingBox[0]);
+ fh.ImagingBoundingBox[1] = htonl(r->header.ImagingBoundingBox[1]);
+ fh.ImagingBoundingBox[2] = htonl(r->header.ImagingBoundingBox[2]);
+ fh.ImagingBoundingBox[3] = htonl(r->header.ImagingBoundingBox[3]);
+ fh.InsertSheet = htonl(r->header.InsertSheet);
+ fh.Jog = htonl(r->header.Jog);
+ fh.LeadingEdge = htonl(r->header.LeadingEdge);
+ fh.ManualFeed = htonl(r->header.ManualFeed);
+ fh.MediaPosition = htonl(r->header.MediaPosition);
+ fh.MediaWeight = htonl(r->header.MediaWeight);
+ fh.NumCopies = htonl(r->header.NumCopies);
+ fh.Orientation = htonl(r->header.Orientation);
+ fh.PageSize[0] = htonl(r->header.PageSize[0]);
+ fh.PageSize[1] = htonl(r->header.PageSize[1]);
+ fh.Tumble = htonl(r->header.Tumble);
+ fh.cupsWidth = htonl(r->header.cupsWidth);
+ fh.cupsHeight = htonl(r->header.cupsHeight);
+ fh.cupsBitsPerColor = htonl(r->header.cupsBitsPerColor);
+ fh.cupsBitsPerPixel = htonl(r->header.cupsBitsPerPixel);
+ fh.cupsBytesPerLine = htonl(r->header.cupsBytesPerLine);
+ fh.cupsColorOrder = htonl(r->header.cupsColorOrder);
+ fh.cupsColorSpace = htonl(r->header.cupsColorSpace);
+ fh.cupsNumColors = htonl(r->header.cupsNumColors);
+ fh.cupsInteger[0] = htonl(r->header.cupsInteger[0]);
+ fh.cupsInteger[1] = htonl(r->header.cupsInteger[1]);
+ fh.cupsInteger[2] = htonl(r->header.cupsInteger[2]);
+ fh.cupsInteger[3] = htonl((unsigned)(r->header.cupsImagingBBox[0] *
+ r->header.HWResolution[0]));
+ fh.cupsInteger[4] = htonl((unsigned)(r->header.cupsImagingBBox[1] *
+ r->header.HWResolution[1]));
+ fh.cupsInteger[5] = htonl((unsigned)(r->header.cupsImagingBBox[2] *
+ r->header.HWResolution[0]));
+ fh.cupsInteger[6] = htonl((unsigned)(r->header.cupsImagingBBox[3] *
+ r->header.HWResolution[1]));
+ fh.cupsInteger[7] = htonl(0xffffff);
return (cups_raster_io(r, (unsigned char *)&fh, sizeof(fh)) == sizeof(fh));
}
unsigned char *p, /* I - Bytes to write */
unsigned len)/* I - Number of bytes to write */
{
- int bytes; /* Bytes read */
+ ssize_t bytes; /* Bytes read */
unsigned remaining; /* Bytes remaining */
* Write the byte-swapped buffer...
*/
- return (cups_raster_io(r, r->buffer, len));
+ return ((unsigned)cups_raster_io(r, r->buffer, len));
}
else
- return (cups_raster_io(r, p, len));
+ return ((unsigned)cups_raster_io(r, p, len));
}
/*
* Otherwise, compress each line...
*/
- for (remaining = len; remaining > 0; remaining -= bytes, p += bytes)
+ for (remaining = len; remaining > 0; remaining -= (unsigned)bytes, p += bytes)
{
/*
* Figure out the number of remaining bytes on the current line...
*/
- if ((bytes = remaining) > (r->pend - r->pcurrent))
- bytes = r->pend - r->pcurrent;
+ if ((bytes = (ssize_t)remaining) > (ssize_t)(r->pend - r->pcurrent))
+ bytes = (ssize_t)(r->pend - r->pcurrent);
if (r->count > 0)
{
* Check to see if this line is the same as the previous line...
*/
- if (memcmp(p, r->pcurrent, bytes))
+ if (memcmp(p, r->pcurrent, (size_t)bytes))
{
if (!cups_raster_write(r, r->pixels))
return (0);
r->remaining --;
if (r->remaining == 0)
- return (cups_raster_write(r, r->pixels));
+ return ((unsigned)cups_raster_write(r, r->pixels));
else if (r->count == 256)
{
if (cups_raster_write(r, r->pixels) == 0)
* Copy the raster data to the buffer...
*/
- memcpy(r->pcurrent, p, bytes);
+ memcpy(r->pcurrent, p, (size_t)bytes);
r->pcurrent += bytes;
r->remaining --;
if (r->remaining == 0)
- return (cups_raster_write(r, r->pixels));
+ return ((unsigned)cups_raster_write(r, r->pixels));
}
}
}
cups_raster_read_header(
cups_raster_t *r) /* I - Raster stream */
{
- int len; /* Length for read/swap */
+ size_t len; /* Length for read/swap */
if (r == NULL || r->mode != CUPS_RASTER_READ)
memset(&(r->header), 0, sizeof(r->header));
- if (cups_raster_read(r, (unsigned char *)&(r->header), len) < len)
+ if (cups_raster_read(r, (unsigned char *)&(r->header), len) < (ssize_t)len)
return (0);
/*
cups_raster_update(r);
- return (1);
+ return (r->header.cupsBytesPerLine != 0 && r->header.cupsHeight != 0);
}
* 'cups_raster_io()' - Read/write bytes from a context, handling interruptions.
*/
-static int /* O - Bytes read or -1 */
-cups_raster_io(cups_raster_t *r, /* I - Raster stream */
- unsigned char *buf, /* I - Buffer for read/write */
- int bytes) /* I - Number of bytes to read/write */
+static ssize_t /* O - Bytes read/write or -1 */
+cups_raster_io(cups_raster_t *r, /* I - Raster stream */
+ unsigned char *buf, /* I - Buffer for read/write */
+ size_t bytes) /* I - Number of bytes to read/write */
{
- ssize_t count; /* Number of bytes read/written */
- size_t total; /* Total bytes read/written */
+ ssize_t count, /* Number of bytes read/written */
+ total; /* Total bytes read/written */
- DEBUG_printf(("4cups_raster_io(r=%p, buf=%p, bytes=%d)", r, buf, bytes));
+ DEBUG_printf(("4cups_raster_io(r=%p, buf=%p, bytes=" CUPS_LLFMT ")", r, buf, CUPS_LLCAST bytes));
- for (total = 0; total < bytes; total += count, buf += count)
+ for (total = 0; total < (ssize_t)bytes; total += count, buf += count)
{
- count = (*r->iocb)(r->ctx, buf, bytes - total);
+ count = (*r->iocb)(r->ctx, buf, bytes - (size_t)total);
DEBUG_printf(("5cups_raster_io: count=%d, total=%d", (int)count,
(int)total));
return (-1);
}
- return ((int)total);
+ return (total);
}
* 'cups_raster_read()' - Read through the raster buffer.
*/
-static int /* O - Number of bytes read */
+static ssize_t /* O - Number of bytes read */
cups_raster_read(cups_raster_t *r, /* I - Raster stream */
unsigned char *buf, /* I - Buffer */
- int bytes) /* I - Number of bytes to read */
+ size_t bytes) /* I - Number of bytes to read */
{
- int count, /* Number of bytes read */
+ ssize_t count, /* Number of bytes read */
remaining, /* Remaining bytes in buffer */
total; /* Total bytes read */
- DEBUG_printf(("cups_raster_read(r=%p, buf=%p, bytes=%d)\n", r, buf, bytes));
+ DEBUG_printf(("cups_raster_read(r=%p, buf=%p, bytes=" CUPS_LLFMT ")\n", r, buf, CUPS_LLCAST bytes));
if (!r->compressed)
return (cups_raster_io(r, buf, bytes));
* Allocate a read buffer as needed...
*/
- count = 2 * r->header.cupsBytesPerLine;
+ count = (ssize_t)(2 * r->header.cupsBytesPerLine);
if ((size_t)count > r->bufsize)
{
- int offset = r->bufptr - r->buffer; /* Offset to current start of buffer */
- int end = r->bufend - r->buffer; /* Offset to current end of buffer */
+ ssize_t offset = r->bufptr - r->buffer;
+ /* Offset to current start of buffer */
+ ssize_t end = r->bufend - r->buffer;/* Offset to current end of buffer */
unsigned char *rptr; /* Pointer in read buffer */
if (r->buffer)
- rptr = realloc(r->buffer, count);
+ rptr = realloc(r->buffer, (size_t)count);
else
- rptr = malloc(count);
+ rptr = malloc((size_t)count);
if (!rptr)
return (0);
r->buffer = rptr;
r->bufptr = rptr + offset;
r->bufend = rptr + end;
- r->bufsize = count;
+ r->bufsize = (size_t)count;
}
/*
* Loop until we have read everything...
*/
- for (total = 0, remaining = r->bufend - r->bufptr;
- total < bytes;
+ for (total = 0, remaining = (int)(r->bufend - r->bufptr);
+ total < (ssize_t)bytes;
total += count, buf += count)
{
- count = bytes - total;
+ count = (ssize_t)bytes - total;
- DEBUG_printf(("count=%d, remaining=%d, buf=%p, bufptr=%p, bufend=%p...\n",
- count, remaining, buf, r->bufptr, r->bufend));
+ DEBUG_printf(("count=" CUPS_LLFMT ", remaining=" CUPS_LLFMT ", buf=%p, bufptr=%p, bufend=%p...\n", CUPS_LLCAST count, CUPS_LLCAST remaining, buf, r->bufptr, r->bufend));
if (remaining == 0)
{
* Read directly into "buf"...
*/
- count = (*r->iocb)(r->ctx, buf, count);
+ count = (*r->iocb)(r->ctx, buf, (size_t)count);
if (count <= 0)
return (0);
* Use memcpy() for a large read...
*/
- memcpy(buf, r->bufptr, count);
+ memcpy(buf, r->bufptr, (size_t)count);
r->bufptr += count;
remaining -= count;
}
* 'cups_raster_write()' - Write a row of compressed raster data...
*/
-static int /* O - Number of bytes written */
+static ssize_t /* O - Number of bytes written */
cups_raster_write(
cups_raster_t *r, /* I - Raster stream */
const unsigned char *pixels) /* I - Pixel data to write */
*pend, /* End of raster buffer */
*plast; /* Pointer to last pixel */
unsigned char *wptr; /* Pointer into write buffer */
- int bpp, /* Bytes per pixel */
+ unsigned bpp, /* Bytes per pixel */
count; /* Count */
pend = pixels + r->header.cupsBytesPerLine;
plast = pend - bpp;
wptr = r->buffer;
- *wptr++ = r->count - 1;
+ *wptr++ = (unsigned char)(r->count - 1);
/*
* Write using a modified PackBits compression...
if (memcmp(ptr, ptr + bpp, bpp))
break;
- *wptr++ = count - 1;
+ *wptr++ = (unsigned char)(count - 1);
for (count = bpp; count > 0; count --)
*wptr++ = *ptr++;
}
ptr += bpp;
}
- *wptr++ = 257 - count;
+ *wptr++ = (unsigned char)(257 - count);
count *= bpp;
memcpy(wptr, start, count);
}
}
- return (cups_raster_io(r, r->buffer, wptr - r->buffer));
+ return (cups_raster_io(r, r->buffer, (size_t)(wptr - r->buffer)));
}
ssize_t count; /* Number of bytes read */
+#ifdef WIN32 /* Sigh */
+ while ((count = read(fd, buf, (unsigned)bytes)) < 0)
+#else
while ((count = read(fd, buf, bytes)) < 0)
+#endif /* WIN32 */
if (errno != EINTR && errno != EAGAIN)
return (-1);
static void
cups_swap(unsigned char *buf, /* I - Buffer to swap */
- int bytes) /* I - Number of bytes to swap */
+ size_t bytes) /* I - Number of bytes to swap */
{
unsigned char even, odd; /* Temporary variables */
ssize_t count; /* Number of bytes written */
+#ifdef WIN32 /* Sigh */
+ while ((count = write(fd, buf, (unsigned)bytes)) < 0)
+#else
while ((count = write(fd, buf, bytes)) < 0)
+#endif /* WIN32 */
if (errno != EINTR && errno != EAGAIN)
return (-1);
/*
- * End of "$Id: raster.c 7720 2008-07-11 22:46:21Z mike $".
+ * End of "$Id$".
*/