Header | cups/raster.h |
---|---|
Library | -lcups |
See Also | Programming: CUPS Programming Manual Programming: PPD API References: CUPS PPD Specification |
The CUPS raster API provides a standard interface for reading and writing CUPS raster streams which are used for printing to raster printers. Because the raster format is updated from time to time, it is important to use this API to avoid incompatibilities with newer versions of CUPS.
Two kinds of CUPS filters use the CUPS raster API - raster image processor
(RIP) filters such as pstoraster
and cgpdftoraster
(macOS) that produce CUPS raster files and printer driver filters that
convert CUPS raster files into a format usable by the printer. Printer
driver filters are by far the most common.
CUPS raster files (application/vnd.cups-raster
) consists of
a stream of raster page descriptions produced by one of the RIP filters such as
pstoraster, imagetoraster, or
cgpdftoraster. CUPS raster files are referred to using the
cups_raster_t
type and are
opened using the cupsRasterOpen
function. For example, to read raster data from the standard input, open
file descriptor 0:
#include <cups/raster.h> cups_raster_t *ras = cupsRasterOpen(0, CUPS_RASTER_READ);
Each page of data begins with a page dictionary structure called
cups_page_header2_t
. This
structure contains the colorspace, bits per color, media size, media type,
hardware resolution, and so forth used for the page.
Note:Do not confuse the colorspace in the page header with the PPD ColorModel keyword. ColorModel refers to the general type of color used for a device (Gray, RGB, CMYK, DeviceN) and is often used to select a particular colorspace for the page header along with the associate color profile. The page header colorspace (cupsColorSpace) describes both the type and organization of the color data, for example KCMY (black first) instead of CMYK and RGBA (RGB + alpha) instead of RGB.
You read the page header using the
cupsRasterReadHeader2
function:
#include <cups/raster.h> cups_raster_t *ras = cupsRasterOpen(0, CUPS_RASTER_READ); cups_page_header2_t header; while (cupsRasterReadHeader2(ras, &header)) { /* setup this page */ /* read raster data */ /* finish this page */ }
After the page dictionary comes the page data which is a full-resolution,
possibly compressed bitmap representing the page in the printer's output
colorspace. You read uncompressed raster data using the
cupsRasterReadPixels
function. A for
loop is normally used to read the page one line
at a time:
#include <cups/raster.h> cups_raster_t *ras = cupsRasterOpen(0, CUPS_RASTER_READ); cups_page_header2_t header; int page = 0; int y; char *buffer; while (cupsRasterReadHeader2(ras, &header)) { /* setup this page */ page ++; fprintf(stderr, "PAGE: %d %d\n", page, header.NumCopies); /* allocate memory for 1 line */ buffer = malloc(header.cupsBytesPerLine); /* read raster data */ for (y = 0; y < header.cupsHeight; y ++) { if (cupsRasterReadPixels(ras, buffer, header.cupsBytesPerLine) == 0) break; /* write raster data to printer on stdout */ } /* finish this page */ }
When you are done reading the raster data, call the
cupsRasterClose
function to free
the memory used to read the raster file:
cups_raster_t *ras; cupsRasterClose(ras);
Close a raster stream.
void cupsRasterClose(cups_raster_t *r);
r | Stream to close |
---|
The file descriptor associated with the raster stream must be closed separately as needed.
Return the last error from a raster function.
const char *cupsRasterErrorString(void);
Last error or NULL
If there are no recent errors, NULL
is returned.
Initialize a page header for PWG Raster output.
int cupsRasterInitPWGHeader(cups_page_header2_t *h, pwg_media_t *media, const char *type, int xdpi, int ydpi, const char *sides, const char *sheet_back);
h | Page header |
---|---|
media | PWG media information |
type | PWG raster type string |
xdpi | Cross-feed direction (horizontal) resolution |
ydpi | Feed direction (vertical) resolution |
sides | IPP "sides" option value |
sheet_back | Transform for back side or NULL for none |
1 on success, 0 on failure
The "media" argument specifies the media to use.
The "type" argument specifies a "pwg-raster-document-type-supported" value
that controls the color space and bit depth of the raster data.
The "xres" and "yres" arguments specify the raster resolution in dots per
inch.
The "sheet_back" argument specifies a "pwg-raster-document-sheet-back" value
to apply for the back side of a page. Pass NULL
for the front side.
Open a raster stream using a file descriptor.
cups_raster_t *cupsRasterOpen(int fd, cups_mode_t mode);
fd | File descriptor |
---|---|
mode | Mode - CUPS_RASTER_READ ,
CUPS_RASTER_WRITE ,
CUPS_RASTER_WRITE_COMPRESSED ,
or CUPS_RASTER_WRITE_PWG |
New stream
This function associates a raster stream with the given file descriptor.
For most printer driver filters, "fd" will be 0 (stdin). For most raster
image processor (RIP) filters that generate raster data, "fd" will be 1
(stdout).
When writing raster data, the CUPS_RASTER_WRITE
,
CUPS_RASTER_WRITE_COMPRESS
, or CUPS_RASTER_WRITE_PWG
mode can
be used - compressed and PWG output is generally 25-50% smaller but adds a
100-300% execution time overhead.
Open a raster stream using a callback function.
cups_raster_t *cupsRasterOpenIO(cups_raster_iocb_t iocb, void *ctx, cups_mode_t mode);
iocb | Read/write callback |
---|---|
ctx | Context pointer for callback |
mode | Mode - CUPS_RASTER_READ ,
CUPS_RASTER_WRITE ,
CUPS_RASTER_WRITE_COMPRESSED ,
or CUPS_RASTER_WRITE_PWG |
New stream
This function associates a raster stream with the given callback function and
context pointer.
When writing raster data, the CUPS_RASTER_WRITE
,
CUPS_RASTER_WRITE_COMPRESS
, or CUPS_RASTER_WRITE_PWG
mode can
be used - compressed and PWG output is generally 25-50% smaller but adds a
100-300% execution time overhead.
Read a raster page header and store it in a version 1 page header structure.
unsigned cupsRasterReadHeader(cups_raster_t *r, cups_page_header_t *h);
r | Raster stream |
---|---|
h | Pointer to header data |
1 on success, 0 on failure/end-of-file
This function is deprecated. Use cupsRasterReadHeader2
instead.
Version 1 page headers were used in CUPS 1.0 and 1.1 and contain a subset
of the version 2 page header data. This function handles reading version 2
page headers and copying only the version 1 data into the provided buffer.
Read a raster page header and store it in a version 2 page header structure.
unsigned cupsRasterReadHeader2(cups_raster_t *r, cups_page_header2_t *h);
r | Raster stream |
---|---|
h | Pointer to header data |
1 on success, 0 on failure/end-of-file
Read raster pixels.
unsigned cupsRasterReadPixels(cups_raster_t *r, unsigned char *p, unsigned len);
r | Raster stream |
---|---|
p | Pointer to pixel buffer |
len | Number of bytes to read |
Number of bytes read
For best performance, filters should read one or more whole lines. The "cupsBytesPerLine" value from the page header can be used to allocate the line buffer and as the number of bytes to read.
Write a raster page header from a version 1 page header structure.
unsigned cupsRasterWriteHeader(cups_raster_t *r, cups_page_header_t *h);
r | Raster stream |
---|---|
h | Raster page header |
1 on success, 0 on failure
This function is deprecated. Use cupsRasterWriteHeader2
instead.
Write a raster page header from a version 2 page header structure.
unsigned cupsRasterWriteHeader2(cups_raster_t *r, cups_page_header2_t *h);
r | Raster stream |
---|---|
h | Raster page header |
1 on success, 0 on failure
The page header can be initialized using cupsRasterInitPWGHeader
.
Write raster pixels.
unsigned cupsRasterWritePixels(cups_raster_t *r, unsigned char *p, unsigned len);
r | Raster stream |
---|---|
p | Bytes to write |
len | Number of bytes to write |
Number of bytes written
For best performance, filters should write one or more whole lines. The "cupsBytesPerLine" value from the page header can be used to allocate the line buffer and as the number of bytes to write.
AdvanceMedia attribute values
typedef enum cups_adv_e cups_adv_t;
Boolean type
typedef enum cups_bool_e cups_bool_t;
cupsColorSpace attribute values
typedef enum cups_cspace_e cups_cspace_t;
CutMedia attribute values
typedef enum cups_cut_e cups_cut_t;
LeadingEdge attribute values
typedef enum cups_edge_e cups_edge_t;
Jog attribute values
typedef enum cups_jog_e cups_jog_t;
cupsRasterOpen modes
typedef enum cups_mode_e cups_mode_t;
cupsColorOrder attribute values
typedef enum cups_order_e cups_order_t;
Orientation attribute values
typedef enum cups_orient_e cups_orient_t;
Version 2 page header
typedef struct cups_page_header2_s cups_page_header2_t;
Version 1 page header
typedef struct cups_page_header_s cups_page_header_t;
cupsRasterOpenIO callback function
typedef ssize_t (*cups_raster_iocb_t)(void *ctx, unsigned char *buffer, size_t length);
Raster stream data
typedef struct _cups_raster_s cups_raster_t;
Version 2 page header
struct cups_page_header2_s {
unsigned AdvanceDistance;
cups_adv_t AdvanceMedia;
cups_bool_t Collate;
cups_cut_t CutMedia;
cups_bool_t Duplex;
unsigned HWResolution[2];
unsigned ImagingBoundingBox[4];
cups_bool_t InsertSheet;
cups_jog_t Jog;
cups_edge_t LeadingEdge;
cups_bool_t ManualFeed;
unsigned Margins[2];
char MediaClass[64];
char MediaColor[64];
unsigned MediaPosition;
char MediaType[64];
unsigned MediaWeight;
cups_bool_t MirrorPrint;
cups_bool_t NegativePrint;
unsigned NumCopies;
cups_orient_t Orientation;
cups_bool_t OutputFaceUp;
char OutputType[64];
unsigned PageSize[2];
cups_bool_t Separations;
cups_bool_t TraySwitch;
cups_bool_t Tumble;
unsigned cupsBitsPerColor;
unsigned cupsBitsPerPixel;
float cupsBorderlessScalingFactor;
unsigned cupsBytesPerLine;
cups_order_t cupsColorOrder;
cups_cspace_t cupsColorSpace;
unsigned cupsCompression;
unsigned cupsHeight;
float cupsImagingBBox[4];
unsigned cupsInteger[16];
char cupsMarkerType[64];
unsigned cupsMediaType;
unsigned cupsNumColors;
char cupsPageSizeName[64];
float cupsPageSize[2];
float cupsReal[16];
char cupsRenderingIntent[64];
unsigned cupsRowCount;
unsigned cupsRowFeed;
unsigned cupsRowStep;
char cupsString[16][64];
unsigned cupsWidth;
};
AdvanceDistance | AdvanceDistance value in points |
---|---|
AdvanceMedia | AdvanceMedia value (cups_adv_t ) |
Collate | Collated copies value |
CutMedia | CutMedia value (cups_cut_t ) |
Duplex | Duplexed (double-sided) value |
HWResolution[2] | Resolution in dots-per-inch |
ImagingBoundingBox[4] | Pixel region that is painted (points, left, bottom, right, top) |
InsertSheet | InsertSheet value |
Jog | Jog value (cups_jog_t ) |
LeadingEdge | LeadingEdge value (cups_edge_t ) |
ManualFeed | ManualFeed value |
Margins[2] | Lower-lefthand margins in points |
MediaClass[64] | MediaClass string |
MediaColor[64] | MediaColor string |
MediaPosition | MediaPosition value |
MediaType[64] | MediaType string |
MediaWeight | MediaWeight value in grams/m^2 |
MirrorPrint | MirrorPrint value |
NegativePrint | NegativePrint value |
NumCopies | Number of copies to produce |
Orientation | Orientation value (cups_orient_t ) |
OutputFaceUp | OutputFaceUp value |
OutputType[64] | OutputType string |
PageSize[2] | Width and length of page in points |
Separations | Separations value |
TraySwitch | TraySwitch value |
Tumble | Tumble value |
cupsBitsPerColor | Number of bits for each color |
cupsBitsPerPixel | Number of bits for each pixel |
cupsBorderlessScalingFactor CUPS 1.2/macOS 10.5 | Scaling that was applied to page data |
cupsBytesPerLine | Number of bytes per line |
cupsColorOrder | Order of colors |
cupsColorSpace | True colorspace |
cupsCompression | Device compression to use |
cupsHeight | Height of page image in pixels |
cupsImagingBBox[4] CUPS 1.2/macOS 10.5 | Floating point ImagingBoundingBox (scaling factor not applied, left, bottom, right, top) |
cupsInteger[16] CUPS 1.2/macOS 10.5 | User-defined integer values |
cupsMarkerType[64] CUPS 1.2/macOS 10.5 | Ink/toner type |
cupsMediaType | Media type code |
cupsNumColors CUPS 1.2/macOS 10.5 | Number of color compoents |
cupsPageSizeName[64] CUPS 1.2/macOS 10.5 | PageSize name |
cupsPageSize[2] CUPS 1.2/macOS 10.5 | Floating point PageSize (scaling * factor not applied) |
cupsReal[16] CUPS 1.2/macOS 10.5 | User-defined floating-point values |
cupsRenderingIntent[64] CUPS 1.2/macOS 10.5 | Color rendering intent |
cupsRowCount | Rows per band |
cupsRowFeed | Feed between bands |
cupsRowStep | Spacing between lines |
cupsString[16][64] CUPS 1.2/macOS 10.5 | User-defined string values |
cupsWidth | Width of page image in pixels |
Version 1 page header
struct cups_page_header_s {
unsigned AdvanceDistance;
cups_adv_t AdvanceMedia;
cups_bool_t Collate;
cups_cut_t CutMedia;
cups_bool_t Duplex;
unsigned HWResolution[2];
unsigned ImagingBoundingBox[4];
cups_bool_t InsertSheet;
cups_jog_t Jog;
cups_edge_t LeadingEdge;
cups_bool_t ManualFeed;
unsigned Margins[2];
char MediaClass[64];
char MediaColor[64];
unsigned MediaPosition;
char MediaType[64];
unsigned MediaWeight;
cups_bool_t MirrorPrint;
cups_bool_t NegativePrint;
unsigned NumCopies;
cups_orient_t Orientation;
cups_bool_t OutputFaceUp;
char OutputType[64];
unsigned PageSize[2];
cups_bool_t Separations;
cups_bool_t TraySwitch;
cups_bool_t Tumble;
unsigned cupsBitsPerColor;
unsigned cupsBitsPerPixel;
unsigned cupsBytesPerLine;
cups_order_t cupsColorOrder;
cups_cspace_t cupsColorSpace;
unsigned cupsCompression;
unsigned cupsHeight;
unsigned cupsMediaType;
unsigned cupsRowCount;
unsigned cupsRowFeed;
unsigned cupsRowStep;
unsigned cupsWidth;
};
AdvanceDistance | AdvanceDistance value in points |
---|---|
AdvanceMedia | AdvanceMedia value (cups_adv_t ) |
Collate | Collated copies value |
CutMedia | CutMedia value (cups_cut_t ) |
Duplex | Duplexed (double-sided) value |
HWResolution[2] | Resolution in dots-per-inch |
ImagingBoundingBox[4] | Pixel region that is painted (points, left, bottom, right, top) |
InsertSheet | InsertSheet value |
Jog | Jog value (cups_jog_t ) |
LeadingEdge | LeadingEdge value (cups_edge_t ) |
ManualFeed | ManualFeed value |
Margins[2] | Lower-lefthand margins in points |
MediaClass[64] | MediaClass string |
MediaColor[64] | MediaColor string |
MediaPosition | MediaPosition value |
MediaType[64] | MediaType string |
MediaWeight | MediaWeight value in grams/m^2 |
MirrorPrint | MirrorPrint value |
NegativePrint | NegativePrint value |
NumCopies | Number of copies to produce |
Orientation | Orientation value (cups_orient_t ) |
OutputFaceUp | OutputFaceUp value |
OutputType[64] | OutputType string |
PageSize[2] | Width and length of page in points |
Separations | Separations value |
TraySwitch | TraySwitch value |
Tumble | Tumble value |
cupsBitsPerColor | Number of bits for each color |
cupsBitsPerPixel | Number of bits for each pixel |
cupsBytesPerLine | Number of bytes per line |
cupsColorOrder | Order of colors |
cupsColorSpace | True colorspace |
cupsCompression | Device compression to use |
cupsHeight | Height of page image in pixels |
cupsMediaType | Media type code |
cupsRowCount | Rows per band |
cupsRowFeed | Feed between bands |
cupsRowStep | Spacing between lines |
cupsWidth | Width of page image in pixels |
AdvanceMedia attribute values
CUPS_ADVANCE_FILE | Advance the roll after this file |
---|---|
CUPS_ADVANCE_JOB | Advance the roll after this job |
CUPS_ADVANCE_NONE | Never advance the roll |
CUPS_ADVANCE_PAGE | Advance the roll after this page |
CUPS_ADVANCE_SET | Advance the roll after this set |
Boolean type
CUPS_FALSE | Logical false |
---|---|
CUPS_TRUE | Logical true |
cupsColorSpace attribute values
CUPS_CSPACE_ADOBERGB CUPS 1.4.5 | Red, green, blue (Adobe RGB) |
---|---|
CUPS_CSPACE_CIELab CUPS 1.1.19/macOS 10.3 | CIE Lab |
CUPS_CSPACE_CIEXYZ CUPS 1.1.19/macOS 10.3 | CIE XYZ |
CUPS_CSPACE_CMY | Cyan, magenta, yellow (DeviceCMY) |
CUPS_CSPACE_CMYK | Cyan, magenta, yellow, black (DeviceCMYK) |
CUPS_CSPACE_DEVICE1 CUPS 1.4.5 | DeviceN, 1 color |
CUPS_CSPACE_DEVICE2 CUPS 1.4.5 | DeviceN, 2 colors |
CUPS_CSPACE_DEVICE3 CUPS 1.4.5 | DeviceN, 3 colors |
CUPS_CSPACE_DEVICE4 CUPS 1.4.5 | DeviceN, 4 colors |
CUPS_CSPACE_DEVICE5 CUPS 1.4.5 | DeviceN, 5 colors |
CUPS_CSPACE_DEVICE6 CUPS 1.4.5 | DeviceN, 6 colors |
CUPS_CSPACE_DEVICE7 CUPS 1.4.5 | DeviceN, 7 colors |
CUPS_CSPACE_DEVICE8 CUPS 1.4.5 | DeviceN, 8 colors |
CUPS_CSPACE_DEVICE9 CUPS 1.4.5 | DeviceN, 9 colors |
CUPS_CSPACE_DEVICEA CUPS 1.4.5 | DeviceN, 10 colors |
CUPS_CSPACE_DEVICEB CUPS 1.4.5 | DeviceN, 11 colors |
CUPS_CSPACE_DEVICEC CUPS 1.4.5 | DeviceN, 12 colors |
CUPS_CSPACE_DEVICED CUPS 1.4.5 | DeviceN, 13 colors |
CUPS_CSPACE_DEVICEE CUPS 1.4.5 | DeviceN, 14 colors |
CUPS_CSPACE_DEVICEF CUPS 1.4.5 | DeviceN, 15 colors |
CUPS_CSPACE_GMCK DEPRECATED | Gold, magenta, yellow, black |
CUPS_CSPACE_GMCS DEPRECATED | Gold, magenta, yellow, silver |
CUPS_CSPACE_GOLD DEPRECATED | Gold foil |
CUPS_CSPACE_ICC1 CUPS 1.1.19/macOS 10.3 | ICC-based, 1 color |
CUPS_CSPACE_ICC2 CUPS 1.1.19/macOS 10.3 | ICC-based, 2 colors |
CUPS_CSPACE_ICC3 CUPS 1.1.19/macOS 10.3 | ICC-based, 3 colors |
CUPS_CSPACE_ICC4 CUPS 1.1.19/macOS 10.3 | ICC-based, 4 colors |
CUPS_CSPACE_ICC5 CUPS 1.1.19/macOS 10.3 | ICC-based, 5 colors |
CUPS_CSPACE_ICC6 CUPS 1.1.19/macOS 10.3 | ICC-based, 6 colors |
CUPS_CSPACE_ICC7 CUPS 1.1.19/macOS 10.3 | ICC-based, 7 colors |
CUPS_CSPACE_ICC8 CUPS 1.1.19/macOS 10.3 | ICC-based, 8 colors |
CUPS_CSPACE_ICC9 CUPS 1.1.19/macOS 10.3 | ICC-based, 9 colors |
CUPS_CSPACE_ICCA CUPS 1.1.19/macOS 10.3 | ICC-based, 10 colors |
CUPS_CSPACE_ICCB CUPS 1.1.19/macOS 10.3 | ICC-based, 11 colors |
CUPS_CSPACE_ICCC CUPS 1.1.19/macOS 10.3 | ICC-based, 12 colors |
CUPS_CSPACE_ICCD CUPS 1.1.19/macOS 10.3 | ICC-based, 13 colors |
CUPS_CSPACE_ICCE CUPS 1.1.19/macOS 10.3 | ICC-based, 14 colors |
CUPS_CSPACE_ICCF CUPS 1.1.19/macOS 10.3 | ICC-based, 15 colors |
CUPS_CSPACE_K | Black (DeviceK) |
CUPS_CSPACE_KCMY DEPRECATED | Black, cyan, magenta, yellow |
CUPS_CSPACE_KCMYcm DEPRECATED | Black, cyan, magenta, yellow, light-cyan, light-magenta |
CUPS_CSPACE_RGB | Red, green, blue (DeviceRGB, sRGB by default) |
CUPS_CSPACE_RGBA | Red, green, blue, alpha (DeviceRGB, sRGB by default) |
CUPS_CSPACE_RGBW CUPS 1.2/macOS 10.5 | Red, green, blue, white (DeviceRGB, sRGB by default) |
CUPS_CSPACE_SILVER DEPRECATED | Silver foil |
CUPS_CSPACE_SRGB CUPS 1.4.5 | Red, green, blue (sRGB) |
CUPS_CSPACE_SW CUPS 1.4.5 | Luminance (gamma 2.2) |
CUPS_CSPACE_W | Luminance (DeviceGray, gamma 2.2 by default) |
CUPS_CSPACE_WHITE DEPRECATED | White ink (as black) |
CUPS_CSPACE_YMC DEPRECATED | Yellow, magenta, cyan |
CUPS_CSPACE_YMCK DEPRECATED | Yellow, magenta, cyan, black |
CutMedia attribute values
CUPS_CUT_FILE | Cut the roll after this file |
---|---|
CUPS_CUT_JOB | Cut the roll after this job |
CUPS_CUT_NONE | Never cut the roll |
CUPS_CUT_PAGE | Cut the roll after this page |
CUPS_CUT_SET | Cut the roll after this set |
LeadingEdge attribute values
CUPS_EDGE_BOTTOM | Leading edge is the bottom of the page |
---|---|
CUPS_EDGE_LEFT | Leading edge is the left of the page |
CUPS_EDGE_RIGHT | Leading edge is the right of the page |
CUPS_EDGE_TOP | Leading edge is the top of the page |
Jog attribute values
CUPS_JOG_FILE | Move pages after this file |
---|---|
CUPS_JOG_JOB | Move pages after this job |
CUPS_JOG_NONE | Never move pages |
CUPS_JOG_SET | Move pages after this set |
cupsRasterOpen modes
CUPS_RASTER_READ | Open stream for reading |
---|---|
CUPS_RASTER_WRITE | Open stream for writing |
CUPS_RASTER_WRITE_COMPRESSED CUPS 1.3/macOS 10.5 | Open stream for compressed writing |
CUPS_RASTER_WRITE_PWG CUPS 1.5/macOS 10.7 | Open stream for compressed writing in PWG Raster mode |
cupsColorOrder attribute values
CUPS_ORDER_BANDED | CCC MMM YYY KKK ... |
---|---|
CUPS_ORDER_CHUNKED | CMYK CMYK CMYK ... |
CUPS_ORDER_PLANAR | CCC ... MMM ... YYY ... KKK ... |
Orientation attribute values
CUPS_ORIENT_0 | Don't rotate the page |
---|---|
CUPS_ORIENT_180 | Turn the page upside down |
CUPS_ORIENT_270 | Rotate the page clockwise |
CUPS_ORIENT_90 | Rotate the page counter-clockwise |