2 * "$Id: raster.c 7720 2008-07-11 22:46:21Z mike $"
4 * Raster file routines for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * This file is part of the CUPS Imaging library.
11 * These coded instructions, statements, and computer programs are the
12 * property of Apple Inc. and are protected by Federal copyright
13 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
14 * which should have been included with this file. If this file is
15 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * This file is subject to the Apple OS-Developed Software exception.
21 * cupsRasterClose() - Close a raster stream.
22 * cupsRasterOpen() - Open a raster stream.
23 * cupsRasterReadHeader() - Read a raster page header and store it in a
24 * version 1 page header structure.
25 * cupsRasterReadHeader2() - Read a raster page header and store it in a
26 * version 2 page header structure.
27 * cupsRasterReadPixels() - Read raster pixels.
28 * cupsRasterWriteHeader() - Write a raster page header from a version 1
29 * page header structure.
30 * cupsRasterWriteHeader2() - Write a raster page header from a version 2
31 * page header structure.
32 * cupsRasterWritePixels() - Write raster pixels.
33 * cups_raster_read() - Read through the raster buffer.
34 * cups_raster_read_header() - Read a raster page header.
35 * cups_raster_update() - Update the raster header and row count for the
37 * cups_raster_write() - Write a row of raster data...
38 * cups_read() - Read bytes from a file.
39 * cups_swap() - Swap bytes in raster data...
40 * cups_write() - Write bytes to a file.
44 * Include necessary headers...
47 #include "image-private.h"
48 #include <cups/debug.h>
51 #include <cups/string.h>
53 #if defined(WIN32) || defined(__EMX__)
57 #endif /* WIN32 || __EMX__ */
61 * Private structures...
64 struct _cups_raster_s
/**** Raster stream data ****/
66 unsigned sync
; /* Sync word from start of stream */
67 int fd
; /* File descriptor */
68 cups_mode_t mode
; /* Read/write mode */
69 cups_page_header2_t header
; /* Raster header for current page */
70 int count
, /* Current row run-length count */
71 remaining
, /* Remaining rows in page image */
72 bpp
; /* Bytes per pixel/color */
73 unsigned char *pixels
, /* Pixels for current row */
74 *pend
, /* End of pixel buffer */
75 *pcurrent
; /* Current byte in pixel buffer */
76 int compressed
, /* Non-zero if data is compressed */
77 swapped
; /* Non-zero if data is byte-swapped */
78 unsigned char *buffer
, /* Read/write buffer */
79 *bufptr
, /* Current (read) position in buffer */
80 *bufend
; /* End of current (read) buffer */
81 int bufsize
; /* Buffer size */
89 static unsigned cups_raster_read_header(cups_raster_t
*r
);
90 static int cups_raster_read(cups_raster_t
*r
, unsigned char *buf
,
92 static void cups_raster_update(cups_raster_t
*r
);
93 static int cups_raster_write(cups_raster_t
*r
, const unsigned char *pixels
);
94 static int cups_read(int fd
, unsigned char *buf
, int bytes
);
95 static void cups_swap(unsigned char *buf
, int bytes
);
96 static int cups_write(int fd
, const unsigned char *buf
, int bytes
);
100 * 'cupsRasterClose()' - Close a raster stream.
102 * The file descriptor associated with the raster stream must be closed
103 * separately as needed.
107 cupsRasterClose(cups_raster_t
*r
) /* I - Stream to close */
123 * 'cupsRasterOpen()' - Open a raster stream.
125 * This function associates a raster stream with the given file descriptor.
126 * For most printer driver filters, "fd" will be 0 (stdin). For most raster
127 * image processor (RIP) filters that generate raster data, "fd" will be 1
130 * When writing raster data, the @code CUPS_RASTER_WRITE@ or
131 * @code CUPS_RASTER_WRITE_COMPRESS@ mode can be used - compressed output
132 * is generally 25-50% smaller but adds a 100-300% execution time overhead.
135 cups_raster_t
* /* O - New stream */
136 cupsRasterOpen(int fd
, /* I - File descriptor */
137 cups_mode_t mode
) /* I - Mode - @code CUPS_RASTER_READ@, @code CUPS_RASTER_WRITE@, or @code CUPS_RASTER_WRITE_COMPRESSED@ */
139 cups_raster_t
*r
; /* New stream */
142 _cupsRasterClearError();
144 if ((r
= calloc(sizeof(cups_raster_t
), 1)) == NULL
)
146 _cupsRasterAddError("Unable to allocate memory for raster stream: %s\n",
152 r
->mode
= mode
== CUPS_RASTER_WRITE_COMPRESSED
? CUPS_RASTER_WRITE
: mode
;
154 if (mode
== CUPS_RASTER_READ
)
157 * Open for read - get sync word...
160 if (!cups_read(r
->fd
, (unsigned char *)&(r
->sync
), sizeof(r
->sync
)))
162 _cupsRasterAddError("Unable to read header from raster stream: %s\n",
168 if (r
->sync
!= CUPS_RASTER_SYNC
&&
169 r
->sync
!= CUPS_RASTER_REVSYNC
&&
170 r
->sync
!= CUPS_RASTER_SYNCv1
&&
171 r
->sync
!= CUPS_RASTER_REVSYNCv1
&&
172 r
->sync
!= CUPS_RASTER_SYNCv2
&&
173 r
->sync
!= CUPS_RASTER_REVSYNCv2
)
175 _cupsRasterAddError("Unknown raster format %08x!\n", r
->sync
);
180 if (r
->sync
== CUPS_RASTER_SYNCv2
||
181 r
->sync
== CUPS_RASTER_REVSYNCv2
)
184 if (r
->sync
== CUPS_RASTER_REVSYNC
||
185 r
->sync
== CUPS_RASTER_REVSYNCv1
||
186 r
->sync
== CUPS_RASTER_REVSYNCv2
)
189 DEBUG_printf(("r->swapped=%d, r->sync=%08x\n", r
->swapped
, r
->sync
));
194 * Open for write - put sync word...
197 if (mode
== CUPS_RASTER_WRITE_COMPRESSED
)
200 r
->sync
= CUPS_RASTER_SYNCv2
;
203 r
->sync
= CUPS_RASTER_SYNC
;
205 if (cups_write(r
->fd
, (unsigned char *)&(r
->sync
), sizeof(r
->sync
))
208 _cupsRasterAddError("Unable to write raster stream header: %s\n",
220 * 'cupsRasterReadHeader()' - Read a raster page header and store it in a
221 * version 1 page header structure.
223 * This function is deprecated. Use @link cupsRasterReadHeader2@ instead.
225 * Version 1 page headers were used in CUPS 1.0 and 1.1 and contain a subset
226 * of the version 2 page header data. This function handles reading version 2
227 * page headers and copying only the version 1 data into the provided buffer.
232 unsigned /* O - 1 on success, 0 on failure/end-of-file */
233 cupsRasterReadHeader(
234 cups_raster_t
*r
, /* I - Raster stream */
235 cups_page_header_t
*h
) /* I - Pointer to header data */
238 * Get the raster header...
241 if (!cups_raster_read_header(r
))
245 * Copy the header to the user-supplied buffer...
248 memcpy(h
, &(r
->header
), sizeof(cups_page_header_t
));
255 * 'cupsRasterReadHeader2()' - Read a raster page header and store it in a
256 * version 2 page header structure.
258 * @since CUPS 1.2/Mac OS X 10.5@
261 unsigned /* O - 1 on success, 0 on failure/end-of-file */
262 cupsRasterReadHeader2(
263 cups_raster_t
*r
, /* I - Raster stream */
264 cups_page_header2_t
*h
) /* I - Pointer to header data */
267 * Get the raster header...
270 if (!cups_raster_read_header(r
))
274 * Copy the header to the user-supplied buffer...
277 memcpy(h
, &(r
->header
), sizeof(cups_page_header2_t
));
284 * 'cupsRasterReadPixels()' - Read raster pixels.
286 * For best performance, filters should read one or more whole lines.
287 * The "cupsBytesPerLine" value from the page header can be used to allocate
288 * the line buffer and as the number of bytes to read.
291 unsigned /* O - Number of bytes read */
292 cupsRasterReadPixels(cups_raster_t
*r
, /* I - Raster stream */
293 unsigned char *p
, /* I - Pointer to pixel buffer */
294 unsigned len
) /* I - Number of bytes to read */
296 int bytes
; /* Bytes read */
297 unsigned cupsBytesPerLine
; /* cupsBytesPerLine value */
298 unsigned remaining
; /* Bytes remaining */
299 unsigned char *ptr
, /* Pointer to read buffer */
300 byte
, /* Byte from file */
301 *temp
; /* Pointer into buffer */
302 int count
; /* Repetition count */
305 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_READ
|| r
->remaining
== 0)
311 * Read without compression...
314 r
->remaining
-= len
/ r
->header
.cupsBytesPerLine
;
316 if (!cups_read(r
->fd
, p
, len
))
320 * Swap bytes as needed...
323 if ((r
->header
.cupsBitsPerColor
== 16 ||
324 r
->header
.cupsBitsPerPixel
== 12 ||
325 r
->header
.cupsBitsPerPixel
== 16) &&
337 * Read compressed data...
341 cupsBytesPerLine
= r
->header
.cupsBytesPerLine
;
343 while (remaining
> 0 && r
->remaining
> 0)
348 * Need to read a new row...
351 if (remaining
== cupsBytesPerLine
)
357 * Read using a modified TIFF "packbits" compression...
360 if (!cups_raster_read(r
, &byte
, 1))
369 bytes
= cupsBytesPerLine
;
374 * Get a new repeat count...
377 if (!cups_raster_read(r
, &byte
, 1))
383 * Copy N literal pixels...
386 count
= (257 - byte
) * r
->bpp
;
391 if (!cups_raster_read(r
, temp
, count
))
400 * Repeat the next N bytes...
403 count
= (byte
+ 1) * r
->bpp
;
412 if (!cups_raster_read(r
, temp
, r
->bpp
))
420 memcpy(temp
, temp
- r
->bpp
, r
->bpp
);
428 * Swap bytes as needed...
431 if ((r
->header
.cupsBitsPerColor
== 16 ||
432 r
->header
.cupsBitsPerPixel
== 12 ||
433 r
->header
.cupsBitsPerPixel
== 16) &&
435 cups_swap(ptr
, bytes
);
441 if (remaining
>= cupsBytesPerLine
)
443 bytes
= cupsBytesPerLine
;
444 r
->pcurrent
= r
->pixels
;
451 r
->pcurrent
= r
->pixels
+ bytes
;
455 * Copy data as needed...
459 memcpy(p
, ptr
, bytes
);
464 * Copy fragment from buffer...
467 if ((bytes
= r
->pend
- r
->pcurrent
) > remaining
)
470 memcpy(p
, r
->pcurrent
, bytes
);
471 r
->pcurrent
+= bytes
;
473 if (r
->pcurrent
>= r
->pend
)
475 r
->pcurrent
= r
->pixels
;
490 * 'cupsRasterWriteHeader()' - Write a raster page header from a version 1 page
493 * This function is deprecated. Use @link cupsRasterWriteHeader2@ instead.
498 unsigned /* O - 1 on success, 0 on failure */
499 cupsRasterWriteHeader(
500 cups_raster_t
*r
, /* I - Raster stream */
501 cups_page_header_t
*h
) /* I - Raster page header */
503 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_WRITE
)
507 * Make a copy of the header, and compute the number of raster
508 * lines in the page image...
511 memset(&(r
->header
), 0, sizeof(r
->header
));
512 memcpy(&(r
->header
), h
, sizeof(cups_page_header_t
));
514 cups_raster_update(r
);
517 * Write the raster header...
520 return (cups_write(r
->fd
, (unsigned char *)&(r
->header
), sizeof(r
->header
))
526 * 'cupsRasterWriteHeader2()' - Write a raster page header from a version 2
527 * page header structure.
529 * The page header can be initialized using @link cupsRasterInterpretPPD@.
531 * @since CUPS 1.2/Mac OS X 10.5@
534 unsigned /* O - 1 on success, 0 on failure */
535 cupsRasterWriteHeader2(
536 cups_raster_t
*r
, /* I - Raster stream */
537 cups_page_header2_t
*h
) /* I - Raster page header */
539 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_WRITE
)
543 * Make a copy of the header, and compute the number of raster
544 * lines in the page image...
547 memcpy(&(r
->header
), h
, sizeof(cups_page_header2_t
));
549 cups_raster_update(r
);
552 * Write the raster header...
555 return (cups_write(r
->fd
, (unsigned char *)&(r
->header
), sizeof(r
->header
))
561 * 'cupsRasterWritePixels()' - Write raster pixels.
563 * For best performance, filters should write one or more whole lines.
564 * The "cupsBytesPerLine" value from the page header can be used to allocate
565 * the line buffer and as the number of bytes to write.
568 unsigned /* O - Number of bytes written */
569 cupsRasterWritePixels(cups_raster_t
*r
, /* I - Raster stream */
570 unsigned char *p
, /* I - Bytes to write */
571 unsigned len
)/* I - Number of bytes to write */
573 int bytes
; /* Bytes read */
574 unsigned remaining
; /* Bytes remaining */
577 DEBUG_printf(("cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u\n",
578 r
, p
, len
, r
->remaining
));
580 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_WRITE
|| r
->remaining
== 0)
586 * Without compression, just write the raster data raw...
589 r
->remaining
-= len
/ r
->header
.cupsBytesPerLine
;
591 return (cups_write(r
->fd
, p
, len
));
595 * Otherwise, compress each line...
598 for (remaining
= len
; remaining
> 0; remaining
-= bytes
, p
+= bytes
)
601 * Figure out the number of remaining bytes on the current line...
604 if ((bytes
= remaining
) > (r
->pend
- r
->pcurrent
))
605 bytes
= r
->pend
- r
->pcurrent
;
610 * Check to see if this line is the same as the previous line...
613 if (memcmp(p
, r
->pcurrent
, bytes
))
615 if (!cups_raster_write(r
, r
->pixels
))
623 * Mark more bytes as the same...
626 r
->pcurrent
+= bytes
;
628 if (r
->pcurrent
>= r
->pend
)
631 * Increase the repeat count...
635 r
->pcurrent
= r
->pixels
;
638 * Flush out this line if it is the last one...
643 if (r
->remaining
== 0)
644 return (cups_raster_write(r
, r
->pixels
));
645 else if (r
->count
== 256)
647 if (cups_raster_write(r
, r
->pixels
) == 0)
661 * Copy the raster data to the buffer...
664 memcpy(r
->pcurrent
, p
, bytes
);
666 r
->pcurrent
+= bytes
;
668 if (r
->pcurrent
>= r
->pend
)
671 * Increase the repeat count...
675 r
->pcurrent
= r
->pixels
;
678 * Flush out this line if it is the last one...
683 if (r
->remaining
== 0)
684 return (cups_raster_write(r
, r
->pixels
));
694 * 'cups_raster_read_header()' - Read a raster page header.
697 static unsigned /* O - 1 on success, 0 on fail */
698 cups_raster_read_header(
699 cups_raster_t
*r
) /* I - Raster stream */
701 int len
; /* Length for read/swap */
704 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_READ
)
708 * Get the length of the raster header...
711 if (r
->sync
== CUPS_RASTER_SYNCv1
|| r
->sync
== CUPS_RASTER_REVSYNCv1
)
712 len
= sizeof(cups_page_header_t
);
714 len
= sizeof(cups_page_header2_t
);
720 memset(&(r
->header
), 0, sizeof(r
->header
));
722 if (cups_raster_read(r
, (unsigned char *)&(r
->header
), len
) < len
)
726 * Swap bytes as needed...
731 unsigned *s
, /* Current word */
732 temp
; /* Temporary copy */
735 DEBUG_puts("Swapping header bytes...");
737 for (len
= 81, s
= &(r
->header
.AdvanceDistance
);
741 DEBUG_printf(("%08x =>", *s
));
744 *s
= ((temp
& 0xff) << 24) |
745 ((temp
& 0xff00) << 8) |
746 ((temp
& 0xff0000) >> 8) |
747 ((temp
& 0xff000000) >> 24);
749 DEBUG_printf((" %08x\n", *s
));
754 * Update the header and row count...
757 cups_raster_update(r
);
764 * 'cups_raster_read()' - Read through the raster buffer.
767 static int /* O - Number of bytes read */
768 cups_raster_read(cups_raster_t
*r
, /* I - Raster stream */
769 unsigned char *buf
, /* I - Buffer */
770 int bytes
) /* I - Number of bytes to read */
772 int count
, /* Number of bytes read */
773 remaining
, /* Remaining bytes in buffer */
774 total
; /* Total bytes read */
777 DEBUG_printf(("cups_raster_read(r=%p, buf=%p, bytes=%d)\n", r
, buf
, bytes
));
780 return (cups_read(r
->fd
, buf
, bytes
));
783 * Allocate a read buffer as needed...
786 count
= 2 * r
->header
.cupsBytesPerLine
;
788 if (count
> r
->bufsize
)
790 int offset
= r
->bufptr
- r
->buffer
; /* Offset to current start of buffer */
791 int end
= r
->bufend
- r
->buffer
; /* Offset to current end of buffer */
792 unsigned char *rptr
; /* Pointer in read buffer */
795 rptr
= realloc(r
->buffer
, count
);
797 rptr
= malloc(count
);
803 r
->bufptr
= rptr
+ offset
;
804 r
->bufend
= rptr
+ end
;
809 * Loop until we have read everything...
812 for (total
= 0, remaining
= r
->bufend
- r
->bufptr
;
814 total
+= count
, buf
+= count
)
816 count
= bytes
- total
;
818 DEBUG_printf(("count=%d, remaining=%d, buf=%p, bufptr=%p, bufend=%p...\n",
819 count
, remaining
, buf
, r
->bufptr
, r
->bufend
));
826 * Read into the raster buffer and then copy...
829 remaining
= cups_read(r
->fd
, r
->buffer
, r
->bufsize
);
833 r
->bufptr
= r
->buffer
;
834 r
->bufend
= r
->buffer
+ remaining
;
839 * Read directly into "buf"...
842 count
= cups_read(r
->fd
, buf
, count
);
852 * Copy bytes from raster buffer to "buf"...
855 if (count
> remaining
)
864 *buf
= *(r
->bufptr
)++;
867 else if (count
< 128)
870 * Copy up to 127 bytes without using memcpy(); this is
871 * faster because it avoids an extra function call and is
872 * often further optimized by the compiler...
875 unsigned char *bufptr
; /* Temporary buffer pointer */
880 for (bufptr
= r
->bufptr
; count
> 0; count
--, total
++)
888 * Use memcpy() for a large read...
891 memcpy(buf
, r
->bufptr
, count
);
902 * 'cups_raster_update()' - Update the raster header and row count for the
907 cups_raster_update(cups_raster_t
*r
) /* I - Raster stream */
909 if (r
->sync
== CUPS_RASTER_SYNCv1
|| r
->sync
== CUPS_RASTER_REVSYNCv1
||
910 r
->header
.cupsNumColors
== 0)
913 * Set the "cupsNumColors" field according to the colorspace...
916 switch (r
->header
.cupsColorSpace
)
920 case CUPS_CSPACE_WHITE
:
921 case CUPS_CSPACE_GOLD
:
922 case CUPS_CSPACE_SILVER
:
923 r
->header
.cupsNumColors
= 1;
926 case CUPS_CSPACE_RGB
:
927 case CUPS_CSPACE_CMY
:
928 case CUPS_CSPACE_YMC
:
929 case CUPS_CSPACE_CIEXYZ
:
930 case CUPS_CSPACE_CIELab
:
931 case CUPS_CSPACE_ICC1
:
932 case CUPS_CSPACE_ICC2
:
933 case CUPS_CSPACE_ICC3
:
934 case CUPS_CSPACE_ICC4
:
935 case CUPS_CSPACE_ICC5
:
936 case CUPS_CSPACE_ICC6
:
937 case CUPS_CSPACE_ICC7
:
938 case CUPS_CSPACE_ICC8
:
939 case CUPS_CSPACE_ICC9
:
940 case CUPS_CSPACE_ICCA
:
941 case CUPS_CSPACE_ICCB
:
942 case CUPS_CSPACE_ICCC
:
943 case CUPS_CSPACE_ICCD
:
944 case CUPS_CSPACE_ICCE
:
945 case CUPS_CSPACE_ICCF
:
946 r
->header
.cupsNumColors
= 3;
949 case CUPS_CSPACE_RGBA
:
950 case CUPS_CSPACE_RGBW
:
951 case CUPS_CSPACE_CMYK
:
952 case CUPS_CSPACE_YMCK
:
953 case CUPS_CSPACE_KCMY
:
954 case CUPS_CSPACE_GMCK
:
955 case CUPS_CSPACE_GMCS
:
956 r
->header
.cupsNumColors
= 4;
959 case CUPS_CSPACE_KCMYcm
:
960 if (r
->header
.cupsBitsPerPixel
< 8)
961 r
->header
.cupsNumColors
= 6;
963 r
->header
.cupsNumColors
= 4;
969 * Set the number of bytes per pixel/color...
972 if (r
->header
.cupsColorOrder
== CUPS_ORDER_CHUNKED
)
973 r
->bpp
= (r
->header
.cupsBitsPerPixel
+ 7) / 8;
975 r
->bpp
= (r
->header
.cupsBitsPerColor
+ 7) / 8;
978 * Set the number of remaining rows...
981 if (r
->header
.cupsColorOrder
== CUPS_ORDER_PLANAR
)
982 r
->remaining
= r
->header
.cupsHeight
* r
->header
.cupsNumColors
;
984 r
->remaining
= r
->header
.cupsHeight
;
987 * Allocate the compression buffer...
992 if (r
->pixels
!= NULL
)
995 r
->pixels
= calloc(r
->header
.cupsBytesPerLine
, 1);
996 r
->pcurrent
= r
->pixels
;
997 r
->pend
= r
->pixels
+ r
->header
.cupsBytesPerLine
;
1004 * 'cups_raster_write()' - Write a row of compressed raster data...
1007 static int /* O - Number of bytes written */
1009 cups_raster_t
*r
, /* I - Raster stream */
1010 const unsigned char *pixels
) /* I - Pixel data to write */
1012 const unsigned char *start
, /* Start of sequence */
1013 *ptr
, /* Current pointer in sequence */
1014 *pend
, /* End of raster buffer */
1015 *plast
; /* Pointer to last pixel */
1016 unsigned char *wptr
; /* Pointer into write buffer */
1017 int bpp
, /* Bytes per pixel */
1021 DEBUG_printf(("cups_raster_write(r=%p, pixels=%p)\n", r
, pixels
));
1024 * Allocate a write buffer as needed...
1027 count
= r
->header
.cupsBytesPerLine
* 2;
1028 if (count
> r
->bufsize
)
1031 wptr
= realloc(r
->buffer
, count
);
1033 wptr
= malloc(count
);
1043 * Write the row repeat count...
1047 pend
= pixels
+ r
->header
.cupsBytesPerLine
;
1050 *wptr
++ = r
->count
- 1;
1053 * Write using a modified TIFF "packbits" compression...
1056 for (ptr
= pixels
; ptr
< pend
;)
1064 * Encode a single pixel at the end...
1068 for (count
= bpp
; count
> 0; count
--)
1071 else if (!memcmp(start
, ptr
, bpp
))
1074 * Encode a sequence of repeating pixels...
1077 for (count
= 2; count
< 128 && ptr
< plast
; count
++, ptr
+= bpp
)
1078 if (memcmp(ptr
, ptr
+ bpp
, bpp
))
1081 *wptr
++ = count
- 1;
1082 for (count
= bpp
; count
> 0; count
--)
1088 * Encode a sequence of non-repeating pixels...
1091 for (count
= 1; count
< 127 && ptr
< plast
; count
++, ptr
+= bpp
)
1092 if (!memcmp(ptr
, ptr
+ bpp
, bpp
))
1095 if (ptr
>= plast
&& count
< 128)
1101 *wptr
++ = 257 - count
;
1104 memcpy(wptr
, start
, count
);
1109 return (cups_write(r
->fd
, r
->buffer
, wptr
- r
->buffer
));
1114 * 'cups_read()' - Read bytes from a file.
1117 static int /* O - Bytes read or -1 */
1118 cups_read(int fd
, /* I - File descriptor */
1119 unsigned char *buf
, /* I - Buffer for read */
1120 int bytes
) /* I - Number of bytes to read */
1122 int count
, /* Number of bytes read */
1123 total
; /* Total bytes read */
1126 for (total
= 0; total
< bytes
; total
+= count
, buf
+= count
)
1128 count
= read(fd
, buf
, bytes
- total
);
1146 * 'cups_swap()' - Swap bytes in raster data...
1150 cups_swap(unsigned char *buf
, /* I - Buffer to swap */
1151 int bytes
) /* I - Number of bytes to swap */
1153 unsigned char even
, odd
; /* Temporary variables */
1172 * 'cups_write()' - Write bytes to a file.
1175 static int /* O - Bytes written or -1 */
1176 cups_write(int fd
, /* I - File descriptor */
1177 const unsigned char *buf
, /* I - Bytes to write */
1178 int bytes
) /* I - Number of bytes to write */
1180 int count
, /* Number of bytes written */
1181 total
; /* Total bytes written */
1184 for (total
= 0; total
< bytes
; total
+= count
, buf
+= count
)
1186 count
= write(fd
, buf
, bytes
- total
);
1202 * End of "$Id: raster.c 7720 2008-07-11 22:46:21Z mike $".