diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-07 14:17:19 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-07 14:17:19 +0300 |
commit | 73c4d953d38e05fd438c4708c7f59ea385a53550 (patch) | |
tree | c6d3242842832705b40f63cb449505ceab925252 /src/media.c | |
parent | 56ebd2011cdc9e0375a941fac4ecbbc0977e0f79 (diff) |
Media: Refined colorized image exposure
Diffstat (limited to 'src/media.c')
-rw-r--r-- | src/media.c | 22 |
1 files changed, 8 insertions, 14 deletions
diff --git a/src/media.c b/src/media.c index 8f6c6382..94de0bc6 100644 --- a/src/media.c +++ b/src/media.c | |||
@@ -98,25 +98,19 @@ static void applyImageStyle_(enum iImageStyle style, iInt2 size, uint8_t *imgDat | |||
98 | : tmPreformatted_ColorId); | 98 | : tmPreformatted_ColorId); |
99 | /* Maximize contrast. */ | 99 | /* Maximize contrast. */ |
100 | const int colMax = iMax(iMax(colorize.r, colorize.g), colorize.b); | 100 | const int colMax = iMax(iMax(colorize.r, colorize.g), colorize.b); |
101 | if (colMax >= 8) { | 101 | brighten = iClamp(1.0f - (colorize.r + colorize.g + colorize.b) / (colMax * 3), 0.0f, 0.5f); /* compensate loss of light */ |
102 | colorize.r = colorize.r * 255 / colMax; | ||
103 | colorize.g = colorize.g * 255 / colMax; | ||
104 | colorize.b = colorize.b * 255 / colMax; | ||
105 | } | ||
106 | else { | ||
107 | colorize = (iColor){ 255, 255, 255, 255}; | ||
108 | } | ||
109 | // printf("colorize:%d %d %d\n", colorize.r, colorize.g, colorize.b); | ||
110 | brighten = iClamp(1.0f - (colorize.r + colorize.g + colorize.b) / 600.0f, 0.0f, 0.5f); /* compensate loss of light */ | ||
111 | // printf("bright:%f\n", brighten); | ||
112 | } | 102 | } |
113 | uint8_t *pos = imgData; | 103 | uint8_t *pos = imgData; |
114 | size_t numPixels = size.x * size.y; | 104 | size_t numPixels = size.x * size.y; |
105 | iHSLColor hslColorize = hsl_Color(colorize); | ||
115 | while (numPixels-- > 0) { | 106 | while (numPixels-- > 0) { |
116 | iHSLColor hsl = hsl_Color((iColor){ pos[0], pos[1], pos[2], 255 }); | 107 | iHSLColor hsl = hsl_Color((iColor){ pos[0], pos[1], pos[2], 255 }); |
117 | pos[0] = powf((colorize.r * hsl.lum) / 255.0f, 1.0f - brighten) * 255; | 108 | iHSLColor out = { hslColorize.hue, hslColorize.sat, hsl.lum, 1.0f }; |
118 | pos[1] = powf((colorize.g * hsl.lum) / 255.0f, 1.0f - brighten) * 255; | 109 | out.lum = powf(out.lum, 1.0f + brighten * 2); |
119 | pos[2] = powf((colorize.b * hsl.lum) / 255.0f, 1.0f - brighten) * 255; | 110 | iColor outRgb = rgb_HSLColor(out); |
111 | pos[0] = powf(outRgb.r / 255.0f, 1.0f - brighten * 0.75f) * 255; | ||
112 | pos[1] = powf(outRgb.g / 255.0f, 1.0f - brighten * 0.75f) * 255; | ||
113 | pos[2] = powf(outRgb.b / 255.0f, 1.0f - brighten * 0.75f) * 255; | ||
120 | pos += 4; | 114 | pos += 4; |
121 | } | 115 | } |
122 | } | 116 | } |