Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:CUPS raster

From ReverseEngineering.wiki
Format
Magic "RaS3", "RaSt", "RaS2" (or reversed 3SaR, tSaR, 2SaR); "UNIRAST\0" for URF
Extensions .ras, .pwg, .urf
Endianness Native-endian CUPS streams (reversed sync word marks the other order); PWG and URF are big endian
On this wiki Facts · Code · Notes · Topics

CUPS raster streams (sync word RaS3, RaSt, RaS2 or their byte-reversed forms) and the two related page-raster formats PWG Raster (RaS2 with a PwgRaster header, always big endian) and Apple URF (UNIRAST); all are page headers followed by uncompressed or PackBits-style compressed pixel rows, produced by CUPS filters and consumed by raster printer drivers.

Overview

The stream starts with a 4-byte sync word, then for each page a page header followed by the pixel rows. CUPS writes the sync word in the writer's native byte order, so a reader recognises the byte-swapped variant (reversed ASCII) and swaps every 32-bit header word. See Fact:CUPS raster/enum/Raster sync words.

Sync (ASCII) Constant Meaning
RaS3 CUPS_RASTER_SYNC version 3, uncompressed
RaSt CUPS_RASTER_SYNCv1 version 1 header, uncompressed
RaS2 CUPS_RASTER_SYNCv2 version 2, compressed rows
UNIR CUPS_RASTER_SYNCapple Apple raster, followed by AST and NUL

The reader treats RaS2 and UNIR streams as compressed; PWG Raster uses the RaS2 sync word (CUPS_RASTER_SYNC_PWG is defined as the v2 value).

Page header (v2)

Pages in RaS3 and RaS2 streams use cups_page_header2_t: four 64-byte strings (MediaClass, MediaColor, MediaType, OutputType), 29 32-bit integer fields of the PostScript page device dictionary (AdvanceDistance ... Tumble), 12 CUPS fields (cupsWidth, cupsHeight, cupsMediaType, cupsBitsPerColor, cupsBitsPerPixel, cupsBytesPerLine, cupsColorOrder, cupsColorSpace, cupsCompression, cupsRowCount, cupsRowFeed, cupsRowStep), then the version 2 additions (cupsNumColors, cupsBorderlessScalingFactor, cupsPageSize[2], cupsImagingBBox[4], cupsInteger[16], cupsReal[16], cupsString[16][64], cupsMarkerType, cupsRenderingIntent, cupsPageSizeName). Adding the field sizes gives 1796 bytes. See Fact:CUPS raster/struct/cups_page_header2_t. The v1 header (RaSt) stops after cupsRowStep (420 bytes by the same arithmetic).

When the stream is byte swapped, the reader swaps the 81 integer and float words that start at AdvanceDistance (offset 256); the strings are not swapped.

PWG Raster

PWG Raster is RaS2 with big-endian words and the page header mostly zeroed. The writer sets MediaClass to the string PwgRaster and fills only media strings, rendering intent, page size name and the geometry fields; the extra PWG fields live in cupsInteger[0..8, 14, 15] (TotalPageCount, CrossFeedTransform, FeedTransform, ImageBox Left/Top/Right/Bottom, AlternatePrimary, PrintQuality, VendorIdentifier, VendorLength). A PwgRaster string at offset 4 (after the sync word) identifies it. See Fact:CUPS raster/identification/PWG Raster stream.

Apple raster (URF)

Stream header: sync UNIR, then 8 bytes A S T 00 plus a big-endian page count (so the file starts UNIRAST\0). Each page then has a 32-byte big-endian header: bits per pixel, a color space code, duplex mode, print quality, media type, media position, width, height and resolution. See Fact:CUPS raster/struct/Apple URF page header.

Pixel data

Unverified: compressed rows (RaS2, PWG, URF) use a PackBits-like scheme with a repeat count byte per line group; read cups_raster_read_pixels in raster-stream.c before implementing a decoder.

Code & repositories

The reader and writer are in OpenPrinting/cups cups/raster-stream.c with the structures in cups/raster.h; libcupsfilters (cupsfilters/ghostscript.c) writes RaS2 streams.

  • https://github.com/OpenPrinting/cups @ cf2fc5c9390264e4cc0c0d02abdde1a18218b07e · license: Apache-2.0
    CUPS: cups/raster.h (headers, sync words, colorspaces) and cups/raster-stream.c (reader and writer for CUPS, PWG and Apple raster)
    Tested on: source read, not run: source reading only · checked 2026-10-19; last activity 2026-10-18
  • https://github.com/OpenPrinting/libcupsfilters @ d49e92848060d6d9d2e95679a115a8da5102f1de · license: Apache-2.0
    libcupsfilters: filter functions producing and consuming raster (ghostscript.c writes RaS2, pwgtoraster.c, pclmtoraster.c)
    Tested on: source read, not run: source reading only · checked 2026-10-19; last activity 2026-10-13