diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-07 14:43:02 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-09-07 14:43:02 +0300 |
commit | 7ebf62baffed32be593fa1307afd3a303575f1c4 (patch) | |
tree | 4525e8252b9a3836a67edfcece9f57f619e7d50a | |
parent | 73c4d953d38e05fd438c4708c7f59ea385a53550 (diff) |
Added BG-to-FG image colorization mode
-rw-r--r-- | po/en.po | 4 | ||||
-rw-r--r-- | res/lang/de.bin | bin | 23942 -> 23973 bytes | |||
-rw-r--r-- | res/lang/en.bin | bin | 22543 -> 22574 bytes | |||
-rw-r--r-- | res/lang/es.bin | bin | 25069 -> 25100 bytes | |||
-rw-r--r-- | res/lang/fi.bin | bin | 25074 -> 25105 bytes | |||
-rw-r--r-- | res/lang/fr.bin | bin | 26043 -> 26074 bytes | |||
-rw-r--r-- | res/lang/ia.bin | bin | 24670 -> 24701 bytes | |||
-rw-r--r-- | res/lang/ie.bin | bin | 24428 -> 24459 bytes | |||
-rw-r--r-- | res/lang/pl.bin | bin | 25603 -> 25634 bytes | |||
-rw-r--r-- | res/lang/ru.bin | bin | 37325 -> 37356 bytes | |||
-rw-r--r-- | res/lang/sr.bin | bin | 36982 -> 37013 bytes | |||
-rw-r--r-- | res/lang/tok.bin | bin | 22864 -> 22895 bytes | |||
-rw-r--r-- | res/lang/zh_Hans.bin | bin | 21622 -> 21653 bytes | |||
-rw-r--r-- | res/lang/zh_Hant.bin | bin | 21807 -> 21838 bytes | |||
-rw-r--r-- | src/defs.h | 5 | ||||
-rw-r--r-- | src/media.c | 27 | ||||
-rw-r--r-- | src/ui/util.c | 1 |
17 files changed, 30 insertions, 7 deletions
@@ -1342,6 +1342,10 @@ msgstr "None" | |||
1342 | msgid "prefs.imagestyle.grayscale" | 1342 | msgid "prefs.imagestyle.grayscale" |
1343 | msgstr "Grayscale" | 1343 | msgstr "Grayscale" |
1344 | 1344 | ||
1345 | # Abbrevation: background-to-foreground | ||
1346 | msgid "prefs.imagestyle.bgfg" | ||
1347 | msgstr "BG-to-FG" | ||
1348 | |||
1345 | msgid "prefs.imagestyle.text" | 1349 | msgid "prefs.imagestyle.text" |
1346 | msgstr "Text Color" | 1350 | msgstr "Text Color" |
1347 | 1351 | ||
diff --git a/res/lang/de.bin b/res/lang/de.bin index 5788ed84..8e09c601 100644 --- a/res/lang/de.bin +++ b/res/lang/de.bin | |||
Binary files differ | |||
diff --git a/res/lang/en.bin b/res/lang/en.bin index 536ca6a2..859c6461 100644 --- a/res/lang/en.bin +++ b/res/lang/en.bin | |||
Binary files differ | |||
diff --git a/res/lang/es.bin b/res/lang/es.bin index 14203f8e..a1e31cb4 100644 --- a/res/lang/es.bin +++ b/res/lang/es.bin | |||
Binary files differ | |||
diff --git a/res/lang/fi.bin b/res/lang/fi.bin index 875413a5..19aa8c35 100644 --- a/res/lang/fi.bin +++ b/res/lang/fi.bin | |||
Binary files differ | |||
diff --git a/res/lang/fr.bin b/res/lang/fr.bin index 6976a00f..7ad2f654 100644 --- a/res/lang/fr.bin +++ b/res/lang/fr.bin | |||
Binary files differ | |||
diff --git a/res/lang/ia.bin b/res/lang/ia.bin index a77a1d61..6d69af59 100644 --- a/res/lang/ia.bin +++ b/res/lang/ia.bin | |||
Binary files differ | |||
diff --git a/res/lang/ie.bin b/res/lang/ie.bin index 33850dc5..dc519da2 100644 --- a/res/lang/ie.bin +++ b/res/lang/ie.bin | |||
Binary files differ | |||
diff --git a/res/lang/pl.bin b/res/lang/pl.bin index 0b4c3e10..93877061 100644 --- a/res/lang/pl.bin +++ b/res/lang/pl.bin | |||
Binary files differ | |||
diff --git a/res/lang/ru.bin b/res/lang/ru.bin index fbafc283..0b97d0ec 100644 --- a/res/lang/ru.bin +++ b/res/lang/ru.bin | |||
Binary files differ | |||
diff --git a/res/lang/sr.bin b/res/lang/sr.bin index b9ce2f5a..182a2dca 100644 --- a/res/lang/sr.bin +++ b/res/lang/sr.bin | |||
Binary files differ | |||
diff --git a/res/lang/tok.bin b/res/lang/tok.bin index f1988dff..8fee6738 100644 --- a/res/lang/tok.bin +++ b/res/lang/tok.bin | |||
Binary files differ | |||
diff --git a/res/lang/zh_Hans.bin b/res/lang/zh_Hans.bin index 0ef1a915..7c7d9487 100644 --- a/res/lang/zh_Hans.bin +++ b/res/lang/zh_Hans.bin | |||
Binary files differ | |||
diff --git a/res/lang/zh_Hant.bin b/res/lang/zh_Hant.bin index f12f0ef2..5691aef9 100644 --- a/res/lang/zh_Hant.bin +++ b/res/lang/zh_Hant.bin | |||
Binary files differ | |||
@@ -44,8 +44,9 @@ enum iFileVersion { | |||
44 | enum iImageStyle { | 44 | enum 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 | ||
51 | enum iScrollType { | 52 | enum 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 | }; |