From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#56182: 28.1; Display of SVG file with transparent background is incorrect Date: Mon, 11 Sep 2023 20:10:24 +0100 Message-ID: References: <82k096lgj5.fsf@gmail.com> <87a6a2s9e2.fsf@gnus.org> <83czexaycd.fsf@gnu.org> <82pmis3a7g.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="0N1oovWsC0kos1o4" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="11249"; mail-complaints-to="usenet@ciao.gmane.io" To: Pascal Quesseveur , Eli Zaretskii , Lars Ingebrigtsen , 56182@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Sep 11 21:11:23 2023 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1qfmJd-0002it-Ge for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 11 Sep 2023 21:11:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qfmJI-0002D0-3t; Mon, 11 Sep 2023 15:11:00 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qfmJF-0002CS-MA for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2023 15:10:57 -0400 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qfmJF-00075e-EI for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2023 15:10:57 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1qfmJJ-0002Db-J7 for bug-gnu-emacs@gnu.org; Mon, 11 Sep 2023 15:11:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 11 Sep 2023 19:11:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56182 X-GNU-PR-Package: emacs Original-Received: via spool by 56182-submit@debbugs.gnu.org id=B56182.16944594378495 (code B ref 56182); Mon, 11 Sep 2023 19:11:01 +0000 Original-Received: (at 56182) by debbugs.gnu.org; 11 Sep 2023 19:10:37 +0000 Original-Received: from localhost ([127.0.0.1]:54876 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfmIv-0002Cw-6x for submit@debbugs.gnu.org; Mon, 11 Sep 2023 15:10:37 -0400 Original-Received: from dane.soverin.net ([185.233.34.24]:54341) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qfmIt-0002Ci-2K for 56182@debbugs.gnu.org; Mon, 11 Sep 2023 15:10:36 -0400 Original-Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4RkxB90xQlzyd2; Mon, 11 Sep 2023 19:10:25 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4RkxB86BQTzFm; Mon, 11 Sep 2023 19:10:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1694459425; bh=/uv93L9LqIE8q9pLVqcvo9ql+Kee2p+3sqOcu0zt2mA=; h=Date:From:To:Subject:References:In-Reply-To:From; b=RbwMJj8Lt5weUXrAtW207Y8ZDDWUeO2urGGyzPho/+QWnVf+duI5BlD7r7ZepOK+K 8dCuVUV5Hmp1+r+TlMap48sLIxoePqdKJZloqddzuO0PmUUdcYOr5RX9MD+3CtJ0Hk NtqmQpasl/F+4QV/S4S0IGU7X86KH2am11bZjp1FiZqNR88zGeGEwWOReXrcPH86Bf 3S/Wf2WRcflVYWcvN61ugFUZQsnfihjDujf5LFwduREI2nkDl/ymp4Bt15AerliUx3 RuIoukXkNKnB7pj7xf1roVx6BPn4BWI9dQbJaghg9SzgIMGUaKkaTgt8jsyXCKN530 zR2pn2+ugbG9A== Original-Received: from alan by faroe.holly.idiocy.org with local (Exim 4.96) (envelope-from ) id 1qfmIi-001aGp-0q; Mon, 11 Sep 2023 20:10:24 +0100 X-Soverin-Authenticated: true Mail-Followup-To: Alan Third , Pascal Quesseveur , Eli Zaretskii , Lars Ingebrigtsen , 56182@debbugs.gnu.org Content-Disposition: inline In-Reply-To: X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:270076 Archived-At: --0N1oovWsC0kos1o4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Sep 09, 2023 at 01:09:44PM +0100, Alan Third wrote: > On Tue, Jun 28, 2022 at 08:38:11PM +0200, Pascal Quesseveur wrote: > > From what I understand the way to deal with background transparency of > > SVG images has changed in version 28.1 in function svg_load_image > > (comments about opacity are still there but I think they are > > irrelevant). Now the SVG image is encapsulated in another SVG image in > > which a rect element is defined with the background color of the > > image. > > > > I don't know why it doesn't work on the W10 computers I work on. I > > don't know if the problem comes from this modificatino either. It > > seems to me that the displayed color is BGR instead of RGB and the > > screen gamma correction is not applied. > > Apologies for leaving this so long. > > Is this an issue for *all* Windows machines? The documentation for > COLORREF[1] suggests that Windows uses a byte format for *all* colours > of 0x00BBGGRR, which would explain this, but I thought it worked fine > on some machines? > > Alternatively, I'm looking at the wrong documentation, however it > appears the code in w32term.c uses this COLORREF for colours as > defined in a face, so I think it's the right thing. > > If this is right and Windows always uses this format, all we need to > do is format the SVG colour differently on Windows. > > [1] https://learn.microsoft.com/en-gb/windows/win32/gdi/colorref?redirectedfrom=MSDN I've checked with the one Windows box I have available to me and it looks like this is the same there, so I've attached a patch that I hope will fix this. All it's doing is reversing bytes 1 and 3 (from the right) of the colours, so when it's used in the SVG code it should display correctly. I can't check it as I don't have a Windows development box. If someone can confirm that this 1. compiles and 2. fixes the problem that would be great. I found it easy to check by setting the theme to "light blue" and loading etc/images/down.svg. The correct result should have a black triangle on a blue background, but incorrect is a black triangle on a yellow background. -- Alan Third --0N1oovWsC0kos1o4 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="0001-Fix-SVG-colors-bug-56182.patch" >From 94649915ac108fb88b30f5ffda4606c4a1166289 Mon Sep 17 00:00:00 2001 From: Alan Third Date: Mon, 11 Sep 2023 19:58:14 +0100 Subject: [PATCH] Fix SVG colors (bug#56182) * src/image.c (svg_load_image): Reverse the R and B bytes in the Windows colors before using them to generate the SVG. --- src/image.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/image.c b/src/image.c index a4b8d21cee6..84db9bfb3b8 100644 --- a/src/image.c +++ b/src/image.c @@ -12075,6 +12075,18 @@ svg_load_image (struct frame *f, struct image *img, char *contents, img->background_valid = 1; } +#if HAVE_NTGUI + /* Windows stores the image colours in BGR format, and SVG expects + them in RGB. */ + foreground = (foreground & 0x0000FF) << 16 + | (foreground & 0xFF0000) >> 16 + | (foreground & 0x00FF00); + + background = (background & 0x0000FF) << 16 + | (background & 0xFF0000) >> 16 + | (background & 0x00FF00); +#endif + wrapped_contents = xmalloc (buffer_size); if (buffer_size <= snprintf (wrapped_contents, buffer_size, wrapper, -- 2.40.1 --0N1oovWsC0kos1o4--