11/*
22 IIP JTL Command Handler Class Member Function: Export a single tile
33
4- Copyright (C) 2006-2021 Ruven Pillay.
4+ Copyright (C) 2006-2022 Ruven Pillay.
55
66 This program is free software; you can redistribute it and/or modify
77 it under the terms of the GNU General Public License as published by
@@ -43,6 +43,10 @@ void JTL::send( Session* session, int resolution, int tile ){
4343 if ( session->loglevel >= 2 ) command_timer.start ();
4444
4545
46+ // Need to know the number of resolutions
47+ int num_res = (*session->image )->getNumResolutions ();
48+
49+
4650 // If we have requested a rotation, remap the tile index to rotated coordinates
4751 if ( (int )((session->view )->getRotation ()) % 360 == 90 ){
4852
@@ -51,7 +55,6 @@ void JTL::send( Session* session, int resolution, int tile ){
5155
5256 }
5357 else if ( (int )((session->view )->getRotation ()) % 360 == 180 ){
54- int num_res = (*session->image )->getNumResolutions ();
5558 unsigned int im_width = (*session->image )->image_widths [num_res-resolution-1 ];
5659 unsigned int im_height = (*session->image )->image_heights [num_res-resolution-1 ];
5760 unsigned int tw = (*session->image )->getTileWidth ();
@@ -62,7 +65,7 @@ void JTL::send( Session* session, int resolution, int tile ){
6265
6366
6467 // Sanity check
65- if ( (resolution<0 ) || (tile<0 ) ){
68+ if ( (resolution<0 ) || (tile<0 ) || (resolution>=num_res) ){
6669 ostringstream error;
6770 error << " JTL :: Invalid resolution/tile number: " << resolution << " ," << tile;
6871 throw error.str ();
@@ -120,18 +123,20 @@ void JTL::send( Session* session, int resolution, int tile ){
120123
121124
122125 // Set the physical output resolution for this particular view and zoom level
123- int num_res = (*session->image )->getNumResolutions ();
124- unsigned int im_width = (*session->image )->image_widths [num_res-resolution-1 ];
125- unsigned int im_height = (*session->image )->image_heights [num_res-resolution-1 ];
126- float dpi_x = (*session->image )->dpi_x * (float ) im_width / (float ) (*session->image )->getImageWidth ();
127- float dpi_y = (*session->image )->dpi_y * (float ) im_height / (float ) (*session->image )->getImageHeight ();
128- compressor->setResolution ( dpi_x, dpi_y, (*session->image )->dpi_units );
129-
130- if ( session->loglevel >= 5 ){
131- *(session->logfile ) << " JTL :: Setting physical resolution of tile to " << dpi_x << " x " << dpi_y
132- << ( ((*session->image )->dpi_units ==1 ) ? " pixels/inch" : " pixels/cm" ) << endl;
126+ if ( (*session->image )->dpi_x > 0 && (*session->image )->dpi_y > 0 ){
127+ unsigned int im_width = (*session->image )->image_widths [num_res-resolution-1 ];
128+ unsigned int im_height = (*session->image )->image_heights [num_res-resolution-1 ];
129+ float dpi_x = (*session->image )->dpi_x * ( (float )im_width / (float )(*session->image )->getImageWidth () );
130+ float dpi_y = (*session->image )->dpi_y * ( (float )im_height / (float )(*session->image )->getImageHeight () );
131+ compressor->setResolution ( dpi_x, dpi_y, (*session->image )->dpi_units );
132+
133+ if ( session->loglevel >= 5 ){
134+ *(session->logfile ) << " JTL :: Setting physical resolution of tile to " << dpi_x << " x " << dpi_y
135+ << ( ((*session->image )->dpi_units ==1 ) ? " pixels/inch" : " pixels/cm" ) << endl;
136+ }
133137 }
134138
139+
135140 // Embed ICC profile
136141 if ( session->view ->embedICC () && ((*session->image )->getMetadata (" icc" ).size ()>0 ) ){
137142 if ( session->loglevel >= 3 ){
0 commit comments