unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#67968: [PATCH] A small patch to make emacs support transparent image (png, webp, svg)
       [not found] <CACph+bW99OiFn2c_yWy_vE3nw90ZLwmPES-uCuu=JYdQtHhubQ@mail.gmail.com>
@ 2023-12-22 11:38 ` Qiutum
  2023-12-24 14:36   ` Stefan Kangas
  2024-03-10 20:50   ` nsan
  0 siblings, 2 replies; 3+ messages in thread
From: Qiutum @ 2023-12-22 11:38 UTC (permalink / raw)
  To: 67968


[-- Attachment #1.1: Type: text/plain, Size: 819 bytes --]

Hi everyone,

Recently, I've been reading the code of image.c and wondering how to make
emacs support transparent image. Then I find that a small change on the
src/image.c can make it worked (and wonder why this have not been solved
since the solution is so simple).

This patch can support the transparent png, webp and svg. The core of the
patch is to change the code,

 PUT_PIXEL (mask_img, x, y, *p > 0 ? PIX_MASK_DRAW : PIX_MASK_RETAIN);

to

 PUT_PIXEL (mask_img, x, y, *p > 0 ? *p : PIX_MASK_RETAIN);

Then all worked like a magic.

I have checked my patch in linux by default configure option "../configure"
for dwm and pgtk build for hyprland, both are fine. I don't know whether it
could support other platforms since I don't have them.

Please check my patch and happy to hear comments.

Best regards,
Zhang

[-- Attachment #1.2: Type: text/html, Size: 1193 bytes --]

[-- Attachment #2: support-image-transparent.patch --]
[-- Type: application/x-patch, Size: 9393 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#67968: [PATCH] A small patch to make emacs support transparent image (png, webp, svg)
  2023-12-22 11:38 ` bug#67968: [PATCH] A small patch to make emacs support transparent image (png, webp, svg) Qiutum
@ 2023-12-24 14:36   ` Stefan Kangas
  2024-03-10 20:50   ` nsan
  1 sibling, 0 replies; 3+ messages in thread
From: Stefan Kangas @ 2023-12-24 14:36 UTC (permalink / raw)
  To: Qiutum; +Cc: 67968

Qiutum <zh4710jj@gmail.com> writes:

> Hi everyone,
>
> Recently, I've been reading the code of image.c and wondering how to make emacs support transparent image. Then I find that a small change on the
> src/image.c can make it worked (and wonder why this have not been solved since the solution is so simple).
>
> This patch can support the transparent png, webp and svg. The core of the patch is to change the code,
>
>  PUT_PIXEL (mask_img, x, y, *p > 0 ? PIX_MASK_DRAW : PIX_MASK_RETAIN);
>
> to
>
>  PUT_PIXEL (mask_img, x, y, *p > 0 ? *p : PIX_MASK_RETAIN);
>
> Then all worked like a magic.
>
> I have checked my patch in linux by default configure option "../configure" for dwm and pgtk build for hyprland, both are fine. I don't know whether it
> could support other platforms since I don't have them.
>
> Please check my patch and happy to hear comments.

I thought we already supported transparency in png, webp and svg?

Could you please explain more about the problem you are trying to solve?





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#67968: [PATCH] A small patch to make emacs support transparent image (png, webp, svg)
  2023-12-22 11:38 ` bug#67968: [PATCH] A small patch to make emacs support transparent image (png, webp, svg) Qiutum
  2023-12-24 14:36   ` Stefan Kangas
@ 2024-03-10 20:50   ` nsan
  1 sibling, 0 replies; 3+ messages in thread
From: nsan @ 2024-03-10 20:50 UTC (permalink / raw)
  To: 67968

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

 

Hi Qiutum,

I can confirm that this patch works great on pgtk (sway). Thank you for
this!

Let me explain the problem it solves. The problem arises mostly for
users of the frame parameter alpha-background. Having set the
alpha-background sufficiently low, it becomes apparent that Emacs
doesn't *really* support transparency for these image types. Instead, it
either fills the background with the background color of the frame (png
& svg) or supports only a binary form of transparency (webp).

Here are some screenshots which show the difference, with
alpha-background set to 50 with
(set-frame-parameter nil 'alpha-background 50)

The svg is created with
(let ((svg (svg-create 100 100 :stroke-width 10)))
 (svg-circle svg 50 50 25 :fill "none" :stroke "black")
 (insert-image (svg-image svg)))

The png is the logo at
https://de.wikipedia.org/wiki/Portable_Network_Graphics and the webp is
the same image exported to webp.

 (I hope these images will show fine in the mailing list.)

SVG before (no transparency):

SVG after:

PNG before (note also that the G is rather gray instead of the correct
blue. The tint seems generally off due to the partial transparency of
the source):

PNG after:

webp before (note the binary transparency):

webp after partial transparency):

Best regards,
Nate

 

[-- Attachment #2.1: Type: text/html, Size: 2030 bytes --]

[-- Attachment #2.2: 0b5d9bc6.png --]
[-- Type: image/png, Size: 80093 bytes --]

[-- Attachment #2.3: 25e3531c.png --]
[-- Type: image/png, Size: 89982 bytes --]

[-- Attachment #2.4: 103f5ff5.png --]
[-- Type: image/png, Size: 37163 bytes --]

[-- Attachment #2.5: bbe58141.png --]
[-- Type: image/png, Size: 136647 bytes --]

[-- Attachment #2.6: 1006f992.png --]
[-- Type: image/png, Size: 89747 bytes --]

[-- Attachment #2.7: e747bf70.png --]
[-- Type: image/png, Size: 68822 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-03-10 20:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CACph+bW99OiFn2c_yWy_vE3nw90ZLwmPES-uCuu=JYdQtHhubQ@mail.gmail.com>
2023-12-22 11:38 ` bug#67968: [PATCH] A small patch to make emacs support transparent image (png, webp, svg) Qiutum
2023-12-24 14:36   ` Stefan Kangas
2024-03-10 20:50   ` nsan

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).