jpwl

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

Overview

Package jpwl implements JPEG 2000 Part 11 (JPWL) wireless transmission support as specified in ISO/IEC 15444-11.

JPWL (JPEG 2000 Wireless) provides tools for robust transmission of JPEG 2000 images over error-prone channels, such as wireless networks. It includes forward error correction (FEC) and error detection mechanisms.

Architecture

JPWL extends the standard JPEG 2000 codestream with error protection:

  • EPC (Error Protection Capability): Describes available protection
  • EPB (Error Protection Block): Contains FEC parity data
  • ESD (Error Sensitivity Descriptor): Describes data sensitivity
  • RED (Residual Error Descriptor): Marks uncorrectable errors

Error Protection

JPWL uses Reed-Solomon codes for forward error correction. The EPC marker describes the protection scheme, and EPB markers contain the parity data needed to correct errors.

Error Detection

Even when errors cannot be corrected, JPWL can detect their presence and location. This allows decoders to apply graceful degradation strategies rather than failing completely.

Usage

The JPWL parser integrates with the main JPEG 2000 decoder. When error protection markers are detected, the parser extracts protection metadata and optionally applies error correction.

Security

All operations validate input bounds and use safe integer conversions from the internal/safeconv package. The parser enforces security limits to prevent denial-of-service attacks.

References

  • ISO/IEC 15444-11:2007 - JPEG 2000 image coding system: Wireless
  • ITU-T Rec. T.810 (2007)

Index

Constants

View Source
const (
	// MarkerEPC is the Error Protection Capability marker (0xFF68).
	MarkerEPC uint16 = 0xFF68

	// MarkerEPB is the Error Protection Block marker (0xFF66).
	MarkerEPB uint16 = 0xFF66

	// MarkerESD is the Error Sensitivity Descriptor marker (0xFF67).
	MarkerESD uint16 = 0xFF67

	// MarkerRED is the Residual Error Descriptor marker (0xFF69).
	MarkerRED uint16 = 0xFF69
)

JPWL marker codes per ISO/IEC 15444-11.

View Source
const (
	// CodeNone indicates no error correction.
	CodeNone uint8 = 0x00

	// CodeRS1 is Reed-Solomon (160, 64) over GF(2^8).
	CodeRS1 uint8 = 0x01

	// CodeRS2 is Reed-Solomon (80, 25) over GF(2^8).
	CodeRS2 uint8 = 0x02

	// CodeRS3 is Reed-Solomon (40, 13) over GF(2^8).
	CodeRS3 uint8 = 0x03

	// CodeRS4 is Reed-Solomon (20, 7) over GF(2^8).
	CodeRS4 uint8 = 0x04

	// CodeCRC16 is 16-bit CRC for error detection only.
	CodeCRC16 uint8 = 0x10

	// CodeCRC32 is 32-bit CRC for error detection only.
	CodeCRC32 uint8 = 0x11
)

Error correction code identifiers.

View Source
const (
	// MaxParityBytes is the maximum parity bytes per protection block.
	MaxParityBytes = 256

	// MaxProtectedLength is the maximum protected data length.
	MaxProtectedLength = 1024 * 1024 // 1 MB

	// MaxEPBCount is the maximum number of EPB markers.
	MaxEPBCount = 1024
)

Maximum limits for validation.

Variables

View Source
var (
	// ErrEPCParsing indicates an error parsing the EPC marker.
	ErrEPCParsing = errors.New("jpwl: error protection capability parsing error")

	// ErrEPBParsing indicates an error parsing an EPB marker.
	ErrEPBParsing = errors.New("jpwl: error protection block parsing error")

	// ErrCorrectionFailed indicates error correction could not be applied.
	ErrCorrectionFailed = errors.New("jpwl: error correction failed")

	// ErrTruncatedData indicates the protection data is incomplete.
	ErrTruncatedData = errors.New("jpwl: truncated data")

	// ErrInvalidMarker indicates an invalid JPWL marker was encountered.
	ErrInvalidMarker = errors.New("jpwl: invalid marker")

	// ErrInvalidProtection indicates invalid protection parameters.
	ErrInvalidProtection = errors.New("jpwl: invalid protection parameters")

	// ErrUnsupportedCode indicates an unsupported error correction code.
	ErrUnsupportedCode = errors.New("jpwl: unsupported error correction code")

	// ErrMaxErrorsExceeded indicates too many errors to correct.
	ErrMaxErrorsExceeded = errors.New("jpwl: maximum correctable errors exceeded")

	// ErrDataCorrupted indicates data is corrupted beyond repair.
	ErrDataCorrupted = errors.New("jpwl: data corrupted beyond repair")

	// ErrInvalidParity indicates parity data is invalid.
	ErrInvalidParity = errors.New("jpwl: invalid parity data")
)

JPWL-specific errors for error protection parsing and correction.

Functions

This section is empty.

Types

type EPBMarker

type EPBMarker struct {
	// Length is the marker segment length.
	Length uint16

	// Depb contains style and index information.
	Depb uint8

	// LDPepb is the length of the data protected by this EPB.
	LDPepb uint32

	// Pepb contains the protection method ID.
	Pepb uint32

	// Parity contains the error correction parity data.
	Parity []byte
}

EPBMarker represents a parsed EPB (Error Protection Block) marker.

func (*EPBMarker) Index

func (e *EPBMarker) Index() int

Index returns the EPB index.

