]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/raster-stubs.c
2 * Imaging library stubs for CUPS.
4 * Copyright © 2018 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 * Include necessary headers...
14 #include "raster-private.h"
18 * These stubs wrap the real functions in libcups - this allows one library to
19 * provide all of the CUPS API functions while still supporting the old split
20 * library organization...
28 static ssize_t
cups_read_fd(void *ctx
, unsigned char *buf
, size_t bytes
);
29 static ssize_t
cups_write_fd(void *ctx
, unsigned char *buf
, size_t bytes
);
34 * 'cupsRasterClose()' - Close a raster stream.
36 * The file descriptor associated with the raster stream must be closed
37 * separately as needed.
41 cupsRasterClose(cups_raster_t
*r
) /* I - Stream to close */
48 * 'cupsRasterErrorString()' - Return the last error from a raster function.
50 * If there are no recent errors, `NULL` is returned.
52 * @since CUPS 1.3/macOS 10.5@
55 const char * /* O - Last error or `NULL` */
56 cupsRasterErrorString(void)
58 return (_cupsRasterErrorString());
63 * 'cupsRasterInitPWGHeader()' - Initialize a page header for PWG Raster output.
65 * The "media" argument specifies the media to use.
67 * The "type" argument specifies a "pwg-raster-document-type-supported" value
68 * that controls the color space and bit depth of the raster data.
70 * The "xres" and "yres" arguments specify the raster resolution in dots per
73 * The "sheet_back" argument specifies a "pwg-raster-document-sheet-back" value
74 * to apply for the back side of a page. Pass @code NULL@ for the front side.
76 * @since CUPS 2.2/macOS 10.12@
79 int /* O - 1 on success, 0 on failure */
80 cupsRasterInitPWGHeader(
81 cups_page_header2_t
*h
, /* I - Page header */
82 pwg_media_t
*media
, /* I - PWG media information */
83 const char *type
, /* I - PWG raster type string */
84 int xdpi
, /* I - Cross-feed direction (horizontal) resolution */
85 int ydpi
, /* I - Feed direction (vertical) resolution */
86 const char *sides
, /* I - IPP "sides" option value */
87 const char *sheet_back
) /* I - Transform for back side or @code NULL@ for none */
89 return (_cupsRasterInitPWGHeader(h
, media
, type
, xdpi
, ydpi
, sides
, sheet_back
));
94 * 'cupsRasterOpen()' - Open a raster stream using a file descriptor.
96 * This function associates a raster stream with the given file descriptor.
97 * For most printer driver filters, "fd" will be 0 (stdin). For most raster
98 * image processor (RIP) filters that generate raster data, "fd" will be 1
101 * When writing raster data, the @code CUPS_RASTER_WRITE@,
102 * @code CUPS_RASTER_WRITE_COMPRESS@, or @code CUPS_RASTER_WRITE_PWG@ mode can
103 * be used - compressed and PWG output is generally 25-50% smaller but adds a
104 * 100-300% execution time overhead.
107 cups_raster_t
* /* O - New stream */
108 cupsRasterOpen(int fd
, /* I - File descriptor */
109 cups_mode_t mode
) /* I - Mode - @code CUPS_RASTER_READ@,
110 @code CUPS_RASTER_WRITE@,
111 @code CUPS_RASTER_WRITE_COMPRESSED@,
112 or @code CUPS_RASTER_WRITE_PWG@ */
114 if (mode
== CUPS_RASTER_READ
)
115 return (_cupsRasterNew(cups_read_fd
, (void *)((intptr_t)fd
), mode
));
117 return (_cupsRasterNew(cups_write_fd
, (void *)((intptr_t)fd
), mode
));
122 * 'cupsRasterOpenIO()' - Open a raster stream using a callback function.
124 * This function associates a raster stream with the given callback function and
127 * When writing raster data, the @code CUPS_RASTER_WRITE@,
128 * @code CUPS_RASTER_WRITE_COMPRESS@, or @code CUPS_RASTER_WRITE_PWG@ mode can
129 * be used - compressed and PWG output is generally 25-50% smaller but adds a
130 * 100-300% execution time overhead.
133 cups_raster_t
* /* O - New stream */
135 cups_raster_iocb_t iocb
, /* I - Read/write callback */
136 void *ctx
, /* I - Context pointer for callback */
137 cups_mode_t mode
) /* I - Mode - @code CUPS_RASTER_READ@,
138 @code CUPS_RASTER_WRITE@,
139 @code CUPS_RASTER_WRITE_COMPRESSED@,
140 or @code CUPS_RASTER_WRITE_PWG@ */
142 return (_cupsRasterNew(iocb
, ctx
, mode
));
147 * 'cupsRasterReadHeader()' - Read a raster page header and store it in a
148 * version 1 page header structure.
150 * This function is deprecated. Use @link cupsRasterReadHeader2@ instead.
152 * Version 1 page headers were used in CUPS 1.0 and 1.1 and contain a subset
153 * of the version 2 page header data. This function handles reading version 2
154 * page headers and copying only the version 1 data into the provided buffer.
159 unsigned /* O - 1 on success, 0 on failure/end-of-file */
160 cupsRasterReadHeader(
161 cups_raster_t
*r
, /* I - Raster stream */
162 cups_page_header_t
*h
) /* I - Pointer to header data */
165 * Get the raster header...
168 if (!_cupsRasterReadHeader(r
))
170 memset(h
, 0, sizeof(cups_page_header_t
));
175 * Copy the header to the user-supplied buffer...
178 memcpy(h
, &(r
->header
), sizeof(cups_page_header_t
));
184 * 'cupsRasterReadHeader2()' - Read a raster page header and store it in a
185 * version 2 page header structure.
187 * @since CUPS 1.2/macOS 10.5@
190 unsigned /* O - 1 on success, 0 on failure/end-of-file */
191 cupsRasterReadHeader2(
192 cups_raster_t
*r
, /* I - Raster stream */
193 cups_page_header2_t
*h
) /* I - Pointer to header data */
196 * Get the raster header...
199 if (!_cupsRasterReadHeader(r
))
201 memset(h
, 0, sizeof(cups_page_header2_t
));
206 * Copy the header to the user-supplied buffer...
209 memcpy(h
, &(r
->header
), sizeof(cups_page_header2_t
));
215 * 'cupsRasterReadPixels()' - Read raster pixels.
217 * For best performance, filters should read one or more whole lines.
218 * The "cupsBytesPerLine" value from the page header can be used to allocate
219 * the line buffer and as the number of bytes to read.
222 unsigned /* O - Number of bytes read */
223 cupsRasterReadPixels(
224 cups_raster_t
*r
, /* I - Raster stream */
225 unsigned char *p
, /* I - Pointer to pixel buffer */
226 unsigned len
) /* I - Number of bytes to read */
228 return (_cupsRasterReadPixels(r
, p
, len
));
233 * 'cupsRasterWriteHeader()' - Write a raster page header from a version 1 page
236 * This function is deprecated. Use @link cupsRasterWriteHeader2@ instead.
241 unsigned /* O - 1 on success, 0 on failure */
242 cupsRasterWriteHeader(
243 cups_raster_t
*r
, /* I - Raster stream */
244 cups_page_header_t
*h
) /* I - Raster page header */
246 if (r
== NULL
|| r
->mode
== CUPS_RASTER_READ
)
250 * Make a copy of the header and write using the private function...
253 memset(&(r
->header
), 0, sizeof(r
->header
));
254 memcpy(&(r
->header
), h
, sizeof(cups_page_header_t
));
256 return (_cupsRasterWriteHeader(r
));
261 * 'cupsRasterWriteHeader2()' - Write a raster page header from a version 2
262 * page header structure.
264 * The page header can be initialized using @link cupsRasterInitPWGHeader@.
266 * @since CUPS 1.2/macOS 10.5@
269 unsigned /* O - 1 on success, 0 on failure */
270 cupsRasterWriteHeader2(
271 cups_raster_t
*r
, /* I - Raster stream */
272 cups_page_header2_t
*h
) /* I - Raster page header */
274 if (r
== NULL
|| r
->mode
== CUPS_RASTER_READ
)
278 * Make a copy of the header, and compute the number of raster
279 * lines in the page image...
282 memcpy(&(r
->header
), h
, sizeof(cups_page_header2_t
));
284 return (_cupsRasterWriteHeader(r
));
289 * 'cupsRasterWritePixels()' - Write raster pixels.
291 * For best performance, filters should write one or more whole lines.
292 * The "cupsBytesPerLine" value from the page header can be used to allocate
293 * the line buffer and as the number of bytes to write.
296 unsigned /* O - Number of bytes written */
297 cupsRasterWritePixels(
298 cups_raster_t
*r
, /* I - Raster stream */
299 unsigned char *p
, /* I - Bytes to write */
300 unsigned len
) /* I - Number of bytes to write */
302 return (_cupsRasterWritePixels(r
, p
, len
));
307 * 'cups_read_fd()' - Read bytes from a file.
310 static ssize_t
/* O - Bytes read or -1 */
311 cups_read_fd(void *ctx
, /* I - File descriptor as pointer */
312 unsigned char *buf
, /* I - Buffer for read */
313 size_t bytes
) /* I - Maximum number of bytes to read */
315 int fd
= (int)((intptr_t)ctx
);
316 /* File descriptor */
317 ssize_t count
; /* Number of bytes read */
320 #ifdef _WIN32 /* Sigh */
321 while ((count
= read(fd
, buf
, (unsigned)bytes
)) < 0)
323 while ((count
= read(fd
, buf
, bytes
)) < 0)
325 if (errno
!= EINTR
&& errno
!= EAGAIN
)
333 * 'cups_write_fd()' - Write bytes to a file.
336 static ssize_t
/* O - Bytes written or -1 */
337 cups_write_fd(void *ctx
, /* I - File descriptor pointer */
338 unsigned char *buf
, /* I - Bytes to write */
339 size_t bytes
) /* I - Number of bytes to write */
341 int fd
= (int)((intptr_t)ctx
);
342 /* File descriptor */
343 ssize_t count
; /* Number of bytes written */
346 #ifdef _WIN32 /* Sigh */
347 while ((count
= write(fd
, buf
, (unsigned)bytes
)) < 0)
349 while ((count
= write(fd
, buf
, bytes
)) < 0)
351 if (errno
!= EINTR
&& errno
!= EAGAIN
)