Backport a patch from master to drop the python3-pillow dep

Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1935838
This commit is contained in:
Richard Hughes 2021-04-12 14:25:36 +01:00
parent ee5fe5435e
commit 7dc4a40303
2 changed files with 93 additions and 2 deletions

View File

@ -0,0 +1,84 @@
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:

View File

@ -44,11 +44,14 @@
Summary: Firmware update daemon
Name: fwupd
Version: 1.5.5
Release: 2%{?dist}
Release: 3%{?dist}
License: LGPLv2+
URL: https://github.com/fwupd/fwupd
Source0: http://people.freedesktop.org/~hughsient/releases/%{name}-%{version}.tar.xz
# backport from upstream
Patch0: 13524af2029c2a8a3fb32ef27c39c214d9b5b13c.patch
BuildRequires: gettext
BuildRequires: glib2-devel >= %{glib2_version}
BuildRequires: libxmlb-devel >= %{libxmlb_version}
@ -89,7 +92,7 @@ BuildRequires: libqmi-devel >= 1.22.0
%if 0%{?have_uefi}
BuildRequires: efivar-devel >= 33
BuildRequires: python3 python3-cairo python3-gobject python3-pillow
BuildRequires: python3 python3-cairo python3-gobject
BuildRequires: pango-devel
BuildRequires: cairo-devel cairo-gobject-devel
BuildRequires: freetype
@ -471,6 +474,10 @@ done
%endif
%changelog
* Mon Apr 12 2021 Richard Hughes <richard@hughsie.com> 1.5.5-3
- Backport a patch from master to drop the python3-pillow dep
- Resolves: rhbz#1935838
* Tue Jan 26 2021 Fedora Release Engineering <releng@fedoraproject.org> - 1.5.5-2
- Rebuilt for https://fedoraproject.org/wiki/Fedora_34_Mass_Rebuild