Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
isp:hsl-_rgb [2021/07/24 10:53] – [Division-less division] Igor Yefmov | isp:hsl-_rgb [2021/07/24 11:07] – [Step-by-step algorithm] Igor Yefmov | ||
---|---|---|---|
Line 20: | Line 20: | ||
\[\frac{1}{x} = \frac{1*N}{x*N}\] | \[\frac{1}{x} = \frac{1*N}{x*N}\] | ||
and choosing \(N\) such that \(x*N\) is a whole power of \(2\) we have an optimization where a division is replaced by a pair of a multiplication followed by a (super cheap!) bit-shift operation by \(Z\) bits: | and choosing \(N\) such that \(x*N\) is a whole power of \(2\) we have an optimization where a division is replaced by a pair of a multiplication followed by a (super cheap!) bit-shift operation by \(Z\) bits: | ||
- | \[\frac{C}{x} = C*\frac{1}{x} = C*\frac{1*N}{x*N}\middle|(2^Z = x*N) = C*\frac{N}{2^Z} = [(C*N) \gg Z]\] | + | \[\frac{C}{x} = C*\frac{1}{x} = C*\frac{1*N}{x*N}\Bigg|_{\{x*N=2^Z\}} |
The value \(Z\) depends on the needed precision and, of course, the higher the \(Z\) the less precision loss there will be in the end. | The value \(Z\) depends on the needed precision and, of course, the higher the \(Z\) the less precision loss there will be in the end. | ||
Line 58: | Line 58: | ||
\[(R, | \[(R, | ||
- | ===== Step-by-step algorithm ===== | + | ===== Step-by-step algorithm |
+ | Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table: | ||
+ | |||
+ | ^ # ^ name ^ math excerpt from Wikipedia | ||
+ | | 1 | \[h\] | \[hue(pixel)\] | '' | ||
+ | | 2 | \[s\] | \[sat(pixel)\] | '' | ||
+ | | 3 | \[l\] | \[luma(pixel)\] | '' | ||
+ | | 4 | \[H\] | \[(H+360^\circ) \bmod 360^\circ\] | '' | ||
+ | H = (h1 > 0 ? h1 : h1 + 4096);</ | ||
+ | | | \(S\)((not needed for calculations)) | \[\frac{S}{255}\] | | \[0..1\] | | | | ||
+ | | | \(L\)((not needed for calculations)) | \[\frac{S}{511}\] | | \[0..1\] | | | | ||
+ | | 5 | \[L^\prime\] | \[1-|2L-1|\] | '' | ||
+ | | 6 | \[C\] | \[L^\prime \times S\] | '' | ||
+ | | 7 | \[H^\prime\] | \[\frac{H}{60^\circ}\] | '' | ||
+ | | 8 | \[H^\prime_2\] | \[H^\prime \bmod 2\] | '' | ||
+ | | 9 | \[H^\prime_{2-1}\] | \[H^\prime \bmod 2 - 1\] | '' | ||
+ | | 11 | \[H^\prime_{final}\] | \[1-|H^\prime \bmod 2 - 1|\] | '' | ||
+ | | 12 | \[X\] | \[C \times H^\prime_{final}\] | '' | ||
+ | | 13 | \[(R_1, | ||
+ | / | ||
+ | }else if(Hp < 364*2){ | ||
+ | / | ||
+ | }// | ||
+ | | 14 | \[m\] | \[L - C/2\] | '' | ||
+ | | 15 | \[(R,G,B)\] | \[(R_1+m, | ||
+ | |||
+ | |||
+ | ===== Step-by-step algorithm (10x3 bit channel, 30-bit RGB) ===== | ||
Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table: | Armed with the above information we can now compile the necessary sequence of calculations and format it into an easy-to-use table: | ||