Skip to content

gainmapmath: directly sample gain maps at scale 1 - #480

Open
gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/jpeg-efficiency-investigation
Open

gregbenz wants to merge 1 commit into
google:mainfrom
gregbenz:codex/jpeg-efficiency-investigation

Conversation

@gregbenz

Copy link
Copy Markdown
Contributor

For a gain map at scale 1, the Shepard weights are [1, 0, 0, 0]: the result is just the first sample. The integer samplers still load four neighboring samples and combine them. This change reads the selected pixel directly for grayscale and RGB/RGBA maps, keeping the existing edge clamping, pixel strides, and / 255.0f conversion.

Performance

In a local 12 MP JPEG decode test with a full-resolution RGB gain map, this reduced elapsed time by 8.6-9.5% and process CPU time by 15.5-15.9%.

Run Baseline elapsed Patched elapsed Baseline CPU Patched CPU
1 132.7 ms 121.3 ms 307.8 ms 260.0 ms
2 135.3 ms 122.4 ms 312.6 ms 262.9 ms

Each value is the median of nine iterations after two warmups. The test used a deterministic synthetic 4000x3000 JPEG on macOS ARM64, Apple Clang 21, libjpeg-turbo 3.2.0, and a Release -O3 build with intrinsics enabled. The in-memory harness included decoder creation, setters, decode to linear RGBA half-float, and release; file I/O was outside timing. CPU time includes all process threads. These results measure HDR decoding, not a complete transcoding pipeline.

Tests

The added tests cover padded grayscale and RGB/RGBA rows, edge clamping, alpha-independent RGB sampling, and all 256 grayscale byte values. They also pass against the unmodified baseline.

  • JPEG-only Release build with warnings as errors: 1,099 tests passed; 224 skipped by the suite.
  • All 33 baseline/patched raw-output comparisons were byte-identical across linear, HLG, and PQ, including varied per-channel metadata and a gain map one row shorter than its base.
  • ASan/UBSan: all 64 gain-map math tests and six focused CLI output comparisons passed with halt-on-error enabled. Leak detection was disabled because this macOS runtime does not support it; system libjpeg was not instrumented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant