all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] system: grub: Convert grub background using rsvg-convert
@ 2015-08-23 18:23 Mark H Weaver
  2015-08-27 21:19 ` Ludovic Courtès
  0 siblings, 1 reply; 9+ messages in thread
From: Mark H Weaver @ 2015-08-23 18:23 UTC (permalink / raw)
  To: guix-devel

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

This patch modifies 'svg->png' in (gnu system grub) to use rsvg-convert
instead of inkscape.  Inkscape is a rather heavy dependency to convert
an image.  This is important for users who choose to avoid binary
substitutes.

The main difficulty here was that our SVG artwork is partially
transparent, and includes a "Background" layer with a checker-board
pattern.  I guess this layer is for convenience when editing in
Inkscape, and apparently Inkscape excludes the "Background" layer when
exporting to png.  Other tools render all layers.  Therefore, avoiding
Inkscape required code to remove that layer before conversion to png.

Comments and suggestions welcome,

      Mark



[-- Attachment #2: [PATCH] system: grub: Convert grub background using rsvg-convert --]
[-- Type: text/x-patch, Size: 4638 bytes --]

From 0b3066420f72ecf15b65406bd417768450bfcac7 Mon Sep 17 00:00:00 2001
From: Mark H Weaver <mhw@netris.org>
Date: Wed, 19 Aug 2015 17:26:02 -0400
Subject: [PATCH] system: grub: Convert grub background using rsvg-convert, not
 inkscape.

* gnu/system/grub.scm (svg->png): Accept additional arguments 'width' and
  'height'.  Reimplement using rsvg-convert and emacs instead of inkscape.
  (resize-image): Remove.
  (grub-background-image): Remove 'resize-image' step.  Pass 'width' and
  'height' to 'svg->png'.
---
 gnu/system/grub.scm | 57 +++++++++++++++++++++++++++++++++--------------------
 1 file changed, 36 insertions(+), 21 deletions(-)

diff --git a/gnu/system/grub.scm b/gnu/system/grub.scm
index e49b6db..fe7400a 100644
--- a/gnu/system/grub.scm
+++ b/gnu/system/grub.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -26,8 +27,8 @@
   #:use-module (guix download)
   #:use-module (gnu artwork)
   #:autoload   (gnu packages grub) (grub)
-  #:autoload   (gnu packages inkscape) (inkscape)
-  #:autoload   (gnu packages imagemagick) (imagemagick)
+  #:autoload   (gnu packages emacs) (emacs)
+  #:autoload   (gnu packages gnome) (librsvg)
   #:autoload   (gnu packages compression) (gzip)
   #:use-module (ice-9 match)
   #:use-module (srfi srfi-1)
@@ -119,25 +120,40 @@
 ;;; Background image & themes.
 ;;;
 
-(define (svg->png svg)
+(define (svg->png svg width height)
   "Build a PNG from SVG."
   ;; Don't use #:local-build? so that it's substitutable.
-  (gexp->derivation "grub-image.png"
-                    #~(zero?
-                       (system* (string-append #$inkscape "/bin/inkscape")
-                                "--without-gui"
-                                (string-append "--export-png=" #$output)
-                                #$svg))))
-
-(define (resize-image image width height)
-  "Resize IMAGE to WIDTHxHEIGHT."
-  ;; Don't use #:local-build? so that it's substitutable.
-  (let ((size (string-append (number->string width)
-                             "x" (number->string height))))
-    (gexp->derivation "grub-image.resized.png"
-                      #~(zero?
-                         (system* (string-append #$imagemagick "/bin/convert")
-                                  "-resize" #$size #$image #$output)))))
+  (let ((width  (number->string width))
+        (height (number->string height)))
+    (gexp->derivation
+     "grub-image.png"
+     #~(begin
+         (use-modules (guix build emacs-utils))
+         (let ((image-file "/tmp/image.svg"))
+           ;; The SVG images in the guix-artwork repository contain a bottom
+           ;; "Background" layer containing a checkerboard pattern.  Here we
+           ;; remove that layer.
+           (copy-file #$svg image-file)
+           (chmod image-file #o644)
+           (parameterize ((%emacs (string-append #$emacs "/bin/emacs")))
+             (emacs-batch-edit-file image-file
+               '(progn (goto-char (point-min))
+                       (when (re-search-forward "inkscape:label=\"Background\""
+                                                nil nil)
+                         (nxml-backward-up-element)
+                         (set-mark (point))
+                         (nxml-forward-element)
+                         (kill-region (mark) (point))
+                         (basic-save-buffer)))))
+           (zero?
+            (system* (string-append #$librsvg "/bin/rsvg-convert")
+                     "--width" #$width
+                     "--height" #$height
+                     "--background-color" "black"
+                     "--format" "png"
+                     "--output" #$output
+                     image-file))))
+     #:modules '((guix build emacs-utils)))))
 
 (define* (grub-background-image config #:key (width 640) (height 480))
   "Return the GRUB background image defined in CONFIG with a ratio of
@@ -147,8 +163,7 @@ WIDTH/HEIGHT, or #f if none was found."
                         (= (grub-image-aspect-ratio image) ratio))
                       (grub-theme-images (grub-configuration-theme config)))))
     (if image
-        (mlet %store-monad ((png (svg->png (grub-image-file image))))
-          (resize-image png width height))
+        (svg->png (grub-image-file image) width height)
         (with-monad %store-monad
           (return #f)))))
 
-- 
2.5.0


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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-23 18:23 [PATCH] system: grub: Convert grub background using rsvg-convert Mark H Weaver
@ 2015-08-27 21:19 ` Ludovic Courtès
  2015-08-28 17:15   ` Luis Felipe López Acevedo
  0 siblings, 1 reply; 9+ messages in thread
From: Ludovic Courtès @ 2015-08-27 21:19 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guix-devel, Luis Felipe López Acevedo

Mark H Weaver <mhw@netris.org> skribis:

> This patch modifies 'svg->png' in (gnu system grub) to use rsvg-convert
> instead of inkscape.  Inkscape is a rather heavy dependency to convert
> an image.  This is important for users who choose to avoid binary
> substitutes.

Good idea.

> The main difficulty here was that our SVG artwork is partially
> transparent, and includes a "Background" layer with a checker-board
> pattern.  I guess this layer is for convenience when editing in
> Inkscape, and apparently Inkscape excludes the "Background" layer when
> exporting to png.  Other tools render all layers.  Therefore, avoiding
> Inkscape required code to remove that layer before conversion to png.

Fun.  :-)

If possible, I would rather remove said layer directly in the
guix-artwork repo, or somehow make that layer invisible to
rsvg-convert.  Luis Felipe: What’s your take on this?

Thanks,
Ludo’.

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-27 21:19 ` Ludovic Courtès
@ 2015-08-28 17:15   ` Luis Felipe López Acevedo
  2015-08-28 18:24     ` Mark H Weaver
  2015-08-31  8:57     ` Andy Wingo
  0 siblings, 2 replies; 9+ messages in thread
From: Luis Felipe López Acevedo @ 2015-08-28 17:15 UTC (permalink / raw)
  To: ludo; +Cc: guix-devel

On 2015-08-27 16:19, ludo@gnu.org wrote:
> Mark H Weaver <mhw@netris.org> skribis:
> 
>> This patch modifies 'svg->png' in (gnu system grub) to use 
>> rsvg-convert
>> instead of inkscape.  Inkscape is a rather heavy dependency to convert
>> an image.  This is important for users who choose to avoid binary
>> substitutes.
> 
> Good idea.

Sorry, I didn't see Mark's message because I'm away from the keyboard 
these days and inactive on the list, and I don't know until when.

>> The main difficulty here was that our SVG artwork is partially
>> transparent, and includes a "Background" layer with a checker-board
>> pattern.  I guess this layer is for convenience when editing in
>> Inkscape, and apparently Inkscape excludes the "Background" layer when
>> exporting to png.  Other tools render all layers.  Therefore, avoiding
>> Inkscape required code to remove that layer before conversion to png.
> 
> Fun.  :-)
> 
> If possible, I would rather remove said layer directly in the
> guix-artwork repo, or somehow make that layer invisible to
> rsvg-convert.  Luis Felipe: What’s your take on this?

If I understand correctly, the problem is transparency, right? I don't 
understand why transparency would be an issue when exporting PNG images, 
but I don't know how rsvg works.

In any case, the SVG has transparency in several parts:

- The logo.
- The checkerboard pattern (which is part of the design as in the slim 
login screen).
- The document/page background (inkscape:pageopacity="0").

Modifying the first to be fully opaque is time consuming, but can be 
done.

The checkerboard transparency is used to blend the little squares with 
the gradient of the dark rectangle bellow it. Making it opaque would 
break the design. So the only option I see there is to remove it.

The document background is what Inkscape refers to as "Background" when 
you export the PNG image from the command line:

     $ inkscape -e test-4-3.png GuixSD-fully-black-4-3.svg
     Background RRGGBBAA: ffffff00
     Area 0:0:1024:768 exported to 1024 x 768 pixels (90 dpi)
     Bitmap saved as: test-4-3.png

Modifying the document background does not affect the design at all, 
because we are using the dark rectangle on top of it as the background 
of the image, so it doesn't matter what the background of the document 
is.

Could it be that rsvg-convert is complaining about transparency in the 
page/document background and not about the transparency of the 
checkerboard pattern in the "Background" layer? Because it is not 
complaining about the transparency in the layer that contains the logo 
(which has transparency as well), is it?

If you want to try modifying only the document opacity, set 
«inkscape:pageopacity="0"» to 1. Graphically, this can be done from the 
Document Properties window in Inkscape (Shift+Ctrl+D). But I bet you 
already did that...

:(

-- 
Luis Felipe López Acevedo
http://sirgazil.bitbucket.org/

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-28 17:15   ` Luis Felipe López Acevedo
@ 2015-08-28 18:24     ` Mark H Weaver
  2015-08-28 22:38       ` Luis Felipe López Acevedo
  2015-08-29 13:55       ` Luis Felipe López Acevedo
  2015-08-31  8:57     ` Andy Wingo
  1 sibling, 2 replies; 9+ messages in thread
