Raster API
Keywords: Programming

## Introduction

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.

## General Usage

The <cups/raster.h> header file must be included to use the `cupsRaster` functions.

Programs using these functions must be linked to the CUPS imaging library: libcupsimage.a, libcupsimage.so.2, libcupsimage.2.dylib, libcupsimage_s.a, or libcupsimage2.lib depending on the platform. The following command compiles myprogram.c using GCC and the CUPS imaging library:

    gcc -o myprogram myprogram.c -lcupsimage

## Compatibility

Unless otherwise specified, the raster API functions require CUPS 1.1 or higher.

## Licensing

The CUPS raster API is provided under the terms of the GNU Library General Public License, with exceptions for MacOS X-based programs. Please see the CUPS license agreement for more information.

## Contents

- Enumerations
- Functions
- Structures
- Types

## Enumerations

- `cups_adv_e`
- `cups_bool_e`
- `cups_cspace_e`
- `cups_cut_e`
- `cups_edge_e`
- `cups_jog_e`
- `cups_mode_e`
- `cups_order_e`
- `cups_orient_e`

### cups_adv_e

#### Description

AdvanceMedia attribute values

#### Values

Name | Description
--- | ---
`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

### cups_bool_e

#### Description

Types...

#### Values

Name | Description
--- | ---
`CUPS_FALSE` | Logical false
`CUPS_TRUE` | Logical true

### cups_cspace_e

#### Description

#### Values

Name | Description
--- | ---
`CUPS_CSPACE_CIELab` CUPS 1.1.19 | CIE Lab
`CUPS_CSPACE_CIEXYZ` CUPS 1.1.19 | CIE XYZ
`CUPS_CSPACE_CMY` | Cyan, magenta, yellow
`CUPS_CSPACE_CMYK` | Cyan, magenta, yellow, black
`CUPS_CSPACE_GMCK` | Gold, magenta, yellow, black
`CUPS_CSPACE_GMCS` | Gold, magenta, yellow, silver
`CUPS_CSPACE_GOLD` | Gold foil
`CUPS_CSPACE_ICC1` CUPS 1.1.19 | ICC-based, 1 color
`CUPS_CSPACE_ICC2` CUPS 1.1.19 | ICC-based, 2 colors
`CUPS_CSPACE_ICC3` CUPS 1.1.19 | ICC-based, 3 colors
`CUPS_CSPACE_ICC4` CUPS 1.1.19 | ICC-based, 4 colors
`CUPS_CSPACE_ICC5` CUPS 1.1.19 | ICC-based, 5 colors
`CUPS_CSPACE_ICC6` CUPS 1.1.19 | ICC-based, 6 colors
`CUPS_CSPACE_ICC7` CUPS 1.1.19 | ICC-based, 7 colors
`CUPS_CSPACE_ICC8` CUPS 1.1.19 | ICC-based, 8 colors
`CUPS_CSPACE_ICC9` CUPS 1.1.19 | ICC-based, 9 colors
`CUPS_CSPACE_ICCA` CUPS 1.1.19 | ICC-based, 10 colors
`CUPS_CSPACE_ICCB` CUPS 1.1.19 | ICC-based, 11 colors
`CUPS_CSPACE_ICCC` CUPS 1.1.19 | ICC-based, 12 colors
`CUPS_CSPACE_ICCD` CUPS 1.1.19 | ICC-based, 13 colors
`CUPS_CSPACE_ICCE` CUPS 1.1.19 | ICC-based, 14 colors
`CUPS_CSPACE_ICCF` CUPS 1.1.19 | ICC-based, 15 colors
`CUPS_CSPACE_K` | Black
`CUPS_CSPACE_KCMY` | Black, cyan, magenta, yellow
`CUPS_CSPACE_KCMYcm` | Black, cyan, magenta, yellow, * light-cyan, light-magenta
`CUPS_CSPACE_RGB` | Red, green, blue
`CUPS_CSPACE_RGBA` | Red, green, blue, alpha
`CUPS_CSPACE_RGBW` CUPS 1.2 | Red, green, blue, white
`CUPS_CSPACE_SILVER` | Silver foil
`CUPS_CSPACE_W` | Luminance
`CUPS_CSPACE_WHITE` | White ink (as black)
`CUPS_CSPACE_YMC` | Yellow, magenta, cyan
`CUPS_CSPACE_YMCK` | Yellow, magenta, cyan, black

### cups_cut_e

#### Description

#### Values

Name | Description
--- | ---
`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

