code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>babl</Name>
        <Homepage>http://gegl.org/babl</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv3</License>
        <License>LGPLv3</License>
        <IsA>library</IsA>
        A dynamic, any to any, pixel format translation library
        <Description>babl is a library that allows converting between different methods of storing pixels known as pixel formats that have with different bitdepths and other data representations, color models and component permutations.</Description>
        <Archive sha1sum="a22cbbbd16b730ab7ae030bdf86dab1ee69b448b" type="tarbz2">https://download.gimp.org/pub/babl/0.1/babl-0.1.38.tar.bz2</Archive>
        <BuildDependencies>

            <Dependency>gobject-introspection-devel</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>babl</Name>
        <Files>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="doc">/usr/share/doc</Path>
        </Files>
    </Package>

    <Package>
        <Name>babl-devel</Name>
        Development files for babl
        <RuntimeDependencies>
            <Dependency release="current">babl</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
            <Path fileType="data">/usr/lib/pkgconfig</Path>
            <Path fileType="data">/usr/share/gir-1.0</Path>
        </Files>
    </Package>

    <History>
        <Update release="4">
            <Date>2017-12-21</Date>
            <Version>0.1.38</Version>
            <Comment>Version Bump.</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2017-02-05</Date>
            <Version>0.1.24</Version>
            <Comment>Version Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>0.1.12</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2015-02-07</Date>
            <Version>0.1.12</Version>
            <Comment>First release</Comment>
            <Name>Hakan Yıldız</Name>
            <Email>hknyldz93@gmail.com</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>babl</Name>
        Dinamik piksel biçimi dönüştürme kütüphanesi
        <Description xml:lang="tr">babl, çeşitli piksel saklama yöntemleri arasında dönüşüme izin veren bir programlama kütüphanesidir.</Description>
    </Source>

    <Package>
        <Name>babl-devel</Name>
        babl için geliştirme dosyaları
    </Package>
</PISI>

repo_name: ayhanyalcinsoy/main


code:
<PISI>
    <Name>multimedia.graphics</Name>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/copyleft/gpl.txt.

from pisi.actionsapi import cmaketools
from pisi.actionsapi import shelltools
from pisi.actionsapi import pisitools
from pisi.actionsapi import get

def setup():
    pisitools.ldflags.add("-lgs")
    shelltools.makedirs("build")
    shelltools.cd("build")
    cmaketools.configure("-DCMAKE_INSTALL_LIBDIR=lib \
                          -DDONT_INSTALL_GCONF_SCHEMAS=1 \
                          -DCMAKE_BUILD_TYPE=Release \
                          -DBINARY_PACKAGE_BUILD=1 \
                          -DBUILD_USERMANUAL=False \
                          -DUSE_LIBSECRET=On \
                          -DUSE_OPENJPEG=On \
                          -DUSE_COLORD=On \
                          -DBUILD_USERMANUAL=0", sourceDir="..")

def build():
    shelltools.cd("build")
    cmaketools.make()

def install():
    shelltools.cd("build")
    cmaketools.install()


code:
From 74ca29440e46136504ed6fc811ccd60da8af8abc Mon Sep 17 00:00:00 2001
From: David Bremner <david@tethera.net>
Date: Wed, 26 Oct 2016 22:18:48 -0300
Subject: [PATCH 1/3] debcherry fixup patch

88800f7 J2K: use g_strlcpy() instead of g_snprintf()
	 - no changes against upstream or conflicts
c6e0b7c FindOpenJPEG.cmake: use HINTS, not PATHS. NO_DEFAULT_PATH is not needed.
	 - no changes against upstream or conflicts
5cf698f Port to OpenJPEG2
	 - extra changes or conflicts
6f48d69 FindOpenJPEG.cmake: pick right include path if multiple headers.
	 - extra changes or conflicts
acf974a Update cmake stuff to look for OpenJPEG2 (openjpeg >= 2.0.0 aka openjp2)
	 - extra changes or conflicts
ecef362 restore upstream TODO
	 - no changes against upstream or conflicts
898199a debian: cleanup useless / missing docs
	 - extra changes or conflicts
31da456 remove dcraw.c again
	 - no changes against upstream or conflicts
4c3f916 remove dcraw.c
	 - no changes against upstream or conflicts
3b395b6 "undelete" some files now shipped in upstream tarball
	 - extra changes or conflicts
7d30472 remove version.h from git;  generate it at build time
	 - no changes against upstream or conflicts
7441226 remove version.sh, unneeded for build
	 - no changes against upstream or conflicts
b0be4a0 commit version.h, version.sh for new version
	 - extra changes or conflicts
b5784e1 commit version.sh for current upstream snapshot
	 - extra changes or conflicts
