fwupd/13524af2029c2a8a3fb32ef27c39c214d9b5b13c.patch

85 lines
2.5 KiB
Diff
Raw Normal View History

commit 4706031223f6809b40ef7d4c3f14103941621d57
Author: Richard Hughes <richard@hughsie.com>
Date: Fri Apr 9 15:20:13 2021 +0100
Write BMP data directly without using PIL
This allows us to drop a build-time dep.
diff --git a/po/make-images b/po/make-images
index b1097bc2..c3cad9e7 100755
--- a/po/make-images
+++ b/po/make-images
@@ -18,7 +18,6 @@ import gi
gi.require_version('Pango', '1.0')
gi.require_version('PangoCairo', '1.0')
from gi.repository import Pango, PangoCairo
-from PIL import Image
def usage(return_code):
""" print usage and exit with the supplied return code """
@@ -29,6 +28,32 @@ def usage(return_code):
out.write("usage: make-images <label text> <mo file directory> <LINGUAS> <installdir>")
sys.exit(return_code)
+def _cairo_surface_write_to_bmp(img: cairo.ImageSurface) -> bytes:
+
+ data = bytes(img.get_data())
+ return (
+ b"BM"
+ + struct.pack(
+ "<ihhiiiihhiiiiii",
+ 54 + len(data), # size of BMP file
+ 0, # unused
+ 0, # unused
+ 54, # pixel array offset
+ 40, # DIB header
+ img.get_width(), # width
+ -img.get_height(), # height (top down)
+ 1, # planes
+ 32, # BPP
+ 0, # no compression
+ len(data), # size of the raw bitmap data
+ 2835, # 72DPI H
+ 2835, # 72DPI V
+ 0, # palette
+ 0, # all colors are important
+ )
+ + data
+ )
+
class Rasterizer:
""" Rasterize some text """
@@ -140,11 +165,8 @@ class Rasterizer:
os.mkdir(d, 0o755)
d = os.path.split(filename)[0]
make_dir(d)
- img.write_to_png(filename)
- pimg = Image.open(filename)
- img = pimg.copy()
- del pimg
- img.save(filename)
+ with open(filename, "wb") as f:
+ f.write(_cairo_surface_write_to_bmp(img))
for lang in self.languages:
#print("lang:\"%s\" string:\"%s\"" % (lang, string))
diff --git a/po/test-deps b/po/test-deps
index f5276daa..27b4055b 100755
--- a/po/test-deps
+++ b/po/test-deps
@@ -34,12 +34,6 @@ except ValueError:
print("Error: missing cairo gobject introspection library")
err = 1
-try:
- from PIL import Image
-except ImportError:
- print("Error: missing dependency python pillow (python3-pil)")
- err = 1
-
try:
import cairo
except ImportError: