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