Blame SOURCES/13524af2029c2a8a3fb32ef27c39c214d9b5b13c.patch

8740c7
commit 4706031223f6809b40ef7d4c3f14103941621d57
8740c7
Author: Richard Hughes <richard@hughsie.com>
8740c7
Date:   Fri Apr 9 15:20:13 2021 +0100
8740c7
8740c7
    Write BMP data directly without using PIL
8740c7
    
8740c7
    This allows us to drop a build-time dep.
8740c7
8740c7
diff --git a/plugins/uefi-capsule/make-images.py b/plugins/uefi-capsule/make-images.py
8740c7
index f1b00b8d..1d15bcf3 100755
8740c7
--- a/plugins/uefi-capsule/make-images.py
8740c7
+++ b/plugins/uefi-capsule/make-images.py
8740c7
@@ -16,6 +16,8 @@ import argparse
8740c7
 import tarfile
8740c7
 import math
8740c7
 import io
8740c7
+import struct
8740c7
+
8740c7
 from typing import Dict, Optional, Any
8740c7
 
8740c7
 import cairo
8740c7
@@ -24,7 +26,6 @@ import gi
8740c7
 gi.require_version("Pango", "1.0")
8740c7
 gi.require_version("PangoCairo", "1.0")
8740c7
 from gi.repository import Pango, PangoCairo
8740c7
-from PIL import Image
8740c7
 
8740c7
 
8740c7
 def languages(podir: str):
8740c7
@@ -60,6 +61,33 @@ class PotFile:
8740c7
                     continue
8740c7
 
8740c7
 
8740c7
+def _cairo_surface_write_to_bmp(img: cairo.ImageSurface) -> bytes:
8740c7
+
8740c7
+    data = bytes(img.get_data())
8740c7
+    return (
8740c7
+        b"BM"
8740c7
+        + struct.pack(
8740c7
+            "
8740c7
+            54 + len(data),  # size of BMP file
8740c7
+            0,  # unused
8740c7
+            0,  # unused
8740c7
+            54,  # pixel array offset
8740c7
+            40,  # DIB header
8740c7
+            img.get_width(),  # width
8740c7
+            -img.get_height(),  # height (top down)
8740c7
+            1,  # planes
8740c7
+            32,  # BPP
8740c7
+            0,  # no compression
8740c7
+            len(data),  # size of the raw bitmap data
8740c7
+            2835,  # 72DPI H
8740c7
+            2835,  # 72DPI V
8740c7
+            0,  # palette
8740c7
+            0,  # all colors are important
8740c7
+        )
8740c7
+        + data
8740c7
+    )
8740c7
+
8740c7
+
8740c7
 def main(args) -> int:
8740c7
 
8740c7
     # open output archive
8740c7
@@ -164,20 +192,14 @@ def main(args) -> int:
8740c7
                 fs.foreach(do_write, None)
8740c7
                 img.flush()
8740c7
 
8740c7
-                # write PNG
8740c7
-                with io.BytesIO() as io_png:
8740c7
-                    img.write_to_png(io_png)
8740c7
-                    io_png.seek(0)
8740c7
-
8740c7
-                    # convert to BMP and add to archive
8740c7
-                    with io.BytesIO() as io_bmp:
8740c7
-                        pimg = Image.open(io_png)
8740c7
-                        pimg.save(io_bmp, format="BMP")
8740c7
-                        filename = "fwupd-{}-{}-{}.bmp".format(lang, width, height)
8740c7
-                        tarinfo = tarfile.TarInfo(filename)
8740c7
-                        tarinfo.size = io_bmp.tell()
8740c7
-                        io_bmp.seek(0)
8740c7
-                        tar.addfile(tarinfo, fileobj=io_bmp)
8740c7
+                # convert to BMP and add to archive
8740c7
+                with io.BytesIO() as io_bmp:
8740c7
+                    io_bmp.write(_cairo_surface_write_to_bmp(img))
8740c7
+                    filename = "fwupd-{}-{}-{}.bmp".format(lang, width, height)
8740c7
+                    tarinfo = tarfile.TarInfo(filename)
8740c7
+                    tarinfo.size = io_bmp.tell()
8740c7
+                    io_bmp.seek(0)
8740c7
+                    tar.addfile(tarinfo, fileobj=io_bmp)
8740c7
 
8740c7
     # success
8740c7
     return 0
8740c7
diff --git a/po/test-deps b/po/test-deps
8740c7
index f5276daa..27b4055b 100755
8740c7
--- a/po/test-deps
8740c7
+++ b/po/test-deps
8740c7
@@ -34,12 +34,6 @@ except ValueError:
8740c7
     print("Error: missing cairo gobject introspection library")
8740c7
     err = 1
8740c7
 
8740c7
-try:
8740c7
-    from PIL import Image
8740c7
-except ImportError:
8740c7
-    print("Error: missing dependency python pillow (python3-pil)")
8740c7
-    err = 1
8740c7
-
8740c7
 try:
8740c7
     import cairo
8740c7
 except ImportError: