Documentation
¶
Overview ¶
Package jpegscan is a lightweight, allocation-frugal JPEG marker scanner used by the detection-signature layer. It reads the structural metadata of a JPEG (the APP0/JFIF segment, COM comments, DQT quantization tables, and the SOF frame header with its component sampling factors) WITHOUT performing a full entropy decode.
It is deliberately defensive: every read is bounds-checked and malformed input yields a partial Scan and/or an error rather than a panic, because the input is untrusted.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APP0 ¶
type APP0 struct {
// Identifier is the 5-byte segment identifier, normally "JFIF\x00".
Identifier string
VersionMajor int
VersionMinor int
// Units is the density unit: 0 = none (aspect ratio only), 1 = dots/inch,
// 2 = dots/cm.
Units int
XDensity int
YDensity int
ThumbW int
ThumbH int
}
APP0 is a parsed JFIF APP0 segment.
type QuantTable ¶
QuantTable is one DQT entry. Values are in JPEG zigzag order, exactly as stored in the file.
type Scan ¶
type Scan struct {
APP0 *APP0
Comments [][]byte
QuantTables []QuantTable
Components []Component
// DHTSegments holds the raw payload (the bytes after the 2-byte length
// field) of every DHT marker seen, in file order. f5.jar emits exactly one
// DHT segment carrying all four standard tables; most encoders split them.
DHTSegments [][]byte
// MarkerOrder is the sequence of length-prefixed segment markers seen before
// the scan, terminated by the SOS marker (e.g. APP0, COM, DQT, SOF0, DHT,
// SOS). It captures the encoder's header layout independent of segment
// contents.
MarkerOrder []int
// ScanComponents holds the SOS header's per-component entropy-table
// selections. Empty until an SOS header is parsed.
ScanComponents []ScanComponent
// DQTSegmentCount is the number of distinct DQT marker segments (not tables);
// f5.jar packs both quantization tables into a single segment.
DQTSegmentCount int
// EntropyOffset is the byte offset of the first entropy-coded byte (just past
// the SOS header), or 0 if no SOS was found.
EntropyOffset int
// SOFMarker is the second byte of the SOF marker that was found (e.g. 0xC0
// for baseline). Zero if no SOF was seen before SOS/EOI.
SOFMarker int
Width int
Height int
}
Scan holds the structural metadata extracted from a JPEG byte stream.
func Parse ¶
Parse scans the marker structure of a JPEG. It stops at the first SOS (start of scan) marker, since the structural metadata of interest all precedes the entropy-coded data. A nil Scan is returned only when the input is not a JPEG; otherwise a best-effort partial Scan is returned alongside any error.
func (*Scan) HasDRI ¶
HasDRI reports whether a define-restart-interval (DRI) segment preceded the scan. f5.jar never emits restart markers.
func (*Scan) Is420 ¶
Is420 reports whether the frame uses 4:2:0 chroma subsampling: a luminance component sampled 2x2 and two chroma components sampled 1x1. This is the James R. Weeks / f5.jar encoder's fixed mode.
func (*Scan) IsBaseline ¶
IsBaseline reports whether the frame is baseline sequential DCT (SOF0), the only mode F5 embeds into and the only mode it can be extracted from.
func (*Scan) IsLossless ¶
IsLossless reports whether the frame is lossless (SOF3 or SOF11).
func (*Scan) IsProgressive ¶
IsProgressive reports whether the frame is progressive DCT (SOF2).
func (*Scan) SubsamplingLabel ¶
SubsamplingLabel returns a short human-readable subsampling label derived from the component sampling factors, or "unknown" when it cannot be classified.
type ScanComponent ¶
ScanComponent is one component's entropy-table selection from the SOS header.