Saturation Tone Inline: Changes a pixel saturation
| 819 | |
| 820 | // Saturation Tone Inline: Changes a pixel saturation |
| 821 | static inline void saturation_tone(uint32_t &src_pixel, const int saturation, const int rs, const int gs, const int bs, const int as) { |
| 822 | // Algorithm from OpenPDN (MIT license) |
| 823 | // Transformation in Y'CbCr color space |
| 824 | uint8_t r = (src_pixel >> rs) & 0xFF; |
| 825 | uint8_t g = (src_pixel >> gs) & 0xFF; |
| 826 | uint8_t b = (src_pixel >> bs) & 0xFF; |
| 827 | uint8_t a = (src_pixel >> as) & 0xFF; |
| 828 | |
| 829 | // Y' = 0.299 R' + 0.587 G' + 0.114 B' |
| 830 | uint8_t lum = (7471 * b + 38470 * g + 19595 * r) >> 16; |
| 831 | |
| 832 | // Scale Cb/Cr by scale factor "sat" |
| 833 | int red = ((lum * 1024 + (r - lum) * saturation) >> 10); |
| 834 | red = red > 255 ? 255 : red < 0 ? 0 : red; |
| 835 | int green = ((lum * 1024 + (g - lum) * saturation) >> 10); |
| 836 | green = green > 255 ? 255 : green < 0 ? 0 : green; |
| 837 | int blue = ((lum * 1024 + (b - lum) * saturation) >> 10); |
| 838 | blue = blue > 255 ? 255 : blue < 0 ? 0 : blue; |
| 839 | |
| 840 | src_pixel = ((uint32_t)red << rs) | ((uint32_t)green << gs) | ((uint32_t)blue << bs) | ((uint32_t)a << as); |
| 841 | } |
| 842 | |
| 843 | // Color Tone Inline: Changes color of a pixel by hard light table |
| 844 | static inline void color_tone(uint32_t &src_pixel, const Tone& tone, const int rs, const int gs, const int bs, const int as) { |