2 * "$Id: raster.c 6649 2007-07-11 21:46:42Z 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.
228 unsigned /* O - 1 on success, 0 on fail */
229 cupsRasterReadHeader(
230 cups_raster_t
*r
, /* I - Raster stream */
231 cups_page_header_t
*h
) /* I - Pointer to header data */
234 * Get the raster header...
237 if (!cups_raster_read_header(r
))
241 * Copy the header to the user-supplied buffer...
244 memcpy(h
, &(r
->header
), sizeof(cups_page_header_t
));
251 * 'cupsRasterReadHeader2()' - Read a raster page header and store it in a
252 * version 2 page header structure.
254 * @since CUPS 1.2/Mac OS X 10.5@
257 unsigned /* O - 1 on success, 0 on fail */
258 cupsRasterReadHeader2(
259 cups_raster_t
*r
, /* I - Raster stream */
260 cups_page_header2_t
*h
) /* I - Pointer to header data */
263 * Get the raster header...
266 if (!cups_raster_read_header(r
))
270 * Copy the header to the user-supplied buffer...
273 memcpy(h
, &(r
->header
), sizeof(cups_page_header2_t
));
280 * 'cupsRasterReadPixels()' - Read raster pixels.
283 unsigned /* O - Number of bytes read */
284 cupsRasterReadPixels(cups_raster_t
*r
, /* I - Raster stream */
285 unsigned char *p
, /* I - Pointer to pixel buffer */
286 unsigned len
) /* I - Number of bytes to read */
288 int bytes
; /* Bytes read */
289 unsigned cupsBytesPerLine
; /* cupsBytesPerLine value */
290 unsigned remaining
; /* Bytes remaining */
291 unsigned char *ptr
, /* Pointer to read buffer */
292 byte
, /* Byte from file */
293 *temp
; /* Pointer into buffer */
294 int count
; /* Repetition count */
297 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_READ
|| r
->remaining
== 0)
303 * Read without compression...
306 r
->remaining
-= len
/ r
->header
.cupsBytesPerLine
;
308 if (!cups_read(r
->fd
, p
, len
))
312 * Swap bytes as needed...
315 if ((r
->header
.cupsBitsPerColor
== 16 ||
316 r
->header
.cupsBitsPerPixel
== 12 ||
317 r
->header
.cupsBitsPerPixel
== 16) &&
329 * Read compressed data...
333 cupsBytesPerLine
= r
->header
.cupsBytesPerLine
;
335 while (remaining
> 0 && r
->remaining
> 0)
340 * Need to read a new row...
343 if (remaining
== cupsBytesPerLine
)
349 * Read using a modified TIFF "packbits" compression...
352 if (!cups_raster_read(r
, &byte
, 1))
361 bytes
= cupsBytesPerLine
;
366 * Get a new repeat count...
369 if (!cups_raster_read(r
, &byte
, 1))
375 * Copy N literal pixels...
378 count
= (257 - byte
) * r
->bpp
;
383 if (!cups_raster_read(r
, temp
, count
))
392 * Repeat the next N bytes...
395 count
= (byte
+ 1) * r
->bpp
;
404 if (!cups_raster_read(r
, temp
, r
->bpp
))
412 memcpy(temp
, temp
- r
->bpp
, r
->bpp
);
420 * Swap bytes as needed...
423 if ((r
->header
.cupsBitsPerColor
== 16 ||
424 r
->header
.cupsBitsPerPixel
== 12 ||
425 r
->header
.cupsBitsPerPixel
== 16) &&
427 cups_swap(ptr
, bytes
);
433 if (remaining
>= cupsBytesPerLine
)
435 bytes
= cupsBytesPerLine
;
436 r
->pcurrent
= r
->pixels
;
443 r
->pcurrent
= r
->pixels
+ bytes
;
447 * Copy data as needed...
451 memcpy(p
, ptr
, bytes
);
456 * Copy fragment from buffer...
459 if ((bytes
= r
->pend
- r
->pcurrent
) > remaining
)
462 memcpy(p
, r
->pcurrent
, bytes
);
463 r
->pcurrent
+= bytes
;
465 if (r
->pcurrent
>= r
->pend
)
467 r
->pcurrent
= r
->pixels
;
482 * 'cupsRasterWriteHeader()' - Write a raster page header from a version 1 page
485 * This function is deprecated. Use @link cupsRasterWriteHeader2@ instead.
490 unsigned /* O - 1 on success, 0 on failure */
491 cupsRasterWriteHeader(
492 cups_raster_t
*r
, /* I - Raster stream */
493 cups_page_header_t
*h
) /* I - Raster page header */
495 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_WRITE
)
499 * Make a copy of the header, and compute the number of raster
500 * lines in the page image...
503 memset(&(r
->header
), 0, sizeof(r
->header
));
504 memcpy(&(r
->header
), h
, sizeof(cups_page_header_t
));
506 cups_raster_update(r
);
509 * Write the raster header...
512 return (cups_write(r
->fd
, (unsigned char *)&(r
->header
), sizeof(r
->header
))
518 * 'cupsRasterWriteHeader2()' - Write a raster page header from a version 2
519 * page header structure.
521 * The page header can be initialized using @link cupsRasterInterpretPPD@.
523 * @since CUPS 1.2/Mac OS X 10.5@
526 unsigned /* O - 1 on success, 0 on failure */
527 cupsRasterWriteHeader2(
528 cups_raster_t
*r
, /* I - Raster stream */
529 cups_page_header2_t
*h
) /* I - Raster page header */
531 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_WRITE
)
535 * Make a copy of the header, and compute the number of raster
536 * lines in the page image...
539 memcpy(&(r
->header
), h
, sizeof(cups_page_header2_t
));
541 cups_raster_update(r
);
544 * Write the raster header...
547 return (cups_write(r
->fd
, (unsigned char *)&(r
->header
), sizeof(r
->header
))
553 * 'cupsRasterWritePixels()' - Write raster pixels.
556 unsigned /* O - Number of bytes written */
557 cupsRasterWritePixels(cups_raster_t
*r
, /* I - Raster stream */
558 unsigned char *p
, /* I - Bytes to write */
559 unsigned len
)/* I - Number of bytes to write */
561 int bytes
; /* Bytes read */
562 unsigned remaining
; /* Bytes remaining */
565 DEBUG_printf(("cupsRasterWritePixels(r=%p, p=%p, len=%u), remaining=%u\n",
566 r
, p
, len
, r
->remaining
));
568 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_WRITE
|| r
->remaining
== 0)
574 * Without compression, just write the raster data raw...
577 r
->remaining
-= len
/ r
->header
.cupsBytesPerLine
;
579 return (cups_write(r
->fd
, p
, len
));
583 * Otherwise, compress each line...
586 for (remaining
= len
; remaining
> 0; remaining
-= bytes
, p
+= bytes
)
589 * Figure out the number of remaining bytes on the current line...
592 if ((bytes
= remaining
) > (r
->pend
- r
->pcurrent
))
593 bytes
= r
->pend
- r
->pcurrent
;
598 * Check to see if this line is the same as the previous line...
601 if (memcmp(p
, r
->pcurrent
, bytes
))
603 if (!cups_raster_write(r
, r
->pixels
))
611 * Mark more bytes as the same...
614 r
->pcurrent
+= bytes
;
616 if (r
->pcurrent
>= r
->pend
)
619 * Increase the repeat count...
623 r
->pcurrent
= r
->pixels
;
626 * Flush out this line if it is the last one...
631 if (r
->remaining
== 0)
632 return (cups_raster_write(r
, r
->pixels
));
633 else if (r
->count
== 256)
635 if (cups_raster_write(r
, r
->pixels
) == 0)
649 * Copy the raster data to the buffer...
652 memcpy(r
->pcurrent
, p
, bytes
);
654 r
->pcurrent
+= bytes
;
656 if (r
->pcurrent
>= r
->pend
)
659 * Increase the repeat count...
663 r
->pcurrent
= r
->pixels
;
666 * Flush out this line if it is the last one...
671 if (r
->remaining
== 0)
672 return (cups_raster_write(r
, r
->pixels
));
682 * 'cups_raster_read_header()' - Read a raster page header.
685 static unsigned /* O - 1 on success, 0 on fail */
686 cups_raster_read_header(
687 cups_raster_t
*r
) /* I - Raster stream */
689 int len
; /* Length for read/swap */
692 if (r
== NULL
|| r
->mode
!= CUPS_RASTER_READ
)
696 * Get the length of the raster header...
699 if (r
->sync
== CUPS_RASTER_SYNCv1
|| r
->sync
== CUPS_RASTER_REVSYNCv1
)
700 len
= sizeof(cups_page_header_t
);
702 len
= sizeof(cups_page_header2_t
);
708 memset(&(r
->header
), 0, sizeof(r
->header
));
710 if (cups_raster_read(r
, (unsigned char *)&(r
->header
), len
) < len
)
714 * Swap bytes as needed...
719 unsigned *s
, /* Current word */
720 temp
; /* Temporary copy */
723 DEBUG_puts("Swapping header bytes...");
725 for (len
= 81, s
= &(r
->header
.AdvanceDistance
);
729 DEBUG_printf(("%08x =>", *s
));
732 *s
= ((temp
& 0xff) << 24) |
733 ((temp
& 0xff00) << 8) |
734 ((temp
& 0xff0000) >> 8) |
735 ((temp
& 0xff000000) >> 24);
737 DEBUG_printf((" %08x\n", *s
));
742 * Update the header and row count...
745 cups_raster_update(r
);
752 * 'cups_raster_read()' - Read through the raster buffer.
755 static int /* O - Number of bytes read */
756 cups_raster_read(cups_raster_t
*r
, /* I - Raster stream */
757 unsigned char *buf
, /* I - Buffer */
758 int bytes
) /* I - Number of bytes to read */
760 int count
, /* Number of bytes read */
761 remaining
, /* Remaining bytes in buffer */
762 total
; /* Total bytes read */
765 DEBUG_printf(("cups_raster_read(r=%p, buf=%p, bytes=%d)\n", r
, buf
, bytes
));
768 return (cups_read(r
->fd
, buf
, bytes
));
771 * Allocate a read buffer as needed...
774 count
= 2 * r
->header
.cupsBytesPerLine
;
776 if (count
> r
->bufsize
)
778 int offset
= r
->bufptr
- r
->buffer
; /* Offset to current start of buffer */
779 int end
= r
->bufend
- r
->buffer
; /* Offset to current end of buffer */
780 unsigned char *rptr
; /* Pointer in read buffer */
783 rptr
= realloc(r
->buffer
, count
);
785 rptr
= malloc(count
);
791 r
->bufptr
= rptr
+ offset
;
792 r
->bufend
= rptr
+ end
;
797 * Loop until we have read everything...
800 for (total
= 0, remaining
= r
->bufend
- r
->bufptr
;
802 total
+= count
, buf
+= count
)
804 count
= bytes
- total
;
806 DEBUG_printf(("count=%d, remaining=%d, buf=%p, bufptr=%p, bufend=%p...\n",
807 count
, remaining
, buf
, r
->bufptr
, r
->bufend
));
814 * Read into the raster buffer and then copy...
817 remaining
= cups_read(r
->fd
, r
->buffer
, r
->bufsize
);
821 r
->bufptr
= r
->buffer
;
822 r
->bufend
= r
->buffer
+ remaining
;
827 * Read directly into "buf"...
830 count
= cups_read(r
->fd
, buf
, count
);
840 * Copy bytes from raster buffer to "buf"...
843 if (count
> remaining
)
852 *buf
= *(r
->bufptr
)++;
855 else if (count
< 128)
858 * Copy up to 127 bytes without using memcpy(); this is
859 * faster because it avoids an extra function call and is
860 * often further optimized by the compiler...
863 unsigned char *bufptr
; /* Temporary buffer pointer */
868 for (bufptr
= r
->bufptr
; count
> 0; count
--, total
++)
876 * Use memcpy() for a large read...
879 memcpy(buf
, r
->bufptr
, count
);
890 * 'cups_raster_update()' - Update the raster header and row count for the
895 cups_raster_update(cups_raster_t
*r
) /* I - Raster stream */
897 if (r
->sync
== CUPS_RASTER_SYNCv1
|| r
->sync
== CUPS_RASTER_REVSYNCv1
||
898 r
->header
.cupsNumColors
== 0)
901 * Set the "cupsNumColors" field according to the colorspace...
904 switch (r
->header
.cupsColorSpace
)
908 case CUPS_CSPACE_WHITE
:
909 case CUPS_CSPACE_GOLD
:
910 case CUPS_CSPACE_SILVER
:
911 r
->header
.cupsNumColors
= 1;
914 case CUPS_CSPACE_RGB
:
915 case CUPS_CSPACE_CMY
:
916 case CUPS_CSPACE_YMC
:
917 case CUPS_CSPACE_CIEXYZ
:
918 case CUPS_CSPACE_CIELab
:
919 case CUPS_CSPACE_ICC1
:
920 case CUPS_CSPACE_ICC2
:
921 case CUPS_CSPACE_ICC3
:
922 case CUPS_CSPACE_ICC4
:
923 case CUPS_CSPACE_ICC5
:
924 case CUPS_CSPACE_ICC6
:
925 case CUPS_CSPACE_ICC7
:
926 case CUPS_CSPACE_ICC8
:
927 case CUPS_CSPACE_ICC9
:
928 case CUPS_CSPACE_ICCA
:
929 case CUPS_CSPACE_ICCB
:
930 case CUPS_CSPACE_ICCC
:
931 case CUPS_CSPACE_ICCD
:
932 case CUPS_CSPACE_ICCE
:
933 case CUPS_CSPACE_ICCF
:
934 r
->header
.cupsNumColors
= 3;
937 case CUPS_CSPACE_RGBA
:
938 case CUPS_CSPACE_RGBW
:
939 case CUPS_CSPACE_CMYK
:
940 case CUPS_CSPACE_YMCK
:
941 case CUPS_CSPACE_KCMY
:
942 case CUPS_CSPACE_GMCK
:
943 case CUPS_CSPACE_GMCS
:
944 r
->header
.cupsNumColors
= 4;
947 case CUPS_CSPACE_KCMYcm
:
948 if (r
->header
.cupsBitsPerPixel
< 8)
949 r
->header
.cupsNumColors
= 6;
951 r
->header
.cupsNumColors
= 4;
957 * Set the number of bytes per pixel/color...
960 if (r
->header
.cupsColorOrder
== CUPS_ORDER_CHUNKED
)
961 r
->bpp
= (r
->header
.cupsBitsPerPixel
+ 7) / 8;
963 r
->bpp
= (r
->header
.cupsBitsPerColor
+ 7) / 8;
966 * Set the number of remaining rows...
969 if (r
->header
.cupsColorOrder
== CUPS_ORDER_PLANAR
)
970 r
->remaining
= r
->header
.cupsHeight
* r
->header
.cupsNumColors
;
972 r
->remaining
= r
->header
.cupsHeight
;
975 * Allocate the compression buffer...
980 if (r
->pixels
!= NULL
)
983 r
->pixels
= calloc(r
->header
.cupsBytesPerLine
, 1);
984 r
->pcurrent
= r
->pixels
;
985 r
->pend
= r
->pixels
+ r
->header
.cupsBytesPerLine
;
992 * 'cups_raster_write()' - Write a row of compressed raster data...
995 static int /* O - Number of bytes written */
997 cups_raster_t
*r
, /* I - Raster stream */
998 const unsigned char *pixels
) /* I - Pixel data to write */
1000 const unsigned char *start
, /* Start of sequence */
1001 *ptr
, /* Current pointer in sequence */
1002 *pend
, /* End of raster buffer */
1003 *plast
; /* Pointer to last pixel */
1004 unsigned char *wptr
; /* Pointer into write buffer */
1005 int bpp
, /* Bytes per pixel */
1007 maxrun
; /* Maximum run of 128 * bpp */
1010 DEBUG_printf(("cups_raster_write(r=%p, pixels=%p)\n", r
, pixels
));
1013 * Allocate a write buffer as needed...
1016 count
= r
->header
.cupsBytesPerLine
* 2;
1017 if (count
> r
->bufsize
)
1020 wptr
= realloc(r
->buffer
, count
);
1022 wptr
= malloc(count
);
1032 * Write the row repeat count...
1036 pend
= pixels
+ r
->header
.cupsBytesPerLine
;
1039 *wptr
++ = r
->count
- 1;
1043 * Write using a modified TIFF "packbits" compression...
1046 for (ptr
= pixels
; ptr
< pend
;)
1054 * Encode a single pixel at the end...
1058 for (count
= bpp
; count
> 0; count
--)
1061 else if (!memcmp(start
, ptr
, bpp
))
1064 * Encode a sequence of repeating pixels...
1067 for (count
= 2; count
< 128 && ptr
< plast
; count
++, ptr
+= bpp
)
1068 if (memcmp(ptr
, ptr
+ bpp
, bpp
))
1071 *wptr
++ = count
- 1;
1072 for (count
= bpp
; count
> 0; count
--)
1078 * Encode a sequence of non-repeating pixels...
1081 for (count
= 1; count
< 127 && ptr
< plast
; count
++, ptr
+= bpp
)
1082 if (!memcmp(ptr
, ptr
+ bpp
, bpp
))
1085 if (ptr
>= plast
&& count
< 128)
1091 *wptr
++ = 257 - count
;
1094 memcpy(wptr
, start
, count
);
1099 return (cups_write(r
->fd
, r
->buffer
, wptr
- r
->buffer
));
1104 * 'cups_read()' - Read bytes from a file.
1107 static int /* O - Bytes read or -1 */
1108 cups_read(int fd
, /* I - File descriptor */
1109 unsigned char *buf
, /* I - Buffer for read */
1110 int bytes
) /* I - Number of bytes to read */
1112 int count
, /* Number of bytes read */
1113 total
; /* Total bytes read */
1116 for (total
= 0; total
< bytes
; total
+= count
, buf
+= count
)
1118 count
= read(fd
, buf
, bytes
- total
);
1136 * 'cups_swap()' - Swap bytes in raster data...
1140 cups_swap(unsigned char *buf
, /* I - Buffer to swap */
1141 int bytes
) /* I - Number of bytes to swap */
1143 unsigned char even
, odd
; /* Temporary variables */
1162 * 'cups_write()' - Write bytes to a file.
1165 static int /* O - Bytes written or -1 */
1166 cups_write(int fd
, /* I - File descriptor */
1167 const unsigned char *buf
, /* I - Bytes to write */
1168 int bytes
) /* I - Number of bytes to write */
1170 int count
, /* Number of bytes written */
1171 total
; /* Total bytes written */
1174 for (total
= 0; total
< bytes
; total
+= count
, buf
+= count
)
1176 count
= write(fd
, buf
, bytes
- total
);
1192 * End of "$Id: raster.c 6649 2007-07-11 21:46:42Z mike $".