Documentation
¶
Overview ¶
Package imagedecode decodes encoded image bytes into the RGBA8 pixel layout the egui2 image widget consumes: row-major, one uint32 per pixel, packed 0xRRGGBBAA.
The bindings carry no encoded-bytes path — [bindings.Image] takes decoded pixels — so every caller that wants to show a PNG owns this conversion. This package is that conversion, and nothing else: it imports no bindings and draws nothing.
Formats ¶
PNG, JPEG and GIF, blank-imported so image.Decode auto-detects from the magic prefix. WebP / AVIF / BMP are deliberately absent — they add roughly a megabyte to every binary that links them, and the images that reach this package in practice are PNG screenshots and JPEG photos. A caller needing an exotic format can blank-import the decoder itself; image.Decode consults a process-wide registry, so the extra format becomes available here without a change to this file.
Bounds ¶
DecodeRGBA8 resolves the header with image.DecodeConfig and rejects an oversized image *before* the full decode allocates. This is the difference between reading 40 KB and allocating 3.6 GB: PNG compresses uniform data so well that a 30000×30000 image is a small file. Any caller decoding bytes it did not itself produce should pass a real bound.
Index ¶
Constants ¶
const DefaultMaxPixels = 64 << 20
DefaultMaxPixels bounds a decode at 64 megapixels — comfortably past any screenshot or photo, and far short of a decompression bomb. It is a pixel count, not a byte count, because the allocation this guards is 4 bytes per pixel regardless of how small the encoded form was.
Variables ¶
var PackageProps = packageprops.Props{ WASMWASI: packageprops.WASMCompiles, WASMJS: packageprops.WASMCompiles, WASMFreestanding: packageprops.WASMCompiles, }
PackageProps records this package's curated properties (ADR-0080). Seeded by `boxer code analysis golang wasmsurvey props generate`; curate by hand. The same group's `props verify` reconciles it.
Functions ¶
func DecodeRGBA8 ¶
func DecodeRGBA8(data []byte, maxPixels int) (pixels []uint32, widthPx uint32, heightPx uint32, err error)
DecodeRGBA8 decodes PNG / JPEG / GIF bytes into row-major 0xRRGGBBAA pixels sized widthPx × heightPx.
maxPixels bounds widthPx*heightPx, checked against the header before the pixel buffer is allocated; pass DefaultMaxPixels unless the caller has a reason of its own, or zero to decode unbounded (only safe for bytes the caller produced).
The error names what failed — unknown format, oversized, undecodable — so a UI can show it rather than an empty box.
func Pack ¶
Pack converts a decoded image.Image into row-major 0xRRGGBBAA pixels. Exported for callers that already hold a decoded image (a rendered chart, a synthesised bitmap) and only want the packing.
An image with empty bounds yields nil pixels and zero dimensions.
Types ¶
This section is empty.