### cups_edge_e

#### Description

#### Values

Name | Description
--- | ---
`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

### cups_jog_e

#### Description

#### Values

Name | Description
--- | ---
`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

### cups_mode_e

#### Description

#### Values

Name | Description
--- | ---
`CUPS_RASTER_READ` | Open stream for reading
`CUPS_RASTER_WRITE` | Open stream for writing
`CUPS_RASTER_WRITE_COMPRESSED` CUPS 1.3 | Open stream for compressed writing

### cups_order_e

#### Description

#### Values

Name | Description
--- | ---
`CUPS_ORDER_BANDED` | CCC MMM YYY KKK ...
`CUPS_ORDER_CHUNKED` | CMYK CMYK CMYK ...
`CUPS_ORDER_PLANAR` | CCC ... MMM ... YYY ... KKK ...

### cups_orient_e

#### Description

#### Values

Name | Description
--- | ---
`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

## Functions

- `cupsRasterClose()`
- `cupsRasterInterpretPPD()` CUPS 1.2
- `cupsRasterOpen()`
- `cupsRasterReadHeader()`
- `cupsRasterReadHeader2()` CUPS 1.2
- `cupsRasterReadPixels()`
- `cupsRasterWriteHeader()`
- `cupsRasterWriteHeader2()` CUPS 1.2
- `cupsRasterWritePixels()`

### cupsRasterClose()

#### Description

Close a raster stream.

#### Syntax

`void
cupsRasterClose( cups_raster_t * r);`

#### Arguments

Name | Description
--- | ---
`r` | Stream to close

#### Returns

Nothing.

### CUPS 1.2 cupsRasterInterpretPPD()

#### Description

Interpret PPD commands to create a page header.

This function does not mark the options in the PPD using the "num_options" and "options" arguments. Instead, mark the options prior to calling cupsRasterInterpretPPD() - this allows you to do per-page options without manipulating the options array.

The "func" argument specifies an optional callback function that is called prior to the computation of the final raster data. The function can make changes to the cups_page_header2_t data as needed to use a supported raster format and then returns 0 on success and -1 if the requested attributes cannot be supported.

cupsRasterInterpretPPD() supports a subset of the PostScript language. Currently only the [, ], <<, >>, {, }, cleartomark, copy, dup, index, pop, roll, setpagedevice, and stopped operators are supported.

#### Syntax

`int
cupsRasterInterpretPPD( cups_page_header2_t * h, ppd_file_t * ppd, int num_options, cups_option_t * options, cups_interpret_cb_t func);`

#### Arguments

Name | Description
--- | ---
`h` | Page header
`ppd` | PPD file
`num_options` | Number of options
`options` | Options
`func` | Optional page header callback

#### Returns

0 on success, -1 on failure

### cupsRasterOpen()

#### Description

Open a raster stream.

#### Syntax

`cups_raster_t *
cupsRasterOpen( int fd, cups_mode_t mode);`

#### Arguments

Name | Description
--- | ---
`fd` | File descriptor
`mode` | Mode

#### Returns

New stream

### cupsRasterReadHeader()

#### Description

Read a raster page header and store it in a V1 page header structure.

#### Syntax

`unsigned
cupsRasterReadHeader( cups_raster_t * r, cups_page_header_t * h);`

#### Arguments

Name | Description
--- | ---
`r` | Raster stream
`h` | Pointer to header data

#### Returns

1 on success, 0 on fail

### CUPS 1.2 cupsRasterReadHeader2()

#### Description

Read a raster page header and store it in a V2 page header structure.

#### Syntax

`unsigned
cupsRasterReadHeader2( cups_raster_t * r, cups_page_header2_t * h);`

#### Arguments

Name | Description
--- | ---
`r` | Raster stream
`h` | Pointer to header data

#### Returns

1 on success, 0 on fail

### cupsRasterReadPixels()

#### Description

Read raster pixels.

#### Syntax

`unsigned
cupsRasterReadPixels( cups_raster_t * r, unsigned char * p, unsigned len);`

#### Arguments

Name | Description
--- | ---
`r` | Raster stream
`p` | Pointer to pixel buffer
`len` | Number of bytes to read

#### Returns

Number of bytes read

### cupsRasterWriteHeader()

#### Description

Write a raster page header from a V1 page header structure.

#### Syntax

`unsigned
cupsRasterWriteHeader( cups_raster_t * r, cups_page_header_t * h);`

#### Arguments

Name | Description
--- | ---
`r` | Raster stream
`h` | Raster page header

#### Returns

1 on success, 0 on failure

### CUPS 1.2 cupsRasterWriteHeader2()

#### Description

Write a raster page header from a V2 page header structure.

#### Syntax

`unsigned
cupsRasterWriteHeader2( cups_raster_t * r, cups_page_header2_t * h);`

#### Arguments

Name | Description
--- | ---
`r` | Raster stream
`h` | Raster page header

#### Returns

1 on success, 0 on failure

### cupsRasterWritePixels()

#### Description

Write raster pixels.

#### Syntax

`unsigned
cupsRasterWritePixels( cups_raster_t * r, unsigned char * p, unsigned len);`

#### Arguments

Name | Description
--- | ---
`r` | Raster stream
`p` | Bytes to write
`len` | Number of bytes to write

#### Returns

Number of bytes written

## Structures

- `cups_page_header2_s` CUPS 1.2
- `cups_page_header_s`

### CUPS 1.2 cups_page_header2_s

#### Description

Version 2 Page Header

#### Definition

`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;
};`

#### Members

Name | Description
--- | ---
`AdvanceDistance` | AdvanceDistance value in points
`AdvanceMedia` | AdvanceMedia value (see above)
`Collate` | Collated copies value
`CutMedia` | CutMedia value (see above)
`Duplex` | Duplexed (double-sided) value
`HWResolution[2]` | Resolution in dots-per-inch
`ImagingBoundingBox[4]` | Pixel region that is painted (points)
`InsertSheet` | InsertSheet value
`Jog` | Jog value (see above)
`LeadingEdge` | LeadingEdge value (see above)
`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 (see above)
`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 | 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 | Floating point ImagingBoundingBox * (scaling factor not applied)
`cupsInteger[16]` CUPS 1.2 | User-defined integer values
`cupsMarkerType[64]` CUPS 1.2 | Ink/toner type
`cupsMediaType` | Media type code
`cupsNumColors` CUPS 1.2 | Number of colors
`cupsPageSizeName[64]` CUPS 1.2 | PageSize name
`cupsPageSize[2]` CUPS 1.2 | Floating point PageSize (scaling * factor not applied)
`cupsReal[16]` CUPS 1.2 | User-defined floating-point values
`cupsRenderingIntent[64]` CUPS 1.2 | Color rendering intent
`cupsRowCount` | Rows per band
`cupsRowFeed` | Feed between bands
`cupsRowStep` | Spacing between lines
`cupsString[16][64]` CUPS 1.2 | User-defined string values
`cupsWidth` | Width of page image in pixels

### cups_page_header_s

#### Description

Version 1 Page Header

#### Definition

`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;
};`

#### Members

Name | Description
--- | ---
`AdvanceDistance` | AdvanceDistance value in points
`AdvanceMedia` | AdvanceMedia value (see above)
`Collate` | Collated copies value
`CutMedia` | CutMedia value (see above)
`Duplex` | Duplexed (double-sided) value
`HWResolution[2]` | Resolution in dots-per-inch
`ImagingBoundingBox[4]` | Pixel region that is painted (points)
`InsertSheet` | InsertSheet value
`Jog` | Jog value (see above)
`LeadingEdge` | LeadingEdge value (see above)
`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 (see above)
`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

## Types

- `cups_interpret_cb_t`
- `cups_page_header2_t` CUPS 1.2
- `cups_page_header_t`
- `cups_raster_t`

### cups_interpret_cb_t

#### Description

Prototypes...

#### Definition

`typedef int (*cups_interpret_cb_t)(cups_page_header2_t *header, int preferred_bits);`

### CUPS 1.2 cups_page_header2_t

#### Description

Version 2 Page Header

#### Definition

`typedef struct cups_page_header2_s cups_page_header2_t;`

### cups_page_header_t

#### Description

Version 1 Page Header

#### Definition

`typedef struct cups_page_header_s cups_page_header_t;`

### cups_raster_t

#### Description

Raster stream data

#### Definition

`typedef struct _cups_raster_s cups_raster_t;`