summaryrefslogtreecommitdiff
path: root/src/media.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/media.c')
-rw-r--r--src/media.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/media.c b/src/media.c
index 94de0bc6..999368c5 100644
--- a/src/media.c
+++ b/src/media.c
@@ -91,8 +91,27 @@ static void applyImageStyle_(enum iImageStyle style, iInt2 size, uint8_t *imgDat
91 if (style == original_ImageStyle) { 91 if (style == original_ImageStyle) {
92 return; 92 return;
93 } 93 }
94 iColor colorize = (iColor){ 255, 255, 255, 255}; 94 uint8_t *pos = imgData;
95 float brighten = 0.0f; 95 size_t numPixels = size.x * size.y;
96 float brighten = 0.0f;
97 if (style == bgFg_ImageStyle) {
98 iColor dark = get_Color(tmBackground_ColorId);
99 iColor light = get_Color(tmParagraph_ColorId);
100 if (hsl_Color(dark).lum > hsl_Color(light).lum) {
101 iSwap(iColor, dark, light);
102 }
103 while (numPixels-- > 0) {
104 iHSLColor hsl = hsl_Color((iColor){ pos[0], pos[1], pos[2], 255 });
105 const float s = 1.0f - hsl.lum;
106 const float t = hsl.lum;
107 pos[0] = dark.r * s + light.r * t;
108 pos[1] = dark.g * s + light.g * t;
109 pos[2] = dark.b * s + light.b * t;
110 pos += 4;
111 }
112 return;
113 }
114 iColor colorize = (iColor){ 255, 255, 255, 255 };
96 if (style != grayscale_ImageStyle) { 115 if (style != grayscale_ImageStyle) {
97 colorize = get_Color(style == textColorized_ImageStyle ? tmParagraph_ColorId 116 colorize = get_Color(style == textColorized_ImageStyle ? tmParagraph_ColorId
98 : tmPreformatted_ColorId); 117 : tmPreformatted_ColorId);
@@ -100,9 +119,7 @@ static void applyImageStyle_(enum iImageStyle style, iInt2 size, uint8_t *imgDat
100 const int colMax = iMax(iMax(colorize.r, colorize.g), colorize.b); 119 const int colMax = iMax(iMax(colorize.r, colorize.g), colorize.b);
101 brighten = iClamp(1.0f - (colorize.r + colorize.g + colorize.b) / (colMax * 3), 0.0f, 0.5f); /* compensate loss of light */ 120 brighten = iClamp(1.0f - (colorize.r + colorize.g + colorize.b) / (colMax * 3), 0.0f, 0.5f); /* compensate loss of light */
102 } 121 }
103 uint8_t *pos = imgData; 122 iHSLColor hslColorize = hsl_Color(colorize);
104 size_t numPixels = size.x * size.y;
105 iHSLColor hslColorize = hsl_Color(colorize);
106 while (numPixels-- > 0) { 123 while (numPixels-- > 0) {
107 iHSLColor hsl = hsl_Color((iColor){ pos[0], pos[1], pos[2], 255 }); 124 iHSLColor hsl = hsl_Color((iColor){ pos[0], pos[1], pos[2], 255 });
108 iHSLColor out = { hslColorize.hue, hslColorize.sat, hsl.lum, 1.0f }; 125 iHSLColor out = { hslColorize.hue, hslColorize.sat, hsl.lum, 1.0f };