Documentation
¶
Index ¶
- Constants
- Variables
- type Builder
- func (b *Builder) Build(tileData [][]byte) ([]byte, error)
- func (b *Builder) SetComponents(numComps, bitDepth int) *Builder
- func (b *Builder) SetDecompLevels(levels int) *Builder
- func (b *Builder) SetImageSize(width, height uint32) *Builder
- func (b *Builder) SetLayers(layers int) *Builder
- func (b *Builder) SetReversible(reversible bool) *Builder
- func (b *Builder) SetTileSize(width, height uint32) *Builder
- type CODMarker
- type Codestream
- type Parser
- func (p *Parser) Parse(r io.Reader) (*Codestream, error)
- func (p *Parser) ParseCOD(r io.Reader) (*CODMarker, error)
- func (p *Parser) ParseEOC(r io.Reader) error
- func (p *Parser) ParseQCD(r io.Reader) (*QCDMarker, error)
- func (p *Parser) ParseSIZ(r io.Reader) (*SIZMarker, error)
- func (p *Parser) ParseSOC(r io.Reader) error
- func (p *Parser) ParseSOT(r io.Reader) (*SOTMarker, error)
- func (p *Parser) Reset()
- type QCDMarker
- type QCDStepSize
- type SIZComponent
- type SIZMarker
- type SOTMarker
- type TilePart
- type Writer
- func (w *Writer) Bytes() []byte
- func (w *Writer) Reset()
- func (w *Writer) WriteCOD(cod *CODMarker) error
- func (w *Writer) WriteCOM(comment string, latin1 bool)
- func (w *Writer) WriteEOC()
- func (w *Writer) WriteQCD(qcd *QCDMarker) error
- func (w *Writer) WriteSIZ(siz *SIZMarker) error
- func (w *Writer) WriteSOC()
- func (w *Writer) WriteSOD()
- func (w *Writer) WriteSOT(sot *SOTMarker) error
- func (w *Writer) WriteTileData(data []byte)
- func (w *Writer) WriteTo(writer io.Writer) (int64, error)
Constants ¶
const ( // MarkerSOC is the start of codestream marker MarkerSOC = 0xFF4F MarkerSOT = 0xFF90 // Start of tile-part MarkerSOD = 0xFF93 // Start of data MarkerEOC = 0xFFD9 // End of codestream // MarkerSIZ is the image and tile size marker MarkerSIZ = 0xFF51 // MarkerCOD is the coding style default marker MarkerCOD = 0xFF52 MarkerCOC = 0xFF53 // Coding style component MarkerRGN = 0xFF5E // Region of interest // MarkerTLM is the tile-part lengths marker MarkerTLM = 0xFF55 MarkerPLM = 0xFF57 // Packet length, main header MarkerPLT = 0xFF58 // Packet length, tile-part header MarkerPPM = 0xFF60 // Packed packet headers, main header MarkerPPT = 0xFF61 // Packed packet headers, tile-part header // MarkerSOP is the start of packet marker MarkerSOP = 0xFF91 MarkerEPH = 0xFF92 // End of packet header // MarkerCRG is the component registration marker MarkerCRG = 0xFF63 MarkerCOM = 0xFF64 // Comment // MarkerQCD is the quantization default marker MarkerQCD = 0xFF5C MarkerQCC = 0xFF5D // Quantization component // MaxTileCount is the maximum number of tiles (security limit) MaxTileCount = 65535 MaxComponentCount = 16384 MaxDecompLevels = 32 MaxCodeBlockWidth = 64 // 2^6 MaxCodeBlockHeight = 64 MaxImageDimension = 1 << 31 // 2^31 per spec )
J2K codestream marker constants
const ( ProgressionLRCP = 0 // Layer-Resolution-Component-Position ProgressionRLCP = 1 // Resolution-Layer-Component-Position ProgressionCPRL = 4 // Component-Position-Resolution-Layer )
Progression orders
const ( QuantStyleNoQuantization = 0 // No quantization QuantStyleScalarDerived = 1 // Scalar derived QuantStyleScalarExpounded = 2 // Scalar expounded )
Quantization styles
Variables ¶
var ( ErrInvalidMarker = errors.New("invalid marker") ErrInvalidMarkerLength = errors.New("invalid marker length") ErrUnexpectedEOF = errors.New("unexpected end of codestream") ErrMissingSOC = errors.New("missing SOC marker") ErrMissingSIZ = errors.New("missing SIZ marker") ErrInvalidSIZ = errors.New("invalid SIZ marker") ErrInvalidCOD = errors.New("invalid COD marker") ErrInvalidQCD = errors.New("invalid QCD marker") ErrInvalidSOT = errors.New("invalid SOT marker") ErrTooManyTiles = errors.New("too many tiles") ErrTooManyComponents = errors.New("too many components") ErrTooManyDecompLevels = errors.New("too many decomposition levels") ErrInvalidDimensions = errors.New("invalid dimensions") ErrInvalidProgressOrder = errors.New("invalid progression order") ErrInvalidQuantStyle = errors.New("invalid quantization style") )
Errors
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// Image parameters
Width uint32
Height uint32
NumComps int
BitDepth int
TileWidth uint32
TileHeight uint32
// Coding parameters
DecompLevels int
NumLayers int
ProgressOrder int
CodeBlockWidth int
CodeBlockHeight int
Reversible bool // true = 5/3 wavelet, false = 9/7 wavelet
// contains filtered or unexported fields
}
Builder builds a complete JPEG 2000 codestream
func (*Builder) SetComponents ¶
SetComponents sets the number of components and bit depth
func (*Builder) SetDecompLevels ¶
SetDecompLevels sets the number of decomposition levels
func (*Builder) SetImageSize ¶
SetImageSize sets the image dimensions
func (*Builder) SetReversible ¶
SetReversible sets whether to use reversible (lossless) wavelet
func (*Builder) SetTileSize ¶
SetTileSize sets the tile dimensions
type CODMarker ¶
type CODMarker struct {
Scod uint8 // Coding style flags
ProgressionOrder uint8 // Progression order
NumLayers uint16 // Number of layers
MCT uint8 // Multiple component transform
NumDecompLevels uint8 // Number of decomposition levels
CodeBlockWidth uint8 // Code-block width exponent (offset by 2)
CodeBlockHeight uint8 // Code-block height exponent (offset by 2)
CodeBlockStyle uint8 // Code-block coding style
Transform uint8 // Wavelet transform (0=9/7 irreversible, 1=5/3 reversible)
PrecinctSizes []uint8 // Precinct sizes per resolution level (if Scod bit 0 set)
}
CODMarker contains coding style default parameters
func (*CODMarker) ActualCodeBlockHeight ¶
ActualCodeBlockHeight returns the actual code-block height
func (*CODMarker) ActualCodeBlockWidth ¶
ActualCodeBlockWidth returns the actual code-block width
func (*CODMarker) IsReversible ¶
IsReversible returns true if using reversible 5/3 wavelet
func (*CODMarker) UsesPrecincts ¶
UsesPrecincts returns true if precincts are used
type Codestream ¶
type Codestream struct {
SIZ *SIZMarker // Image and tile size
COD *CODMarker // Coding style default
QCD *QCDMarker // Quantization default
TileParts []*TilePart // Tile parts
Comments []string // Comment markers
}
Codestream represents a parsed J2K codestream
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles J2K codestream parsing
func (*Parser) Parse ¶
func (p *Parser) Parse(r io.Reader) (*Codestream, error)
Parse parses a complete J2K codestream
type QCDMarker ¶
type QCDMarker struct {
Sqcd uint8 // Quantization style and guard bits
SPqcd []QCDStepSize // Step sizes per subband
}
QCDMarker contains quantization default parameters
func (*QCDMarker) QuantStyle ¶
QuantStyle returns the quantization style
type QCDStepSize ¶
type QCDStepSize struct {
Exponent uint8 // Exponent (5 bits)
Mantissa uint16 // Mantissa (11 bits for scalar expounded, 0 for others)
}
QCDStepSize contains quantization step size
type SIZComponent ¶
type SIZComponent struct {
SSiz uint8 // Component bit depth (sign bit + depth-1)
XRSiz uint8 // Horizontal subsampling
YRSiz uint8 // Vertical subsampling
}
SIZComponent contains per-component SIZ parameters
func (*SIZComponent) Depth ¶
func (c *SIZComponent) Depth() int
Depth returns the bit depth for this component
func (*SIZComponent) Signed ¶
func (c *SIZComponent) Signed() bool
Signed returns true if this component is signed
type SIZMarker ¶
type SIZMarker struct {
Rsiz uint16 // Capabilities required
XSiz uint32 // Width of reference grid
YSiz uint32 // Height of reference grid
XOSiz uint32 // Horizontal offset from grid origin to image origin
YOSiz uint32 // Vertical offset from grid origin to image origin
XTSiz uint32 // Width of one tile
YTSiz uint32 // Height of one tile
XTOSiz uint32 // Horizontal offset from grid origin to first tile
YTOSiz uint32 // Vertical offset from grid origin to first tile
CSiz uint16 // Number of components
Components []SIZComponent // Per-component parameters
}
SIZMarker contains image and tile size information
func (*SIZMarker) ImageHeight ¶
ImageHeight returns the actual image height
func (*SIZMarker) ImageWidth ¶
ImageWidth returns the actual image width
type SOTMarker ¶
type SOTMarker struct {
Isot uint16 // Tile index
Psot uint32 // Length of tile-part
TPsot uint8 // Tile-part index
TNsot uint8 // Number of tile-parts
}
SOTMarker contains start of tile-part parameters
type TilePart ¶
type TilePart struct {
TileIndex uint16 // Tile index
PartIndex uint8 // Tile-part index
NumParts uint8 // Number of tile-parts (0 = unknown)
Length uint32 // Length of tile-part
DataOffset int64 // Offset of tile-part data in stream
Data []byte // Tile-part data (after SOD)
}
TilePart represents a tile-part in the codestream
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer writes JPEG 2000 codestream markers
func (*Writer) WriteTileData ¶
WriteTileData writes raw tile data