]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/raster-stubs.c
34dde82776779413ef2aa84a89df6f6431f5a08c
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 <cups/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 */
164 DEBUG_printf(("cupsRasterReadHeader(r=%p, h=%p)", (void *)r
, (void *)h
));
167 * Get the raster header...
170 if (!_cupsRasterReadHeader(r
))
172 memset(h
, 0, sizeof(cups_page_header_t
));
173 DEBUG_puts("1cupsRasterReadHeader: Unable to read page header, returning 0.");
178 * Copy the header to the user-supplied buffer...
181 memcpy(h
, &(r
->header
), sizeof(cups_page_header_t
));
183 DEBUG_printf(("1cupsRasterReadHeader: cupsColorSpace=%s", _cupsRasterColorSpaceString(h
->cupsColorSpace
)));
184 DEBUG_printf(("1cupsRasterReadHeader: cupsBitsPerColor=%u", h
->cupsBitsPerColor
));
185 DEBUG_printf(("1cupsRasterReadHeader: cupsBitsPerPixel=%u", h
->cupsBitsPerPixel
));
186 DEBUG_printf(("1cupsRasterReadHeader: cupsBytesPerLine=%u", h
->cupsBytesPerLine
));
187 DEBUG_printf(("1cupsRasterReadHeader: cupsWidth=%u", h
->cupsWidth
));
188 DEBUG_printf(("1cupsRasterReadHeader: cupsHeight=%u", h
->cupsHeight
));
190 DEBUG_puts("1cupsRasterReadHeader: Returning 1.");
196 * 'cupsRasterReadHeader2()' - Read a raster page header and store it in a
197 * version 2 page header structure.
199 * @since CUPS 1.2/macOS 10.5@
202 unsigned /* O - 1 on success, 0 on failure/end-of-file */
203 cupsRasterReadHeader2(
204 cups_raster_t
*r
, /* I - Raster stream */
205 cups_page_header2_t
*h
) /* I - Pointer to header data */
208 * Get the raster header...
211 DEBUG_printf(("cupsRasterReadHeader2(r=%p, h=%p)", (void *)r
, (void *)h
));
213 if (!_cupsRasterReadHeader(r
))
215 memset(h
, 0, sizeof(cups_page_header2_t
));
216 DEBUG_puts("1cupsRasterReadHeader2: Unable to read header, returning 0.");
221 * Copy the header to the user-supplied buffer...
224 memcpy(h
, &(r
->header
), sizeof(cups_page_header2_t
));
226 DEBUG_printf(("1cupsRasterReadHeader2: cupsColorSpace=%s", _cupsRasterColorSpaceString(h
->cupsColorSpace
)));
227 DEBUG_printf(("1cupsRasterReadHeader2: cupsBitsPerColor=%u", h
->cupsBitsPerColor
));
228 DEBUG_printf(("1cupsRasterReadHeader2: cupsBitsPerPixel=%u", h
->cupsBitsPerPixel
));
229 DEBUG_printf(("1cupsRasterReadHeader2: cupsBytesPerLine=%u", h
->cupsBytesPerLine
));
230 DEBUG_printf(("1cupsRasterReadHeader2: cupsWidth=%u", h
->cupsWidth
));
231 DEBUG_printf(("1cupsRasterReadHeader2: cupsHeight=%u", h
->cupsHeight
));
233 DEBUG_puts("1cupsRasterReadHeader2: Returning 1.");
239 * 'cupsRasterReadPixels()' - Read raster pixels.
241 * For best performance, filters should read one or more whole lines.
242 * The "cupsBytesPerLine" value from the page header can be used to allocate
243 * the line buffer and as the number of bytes to read.
246 unsigned /* O - Number of bytes read */
247 cupsRasterReadPixels(
248 cups_raster_t
*r
, /* I - Raster stream */
249 unsigned char *p
, /* I - Pointer to pixel buffer */
250 unsigned len
) /* I - Number of bytes to read */
252 return (_cupsRasterReadPixels(r
, p
, len
));
257 * 'cupsRasterWriteHeader()' - Write a raster page header from a version 1 page
260 * This function is deprecated. Use @link cupsRasterWriteHeader2@ instead.
265 unsigned /* O - 1 on success, 0 on failure */
266 cupsRasterWriteHeader(
267 cups_raster_t
*r
, /* I - Raster stream */
268 cups_page_header_t
*h
) /* I - Raster page header */
270 DEBUG_printf(("cupsRasterWriteHeader(r=%p, h=%p)", (void *)r
, (void *)h
));
272 if (r
== NULL
|| r
->mode
== CUPS_RASTER_READ
)
274 DEBUG_puts("1cupsRasterWriteHeader: Stream NULL or open for reading, returning 0.");
279 * Make a copy of the header and write using the private function...
282 memset(&(r
->header
), 0, sizeof(r
->header
));
283 memcpy(&(r
->header
), h
, sizeof(cups_page_header_t
));
285 return (_cupsRasterWriteHeader(r
));
290 * 'cupsRasterWriteHeader2()' - Write a raster page header from a version 2
291 * page header structure.
293 * The page header can be initialized using @link cupsRasterInitPWGHeader@.
295 * @since CUPS 1.2/macOS 10.5@
298 unsigned /* O - 1 on success, 0 on failure */
299 cupsRasterWriteHeader2(
300 cups_raster_t
*r
, /* I - Raster stream */
301 cups_page_header2_t
*h
) /* I - Raster page header */
303 DEBUG_printf(("cupsRasterWriteHeader(r=%p, h=%p)", (void *)r
, (void *)h
));
305 if (r
== NULL
|| r
->mode
== CUPS_RASTER_READ
)
307 DEBUG_puts("1cupsRasterWriteHeader2: Stream NULL or open for reading, returning 0.");
312 * Make a copy of the header, and compute the number of raster
313 * lines in the page image...
316 memcpy(&(r
->header
), h
, sizeof(cups_page_header2_t
));
318 return (_cupsRasterWriteHeader(r
));
323 * 'cupsRasterWritePixels()' - Write raster pixels.
325 * For best performance, filters should write one or more whole lines.
326 * The "cupsBytesPerLine" value from the page header can be used to allocate
327 * the line buffer and as the number of bytes to write.
330 unsigned /* O - Number of bytes written */
331 cupsRasterWritePixels(
332 cups_raster_t
*r
, /* I - Raster stream */
333 unsigned char *p
, /* I - Bytes to write */
334 unsigned len
) /* I - Number of bytes to write */
336 return (_cupsRasterWritePixels(r
, p
, len
));
341 * 'cups_read_fd()' - Read bytes from a file.
344 static ssize_t
/* O - Bytes read or -1 */
345 cups_read_fd(void *ctx
, /* I - File descriptor as pointer */
346 unsigned char *buf
, /* I - Buffer for read */
347 size_t bytes
) /* I - Maximum number of bytes to read */
349 int fd
= (int)((intptr_t)ctx
);
350 /* File descriptor */
351 ssize_t count
; /* Number of bytes read */
354 #ifdef _WIN32 /* Sigh */
355 while ((count
= read(fd
, buf
, (unsigned)bytes
)) < 0)
357 while ((count
= read(fd
, buf
, bytes
)) < 0)
359 if (errno
!= EINTR
&& errno
!= EAGAIN
)
361 DEBUG_printf(("8cups_read_fd: %s", strerror(errno
)));
365 DEBUG_printf(("8cups_read_fd: Returning %d bytes.", (int)count
));
372 * 'cups_write_fd()' - Write bytes to a file.
375 static ssize_t
/* O - Bytes written or -1 */
376 cups_write_fd(void *ctx
, /* I - File descriptor pointer */
377 unsigned char *buf
, /* I - Bytes to write */
378 size_t bytes
) /* I - Number of bytes to write */
380 int fd
= (int)((intptr_t)ctx
);
381 /* File descriptor */
382 ssize_t count
; /* Number of bytes written */
385 #ifdef _WIN32 /* Sigh */
386 while ((count
= write(fd
, buf
, (unsigned)bytes
)) < 0)
388 while ((count
= write(fd
, buf
, bytes
)) < 0)
390 if (errno
!= EINTR
&& errno
!= EAGAIN
)
392 DEBUG_printf(("8cups_write_fd: %s", strerror(errno
)));