summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defs.h5
-rw-r--r--src/media.c27
-rw-r--r--src/ui/util.c1
3 files changed, 26 insertions, 7 deletions
diff --git a/src/defs.h b/src/defs.h
index 135cc053..6b12c86c 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -44,8 +44,9 @@ enum iFileVersion {
44enum iImageStyle { 44enum iImageStyle {
45 original_ImageStyle = 0, 45 original_ImageStyle = 0,
46 grayscale_ImageStyle = 1, 46 grayscale_ImageStyle = 1,
47 textColorized_ImageStyle = 2, 47 bgFg_ImageStyle = 2,
48 preformatColorized_ImageStyle = 3, 48 textColorized_ImageStyle = 3,
49 preformatColorized_ImageStyle = 4,
49}; 50};
50 51
51enum iScrollType { 52enum iScrollType {
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 };
diff --git a/src/ui/util.c b/src/ui/util.c
index 8a42f75b..906d30ae 100644
--- a/src/ui/util.c
+++ b/src/ui/util.c
@@ -1836,6 +1836,7 @@ iWidget *makePreferences_Widget(void) {
1836 const iMenuItem imgStyles[] = { 1836 const iMenuItem imgStyles[] = {
1837 { "${prefs.imagestyle.original}", 0, 0, format_CStr("imagestyle.set arg:%d", original_ImageStyle) }, 1837 { "${prefs.imagestyle.original}", 0, 0, format_CStr("imagestyle.set arg:%d", original_ImageStyle) },
1838 { "${prefs.imagestyle.grayscale}", 0, 0, format_CStr("imagestyle.set arg:%d", grayscale_ImageStyle) }, 1838 { "${prefs.imagestyle.grayscale}", 0, 0, format_CStr("imagestyle.set arg:%d", grayscale_ImageStyle) },
1839 { "${prefs.imagestyle.bgfg}", 0, 0, format_CStr("imagestyle.set arg:%d", bgFg_ImageStyle) },
1839 { "${prefs.imagestyle.text}", 0, 0, format_CStr("imagestyle.set arg:%d", textColorized_ImageStyle) }, 1840 { "${prefs.imagestyle.text}", 0, 0, format_CStr("imagestyle.set arg:%d", textColorized_ImageStyle) },
1840 { "${prefs.imagestyle.preformat}", 0, 0, format_CStr("imagestyle.set arg:%d", preformatColorized_ImageStyle) }, 1841 { "${prefs.imagestyle.preformat}", 0, 0, format_CStr("imagestyle.set arg:%d", preformatColorized_ImageStyle) },
1841 }; 1842 };