raster

package
v0.0.0-...-1504d7f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 11, 2016 License: MIT Imports: 5 Imported by: 0

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

View Source
const (
	AdvanceNever     = 0
	AdvanceAfterFile = 1
	AdvanceAfterJob  = 2
	AdvanceAfterSet  = 3
	AdvanceAfterPage = 4
)
View Source
const (
	CutNever     = 0
	CutAfterFile = 1
	CutAfterJob  = 2
	CutAfterSet  = 3
	CutAfterPage = 4
)
View Source
const (
	JogNever     = 0
	JogAfterFile = 1
	JogAfterJob  = 2
	JogAfterSet  = 3
)
View Source
const (
	EdgeTop    = 0
	EdgeRight  = 1
	EdgeBottom = 2
	EdgeLeft   = 3
)
View Source
const (
	RotateNone             = 0
	RotateCounterClockwise = 1
	RotateUpsideDown       = 2
	RotateClockwise        = 3
)
View Source
const (
	ChunkyPixels = 0
	BandedPixels = 1
	PlanarPixels = 2
)
View Source
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

View Source
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 BoundingBox

type BoundingBox struct {
	Left   int
	Bottom int
	Right  int
	Top    int
}

type CUPSBoundingBox

type CUPSBoundingBox struct {
	Left   float32
	Bottom float32
	Right  float32
	Top    float32
}

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 Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader) (*Decoder, error)

func (*Decoder) NextPage

func (d *Decoder) NextPage() (*Page, error)

NextPage returns the next page in the raster stream. After a call to NextPage, all previously returned pages from this decoder cannot be used to decode image data anymore. Their header data, however, remains valid.

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) LineSize

func (p *Page) LineSize() int

LineSize returns the size of a single line, in bytes.

func (*Page) ParseColors

func (p *Page) ParseColors(b []byte) ([]color.Color, error)

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

func (p *Page) ReadAll(b []byte) error

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

func (p *Page) ReadAllColors(b []byte) ([]color.Color, error)

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

func (p *Page) ReadLine(b []byte) error

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

func (p *Page) ReadLineColors(b []byte) ([]color.Color, error)

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) Size

func (p *Page) Size() int

Size returns the size of the unread portion of the page, in bytes.

func (*Page) UnreadLines

func (p *Page) UnreadLines() int

UnreadLines returns the number of unread lines in the page.

Directories

Path Synopsis
cmd
Package image allows using CUPS raster pages in combination with image.Image.
Package image allows using CUPS raster pages in combination with image.Image.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL