mirror of
https://git.proxmox.com/git/fwupd
synced 2025-08-13 17:12:19 +00:00
Write BMP data directly without using PIL
This allows us to drop a build-time dep.
This commit is contained in:
parent
4483f609f1
commit
13524af202
@ -8,7 +8,6 @@ extraction:
|
||||
- python3-gi
|
||||
- libarchive-tools
|
||||
- libcogl-pango-dev
|
||||
- python3-pil
|
||||
- python3-pip
|
||||
- python3-setuptools
|
||||
- python3-wheel
|
||||
|
@ -9,7 +9,7 @@ arch=('i686' 'x86_64')
|
||||
url='https://github.com/fwupd/fwupd'
|
||||
license=('GPL2')
|
||||
depends=('libgusb' 'modemmanager' 'tpm2-tss')
|
||||
makedepends=('meson' 'valgrind' 'gobject-introspection' 'gtk-doc' 'python-pillow' 'git'
|
||||
makedepends=('meson' 'valgrind' 'gobject-introspection' 'gtk-doc' 'git'
|
||||
'python-cairo' 'noto-fonts' 'noto-fonts-cjk' 'python-gobject' 'vala'
|
||||
'curl' 'polkit' 'gcab' 'xz')
|
||||
|
||||
|
@ -1092,24 +1092,6 @@
|
||||
<package />
|
||||
</distro>
|
||||
</dependency>
|
||||
<dependency type="build" id="python3-pil">
|
||||
<distro id="arch">
|
||||
<package>python-pillow</package>
|
||||
</distro>
|
||||
<distro id="fedora">
|
||||
<package>python3-pillow</package>
|
||||
</distro>
|
||||
<distro id="debian">
|
||||
<control />
|
||||
<package variant="x86_64" />
|
||||
<package variant="s390x" />
|
||||
<package variant="i386" />
|
||||
</distro>
|
||||
<distro id="ubuntu">
|
||||
<control />
|
||||
<package variant="x86_64" />
|
||||
</distro>
|
||||
</dependency>
|
||||
<dependency type="build" id="python3-requests">
|
||||
<distro id="fedora">
|
||||
<package />
|
||||
|
@ -89,7 +89,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
|
||||
|
@ -16,6 +16,8 @@ import argparse
|
||||
import tarfile
|
||||
import math
|
||||
import io
|
||||
import struct
|
||||
|
||||
from typing import Dict, Optional, Any
|
||||
|
||||
import cairo
|
||||
@ -24,7 +26,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 languages(podir: str):
|
||||
@ -60,6 +61,33 @@ class PotFile:
|
||||
continue
|
||||
|
||||
|
||||
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
|
||||
)
|
||||
|
||||
|
||||
def main(args) -> int:
|
||||
|
||||
# open output archive
|
||||
@ -164,20 +192,14 @@ def main(args) -> int:
|
||||
fs.foreach(do_write, None)
|
||||
img.flush()
|
||||
|
||||
# write PNG
|
||||
with io.BytesIO() as io_png:
|
||||
img.write_to_png(io_png)
|
||||
io_png.seek(0)
|
||||
|
||||
# convert to BMP and add to archive
|
||||
with io.BytesIO() as io_bmp:
|
||||
pimg = Image.open(io_png)
|
||||
pimg.save(io_bmp, format="BMP")
|
||||
filename = "fwupd-{}-{}-{}.bmp".format(lang, width, height)
|
||||
tarinfo = tarfile.TarInfo(filename)
|
||||
tarinfo.size = io_bmp.tell()
|
||||
io_bmp.seek(0)
|
||||
tar.addfile(tarinfo, fileobj=io_bmp)
|
||||
# convert to BMP and add to archive
|
||||
with io.BytesIO() as io_bmp:
|
||||
io_bmp.write(_cairo_surface_write_to_bmp(img))
|
||||
filename = "fwupd-{}-{}-{}.bmp".format(lang, width, height)
|
||||
tarinfo = tarfile.TarInfo(filename)
|
||||
tarinfo.size = io_bmp.tell()
|
||||
io_bmp.seek(0)
|
||||
tar.addfile(tarinfo, fileobj=io_bmp)
|
||||
|
||||
# success
|
||||
return 0
|
||||
|
@ -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:
|
||||
|
@ -163,7 +163,6 @@ parts:
|
||||
stage-packages:
|
||||
- python3-gi
|
||||
- python3-gi-cairo
|
||||
- python3-pil
|
||||
prime:
|
||||
- -etc
|
||||
- -usr
|
||||
|
Loading…
Reference in New Issue
Block a user