From: Mark H Weaver @ 2015-08-28 18:24 UTC (permalink / raw)
  To: Luis Felipe López Acevedo; +Cc: guix-devel

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

Hi Luis, thanks for the quick response.

Luis Felipe López Acevedo <felipe.lopez@openmailbox.org> writes:

> On 2015-08-27 16:19, ludo@gnu.org wrote:
>> Mark H Weaver <mhw@netris.org> skribis:
>>
>>> The main difficulty here was that our SVG artwork is partially
>>> transparent, and includes a "Background" layer with a checker-board
>>> pattern.  I guess this layer is for convenience when editing in
>>> Inkscape, and apparently Inkscape excludes the "Background" layer when
>>> exporting to png.  Other tools render all layers.  Therefore, avoiding
>>> Inkscape required code to remove that layer before conversion to png.
>>
>> Fun.  :-)
>>
>> If possible, I would rather remove said layer directly in the
>> guix-artwork repo, or somehow make that layer invisible to
>> rsvg-convert.  Luis Felipe: What’s your take on this?
>
> If I understand correctly, the problem is transparency, right? I don't
> understand why transparency would be an issue when exporting PNG
> images, but I don't know how rsvg works.
>
> In any case, the SVG has transparency in several parts:
>
> - The logo.
> - The checkerboard pattern (which is part of the design as in the slim
> login screen).

