Documentation
¶
Index ¶
- type Decoder
- func (d *Decoder) ExtractCoefficients(data []byte) ([]int, error)
- func (d *Decoder) GetCoefficients() []int
- func (d *Decoder) GetComponentCount() int
- func (d *Decoder) GetImageDimensions() (width, height int)
- func (d *Decoder) GetQuantizationTables() map[int][64]int
- func (d *Decoder) GetSamplingFactors() (horizontal, vertical []int)
- func (d *Decoder) GetSubsampling() int
- type HuffmanDecoder
- type ImageMetadata
- type Validator
- type ValidatorImpl
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
Decoder implements JPEG coefficient extraction using the Huffman decoder.
This is a thin wrapper that: 1. Creates a ByteReader for platform-independent byte access. 2. Uses HuffmanDecoder interface for actual decoding. 3. Exposes image dimensions and component count.
func NewDecoder ¶
func NewDecoder(huffmanDecoder HuffmanDecoder, validator Validator) *Decoder
NewDecoder creates a new StandardDecoder with the given Huffman decoder and validator. Follows Dependency Inversion Principle by injecting dependencies.
func (*Decoder) ExtractCoefficients ¶
ExtractCoefficients extracts quantized DCT coefficients from JPEG data. Single Responsibility: Orchestrates extraction using Huffman decoder.
func (*Decoder) GetCoefficients ¶
GetCoefficients returns the last extracted coefficients. This allows retrieving coefficients without re-decoding.
func (*Decoder) GetComponentCount ¶
GetComponentCount returns the number of color components. Single Responsibility: Only component count retrieval.
func (*Decoder) GetImageDimensions ¶
GetImageDimensions returns the width and height of the decoded image. Single Responsibility: Only dimension retrieval.
func (*Decoder) GetQuantizationTables ¶
GetQuantizationTables returns the quantization tables from the decoded JPEG.
func (*Decoder) GetSamplingFactors ¶
GetSamplingFactors returns the per-component horizontal and vertical sampling factors, if the underlying Huffman decoder exposes them.
func (*Decoder) GetSubsampling ¶
GetSubsampling returns the chroma subsampling mode. If the decoder doesn't support subsampling detection, returns 4:2:0 as default.
type HuffmanDecoder ¶
type HuffmanDecoder interface {
// Decode extracts quantized DCT coefficients from JPEG data
Decode() ([]int, error)
// GetQuantizationTables returns the parsed quantization tables
GetQuantizationTables() map[int][64]int
}
HuffmanDecoder defines the interface for Huffman decoding. This allows dependency injection and testing with mock decoders.
type ImageMetadata ¶
type ImageMetadata interface {
// GetImageWidth returns the image width in pixels
GetImageWidth() int
// GetImageHeight returns the image height in pixels
GetImageHeight() int
// GetComponentCount returns the number of color components (1 for grayscale, 3 for YCbCr)
GetComponentCount() int
}
ImageMetadata provides image dimension and component information. This interface allows the decoder to query image properties from the Huffman decoder.
type Validator ¶
type Validator interface {
// ValidateData checks if JPEG data is valid for decoding
ValidateData(data []byte) error
// ValidateDimensions checks if image dimensions are reasonable
ValidateDimensions(width, height int) error
// ValidateComponentCount checks if component count is valid (1-4)
ValidateComponentCount(count int) error
}
Validator provides input validation for the decoder. Single Responsibility: Only validates inputs, doesn't decode data.
func NewValidator ¶
func NewValidator() Validator
NewValidator creates a new validator for StandardDecoder.
type ValidatorImpl ¶
type ValidatorImpl struct{}
ValidatorImpl implements the Validator interface for StandardDecoder.
func (*ValidatorImpl) ValidateComponentCount ¶
func (v *ValidatorImpl) ValidateComponentCount(count int) error
ValidateComponentCount checks if component count is valid (1-4).
func (*ValidatorImpl) ValidateData ¶
func (v *ValidatorImpl) ValidateData(data []byte) error
ValidateData checks if JPEG data is valid for decoding.
func (*ValidatorImpl) ValidateDimensions ¶
func (v *ValidatorImpl) ValidateDimensions(width, height int) error
ValidateDimensions checks if image dimensions are reasonable.