Skip to content

Commit

Permalink
Added TIFF codec version reporting in logfile and updated return sign…
Browse files Browse the repository at this point in the history
…ature for getCodecVersion() function.

Also code cleanups for OpenJPEGImage and KakaduImage classes.
  • Loading branch information
ruven committed Sep 24, 2024
1 parent cfad495 commit 91b553a
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 17 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
24/09/2024:
- Added TIFF codec version reporting in logfile and updated return signature for getCodecVersion() function.
Also code cleanups for OpenJPEGImage and KakaduImage classes.


13/09/2024:
- Updated XYZ to sRGB conversion matrix to use that in the official IEC 61966-2-1 specification

Expand Down
2 changes: 1 addition & 1 deletion src/IIPImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ class IIPImage {

/// Get codec version
/** @return codec version */
static const char* getCodecVersion(){ return "0.0.0"; };
static std::string getCodecVersion(){ return "0.0.0"; };


/// Comparison equality operator
Expand Down
2 changes: 1 addition & 1 deletion src/JTL.cc
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void JTL::send( Session* session, int resolution, int tile ){
#ifdef HAVE_WEBP
else if( session->view->output_format == ImageEncoding::WEBP ) compressor = session->webp;
#endif
#ifdef HAVE_AVIF
#ifdef HAVE_AVIF
else if( session->view->output_format == ImageEncoding::AVIF ) compressor = session->avif;
#endif
else compressor = session->jpeg;
Expand Down
4 changes: 2 additions & 2 deletions src/KakaduImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,9 @@ void KakaduImage::loadImageInfo( int seq, int ang )
logfile << "Kakadu :: Capture Resolution : " << dpi_x << "x" << dpi_y << " pixels/cm" << endl;
#endif

// Loop through each resolution and calculate the image dimensions -
// Loop through each resolution and calculate the image dimensions -
// We calculate ourselves rather than relying on get_dims() to force a similar
// behaviour to TIFF with resolutions at floor(x/2) rather than Kakadu's default ceil(x/2)
// behaviour to TIFF with resolutions at floor(x/2) rather than Kakadu's default ceil(x/2)
for( unsigned int c=1; c<numResolutions; c++ ){
// codestream.apply_input_restrictions(0,0,c,1,NULL,KDU_WANT_OUTPUT_COMPONENTS);
// kdu_dims layers;
Expand Down
4 changes: 2 additions & 2 deletions src/KakaduImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Culture of the Czech Republic.
Copyright (C) 2009-2023 IIPImage.
Copyright (C) 2009-2024 IIPImage.
Author: Ruven Pillay
This program is free software; you can redistribute it and/or modify
Expand Down Expand Up @@ -139,7 +139,7 @@ class KakaduImage : public IIPImage {

/// Get codec version
/** @return codec version */
static const char* getCodecVersion(){ return kdu_get_core_version(); };
static std::string getCodecVersion(){ return kdu_get_core_version(); };


/// Overloaded function for opening a TIFF image
Expand Down
1 change: 1 addition & 0 deletions src/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ int main( int argc, char *argv[] )
logfile << "Setting ICC profile embedding to " << (embed_icc? "true" : "false") << endl;
logfile << "Setting codec passthrough to " << (IIPImage::codec_passthrough? "true" : "false") << endl;
if( !copyright.empty() ) logfile << "Setting default rights/copyright statement to '" << copyright << "'" << endl;
logfile << "Setting up TIFF support via " << TPTImage::getCodecVersion() << endl;
#ifdef HAVE_KAKADU
logfile << "Setting up JPEG2000 support via Kakadu SDK " << KakaduImage::getCodecVersion() << endl;
logfile << "Setting Kakadu read-mode to " << ((kdu_readmode==2) ? "resilient" : (kdu_readmode==1) ? "fussy" : "fast") << endl;
Expand Down
20 changes: 10 additions & 10 deletions src/OpenJPEGImage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,9 @@ void OpenJPEGImage::loadImageInfo( int seq, int ang )
logfile << "OpenJPEG :: Resolution : " << w << "x" << h << endl;
#endif

// Loop through each resolution and calculate the image dimensions -
// Loop through each resolution and calculate the image dimensions -
// We force a similar behaviour to TIFF with resolutions at floor(x/2)
// rather than OpenJPEG's default ceil(x/2)
// rather than OpenJPEG's default ceil(x/2)
for( unsigned int c=1; c<numResolutions; c++ ){
w = floor( w/2.0 );
h = floor( h/2.0 );
Expand Down Expand Up @@ -274,7 +274,7 @@ void OpenJPEGImage::loadImageInfo( int seq, int ang )
if( bpc == 16 ) max.push_back( 65535.0 );
else max.push_back( 255.0 );
}

// Indicate that our metadata has been read
isSet = true;

Expand Down Expand Up @@ -310,7 +310,7 @@ RawTile OpenJPEGImage::getTile( int seq, int ang, unsigned int res, int layers,

unsigned int tw = tile_widths[0];
unsigned int th = tile_heights[0];

// Get the width and height for last row and column tiles
unsigned int rem_x = image_widths[vipsres] % tile_widths[0];
unsigned int rem_y = image_heights[vipsres] % tile_heights[0];
Expand Down Expand Up @@ -339,7 +339,7 @@ RawTile OpenJPEGImage::getTile( int seq, int ang, unsigned int res, int layers,
// Calculate the pixel offsets for this tile
int xoffset = (tile % ntlx) * tile_widths[0];
int yoffset = (unsigned int) floor((double)(tile/ntlx)) * tile_heights[0];

#ifdef OPENJPEG_DEBUG
logfile << "OpenJPEG :: Tile size: " << tw << "x" << th << " @" << channels << endl;
#endif
Expand Down Expand Up @@ -372,7 +372,7 @@ RawTile OpenJPEGImage::getRegion( int ha, int va, unsigned int res, int layers,
unsigned int obpc = bpc;
if( bpc <= 16 && bpc > 8 ) obpc = 16;
else if( bpc <= 8 ) obpc = 8;

#ifdef OPENJPEG_DEBUG
Timer timer;
timer.start();
Expand Down Expand Up @@ -410,7 +410,7 @@ void OpenJPEGImage::process( unsigned int res, int layers, int xoffset, int yoff
else if( bpc <= 8 ) obpc = 8;

unsigned int factor = 1; // Downsampling factor - set it to default value
int vipsres = (numResolutions - 1) - res; // Reverse resolution number
int vipsres = getNativeResolution( res ); // Reverse resolution number

// Calculate number of extra resolutions needed that have not been encoded in the image
if( res < virtual_levels ){
Expand Down Expand Up @@ -488,10 +488,10 @@ void OpenJPEGImage::process( unsigned int res, int layers, int xoffset, int yoff
// Copy our decoded data by looping over all pixels
size_t n = 0;

for( unsigned int j=0; j < th; j += factor ){
for( unsigned int i = 0; i < tw; i += factor ){
for( unsigned int j=0; j<th; j+=factor ){
for( unsigned int i=0; i<tw; i+=factor ){
size_t index = tw*j + i;
for( unsigned int k = 0; k < channels; k++ ){
for( unsigned int k=0; k<channels; k++ ){
// Handle 16 and 8 bit data:
// OpenJPEG's output data is 32 bit unsigned int, so just mask of the bottom 2 bytes
// for 16 bit output or bottom 1 byte for 8 bit
Expand Down
2 changes: 1 addition & 1 deletion src/OpenJPEGImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class OpenJPEGImage : public IIPImage {

/// Get codec version
/** @return codec version */
static const char* getCodecVersion(){ return opj_version(); };
static std::string getCodecVersion(){ return opj_version(); };


};
Expand Down
20 changes: 20 additions & 0 deletions src/TPTImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,19 @@ class TPTImage : public IIPImage {
/// Constructor
TPTImage():IIPImage(), tiff( NULL ) {};


/// Constructor
/** @param path image path
*/
TPTImage( const std::string& path ): IIPImage(path), tiff(NULL), subifd_ifd(0) {};


/// Copy Constructor
/** @param image IIPImage object
*/
TPTImage( const TPTImage& image ): IIPImage(image), tiff(NULL), subifd_ifd(0) {};


/// Assignment Operator
/** @param image TPTImage object
*/
Expand All @@ -78,29 +81,46 @@ class TPTImage : public IIPImage {
return *this;
}


/// Construct from an IIPImage object
/** @param image IIPImage object
*/
TPTImage( const IIPImage& image ): IIPImage(image), tiff(NULL), subifd_ifd(0) {};


/// Destructor
~TPTImage() { closeImage(); };


/// Overloaded static function for seting up logging for codec library
static void setupLogging();


/// Get codec version
/** @return codec version */
static std::string getCodecVersion(){
std::string version = std::string( TIFFGetVersion() );
// Strip off everything after newline
version = version.substr( 0, version.find_first_of("\n") );
return version;
}


/// Overloaded function for opening a TIFF image
void openImage();


/// Overloaded function for loading TIFF image information
/** @param x horizontal sequence angle
@param y vertical sequence angle
*/
void loadImageInfo( int x, int y );


/// Overloaded function for closing a TIFF image
void closeImage();


/// Overloaded function for getting a particular tile
/** @param x horizontal sequence angle
@param y vertical sequence angle
Expand Down

0 comments on commit 91b553a

Please sign in to comment.