jp2

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 30, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BoxTypeSignature   = 0x6A502020 // 'jP  ' - JP2 Signature
	BoxTypeFileType    = 0x66747970 // 'ftyp' - File Type
	BoxTypeJP2Header   = 0x6A703268 // 'jp2h' - JP2 Header
	BoxTypeImageHeader = 0x69686472 // 'ihdr' - Image Header
	BoxTypeColourSpec  = 0x636F6C72 // 'colr' - Colour Specification
	BoxTypeCodestream  = 0x6A703263 // 'jp2c' - Contiguous Codestream
)

JP2 box types

View Source
const (
	ColourMethodEnumCS        = 1 // Enumerated Colourspace
	ColourMethodRestrictedICC = 2 // Restricted ICC Profile
)

Colour specification method

View Source
const (
	ColourSpaceUnknown = 0
	ColourSpaceSRGB    = 16 // sRGB
	ColourSpaceGray    = 17 // Greyscale
	ColourSpaceSYCC    = 18 // sYCC (YCbCr)
)

Enumerated colourspaces

Variables

View Source
var (
	ErrInvalidSignature  = errors.New("invalid JP2 signature")
	ErrMissingHeader     = errors.New("missing JP2 header")
	ErrInvalidBox        = errors.New("invalid box structure")
	ErrMissingCodestream = errors.New("missing codestream")
)

Errors

View Source
var BrandJP2 = [4]byte{'j', 'p', '2', ' '}

BrandJP2 is the JP2 file type brand identifier.

View Source
var Signature = [4]byte{0x0D, 0x0A, 0x87, 0x0A}

Signature contains the signature box contents for JP2 files

Functions

This section is empty.

Types

type Box

type Box struct {
	Type     uint32
	Data     []byte
	Children []*Box // For superboxes like jp2h
}

Box represents a JP2 box structure

type Builder

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

Builder builds a complete JP2 file

func NewBuilder

func NewBuilder() *Builder

NewBuilder creates a new JP2 builder

func (*Builder) Build

func (b *Builder) Build(codestream []byte) ([]byte, error)

Build creates the JP2 file with the given codestream

func (*Builder) SetBitDepth

func (b *Builder) SetBitDepth(bpc uint8, signed bool) *Builder

SetBitDepth sets the bits per component

func (*Builder) SetColourSpace

func (b *Builder) SetColourSpace(cs int) *Builder

SetColourSpace sets the colour space

func (*Builder) SetComponents

func (b *Builder) SetComponents(numComps uint16) *Builder

SetComponents sets the number of components

func (*Builder) SetImageSize

func (b *Builder) SetImageSize(width, height uint32) *Builder

SetImageSize sets the image dimensions

type ImageInfo

type ImageInfo struct {
	Width       uint32
	Height      uint32
	NumComps    uint16
	BitsPerComp uint8
	Signed      bool
	ColourSpace int
}

ImageInfo contains image information for JP2 header

type Reader

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

Reader reads JP2 container format

func NewReader

func NewReader(data []byte) *Reader

NewReader creates a new JP2 reader

func (*Reader) ExtractCodestream

func (r *Reader) ExtractCodestream() ([]byte, error)

ExtractCodestream extracts the codestream from the JP2 file

func (*Reader) GetImageInfo

func (r *Reader) GetImageInfo() (*ImageInfo, error)

GetImageInfo extracts image information from the JP2 header

func (*Reader) ReadBox

func (r *Reader) ReadBox() (*Box, error)

ReadBox reads the next box from the stream

func (*Reader) Verify

func (r *Reader) Verify() error

Verify verifies that data is a valid JP2 file

type Writer

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

Writer writes JP2 container format

func NewWriter

func NewWriter() *Writer

NewWriter creates a new JP2 writer

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns the written data

func (*Writer) Reset

func (w *Writer) Reset()

Reset resets the writer for reuse

func (*Writer) WriteBox

func (w *Writer) WriteBox(boxType uint32, data []byte)

WriteBox writes a generic box

func (*Writer) WriteJP2

func (w *Writer) WriteJP2(info *ImageInfo, codestream []byte) error

WriteJP2 writes a complete JP2 file with the given image info and codestream

func (*Writer) WriteTo

func (w *Writer) WriteTo(writer io.Writer) (int64, error)

WriteTo writes to an io.Writer

Jump to

Keyboard shortcuts

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