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