Skip to content

Use powf instead of pow when building the gamma LUT - #287

Open
afonsojanu wants to merge 1 commit into
randy408:masterfrom
afonsojanu:fix/gamma-lut-use-powf
Open

afonsojanu wants to merge 1 commit into
randy408:masterfrom
afonsojanu:fix/gamma-lut-use-powf

Conversation

@afonsojanu

Copy link
Copy Markdown

Closes #282.

Every value going into this call is already a float (i, max, exponent are all float), but the code calls the double-precision pow() anyway. That pulls in the double exp/log LUTs, adding close to 10KB to the binary on platforms where the double and float math paths aren't otherwise linked in, even though the rest of this codebase already sticks to powf/expf-style float math where it can.

Swapped it for powf(). I checked the resulting gamma_lut values against the old code across a wide range of gamma settings (both the 8-bit and 16-bit LUT sizes) and every entry comes out identical, so this is purely a code-size/perf change, no behavior difference.

Built with meson (-Db_sanitize=address,undefined) and ran the test suite before and after: 165 passing / 41 expected-fail / 2 failing, same numbers on both, and the 2 failures (ch1n3p04, ch2n3p08) reproduce identically on unmodified master, unrelated to this change.

All the values going into this call are float, but pow() pulls in
the double-precision exp/log tables anyway, which costs almost 10KB
of extra binary size on some platforms for no benefit. Switched to
powf() so it stays on the float LUTs the rest of the file already
uses. Checked the resulting gamma_lut entries against the old code
across a wide range of gamma values and they come out identical.
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.

spng_decode_image should use powf, not pow

1 participant