standard

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: 1 Imported by: 0

Documentation

Index

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

func (d *Decoder) ExtractCoefficients(data []byte) ([]int, error)

ExtractCoefficients extracts quantized DCT coefficients from JPEG data. Single Responsibility: Orchestrates extraction using Huffman decoder.

func (*Decoder) GetCoefficients

func (d *Decoder) GetCoefficients() []int

GetCoefficients returns the last extracted coefficients. This allows retrieving coefficients without re-decoding.

func (*Decoder) GetComponentCount

func (d *Decoder) GetComponentCount() int

GetComponentCount returns the number of color components. Single Responsibility: Only component count retrieval.

func (*Decoder) GetImageDimensions

func (d *Decoder) GetImageDimensions() (width, height int)

GetImageDimensions returns the width and height of the decoded image. Single Responsibility: Only dimension retrieval.

func (*Decoder) GetQuantizationTables

func (d *Decoder) GetQuantizationTables() map[int][64]int

GetQuantizationTables returns the quantization tables from the decoded JPEG.

func (*Decoder) GetSamplingFactors

func (d *Decoder) GetSamplingFactors() (horizontal, vertical []int)

GetSamplingFactors returns the per-component horizontal and vertical sampling factors, if the underlying Huffman decoder exposes them.

func (*Decoder) GetSubsampling

func (d *Decoder) GetSubsampling() int

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.

Jump to

Keyboard shortcuts

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