3 ms·
Going from 8-bit sRGB channels to 32-bit IEEE float channels is a simple lookup in a table with 256 values. Going the other way is only slightly harder. Scale
by burfog 8y ago
Going from 8-bit sRGB channels to 32-bit IEEE float channels is a simple lookup in a table with 256 values.
Going the other way is only slightly harder. Scale to the range 0 ... 4095, properly round the float to an integer, verify the range or mask with 0xfff to protect against NaN and Inf, and then to a table lookup in a table with 4096 values.
Tux Paint contains GPL code for it. It's been there for more than a decade. All you GIMP and Photoshop users having trouble with this should have been using Tux Paint. :-)
- mark-r 8y agoLookup tables are cache killers on modern CPUs. Arithmetic is often faster.
- burfog 8y agoIt's 5120 bytes for the both of them, the access is not at all random (due to color popularity), and the real cache killer is the image itself. You're dealing with a few megabytes for the image.
- mark-r 8y agoOh, the lookup tables are cached just fine. It's just that they crowd out something else.
- burfog 8y agoThat "something else" is already crowded out by running through a multi-megabyte image. At least the instruction cache is barely affected, which would not be the case for a math library function.
- AstralStorm 8y agoYou're not running a multi MB image but a small block thereof. Not that 5-6KiB LUT matters, but the extra conditional multiply ops or power or logarithm function evaluations do. Latter are need a few MACs for a good approximation (at least 12 bit precise, preferably 16 bit - like 5th order polynomial), former have masks, worse for SIMD.