Skip to content
Permalink
Browse files Browse the repository at this point in the history
Added verification that image has been set in SPECTRA.cc and check on…
… the validity of the requested tile resolution in JTL.cc. Fixes a couple of the crash conditions reported in #223
  • Loading branch information
ruven committed Jan 14, 2022
1 parent 4db9fff commit 4ed5926
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
15/01/2022:
- Added verification that image has been set in SPECTRA.cc and check on the validity of the requested tile
resolution in JTL.cc. Fixes a couple of the crash conditions reported in https://github.com/ruven/iipsrv/issues/223


14/01/2022:
- Detection of HTJ2K also added for KakaduImage.cc for logging purposes (DEBUG needs to be enabled at compile time)

Expand Down
31 changes: 18 additions & 13 deletions src/JTL.cc
@@ -1,7 +1,7 @@
/*
IIP JTL Command Handler Class Member Function: Export a single tile
Copyright (C) 2006-2021 Ruven Pillay.
Copyright (C) 2006-2022 Ruven Pillay.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -43,6 +43,10 @@ void JTL::send( Session* session, int resolution, int tile ){
if( session->loglevel >= 2 ) command_timer.start();


// Need to know the number of resolutions
int num_res = (*session->image)->getNumResolutions();


// If we have requested a rotation, remap the tile index to rotated coordinates
if( (int)((session->view)->getRotation()) % 360 == 90 ){

Expand All @@ -51,7 +55,6 @@ void JTL::send( Session* session, int resolution, int tile ){

}
else if( (int)((session->view)->getRotation()) % 360 == 180 ){
int num_res = (*session->image)->getNumResolutions();
unsigned int im_width = (*session->image)->image_widths[num_res-resolution-1];
unsigned int im_height = (*session->image)->image_heights[num_res-resolution-1];
unsigned int tw = (*session->image)->getTileWidth();
Expand All @@ -62,7 +65,7 @@ void JTL::send( Session* session, int resolution, int tile ){


// Sanity check
if( (resolution<0) || (tile<0) ){
if( (resolution<0) || (tile<0) || (resolution>=num_res) ){
ostringstream error;
error << "JTL :: Invalid resolution/tile number: " << resolution << "," << tile;
throw error.str();
Expand Down Expand Up @@ -120,18 +123,20 @@ void JTL::send( Session* session, int resolution, int tile ){


// Set the physical output resolution for this particular view and zoom level
int num_res = (*session->image)->getNumResolutions();
unsigned int im_width = (*session->image)->image_widths[num_res-resolution-1];
unsigned int im_height = (*session->image)->image_heights[num_res-resolution-1];
float dpi_x = (*session->image)->dpi_x * (float) im_width / (float) (*session->image)->getImageWidth();
float dpi_y = (*session->image)->dpi_y * (float) im_height / (float) (*session->image)->getImageHeight();
compressor->setResolution( dpi_x, dpi_y, (*session->image)->dpi_units );

if( session->loglevel >= 5 ){
*(session->logfile) << "JTL :: Setting physical resolution of tile to " << dpi_x << " x " << dpi_y
<< ( ((*session->image)->dpi_units==1) ? " pixels/inch" : " pixels/cm" ) << endl;
if( (*session->image)->dpi_x > 0 && (*session->image)->dpi_y > 0 ){
unsigned int im_width = (*session->image)->image_widths[num_res-resolution-1];
unsigned int im_height = (*session->image)->image_heights[num_res-resolution-1];
float dpi_x = (*session->image)->dpi_x * ( (float)im_width / (float)(*session->image)->getImageWidth() );
float dpi_y = (*session->image)->dpi_y * ( (float)im_height / (float)(*session->image)->getImageHeight() );
compressor->setResolution( dpi_x, dpi_y, (*session->image)->dpi_units );

if( session->loglevel >= 5 ){
*(session->logfile) << "JTL :: Setting physical resolution of tile to " << dpi_x << " x " << dpi_y
<< ( ((*session->image)->dpi_units==1) ? " pixels/inch" : " pixels/cm" ) << endl;
}
}


// Embed ICC profile
if( session->view->embedICC() && ((*session->image)->getMetadata("icc").size()>0) ){
if( session->loglevel >= 3 ){
Expand Down
15 changes: 9 additions & 6 deletions src/SPECTRA.cc
@@ -1,7 +1,7 @@
/*
IIP SPECTRA Command Handler Class Member Function
Copyright (C) 2009-2021 Ruven Pillay.
Copyright (C) 2009-2022 Ruven Pillay.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -36,7 +36,10 @@ void SPECTRA::run( Session* session, const std::string& argument ){

if( session->loglevel >= 3 ) (*session->logfile) << "SPECTRA handler reached" << endl;

int resolution, tile, x, y;

// Make sure we have set our image
this->session = session;
checkImage();


// Time this command
Expand All @@ -46,19 +49,19 @@ void SPECTRA::run( Session* session, const std::string& argument ){
// Parse the argument list
string arg = argument;
int delimitter = arg.find( "," );
resolution = atoi( arg.substr(0,delimitter).c_str() );
int resolution = atoi( arg.substr(0,delimitter).c_str() );

arg = arg.substr( delimitter + 1, arg.length() );
delimitter = arg.find( "," );
tile = atoi( arg.substr(0,delimitter).c_str() );
int tile = atoi( arg.substr(0,delimitter).c_str() );

arg = arg.substr( delimitter + 1, arg.length() );
delimitter = arg.find( "," );
x = atoi( arg.substr(0,delimitter).c_str() );
int x = atoi( arg.substr(0,delimitter).c_str() );

arg = arg.substr( delimitter + 1, arg.length() );
delimitter = arg.find( "," );
y = atoi( arg.substr(0,arg.length()).c_str() );
int y = atoi( arg.substr(0,arg.length()).c_str() );

if( session->loglevel >= 5 ){
(*session->logfile) << "SPECTRA :: resolution: " << resolution
Expand Down

0 comments on commit 4ed5926

Please sign in to comment.