cea1f68 remove generated files that are no longer carried in upstream branch (since we are not going to import them from tarballs.
	 - extra changes or conflicts
f67ef8e Revert "As a workaround, add files to POTFILES.skip"
	 - extra changes or conflicts
f6a4d09 As a workaround, add files to POTFILES.skip
	 - extra changes or conflicts
1eb15b3 Imported Upstream version 0.5
	 - extra changes or conflicts
---
 cmake/modules/FindOpenJPEG.cmake  | 112 ++++---------------
 src/CMakeLists.txt                |  17 +--
 src/common/imageio_j2k.c          | 228 ++++++++++++++++++++++----------------
 src/imageio/format/CMakeLists.txt |   4 +-
 src/imageio/format/j2k.c          | 130 +++++++++++-----------
 5 files changed, 224 insertions(+), 267 deletions(-)

diff --git a/cmake/modules/FindOpenJPEG.cmake b/cmake/modules/FindOpenJPEG.cmake
index b80f922..da6d275 100644
--- a/cmake/modules/FindOpenJPEG.cmake
+++ b/cmake/modules/FindOpenJPEG.cmake
@@ -1,101 +1,29 @@
-# - Find OpenJPEG library
-# Find the native OpenJPEG includes and library
-# This module defines
-#  OPENJPEG_INCLUDE_DIRS, where to find openjpeg.h, Set when
-#                        OPENJPEG_INCLUDE_DIR is found.
-#  OPENJPEG_LIBRARIES, libraries to link against to use OpenJPEG.
-#  OPENJPEG_ROOT_DIR, The base directory to search for OpenJPEG.
-#                    This can also be an environment variable.
-#  OPENJPEG_FOUND, If false, do not try to use OpenJPEG.
+# - Try to find OpenJPEG
+# Once done, this will define
 #
-# also defined, but not for general use are
-#  OPENJPEG_LIBRARY, where to find the OpenJPEG library.
-
-#=============================================================================
-# Copyright 2011 Blender Foundation.
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-
-# If OPENJPEG_ROOT_DIR was defined in the environment, use it.
-IF(NOT OPENJPEG_ROOT_DIR AND NOT $ENV{OPENJPEG_ROOT_DIR} STREQUAL "")
-  SET(OPENJPEG_ROOT_DIR $ENV{OPENJPEG_ROOT_DIR})
-ENDIF()
+#  OpenJPEG_FOUND - system has OpenJPEG
+#  OpenJPEG_INCLUDE_DIRS - the OpenJPEG include directories
+#  OpenJPEG_LIBRARIES - link these to use OpenJPEG

 include(LibFindMacros)

-libfind_pkg_check_modules(PC_OPENJPEG libopenjpeg1)
+# Use pkg-config to get hints about paths
+libfind_pkg_check_modules(OpenJPEG_PKGCONF libopenjp2)

-SET(_openjpeg_SEARCH_DIRS
-  ${OPENJPEG_ROOT_DIR}
-  /usr/local
-  /sw # Fink
-  /opt/local # DarwinPorts
-  /opt/csw # Blastwave
+# Include dir
+find_path(OpenJPEG_INCLUDE_DIR
+  NAMES openjpeg.h
+  HINTS ${OpenJPEG_PKGCONF_INCLUDE_DIRS}
 )

-FIND_PATH(OPENJPEG_INCLUDE_DIR
-  NAMES
-    openjpeg.h
-  HINTS
-    ${PC_OPENJPEG_INCLUDEDIR}
-    ${PC_OPENJPEG_INCLUDE_DIRS}
-    ${_openjpeg_SEARCH_DIRS}
-  PATH_SUFFIXES
-    include
+# Finally the library itself
+find_library(OpenJPEG_LIBRARY
+  NAMES openjp2
+  HINTS ${OpenJPEG_PKGCONF_LIBRARY_DIRS}
 )

-FIND_LIBRARY(OPENJPEG_LIBRARY
-  NAMES
-    openjpeg
-  HINTS
-    ${PC_OPENJPEG_LIBDIR}
-    ${PC_OPENJPEG_LIBRARY_DIRS}
-    ${_openjpeg_SEARCH_DIRS}
-  PATH_SUFFIXES
-    lib64 lib
-  )
-
-# handle the QUIETLY and REQUIRED arguments and set OPENJPEG_FOUND to TRUE if
-# all listed variables are TRUE
-INCLUDE(FindPackageHandleStandardArgs)
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(OpenJPEG DEFAULT_MSG
-    OPENJPEG_LIBRARY OPENJPEG_INCLUDE_DIR)
-
-IF(OPENJPEG_FOUND)
-  SET(OPENJPEG_LIBRARIES ${OPENJPEG_LIBRARY})
-  SET(OPENJPEG_INCLUDE_DIRS ${OPENJPEG_INCLUDE_DIR})
-
-  # 1.3 didn't have pkg-config support, so we can't use that to get the version.
-  # 1.5 no longer has the #define OPENJPEG_VERSION ... in openjpeg.h so we can't use that either.
-  # Thus we might have to compile a smalltest program to get the version string. Could someone please kill me?
-
-  # see if pkg-config found the library. this should succeed for cross compiles as they are harder to run test programs
-  if(NOT "${PC_OPENJPEG_VERSION}" STREQUAL "")
-    # use the version as found by pkg-config
-    set(OPENJPEG_VERSION ${PC_OPENJPEG_VERSION})
-  else(NOT "${PC_OPENJPEG_VERSION}" STREQUAL "")
-    # too bad, we have to run our test code
-    try_run(run_var result_var
-            ${CMAKE_BINARY_DIR}/CMakeTmp
-            ${CMAKE_SOURCE_DIR}/cmake/modules/openjpeg_version.c
-            CMAKE_FLAGS "-DLINK_LIBRARIES:STRING=${OPENJPEG_LIBRARIES}"
-                        "-DINCLUDE_DIRECTORIES:STRING=${OPENJPEG_INCLUDE_DIRS}"
-            RUN_OUTPUT_VARIABLE rout_var
-    )
-    if(result_var)
-      set(OPENJPEG_VERSION ${rout_var})
-    endif(result_var)
-  endif(NOT "${PC_OPENJPEG_VERSION}" STREQUAL "")
-
-ENDIF(OPENJPEG_FOUND)
-
-MARK_AS_ADVANCED(
-  OPENJPEG_INCLUDE_DIR
-  OPENJPEG_LIBRARY
-)
+# Set the include dir variables and the libraries and let libfind_process do the rest.
+# NOTE: Singular variables for this library, plural for libraries this this lib depends on.
+set(OpenJPEG_PROCESS_INCLUDES OpenJPEG_INCLUDE_DIR)
+set(OpenJPEG_PROCESS_LIBS OpenJPEG_LIBRARY)
+libfind_process(OpenJPEG)
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 9278d91..7d29528 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -225,18 +225,13 @@ endif(USE_FLICKR)

 if(USE_OPENJPEG)
   find_package(OpenJPEG)
-  if(OPENJPEG_FOUND)
-    list(APPEND SOURCES "common/imageio_j2k.c")
-    include_directories(SYSTEM ${OPENJPEG_INCLUDE_DIRS})
-    list(APPEND LIBS ${OPENJPEG_LIBRARIES})
-    add_definitions(${OPENJPEG_DEFINITIONS})
+  if(OpenJPEG_FOUND)
     add_definitions("-DHAVE_OPENJPEG")
-    if(OPENJPEG_VERSION VERSION_LESS "1.5.0")
-      message(STATUS "OpenJPEG version ${OPENJPEG_VERSION} found. Only 1.5 and newer support reading of icc profiles.")
-    else()
-      add_definitions("-DHAVE_OPENJPEG_ICC")
-    endif()
-  endif(OPENJPEG_FOUND)
+    list(APPEND SOURCES "common/imageio_j2k.c")
+
+    include_directories(SYSTEM ${OpenJPEG_INCLUDE_DIRS})
+    list(APPEND LIBS ${OpenJPEG_LIBRARIES})
+  endif(OpenJPEG_FOUND)
 endif(USE_OPENJPEG)

 #
diff --git a/src/common/imageio_j2k.c b/src/common/imageio_j2k.c
index 84bcd28..7f60e7f 100644
--- a/src/common/imageio_j2k.c
+++ b/src/common/imageio_j2k.c
@@ -36,6 +36,7 @@
 #define JPT_CFMT 2

 static char JP2_HEAD[] = { 0x0, 0x0, 0x0, 0x0C, 0x6A, 0x50, 0x20, 0x20, 0x0D, 0x0A, 0x87, 0x0A };
+static char JP2_MAGIC[] = { 0x0d, 0x0a, 0x87, 0x0a };
 static char J2K_HEAD[] = { 0xFF, 0x4F, 0xFF, 0x51, 0x00 };
 // there seems to be no JPIP/JPT magic string, so we can't load it ...

@@ -74,7 +75,7 @@ static int get_file_format(const char *filename)
   char *ext = strrchr(filename, '.');
   if(ext == NULL) return -1;
   ext++;
-  if(ext)
+  if(*ext)
   {
     for(i = 0; i < sizeof(format) / sizeof(*format); i++)
     {
@@ -91,100 +92,116 @@ static int get_file_format(const char *filename)
 dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, const char *filename, dt_mipmap_buffer_t *mbuf)
 {
   opj_dparameters_t parameters; /* decompression parameters */
-  opj_event_mgr_t event_mgr;    /* event manager */
   opj_image_t *image = NULL;
   FILE *fsrc = NULL;
-  unsigned char *src = NULL;
-  size_t file_length;
-  opj_dinfo_t *dinfo = NULL; /* handle to a decompressor */
-  opj_cio_t *cio = NULL;
+  unsigned char src_header[12] = { 0 };
+  opj_codec_t *d_codec = NULL;
   OPJ_CODEC_FORMAT codec;
+  opj_stream_t *d_stream = NULL; /* Stream */
   int ret = DT_IMAGEIO_FILE_CORRUPTED;

-  int file_format = get_file_format(filename);
-  if(file_format == -1) return DT_IMAGEIO_FILE_CORRUPTED;
+  /* set decoding parameters to default values */
+  opj_set_default_decoder_parameters(&parameters);
+
+  g_strlcpy(parameters.infile, filename, sizeof(parameters.infile));
+
+  parameters.decod_format = get_file_format(filename);
+  if(parameters.decod_format == -1) return DT_IMAGEIO_FILE_CORRUPTED;

   if(!img->exif_inited) (void)dt_exif_read(img, filename);

-  /* read the input file and put it in memory */
-  /* ---------------------------------------- */
   fsrc = fopen(filename, "rb");
   if(!fsrc)
   {
     fprintf(stderr, "[j2k_open] Error: failed to open `%s' for reading\n", filename);
     return DT_IMAGEIO_FILE_NOT_FOUND;
   }
-  fseek(fsrc, 0, SEEK_END);
-  file_length = ftell(fsrc);
-  fseek(fsrc, 0, SEEK_SET);
-  src = (unsigned char *)malloc(file_length);
-  if(fread(src, 1, file_length, fsrc) != file_length)
+  if(fread(src_header, 1, 12, fsrc) != 12)
   {
-    free(src);
     fclose(fsrc);
     fprintf(stderr, "[j2k_open] Error: fread returned a number of elements different from the expected.\n");
     return DT_IMAGEIO_FILE_NOT_FOUND;
   }
   fclose(fsrc);

-  if(memcmp(JP2_HEAD, src, sizeof(JP2_HEAD)) == 0)
+  if(memcmp(JP2_HEAD, src_header, sizeof(JP2_HEAD)) == 0 || memcmp(JP2_MAGIC, src_header, sizeof(JP2_MAGIC)) == 0)
   {
-    file_format = JP2_CFMT; // just in case someone used the wrong extension
+    parameters.decod_format = JP2_CFMT; // just in case someone used the wrong extension
   }
-  else if(memcmp(J2K_HEAD, src, sizeof(J2K_HEAD)) == 0)
+  else if(memcmp(J2K_HEAD, src_header, sizeof(J2K_HEAD)) == 0)
   {
-    file_format = J2K_CFMT; // just in case someone used the wrong extension
+    parameters.decod_format = J2K_CFMT; // just in case someone used the wrong extension
   }
   else // this will also reject jpt files.
   {
-    free(src);
     fprintf(stderr, "[j2k_open] Error: `%s' has unsupported file format.\n", filename);
     return DT_IMAGEIO_FILE_CORRUPTED;
   }

-  /* configure the event callbacks (not required) */
-  memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
-  event_mgr.error_handler = error_callback;
-  //   event_mgr.warning_handler = warning_callback;
-  //   event_mgr.info_handler = info_callback;
-
-  /* set decoding parameters to default values */
-  opj_set_default_decoder_parameters(&parameters);

   /* decode the code-stream */
   /* ---------------------- */
-  if(file_format == J2K_CFMT) /* JPEG-2000 codestream */
-    codec = CODEC_J2K;
-  else if(file_format == JP2_CFMT) /* JPEG 2000 compressed image data */
-    codec = CODEC_JP2;
-  else if(file_format == JPT_CFMT) /* JPEG 2000, JPIP */
-    codec = CODEC_JPT;
+  if(parameters.decod_format == J2K_CFMT) /* JPEG-2000 codestream */
+    codec = OPJ_CODEC_J2K;
+  else if(parameters.decod_format == JP2_CFMT) /* JPEG 2000 compressed image data */
+    codec = OPJ_CODEC_JP2;
+  else if(parameters.decod_format == JPT_CFMT) /* JPEG 2000, JPIP */
+    codec = OPJ_CODEC_JPT;
   else
   {
-    free(src);
     return DT_IMAGEIO_FILE_CORRUPTED; // can't happen
   }

-  /* get a decoder handle */
-  dinfo = opj_create_decompress(codec);
+  d_codec = opj_create_decompress(codec);
+  if(!d_codec)
+  {
+    fprintf(stderr, "[j2k_open] Error: failed to create the decoder\n");
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

   /* catch events using our callbacks and give a local context */
-  opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);
+  opj_set_error_handler(d_codec, error_callback, stderr);
+  // opj_set_warning_handler(d_codec, error_callback, stderr);
+  // opj_set_info_handler(d_codec, error_callback, stderr);

   /* setup the decoder decoding parameters using user parameters */
-  opj_setup_decoder(dinfo, &parameters);
+  if(!opj_setup_decoder(d_codec, &parameters))
+  {
+    fprintf(stderr, "[j2k_open] Error: failed to setup the decoder %s\n", parameters.infile);
+    opj_destroy_codec(d_codec);
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

-  /* open a byte stream */
-  cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
+  d_stream = opj_stream_create_default_file_stream(parameters.infile, 1);
+  if(!d_stream)
+  {
+    fprintf(stderr, "[j2k_open] Error: failed to create the stream from the file %s\n", parameters.infile);
+    opj_destroy_codec(d_codec);
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

-  /* decode the stream and fill the image structure */
-  image = opj_decode(dinfo, cio);
+  /* Read the main header of the codestream and if necessary the JP2 boxes*/
+  if(!opj_read_header(d_stream, d_codec, &image))
+  {
+    fprintf(stderr, "[j2k_open] Error: failed to read the header\n");
+    opj_stream_destroy(d_stream);
+    opj_destroy_codec(d_codec);
+    opj_image_destroy(image);
+    return EXIT_FAILURE;
+  }

-  /* close the byte stream */
-  opj_cio_close(cio);
+  /* Get the decoded image */
+  if(!(opj_decode(d_codec, d_stream, image) && opj_end_decompress(d_codec, d_stream)))
+  {
+    fprintf(stderr, "[j2k_open] Error: failed to decode image!\n");
+    opj_destroy_codec(d_codec);
+    opj_stream_destroy(d_stream);
+    opj_image_destroy(image);
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

-  /* free the memory containing the code-stream */
-  free(src);
+  /* Close the byte stream */
+  opj_stream_destroy(d_stream);

   if(!image)
   {
@@ -193,14 +210,11 @@ dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, const char *filename, d
     goto end_of_the_world;
   }

-  if(image->color_space == CLRSPC_SYCC)
+  if(image->color_space == OPJ_CLRSPC_SYCC)
   {
     color_sycc_to_rgb(image);
   }

-// FIXME: openjpeg didn't have support for icc profiles before version 1.5
-// this needs some #ifdef magic and proper implementation
-#ifdef HAVE_OPENJPEG_ICC
   if(image->icc_profile_buf)
   {
 #if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
@@ -211,7 +225,6 @@ dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, const char *filename, d
     image->icc_profile_buf = NULL;
     image->icc_profile_len = 0;
   }
-#endif

   /* create output image */
   /* ------------------- */
@@ -289,7 +302,7 @@ dt_imageio_retval_t dt_imageio_open_j2k(dt_image_t *img, const char *filename, d

 end_of_the_world:
   /* free remaining structures */
-  if(dinfo) opj_destroy_decompress(dinfo);
+  opj_destroy_codec(d_codec);

   /* free image data structure */
   opj_image_destroy(image);
@@ -299,83 +312,113 @@ end_of_the_world:

 int dt_imageio_j2k_read_profile(const char *filename, uint8_t **out)
 {
-#ifdef HAVE_OPENJPEG_ICC
   opj_dparameters_t parameters; /* decompression parameters */
   opj_image_t *image = NULL;
   FILE *fsrc = NULL;
-  unsigned char *src = NULL;
-  size_t file_length;
-  opj_dinfo_t *dinfo = NULL; /* handle to a decompressor */
-  opj_cio_t *cio = NULL;
+  unsigned char src_header[12] = { 0 };
+  opj_codec_t *d_codec = NULL;
   OPJ_CODEC_FORMAT codec;
+  opj_stream_t *d_stream = NULL; /* Stream */
   gboolean res = FALSE;
   unsigned int length = 0;
   *out = NULL;

+  /* set decoding parameters to default values */
+  opj_set_default_decoder_parameters(&parameters);
+
+  g_strlcpy(parameters.infile, filename, sizeof(parameters.infile));
+
+  parameters.decod_format = get_file_format(filename);
+  if(parameters.decod_format == -1) return DT_IMAGEIO_FILE_CORRUPTED;
+
   /* read the input file and put it in memory */
   /* ---------------------------------------- */
   fsrc = fopen(filename, "rb");
   if(!fsrc)
   {
-    fprintf(stderr, "[j2k_open] Error: failed to open `%s' for reading\n", filename);
+    fprintf(stderr, "[j2k_read_profile] Error: failed to open `%s' for reading\n", filename);
     goto another_end_of_the_world;
   }
-  fseek(fsrc, 0, SEEK_END);
-  file_length = ftell(fsrc);
-  fseek(fsrc, 0, SEEK_SET);
-  src = (unsigned char *)malloc(file_length);
-  if(fread(src, 1, file_length, fsrc) != file_length)
+  if(fread(src_header, 1, 12, fsrc) != 12)
   {
-    free(src);
     fclose(fsrc);
-    fprintf(stderr, "[j2k_open] Error: fread returned a number of elements different from the expected.\n");
+    fprintf(stderr,
+            "[j2k_read_profile] Error: fread returned a number of elements different from the expected.\n");
     goto another_end_of_the_world;
   }
   fclose(fsrc);

-  if(memcmp(JP2_HEAD, src, sizeof(JP2_HEAD)) == 0)
+  if(memcmp(JP2_HEAD, src_header, sizeof(JP2_HEAD)) == 0 || memcmp(JP2_MAGIC, src_header, sizeof(JP2_MAGIC)) == 0)
   {
-    codec = CODEC_JP2;
+    codec = OPJ_CODEC_JP2;
   }
-  else if(memcmp(J2K_HEAD, src, sizeof(J2K_HEAD)) == 0)
+  else if(memcmp(J2K_HEAD, src_header, sizeof(J2K_HEAD)) == 0)
   {
-    codec = CODEC_J2K;
+    codec = OPJ_CODEC_J2K;
   }
   else // this will also reject jpt files.
   {
-    free(src);
-    fprintf(stderr, "[j2k_open] Error: `%s' has unsupported file format.\n", filename);
+    fprintf(stderr, "[j2k_read_profile] Error: `%s' has unsupported file format.\n", filename);
     goto another_end_of_the_world;
   }

-  /* set decoding parameters to default values */
-  opj_set_default_decoder_parameters(&parameters);
-  parameters.cp_limit_decoding = LIMIT_TO_MAIN_HEADER;
-
   /* decode the code-stream */
   /* ---------------------- */

   /* get a decoder handle */
-  dinfo = opj_create_decompress(codec);
+  d_codec = opj_create_decompress(codec);
+  if(!d_codec)
+  {
+    fprintf(stderr, "[j2k_read_profile] Error: failed to create the decoder\n");
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

   /* setup the decoder decoding parameters using user parameters */
-  opj_setup_decoder(dinfo, &parameters);
+  opj_setup_decoder(d_codec, &parameters);
+  if(!d_codec)
+  {
+    fprintf(stderr, "[j2k_read_profile] Error: failed to setup the decoder %s\n", parameters.infile);
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

-  /* open a byte stream */
-  cio = opj_cio_open((opj_common_ptr)dinfo, src, file_length);
+  d_stream = opj_stream_create_default_file_stream(parameters.infile, 1);
+  if(!d_stream)
+  {
+    fprintf(stderr, "[j2k_read_profile] Error: failed to create the stream from the file %s\n", parameters.infile);
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

-  /* decode the stream and fill the image structure */
-  image = opj_decode(dinfo, cio);
+  /* Read the main header of the codestream and if necessary the JP2 boxes*/
+  if(!opj_read_header(d_stream, d_codec, &image))
+  {
+    fprintf(stderr, "[j2k_read_profile] Error: failed to read the header\n");
+    opj_stream_destroy(d_stream);
+    opj_destroy_codec(d_codec);
+    opj_image_destroy(image);
+    return EXIT_FAILURE;
+  }

-  /* close the byte stream */
-  opj_cio_close(cio);
+  /* Get the decoded image */
+  if(!(opj_decode(d_codec, d_stream, image) && opj_end_decompress(d_codec, d_stream)))
+  {
+    fprintf(stderr, "[j2k_read_profile] Error: failed to decode image!\n");
+    opj_destroy_codec(d_codec);
+    opj_stream_destroy(d_stream);
+    opj_image_destroy(image);
+    return DT_IMAGEIO_FILE_CORRUPTED;
+  }

-  /* free the memory containing the code-stream */
-  free(src);
+  // FIXME: how to do it without fully-decoding the whole image?
+  // opj_jp2_decode() copies the icc_profile_{buf,len}
+  // from opj_codec_t *d_codec d_codec->color into opj_image_t *image, but
+  // opj_codec_t is private type.
+
+  /* Close the byte stream */
+  opj_stream_destroy(d_stream);

   if(!image)
   {
-    fprintf(stderr, "[j2k_open] Error: failed to decode image `%s'\n", filename);
+    fprintf(stderr, "[j2k_read_profile] Error: failed to decode image `%s'\n", filename);
     goto another_end_of_the_world;
   }

@@ -391,15 +434,12 @@ int dt_imageio_j2k_read_profile(const char *filename, uint8_t **out)

 another_end_of_the_world:
   /* free remaining structures */
-  if(dinfo) opj_destroy_decompress(dinfo);
+  opj_destroy_codec(d_codec);

   /* free image data structure */
   opj_image_destroy(image);

   return res ? length : 0;
-#else
-  return 0;
-#endif
 }

@@ -632,7 +672,7 @@ static void color_sycc_to_rgb(opj_image_t *img)
 {
   if(img->numcomps < 3)
   {
-    img->color_space = CLRSPC_GRAY;
+    img->color_space = OPJ_CLRSPC_GRAY;
     return;
   }

@@ -658,7 +698,7 @@ static void color_sycc_to_rgb(opj_image_t *img)
     fprintf(stderr, "%s:%d:color_sycc_to_rgb\n\tCAN NOT CONVERT\n", __FILE__, __LINE__);
     return;
   }
-  img->color_space = CLRSPC_SRGB;
+  img->color_space = OPJ_CLRSPC_SRGB;
 } /* color_sycc_to_rgb() */

 // modelines: These editor modelines have been set for all relevant files by tools/update_modelines.sh
diff --git a/src/imageio/format/CMakeLists.txt b/src/imageio/format/CMakeLists.txt
index e328cb8..a79f3ee 100644
--- a/src/imageio/format/CMakeLists.txt
+++ b/src/imageio/format/CMakeLists.txt
@@ -22,10 +22,10 @@ if(OPENEXR_FOUND)
 	add_library(exr MODULE "exr.cc")
 endif(OPENEXR_FOUND)

-if(OPENJPEG_FOUND)
+if(OpenJPEG_FOUND)
 	list(APPEND MODULES "j2k")
 	add_library(j2k MODULE "j2k.c")
-endif(OPENJPEG_FOUND)
+endif(OpenJPEG_FOUND)

 foreach(module ${MODULES})
 	target_link_libraries(${module} ${LIBS})
diff --git a/src/imageio/format/j2k.c b/src/imageio/format/j2k.c
index 0344b75..44a995c 100644
--- a/src/imageio/format/j2k.c
+++ b/src/imageio/format/j2k.c
@@ -63,11 +63,6 @@

 #include <openjpeg.h>

-#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/
-#define CINEMA_48_CS 651041  /*Codestream length for 48fps*/
-#define COMP_24_CS 1041666   /*Maximum size per color component for 2K & 4K @ 24fps*/
-#define COMP_48_CS 520833    /*Maximum size per color component for 2K @ 48fps*/
-
 typedef enum
 {
   J2K_CFMT = 0,
@@ -168,14 +163,14 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres)
   POC[0].layno1 = 1;
   POC[0].resno1 = numres - 1;
   POC[0].compno1 = 3;
-  POC[0].prg1 = CPRL;
+  POC[0].prg1 = OPJ_CPRL;
   POC[1].tile = 1;
   POC[1].resno0 = numres - 1;
   POC[1].compno0 = 0;
   POC[1].layno1 = 1;
   POC[1].resno1 = numres;
   POC[1].compno1 = 3;
-  POC[1].prg1 = CPRL;
+  POC[1].prg1 = OPJ_CPRL;
   return 2;
 }

@@ -201,7 +196,7 @@ static void cinema_parameters(opj_cparameters_t *parameters)
   parameters->csty |= 0x01;

   /*The progression order shall be CPRL*/
-  parameters->prog_order = CPRL;
+  parameters->prog_order = OPJ_CPRL;

   /* No ROI */
   parameters->roi_compno = -1;
@@ -220,9 +215,9 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima

   switch(parameters->cp_cinema)
   {
-    case CINEMA2K_24:
-    case CINEMA2K_48:
-      parameters->cp_rsiz = CINEMA2K;
+    case OPJ_CINEMA2K_24:
+    case OPJ_CINEMA2K_48:
+      parameters->cp_rsiz = OPJ_CINEMA2K;
       if(parameters->numresolution > 6)
       {
         parameters->numresolution = 6;
@@ -233,12 +228,12 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima
                 "Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 "
                 "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n",
                 image->comps[0].w, image->comps[0].h);
-        parameters->cp_rsiz = STD_RSIZ;
+        parameters->cp_rsiz = OPJ_STD_RSIZ;
       }
       break;

-    case CINEMA4K_24:
-      parameters->cp_rsiz = CINEMA4K;
+    case OPJ_CINEMA4K_24:
+      parameters->cp_rsiz = OPJ_CINEMA4K;
       if(parameters->numresolution < 1)
       {
         parameters->numresolution = 1;
@@ -253,7 +248,7 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima
                 "Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4"
                 "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n",
                 image->comps[0].w, image->comps[0].h);
-        parameters->cp_rsiz = STD_RSIZ;
+        parameters->cp_rsiz = OPJ_STD_RSIZ;
       }
       parameters->numpocs = initialise_4K_poc(parameters->POC, parameters->numresolution);
       break;
@@ -263,26 +258,26 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima

   switch(parameters->cp_cinema)
   {
-    case CINEMA2K_24:
-    case CINEMA4K_24:
+    case OPJ_CINEMA2K_24:
+    case OPJ_CINEMA4K_24:
       for(i = 0; i < parameters->tcp_numlayers; i++)
       {
         if(rates[i] == 0)
         {
           parameters->tcp_rates[0]
               = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
-                / (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+                / (OPJ_CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
         }
         else
         {
           temp_rate
               = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
                 / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
-          if(temp_rate > CINEMA_24_CS)
+          if(temp_rate > OPJ_CINEMA_24_CS)
           {
             parameters->tcp_rates[i]
                 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
-                  / (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+                  / (OPJ_CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy);
           }
           else
           {
@@ -290,28 +285,28 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima
           }
         }
       }
-      parameters->max_comp_size = COMP_24_CS;
+      parameters->max_comp_size = OPJ_CINEMA_24_COMP;
       break;

-    case CINEMA2K_48:
+    case OPJ_CINEMA2K_48:
       for(i = 0; i < parameters->tcp_numlayers; i++)
       {
         if(rates[i] == 0)
         {
           parameters->tcp_rates[0]
               = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
-                / (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+                / (OPJ_CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
         }
         else
         {
           temp_rate
               = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
                 / (rates[i] * 8 * image->comps[0].dx * image->comps[0].dy);
-          if(temp_rate > CINEMA_48_CS)
+          if(temp_rate > OPJ_CINEMA_48_CS)
           {
             parameters->tcp_rates[0]
                 = ((float)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))
-                  / (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
+                  / (OPJ_CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy);
           }
           else
           {
@@ -319,7 +314,7 @@ static void cinema_setup_encoder(opj_cparameters_t *parameters, opj_image_t *ima
           }
         }
       }
-      parameters->max_comp_size = COMP_48_CS;
+      parameters->max_comp_size = OPJ_CINEMA_48_COMP;
       break;
     default:
       break;
@@ -334,19 +329,9 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v
   dt_imageio_j2k_t *j2k = (dt_imageio_j2k_t *)j2k_tmp;
   opj_cparameters_t parameters; /* compression parameters */
   float *rates = NULL;
-  opj_event_mgr_t event_mgr; /* event manager */
   opj_image_t *image = NULL;
   const int quality = CLAMP(j2k->quality, 1, 100);

-  /*
-  configure the event callbacks (not required)
-  setting of each callback is optional
-  */
-  memset(&event_mgr, 0, sizeof(opj_event_mgr_t));
-  event_mgr.error_handler = error_callback;
-  event_mgr.warning_handler = warning_callback;
-  event_mgr.info_handler = info_callback;
-
   /* set encoding parameters to default values */
   opj_set_default_encoder_parameters(&parameters);

@@ -357,7 +342,7 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v

   parameters.tcp_numlayers = 1; /* only one resolution */
   parameters.cp_disto_alloc = 1;
-  parameters.cp_rsiz = STD_RSIZ;
+  parameters.cp_rsiz = OPJ_STD_RSIZ;

   parameters.cod_format = j2k->format;
   parameters.cp_cinema = (OPJ_CINEMA_MODE)j2k->preset;
@@ -397,7 +382,7 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v
       cmptparm[i].w = w;
       cmptparm[i].h = h;
     }
-    image = opj_image_create(numcomps, &cmptparm[0], CLRSPC_SRGB);
+    image = opj_image_create(numcomps, &cmptparm[0], OPJ_CLRSPC_SRGB);
     if(!image)
     {
       fprintf(stderr, "Error: opj_image_create() failed\n");
@@ -437,6 +422,7 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v
         fprintf(stderr, "Error: this shouldn't happen, there is no bit depth of %d for jpeg 2000 images.\n",
                 prec);
         free(rates);
+        opj_image_destroy(image);
         return 1;
     }
   }
@@ -457,58 +443,66 @@ int write_image(dt_imageio_module_data_t *j2k_tmp, const char *filename, const v
   int rc = 1;
   OPJ_CODEC_FORMAT codec;
   if(parameters.cod_format == J2K_CFMT) /* J2K format output */
-    codec = CODEC_J2K;
+    codec = OPJ_CODEC_J2K;
   else
-    codec = CODEC_JP2;
+    codec = OPJ_CODEC_JP2;

-  int codestream_length;
-  size_t res;
-  opj_cio_t *cio = NULL;
-  FILE *f = NULL;
+  opj_stream_t *cstream = NULL;

   /* get a J2K/JP2 compressor handle */
-  opj_cinfo_t *cinfo = opj_create_compress(codec);
+  opj_codec_t *ccodec = opj_create_compress(codec);
+
+  opj_set_error_handler(ccodec, error_callback, stderr);
+  opj_set_warning_handler(ccodec, warning_callback, stderr);
+  opj_set_info_handler(ccodec, info_callback, stderr);

-  /* catch events using our callbacks and give a local context */
-  opj_set_event_mgr((opj_common_ptr)cinfo, &event_mgr, stderr);
+  g_strlcpy(parameters.outfile, filename, sizeof(parameters.outfile));

   /* setup the encoder parameters using the current image and user parameters */
-  opj_setup_encoder(cinfo, &parameters, image);
+  opj_setup_encoder(ccodec, &parameters, image);

   /* open a byte stream for writing */
   /* allocate memory for all tiles */
-  cio = opj_cio_open((opj_common_ptr)cinfo, NULL, 0);
-
-  /* encode the image */
-  if(!opj_encode(cinfo, cio, image, NULL))
+  cstream = opj_stream_create_default_file_stream(parameters.outfile, OPJ_FALSE);
+  if(!cstream)
   {
-    opj_cio_close(cio);
-    fprintf(stderr, "failed to encode image\n");
+    opj_destroy_codec(ccodec);
+    opj_image_destroy(image);
+    fprintf(stderr, "failed to create output stream\n");
     return 1;
   }
-  codestream_length = cio_tell(cio);

-  /* write the buffer to disk */
-  f = fopen(filename, "wb");
-  if(!f)
+  if(!opj_start_compress(ccodec, image, cstream))
   {
-    fprintf(stderr, "failed to open %s for writing\n", filename);
+    opj_stream_destroy(cstream);
+    opj_destroy_codec(ccodec);
+    opj_image_destroy(image);
+    fprintf(stderr, "failed to encode image: opj_start_compress\n");
     return 1;
   }
-  res = fwrite(cio->buffer, 1, codestream_length, f);
-  if(res < (size_t)codestream_length) /* FIXME */
+
+  /* encode the image */
+  if(!opj_encode(ccodec, cstream))
   {
-    fprintf(stderr, "failed to write %d (%s)\n", codestream_length, filename);
-    fclose(f);
+    opj_stream_destroy(cstream);
+    opj_destroy_codec(ccodec);
+    opj_image_destroy(image);
+    fprintf(stderr, "failed to encode image: opj_encode\n");
     return 1;
   }
-  fclose(f);

-  /* close and free the byte stream */
-  opj_cio_close(cio);
+  /* encode the image */
+  if(!opj_end_compress(ccodec, cstream))
+  {
+    opj_stream_destroy(cstream);
+    opj_destroy_codec(ccodec);
+    opj_image_destroy(image);
+    fprintf(stderr, "failed to encode image: opj_end_compress\n");
+    return 1;
+  }

-  /* free remaining compression structures */
-  opj_destroy_compress(cinfo);
+  opj_stream_destroy(cstream);
+  opj_destroy_codec(ccodec);

   /* add exif data blob. seems to not work for j2k files :( */
   if(exif && j2k->format == JP2_CFMT) rc = dt_exif_write_blob(exif, exif_len, filename, 1);


code:
From c508a40d9b3fb0e113b0d2618c71b744c715899d Mon Sep 17 00:00:00 2001
From: Roman Lebedev <lebedev.ri@gmail.com>
Date: Thu, 9 Jun 2016 12:50:02 +0300
Subject: [PATCH 2/3] CMake modules: update our copy of LibFindMacros.

(cherry picked from commit 7bd5417fd20308b0334dfd4bf96a71f6361ae3e4)
---
 cmake/modules/LibFindMacros.cmake | 324 ++++++++++++++++++++++++++++++--------
 1 file changed, 257 insertions(+), 67 deletions(-)

diff --git a/cmake/modules/LibFindMacros.cmake b/cmake/modules/LibFindMacros.cmake
index 5a83443..1e29796 100644
--- a/cmake/modules/LibFindMacros.cmake
+++ b/cmake/modules/LibFindMacros.cmake
@@ -1,30 +1,97 @@
-# Works the same as find_package, but forwards the "REQUIRED" argument used for
-# the current package and always uses the "QUIET" flag. For this to work, the
-# first parameter must be the prefix of the current package, then the prefix of
-# the new package etc, which are passed to find_package.
-macro (libfind_package PREFIX)
-  set (LIBFIND_PACKAGE_ARGS ${ARGN} QUIET)
+# Version 2.2
+# Public Domain, originally written by Lasse Kärkkäinen <tronic>
+# Maintained at https://github.com/Tronic/cmake-modules
+# Please send your improvements as pull requests on Github.
+
+# Find another package and make it a dependency of the current package.
+# This also automatically forwards the "REQUIRED" argument.
+# Usage: libfind_package(<prefix> <another package> [extra args to find_package])
+macro (libfind_package PREFIX PKG)
+  set(${PREFIX}_args ${PKG} ${ARGN})
   if (${PREFIX}_FIND_REQUIRED)
-    set (LIBFIND_PACKAGE_ARGS ${LIBFIND_PACKAGE_ARGS} REQUIRED)
-  endif (${PREFIX}_FIND_REQUIRED)
-  find_package(${LIBFIND_PACKAGE_ARGS})
-endmacro (libfind_package)
-
-# Damn CMake developers made the UsePkgConfig system deprecated in the same release (2.6)
-# where they added pkg_check_modules. Consequently I need to support both in my scripts
-# to avoid those deprecated warnings. Here's a helper that does just that.
-# Works identically to pkg_check_modules, except that no checks are needed prior to use.
-macro (libfind_pkg_check_modules PREFIX PKGNAME)
-  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
-    include(UsePkgConfig)
-    pkgconfig(${PKGNAME} ${PREFIX}_INCLUDE_DIRS ${PREFIX}_LIBRARY_DIRS ${PREFIX}_LDFLAGS ${PREFIX}_CFLAGS)
-  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
-    find_package(PkgConfig)
-    if (PKG_CONFIG_FOUND)
-      pkg_check_modules(${PREFIX} ${PKGNAME})
-    endif (PKG_CONFIG_FOUND)
-  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 4)
-endmacro (libfind_pkg_check_modules)
+    set(${PREFIX}_args ${${PREFIX}_args} REQUIRED)
+  endif()
+  find_package(${${PREFIX}_args})
+  set(${PREFIX}_DEPENDENCIES ${${PREFIX}_DEPENDENCIES};${PKG})
+  unset(${PREFIX}_args)
+endmacro()
+
+# A simple wrapper to make pkg-config searches a bit easier.
+# Works the same as CMake's internal pkg_check_modules but is always quiet.
+macro (libfind_pkg_check_modules)
+  find_package(PkgConfig QUIET)
+  if (PKG_CONFIG_FOUND)
+    pkg_check_modules(${ARGN} QUIET)
+  endif()
+endmacro()
+
+# Avoid useless copy&pasta by doing what most simple libraries do anyway:
+# pkg-config, find headers, find library.
+# Usage: libfind_pkg_detect(<prefix> <pkg-config args> FIND_PATH <name> [other args] FIND_LIBRARY <name> [other args])
+# E.g. libfind_pkg_detect(SDL2 sdl2 FIND_PATH SDL.h PATH_SUFFIXES SDL2 FIND_LIBRARY SDL2)
+function (libfind_pkg_detect PREFIX)
+  # Parse arguments
+  set(argname pkgargs)
+  foreach (i ${ARGN})
+    if ("${i}" STREQUAL "FIND_PATH")
+      set(argname pathargs)
+    elseif ("${i}" STREQUAL "FIND_LIBRARY")
+      set(argname libraryargs)
+    else()
+      set(${argname} ${${argname}} ${i})
+    endif()
+  endforeach()
+  if (NOT pkgargs)
+    message(FATAL_ERROR "libfind_pkg_detect requires at least a pkg_config package name to be passed.")
+  endif()
+  # Find library
+  libfind_pkg_check_modules(${PREFIX}_PKGCONF ${pkgargs})
+  if (pathargs)
+    find_path(${PREFIX}_INCLUDE_DIR NAMES ${pathargs} HINTS ${${PREFIX}_PKGCONF_INCLUDE_DIRS})
+  endif()
+  if (libraryargs)
+    find_library(${PREFIX}_LIBRARY NAMES ${libraryargs} HINTS ${${PREFIX}_PKGCONF_LIBRARY_DIRS})
+  endif()
+endfunction()
+
+# Extracts a version #define from a version.h file, output stored to <PREFIX>_VERSION.
+# Usage: libfind_version_header(Foobar foobar/version.h FOOBAR_VERSION_STR)
+# Fourth argument "QUIET" may be used for silently testing different define names.
+# This function does nothing if the version variable is already defined.
+function (libfind_version_header PREFIX VERSION_H DEFINE_NAME)
+  # Skip processing if we already have a version or if the include dir was not found
+  if (${PREFIX}_VERSION OR NOT ${PREFIX}_INCLUDE_DIR)
+    return()
+  endif()
+  set(quiet ${${PREFIX}_FIND_QUIETLY})
+  # Process optional arguments
+  foreach(arg ${ARGN})
+    if (arg STREQUAL "QUIET")
+      set(quiet TRUE)
+    else()
+      message(AUTHOR_WARNING "Unknown argument ${arg} to libfind_version_header ignored.")
+    endif()
+  endforeach()
+  # Read the header and parse for version number
+  set(filename "${${PREFIX}_INCLUDE_DIR}/${VERSION_H}")
+  if (NOT EXISTS ${filename})
+    if (NOT quiet)
+      message(AUTHOR_WARNING "Unable to find ${${PREFIX}_INCLUDE_DIR}/${VERSION_H}")
+    endif()
+    return()
+  endif()
+  file(READ "${filename}" header)
+  string(REGEX REPLACE ".*#[ \t]*define[ \t]*${DEFINE_NAME}[ \t]*\"([^\n]*)\".*" "\\1" match "${header}")
+  # No regex match?
+  if (match STREQUAL header)
+    if (NOT quiet)
+      message(AUTHOR_WARNING "Unable to find \#define ${DEFINE_NAME} \"<version>\" from ${${PREFIX}_INCLUDE_DIR}/${VERSION_H}")
+    endif()
+    return()
+  endif()
+  # Export the version string
+  set(${PREFIX}_VERSION "${match}" PARENT_SCOPE)
+endfunction()

 # Do the final processing once the paths have been detected.
 # If include dirs are needed, ${PREFIX}_PROCESS_INCLUDES should be set to contain
@@ -32,45 +99,168 @@ endmacro (libfind_pkg_check_modules)
 # Ditto for ${PREFIX}_PROCESS_LIBS and library files.
 # Will set ${PREFIX}_FOUND, ${PREFIX}_INCLUDE_DIRS and ${PREFIX}_LIBRARIES.
 # Also handles errors in case library detection was required, etc.
-macro (libfind_process PREFIX)
-  # Skip processing if already processed during this run
-  if (NOT ${PREFIX}_FOUND)
-    # Start with the assumption that the library was found
-    set (${PREFIX}_FOUND TRUE)
-
-    # Process all includes and set _FOUND to false if any are missing
-    foreach (i ${${PREFIX}_PROCESS_INCLUDES})
-      if (i)
-        set (${PREFIX}_INCLUDE_DIRS ${${PREFIX}_INCLUDE_DIRS} ${${i}})
-        mark_as_advanced(${i})
-      else (i)
-        set (${PREFIX}_FOUND FALSE)
-      endif (i)
-    endforeach (i)
-
-    # Process all libraries and set _FOUND to false if any are missing
-    foreach (i ${${PREFIX}_PROCESS_LIBS})
-      if (i)
-        set (${PREFIX}_LIBRARIES ${${PREFIX}_LIBRARIES} ${${i}})
-        mark_as_advanced(${i})
-      else (i)
-        set (${PREFIX}_FOUND FALSE)
-      endif (i)
-    endforeach (i)
-
-    # Print message and/or exit on fatal error
-    if (${PREFIX}_FOUND)
-      if (NOT ${PREFIX}_FIND_QUIETLY)
-        message (STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
-      endif (NOT ${PREFIX}_FIND_QUIETLY)
-    else (${PREFIX}_FOUND)
-      if (${PREFIX}_FIND_REQUIRED)
-        foreach (i ${${PREFIX}_PROCESS_INCLUDES} ${${PREFIX}_PROCESS_LIBS})
-          message("${i}=${${i}}")
-        endforeach (i)
-        message (FATAL_ERROR "Required library ${PREFIX} NOT FOUND.\nInstall the library (dev version) and try again. If the library is already installed, use ccmake to set the missing variables manually.")
-      endif (${PREFIX}_FIND_REQUIRED)
-    endif (${PREFIX}_FOUND)
-  endif (NOT ${PREFIX}_FOUND)
-endmacro (libfind_process)
+function (libfind_process PREFIX)
+  # Skip processing if already processed during this configuration run
+  if (${PREFIX}_FOUND)
+    return()
+  endif()
+
+  set(found TRUE)  # Start with the assumption that the package was found
+
+  # Did we find any files? Did we miss includes? These are for formatting better error messages.
+  set(some_files FALSE)
+  set(missing_headers FALSE)
+
+  # Shorthands for some variables that we need often
+  set(quiet ${${PREFIX}_FIND_QUIETLY})
+  set(required ${${PREFIX}_FIND_REQUIRED})
+  set(exactver ${${PREFIX}_FIND_VERSION_EXACT})
+  set(findver "${${PREFIX}_FIND_VERSION}")
+  set(version "${${PREFIX}_VERSION}")
+
+  # Lists of config option names (all, includes, libs)
+  unset(configopts)
+  set(includeopts ${${PREFIX}_PROCESS_INCLUDES})
+  set(libraryopts ${${PREFIX}_PROCESS_LIBS})
+
+  # Process deps to add to
+  foreach (i ${PREFIX} ${${PREFIX}_DEPENDENCIES})
+    if (DEFINED ${i}_INCLUDE_OPTS OR DEFINED ${i}_LIBRARY_OPTS)
+      # The package seems to export option lists that we can use, woohoo!
+      list(APPEND includeopts ${${i}_INCLUDE_OPTS})
+      list(APPEND libraryopts ${${i}_LIBRARY_OPTS})
+    else()
+      # If plural forms don't exist or they equal singular forms
+      if ((NOT DEFINED ${i}_INCLUDE_DIRS AND NOT DEFINED ${i}_LIBRARIES) OR
+          ({i}_INCLUDE_DIR STREQUAL ${i}_INCLUDE_DIRS AND ${i}_LIBRARY STREQUAL ${i}_LIBRARIES))
+        # Singular forms can be used
+        if (DEFINED ${i}_INCLUDE_DIR)
+          list(APPEND includeopts ${i}_INCLUDE_DIR)
+        endif()
+        if (DEFINED ${i}_LIBRARY)
+          list(APPEND libraryopts ${i}_LIBRARY)
+        endif()
+      else()
+        # Oh no, we don't know the option names
+        message(FATAL_ERROR "We couldn't determine config variable names for ${i} includes and libs. Aieeh!")
+      endif()
+    endif()
+  endforeach()
+
+  if (includeopts)
+    list(REMOVE_DUPLICATES includeopts)
+  endif()
+
+  if (libraryopts)
+    list(REMOVE_DUPLICATES libraryopts)
+  endif()
+
+  string(REGEX REPLACE ".*[ ;]([^ ;]*(_INCLUDE_DIRS|_LIBRARIES))" "\\1" tmp "${includeopts} ${libraryopts}")
+  if (NOT tmp STREQUAL "${includeopts} ${libraryopts}")
+    message(AUTHOR_WARNING "Plural form ${tmp} found in config options of ${PREFIX}. This works as before but is now deprecated. Please only use singular forms INCLUDE_DIR and LIBRARY, and update your find scripts for LibFindMacros > 2.0 automatic dependency system (most often you can simply remove the PROCESS variables entirely).")
+  endif()
+
+  # Include/library names separated by spaces (notice: not CMake lists)
+  unset(includes)
+  unset(libs)
+
+  # Process all includes and set found false if any are missing
+  foreach (i ${includeopts})
+    list(APPEND configopts ${i})
+    if (NOT "${${i}}" STREQUAL "${i}-NOTFOUND")
+      list(APPEND includes "${${i}}")
+    else()
+      set(found FALSE)
+      set(missing_headers TRUE)
+    endif()
+  endforeach()
+
+  # Process all libraries and set found false if any are missing
+  foreach (i ${libraryopts})
+    list(APPEND configopts ${i})
+    if (NOT "${${i}}" STREQUAL "${i}-NOTFOUND")
+      list(APPEND libs "${${i}}")
+    else()
+      set (found FALSE)
+    endif()
+  endforeach()
+
+  # Version checks
+  if (found AND findver)
+    if (NOT version)
+      message(WARNING "The find module for ${PREFIX} does not provide version information, so we'll just assume that it is OK. Please fix the module or remove package version requirements to get rid of this warning.")
+    elseif (version VERSION_LESS findver OR (exactver AND NOT version VERSION_EQUAL findver))
+      set(found FALSE)
+      set(version_unsuitable TRUE)
+    endif()
+  endif()
+
+  # If all-OK, hide all config options, export variables, print status and exit
+  if (found)
+    foreach (i ${configopts})
+      mark_as_advanced(${i})
+    endforeach()
+    if (NOT quiet)
+      message(STATUS "Found ${PREFIX} ${${PREFIX}_VERSION}")
+      if (LIBFIND_DEBUG)
+        message(STATUS "  ${PREFIX}_DEPENDENCIES=${${PREFIX}_DEPENDENCIES}")
+        message(STATUS "  ${PREFIX}_INCLUDE_OPTS=${includeopts}")
+        message(STATUS "  ${PREFIX}_INCLUDE_DIRS=${includes}")
+        message(STATUS "  ${PREFIX}_LIBRARY_OPTS=${libraryopts}")
+        message(STATUS "  ${PREFIX}_LIBRARIES=${libs}")
+      endif()
+      set (${PREFIX}_INCLUDE_OPTS ${includeopts} PARENT_SCOPE)
+      set (${PREFIX}_LIBRARY_OPTS ${libraryopts} PARENT_SCOPE)
+      set (${PREFIX}_INCLUDE_DIRS ${includes} PARENT_SCOPE)
+      set (${PREFIX}_LIBRARIES ${libs} PARENT_SCOPE)
+      set (${PREFIX}_FOUND TRUE PARENT_SCOPE)
+    endif()
+    return()
+  endif()
+
+  # Format messages for debug info and the type of error
+  set(vars "Relevant CMake configuration variables:\n")
+  foreach (i ${configopts})
+    mark_as_advanced(CLEAR ${i})
+    set(val ${${i}})
+    if ("${val}" STREQUAL "${i}-NOTFOUND")
+      set (val "<not found>")
+    elseif (val AND NOT EXISTS ${val})
+      set (val "${val}  (does not exist)")
+    else()
+      set(some_files TRUE)
+    endif()
+    set(vars "${vars}  ${i}=${val}\n")
+  endforeach()
+  set(vars "${vars}You may use CMake GUI, cmake -D or ccmake to modify the values. Delete CMakeCache.txt to discard all values and force full re-detection if necessary.\n")
+  if (version_unsuitable)
+    set(msg "${PREFIX} ${${PREFIX}_VERSION} was found but")
+    if (exactver)
+      set(msg "${msg} only version ${findver} is acceptable.")
+    else()
+      set(msg "${msg} version ${findver} is the minimum requirement.")
+    endif()
+  else()
+    if (missing_headers)
+      set(msg "We could not find development headers for ${PREFIX}. Do you have the necessary dev package installed?")
+    elseif (some_files)
+      set(msg "We only found some files of ${PREFIX}, not all of them. Perhaps your installation is incomplete or maybe we just didn't look in the right place?")
+      if(findver)
+        set(msg "${msg} This could also be caused by incompatible version (if it helps, at least ${PREFIX} ${findver} should work).")
+      endif()
+    else()
+      set(msg "We were unable to find package ${PREFIX}.")
+    endif()
+  endif()
+
+  # Fatal error out if REQUIRED
+  if (required)
+    set(msg "REQUIRED PACKAGE NOT FOUND\n${msg} This package is REQUIRED and you need to install it or adjust CMake configuration in order to continue building ${CMAKE_PROJECT_NAME}.")
+    message(FATAL_ERROR "${msg}\n${vars}")
+  endif()
+  # Otherwise just print a nasty warning
+  if (NOT quiet)
+    message(WARNING "WARNING: MISSING PACKAGE\n${msg} This package is NOT REQUIRED and you may ignore this warning but by doing so you may miss some functionality of ${CMAKE_PROJECT_NAME}. \n${vars}")
+  endif()
+endfunction()


code:
From 6f52fa346ef5dd5c22895a5fc404bf02bf29932c Mon Sep 17 00:00:00 2001
From: Roman Lebedev <lebedev.ri@gmail.com>
Date: Thu, 9 Jun 2016 12:52:09 +0300
Subject: [PATCH 3/3] Fix warning in FindGIO.cmake

CMake Warning (dev) at cmake/modules/LibFindMacros.cmake:160 (message):
  Plural form Glib_LIBRARIES;Glib_LIBRARY found in config options of GIO.
  This works as before but is now deprecated.  Please only use singular forms
  INCLUDE_DIR and LIBRARY, and update your find scripts for LibFindMacros >
  2.0 automatic dependency system (most often you can simply remove the
  PROCESS variables entirely).
Call Stack (most recent call first):
  cmake/modules/FindGIO.cmake:26 (libfind_process)
  src/CMakeLists.txt:196 (find_package)

(cherry picked from commit 0717a2f5fc9dce880376c22856eae0c4dd7e4955)
---
 cmake/modules/FindGIO.cmake | 2 --
 1 file changed, 2 deletions(-)

diff --git a/cmake/modules/FindGIO.cmake b/cmake/modules/FindGIO.cmake
index c039042..a62f36e 100644
--- a/cmake/modules/FindGIO.cmake
+++ b/cmake/modules/FindGIO.cmake
@@ -21,7 +21,5 @@ find_library(GIO_LIBRARY

 # Set the include dir variables and the libraries and let libfind_process do the rest.
 # NOTE: Singular variables for this library, plural for libraries this this lib depends on.
-set(GIO_PROCESS_INCLUDES Glib_INCLUDE_DIRS)
-set(GIO_PROCESS_LIBS GIO_LIBRARY Glib_LIBRARIES)
 libfind_process(GIO)


code:
#!/usr/bin/env xdg-open
[Desktop Entry]
Name=Darktable
GenericName=Virtual Lighttable and Darkroom
GenericName[ru]=Программа для отсмотра и проявки цифровых негативов
GenericName[de]=Virtueller Leuchttisch und Dunkelkammer
GenericName[sv]=Virtuellt ljusbord och mörkerrum
GenericName[nl]=Virtuele Lichttafel en Doka
GenericName[fi]=Virtuaalinen valopöytä ja pimiö
GenericName[fr]=Table lumineuse et chambre noire virtuelles
GenericName[cs]=Virtuální prosvětlovací pult a fotokomora

Comment=Organize and develop images from digital cameras
Comment[ru]=Организация, сортировка и проявка цифровых негативов
Comment[de]=Organisiere und entwickle Bilder von Digitalkameras
Comment[sv]=Organisera och utveckla bilder ifrån digitalkameror
Comment[nl]=Organiseer en ontwikkel beelden van digitale camera's
Comment[fi]=Järjestele ja kehitä kuvia digitaalikameroista
Comment[fr]=Organiser et développer les images d'un boîtier numérique
Comment[cs]=Správa a vyvolávání snímků z digitálních fotoaparátů
X-GNOME-FullName=Darktable Photo Workflow Software
Version=1.0
Type=Application
Categories=Graphics;Photography;GTK;
Exec=darktable
TryExec=darktable
Terminal=false
StartupNotify=true
MimeType=application/x-darktable;image/x-dcraw;
Icon=darktable


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>darktable</Name>
        <Packager>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Packager>
        <License>GPL-3.0</License>
        <PartOf>multimedia.graphics</PartOf>
        <Summary>darktable is an open source photography workflow application and RAW developer.</Summary>
        <Description>darktable is an open source photography workflow application and RAW developer. A virtual lighttable and darkroom for photographers.
</Description>
        <Archive type="tarxz" sha1sum="f60ab3f9118e96c311f286a87102ad0d647cb111">https://github.com/darktable-org/darktable/releases/download/release-2.2.5/darktable-2.2.5.tar.xz</Archive>
        <Patches>
            <!--Patch level="1">0002-CMake-modules-update-our-copy-of-LibFindMacros.patch</Patch-->
            <!--Patch level="1">0003-Fix-warning-in-FindGIO.cmake.patch</Patch-->
            <!--Patch level="1">0001-debcherry-fixup-patch.patch</Patch-->
        </Patches>
        <BuildDependencies>
            <Dependency>exiv2-devel</Dependency>
            <Dependency>intltool</Dependency>
            <Dependency>cmake</Dependency>
            <Dependency>gconf-devel</Dependency>
            <Dependency>gtk2-devel</Dependency>
            <Dependency>libjpeg-turbo-devel</Dependency>
            <Dependency>lcms2-devel</Dependency>
            <Dependency>lensfun-devel</Dependency>
            <Dependency>libgnome-keyring-devel</Dependency>
            <Dependency>libgphoto2-devel</Dependency>
            <Dependency>librsvg-devel</Dependency>
            <Dependency>libsdl-devel</Dependency>
            <Dependency>mesa-devel</Dependency>
            <Dependency>mesa-glu-devel</Dependency>
            <Dependency>openexr-devel</Dependency>
            <Dependency>tiff-devel</Dependency>
            <Dependency>libsoup-devel</Dependency>
            <Dependency>json-glib-devel</Dependency>
            <Dependency>libgomp</Dependency>
            <Dependency>cups-devel</Dependency>
            <Dependency>curl-devel</Dependency>
            <Dependency>gtk3-devel</Dependency>
            <Dependency>zlib-devel</Dependency>
            <Dependency>glib2-devel</Dependency>
            <Dependency>libX11-devel</Dependency>
            <Dependency>libpng-devel</Dependency>
            <Dependency>sqlite-devel</Dependency>
            <Dependency>libxml2-devel</Dependency>
            <Dependency>pugixml-devel</Dependency>
            <Dependency>libXrandr-devel</Dependency>
            <Dependency>libsecret-devel</Dependency>
            <Dependency>openjpeg-devel</Dependency>
            <Dependency>ghostscript-devel</Dependency>
            <Dependency>GraphicsMagick-devel</Dependency>
            <Dependency>webp-devel</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>darktable</Name>
        <RuntimeDependencies>
            <Dependency>webp</Dependency>
            <Dependency>cups</Dependency>
            <Dependency>curl</Dependency>
            <Dependency>gtk3</Dependency>
            <Dependency>zlib</Dependency>
            <Dependency>glib2</Dependency>
            <Dependency>libX11</Dependency>
            <Dependency>libgcc</Dependency>
            <Dependency>libpng</Dependency>
            <Dependency>sqlite</Dependency>
            <Dependency>libxml2</Dependency>
            <Dependency>pugixml</Dependency>
            <Dependency>libXrandr</Dependency>
            <Dependency>libsecret</Dependency>
            <Dependency>mesa</Dependency>
            <Dependency>tiff</Dependency>
            <Dependency>gtk2</Dependency>
            <Dependency>lcms2</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>libsdl</Dependency>
            <Dependency>ilmbase</Dependency>
            <Dependency>lensfun</Dependency>
            <Dependency>librsvg</Dependency>
            <Dependency>libsoup</Dependency>
            <Dependency>libgomp</Dependency>
            <Dependency>mesa-glu</Dependency>
            <Dependency>openjpeg</Dependency>
            <Dependency>json-glib</Dependency>
            <Dependency>exiv2-libs</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
            <Dependency>libgphoto2</Dependency>
            <Dependency>ghostscript</Dependency>
            <Dependency>openexr-libs</Dependency>
            <Dependency>libjpeg-turbo</Dependency>
            <Dependency>GraphicsMagick</Dependency>
            <Dependency>libgnome-keyring</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="config">/etc</Path>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib/darktable</Path>
            <Path fileType="data">/usr/share/applications</Path>
            <Path fileType="data">/usr/share/appdata</Path>
            <Path fileType="data">/usr/share/darktable</Path>
            <Path fileType="doc">/usr/share/doc/darktable</Path>
            <Path fileType="data">/usr/share/icons</Path>
            <Path fileType="localedata">/usr/share/locale</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
    </Package>

    <History>
        <Update release="4">
            <Date>2018-02-14</Date>
            <Version>2.2.5</Version>
            <Comment>Rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="3">
            <Date>2017-10-06</Date>
            <Version>2.2.5</Version>
            <Comment>Rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="2">
            <Date>2017-04-15</Date>
            <Version>2.2.4</Version>
            <Comment>Rebuild with new toolchain</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2016-11-13</Date>
            <Version>2.0.7</Version>
            <Comment>First Release</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/copyleft/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools

def setup():
    pisitools.cxxflags.add("-fpermissive")
    pisitools.dosed("plug-ins/postscript/diapsft2renderer.c", "freetype/ftglyph.h", "freetype2/ftglyph.h")
    pisitools.dosed("plug-ins/postscript/diapsft2renderer.c", "freetype/ftoutln.h", "freetype2/ftoutln.h")
    autotools.configure("--prefix=/usr \
    --with-cairo \
    --with-python \
    --disable-gnome")

    pisitools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make()

def install():
    autotools.install()
    pisitools.remove("/usr/share/icons/hicolor/icon-theme.cache")

    pisitools.dodoc("AUTHORS", "ChangeLog", "COPYING", "NEWS", "README")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>dia</Name>
        <Homepage>https://live.gnome.org/Dia</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv3</License>
        <PartOf>multimedia.graphics</PartOf>
        <Icon>dia</Icon>
        <IsA>app:gui</IsA>
        <Summary>Diagram editor</Summary>
        <Description>Dia is a GTK+ based diagram creation program for GNU/Linux,</Description>
        <Archive sha1sum="316393951daebd186ba387e1cd6e34160a458c39" type="tarxz">http://ftp.gnome.org/pub/gnome/sources/dia/0.97/dia-0.97.3.tar.xz</Archive>
        <BuildDependencies>
            <Dependency>intltool</Dependency>
            <Dependency>qt5-base-devel</Dependency>
            <Dependency>cairo-devel</Dependency>
            <Dependency>python-devel</Dependency>
            <Dependency>zlib-devel</Dependency>
            <Dependency>freetype-devel</Dependency>
            <Dependency>gdk-pixbuf-devel</Dependency>
            <Dependency>gtk2-devel</Dependency>
            <Dependency>glib2-devel</Dependency>
            <Dependency>pango-devel</Dependency>
            <Dependency>libxml2-devel</Dependency>
            <Dependency>libpng-devel</Dependency>
            <Dependency>libart_lgpl-devel</Dependency>
            <Dependency>atk-devel</Dependency>
            <Dependency>docbook-xsl</Dependency>
            <Dependency>perl-XML-Parser</Dependency>
            <Dependency>libxslt-devel</Dependency>
            <Dependency>fontconfig-devel</Dependency>
        </BuildDependencies>
    </Source>

    <Package>
        <Name>dia</Name>
        <RuntimeDependencies>
            <Dependency>python</Dependency>
            <Dependency>zlib</Dependency>
            <Dependency>freetype</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
            <Dependency>gtk2</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>libxml2</Dependency>
            <Dependency>libpng</Dependency>
            <Dependency>libart_lgpl</Dependency>
            <Dependency>atk</Dependency>
            <Dependency>libxslt</Dependency>
            <Dependency>fontconfig</Dependency>
            <Dependency>glib2</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib/dia</Path>
            <Path fileType="data">/usr/share/applications</Path>
            <Path fileType="data">/usr/share/icons</Path>
            <Path fileType="data">/usr/share/oaf</Path>
            <Path fileType="data">/usr/share/dia</Path>
            <Path fileType="data">/usr/share/mime-info</Path>
            <Path fileType="localedata">/usr/share/locale</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="doc">/usr/share/man</Path>
        </Files>
    </Package>

    <History>
        <Update release="2">
            <Date>2017-04-15</Date>
            <Version>0.97.3</Version>
            <Comment>Rebuild with new toolchain</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2016-12-07</Date>
            <Version>0.97.3</Version>
            <Comment>First Release</Comment>
            <Name>Stefan Gronewold</Name>
            <Email>groni@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>dia</Name>
        <Summary xml:lang="tr">Diyagram editörü.</Summary>
        <Description xml:lang="tr">Dia, GTK tabanlı diyagram çizme ve düzenleme programıdır.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import get
from pisi.actionsapi import cmaketools
from pisi.actionsapi import pisitools

def setup():
    cmaketools.configure()

def build():
    cmaketools.make()

def install():
    cmaketools.rawInstall("DESTDIR=%s" % get.installDIR())

    pisitools.dodoc("AUTHORS", "ChangeLog", "COPYING", "NEWS", "README")


code:
diff -r 6aec0cc8d22a -r 467a73754dbb include/vigra_ext/impexalpha.hxx
--- a/include/vigra_ext/impexalpha.hxx	Mon Sep 28 09:41:56 2015 +0200
+++ b/include/vigra_ext/impexalpha.hxx	Sun Jan 24 17:05:51 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012-2014 Christoph L. Spiel
+ * Copyright (C) 2012-2016 Christoph L. Spiel
  *
  * This file is part of Enblend.
  *
@@ -26,6 +26,9 @@
 #include <vigra/imageinfo.hxx>
 #include <vigra/impex.hxx>

+#ifndef VIGRA_UNIQUE_PTR
+#define VIGRA_UNIQUE_PTR std::auto_ptr
+#endif

 namespace vigra_ext
 {
@@ -194,7 +197,7 @@
                          AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor,
                          vigra::VigraTrueType)
         {
-            std::auto_ptr<vigra::Decoder> decoder(vigra::decoder(import_info));
+            VIGRA_UNIQUE_PTR<vigra::Decoder> decoder(vigra::decoder(import_info));

             switch (pixel_t_of_string(decoder->getPixelType()))
             {
@@ -249,7 +252,7 @@
                          AlphaIterator alpha_iterator, AlphaAccessor alpha_accessor,
                          vigra::VigraFalseType)
         {
-            std::auto_ptr<vigra::Decoder> decoder(vigra::decoder(import_info));
+            VIGRA_UNIQUE_PTR<vigra::Decoder> decoder(vigra::decoder(import_info));

             switch (pixel_t_of_string(decoder->getPixelType()))
             {
@@ -467,7 +470,7 @@
                          vigra::VigraTrueType)
         {
             const std::string pixel_type(export_info.getPixelType());
-            std::auto_ptr<vigra::Encoder> encoder(vigra::encoder(export_info));
+            VIGRA_UNIQUE_PTR<vigra::Encoder> encoder(vigra::encoder(export_info));

             encoder->setPixelType(pixel_type);

@@ -525,7 +528,7 @@
                          vigra::VigraFalseType)
         {
             const std::string pixel_type(export_info.getPixelType());
-            std::auto_ptr<vigra::Encoder> encoder(vigra::encoder(export_info));
+            VIGRA_UNIQUE_PTR<vigra::Encoder> encoder(vigra::encoder(export_info));

             encoder->setPixelType(pixel_type);

diff -r 596efbff27a8 -r 73e6f16de80a src/filespec.cc
--- a/src/filespec.cc	Sun Jan 24 17:06:09 2016 +0100
+++ b/src/filespec.cc	Mon Feb 15 10:20:30 2016 +0100
@@ -37,7 +37,6 @@
 #include <cctype>

 #include <boost/algorithm/string/case_conv.hpp>
-#include <boost/assign/list_of.hpp>

 #include <vigra/imageinfo.hxx>

@@ -412,17 +411,12 @@
 public:
     Globbing() : algorithm_name_("literal"), algorithm_(NULL)
     {
-        installed_algorithms_ =
-            boost::assign::map_list_of
-            ("literal", MAKE_ALGORITHM(new LiteralGlobbingAlgorithm))
-            ("wildcard", MAKE_ALGORITHM(new WildcardGlobbingAlgorithm))
+        installed_algorithms_["literal"] = MAKE_ALGORITHM(new LiteralGlobbingAlgorithm);
+        installed_algorithms_["wildcard"] = MAKE_ALGORITHM(new WildcardGlobbingAlgorithm);
+        setup_alias("literal", "none");
+
 #ifndef _WIN32
-            ("shell", MAKE_ALGORITHM(new ShellGlobbingAlgorithm))
-#endif
-            ;
-
-        setup_alias("literal", "none");
-#ifndef _WIN32
+        installed_algorithms_["shell"] = MAKE_ALGORITHM(new ShellGlobbingAlgorithm);
         setup_alias("shell", "sh");
 #endif
     }


code:
diff -Nuar enblend-enfuse-4.1.3.orig/CMakeLists.txt enblend-enfuse-4.1.3/CMakeLists.txt
--- enblend-enfuse-4.1.3.orig/CMakeLists.txt	2013-01-18 11:01:29.000000000 +0200
+++ enblend-enfuse-4.1.3/CMakeLists.txt	2014-06-01 09:45:16.180117386 +0300
@@ -124,7 +124,7 @@

 # Compiler specific tweaks and optimizations
 IF(CMAKE_COMPILER_IS_GNUCXX)
-  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -ffast-math -DNDEBUG -Wall")
+  SET(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}  -ffast-math -DNDEBUG -Wall")
   IF(APPLE AND CMAKE_MAJOR_VERSION EQUAL 2 AND CMAKE_MINOR_VERSION LESS 5)
     ## Add needed Compiler and Linker flags for OSX
     SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flat_namespace -undefined suppress")
diff -Nuar enblend-enfuse-4.1.3.orig/doc/CMakeLists.txt enblend-enfuse-4.1.3/doc/CMakeLists.txt
--- enblend-enfuse-4.1.3.orig/doc/CMakeLists.txt	2013-01-01 11:49:53.000000000 +0200
+++ enblend-enfuse-4.1.3/doc/CMakeLists.txt	2014-06-01 09:45:29.373117879 +0300
@@ -8,7 +8,7 @@
 IF(WIN32)
 set(DocumentsDirectory "doc")
 ELSE(WIN32)
-set(DocumentsDirectory "doc/enblend")
+set(DocumentsDirectory "doc/")
 ENDIF(WIN32)

 include(${TOP_SRC_DIR}/doc/macros.cmake)


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>enblend</Name>
        <Homepage>http://enblend.sourceforge.net/</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv2</License>
        <IsA>app:console</IsA>
        <Summary>Image blending with multiresolution splines</Summary>
        <Description>enblend is a tool for compositing images. Given a set of images that overlap in some irregular way, enblend overlays them in such a way that the seam between the images is invisible, or at least very difficult to see.</Description>
        <Archive sha1sum="12a4ef9138107c2eed06033c1a99b55249552c54" type="targz">mirrors://sourceforge/enblend/enblend-enfuse/enblend-enfuse-4.1/enblend-enfuse-4.1.3.tar.gz</Archive>
        <BuildDependencies>
            <Dependency>cmake</Dependency>
            <Dependency>gsl-devel</Dependency>
            <Dependency>zlib-devel</Dependency>
            <Dependency>tiff-devel</Dependency>
            <Dependency>vigra-devel</Dependency>
            <Dependency>boost-devel</Dependency>
            <Dependency>lcms2-devel</Dependency>
            <Dependency>libpng-devel</Dependency>
            <Dependency>openexr-devel</Dependency>
            <Dependency>imagemagick-devel</Dependency>
            <Dependency>libjpeg-turbo-devel</Dependency>
        </BuildDependencies>
        <Patches>
            <Patch level="1">gentoo_prepare.patch</Patch>
            <Patch level="1">enblend-4.1.4-gcc6.patch</Patch>
        </Patches>
    </Source>

    <Package>
        <Name>enblend</Name>
        <RuntimeDependencies>
            <Dependency>gsl</Dependency>
            <Dependency>tiff</Dependency>
            <Dependency>boost</Dependency>
            <Dependency>lcms2</Dependency>
            <Dependency>vigra</Dependency>
            <Dependency>libgcc</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="man">/usr/share/man</Path>
            <Path fileType="data">/usr/share/doc</Path>
            <Path fileType="data">/usr/share/info</Path>
        </Files>
    </Package>

    <History>
        <Update release="3">
            <Date>2017-03-17</Date>
            <Version>4.1.3</Version>
            <Comment>Rebuild for new toolchain.</Comment>
            <Name>Ayhan Yalçınsoy</Name>
            <Email>ayhanyalcinsoy@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-09</Date>
            <Version>4.1.3</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-12-27</Date>
            <Version>4.1.3</Version>
            <Comment>First release</Comment>
            <Name>Yusuf Aydemir</Name>
            <Email>yusuf.aydemir@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>enblend</Name>
        <Summary xml:lang="tr">Resim harmanlama aracı</Summary>
        <Description xml:lang="tr">enblend, resimleri birleştirmek için kullanılan bir araçtır. Düzensiz bir şekilde üstüste binen bir resim grubunu, resimlerin arasındaki düğüm noktaları anlaşılmayacak şekilde harmanlar.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import shelltools
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import get

def setup():
    #autotools.autoreconf("-vfi")
    autotools.configure("--enable-mmx \
                         --enable-sse \
                         --includedir=/usr/include \
                         --datadir=/usr/share \
                         --with-pic \
                         --with-gio \
                         --with-gtk \
                         --with-cairo \
                         --with-pango \
                         --with-pangocairo \
                         --with-gdk-pixbuf \
                         --with-lensfun \
                         --with-libjpeg \
                         --with-libpng \
                         --with-openexr \
                         --with-sdl \
                         --with-libopenraw \
                         --with-jasper \
                         --with-lua \
                         --without-libavformat \
                         --with-libv4l \
                         --with-libspiro \
                         --with-exiv2 \
                         --with-umfpack \
                         --disable-static \
                         --disable-gtk-doc \
                         --enable-gtk-doc-html=no \
                         --disable-docs \
                         --disable-workshop")
                         #--with-librsvg \
                         #--with-graphviz \

    pisitools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make()

# disabled due sandbox violations
#def check():
#    autotools.make("check")

def install():
    autotools.rawInstall("DESTDIR=%s" % get.installDIR())

    pisitools.dodoc("AUTHORS", "ChangeLog", "COPYING", "COPYING.LESSER", "NEWS", "README")


code:
From 1e92e5235ded0415d555aa86066b8e4041ee5a53 Mon Sep 17 00:00:00 2001
From: Nils Philippsen <nils@redhat.com>
Date: Tue, 16 Oct 2012 14:58:27 +0000
Subject: ppm-load: CVE-2012-4433: don't overflow memory allocation

Carefully selected width/height values could cause the size of a later
allocation to overflow, resulting in a buffer much too small to store
the data which would then written beyond its end.
---
diff --git a/operations/external/ppm-load.c b/operations/external/ppm-load.c
index efe6d56..3d6bce7 100644
--- a/operations/external/ppm-load.c
+++ b/operations/external/ppm-load.c
@@ -84,7 +84,6 @@ ppm_load_read_header(FILE       *fp,
     /* Get Width and Height */
     img->width  = strtol (header,&ptr,0);
     img->height = atoi (ptr);
-    img->numsamples = img->width * img->height * CHANNEL_COUNT;

     fgets (header,MAX_CHARS_IN_ROW,fp);
     maxval = strtol (header,&ptr,0);
@@ -109,6 +108,16 @@ ppm_load_read_header(FILE       *fp,
       g_warning ("%s: Programmer stupidity error", G_STRLOC);
     }

+    /* Later on, img->numsamples is multiplied with img->bpc to allocate
+     * memory. Ensure it doesn't overflow. */
+    if (!img->width || !img->height ||
+        G_MAXSIZE / img->width / img->height / CHANNEL_COUNT < img->bpc)
+      {
+        g_warning ("Illegal width/height: %ld/%ld", img->width, img->height);
+        return FALSE;
+      }
+    img->numsamples = img->width * img->height * CHANNEL_COUNT;
+
     return TRUE;
 }

@@ -229,12 +238,24 @@ process (GeglOperation       *operation,
   if (!ppm_load_read_header (fp, &img))
     goto out;

-  rect.height = img.height;
-  rect.width = img.width;
-
   /* Allocating Array Size */
+
+  /* Should use g_try_malloc(), but this causes crashes elsewhere because the
+   * error signalled by returning FALSE isn't properly acted upon. Therefore
+   * g_malloc() is used here which aborts if the requested memory size can't be
+   * allocated causing a controlled crash. */
   img.data = (guchar*) g_malloc (img.numsamples * img.bpc);

+  /* No-op without g_try_malloc(), see above. */
+  if (! img.data)
+    {
+      g_warning ("Couldn't allocate %" G_GSIZE_FORMAT " bytes, giving up.", ((gsize)img.numsamples * img.bpc));
+      goto out;
+    }
+
+  rect.height = img.height;
+  rect.width = img.width;
+
   switch (img.bpc)
     {
     case 1:
--
cgit v0.9.0.2


code:
From 4757cdf73d3675478d645a3ec8250ba02168a230 Mon Sep 17 00:00:00 2001
From: Nils Philippsen <nils@redhat.com>
Date: Tue, 16 Oct 2012 14:56:40 +0000
Subject: ppm-load: CVE-2012-4433: add plausibility checks for header fields

Refuse values that are non-decimal, negative or overflow the target
type.
---
diff --git a/operations/external/ppm-load.c b/operations/external/ppm-load.c
index 3d6bce7..465096d 100644
--- a/operations/external/ppm-load.c
+++ b/operations/external/ppm-load.c
@@ -36,6 +36,7 @@ gegl_chant_file_path (path, _("File"), "", _("Path of file to load."))
 #include "gegl-chant.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <errno.h>

 typedef enum {
   PIXMAP_ASCII  = 51,
@@ -44,8 +45,8 @@ typedef enum {

 typedef struct {
 	map_type   type;
-	gint       width;
-	gint       height;
+	glong      width;
+	glong      height;
         gsize      numsamples; /* width * height * channels */
         gsize      bpc;        /* bytes per channel */
 	guchar    *data;
@@ -82,11 +83,33 @@ ppm_load_read_header(FILE       *fp,
       }

     /* Get Width and Height */
-    img->width  = strtol (header,&ptr,0);
-    img->height = atoi (ptr);
+    errno = 0;
+    img->width  = strtol (header,&ptr,10);
+    if (errno)
+      {
+        g_warning ("Error reading width: %s", strerror(errno));
+        return FALSE;
+      }
+    else if (img->width < 0)
+      {
+        g_warning ("Error: width is negative");
+        return FALSE;
+      }
+
+    img->height = strtol (ptr,&ptr,10);
+    if (errno)
+      {
+        g_warning ("Error reading height: %s", strerror(errno));
+        return FALSE;
+      }
+    else if (img->width < 0)
+      {
+        g_warning ("Error: height is negative");
+        return FALSE;
+      }

     fgets (header,MAX_CHARS_IN_ROW,fp);
-    maxval = strtol (header,&ptr,0);
+    maxval = strtol (header,&ptr,10);

     if ((maxval != 255) && (maxval != 65535))
       {
--
cgit v0.9.0.2


code:
--- operations/external/ff-load.c.orig	2012-04-01 13:17:57.000000000 +0200
+++ operations/external/ff-load.c	2012-07-11 12:42:05.174756560 +0200
@@ -271,7 +271,7 @@
       gint err;

       ff_cleanup (o);
-      err = av_open_input_file (&p->ic, o->path, NULL, 0, NULL);
+err = avformat_open_input (&p->ic, o->path, NULL, NULL);
       if (err < 0)
         {
           print_error (o->path, err);


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>gegl</Name>
        <Homepage>http://gegl.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv3+</License>
        <License>LGPLv3+</License>
        <IsA>library</IsA>
        <IsA>app:console</IsA>
        A graph based image processing framework
        <Description>gegl (Generic Graphics Library) provides infrastructure to do demand based cached non destructive image editing on larger than RAM buffers. Through babl it provides support for a wide range of color models and pixel storage formats for input and output.</Description>
        <Archive sha1sum="065ab41d3f828bebae81eb103c33b2ad98046a9e" type="tarbz2">https://download.gimp.org/pub/gegl/0.3/gegl-0.3.26.tar.bz2</Archive>
        <BuildDependencies>

            <Dependency>libspiro-devel</Dependency>
            <Dependency>json-glib-devel</Dependency>
            <Dependency>openexr-devel</Dependency>
            <Dependency>ffmpeg-devel</Dependency>
            <Dependency>libsdl-devel</Dependency>
            <Dependency>lcms2-devel</Dependency>
            <Dependency>libv4l-devel</Dependency>
            <Dependency>jasper-devel</Dependency>
            <Dependency>cairo-devel</Dependency>
            <Dependency>pango-devel</Dependency>
            <Dependency>exiv2-devel</Dependency>
            <Dependency>babl-devel</Dependency>
            <Dependency>libjpeg-turbo-devel</Dependency>
            <Dependency>gtk2-devel</Dependency>
            <Dependency>lua-devel</Dependency>
            <Dependency>asciidoc</Dependency>
            <Dependency>intltool</Dependency>

            <Dependency>ruby</Dependency>
            <Dependency>enscript</Dependency>
            <Dependency>librsvg-devel</Dependency>
            <Dependency>vala-devel</Dependency>
            <Dependency>libraw-devel</Dependency>
            <Dependency>webp-devel</Dependency>
            <Dependency>tiff-devel</Dependency>
            <Dependency>libgexiv2-devel</Dependency>
            <Dependency>ilmbase-devel</Dependency>
            <Dependency>gobject-introspection-devel</Dependency>
        </BuildDependencies>
        <Patches>

        </Patches>
    </Source>

    <Package>
        <Name>gegl</Name>
        <RuntimeDependencies>
            <Dependency>tiff</Dependency>
            <Dependency>webp</Dependency>
            <Dependency>libraw</Dependency>
            <Dependency>lcms2</Dependency>
            <Dependency>libgcc</Dependency>
            <Dependency>librsvg</Dependency>
            <Dependency>json-glib</Dependency>
            <Dependency>libgexiv2</Dependency>
            <Dependency>openexr-libs</Dependency>
            <Dependency>glib2</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
            <Dependency>libspiro</Dependency>
            <Dependency>jasper</Dependency>
            <Dependency>libpng</Dependency>
            <Dependency>libsdl</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>babl</Dependency>
            <Dependency>libjpeg-turbo</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="data">/usr/share</Path>
            <Path fileType="localedata">/usr/share/locale/</Path>
        </Files>
    </Package>

    <Package>
        <Name>gegl-devel</Name>
        Development files for gegl
        <RuntimeDependencies>
            <Dependency release="current">gegl</Dependency>
            <Dependency>glib2-devel</Dependency>
            <Dependency>babl-devel</Dependency>
            <Dependency>json-glib-devel</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
            <Path fileType="data">/usr/lib/pkgconfig</Path>
            <Path fileType="doc">/usr/share/gtk-doc/html</Path>
        </Files>
    </Package>

    <History>
        <Update release="5">
            <Date>2018-02-13</Date>
            <Version>0.3.26</Version>
            <Comment>Rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="4">
            <Date>2017-12-21</Date>
            <Version>0.3.26</Version>
            <Comment>update</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2017-03-05</Date>
            <Version>0.3.14</Version>
            <Comment>update</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-06-15</Date>
            <Version>0.2.0</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-12-20</Date>
            <Version>0.2.0</Version>
            <Comment>First release</Comment>
            <Name>Osman Erkan</Name>
            <Email>osman.erkan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>gegl</Name>
        Graf tabanlı resim işleme altyapısı
        <Description xml:lang="tr">gegl, orijinal kopyaya zarar vermeden (non-destructive) isteğe bağlı (demand based) resim işleme altyapısı sunan bir kütüphanedir.</Description>
    </Source>

    <Package>
        <Name>gegl-devel</Name>
        gegl için geliştirme dosyaları
    </Package>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import shelltools
from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import get

def setup():
    #autotools.autoreconf("-vfi")
    autotools.configure("--enable-mmx \
                         --enable-sse \
                         --includedir=/usr/include \
                         --datadir=/usr/share \
                         --with-pic \
                         --with-gio \
                         --with-gtk \
                         --with-cairo \
                         --with-pango \
                         --with-pangocairo \
                         --with-gdk-pixbuf \
                         --with-lensfun \
                         --with-libjpeg \
                         --with-libpng \
                         --with-openexr \
                         --with-sdl \
                         --with-libopenraw \
                         --with-jasper \
                         --with-lua \
                         --without-libavformat \
                         --with-libv4l \
                         --with-libspiro \
                         --with-exiv2 \
                         --with-umfpack \
                         --disable-static \
                         --disable-gtk-doc \
                         --enable-gtk-doc-html=no \
                         --disable-docs \
                         --disable-workshop")
                         #--with-librsvg \
                         #--with-graphviz \

    pisitools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make()

# disabled due sandbox violations
#def check():
#    autotools.make("check")

def install():
    autotools.rawInstall("DESTDIR=%s" % get.installDIR())
    #avoid file conflicts with gegl1.x
    pisitools.removeDir("/usr/bin")

    pisitools.dodoc("AUTHORS", "ChangeLog", "COPYING", "COPYING.LESSER", "NEWS", "README")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>gegl02</Name>
        <Homepage>http://gegl.org</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>GPLv3+</License>
        <License>LGPLv3+</License>
        <IsA>library</IsA>
        <IsA>app:console</IsA>
        A graph based image processing framework
        <Description>gegl (Generic Graphics Library) provides infrastructure to do demand based cached non destructive image editing on larger than RAM buffers. Through babl it provides support for a wide range of color models and pixel storage formats for input and output.</Description>
        <Archive sha1sum="764cc66cb3c7b261b8fc18a6268a0e264a91d573" type="tarbz2">http://ftp.gimp.org/pub/gegl/0.2/gegl-0.2.0.tar.bz2</Archive>
        <BuildDependencies>

            <Dependency>libspiro-devel</Dependency>
            <Dependency>json-glib-devel</Dependency>
            <Dependency>openexr-devel</Dependency>
            <Dependency>ffmpeg-devel</Dependency>
            <Dependency>libsdl-devel</Dependency>
            <Dependency>libv4l-devel</Dependency>
            <Dependency>jasper-devel</Dependency>
            <Dependency>cairo-devel</Dependency>
            <Dependency>pango-devel</Dependency>
            <Dependency>exiv2-devel</Dependency>
            <Dependency>babl-devel</Dependency>
            <Dependency>libjpeg-turbo-devel</Dependency>
            <Dependency>gtk2-devel</Dependency>
            <Dependency>lua-devel</Dependency>
            <Dependency>asciidoc</Dependency>
            <Dependency>intltool</Dependency>

            <Dependency>ruby</Dependency>
            <Dependency>ilmbase-devel</Dependency>
        </BuildDependencies>
        <Patches>
            <Patch level="1">gegl-0.2.0-cve-2012-4433-1e92e523.patch</Patch>
            <Patch level="1">gegl-0.2.0-cve-2012-4433-4757cdf7.patch</Patch>
            <Patch level="0">gegl-0.2.0-ffmpeg-0.11.patch</Patch>
        </Patches>
    </Source>

    <Package>
        <Name>gegl02</Name>
        <RuntimeDependencies>
            <Dependency>glib2</Dependency>
            <Dependency>gdk-pixbuf</Dependency>
            <Dependency>libspiro</Dependency>
            <Dependency>jasper</Dependency>
            <Dependency>libpng</Dependency>
            <Dependency>libsdl</Dependency>
            <Dependency>cairo</Dependency>
            <Dependency>pango</Dependency>
            <Dependency>babl</Dependency>
            <Dependency>libjpeg-turbo</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="localedata">/usr/share/locale/</Path>
        </Files>
    </Package>

    <Package>
        <Name>gegl02-devel</Name>
        Development files for gegl02
        <RuntimeDependencies>
            <Dependency release="current">gegl02</Dependency>
            <Dependency>glib2-devel</Dependency>
            <Dependency>babl-devel</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
            <Path fileType="data">/usr/lib/pkgconfig</Path>
            <Path fileType="doc">/usr/share/gtk-doc/html</Path>
        </Files>
    </Package>

    <History>
        <Update release="3">
            <Date>2018-02-13</Date>
            <Version>0.2.0</Version>
            <Comment>Rebuild</Comment>
            <Name>Mustafa Cinasal</Name>
            <Email>muscnsl@gmail.com</Email>
        </Update>
        <Update release="2">
            <Date>2017-03-09</Date>
            <Version>0.2.0</Version>
            <Comment>fixed file conflict with gegl1.x</Comment>
            <Name>Ayhan Yalçınsoy</Name>
            <Email>ayhanyalcinsoy@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-12-20</Date>
            <Version>0.2.0</Version>
            <Comment>First release</Comment>
            <Name>Osman Erkan</Name>
            <Email>osman.erkan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>gegl02</Name>
        Graf tabanlı resim işleme altyapısı
        <Description xml:lang="tr">gegl02, orijinal kopyaya zarar vermeden (non-destructive) isteğe bağlı (demand based) resim işleme altyapısı sunan bir kütüphanedir.</Description>
    </Source>

    <Package>
        <Name>gegl02-devel</Name>
        gegl02 için geliştirme dosyaları
    </Package>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import libtools
from pisi.actionsapi import get

def setup():
    libtools.libtoolize("--force --install")
    autotools.autoreconf("-fi")

    autotools.configure("--disable-static")

    pisitools.dosed("libtool", " -shared ", " -Wl,-O1,--as-needed -shared ")

def build():
    autotools.make("-j1")

def install():
    autotools.rawInstall("DESTDIR=%s" % get.installDIR())

    pisitools.dohtml("doc/")
    pisitools.dodoc("AUTHORS","BUGS","ChangeLog","NEWS","doc/*.txt")


code:
<?xml version="1.0" ?>
<!DOCTYPE PISI SYSTEM "http://www.pisilinux.org/projeler/pisi/pisi-spec.dtd">
<PISI>
    <Source>
        <Name>giflib</Name>
        <Homepage>http://sourceforge.net/projects/giflib</Homepage>
        <Packager>
            <Name>PisiLinux Community</Name>
            <Email>admins@pisilinux.org</Email>
        </Packager>
        <License>MIT</License>
        <IsA>library</IsA>
        Library to handle, display and manipulate GIF images
        <Description>The giflib package contains a shared library of functions for loading and saving GIF format image files. It is API and ABI compatible with libungif, the library which supported uncompressed GIFs while the Unisys LZW patent was in effect.</Description>
        <Archive sha1sum="5f1157cfc377916280849e247b8e34fa0446513f" type="tarbz2">mirrors://sourceforge/giflib/giflib-5.1.4.tar.bz2</Archive>
        <BuildDependencies>

        </BuildDependencies>
    </Source>

    <Package>
        <Name>giflib</Name>
        <Files>
            <Path fileType="executable">/usr/bin</Path>
            <Path fileType="library">/usr/lib</Path>
            <Path fileType="doc">/usr/share/doc</Path>
            <Path fileType="man">/usr/share/man</Path>
        </Files>
    </Package>

    <Package>
        <Name>giflib-devel</Name>
        <RuntimeDependencies>
            <Dependency release="current">giflib</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="header">/usr/include</Path>
            <Path fileType="doc">/usr/share/doc/giflib/html</Path>
        </Files>
    </Package>

    <Package>
        <Name>giflib-32bit</Name>
        <PartOf>emul32</PartOf>
        32-bit shared libraries for giflib
        <BuildType>emul32</BuildType>
        <BuildDependencies>

        </BuildDependencies>
        <RuntimeDependencies>
            <Dependency release="current">giflib</Dependency>
        </RuntimeDependencies>
        <Files>
            <Path fileType="library">/usr/lib32</Path>
        </Files>
    </Package>

    <History>
        <Update release="4">
            <Date>2017-02-05</Date>
            <Version>5.1.4</Version>
            <Comment>Version Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="3">
            <Date>2016-06-09</Date>
            <Version>5.0.6</Version>
            <Comment>Release Bump</Comment>
            <Name>Pisi Linux Community</Name>
            <Email>admin@pisilinux.org</Email>
        </Update>
        <Update release="2">
            <Date>2016-05-25</Date>
            <Version>5.0.6</Version>
            <Comment>Release bump</Comment>
            <Name>Serdar Soytetir</Name>
            <Email>kaptan@pisilinux.org</Email>
        </Update>
        <Update release="1">
            <Date>2014-05-20</Date>
            <Version>5.0.6</Version>
            <Comment>First release</Comment>
            <Name>Serdar Soytetir</Name>
            <Email>kaptan@pisilinux.org</Email>
        </Update>
    </History>
</PISI>


code:
<?xml version="1.0" ?>
<PISI>
    <Source>
        <Name>giflib</Name>
        <Summary xml:lang="tr">GIF türündeki resimleri görüntüleyip işlemeye aracılık eden kitaplık</Summary>
        <Description xml:lang="tr">libungif, gif dosyalarını okumaya ve yazmaya yarayan bir kütüphanedir. Kaydetme algoritması Unisys LZW patentine takılmamak için sıkıştırma yapmamaktadır. Böylece LZW'nin patentli olmadığı ülkelerde kullanılmak için API ve ABI uyumlu bir alternatif sunar.</Description>
        <Description xml:lang="fr">libungif est une librairies de lecture et d'écriture d'images gif. La fonctionnalité de sauvegarde utilise un algorithme gif non compressé pour éviter le brevet Unisys LZW. giflib est un remplaçant de cette dernière compatible aussi bien au niveau de l'interface de programmation (API) qu'au niveau binaire (ABI) pour les pays où LZW n'est pas breveté.</Description>
    </Source>
</PISI>


code:
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Licensed under the GNU General Public License, version 3.
# See the file http://www.gnu.org/licenses/gpl.txt

from pisi.actionsapi import autotools
from pisi.actionsapi import pisitools
from pisi.actionsapi import shelltools
from pisi.actionsapi import get

WorkDir="colorize-gimp"

def setup():
    #pisitools.dosed("Makefile", "pardus_cflags", "%s" % get.CFLAGS())
    pisitools.dosed("Makefile", "^CC=.*", "CC=%s" % get.CC())

def build():
    autotools.make()

def install():
    pisitools.insinto("/usr/lib/gimp/2.0/plug-ins", "colorize")