Skip to content

Commit

Permalink
ENH: Add HTJP2K support for jph files
Browse files Browse the repository at this point in the history
  • Loading branch information
blowekamp committed Dec 5, 2024
1 parent 4cb465d commit 823a55f
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Modules/IO/JPEG2000/src/itkJPEG2000ImageIO.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ JPEG2000ImageIO::JPEG2000ImageIO()
this->AddSupportedWriteExtension(ext);
this->AddSupportedReadExtension(ext);
}

#if OPJ_VERSION_MAJOR >= 2 && OPJ_VERSION_MINOR >= 5
// HTJ2K with JP2 boxes OpenJPEG only support decoding as of 2.5.0
this->AddSupportedReadExtension(".jph");
#endif
}

JPEG2000ImageIO::~JPEG2000ImageIO() = default;
Expand All @@ -112,7 +117,7 @@ JPEG2000ImageIO::CanReadFile(const char * filename)
itkDebugMacro("JPEG2000ImageIO::CanReadFile()");

//
// If the file exists, and have extension .j2k or jp2 or jpt, then we are good
// If the file exists, and have extension j2k or jp2 or jpt or jph, then we are good
// to read it.
//
if (!itksys::SystemTools::FileExists(filename))
Expand Down Expand Up @@ -168,6 +173,11 @@ JPEG2000ImageIO::ReadImageInformation()
this->m_Internal->m_DecompressionParameters.decod_format =
static_cast<int>(JPEG2000ImageIOInternal::DecodingFormatEnum::JPT_CFMT);
}
else if (extension == ".jph")
{
this->m_Internal->m_DecompressionParameters.decod_format =
static_cast<int>(JPEG2000ImageIOInternal::DecodingFormatEnum::JP2_CFMT);
}

switch (this->m_Internal->m_DecompressionParameters.decod_format)
{
Expand Down Expand Up @@ -817,7 +827,7 @@ JPEG2000ImageIO::Write(const void * buffer)
for (auto & cmptparm : cmptparms)
{
cmptparm.prec = 8;
cmptparm.bpp = 8;
/* cmptparm.bpp = 8; deprecated "Use prec instead" */
cmptparm.sgnd = 0;
cmptparm.dx = 1;
cmptparm.dy = 1; // this->GetSpacing( 1 )
Expand All @@ -836,13 +846,13 @@ JPEG2000ImageIO::Write(const void * buffer)
if (this->GetComponentType() == IOComponentEnum::UCHAR)
{
cmptparms[0].prec = 8;
cmptparms[0].bpp = 8;
/* cmptparms[0].bpp = 8; deprecated "Use prec instead" */
}

if (this->GetComponentType() == IOComponentEnum::USHORT)
{
cmptparms[0].prec = 16;
cmptparms[0].bpp = 16;
/* cmptparms[0].bpp = 16; deprecated "Use prec instead" */
}

cmptparms[0].sgnd = 0;
Expand Down

0 comments on commit 823a55f

Please sign in to comment.