Documentation
¶
Index ¶
- Constants
- func SOFTypeName(sofType int) string
- type ByteReader
- type Decoder
- func (d *Decoder) Decode() ([]int, error)
- func (d *Decoder) GetComponentCount() int
- func (d *Decoder) GetImageHeight() int
- func (d *Decoder) GetImageWidth() int
- func (d *Decoder) GetPrecision() int
- func (d *Decoder) GetQuantTableIDs() []int
- func (d *Decoder) GetQuantizationTables() map[int][64]int
- func (d *Decoder) GetSOFType() int
- func (d *Decoder) GetSamplingFactors() (horizontal, vertical []int)
- func (d *Decoder) GetSpectralSelection() (ss, se int)
- func (d *Decoder) GetSuccessiveApproximation() (ah, al int)
- func (d *Decoder) IsDifferential() bool
- func (d *Decoder) IsLossless() bool
- func (d *Decoder) IsProgressive() bool
- type Table
- type Validator
- type ValidatorAdapter
- func (v *ValidatorAdapter) ValidateArrayIndex(index int, arrayLength int) error
- func (v *ValidatorAdapter) ValidateBitCount(bits int) error
- func (v *ValidatorAdapter) ValidateCoefficientIndex(k int) error
- func (v *ValidatorAdapter) ValidateSliceAccess(slice []int, index int) error
- func (v *ValidatorAdapter) ValidateTableIndex(tableIdx int) error
Constants ¶
const ( SOFUnknown = 0 // Unknown or not yet parsed SOF0BaselineDCT = 192 // Baseline DCT SOF1ExtendedSequentialDCT = 193 // Extended Sequential DCT SOF2ProgressiveDCT = 194 // Progressive DCT SOF3LosslessSequential = 195 // Lossless Sequential SOF5DifferentialSequentialDCT = 197 // Differential Sequential DCT SOF6DifferentialProgressiveDCT = 198 // Differential Progressive DCT SOF7DifferentialLossless = 199 // Differential Lossless SOF9ArithmeticSequentialDCT = 201 // Arithmetic Sequential DCT SOF10ArithmeticProgressiveDCT = 202 // Arithmetic Progressive DCT SOF11ArithmeticLossless = 203 // Arithmetic Lossless SOF13DiffArithmeticSequentialDCT = 205 // Differential Arithmetic Sequential DCT SOF14DiffArithmeticProgressiveDCT = 206 // Differential Arithmetic Progressive DCT SOF15DiffArithmeticLossless = 207 // Differential Arithmetic Lossless )
SOF marker type constants for decoder routing
Variables ¶
This section is empty.
Functions ¶
func SOFTypeName ¶
SOFTypeName returns a human-readable name for an SOF marker type.
Types ¶
type ByteReader ¶
type ByteReader interface {
// ReadByte reads and returns the next byte.
ReadByte() (byte, error)
// Remaining returns the number of unread bytes.
Remaining() int
}
ByteReader defines an interface for reading bytes with position tracking. This abstraction allows the decoder to work with any byte source.
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder performs Huffman decoding of JPEG entropy-coded data to extract DCT coefficients. This structure is optimized for memory alignment (largest to smallest).
func NewDecoder ¶
func NewDecoder(_ []byte, reader ByteReader, validator Validator) *Decoder
NewDecoder creates a new Huffman decoder with the given validator. Follows Dependency Inversion Principle by injecting validator.
func NewDecoderForSOF ¶
func NewDecoderForSOF(sofType int, data []byte, reader ByteReader, validator Validator) (*Decoder, error)
NewDecoderForSOF creates a decoder appropriate for the given SOF marker type. Returns the decoder and an error if the SOF type is not supported. This factory function maintains backward compatibility while enabling routing to specialized decoders for different JPEG encoding modes.
func (*Decoder) Decode ¶
Decode extracts DCT coefficients from the JPEG data. Returns array of quantized DCT coefficients or error. For progressive JPEG (SOF2), this decodes all scans and returns accumulated coefficients. For lossless JPEG (SOF3), this returns raw pixel values (not DCT coefficients). For differential JPEG (SOF5-7, SOF13-15), this decodes differential values.
func (*Decoder) GetComponentCount ¶
GetComponentCount returns the number of color components.
func (*Decoder) GetImageHeight ¶
GetImageHeight returns the image height in pixels.
func (*Decoder) GetImageWidth ¶
GetImageWidth returns the image width in pixels.
func (*Decoder) GetPrecision ¶
GetPrecision returns the sample precision in bits.
func (*Decoder) GetQuantTableIDs ¶
GetQuantTableIDs returns the quantization table ID for each component. Returns a slice where index 0=Y, 1=Cb, 2=Cr.
func (*Decoder) GetQuantizationTables ¶
GetQuantizationTables returns all quantization tables.
func (*Decoder) GetSOFType ¶
GetSOFType returns the detected SOF marker type. Returns 0 (SOFUnknown) if no SOF marker has been parsed yet.
func (*Decoder) GetSamplingFactors ¶
GetSamplingFactors returns the horizontal and vertical sampling factors for each component. Returns two slices: horizontal and vertical factors, indexed by component (0=Y, 1=Cb, 2=Cr). For 4:2:0: Y=(2,2), Cb=(1,1), Cr=(1,1) For 4:2:2: Y=(2,1), Cb=(1,1), Cr=(1,1) For 4:4:4: Y=(1,1), Cb=(1,1), Cr=(1,1)
func (*Decoder) GetSpectralSelection ¶
GetSpectralSelection returns the spectral selection parameters (Ss, Se). Only meaningful for progressive JPEG (SOF2).
func (*Decoder) GetSuccessiveApproximation ¶
GetSuccessiveApproximation returns the successive approximation parameters (Ah, Al). Only meaningful for progressive JPEG (SOF2).
func (*Decoder) IsDifferential ¶
IsDifferential returns true if the image uses differential encoding (SOF5-7, SOF13-15).
func (*Decoder) IsLossless ¶
IsLossless returns true if the image uses lossless encoding (SOF3).
func (*Decoder) IsProgressive ¶
IsProgressive returns true if the image uses progressive DCT encoding (SOF2).
type Table ¶
type Table struct {
// contains filtered or unexported fields
}
Table represents a Huffman table for JPEG decoding. This structure follows the JPEG/JFIF specification for Huffman table construction.
func NewTable ¶
func NewTable(reader ByteReader) *Table
NewTable creates a new Huffman table from a byte reader. The reader parameter provides abstracted byte reading.
func (*Table) GetHuffval ¶
GetHuffval returns the HUFFVAL array.
func (*Table) GetMaxcode ¶
GetMaxcode returns the MAXCODE array.
func (*Table) GetMincode ¶
GetMincode returns the MINCODE array.
type Validator ¶
type Validator interface {
// ValidateArrayIndex checks if an array index is within bounds
ValidateArrayIndex(index int, arrayLength int) error
// ValidateSliceAccess checks if a slice access is safe
ValidateSliceAccess(slice []int, index int) error
// ValidateTableIndex checks if a Huffman table index is valid
ValidateTableIndex(tableIdx int) error
// ValidateBitCount checks if bit count is within valid range (0-16)
ValidateBitCount(bits int) error
// ValidateCoefficientIndex checks if coefficient index is valid (0-63)
ValidateCoefficientIndex(k int) error
}
Validator provides input validation and bounds checking. Single Responsibility: Only validates inputs, doesn't decode data.
type ValidatorAdapter ¶
type ValidatorAdapter struct {
// contains filtered or unexported fields
}
ValidatorAdapter adapts the parent package Validator to the huffman-specific Validator interface. This follows the Adapter pattern and Dependency Inversion Principle.
func NewValidatorAdapter ¶
func NewValidatorAdapter(parentValidator interface {
ValidatePosition(pos int, maxPos int) error
},
) *ValidatorAdapter
NewValidatorAdapter creates a new validator adapter.
func (*ValidatorAdapter) ValidateArrayIndex ¶
func (v *ValidatorAdapter) ValidateArrayIndex(index int, arrayLength int) error
ValidateArrayIndex checks if an array index is within bounds.
func (*ValidatorAdapter) ValidateBitCount ¶
func (v *ValidatorAdapter) ValidateBitCount(bits int) error
ValidateBitCount checks if bit count is within valid range (0-16).
func (*ValidatorAdapter) ValidateCoefficientIndex ¶
func (v *ValidatorAdapter) ValidateCoefficientIndex(k int) error
ValidateCoefficientIndex checks if coefficient index is valid (0-63).
func (*ValidatorAdapter) ValidateSliceAccess ¶
func (v *ValidatorAdapter) ValidateSliceAccess(slice []int, index int) error
ValidateSliceAccess checks if a slice access is safe.
func (*ValidatorAdapter) ValidateTableIndex ¶
func (v *ValidatorAdapter) ValidateTableIndex(tableIdx int) error
ValidateTableIndex checks if a Huffman table index is valid (0-3).