1
0
Fork 0

hgt: runtime optimization

This commit is contained in:
Scott Giese 2019-01-13 01:30:40 -06:00
parent 661f840843
commit 1a3d4e386e
2 changed files with 18 additions and 18 deletions

View file

@ -58,16 +58,12 @@ TGHgt::TGHgt( int _res )
hgt_resolution = _res; hgt_resolution = _res;
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; read_buffer = new short int[MAX_HGT_SIZE];
} }
TGHgt::TGHgt( int _res, const SGPath &file ) TGHgt::TGHgt( int _res, const SGPath &file ) : TGHgt( _res )
{ {
hgt_resolution = _res;
data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE];
TGHgt::open( file ); TGHgt::open( file );
} }
@ -164,16 +160,21 @@ TGHgt::load( ) {
return false; return false;
} }
short int *var;
for ( int row = size - 1; row >= 0; --row ) { for ( int row = size - 1; row >= 0; --row ) {
for ( int col = 0; col < size; ++col ) { if ( gzfread( (voidp)read_buffer, 2, size, fd ) != (unsigned)size ) {
var = &data[col][row]; return false;
if ( gzread ( fd, var, sizeof(short) ) != sizeof(short) ) { }
return false;
} // convert to column-major
if ( sgIsLittleEndian() ) { for ( int col = 0; col < size; ++col )
sgEndianSwap( (unsigned short int*)var); data[col][row] = *(read_buffer + col);
} }
if (sgIsLittleEndian()) {
auto pData = (unsigned short *)data;
for (int i = 0; i < rows * cols; ++i) {
sgEndianSwap(pData++);
} }
} }
@ -181,9 +182,8 @@ TGHgt::load( ) {
} }
TGHgt::~TGHgt() { TGHgt::~TGHgt() {
// printf("class TGSrtmBase DEstructor called.\n"); // printf("class TGSrtmBase DEstructor called.\n");
delete [] data; delete [] data;
delete [] output_data; delete [] read_buffer;
} }

View file

@ -53,7 +53,7 @@ private:
// pointers to the actual grid data allocated here // pointers to the actual grid data allocated here
short int (*data)[MAX_HGT_SIZE]; short int (*data)[MAX_HGT_SIZE];
short int (*output_data)[MAX_HGT_SIZE]; short int *read_buffer;
public: public: