unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Pip Cet <pipcet@gmail.com>
To: YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Cc: 36315@debbugs.gnu.org
Subject: bug#36315: 27.0.50; SVG transparency handling is inaccurate
Date: Mon, 24 Jun 2019 16:24:17 +0000	[thread overview]
Message-ID: <CAOqdjBcsA4ee-KAqpvVAD_mJ4DmVSxHC+9Q1xbqDepmPsFJ39g@mail.gmail.com> (raw)
In-Reply-To: <wl1rzjjt1o.wl-mituharu@math.s.chiba-u.ac.jp>

[-- Attachment #1: Type: text/plain, Size: 2554 bytes --]

On Mon, Jun 24, 2019 at 8:17 AM YAMAMOTO Mitsuharu
<mituharu@math.s.chiba-u.ac.jp> wrote:
> On Mon, 24 Jun 2019 16:56:45 +0900,
> YAMAMOTO Mitsuharu wrote:
> >
> > An alternative way would be to use rsvg_handle_render_cairo, which is
> > recommended by librsvg, and let it blend with the background color.
> >
> > Patch attached.  Note that this does not require --with-cairo.
> > Raising the required version of librsvg to 2.14 is not a problem, as
> > we are already using rsvg_handle_get_dimensions that requires that
> > version.  Is Windows librsvg DLL compiled with libcairo?
>
> Sorry, wrong patch.  Please try this instead.

Thank you very much, that fixes the problem. Unfortunately, I do not
know about the situation on Windows.

I'm not sure about the additional changes in the attached relative
patch, so feel free to take or leave them as you see fit. The second
call to cairo_set_source_rgb is currently unnecessary, because rsvg
forces the foreground color to black anyway, but that might change one
day (ideally, we'd use the frame foreground color, or even the current
face's foreground color; I have patches here that do this, though they
don't fix rsvg).

@@ -9619,15 +9619,19 @@ svg_load_image (struct frame *f, struct image
*img, char *contents,

   cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
                              width, height);
+  if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
+    goto rsvg_error;
   cairo_t *cr = cairo_create (surface);
   cairo_set_source_rgb (cr, background.red / 65535.0,
             background.green / 65535.0,
             background.blue / 65535.0);
   cairo_paint (cr);
+  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
   rsvg_handle_render_cairo (rsvg_handle, cr);
   cairo_destroy (cr);
   g_object_unref (rsvg_handle);

+  cairo_surface_flush (surface);
   unsigned char *data = cairo_image_surface_get_data (surface);
   int stride = cairo_image_surface_get_stride (surface);
   for (int y = 0; y < height; ++y)
@@ -9636,9 +9640,9 @@ svg_load_image (struct frame *f, struct image
*img, char *contents,
       for (int x = 0; x < width; ++x)
     {
       guint32 rgb = *pixels++;
-      int red   = ((rgb >> 16) & 0xff) << 8;
-      int green = ((rgb >> 8) & 0xff) << 8;
-      int blue  = (rgb & 0xff) << 8;
+      int red   = ((rgb >> 16) & 0xff) * 0x101;
+      int green = ((rgb >> 8) & 0xff) * 0x101;
+      int blue  = (rgb & 0xff) * 0x101;
       PUT_PIXEL (ximg, x, y, lookup_rgb_color (f, red, green, blue));
     }
       data += stride;

[-- Attachment #2: 0001-minor-things.patch --]
[-- Type: text/x-patch, Size: 1691 bytes --]

From 402dbd1e1ff5c33fe9061dd362d3b47a10ac5658 Mon Sep 17 00:00:00 2001
From: Pip Cet <pipcet@gmail.com>
Date: Mon, 24 Jun 2019 16:20:19 +0000
Subject: [PATCH] minor things

---
 src/image.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/image.c b/src/image.c
index 924a188b4a..ce5534b07a 100644
--- a/src/image.c
+++ b/src/image.c
@@ -9619,15 +9619,19 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
 
   cairo_surface_t *surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24,
 							 width, height);
+  if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS)
+    goto rsvg_error;
   cairo_t *cr = cairo_create (surface);
   cairo_set_source_rgb (cr, background.red / 65535.0,
 			background.green / 65535.0,
 			background.blue / 65535.0);
   cairo_paint (cr);
+  cairo_set_source_rgb (cr, 0.0, 0.0, 0.0);
   rsvg_handle_render_cairo (rsvg_handle, cr);
   cairo_destroy (cr);
   g_object_unref (rsvg_handle);
 
+  cairo_surface_flush (surface);
   unsigned char *data = cairo_image_surface_get_data (surface);
   int stride = cairo_image_surface_get_stride (surface);
   for (int y = 0; y < height; ++y)
@@ -9636,9 +9640,9 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
       for (int x = 0; x < width; ++x)
 	{
 	  guint32 rgb = *pixels++;
-	  int red   = ((rgb >> 16) & 0xff) << 8;
-	  int green = ((rgb >> 8) & 0xff) << 8;
-	  int blue  = (rgb & 0xff) << 8;
+	  int red   = ((rgb >> 16) & 0xff) * 0x101;
+	  int green = ((rgb >> 8) & 0xff) * 0x101;
+	  int blue  = (rgb & 0xff) * 0x101;
 	  PUT_PIXEL (ximg, x, y, lookup_rgb_color (f, red, green, blue));
 	}
       data += stride;
-- 
2.20.1


  reply	other threads:[~2019-06-24 16:24 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-20 20:26 bug#36315: 27.0.50; SVG transparency handling is inaccurate Pip Cet
2019-06-20 20:46 ` 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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAOqdjBcsA4ee-KAqpvVAD_mJ4DmVSxHC+9Q1xbqDepmPsFJ39g@mail.gmail.com \
    --to=pipcet@gmail.com \
    --cc=36315@debbugs.gnu.org \
    --cc=mituharu@math.s.chiba-u.ac.jp \
    /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 public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).