From: Pip Cet <pipcet@gmail.com>
To: 36315@debbugs.gnu.org
Subject: bug#36315: 27.0.50; SVG transparency handling is inaccurate
Date: Thu, 20 Jun 2019 20:26:53 +0000 [thread overview]
Message-ID: <CAOqdjBcuLiay8U9Q5DfP-b7z8HRNV3HoGdhrUj9enVwYp52T1w@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 565 bytes --]
Evaluate the following in emacs -Q:
(require 'svg)
(defun make-image (color)
(let ((svg (svg-create 100 100)))
(svg-rectangle svg 0 0 100 100 :fill color)
(svg-image svg)))
(set-frame-parameter (window-frame) 'background-color "black")
(insert (propertize " " 'display (make-image "#f00000")))
The expected result is a rectangle (on black background) of color
#f00000. The actual result is a rectangle of color #ef0000. For black
backgrounds, white is no longer representable.
This is related to bug #36304, but much easier to fix.
Patch attached.
[-- Attachment #2: 0001-SVG-scale-color-values-properly.patch --]
[-- Type: text/x-patch, Size: 1707 bytes --]
From 7abe6404d3af04db2f5a503c1c873f80ab86f69e Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Thu, 20 Jun 2019 20:13:12 +0000
Subject: [PATCH] SVG: scale color values properly
* src/image.c (svg_load_image): scale color channel values to proper
range.
---
src/image.c | 25 ++++++++++++++-----------
1 file changed, 14 insertions(+), 11 deletions(-)
diff --git a/src/image.c b/src/image.c
index 866323ba6e..6b6235a617 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9658,17 +9658,20 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
{
for (int x = 0; x < width; ++x)
{
- int red = *pixels++;
- int green = *pixels++;
- int blue = *pixels++;
- int opacity = *pixels++;
-
- red = ((red * opacity)
- + (background.red * ((1 << 8) - opacity)));
- green = ((green * opacity)
- + (background.green * ((1 << 8) - opacity)));
- blue = ((blue * opacity)
- + (background.blue * ((1 << 8) - opacity)));
+ unsigned int red = *pixels++;
+ unsigned int green = *pixels++;
+ unsigned int blue = *pixels++;
+ unsigned int opacity = *pixels++;
+
+ /* opacity and the color channel values are in the range {0..255},
+ * but expected output values are in the range {0..65535}, so scale
+ * by (256/255)^2. */
+#define MIX(a, b, opacity) \
+ (((((a) * opacity) + ((b) * (255 - opacity))) * 65535 + 32512) / 65025)
+ red = MIX (red, background.red, opacity);
+ green = MIX (green, background.red, opacity);
+ blue = MIX (blue, background.red, opacity);
+#undef MIX
PUT_PIXEL (ximg, x, y, lookup_rgb_color (f, red, green, blue));
}
--
2.20.1
next reply other threads:[~2019-06-20 20:26 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-20 20:26 Pip Cet [this message]
2019-06-20 20:46 ` bug#36315: 27.0.50; SVG transparency handling is inaccurate Pip Cet
2019-06-22 20:56 ` Alan Third
2019-06-24 7:56 ` YAMAMOTO Mitsuharu
2019-06-24 8:17 ` YAMAMOTO Mitsuharu
2019-06-24 16:24 ` Pip Cet
2019-06-24 17:41 ` Eli Zaretskii
2019-06-24 23:06 ` YAMAMOTO Mitsuharu
2019-06-25 16:54 ` Eli Zaretskii
2019-06-25 18:44 ` Alan Third
2019-06-25 18:55 ` Eli Zaretskii
2019-06-25 23:48 ` YAMAMOTO Mitsuharu
2019-06-26 0:12 ` Lars Ingebrigtsen
2019-06-26 15:57 ` Eli Zaretskii
2019-06-27 3:33 ` YAMAMOTO Mitsuharu
2019-06-27 14:16 ` Eli Zaretskii
2019-06-30 6:12 ` YAMAMOTO Mitsuharu
2019-06-30 14:26 ` Eli Zaretskii
2019-07-01 3:46 ` YAMAMOTO Mitsuharu
2019-07-01 14:11 ` Eli Zaretskii
2019-07-01 16:25 ` Pip Cet
2019-07-02 2:32 ` Eli Zaretskii
2019-07-02 9:46 ` YAMAMOTO Mitsuharu
2019-07-02 14:26 ` Eli Zaretskii
2020-08-21 13:04 ` Lars Ingebrigtsen
2020-08-21 15:04 ` Alan Third
2020-08-22 13:29 ` Lars Ingebrigtsen
2020-08-22 16:00 ` Alan Third
2020-12-18 0:49 ` bug#36315: Incorrect SVG color Qiantan Hong
2020-12-18 15:00 ` Alan Third
2020-12-18 15:47 ` Qiantan Hong
2020-12-18 15:51 ` Qiantan Hong
2020-12-18 16:42 ` Qiantan Hong
2020-12-18 18:04 ` Alan Third
2020-12-18 18:16 ` Alan Third
2020-12-19 0:24 ` Lars Ingebrigtsen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOqdjBcuLiay8U9Q5DfP-b7z8HRNV3HoGdhrUj9enVwYp52T1w@mail.gmail.com \
--to=pipcet@gmail.com \
--cc=36315@debbugs.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.