hgt: runtime optimization
This commit is contained in:
parent
661f840843
commit
1a3d4e386e
2 changed files with 18 additions and 18 deletions
|
@ -58,16 +58,12 @@ TGHgt::TGHgt( int _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];
|
||||
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 );
|
||||
}
|
||||
|
||||
|
@ -164,16 +160,21 @@ TGHgt::load( ) {
|
|||
return false;
|
||||
}
|
||||
|
||||
short int *var;
|
||||
|
||||
for ( int row = size - 1; row >= 0; --row ) {
|
||||
for ( int col = 0; col < size; ++col ) {
|
||||
var = &data[col][row];
|
||||
if ( gzread ( fd, var, sizeof(short) ) != sizeof(short) ) {
|
||||
return false;
|
||||
}
|
||||
if ( sgIsLittleEndian() ) {
|
||||
sgEndianSwap( (unsigned short int*)var);
|
||||
}
|
||||
if ( gzfread( (voidp)read_buffer, 2, size, fd ) != (unsigned)size ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// convert to column-major
|
||||
for ( int col = 0; col < size; ++col )
|
||||
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() {
|
||||
// printf("class TGSrtmBase DEstructor called.\n");
|
||||
delete [] data;
|
||||
delete [] output_data;
|
||||
delete [] read_buffer;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ private:
|
|||
|
||||
// pointers to the actual grid data allocated here
|
||||
short int (*data)[MAX_HGT_SIZE];
|
||||
short int (*output_data)[MAX_HGT_SIZE];
|
||||
short int *read_buffer;
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in a new issue