• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<!--
2  Raster API introduction for CUPS.
3
4  Copyright © 2020-2024 by OpenPrinting.
5  Copyright © 2007-2019 by Apple Inc.
6  Copyright © 1997-2006 by Easy Software Products, all rights reserved.
7
8  Licensed under Apache License v2.0.  See the file "LICENSE" for more
9  information.
10-->
11
12<h2 class='title'><a name="OVERVIEW">Overview</a></h2>
13
14<p>The CUPS raster API provides a standard interface for reading and writing
15CUPS raster streams which are used for printing to raster printers. Because the
16raster format is updated from time to time, it is important to use this API to
17avoid incompatibilities with newer versions of CUPS.</p>
18
19<p>Two kinds of CUPS filters use the CUPS raster API - raster image processor
20(RIP) filters such as <code>pstoraster</code> and <code>cgpdftoraster</code>
21(macOS) that produce CUPS raster files and printer driver filters that
22convert CUPS raster files into a format usable by the printer. Printer
23driver filters are by far the most common.</p>
24
25<p>CUPS raster files (<code>application/vnd.cups-raster</code>) consists of
26a stream of raster page descriptions produced by one of the RIP filters such as
27<var>pstoraster</var>, <var>imagetoraster</var>, or
28<var>cgpdftoraster</var>. CUPS raster files are referred to using the
29<a href='#cups_raster_t'><code>cups_raster_t</code></a> type and are
30opened using the <a href='#cupsRasterOpen'><code>cupsRasterOpen</code></a>
31function. For example, to read raster data from the standard input, open
32file descriptor 0:</p>
33
34<pre class="example">
35#include &lt;cups/raster.h&gt;
36
37<a href="#cups_raster_t">cups_raster_t</a> *ras = <a href="#cupsRasterOpen">cupsRasterOpen</a>(0, CUPS_RASTER_READ);
38</pre>
39
40<p>Each page of data begins with a page dictionary structure called
41<a href="#cups_page_header2_t"><code>cups_page_header2_t</code></a>. This
42structure contains the colorspace, bits per color, media size, media type,
43hardware resolution, and so forth used for the page.</p>
44
45<blockquote><b>Note:</b>
46
47  <p>Do not confuse the colorspace in the page header with the PPD
48  <tt>ColorModel</tt> keyword. <tt>ColorModel</tt> refers to the general type of
49  color used for a device (Gray, RGB, CMYK, DeviceN) and is often used to
50  select a particular colorspace for the page header along with the associate
51  color profile. The page header colorspace (<tt>cupsColorSpace</tt>) describes
52  both the type and organization of the color data, for example KCMY (black
53  first) instead of CMYK and RGBA (RGB + alpha) instead of RGB.</p>
54
55</blockquote>
56
57<p>You read the page header using the
58<a href="#cupsRasterReadHeader2"><code>cupsRasterReadHeader2</code></a>
59function:</p>
60
61<pre class="example">
62#include &lt;cups/raster.h&gt;
63
64<a href="#cups_raster_t">cups_raster_t</a> *ras = <a href="#cupsRasterOpen">cupsRasterOpen</a>(0, CUPS_RASTER_READ);
65<a href="#cups_page_header2_t">cups_page_header2_t</a> header;
66
67while (<a href="#cupsRasterReadHeader2">cupsRasterReadHeader2</a>(ras, &amp;header))
68{
69  /* setup this page */
70
71  /* read raster data */
72
73  /* finish this page */
74}
75</pre>
76
77<p>After the page dictionary comes the page data which is a full-resolution,
78possibly compressed bitmap representing the page in the printer's output
79colorspace. You read uncompressed raster data using the
80<a href="#cupsRasterReadPixels"><code>cupsRasterReadPixels</code></a>
81function. A <code>for</code> loop is normally used to read the page one line
82at a time:</p>
83
84<pre class="example">
85#include &lt;cups/raster.h&gt;
86
87<a href="#cups_raster_t">cups_raster_t</a> *ras = <a href="#cupsRasterOpen">cupsRasterOpen</a>(0, CUPS_RASTER_READ);
88<a href="#cups_page_header2_t">cups_page_header2_t</a> header;
89int page = 0;
90int y;
91char *buffer;
92
93while (<a href="#cupsRasterReadHeader2">cupsRasterReadHeader2</a>(ras, &amp;header))
94{
95  /* setup this page */
96  page ++;
97  fprintf(stderr, "PAGE: %d %d\n", page, header.NumCopies);
98
99  /* allocate memory for 1 line */
100  buffer = malloc(header.cupsBytesPerLine);
101
102  /* read raster data */
103  for (y = 0; y &lt; header.cupsHeight; y ++)
104  {
105    if (<a href="#cupsRasterReadPixels">cupsRasterReadPixels</a>(ras, buffer, header.cupsBytesPerLine) == 0)
106      break;
107
108    /* write raster data to printer on stdout */
109  }
110
111  /* finish this page */
112}
113</pre>
114
115<p>When you are done reading the raster data, call the
116<a href="#cupsRasterClose"><code>cupsRasterClose</code></a> function to free
117the memory used to read the raster file:</p>
118
119<pre class="example">
120<a href="#cups_raster_t">cups_raster_t</a> *ras;
121
122<a href="#cupsRasterClose">cupsRasterClose</a>(ras);
123</pre>
124
125
126<h2 class='title'><a name="TASKS">Functions by Task</a></h2>
127
128<h3><a name="OPENCLOSE">Opening and Closing Raster Streams</a></h3>
129
130<ul class="code">
131
132	<li><a href="#cupsRasterClose" title="Close a raster stream.">cupsRasterClose</a></li>
133	<li><a href="#cupsRasterOpen" title="Open a raster stream.">cupsRasterOpen</a></li>
134
135</ul>
136
137<h3><a name="READING">Reading Raster Streams</a></h3>
138
139<ul class="code">
140
141	<li><a href="#cupsRasterReadHeader" title="Read a raster page header and store it in a version 1 page header structure.">cupsRasterReadHeader</a> <span class="info">Deprecated in CUPS 1.2/macOS 10.5</span></li>
142	<li><a href="#cupsRasterReadHeader2" title="Read a raster page header and store it in a version 2 page header structure.">cupsRasterReadHeader2</a></li>
143	<li><a href="#cupsRasterReadPixels" title="Read raster pixels.">cupsRasterReadPixels</a></li>
144
145</ul>
146
147<h3><a name="WRITING">Writing Raster Streams</a></h3>
148
149<ul class="code">
150
151	<li><a href="#cupsRasterInitPWGHeader" title="Interpret IPP attributes to create a page header.">cupsRasterInitPWGHeader</a></li>
152	<li><a href="#cupsRasterWriteHeader" title="Write a raster page header from a version 1 page header structure.">cupsRasterWriteHeader</a> <span class="info">Deprecated in CUPS 1.2/macOS 10.5</span></li>
153	<li><a href="#cupsRasterWriteHeader2" title="Write a raster page header from a version 2 page header structure.">cupsRasterWriteHeader2</a></li>
154	<li><a href="#cupsRasterWritePixels" title="Write raster pixels.">cupsRasterWritePixels</a></li>
155
156</ul>
157