Documentation
¶
Index ¶
- Constants
- Variables
- type Box
- type ColourSpec
- type FileType
- type ImageHeader
- type JP2File
- type JP2Header
- type Parser
- func (p *Parser) IsJP2(data []byte) bool
- func (p *Parser) IsRawJ2K(data []byte) bool
- func (p *Parser) Parse(r io.Reader) (*JP2File, error)
- func (p *Parser) ParseBox(r io.ReadSeeker, offset int64, _ int) (*Box, error)
- func (p *Parser) ParseColourSpec(box *Box) (*ColourSpec, error)
- func (p *Parser) ParseFileType(box *Box) (*FileType, error)
- func (p *Parser) ParseImageHeader(box *Box) (*ImageHeader, error)
- func (p *Parser) ParseJP2Header(box *Box) (*JP2Header, error)
- func (p *Parser) ParseSuperboxChildren(box *Box, depth int) error
- func (p *Parser) Reset()
- func (p *Parser) ValidateSignature(data []byte) error
Constants ¶
const ( // JP2SignatureLength is the length of the JP2 file signature (12 bytes at file start) // 0x00 0x00 0x00 0x0C 0x6A 0x50 0x20 0x20 0x0D 0x0A 0x87 0x0A JP2SignatureLength = 12 // BoxTypeSignature is the JP2 signature box type identifier (4-byte ASCII code as uint32) BoxTypeSignature = 0x6A502020 // "jP " BoxTypeFileType = 0x66747970 // "ftyp" - File type box BoxTypeJP2Header = 0x6A703268 // "jp2h" - JP2 header superbox BoxTypeImageHeader = 0x69686472 // "ihdr" - Image header box BoxTypeColourSpec = 0x636F6C72 // "colr" - Colour specification box BoxTypeCodestream = 0x6A703263 // "jp2c" - Contiguous codestream box BoxTypePalette = 0x70636C72 // "pclr" - Palette box BoxTypeCompMap = 0x636D6170 // "cmap" - Component mapping box BoxTypeChanDef = 0x63646566 // "cdef" - Channel definition box BoxTypeResolution = 0x72657320 // "res " - Resolution superbox BoxTypeBPC = 0x62706363 // "bpcc" - Bits per component box BoxTypeXML = 0x786D6C20 // "xml " - XML box BoxTypeUUID = 0x75756964 // "uuid" - UUID box BoxTypeUUIDInfo = 0x75696E66 // "uinf" - UUID info box // MarkerSOC is the J2K start of codestream marker MarkerSOC = 0xFF4F MarkerSOT = 0xFF90 // Start of tile-part MarkerSOD = 0xFFD9 // Start of data MarkerEOC = 0xFFD9 // End of codestream // MaxBoxRecursionDepth is the maximum box recursion depth (safety limit) MaxBoxRecursionDepth = 16 MaxBoxLength = 1 << 30 // 1 GB max box length MaxBoxCount = 1000 // Maximum boxes to parse MaxComponentCount = 16384 // Max components per JPEG 2000 MinImageDimension = 1 MaxImageDimension = 65535 )
JP2 file format constants
const ( ColourSpaceSRGB = 16 // sRGB ColourSpaceGrey = 17 // Greyscale ColourSpaceSYCC = 18 // sYCC )
ColourSpace enumeration values
const ( BrandJP2 = 0x6A703220 // "jp2 " - JP2 format BrandJPX = 0x6A707820 // "jpx " - JPX format )
Common brand identifiers
Variables ¶
var ( ErrInvalidJP2Signature = errors.New("invalid JP2 signature") ErrInvalidBoxLength = errors.New("invalid box length") ErrUnexpectedEOF = errors.New("unexpected end of file") ErrMissingRequiredBox = errors.New("missing required box") ErrInvalidBoxType = errors.New("invalid box type") ErrRecursionDepthExceeded = errors.New("box recursion depth exceeded") ErrBoxCountExceeded = errors.New("maximum box count exceeded") ErrInvalidImageHeader = errors.New("invalid image header") ErrInvalidColourSpec = errors.New("invalid colour specification") ErrNoCodestream = errors.New("no codestream found") )
Errors
var J2KSignature = []byte{0xFF, 0x4F, 0xFF, 0x51}
J2KSignature contains the J2K codestream signature (SOC marker)
var JP2Signature = []byte{
0x00, 0x00, 0x00, 0x0C,
0x6A, 0x50, 0x20, 0x20,
0x0D, 0x0A, 0x87, 0x0A,
}
JP2Signature contains the JP2 signature bytes
Functions ¶
This section is empty.
Types ¶
type Box ¶
type Box struct {
Type uint32 // 4-byte box type
Length uint64 // Box length (including header)
Offset int64 // Offset in file
Data []byte // Box content (excluding header)
Children []*Box // Child boxes for superboxes
}
Box represents a JP2 box structure
func (*Box) TypeString ¶
TypeString returns the box type as a 4-character string
type ColourSpec ¶
type ColourSpec struct {
Method uint8 // Specification method (1=enumerated, 2=ICC profile)
Precedence uint8 // Precedence
Approx uint8 // Colourspace approximation
EnumCS uint32 // Enumerated colourspace (if method=1)
ICCProfile []byte // ICC profile data (if method=2)
}
ColourSpec contains colour specification box data
type FileType ¶
type FileType struct {
Brand uint32 // Brand identifier
MinorVersion uint32 // Minor version
Compatibility []uint32 // Compatibility list
}
FileType contains file type box data
type ImageHeader ¶
type ImageHeader struct {
Height uint32 // Image height
Width uint32 // Image width
NumComponents uint16 // Number of components
BitsPerComp uint8 // Bits per component (7-bit value)
CompressionType uint8 // Compression type (7 = wavelet)
UnknownColour uint8 // Unknown colourspace flag
IntellProp uint8 // Intellectual property flag
}
ImageHeader contains JP2 image header box data
type JP2File ¶
type JP2File struct {
Signature *Box // Signature box
FileType *FileType // File type box
Header *JP2Header // JP2 header
Codestream []byte // Raw codestream data
Boxes []*Box // All top-level boxes
IsRawJ2K bool // True if raw J2K without JP2 wrapper
}
JP2File represents a parsed JP2 file
type JP2Header ¶
type JP2Header struct {
ImageHeader *ImageHeader // Image header (ihdr)
ColourSpec *ColourSpec // Colour specification (colr)
Palette *Box // Palette box (pclr) - optional
CompMap *Box // Component mapping (cmap) - optional
ChanDef *Box // Channel definition (cdef) - optional
Resolution *Box // Resolution (res ) - optional
BPC *Box // Bits per component (bpcc) - optional
}
JP2Header contains the parsed JP2 header superbox content
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles JP2/J2K file parsing
func (*Parser) ParseColourSpec ¶
func (p *Parser) ParseColourSpec(box *Box) (*ColourSpec, error)
ParseColourSpec parses a colour specification box (colr)
func (*Parser) ParseFileType ¶
ParseFileType parses a file type box (ftyp)
func (*Parser) ParseImageHeader ¶
func (p *Parser) ParseImageHeader(box *Box) (*ImageHeader, error)
ParseImageHeader parses an image header box (ihdr)
func (*Parser) ParseJP2Header ¶
ParseJP2Header parses a JP2 header superbox
func (*Parser) ParseSuperboxChildren ¶
ParseSuperboxChildren parses child boxes within a superbox
func (*Parser) ValidateSignature ¶
ValidateSignature validates the JP2 12-byte signature