unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Pascal Quesseveur <pquessev@gmail.com>
To: Alan Third <alan@idiocy.org>
Cc: Eli Zaretskii <eliz@gnu.org>, Lars Ingebrigtsen <larsi@gnus.org>,
	56182@debbugs.gnu.org
Subject: bug#56182: 28.1; Display of SVG file with transparent background is incorrect
Date: Tue, 28 Jun 2022 20:38:11 +0200	[thread overview]
Message-ID: <82pmis3a7g.fsf@gmail.com> (raw)
In-Reply-To: <Yrc4otF6syz/rO6k@idiocy.org> (Alan Third's message of "Sat, 25 Jun 2022 17:32:34 +0100")

>"AT" == Alan Third <alan@idiocy.org> a écrit :

  AT> I can't reproduce it.

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. For what it's worth I managed
to work around the problem in lisp. With version 27.1 I had
implemented an advice to improve the taking into account of the
background color in the style of SVG file. So I extended that advice
to solve my problem.

(defun qsr/create-image (orig-fun file-or-data &optional type data-p &rest props)
  "Advice around create-image. When image type is SVG, look for a
background color in SVG style and define this color as background
property in returned image.

When emacs 28 on Windows correct background color."
  (let ((data-format
         (and data-p (or (plist-get props :format) t))))
    (setq type (ignore-error unknown-image-type
                 (image-type file-or-data type data-format)))
    (let ((image (apply orig-fun file-or-data type data-p props))
          color)
      (when image
        ;; Regexp to match
        ;; <svg xmlns="http://www" style="width:566px;background:#dddddd;"
        ;; or
        ;; <style ..>...background-color::#dddddd;...</style>
        (if (and (eq type 'svg) data-p
                 (or (string-match
                      "<svg[^>]*\\<style=\"[^\"]*\\<background[^:]*:\\([^;]*\\);"
                      file-or-data)
                     (string-match
                      "<style[^<]*background-color: *\\([^;]*\\);"
                      file-or-data)))
            (setq color (match-string 1 file-or-data))
          ;; No color defined in svg element, use default background.
          (setq color (face-attribute 'default :background))
          (when (and (= emacs-major-version 28)
                     (eq system-type 'windows-nt))
            ;; When emacs 28 transform color.
            (let ((crgb (color-values color))
                  (gamma (frame-parameter nil 'screen-gamma)))
              (when crgb
                (let ((r (elt crgb 0))
                      (g (elt crgb 1))
                      (b (elt crgb 2)))
                  ;; If screen gamma correction is defined in frame
                  ;; parameters, inverse gamma correction.
                  (when gamma
                    (let ((invgc (* gamma 0.45445)))
                      ;; are r g b always 2 bytes?
                      (setq r (* (expt (/ r 65535.0) invgc) 65535.0)
                            g (* (expt (/ g 65535.0) invgc) 65535.0)
                            b (* (expt (/ b 65535.0) invgc) 65535.0))))
                  ;; color is defined as BGR.
                  (setq color (format "#%4X%4X%4X" b g r)))
                )))
          )
        (setq image (nconc image (list :background color))))
      image)))
    
(advice-add 'create-image :around #'qsr/create-image)


-- 
Pascal Quesseveur
pquessev@gmail.com





  parent reply	other threads:[~2022-06-28 18:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-24  6:30 bug#56182: 28.1; Display of SVG file with transparent background is incorrect Pascal Quesseveur
2022-06-24  9:23 ` Lars Ingebrigtsen
2022-06-24 12:18   ` Pascal Quesseveur
2022-06-25  9:25   ` Eli Zaretskii
2022-06-25 16:32     ` Alan Third
2022-06-27  6:49       ` Pascal Quesseveur
2022-06-27  8:12       ` Pascal Quesseveur
2022-06-28 18:38       ` Pascal Quesseveur [this message]
2022-06-28 19:45         ` Alan Third
2022-06-29  2:26           ` Eli Zaretskii
2023-09-09 12:09         ` Alan Third
2023-09-11 19:10           ` Alan Third
2023-09-12 13:55             ` Corwin Brust
2023-09-12 14:22               ` Eli Zaretskii
2023-09-12 17:01                 ` Corwin Brust
2023-09-12 14:19             ` Eli Zaretskii
2023-09-13 19:21               ` Alan Third

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=82pmis3a7g.fsf@gmail.com \
    --to=pquessev@gmail.com \
    --cc=56182@debbugs.gnu.org \
    --cc=alan@idiocy.org \
    --cc=eliz@gnu.org \
    --cc=larsi@gnus.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 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).