Documentation ¶
Overview ¶
Package raster implements a decoder for the CUPS raster format. It provides functions for decoding a CUPS raster stream line-wise or page-wise.
For a list of currently supported color spaces and bit depths, see the documentation of Page.ParseColors.
Index ¶
- Constants
- Variables
- type BoundingBox
- type CUPSBoundingBox
- type CUPSHeader
- type Decoder
- type Header
- type Page
- func (p *Page) LineSize() int
- func (p *Page) ParseColors(b []byte) ([]color.Color, error)
- func (p *Page) ReadAll(b []byte) error
- func (p *Page) ReadAllColors(b []byte) ([]color.Color, error)
- func (p *Page) ReadLine(b []byte) error
- func (p *Page) ReadLineColors(b []byte) ([]color.Color, error)
- func (p *Page) Size() int
- func (p *Page) UnreadLines() int
Constants ¶
const ( AdvanceNever = 0 AdvanceAfterFile = 1 AdvanceAfterJob = 2 AdvanceAfterSet = 3 AdvanceAfterPage = 4 )
const ( CutNever = 0 CutAfterFile = 1 CutAfterJob = 2 CutAfterSet = 3 CutAfterPage = 4 )
const ( JogNever = 0 JogAfterFile = 1 JogAfterJob = 2 JogAfterSet = 3 )
const ( EdgeTop = 0 EdgeRight = 1 EdgeBottom = 2 EdgeLeft = 3 )
const ( RotateNone = 0 RotateCounterClockwise = 1 RotateUpsideDown = 2 RotateClockwise = 3 )
const ( ChunkyPixels = 0 BandedPixels = 1 PlanarPixels = 2 )
const ( ColorSpaceGray = 0 ColorSpaceRGB = 1 ColorSpaceRGBA = 2 ColorSpaceBlack = 3 ColorSpaceCMY = 4 ColorSpaceYMC = 5 ColorSpaceCMYK = 6 ColorSpaceYMCK = 7 ColorSpaceKCMY = 8 ColorSpaceKCMYcm = 9 ColorSpaceGMCK = 10 ColorSpaceGMCS = 11 ColorSpaceWHITE = 12 ColorSpaceGOLD = 13 ColorSpaceSILVER = 14 ColorSpaceCIEXYZ = 15 ColorSpaceCIELab = 16 ColorSpaceRGBW = 17 ColorSpacesGray = 18 ColorSpacesRGB = 19 ColorSpaceAdobeRGB = 20 ColorSpaceICC1 = 32 ColorSpaceICC2 = 33 ColorSpaceICC3 = 34 ColorSpaceICC4 = 35 ColorSpaceICC5 = 36 ColorSpaceICC6 = 37 ColorSpaceICC7 = 38 ColorSpaceICC8 = 39 ColorSpaceICC9 = 40 ColorSpaceICCA = 41 ColorSpaceICCB = 42 ColorSpaceICCC = 43 ColorSpaceICCD = 44 ColorSpaceICCE = 45 ColorSpaceICCF = 46 ColorSpaceDevice1 = 48 ColorSpaceDevice2 = 49 ColorSpaceDevice3 = 50 ColorSpaceDevice4 = 51 ColorSpaceDevice5 = 52 ColorSpaceDevice6 = 53 ColorSpaceDevice7 = 54 ColorSpaceDevice8 = 55 ColorSpaceDevice9 = 56 ColorSpaceDeviceA = 57 ColorSpaceDeviceB = 58 ColorSpaceDeviceC = 59 ColorSpaceDeviceD = 60 ColorSpaceDeviceE = 61 ColorSpaceDeviceF = 62 )
Variables ¶
var ( // ErrUnknownVersion is returned when encountering an unknown // magic byte sequence. It is indicative of input in a newer // format, or input that isn't a CUPS raster stream at all. ErrUnknownVersion = errors.New("unsupported file format or version") // ErrUnsupported is returned when encountering an unsupported // feature. This includes unsupported color spaces, color // orderings or bit depths. ErrUnsupported = errors.New("unsupported feature") // ErrBufferTooSmall is returned from ReadLine and ReadAll when // the buffer is smaller than Page.LineSize or Page.Size // respectively. ErrBufferTooSmall = errors.New("buffer too small") // ErrInvalidFormat is returned when encountering values that // aren't possible in the supported versions of the format. ErrInvalidFormat = errors.New("error in the format") )
Functions ¶
This section is empty.
Types ¶
type CUPSBoundingBox ¶
type CUPSHeader ¶
type CUPSHeader struct { // v1 Width int Height int MediaType int BitsPerColor int BitsPerPixel int BytesPerLine int ColorOrder int ColorSpace int Compression int RowCount int RowFeed int RowStep int // v2, v3 NumColors int BorderlessScalingFactor float32 PageSize [2]float32 ImagingBBox CUPSBoundingBox Integer [16]int Real [16]float32 String [16]string MarkerType string RenderingIntent string PageSizeName string }
type Header ¶
type Header struct { MediaClass string MediaColor string MediaType string OutputType string AdvanceDistance int AdvanceMedia int Collate bool CutMedia int Duplex bool HorizDPI int VertDPI int BoundingBox BoundingBox InsertSheet bool Jog int LeadingEdge int MarginLeft int MarginBottom int ManualFeed bool MediaPosition int MediaWeight int MirrorPrint bool NegativePrint bool NumCopies int Orientation int OutputFaceUp bool Width int Length int Separations bool TraySwitch bool Tumble bool CUPS CUPSHeader }
type Page ¶
type Page struct { Header *Header // contains filtered or unexported fields }
func (*Page) ParseColors ¶
ParseColors parses b and returns the colors stored in it, one per pixel.
It currently supports the following color spaces and bit depths, although more might be added later:
- 1-bit, ColorSpaceBlack -> color.Gray
- 8-bit, ColorSpaceBlack -> color.Gray
- 8-bit, ColorSpaceCMYK -> color.CMYK
Note that b might contain data for more colors than are actually present. This happens when data is stored with less than 8 bits per pixel. A page with 633 pixels per line would necessarily contain data for 640 pixels, as pixels 633-640 are stored in the same byte. When parsing ReadLine data, make sure to truncate the returned slice to the length of a single line. When parsing ReadAll data, the stride with which the resulting slice of colors is accessed has to be rounded up. Alternatively, ReadLineColors and ReadAllColors may be used, which return slices of colors and truncate them as needed.
func (*Page) ReadAll ¶
ReadAll reads the entire page into b. If ReadLine has been called previously, ReadAll will read the remainder of the page. It returns io.EOF if the entire page has been read already.
func (*Page) ReadAllColors ¶
ReadAllColors reads the page and returns the color for each pixel. Unlike using ReadAll and ParseColors, this function will not return more values than there are pixels in a page. b is used as scratch space and must be at least p.Header.CUPSBytesPerLine bytes large.
func (*Page) ReadLine ¶
ReadLine returns the next line of pixels in the image. It returns io.EOF if no more lines can be read. The buffer b must be at least p.Header.CUPSBytesPerLine bytes large.
func (*Page) ReadLineColors ¶
ReadLineColors reads a line and returns the color for each pixel. Unlike using ReadLine and ParseColors, this function will not return more values than there are pixels in a line. b is used as scratch space and must be at least p.Header.CUPSBytesPerLine bytes large.
func (*Page) UnreadLines ¶
UnreadLines returns the number of unread lines in the page.