media-libs/libicns: Port to EAPI 7
authorDavid Seifert <soap@gentoo.org>
Sat, 13 Jul 2019 23:04:39 +0000 (01:04 +0200)
committerDavid Seifert <soap@gentoo.org>
Sat, 13 Jul 2019 23:04:39 +0000 (01:04 +0200)
Package-Manager: Portage-2.3.68, Repoman-2.3.16
Signed-off-by: David Seifert <soap@gentoo.org>
media-libs/libicns/files/libicns-0.8.1-fix-build-system.patch [new file with mode: 0644]
media-libs/libicns/files/libicns-0.8.1-fix-gcc-warnings.patch [new file with mode: 0644]
media-libs/libicns/files/libicns-0.8.1-support-libopenjp2.patch [new file with mode: 0644]
media-libs/libicns/libicns-0.8.1-r1.ebuild [new file with mode: 0644]

diff --git a/media-libs/libicns/files/libicns-0.8.1-fix-build-system.patch b/media-libs/libicns/files/libicns-0.8.1-fix-build-system.patch
new file mode 100644 (file)
index 0000000..63555b5
--- /dev/null
@@ -0,0 +1,61 @@
+Use pkg-config instead of brittle AC_CHECK_LIB hackery
+
+--- a/configure.ac
++++ b/configure.ac
+@@ -142,41 +142,11 @@
+ ] )
+ # Check for libpng
+-AC_CHECK_LIB(png, png_create_read_struct, [
+-AC_SUBST(PNG_LIBS, "-lpng")
+-], [
+-  AC_CHECK_LIB(png10, png_create_read_struct, [
+-  AC_SUBST(PNG_LIBS, "-lpng10")
+-  ], [
+-    AC_CHECK_LIB(png12, png_create_read_struct, [
+-    AC_SUBST(PNG_LIBS, "-lpng12")
+-    ], [
+-      AC_MSG_ERROR([cannot find required library png])
+-    ], [])
+-  ], [])
+-], [])
+-AC_CHECK_HEADERS([png.h libpng/png.h libpng10/png.h libpng12/png.h])
++PKG_CHECK_MODULES([PNG], [libpng])
+ # Check for libopenjpeg, fall back to libjasper if not available
+-AC_CHECK_LIB(jasper, jas_init, [
+-AC_SUBST(JP2000_LIBS, "-ljasper")
+-AC_CHECK_HEADERS([jasper/jasper.h])
+-AC_DEFINE([ICNS_JASPER],[1],[We have Jasper])
+-], [
+-  AC_CHECK_LIB(openjpeg2, opj_setup_decoder, [
+-  AC_SUBST(JP2000_LIBS, "-lopenjpeg2")
+-  AC_CHECK_HEADERS([openjpeg.h])
+-  AC_DEFINE([ICNS_OPENJPEG],[1],[We have OpenJPEG])
+-  ], [
+-    AC_CHECK_LIB(openjpeg, opj_setup_decoder, [
+-    AC_SUBST(JP2000_LIBS, "-lopenjpeg")
+-    AC_CHECK_HEADERS([openjpeg.h])
+-    AC_DEFINE([ICNS_OPENJPEG],[1],[We have OpenJPEG])
+-    ], [
+-      AC_MSG_WARN([libopenjpeg or libjasper jp2000 codec libraries not found])
+-      AC_MSG_WARN([libicns will be built without 256x256 and 512x512 support])
+-    ])
+-  ])
++PKG_CHECK_MODULES([JP2000], [libopenjp2], [
++  AC_DEFINE([ICNS_OPENJPEG], [2], [We have OpenJPEG 2.x])
+ ])
+ AC_CONFIG_FILES([Makefile libicns.spec icnsutils/Makefile src/Makefile src/libicns.pc])
+--- a/src/Makefile.am
++++ b/src/Makefile.am
+@@ -3,7 +3,8 @@
+ libicns_la_LDFLAGS = -version-info 3:0:2
+-libicns_la_LIBADD = @PNG_LIBS@ @JP2000_LIBS@
++libicns_la_LIBADD = $(PNG_LIBS) $(JP2000_LIBS)
++libicns_la_CPPFLAGS = $(PNG_CFLAGS) $(JP2000_CFLAGS)
+ libicns_la_SOURCES = \
+   icns_debug.c \
diff --git a/media-libs/libicns/files/libicns-0.8.1-fix-gcc-warnings.patch b/media-libs/libicns/files/libicns-0.8.1-fix-gcc-warnings.patch
new file mode 100644 (file)
index 0000000..d7f0dd6
--- /dev/null
@@ -0,0 +1,52 @@
+From: Carlos Maddela <e7appew@gmail.com>
+Date: Fri, 11 Nov 2016 17:12:25 +1100
+Subject: Fix GCC warnings.
+
+Description: Fix GCC warnings.
+Author: Carlos Maddela <e7appew@gmail.com>
+Origin: vendor
+Forwarded: no
+Last-Update: 2016-11-11
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+---
+ icnsutils/icns2png.c | 12 +++++++-----
+ icnsutils/png2icns.c |  2 ++
+ 2 files changed, 9 insertions(+), 5 deletions(-)
+
+--- a/icnsutils/icns2png.c
++++ b/icnsutils/icns2png.c
+@@ -530,15 +530,17 @@
+                       case ICNS_ICON_VERSION:
+                       {
+                               icns_byte_t     iconBytes[4];
+-                              icns_uint32_t   iconVersion = 0;
+-                              float           iconVersionNumber = 0;
++                              union
++                              {
++                                      icns_uint32_t   asUint32;
++                                      float           asFloat;
++                              } iconVersion = { .asUint32 = 0 };
+                               if(iconDataSize == 4) {
+                                       memcpy(&iconBytes[0],(dataPtr+dataOffset+8),4);
+-                                      iconVersion = iconBytes[3]|iconBytes[2]<<8|iconBytes[1]<<16|iconBytes[0]<<24;
+-                                      iconVersionNumber = *((float *)(&iconVersion));
++                                      iconVersion.asUint32 = iconBytes[3]|iconBytes[2]<<8|iconBytes[1]<<16|iconBytes[0]<<24;
+                               }
+                               if(extractMode & LIST_MODE) {
+-                                      printf(" value: %f\n",iconVersionNumber);
++                                      printf(" value: %f\n",iconVersion.asFloat);
+                               }
+                       }
+                       break;
+--- a/icnsutils/png2icns.c
++++ b/icnsutils/png2icns.c
+@@ -28,6 +28,8 @@
+ #include <png.h>\r
+ #include <icns.h>\r
\r
++#include <unistd.h>\r
++\r
+ #define       FALSE   0\r
+ #define       TRUE    1\r
\r
diff --git a/media-libs/libicns/files/libicns-0.8.1-support-libopenjp2.patch b/media-libs/libicns/files/libicns-0.8.1-support-libopenjp2.patch
new file mode 100644 (file)
index 0000000..7440ad9
--- /dev/null
@@ -0,0 +1,365 @@
+From: Carlos Maddela <e7appew@gmail.com>
+Date: Wed, 9 Nov 2016 05:05:01 +1100
+Subject: Add support for linking with openjpeg 2.x library.
+
+Description: Add support for linking with openjpeg 2.x library.
+ Even though the Debian package attempted to build with the openjpeg 2.x
+ library, the resulting binaries didn't support conversion of images with
+ dimensions of 256x256 or greater, since autoconf was incorrectly trying
+ to find libopenjpeg2 instead of libopenjp2. Changes were also required
+ to address the API differences between openjpeg 1.x and openjpeg 2.x.
+ (Closes: #844055)
+Author: Carlos Maddela <e7appew@gmail.com>
+Origin: vendor
+Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=844055
+Last-Update: 2016-11-12
+---
+This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
+---
+ src/icns_jp2.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
+ 1 file changed, 256 insertions(+), 8 deletions(-)
+
+diff --git a/src/icns_jp2.c b/src/icns_jp2.c
+index 6d809fb..e994f58 100644
+--- a/src/icns_jp2.c
++++ b/src/icns_jp2.c
+@@ -125,19 +125,19 @@ int icns_image_to_jp2(icns_image_t *image, icns_size_t *dataSizeOut, icns_byte_t
+       
+       #ifdef ICNS_JASPER
+               error = icns_jas_image_to_jp2(image, dataSizeOut, dataPtrOut);  
+-      #else
+-      #ifdef ICNS_OPENJPEG
++      #elif (ICNS_OPENJPEG == 1)
+               // OpenJPEG is broken for RGB+A images for now. See a possible patch here:
+               // http://groups.google.com/group/openjpeg/browse_thread/thread/1cb7807b2053592e
+               // error = icns_opj_image_to_jp2(image, dataSizeOut, dataPtrOut);
+               icns_print_err("icns_image_to_jp2: Saving JP2 data with OpenJPEG is not yet supported!\n");
+               error = ICNS_STATUS_UNSUPPORTED;
++      #elif (ICNS_OPENJPEG == 2)
++              error = icns_opj_image_to_jp2(image, dataSizeOut, dataPtrOut);
+       #else
+               *dataPtrOut = NULL;
+               error = ICNS_STATUS_UNSUPPORTED;
+       #endif
+-      #endif
+-      
++
+       return error;
+ }
+@@ -547,9 +547,136 @@ int icns_opj_jp2_to_image(icns_size_t dataSize, icns_byte_t *dataPtr, icns_image
+       return error;   
+ }
++#if (ICNS_OPENJPEG == 2)
++
++typedef struct mem_stream
++{
++      OPJ_BYTE     *buffer;
++      OPJ_SIZE_T    bufferSize;
++      OPJ_OFF_T     offset;
++      OPJ_BOOL      readOnly;
++      opj_stream_t *stream;
++} mem_stream_t;
++
++static OPJ_SIZE_T read_mem_stream(void *buffer, OPJ_SIZE_T numBytes, void *userData)
++{
++      mem_stream_t *memStream = (mem_stream_t *) userData;
++      OPJ_SIZE_T    remaining = memStream->bufferSize - memStream->offset;
++      OPJ_SIZE_T    bytesRead = (remaining < numBytes) ? remaining : numBytes;
++      memcpy(buffer, memStream->buffer + memStream->offset, bytesRead);
++      memStream->offset += bytesRead;
++      return bytesRead ? bytesRead : (OPJ_SIZE_T) -1;
++}
++
++static OPJ_SIZE_T write_mem_stream(void *buffer, OPJ_SIZE_T numBytes, void *userData)
++{
++      mem_stream_t *memStream = (mem_stream_t *) userData;
++      if(!memStream->readOnly) {
++              OPJ_SIZE_T remaining = memStream->bufferSize - memStream->offset;
++              if(remaining < numBytes) {
++                      OPJ_SIZE_T newBufferSize = memStream->bufferSize + numBytes;
++                      OPJ_BYTE  *newBuffer = (OPJ_BYTE *) realloc(memStream->buffer, newBufferSize);
++                      if(!newBuffer) {
++                              return (OPJ_SIZE_T) -1;
++                      }
++                      memStream->buffer = newBuffer;
++                      memStream->bufferSize = newBufferSize;
++                      opj_stream_set_user_data_length(memStream->stream, newBufferSize);
++              }
++              memcpy(memStream->buffer + memStream->offset, buffer, numBytes);
++              memStream->offset += numBytes;
++              return numBytes ? numBytes : (OPJ_SIZE_T) -1;
++      }
++      return (OPJ_SIZE_T) -1;
++}
++
++static OPJ_OFF_T skip_mem_stream(OPJ_OFF_T offset, void *userData)
++{
++      mem_stream_t *memStream = (mem_stream_t *) userData;
++      OPJ_OFF_T remaining = memStream->bufferSize - memStream->offset;
++      if(offset > remaining) {
++              if(!memStream->readOnly) {
++                      OPJ_SIZE_T newBufferSize = memStream->bufferSize + offset;
++                      OPJ_BYTE  *newBuffer = (OPJ_BYTE *) realloc(memStream->buffer, newBufferSize);
++                      if(!newBuffer) {
++                              return (OPJ_OFF_T) -1;
++                      }
++                      memStream->buffer = newBuffer;
++                      memStream->bufferSize = newBufferSize;
++                      opj_stream_set_user_data_length(memStream->stream, newBufferSize);
++              } else {
++                      offset = remaining;
++              }
++      }
++      memStream->offset += offset;
++      if(memStream->offset < 0) {
++              offset -= memStream->offset;
++              memStream->offset = 0;
++      }
++      return offset ? offset : (OPJ_OFF_T) -1;
++}
++
++static OPJ_BOOL seek_mem_stream(OPJ_OFF_T offset, void *userData)
++{
++      mem_stream_t *memStream = (mem_stream_t *) userData;
++      if(offset < 0) {
++              return OPJ_FALSE;
++      }
++      if((OPJ_SIZE_T) offset > memStream->bufferSize) {
++              if(!memStream->readOnly) {
++                      OPJ_SIZE_T newBufferSize = offset;
++                      OPJ_BYTE  *newBuffer = (OPJ_BYTE *) realloc(memStream->buffer, newBufferSize);
++                      if(!newBuffer) {
++                              return OPJ_FALSE;
++                      }
++                      memStream->buffer = newBuffer;
++                      memStream->bufferSize = newBufferSize;
++                      opj_stream_set_user_data_length(memStream->stream, newBufferSize);
++              } else {
++                      return OPJ_FALSE;
++              }
++      }
++      memStream->offset = offset;
++      return OPJ_TRUE;
++}
++
++static opj_stream_t *create_mem_stream(OPJ_BYTE *buffer, OPJ_SIZE_T bufferSize, OPJ_BOOL readOnly, mem_stream_t **memStreamOut)
++{
++      opj_stream_t *stream = opj_stream_default_create(readOnly);
++      if(stream) {
++              mem_stream_t *memStream = malloc(sizeof(*memStream));
++              if(memStream) {
++                      memStream->buffer = buffer;
++                      memStream->bufferSize = bufferSize;
++                      memStream->offset = 0;
++                      memStream->readOnly = readOnly;
++                      memStream->stream = stream;
++                      if(memStreamOut) {
++                              *memStreamOut = memStream;
++                      }
++                      opj_stream_set_user_data(stream, memStream, free);
++                      opj_stream_set_user_data_length(stream, bufferSize);
++                      opj_stream_set_read_function(stream, read_mem_stream);
++                      if(!readOnly) {
++                              opj_stream_set_write_function(stream, write_mem_stream);
++                      }
++                      opj_stream_set_skip_function(stream, skip_mem_stream);
++                      opj_stream_set_seek_function(stream, seek_mem_stream);
++              } else {
++                      opj_stream_destroy(stream);
++                      stream = NULL;
++              }
++      }
++      return stream;
++}
++
++#endif /* (ICNS_OPENJPEG == 2) */
++
+ // Decode jp2 data using OpenJPEG
+ int icns_opj_jp2_dec(icns_size_t dataSize, icns_byte_t *dataPtr, opj_image_t **imageOut)
+ {
++#if (ICNS_OPENJPEG == 1)
++
+       opj_event_mgr_t    event_mgr;   
+       opj_dparameters_t  parameters;
+       opj_dinfo_t        *dinfo = NULL;
+@@ -583,6 +710,59 @@ int icns_opj_jp2_dec(icns_size_t dataSize, icns_byte_t *dataPtr, opj_image_t **i
+       opj_destroy_decompress(dinfo);
+       return ICNS_STATUS_OK;
++
++#else /* (ICNS_OPENJPEG == 2) */
++
++      opj_dparameters_t  parameters;
++      opj_codec_t        *decoder = NULL;
++      opj_stream_t       *stream = NULL;
++      opj_image_t        *image = NULL;
++
++      *imageOut = NULL;
++
++      decoder = opj_create_decompress(OPJ_CODEC_JP2);
++      if(!decoder) {
++              icns_print_err("icns_opj_jp2_dec: failed to create decoder!\n");
++              return ICNS_STATUS_NO_MEMORY;
++      }
++
++      opj_set_error_handler(decoder, icns_opj_error_callback, stderr);
++      opj_set_warning_handler(decoder, icns_opj_warning_callback, stderr);
++      opj_set_info_handler(decoder, icns_opj_info_callback, stderr);
++
++      opj_set_default_decoder_parameters(&parameters);
++      opj_setup_decoder(decoder, &parameters);
++
++      stream = create_mem_stream(dataPtr, dataSize, OPJ_TRUE, NULL);
++      if(!stream) {
++              icns_print_err("icns_opj_jp2_dec: failed to create stream!\n");
++              opj_destroy_codec(decoder);
++              return ICNS_STATUS_NO_MEMORY;
++      }
++
++      if(!opj_read_header(stream, decoder, &image)) {
++              icns_print_err("icns_opj_jp2_dec: failed to read header!\n");
++              opj_stream_destroy(stream);
++              opj_destroy_codec(decoder);
++              return ICNS_STATUS_INVALID_DATA;
++      }
++
++      if(!opj_decode(decoder, stream, image) || !opj_end_decompress(decoder, stream)) {
++              icns_print_err("icns_opj_jp2_dec: failed to decode image!\n");
++              opj_image_destroy(image);
++              opj_stream_destroy(stream);
++              opj_destroy_codec(decoder);
++              return ICNS_STATUS_INVALID_DATA;
++      }
++
++      *imageOut = image;
++
++      opj_stream_destroy(stream);
++      opj_destroy_codec(decoder);
++
++      return ICNS_STATUS_OK;
++
++#endif /* (ICNS_OPENJPEG == 2) */
+ }
+ // Convert from opj_image_t to icns_image_t
+@@ -666,18 +846,30 @@ int icns_opj_to_image(opj_image_t *opjImg, icns_image_t *iconImg)
+ int icns_opj_image_to_jp2(icns_image_t *iconImg, icns_size_t *dataSizeOut, icns_byte_t **dataPtrOut)
+ {
+-      int                  error = ICNS_STATUS_OK;
++#if (ICNS_OPENJPEG == 1)
++      int                  error = ICNS_STATUS_OK;
+       opj_event_mgr_t      event_mgr;
++#endif /* (ICNS_OPENJPEG == 1) */
+       opj_cparameters_t    parameters;
++#if (ICNS_OPENJPEG == 1)
+       OPJ_COLOR_SPACE      color_space = CLRSPC_SRGB;
++#else /* (ICNS_OPENJPEG == 2) */
++      OPJ_COLOR_SPACE      color_space = OPJ_CLRSPC_SRGB;
++#endif /* (ICNS_OPENJPEG == 2) */
+       opj_image_cmptparm_t cmptparm[4];
+       opj_image_t          *opjImg = NULL;
+       icns_byte_t          *dataPtr = NULL;
+       int                  i, j;
+       int                  rowOffset, colOffset;
++#if (ICNS_OPENJPEG == 1)
+       opj_cinfo_t          *cinfo = NULL;
+       opj_cio_t            *cio = NULL;
+       int                  success = 0;
++#else /* (ICNS_OPENJPEG == 2) */
++      opj_codec_t          *encoder = NULL;
++      opj_stream_t         *stream = NULL;
++      mem_stream_t         *memStream = NULL;
++#endif /* (ICNS_OPENJPEG == 2) */
+       
+       if(iconImg == NULL)
+       {
+@@ -713,12 +905,14 @@ int icns_opj_image_to_jp2(icns_image_t *iconImg, icns_size_t *dataSizeOut, icns_
+       
+       *dataSizeOut = 0;
+       *dataPtrOut = NULL;
+-      
++
++#if (ICNS_OPENJPEG == 1)
+       memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
+       event_mgr.error_handler = icns_opj_error_callback;
+       event_mgr.warning_handler = icns_opj_warning_callback;
+       event_mgr.info_handler = icns_opj_info_callback;
+-      
++#endif /* (ICNS_OPENJPEG == 1) */
++
+       opj_set_default_encoder_parameters(&parameters);
+       parameters.tcp_numlayers = 1;
+@@ -766,7 +960,9 @@ int icns_opj_image_to_jp2(icns_image_t *iconImg, icns_size_t *dataSizeOut, icns_
+                       opjImg->comps[3].data[p] = src_pixel->a;
+               }
+       }
+-      
++
++#if (ICNS_OPENJPEG == 1)
++
+       cinfo = opj_create_compress(CODEC_JP2);
+       opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
+       opj_setup_encoder(cinfo, &parameters, opjImg);
+@@ -810,6 +1006,58 @@ exception:
+       }
+       
+       return error;
++
++#else /* (ICNS_OPENJPEG == 2) */
++
++      encoder = opj_create_compress(OPJ_CODEC_JP2);
++      if(!encoder) {
++              icns_print_err("icns_opj_image_to_jp2: failed to create encoder!\n");
++              opj_image_destroy(opjImg);
++              return ICNS_STATUS_NO_MEMORY;
++      }
++
++      opj_set_error_handler(encoder, icns_opj_error_callback, stderr);
++      opj_set_warning_handler(encoder, icns_opj_warning_callback, stderr);
++      opj_set_info_handler(encoder, icns_opj_info_callback, stderr);
++
++      opj_setup_encoder(encoder, &parameters, opjImg);
++
++      stream = create_mem_stream(NULL, 0, OPJ_FALSE, &memStream);
++      if(!stream) {
++              icns_print_err("icns_opj_image_to_jp2: failed to create stream!\n");
++              opj_image_destroy(opjImg);
++              opj_destroy_codec(encoder);
++              return ICNS_STATUS_NO_MEMORY;
++      }
++
++      if(!opj_start_compress(encoder, opjImg, stream) || !opj_encode(encoder, stream) || !opj_end_compress(encoder, stream)) {
++              icns_print_err("icns_opj_image_to_jp2: Error while encoding jp2 data!\n");
++              opj_image_destroy(opjImg);
++              opj_stream_destroy(stream);
++              opj_destroy_codec(encoder);
++              return ICNS_STATUS_INVALID_DATA;
++      }
++
++      *dataSizeOut = memStream->bufferSize + 34;
++      *dataPtrOut = (icns_byte_t *) realloc(memStream->buffer, *dataSizeOut);
++
++      if(!(*dataPtrOut))
++      {
++              icns_print_err("icns_opj_image_to_jp2: Unable to allocate memory block of size: %d!\n", (int) *dataSizeOut);
++              opj_image_destroy(opjImg);
++              opj_stream_destroy(stream);
++              opj_destroy_codec(encoder);
++              return ICNS_STATUS_NO_MEMORY;
++      }
++
++      icns_place_jp2_cdef(*dataPtrOut, *dataSizeOut);
++
++      opj_image_destroy(opjImg);
++      opj_stream_destroy(stream);
++      opj_destroy_codec(encoder);
++
++      return ICNS_STATUS_OK;
++#endif /* (ICNS_OPENJPEG == 2) */
+ }
+ void icns_opj_error_callback(const char *msg, void *client_data) {
diff --git a/media-libs/libicns/libicns-0.8.1-r1.ebuild b/media-libs/libicns/libicns-0.8.1-r1.ebuild
new file mode 100644 (file)
index 0000000..2573e08
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright 1999-2019 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+inherit autotools
+
+DESCRIPTION="A library for manipulating MacOS X .icns icon format"
+HOMEPAGE="https://sourceforge.net/projects/icns/"
+SRC_URI="mirror://sourceforge/icns/${P}.tar.gz"
+
+LICENSE="GPL-2 LGPL-2.1"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE="static-libs"
+
+RDEPEND="
+       media-libs/libpng:0=
+       media-libs/openjpeg:2="
+DEPEND="${RDEPEND}"
+BDEPEND="virtual/pkgconfig"
+
+PATCHES=(
+       "${FILESDIR}"/${PN}-0.8.1-fix-build-system.patch
+       "${FILESDIR}"/${PN}-0.8.1-support-libopenjp2.patch
+       "${FILESDIR}"/${PN}-0.8.1-fix-gcc-warnings.patch
+)
+
+src_prepare() {
+       default
+       eautoreconf
+}
+
+src_configure() {
+       econf $(use_enable static-libs static)
+}
+
+src_install() {
+       default
+       find "${D}" -name '*.la' -delete || die
+}