Ah, okay, so my guesses were incorrect.  I guess the problem is actually
that rsvg-convert (from librsvg) fails to render these SVG files
correctly.  Here's how it renders grub/GuixSD-fully-black-4-3.svg on a
black background:

rsvg-convert --width 640 --height 480 --background-color black \
             --format png --output ~/grub-background.png \
             grub/GuixSD-fully-black-4-3.svg


[-- Attachment #2: rsvg-convert rendering of grub/GuixSD-fully-black-4-3.svg --]
[-- Type: image/png, Size: 71145 bytes --]

[-- Attachment #3: Type: text/plain, Size: 309 bytes --]


> Modifying the first to be fully opaque is time consuming, but can be
> done.

No need, we should keep the source file in the preferred form for
editing.  I'll see if I can figure out what librsvg is doing wrong,
and in the meantime we can keep using inkscape to do the conversion.

Thanks again,

    Mark

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-28 18:24     ` Mark H Weaver
@ 2015-08-28 22:38       ` Luis Felipe López Acevedo
  2015-08-29 13:55       ` Luis Felipe López Acevedo
  1 sibling, 0 replies; 9+ messages in thread
From: Luis Felipe López Acevedo @ 2015-08-28 22:38 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guix-devel

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

On 2015-08-28 13:24, Mark H Weaver wrote:
> Hi Luis, thanks for the quick response.
> 
> Luis Felipe López Acevedo <felipe.lopez@openmailbox.org> writes:
> 
>> On 2015-08-27 16:19, ludo@gnu.org wrote:
>>> Mark H Weaver <mhw@netris.org> skribis:
>>> 
>>>> The main difficulty here was that our SVG artwork is partially
>>>> transparent, and includes a "Background" layer with a checker-board
>>>> pattern.  I guess this layer is for convenience when editing in
>>>> Inkscape, and apparently Inkscape excludes the "Background" layer 
>>>> when
>>>> exporting to png.  Other tools render all layers.  Therefore, 
>>>> avoiding
>>>> Inkscape required code to remove that layer before conversion to 
>>>> png.
>>> 
>>> Fun.  :-)
>>> 
>>> If possible, I would rather remove said layer directly in the
>>> guix-artwork repo, or somehow make that layer invisible to
>>> rsvg-convert.  Luis Felipe: What’s your take on this?
>> 
>> If I understand correctly, the problem is transparency, right? I don't
>> understand why transparency would be an issue when exporting PNG
>> images, but I don't know how rsvg works.
>> 
>> In any case, the SVG has transparency in several parts:
>> 
>> - The logo.
>> - The checkerboard pattern (which is part of the design as in the slim
>> login screen).
> 
> Ah, okay, so my guesses were incorrect.  I guess the problem is 
> actually
> that rsvg-convert (from librsvg) fails to render these SVG files
> correctly.  Here's how it renders grub/GuixSD-fully-black-4-3.svg on a
> black background:
> 
> rsvg-convert --width 640 --height 480 --background-color black \
>              --format png --output ~/grub-background.png \
>              grub/GuixSD-fully-black-4-3.svg
> 
> 
> 
>> Modifying the first to be fully opaque is time consuming, but can be
>> done.
> 
> No need, we should keep the source file in the preferred form for
> editing.  I'll see if I can figure out what librsvg is doing wrong,
> and in the meantime we can keep using inkscape to do the conversion.
> 
> Thanks again,
> 
>     Mark

OK, so the culprit is the checkerboard pattern. I generated it with 
Inkscape, and it seems that it uses raster images instead of SVG. I 
tried doing one by hand and it works alright with rsvg-convert (see 
attached SVG).

I would commit changes directly to the repo, but I don't have a computer 
right now where I can install my tools. If you want, I can modify the 
files that use the checkerboard pattern this Saturday or Sunday and send 
them to you to put them in the repo.

Is that OK?

-- 
Luis Felipe López Acevedo
http://sirgazil.bitbucket.org/

[-- Attachment #2: GuixSD-fully-black-4-3.svg --]
[-- Type: image/svg+xml, Size: 574226 bytes --]

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-28 18:24     ` Mark H Weaver
  2015-08-28 22:38       ` Luis Felipe López Acevedo
@ 2015-08-29 13:55       ` Luis Felipe López Acevedo
  1 sibling, 0 replies; 9+ messages in thread
From: Luis Felipe López Acevedo @ 2015-08-29 13:55 UTC (permalink / raw)
  To: Mark H Weaver; +Cc: guix-devel

Here are the grub SVGs with vector checkerboard:

https://cloud.openmailbox.org/index.php/s/uBM9iQ3oLLjjIZX

So no need for Inkscape anymore :)

-- 
Luis Felipe López Acevedo
http://sirgazil.bitbucket.org/

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-28 17:15   ` Luis Felipe López Acevedo
  2015-08-28 18:24     ` Mark H Weaver
@ 2015-08-31  8:57     ` Andy Wingo
  2015-08-31 21:05       ` Ludovic Courtès
  2015-10-17 13:17       ` Ludovic Courtès
  1 sibling, 2 replies; 9+ messages in thread
From: Andy Wingo @ 2015-08-31  8:57 UTC (permalink / raw)
  To: Luis Felipe López Acevedo; +Cc: guix-devel

On Fri 28 Aug 2015 19:15, Luis Felipe López Acevedo <felipe.lopez@openmailbox.org> writes:

> Modifying the document background does not affect the design at all,
> because we are using the dark rectangle on top of it as the background
> of the image, so it doesn't matter what the background of the document
> is.
>
> Could it be that rsvg-convert is complaining about transparency in the
> page/document background and not about the transparency of the
> checkerboard pattern in the "Background" layer? Because it is not
> complaining about the transparency in the layer that contains the logo
> (which has transparency as well), is it?

We could use guile-cairo / guile-rsvg to convert, fwiw.  Better to do
that than to cause our graphics people to modify the image.

  (use-modules (rsvg) (cairo))

  (define (->int x) (inexact->exact (ceiling x)))

  (define (render-to-png in-svg out-png)
    (let ((svg (rsvg-handle-new-from-file in-svg)))
      (call-with-values (lambda () (rsvg-handle-get-dimensions svg))
        (lambda (width height em ex)
          (let* ((surf (cairo-image-surface-create 'argb32
                                                   (->int width)
                                                   (->int height)))
                 (cr (cairo-create surf)))
            (rsvg-handle-render-cairo svg cr)
            (cairo-surface-flush surf)
            (cairo-surface-write-to-png (cairo-get-target cr) out-png))))))

That will render a png with the svg's natural pixel dimensions.  You can
use the png as is, or instead of rendering to a png you could use "surf"
as a source surface for other paint operations, for example if you want
to down-scale the image nicely.  Here's an example, for a suitable
definition of create-image-surface and scale-dimensions:

  (call-with-values (lambda () (create-image-surface filename width height))
    (lambda (surface swidth sheight)
      (if surface
          (call-with-values (lambda () (scale-dimensions (/ swidth 1.0 sheight)))
            (lambda (x0 y0 width height)
              (cairo-save cr)
              (cairo-translate cr x0 y0)
              (cairo-scale cr (/ width swidth) (/ height sheight))
              (cairo-set-source-surface cr surface 0 0)
              (cairo-pattern-set-filter (cairo-get-source cr) 'best)
              (cairo-rectangle cr 0 0 swidth sheight)
              (cairo-fill cr)
              (cairo-restore cr)
              (values width height)))
          (values 0 0))))

FWIW :)

Cheers,

Andy

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-31  8:57     ` Andy Wingo
@ 2015-08-31 21:05       ` Ludovic Courtès
  2015-10-17 13:17       ` Ludovic Courtès
  1 sibling, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2015-08-31 21:05 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guix-devel, Luis Felipe López Acevedo

Andy Wingo <wingo@igalia.com> skribis:

> We could use guile-cairo / guile-rsvg to convert, fwiw.  Better to do
> that than to cause our graphics people to modify the image.

Indeed, that sounds even better.

I had an old stash with Guile-{RSVG,Present}, so I’ve just finished it
and pushed.

Would you like to rewrite ‘svg->png’ in (gnu system grub) the way you
suggested?  :-)

