commit:     d23b080b9afe74c6590a9827d505e9234c00deb0
Author:     Horea Christian <chr <AT> chymera <DOT> eu>
AuthorDate: Sat Mar 25 01:48:55 2023 +0000
Commit:     Horea Christian <horea.christ <AT> gmail <DOT> com>
CommitDate: Sat Mar 25 01:48:55 2023 +0000
URL:        https://gitweb.gentoo.org/proj/sci.git/commit/?id=d23b080b

sci-libs/itk: add 5.3.0

Signed-off-by: Horea Christian <chr <AT> chymera.eu>

 sci-libs/itk/files/itk-5.3.0-system-openjpeg.patch | 550 +++++++++++++++++++++
 sci-libs/itk/itk-5.3.0.ebuild                      | 251 ++++++++++
 2 files changed, 801 insertions(+)

diff --git a/sci-libs/itk/files/itk-5.3.0-system-openjpeg.patch 
b/sci-libs/itk/files/itk-5.3.0-system-openjpeg.patch
new file mode 100644
index 000000000..27f139553
--- /dev/null
+++ b/sci-libs/itk/files/itk-5.3.0-system-openjpeg.patch
@@ -0,0 +1,550 @@
+--- a/Modules/ThirdParty/OpenJPEG/CMakeLists.txt
++++ b/Modules/ThirdParty/OpenJPEG/CMakeLists.txt
+@@ -1,16 +1,32 @@
+ project(ITKOpenJPEG)
+ set(ITKOpenJPEG_THIRD_PARTY 1)
+ 
+-set(ITKOpenJPEG_INCLUDE_DIRS
+-  ${ITKOpenJPEG_BINARY_DIR}/src/openjpeg
+-  ${ITKOpenJPEG_SOURCE_DIR}/src/openjpeg
+-  )
+-set(ITKOpenJPEG_LIBRARIES itkopenjpeg)
++option(ITK_USE_SYSTEM_OPENJPEG "Use system-installed openjpeg" 
${ITK_USE_SYSTEM_LIBRARIES})
++mark_as_advanced(ITK_USE_SYSTEM_OPENJPEG)
++
++if(ITK_USE_SYSTEM_OPENJPEG)
++  find_package(OpenJPEG REQUIRED)
++  set(ITKOpenJPEG_INCLUDE_DIRS
++    ${ITKOpenJPEG_BINARY_DIR}/src
++    )
++  set(ITKOpenJPEG_SYSTEM_INCLUDE_DIRS
++    ${OPENJPEG_INCLUDE_DIRS}
++    )
++  set(ITKOpenJPEG_LIBRARIES "${OPENJPEG_LIBRARIES}")
++  set(ITKOpenJPEG_NO_SRC 1)
++else()
++  set(ITKOpenJPEG_INCLUDE_DIRS
++    ${ITKOpenJPEG_BINARY_DIR}/src/openjpeg
++    ${ITKOpenJPEG_SOURCE_DIR}/src/openjpeg
++    )
++  set(ITKOpenJPEG_LIBRARIES itkopenjpeg)
++endif()
++
++configure_file(src/itk_openjpeg.h.in src/itk_openjpeg.h)
+ set(ITK_LIBRARY_PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS FALSE)
+-
+ itk_module_impl()
+ 
+-install(FILES ${ITKOpenJPEG_SOURCE_DIR}/src/itk_openjpeg.h
++install(FILES ${ITKOpenJPEG_BINARY_DIR}/src/itk_openjpeg.h
+   DESTINATION ${ITKOpenJPEG_INSTALL_INCLUDE_DIR}
+   COMPONENT Development
+   )
+diff --git a/Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h 
b/Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h.in
+rename from Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h
+rename to Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h.in
+--- a/Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h
++++ b/Modules/ThirdParty/OpenJPEG/src/itk_openjpeg.h.in
+@@ -25,6 +25,12 @@
+ #ifndef itk_openjpeg_h
+ #define itk_openjpeg_h
+ 
+-#include <itkopenjpeg/openjpeg.h>
++/* Use the openjpeg library configured for ITK.  */
++#cmakedefine ITK_USE_SYSTEM_OPENJPEG
++#ifdef ITK_USE_SYSTEM_OPENJPEG
++# include <openjpeg.h>
++#else
++# include <itkopenjpeg/openjpeg.h>
++#endif
+ 
+ #endif
+--- a/Modules/IO/JPEG2000/src/itkJPEG2000ImageIO.cxx
++++ b/Modules/IO/JPEG2000/src/itkJPEG2000ImageIO.cxx
+@@ -27,8 +27,6 @@
+ extern "C"
+ {
+ #include "openjpeg.h"
+-#include "j2k.h"
+-#include "jp2.h"
+ }
+ 
+ 
+@@ -139,11 +137,11 @@
+ {
+   itkDebugMacro(<< "ReadImageInformation()");
+ 
+-  FILE * l_file = fopen(this->m_FileName.c_str(), "rb");
+-
+-  /* decompression parameters */
++  /* set decoding parameters to default values */
++  
opj_set_default_decoder_parameters(&(this->m_Internal->m_DecompressionParameters));
+ 
+-  if (!l_file)
++  opj_stream_t * cio = 
opj_stream_create_default_file_stream(this->m_FileName.c_str(), true);
++  if (!cio)
+   {
+     itkExceptionMacro("JPEG2000ImageIO failed to open file for reading: " << 
this->GetFileName() << std::endl
+                                                                           << 
"Reason: "
+@@ -151,10 +149,5 @@
+   }
+ 
+-  /* set decoding parameters to default values */
+-  
opj_set_default_decoder_parameters(&(this->m_Internal->m_DecompressionParameters));
+-
+-  opj_stream_t * cio = opj_stream_create_default_file_stream(l_file, true);
+-
+   this->m_Internal->m_Dinfo = nullptr; /* handle to a decompressor */
+ 
+   opj_image_t * l_image = nullptr;
+@@ -188,9 +181,8 @@
+ 
+       /* get a decoder handle */
+-      this->m_Internal->m_Dinfo = opj_create_decompress(CODEC_J2K);
++      this->m_Internal->m_Dinfo = opj_create_decompress(OPJ_CODEC_J2K);
+       if (!this->m_Internal->m_Dinfo)
+       {
+         opj_stream_destroy(cio);
+-        fclose(l_file);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                           << this->GetFileName() << std::endl
+@@ -202,10 +194,9 @@
+     {
+       /* JPEG 2000 compressed image data */
+       /* get a decoder handle */
+-      this->m_Internal->m_Dinfo = opj_create_decompress(CODEC_JP2);
++      this->m_Internal->m_Dinfo = opj_create_decompress(OPJ_CODEC_JP2);
+       if (!this->m_Internal->m_Dinfo)
+       {
+         opj_stream_destroy(cio);
+-        fclose(l_file);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                           << this->GetFileName() << std::endl
+@@ -217,10 +208,9 @@
+     {
+       /* JPEG 2000, JPIP */
+       /* get a decoder handle */
+-      this->m_Internal->m_Dinfo = opj_create_decompress(CODEC_JPT);
++      this->m_Internal->m_Dinfo = opj_create_decompress(OPJ_CODEC_JPT);
+       if (!this->m_Internal->m_Dinfo)
+       {
+         opj_stream_destroy(cio);
+-        fclose(l_file);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                           << this->GetFileName() << std::endl
+@@ -230,7 +220,6 @@
+     }
+     default:
+       opj_stream_destroy(cio);
+-      fclose(l_file);
+       itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                         << this->GetFileName() << std::endl
+                         << "Reason: "
+@@ -248,26 +237,8 @@
+   }
+ 
+-  // Image parameters - first tile
+-  OPJ_INT32 l_tile_x0;
+-  OPJ_INT32 l_tile_y0;
+-
+-  // Image parameters - tile width, height and number of tiles
+-  OPJ_UINT32 l_tile_width;
+-  OPJ_UINT32 l_tile_height;
+-  OPJ_UINT32 l_nb_tiles_x;
+-  OPJ_UINT32 l_nb_tiles_y;
+-
+   itkDebugMacro(<< "Trying to read header now...");
+ 
+-  bResult = opj_read_header(this->m_Internal->m_Dinfo,
+-                            &l_image,
+-                            &l_tile_x0,
+-                            &l_tile_y0,
+-                            &l_tile_width,
+-                            &l_tile_height,
+-                            &l_nb_tiles_x,
+-                            &l_nb_tiles_y,
+-                            cio);
++  bResult = opj_read_header(cio, this->m_Internal->m_Dinfo, &l_image);
+ 
+   if (!bResult)
+   {
+@@ -284,13 +255,21 @@
+   }
+ 
+-  this->m_Internal->m_TileStartX = l_tile_x0;
+-  this->m_Internal->m_TileStartY = l_tile_y0;
++  opj_codestream_info_v2_t* cp = opj_get_cstr_info(this->m_Internal->m_Dinfo);
++  if (!cp)
++  {
++    opj_stream_destroy(cio);
++    opj_image_destroy(l_image);
++    itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
++                                                              << "Reason: 
Error while reading image header");
++  }
++  this->m_Internal->m_TileStartX = cp->tx0;
++  this->m_Internal->m_TileStartY = cp->ty0;
+ 
+-  this->m_Internal->m_TileWidth = l_tile_width;
+-  this->m_Internal->m_TileHeight = l_tile_height;
++  this->m_Internal->m_TileWidth = cp->tdx;
++  this->m_Internal->m_TileHeight = cp->tdy;
+ 
+-  this->m_Internal->m_NumberOfTilesInX = l_nb_tiles_x;
+-  this->m_Internal->m_NumberOfTilesInY = l_nb_tiles_y;
++  this->m_Internal->m_NumberOfTilesInX = cp->tw;
++  this->m_Internal->m_NumberOfTilesInY = cp->th;
+ 
+ 
+   itkDebugMacro(<< "Number of Components = " << l_image->numcomps);
+@@ -307,6 +286,7 @@
+   else
+   {
+     opj_stream_destroy(cio);
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+                                                               << "Reason: "
+                                                               << "Unknown 
precision in file: "
+@@ -320,6 +300,6 @@
+       break;
+     case 3:
+-      if (l_image->color_space != CLRSPC_SRGB)
++      if (l_image->color_space != OPJ_CLRSPC_SRGB)
+       {
+         itkWarningMacro(<< "file does not specify color space, assuming 
sRGB");
+       }
+@@ -349,7 +329,6 @@
+ 
+   /* close the byte stream */
+   opj_stream_destroy(cio);
+-  fclose(l_file);
+ 
+   if (this->m_Internal->m_Dinfo)
+   {
+@@ -368,16 +347,7 @@
+ {
+   itkDebugMacro(<< "JPEG2000ImageIO::Read() Begin");
+ 
+-  FILE * l_file = fopen(this->m_FileName.c_str(), "rb");
+-
+-  if (!l_file)
+-  {
+-    itkExceptionMacro("JPEG2000ImageIO failed to open file for reading: " << 
this->GetFileName() << std::endl
+-                                                                          << 
"Reason: "
+-                                                                          << 
itksys::SystemTools::GetLastSystemError());
+-  }
+-
+-  opj_stream_t * l_stream = opj_stream_create_default_file_stream(l_file, 
true);
++  opj_stream_t * l_stream = 
opj_stream_create_default_file_stream(this->m_FileName.c_str(), true);
+   if (!l_stream)
+   {
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+@@ -397,9 +367,10 @@
+     {
+       /* JPEG-2000 codestream */
+       /* get a decoder handle */
+-      this->m_Internal->m_Dinfo = opj_create_decompress(CODEC_J2K);
++      this->m_Internal->m_Dinfo = opj_create_decompress(OPJ_CODEC_J2K);
+       if (!this->m_Internal->m_Dinfo)
+       {
++        opj_stream_destroy(l_stream);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                           << this->GetFileName() << std::endl
+                           << "Reason: opj_create_decompress(CODEC_J2K) 
returns nullptr");
+@@ -410,9 +381,10 @@
+     {
+       /* JPEG 2000 compressed image data */
+       /* get a decoder handle */
+-      this->m_Internal->m_Dinfo = opj_create_decompress(CODEC_JP2);
++      this->m_Internal->m_Dinfo = opj_create_decompress(OPJ_CODEC_JP2);
+       if (!this->m_Internal->m_Dinfo)
+       {
++        opj_stream_destroy(l_stream);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                           << this->GetFileName() << std::endl
+                           << "Reason: opj_create_decompress(CODEC_JP2) 
returns nullptr");
+@@ -423,9 +395,10 @@
+     {
+       /* JPEG 2000, JPIP */
+       /* get a decoder handle */
+-      this->m_Internal->m_Dinfo = opj_create_decompress(CODEC_JPT);
++      this->m_Internal->m_Dinfo = opj_create_decompress(OPJ_CODEC_JPT);
+       if (!this->m_Internal->m_Dinfo)
+       {
++        opj_stream_destroy(l_stream);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                           << this->GetFileName() << std::endl
+                           << "Reason: opj_create_decompress(CODEC_JPT) 
returns nullptr");
+@@ -433,7 +406,7 @@
+       break;
+     }
+     default:
+-      fclose(l_file);
++      opj_stream_destroy(l_stream);
+       itkExceptionMacro("JPEG2000ImageIO failed to read file: "
+                         << this->GetFileName() << std::endl
+                         << "Reason: "
+@@ -445,32 +418,17 @@
+   if (!opj_setup_decoder(this->m_Internal->m_Dinfo, 
&(this->m_Internal->m_DecompressionParameters)))
+   {
++    opj_stream_destroy(l_stream);
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+                                                               << "Reason: 
opj_setup_decoder returns false");
+   }
+ 
+-  OPJ_INT32 l_tile_x0, l_tile_y0;
+-
+-  OPJ_UINT32 l_tile_width;
+-  OPJ_UINT32 l_tile_height;
+-  OPJ_UINT32 l_nb_tiles_x;
+-  OPJ_UINT32 l_nb_tiles_y;
+-
+-  bool bResult = opj_read_header(this->m_Internal->m_Dinfo,
+-                                 &l_image,
+-                                 &l_tile_x0,
+-                                 &l_tile_y0,
+-                                 &l_tile_width,
+-                                 &l_tile_height,
+-                                 &l_nb_tiles_x,
+-                                 &l_nb_tiles_y,
+-                                 l_stream);
++  bool bResult = opj_read_header(l_stream, this->m_Internal->m_Dinfo, 
&l_image);
+ 
+   if (!bResult)
+   {
+     opj_destroy_codec(this->m_Internal->m_Dinfo);
+     this->m_Internal->m_Dinfo = nullptr;
+     opj_stream_destroy(l_stream);
+-    fclose(l_file);
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+                                                               << "Reason: 
opj_read_header returns false");
+   }
+@@ -499,7 +457,7 @@
+   itkDebugMacro(<< "p_end_x = " << p_end_x);
+   itkDebugMacro(<< "p_end_y = " << p_end_y);
+ 
+-  bResult = opj_set_decode_area(this->m_Internal->m_Dinfo, p_start_x, 
p_start_y, p_end_x, p_end_y);
++  bResult = opj_set_decode_area(this->m_Internal->m_Dinfo, l_image, 
p_start_x, p_start_y, p_end_x, p_end_y);
+ 
+   itkDebugMacro(<< "opj_set_decode_area() after");
+ 
+@@ -509,6 +467,5 @@
+     this->m_Internal->m_Dinfo = nullptr;
+     opj_stream_destroy(l_stream);
+-    fclose(l_file);
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+                                                               << "Reason: 
opj_set_decode_area returns false");
+   }
+@@ -525,13 +482,14 @@
+ 
+   OPJ_UINT32 l_max_data_size = 1000;
+ 
+-  bool l_go_on = true;
++  OPJ_BOOL l_go_on = true;
+ 
+   auto * l_data = (OPJ_BYTE *)malloc(1000);
+ 
+   while (l_go_on)
+   {
+     bool tileHeaderRead = opj_read_tile_header(this->m_Internal->m_Dinfo,
++                                               l_stream,
+                                                &l_tile_index,
+                                                &l_data_size,
+                                                &l_current_tile_x0,
+@@ -540,13 +498,11 @@
+                                                &l_current_tile_y1,
+                                                &l_nb_comps,
+-                                               &l_go_on,
+-                                               l_stream);
++                                               &l_go_on);
+ 
+     if (!tileHeaderRead)
+     {
+       free(l_data);
+       opj_stream_destroy(l_stream);
+-      fclose(l_file);
+       opj_destroy_codec(this->m_Internal->m_Dinfo);
+       opj_image_destroy(l_image);
+       itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+@@ -571,7 +527,6 @@
+         if (!l_data)
+         {
+           opj_stream_destroy(l_stream);
+-          fclose(l_file);
+           opj_destroy_codec(this->m_Internal->m_Dinfo);
+           opj_image_destroy(l_image);
+           itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+@@ -590,7 +545,6 @@
+       {
+         free(l_data);
+         opj_stream_destroy(l_stream);
+-        fclose(l_file);
+         opj_destroy_codec(this->m_Internal->m_Dinfo);
+         opj_image_destroy(l_image);
+         itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+@@ -654,7 +608,6 @@
+   {
+     free(l_data);
+     opj_stream_destroy(l_stream);
+-    fclose(l_file);
+     opj_destroy_codec(this->m_Internal->m_Dinfo);
+     opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+@@ -667,13 +620,11 @@
+     this->m_Internal->m_Dinfo = nullptr;
+     opj_stream_destroy(l_stream);
+-    fclose(l_file);
+     itkExceptionMacro("JPEG2000ImageIO failed to read file: " << 
this->GetFileName() << std::endl
+                                                               << "Reason: 
error whle reading image");
+   }
+ 
+   /* close the byte stream */
+   opj_stream_destroy(l_stream);
+-  fclose(l_file);
+ 
+   if (this->m_Internal->m_Dinfo)
+   {
+@@ -840,13 +791,13 @@
+ 
+   parameters.numresolution = numberOfResolutions;
+ 
+-  OPJ_COLOR_SPACE      color_space = CLRSPC_GRAY;
++  OPJ_COLOR_SPACE      color_space = OPJ_CLRSPC_GRAY;
+   opj_image_cmptparm_t cmptparms[3];
+ 
+   if (this->GetNumberOfComponents() == 3)
+   {
+ 
+-    color_space = (this->GetPixelType() == IOPixelEnum::RGB) ? CLRSPC_SRGB : 
CLRSPC_UNSPECIFIED;
++    color_space = (this->GetPixelType() == IOPixelEnum::RGB) ? 
OPJ_CLRSPC_SRGB : OPJ_CLRSPC_UNSPECIFIED;
+ 
+     /* initialize image components */
+     memset(&cmptparms[0], 0, 3 * sizeof(opj_image_cmptparm_t));
+@@ -864,7 +815,7 @@
+ 
+   if (this->GetNumberOfComponents() == 1)
+   {
+-    color_space = CLRSPC_GRAY;
++    color_space = OPJ_CLRSPC_GRAY;
+ 
+     /* initialize image components */
+     memset(&cmptparms[0], 0, sizeof(opj_image_cmptparm_t));
+@@ -941,8 +892,9 @@
+   if (extension == ".j2k")
+   {
+-    cinfo = opj_create_compress(CODEC_J2K);
++    cinfo = opj_create_compress(OPJ_CODEC_J2K);
+     if (!cinfo)
+     {
++      opj_image_destroy(l_image);
+       itkExceptionMacro("JPEG2000ImageIO failed to write file: "
+                         << this->GetFileName() << std::endl
+                         << "Reason: opj_create_compress(CODEC_J2K) returns 
nullptr");
+@@ -950,9 +902,10 @@
+   }
+   else if (extension == ".jp2")
+   {
+-    cinfo = opj_create_compress(CODEC_JP2);
++    cinfo = opj_create_compress(OPJ_CODEC_JP2);
+     if (!cinfo)
+     {
++      opj_image_destroy(l_image);
+       itkExceptionMacro("JPEG2000ImageIO failed to write file: "
+                         << this->GetFileName() << std::endl
+                         << "Reason: opj_create_compress(CODEC_JP2) returns 
nullptr");
+@@ -960,9 +913,10 @@
+   }
+   else if (extension == ".jpt")
+   {
+-    cinfo = opj_create_compress(CODEC_JPT);
++    cinfo = opj_create_compress(OPJ_CODEC_JPT);
+     if (!cinfo)
+     {
++      opj_image_destroy(l_image);
+       itkExceptionMacro("JPEG2000ImageIO failed to write file: "
+                         << this->GetFileName() << std::endl
+                         << "Reason: opj_create_compress(CODEC_JPT) returns 
nullptr");
+@@ -970,6 +924,7 @@
+   }
+   else
+   {
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to write file: " << 
this->GetFileName() << std::endl
+                                                                << "Reason: 
unknown encode format: " << extension);
+   }
+@@ -985,23 +940,19 @@
+ 
+   if (!opj_setup_encoder(cinfo, &parameters, l_image))
+   {
++    opj_destroy_codec(cinfo);
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to write file: " << 
this->GetFileName() << std::endl
+                                                                << "Reason: 
opj_setup_encoder returns false");
+   }
+ 
+-  FILE * l_file = fopen(parameters.outfile, "wb");
+-  if (!l_file)
+-  {
+-    itkExceptionMacro("JPEG2000ImageIO failed to open file for writing: " << 
this->GetFileName() << std::endl
+-                                                                          << 
"Reason: "
+-                                                                          << 
itksys::SystemTools::GetLastSystemError());
+-  }
+-
+   /* open a byte stream for writing */
+   /* allocate memory for all tiles */
+-  opj_stream_t * cio = opj_stream_create_default_file_stream(l_file, false);
++  opj_stream_t * cio = 
opj_stream_create_default_file_stream(parameters.outfile, false);
+   if (!cio)
+   {
++    opj_destroy_codec(cinfo);
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to write file: "
+                       << this->GetFileName() << std::endl
+                       << "Reason: "
+@@ -1017,7 +968,8 @@
+   if (!bSuccess)
+   {
+     opj_stream_destroy(cio);
+-    fclose(l_file);
++    opj_destroy_codec(cinfo);
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to write file: " << 
this->GetFileName() << std::endl
+                                                                << "Reason: 
opj_start_compress returns false");
+   }
+@@ -1026,7 +978,8 @@
+   if (!bSuccess)
+   {
+     opj_stream_destroy(cio);
+-    fclose(l_file);
++    opj_destroy_codec(cinfo);
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to write file: " << 
this->GetFileName() << std::endl
+                                                                << "Reason: 
opj_encode returns false");
+   }
+@@ -1035,14 +988,14 @@
+   if (!bSuccess)
+   {
+     opj_stream_destroy(cio);
+-    fclose(l_file);
++    opj_destroy_codec(cinfo);
++    opj_image_destroy(l_image);
+     itkExceptionMacro("JPEG2000ImageIO failed to write file: " << 
this->GetFileName() << std::endl
+                                                                << "Reason: 
opj_end_compress returns false");
+   }
+ 
+   /* close and free the byte stream */
+   opj_stream_destroy(cio);
+-  fclose(l_file);
+ 
+   /* free remaining compression structures */
+   opj_destroy_codec(cinfo);
+--- a/Modules/Nonunit/Review/src/CMakeLists.txt
++++ b/Modules/Nonunit/Review/src/CMakeLists.txt
+@@ -5,7 +5,7 @@
+ 
+ add_library(ITKReview ${ITKReview_SRC})
+ itk_module_link_dependencies()
+-target_link_libraries(ITKReview LINK_PUBLIC ${ITKTestKernel_LIBRARIES} 
${ITKIOLSM_LIBRARIES} itkopenjpeg)
++target_link_libraries(ITKReview LINK_PUBLIC ${ITKTestKernel_LIBRARIES} 
${ITKIOLSM_LIBRARIES} ${ITKOpenJPEG_LIBRARIES})
+ itk_module_target(ITKReview)
+ 
+ 

diff --git a/sci-libs/itk/itk-5.3.0.ebuild b/sci-libs/itk/itk-5.3.0.ebuild
new file mode 100644
index 000000000..54b7c89b3
--- /dev/null
+++ b/sci-libs/itk/itk-5.3.0.ebuild
@@ -0,0 +1,251 @@
+# Copyright 1999-2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+
+PYTHON_COMPAT=( python3_{10..11} )
+VIRTUALX_REQUIRED="manual"
+
+inherit cmake python-single-r1 virtualx
+
+# rsync: [sender] link_stat 
"/distfiles/1c/itk-test-bcdbb347f3704262d1f00be7179d6a0a6e68aed56c0653e8072ee5a94985c713bd229c935b1226a658af84fb7f1fffc2458c98364fc35303a2303b12f9f7ce2f"
 (in gentoo) failed: No such file or directory (2)
+
+MY_PN="InsightToolkit"
+MY_P="${MY_PN}-${PV}"
+GLI_V="1.2.0"
+IAD_HASH="24825c8d246e941334f47968553f0ae388851f0c"
+TEST_HASH="bb6d3b9a932333901465c75417fe8859124f5fed"
+declare -a GLI_TEST_HASHES=(
+       
"a5e11ea71164ff78c65fcf259db01ea5db981a9d868e60045ff2bffca92984df1174bf984a1076e450f0d5d69b4f0191ed1a61465c220e2c91a893b5df150c0a"
+       
"bcdbb347f3704262d1f00be7179d6a0a6e68aed56c0653e8072ee5a94985c713bd229c935b1226a658af84fb7f1fffc2458c98364fc35303a2303b12f9f7ce2f"
+)
+
+GLI_TEST_SRC=""
+for i in "${GLI_TEST_HASHES[@]}"; do
+       
GLI_TEST_SRC+="https://data.kitware.com/api/v1/file/hashsum/sha512/${i}/download
 -> ${PN}-test-${i} "
+done
+
+DESCRIPTION="NLM Insight Segmentation and Registration Toolkit"
+HOMEPAGE="https://itk.org";
+SRC_URI="
+       
https://github.com/InsightSoftwareConsortium/ITK/releases/download/v${PV}/${MY_P}.tar.gz
+       
https://github.com/InsightSoftwareConsortium/ITKGenericLabelInterpolator/archive/refs/tags/v${GLI_V}.tar.gz
 -> ITKGenericLabelInterpolator-${GLI_V}
+       
https://github.com/ntustison/ITKAdaptiveDenoising/archive/${IAD_HASH}.tar.gz -> 
ITKAdaptiveDenoising-${PV}.tar.gz
+       test? (
+               
https://github.com/InsightSoftwareConsortium/ITK/releases/download/v${PV}/InsightData-${PV}.tar.gz
+               
https://github.com/InsightSoftwareConsortium/ITKTestingData/archive/${TEST_HASH}.tar.gz
 -> ${P}-testingdata.tar.gz
+               ${GLI_TEST_SRC}
+               )
+       "
+
+LICENSE="Apache-2.0"
+SLOT="0"
+KEYWORDS="~amd64 ~x86"
+IUSE="debug doc examples fftw itkv4-compat python review test vtkglue"
+REQUIRED_USE="python? ( ${PYTHON_REQUIRED_USE} )"
+
+RESTRICT="!test? ( test )"
+
+RDEPEND="
+       dev-cpp/eigen:3
+       dev-libs/double-conversion:0=
+       dev-libs/expat:0=
+       media-libs/openjpeg:2
+       media-libs/libpng:0=
+       media-libs/tiff:0=[jpeg]
+       sci-libs/dcmtk:0=
+       sci-libs/hdf5:0=[cxx]
+       sci-libs/gdcm:0=
+       sys-libs/zlib:0=
+       media-libs/libjpeg-turbo:0=
+       fftw? ( sci-libs/fftw:3.0= )
+       vtkglue? (
+               sci-libs/vtk:0=[rendering]
+               python? (
+                       sci-libs/vtk:0=[python,${PYTHON_SINGLE_USEDEP}]
+               )
+       )
+       python? ( ${PYTHON_DEPS} )
+"
+DEPEND="${RDEPEND}
+       sys-apps/coreutils
+       python? (
+               >=dev-lang/swig-2.0:0
+               dev-libs/castxml
+       )
+       doc? ( app-doc/doxygen )
+"
+BDEPEND="
+       test? (
+               vtkglue? ( ${VIRTUALX_DEPEND} )
+               python? (
+                       $(python_gen_cond_dep 
'dev-python/numpy[${PYTHON_USEDEP}]')
+               )
+       )
+"
+
+S="${WORKDIR}/${MY_P}"
+
+PATCHES=(
+       "${FILESDIR}/${PN}-5.2.1-system-tiff-has-64.patch"
+       "${FILESDIR}/${PN}-5.3.0-system-openjpeg.patch"
+)
+
+pkg_pretend() {
+       if [[ -z ${ITK_COMPUTER_MEMORY_SIZE} ]]; then
+               elog "To tune ITK to make the best use of working memory you 
can set"
+               elog "    ITK_COMPUTER_MEMORY_SIZE=XX"
+               elog "in make.conf, default is 1 (unit is GB)"
+       fi
+       if use python && [[ -z ${ITK_WRAP_DIMS} ]]; then
+               elog "For Python language bindings, you can define the 
dimensions"
+               elog "you want to create bindings for by setting"
+               elog "    ITK_WRAP_DIMS=X;Y;Z..."
+               elog "in make.conf, default is 2;3 for 2D and 3D data"
+       fi
+}
+
+src_prepare() {
+       # drop bundled libs
+       local -a DROPS=(
+               DoubleConversion/src/double-conversion
+               Eigen3/src/itkeigen
+               Expat/src/expat
+               GDCM/src/gdcm
+               JPEG/src/itkjpeg
+               HDF5/src/itkhdf5
+               OpenJPEG/src/openjpeg
+               PNG/src/itkpng
+               TIFF/src/itktiff
+       )
+       local x
+       for x in "${DROPS[@]}"; do
+               ebegin "Dropping bundled ${x%%/*}"
+               rm -r "Modules/ThirdParty/${x}" || die
+               eend $?
+       done
+       {
+               find Modules/ThirdParty -mindepth 2 -maxdepth 2 -type d -name 
src -printf '%P\n'
+               printf '%s\n' "${DROPS[@]}" | sed 's,/[^/]*$,,'
+       } | sort | uniq -u | xargs -n 1 ewarn "Using bundled" || die
+
+       # Remote modules
+       ln -sr "../ITKGenericLabelInterpolator-${GLI_HASH}" 
Modules/External/ITKGenericLabelInterpolator || die
+       ln -sr "../ITKAdaptiveDenoising-${IAD_HASH}" 
Modules/External/ITKAdaptiveDenoising || die
+
+       cmake_src_prepare
+
+       if use test; then
+               cp -rf "../ITKTestingData-${TEST_HASH}/"* ".ExternalData/" || 
die
+               mv "../ITKTestingData-${TEST_HASH}" 
"${BUILD_DIR}/.ExternalData" || die
+               for i in "${GLI_TEST_HASHES[@]}"; do
+                       cp "${DISTDIR}/${PN}-test-${i}" 
".ExternalData/SHA512/${i}" || die
+                       cp "${DISTDIR}/${PN}-test-${i}" 
"${BUILD_DIR}/.ExternalData/SHA512/${i}" || die
+               done
+       fi
+}
+
+src_configure() {
+       local mycmakeargs=(
+               -DITK_BUILD_DOCUMENTATION="$(usex doc ON OFF)"
+               -DITK_INSTALL_DOC_DIR="share/doc/${P}"
+               -DBUILD_EXAMPLES="$(usex examples ON OFF)"
+               -DBUILD_SHARED_LIBS=ON
+               -DBUILD_TESTING="$(usex test ON OFF)"
+               
-Ddouble-conversion_INCLUDE_DIRS="${EPREFIX}/usr/include/double-conversion"
+               
-DExternalData_OBJECT_STORES="${WORKDIR}/InsightToolkit-${PV}/.ExternalData"
+               -DGDCM_USE_SYSTEM_OPENJPEG=ON
+               -DITK_FORBID_DOWNLOADS:BOOL=ON
+               -DITK_INSTALL_LIBRARY_DIR=$(get_libdir)
+               -DITK_USE_REVIEW="$(usex review ON OFF)"
+               -DITK_USE_SYSTEM_DCMTK=ON
+               -DITK_USE_SYSTEM_DOUBLECONVERSION=ON
+               -DITK_USE_SYSTEM_CASTXML=ON
+               -DITK_USE_SYSTEM_EIGEN=ON
+               -DITK_USE_SYSTEM_EXPAT=ON
+               -DITK_USE_SYSTEM_GDCM=ON
+               -DITK_USE_SYSTEM_HDF5=ON
+               -DITK_USE_SYSTEM_JPEG=ON
+               -DITK_USE_SYSTEM_OPENJPEG=ON
+               -DITK_USE_SYSTEM_PNG=ON
+               -DITK_USE_SYSTEM_SWIG=ON
+               -DITK_USE_SYSTEM_TIFF=ON
+               -DITK_USE_SYSTEM_ZLIB=ON
+               -DITK_USE_KWSTYLE=OFF
+               -DITK_BUILD_DEFAULT_MODULES=ON
+               -DITK_COMPUTER_MEMORY_SIZE="${ITK_COMPUTER_MEMORY_SIZE:-1}"
+               -DModule_AdaptiveDenoising:BOOL=ON
+               -DModule_GenericLabelInterpolator:BOOL=ON
+               -DModule_ITKReview:BOOL=ON
+               -DWRAP_ITK_JAVA=OFF
+               -DWRAP_ITK_TCL=OFF
+               -DITKV4_COMPATIBILITY:BOOL=$(usex itkv4-compat)
+       )
+       if use fftw; then
+               mycmakeargs+=(
+                       -DUSE_FFTWD=ON
+                       -DUSE_FFTWF=ON
+                       -DUSE_SYSTEM_FFTW=ON
+                       -DITK_WRAP_double=ON
+                       -DITK_WRAP_vector_double=ON
+                       -DITK_WRAP_covariant_vector_double=ON
+                       -DITK_WRAP_complex_double=ON
+               )
+       fi
+       if use vtkglue; then
+               mycmakeargs+=(
+                       -DModule_ITKVtkGlue=ON
+               )
+       fi
+       if use python; then
+               mycmakeargs+=(
+                       -DITK_WRAP_PYTHON=ON
+                       -DPython3_EXECUTABLE="${PYTHON}"
+                       -DITK_WRAP_DIMS="${ITK_WRAP_DIMS:-2;3}"
+               )
+       else
+               mycmakeargs+=(
+                       -DITK_WRAP_PYTHON=OFF
+               )
+       fi
+       cmake_src_configure
+}
+
+src_install() {
+       cmake_src_install
+
+       if use examples; then
+               docinto examples
+               docompress -x /usr/share/doc/${PF}/examples
+               dodoc -r "${S}"/Examples/*
+       fi
+
+       echo "ITK_DATA_ROOT=${EPREFIX}/usr/share/${PN}/data" > ${T}/40${PN} || 
die
+       local ldpath="${EPREFIX}/usr/$(get_libdir)/InsightToolkit"
+       if use python; then
+               echo 
"PYTHONPATH=${EPREFIX}/usr/$(get_libdir)/InsightToolkit/WrapITK/Python" >> 
"${T}"/40${PN} || die
+               
ldpath="${ldpath}:${EPREFIX}/usr/$(get_libdir)/InsightToolkit/WrapITK/lib"
+       fi
+       echo "LDPATH=${ldpath}" >> "${T}"/40${PN} || die
+       doenvd "${T}"/40${PN}
+
+       if use doc; then
+               cd "${WORKDIR}"/html || die
+               rm  *.md5 || die "Failed to remove superfluous hashes"
+               einfo "Installing API docs. This may take some time."
+               docinto api-docs
+               dodoc -r *
+       fi
+
+       use python && python_optimize
+}
+
+src_test() {
+       # Failing tests reported upstream:
+       # https://github.com/ntustison/ITKAdaptiveDenoising/issues/13
+       if use vtkglue; then
+               virtx cmake_src_test -E 
"(AdaptiveNonLocalMeansDenoisingImageFilterTest1|AdaptiveNonLocalMeansDenoisingImageFilterTest2)"
+       else
+               cmake_src_test -E 
"(AdaptiveNonLocalMeansDenoisingImageFilterTest1|AdaptiveNonLocalMeansDenoisingImageFilterTest2)"
+       fi
+}

Reply via email to