func (*EPBMarker) Style

func (e *EPBMarker) Style() int

Style returns the EPB style (packed or unpacked).

type EPCMarker

type EPCMarker struct {
	// Length is the marker segment length.
	Length uint16

	// PCRC is the CRC of the protected data.
	PCRC uint16

	// DL is the data length protected by this EPC.
	DL uint32

	// Pepc contains the EPC method information.
	Pepc uint8

	// Methods contains the list of protection methods.
	Methods []ProtectionMethod
}

EPCMarker represents a parsed EPC (Error Protection Capability) marker.

type ESDMarker

type ESDMarker struct {
	// Length is the marker segment length.
	Length uint16

	// Cesd contains the component index.
	Cesd uint16

	// Pesd contains sensitivity parameters.
	Pesd uint8

	// Sensitivities contains the sensitivity data.
	Sensitivities []SensitivityEntry
}

ESDMarker represents a parsed ESD (Error Sensitivity Descriptor) marker.

type ErrorLocation

type ErrorLocation struct {
	// Offset is the byte offset of the error.
	Offset uint32

	// Length is the length of the corrupted data.
	Length uint32
}

ErrorLocation describes the location of an error.

type Parser

type Parser struct{}

Parser parses JPWL error protection markers.

func NewParser

func NewParser() *Parser

NewParser creates a new JPWL parser.

func (*Parser) ParseEPB

func (p *Parser) ParseEPB(data []byte) (*EPBMarker, error)

ParseEPB parses an EPB (Error Protection Block) marker.

func (*Parser) ParseEPC

func (p *Parser) ParseEPC(data []byte) (*EPCMarker, error)

ParseEPC parses an EPC (Error Protection Capability) marker.

type ProtectionContext

type ProtectionContext struct {
	// EPC contains the error protection capability.
	EPC *EPCMarker

	// EPBs contains all error protection blocks.
	EPBs []*EPBMarker

	// ESD contains error sensitivity data.
	ESD *ESDMarker

	// RED contains residual error information.
	RED *REDMarker

	// HasProtection is true if any protection is present.
	HasProtection bool

	// ErrorsDetected counts detected errors.
	ErrorsDetected int

	// ErrorsCorrected counts corrected errors.
	ErrorsCorrected int
}

ProtectionContext holds all JPWL protection information.

func NewProtectionContext

func NewProtectionContext() *ProtectionContext

NewProtectionContext creates an empty protection context.

func (*ProtectionContext) AddEPB

func (c *ProtectionContext) AddEPB(epb *EPBMarker) error

AddEPB adds an error protection block to the context.

type ProtectionMethod

type ProtectionMethod struct {
	// Code is the error correction code identifier.
	Code uint8

	// Lprot is the length of the protected data.
	Lprot uint32

	// Pprot contains method-specific parameters.
	Pprot []byte
}

ProtectionMethod describes an error protection method.

type REDMarker

type REDMarker struct {
	// Length is the marker segment length.
	Length uint16

	// Dred contains the descriptor information.
	Dred uint8

	// Errors contains information about detected/uncorrected errors.
	Errors []ErrorLocation
}

REDMarker represents a parsed RED (Residual Error Descriptor) marker.

type RSCodeParams

type RSCodeParams struct {
	// N is the codeword length.
	N int

	// K is the data length.
	K int

	// T is the error correction capability (correctable symbols).
	T int

	// SymbolBits is the symbol size in bits.
	SymbolBits int
}

RSCodeParams contains Reed-Solomon code parameters.

func GetRSParams

func GetRSParams(code uint8) (*RSCodeParams, error)

GetRSParams returns RS parameters for a code identifier.

type Reader

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

Reader reads JPWL-protected JPEG 2000 codestreams.

func NewReader

func NewReader(data []byte) *Reader

NewReader creates a new JPWL reader.

func (*Reader) ApplyCorrection

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

ApplyCorrection attempts to apply error correction to the data.

func (*Reader) ErrorsCorrected

func (r *Reader) ErrorsCorrected() int

ErrorsCorrected returns the number of errors corrected.

func (*Reader) ErrorsDetected

func (r *Reader) ErrorsDetected() int

ErrorsDetected returns the number of errors detected.

func (*Reader) GetContext

func (r *Reader) GetContext() *ProtectionContext

GetContext returns the protection context.

func (*Reader) HasProtection

func (r *Reader) HasProtection() bool

HasProtection returns true if the codestream has error protection.

type ReedSolomonCorrector

type ReedSolomonCorrector struct{}

ReedSolomonCorrector implements Reed-Solomon error correction.

func NewReedSolomonCorrector

func NewReedSolomonCorrector() *ReedSolomonCorrector

NewReedSolomonCorrector creates a new RS corrector.

func (*ReedSolomonCorrector) Correct

func (c *ReedSolomonCorrector) Correct(data, parity []byte, code uint8) ([]byte, error)

Correct applies Reed-Solomon error correction to data. Returns the corrected data and the number of errors corrected.

type SensitivityEntry

type SensitivityEntry struct {
	// Offset is the byte offset of the sensitive data.
	Offset uint32

	// Length is the length of the sensitive data.
	Length uint32

	// Sensitivity is the sensitivity level (0-255, higher = more sensitive).
	Sensitivity uint8
}

SensitivityEntry describes sensitivity of a portion of data.

Jump to

Keyboard shortcuts

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