A helper module, say (gnu build images) would probably be needed.

Thanks,
Ludo’.

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

* Re: [PATCH] system: grub: Convert grub background using rsvg-convert
  2015-08-31  8:57     ` Andy Wingo
  2015-08-31 21:05       ` Ludovic Courtès
@ 2015-10-17 13:17       ` Ludovic Courtès
  1 sibling, 0 replies; 9+ messages in thread
From: Ludovic Courtès @ 2015-10-17 13:17 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guix-devel, Luis Felipe López Acevedo

Andy Wingo <wingo@igalia.com> skribis:

> On Fri 28 Aug 2015 19:15, Luis Felipe López Acevedo <felipe.lopez@openmailbox.org> writes:
>
>> Modifying the document background does not affect the design at all,
>> because we are using the dark rectangle on top of it as the background
>> of the image, so it doesn't matter what the background of the document
>> is.
>>
>> Could it be that rsvg-convert is complaining about transparency in the
>> page/document background and not about the transparency of the
>> checkerboard pattern in the "Background" layer? Because it is not
>> complaining about the transparency in the layer that contains the logo
>> (which has transparency as well), is it?
>
> We could use guile-cairo / guile-rsvg to convert, fwiw.  Better to do
> that than to cause our graphics people to modify the image.
>
>   (use-modules (rsvg) (cairo))
>
>   (define (->int x) (inexact->exact (ceiling x)))
>
>   (define (render-to-png in-svg out-png)
>     (let ((svg (rsvg-handle-new-from-file in-svg)))
>       (call-with-values (lambda () (rsvg-handle-get-dimensions svg))
>         (lambda (width height em ex)
>           (let* ((surf (cairo-image-surface-create 'argb32
>                                                    (->int width)
>                                                    (->int height)))
>                  (cr (cairo-create surf)))
>             (rsvg-handle-render-cairo svg cr)
>             (cairo-surface-flush surf)
>             (cairo-surface-write-to-png (cairo-get-target cr) out-png))))))

FWIW I tried this (finally!) and this has the same problem as
‘rsvg-convert’ regarding the checkerboard pattern.

So maybe we need to apply Felipe’s changes anyway?  Thoughts?

Ludo’.

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

end of thread, other threads:[~2015-10-17 13:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-23 18:23 [PATCH] system: grub: Convert grub background using rsvg-convert Mark H Weaver
2015-08-27 21:19 ` Ludovic Courtès
2015-08-28 17:15   ` Luis Felipe López Acevedo
2015-08-28 18:24     ` Mark H Weaver
2015-08-28 22:38       ` Luis Felipe López Acevedo
2015-08-29 13:55       ` Luis Felipe López Acevedo
2015-08-31  8:57     ` Andy Wingo
2015-08-31 21:05       ` Ludovic Courtès
2015-10-17 13:17       ` Ludovic Courtès

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.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.