diff options
author | Remi Collet <remi@remirepo.net> | 2021-03-17 14:07:04 +0100 |
---|---|---|
committer | Remi Collet <remi@remirepo.net> | 2021-03-17 14:07:04 +0100 |
commit | 4a5c2d3bbb6601767c9eac6dfb13f4cf2e7cc4c6 (patch) | |
tree | 1091e56c7f536f60e6e66e1299dd1bc6111e3320 | |
parent | c4eb4636c2f19cc5c15c972528bc6df7168ab79f (diff) |
enable avif support on Fedora 33+
-rw-r--r-- | gd.spec | 14 | ||||
-rw-r--r-- | libgd-upstream.patch | 141 |
2 files changed, 151 insertions, 4 deletions
@@ -15,7 +15,7 @@ %bcond_without webp %bcond_without raqm -%if 0%{?fedora} >= 34 +%if 0%{?fedora} >= 33 %bcond_without avif %else # Not available or too old @@ -45,7 +45,7 @@ Name: gd Name: gd-last %endif Version: 2.3.2 -Release: 2%{?prever}%{?short}%{?dist} +Release: 3%{?prever}%{?short}%{?dist} License: MIT URL: http://libgd.github.io/ %if 0%{?commit:1} @@ -58,6 +58,8 @@ Source0: https://github.com/libgd/libgd/releases/download/gd-%{version}/li # Missing, temporary workaround, fixed upstream for next version Source1: https://raw.githubusercontent.com/libgd/libgd/gd-%{version}/tests/heif/label.heic +Patch0: libgd-upstream.patch + BuildRequires: freetype-devel BuildRequires: fontconfig-devel BuildRequires: gettext-devel @@ -78,10 +80,10 @@ BuildRequires: libimagequant-devel BuildRequires: libraqm-devel %endif %if %{with avif} -BuildRequires: libavif-devel +BuildRequires: libavif-devel >= 0.8.2 %endif %if %{with heif} -BuildRequires: libheif-devel +BuildRequires: libheif-devel >= 1.7.0 %endif BuildRequires: libX11-devel BuildRequires: libXpm-devel @@ -166,6 +168,7 @@ files for gd, a graphics library for creating PNG and JPEG graphics. %prep %setup -q -n libgd-%{version}%{?prever:-%{prever}} install -m 0644 %{SOURCE1} tests/heif/ +%patch0 -p1 -b .up : $(perl config/getver.pl) @@ -277,6 +280,9 @@ grep %{version} $RPM_BUILD_ROOT%{_libdir}/pkgconfig/gdlib.pc %changelog +* Wed Mar 17 2021 Remi Collet <remi@remirepo.net> - 2.3.2-3 +- enable avif support on Fedora 33+ + * Mon Mar 8 2021 Remi Collet <remi@remirepo.net> - 2.3.2-2 - enable avif support on Fedora 34 diff --git a/libgd-upstream.patch b/libgd-upstream.patch new file mode 100644 index 0000000..e15ad63 --- /dev/null +++ b/libgd-upstream.patch @@ -0,0 +1,141 @@ +From f7d12c91fa8bb0313dfc9d5ca827674c49a7bc9d Mon Sep 17 00:00:00 2001 +From: Martin Reboredo <39890836+YakoYakoYokuYoku@users.noreply.github.com> +Date: Tue, 16 Mar 2021 12:53:16 -0300 +Subject: [PATCH] Permit compilation with libheif version 1.7.0 (#686) + +libheif versions that came before 1.9.0 don't support changing the output image chroma. +I did not notice that and it resulted with tests failures across other OSes that don't have +a much newer libheif. + +See #678. Supersedes #685. +--- + src/gd_heif.c | 14 ++++++++------ + tests/heif/heif_im2im.c | 3 +++ + 2 files changed, 11 insertions(+), 6 deletions(-) + +diff --git a/src/gd_heif.c b/src/gd_heif.c +index 3b00a6c5..47ecd7ad 100644 +--- a/src/gd_heif.c ++++ b/src/gd_heif.c +@@ -321,12 +321,14 @@ static int _gdImageHeifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, gdHeifC + return GD_FALSE; + } + +- err = heif_encoder_set_parameter_string(heif_enc, "chroma", chroma); +- if (err.code != heif_error_Ok) { +- gd_error("gd-heif invalid chroma subsampling parameter\n"); +- heif_encoder_release(heif_enc); +- heif_context_free(heif_ctx); +- return GD_FALSE; ++ if (heif_get_version_number_major() >= 1 && heif_get_version_number_minor() >= 9) { ++ err = heif_encoder_set_parameter_string(heif_enc, "chroma", chroma); ++ if (err.code != heif_error_Ok) { ++ gd_error("gd-heif invalid chroma subsampling parameter\n"); ++ heif_encoder_release(heif_enc); ++ heif_context_free(heif_ctx); ++ return GD_FALSE; ++ } + } + + err = heif_image_create(gdImageSX(im), gdImageSY(im), heif_colorspace_RGB, heif_chroma_interleaved_RGBA, &heif_im); +diff --git a/tests/heif/heif_im2im.c b/tests/heif/heif_im2im.c +index 202d6b3e..01abf021 100644 +--- a/tests/heif/heif_im2im.c ++++ b/tests/heif/heif_im2im.c +@@ -17,6 +17,9 @@ int main() + int size = 0; + CuTestImageResult result = {0, 0}; + ++ if (!gdTestAssertMsg(heif_get_version_number_major() == 1 && heif_get_version_number_minor() >= 9, "changing chroma subsampling is not supported in this libheif version\n")) ++ return 77; ++ + if (!gdTestAssertMsg(heif_have_decoder_for_format(heif_compression_HEVC) && heif_have_encoder_for_format(heif_compression_HEVC), "HEVC codec support missing from libheif\n")) + return 77; + +From f6a111c632fcf76dd3a42d750f18d2ed7bf8a5f1 Mon Sep 17 00:00:00 2001 +From: Ben Morss <morss@google.com> +Date: Tue, 16 Mar 2021 12:26:17 -0400 +Subject: [PATCH] Fix for libavif v0.8.2 (#680) + +Don't return AVIF_RESULT_TRUNCATED_DATA, as this is normal for libavif <= 0.8.2. In our tests, +this makes tests pass with libavif 0.8.2. + +Plus, we did a few things to stop compiler warnings - and added a newline to error output. + +thanks @wantehchang for the collaboration here! + +This fixes #677. +--- + src/gd_avif.c | 19 ++++++++++++------- + 1 file changed, 12 insertions(+), 7 deletions(-) + +diff --git a/src/gd_avif.c b/src/gd_avif.c +index cf94c70a..20906618 100644 +--- a/src/gd_avif.c ++++ b/src/gd_avif.c +@@ -151,7 +151,7 @@ static avifBool isAvifSrgbImage(avifImage *avifIm) { + */ + static avifBool isAvifError(avifResult result, const char *msg) { + if (result != AVIF_RESULT_OK) { +- gd_error("avif error - %s: %s", msg, avifResultToString(result)); ++ gd_error("avif error - %s: %s\n", msg, avifResultToString(result)); + return AVIF_TRUE; + } + +@@ -177,13 +177,18 @@ static avifResult readFromCtx(avifIO *io, uint32_t readFlags, uint64_t offset, s + void *dataBuf = NULL; + gdIOCtx *ctx = (gdIOCtx *) io->data; + ++ // readFlags is unsupported ++ if (readFlags != 0) { ++ return AVIF_RESULT_IO_ERROR; ++ } ++ + // TODO: if we set sizeHint, this will be more efficient. + +- if (offset > LONG_MAX || size < 0) ++ if (offset > INT_MAX || size > INT_MAX) + return AVIF_RESULT_IO_ERROR; + + // Try to seek offset bytes forward. If we pass the end of the buffer, throw an error. +- if (!ctx->seek(ctx, offset)) ++ if (!ctx->seek(ctx, (int) offset)) + return AVIF_RESULT_IO_ERROR; + + dataBuf = gdMalloc(size); +@@ -194,7 +199,7 @@ static avifResult readFromCtx(avifIO *io, uint32_t readFlags, uint64_t offset, s + + // Read the number of bytes requested. + // If getBuf() returns a negative value, that means there was an error. +- int charsRead = ctx->getBuf(ctx, dataBuf, size); ++ int charsRead = ctx->getBuf(ctx, dataBuf, (int) size); + if (charsRead < 0) { + gdFree(dataBuf); + return AVIF_RESULT_IO_ERROR; +@@ -202,7 +207,7 @@ static avifResult readFromCtx(avifIO *io, uint32_t readFlags, uint64_t offset, s + + out->data = dataBuf; + out->size = charsRead; +- return charsRead == size ? AVIF_RESULT_OK : AVIF_RESULT_TRUNCATED_DATA; ++ return AVIF_RESULT_OK; + } + + // avif.h says this is optional, but it seemed easy to implement. +@@ -339,7 +344,7 @@ BGD_DECLARE(gdImagePtr) gdImageCreateFromAvifPtr(int size, void *data) + */ + BGD_DECLARE(gdImagePtr) gdImageCreateFromAvifCtx (gdIOCtx *ctx) + { +- int x, y; ++ uint32_t x, y; + gdImage *im = NULL; + avifResult result; + avifIO *io; +@@ -482,7 +487,7 @@ static avifBool _gdImageAvifCtx(gdImagePtr im, gdIOCtx *outfile, int quality, in + + uint32_t val; + uint8_t *p; +- int x, y; ++ uint32_t x, y; + + if (im == NULL) + return 1; |