Skip to content

Commit 6b55ee4

Browse files
committedOct 16, 2012
undersampling if possible in QgsRasterDataProvider, multicolor widget loadMinMax fix
1 parent c46009e commit 6b55ee4

14 files changed

+258
-175
lines changed
 

‎python/core/raster/qgsrasterdataprovider.sip

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,12 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
135135
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
136136

137137
/** Returns data type for the band specified by number */
138-
virtual QgsRasterBlock::DataType dataType( int bandNo ) const;
138+
virtual QgsRasterBlock::DataType dataType( int bandNo ) const = 0;
139139

140140
/** Returns source data type for the band specified by number,
141141
* source data type may be shorter than dataType
142142
*/
143-
virtual QgsRasterBlock::DataType srcDataType( int bandNo ) const;
143+
virtual QgsRasterBlock::DataType srcDataType( int bandNo ) const = 0;
144144

145145
/** Returns data type for the band specified by number */
146146
virtual int colorInterpretation( int theBandNo ) const;
@@ -388,9 +388,6 @@ class QgsRasterDataProvider : QgsDataProvider, QgsRasterInterface
388388
static QString makeTableCell( const QString & value );
389389
static QString makeTableCells( const QStringList & values );
390390

391-
/** \brief Set null value in char */
392-
QByteArray noValueBytes( int theBandNo );
393-
394391
/** Time stamp of data source in the moment when data/metadata were loaded by provider */
395392
virtual QDateTime timestamp() const;
396393

‎python/gui/raster/qgsmultibandcolorrendererwidget.sip

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ class QgsMultiBandColorRendererWidget: QgsRasterRendererWidget
2020
int selectedBand( int index = 0 );
2121

2222
public slots:
23-
void loadMinMax( int theBandNo, double theMin, double theMax );
23+
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
2424
};

‎src/core/raster/qgsrasterblock.cpp

Lines changed: 83 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ bool QgsRasterBlock::reset( DataType theDataType, int theWidth, int theHeight, d
7575
if ( typeIsNumeric( theDataType ) )
7676
{
7777
QgsDebugMsg( "Numeric type" );
78-
int tSize = typeSize( theDataType ) / 8;
78+
size_t tSize = typeSize( theDataType );
79+
QgsDebugMsg( QString( "allocate %1 bytes" ).arg( tSize * theWidth * theHeight ) );
7980
mData = QgsMalloc( tSize * theWidth * theHeight );
8081
if ( mData == 0 )
8182
{
@@ -341,6 +342,36 @@ bool QgsRasterBlock::setColor( size_t index, QRgb color )
341342
return true;
342343
}
343344

345+
bool QgsRasterBlock::setIsNoData( int row, int column )
346+
{
347+
return setIsNoData(( size_t )row*column );
348+
}
349+
350+
bool QgsRasterBlock::setIsNoData( size_t index )
351+
{
352+
return setValue( index, mNoDataValue );
353+
}
354+
355+
bool QgsRasterBlock::setIsNoData()
356+
{
357+
if ( !mData )
358+
{
359+
QgsDebugMsg( "Data block not allocated" );
360+
return false;
361+
}
362+
363+
int dataTypeSize = typeSize( mDataType );
364+
QByteArray noDataByteArray = valueBytes( mDataType, mNoDataValue );
365+
366+
char *nodata = noDataByteArray.data();
367+
for ( size_t i = 0; i < ( size_t )mWidth*mHeight; i++ )
368+
{
369+
memcpy(( char* )mData + i*dataTypeSize, nodata, dataTypeSize );
370+
}
371+
372+
return true;
373+
}
374+
344375
char * QgsRasterBlock::bits( size_t index )
345376
{
346377
// Not testing type to avoid too much overhead because this method is called per pixel
@@ -481,7 +512,7 @@ QString QgsRasterBlock::printValue( double value )
481512

482513
void * QgsRasterBlock::convert( void *srcData, QgsRasterBlock::DataType srcDataType, QgsRasterBlock::DataType destDataType, size_t size )
483514
{
484-
int destDataTypeSize = typeSize( destDataType ) / 8;
515+
int destDataTypeSize = typeSize( destDataType );
485516
void *destData = QgsMalloc( destDataTypeSize * size );
486517
for ( size_t i = 0; i < size; i++ )
487518
{
@@ -492,3 +523,53 @@ void * QgsRasterBlock::convert( void *srcData, QgsRasterBlock::DataType srcDataT
492523
}
493524
return destData;
494525
}
526+
527+
QByteArray QgsRasterBlock::valueBytes( DataType theDataType, double theValue )
528+
{
529+
size_t size = QgsRasterBlock::typeSize( theDataType );
530+
QByteArray ba;
531+
ba.resize(( int )size );
532+
char * data = ba.data();
533+
unsigned char uc;
534+
unsigned short us;
535+
short s;
536+
unsigned int ui;
537+
int i;
538+
float f;
539+
double d;
540+
// TODO: define correct data types (typedef) like in GDAL
541+
switch ( theDataType )
542+
{
543+
case QgsRasterBlock::Byte:
544+
uc = ( unsigned char )theValue;
545+
memcpy( data, &uc, size );
546+
break;
547+
case QgsRasterBlock::UInt16:
548+
us = ( unsigned short )theValue;
549+
memcpy( data, &us, size );
550+
break;
551+
case QgsRasterBlock::Int16:
552+
s = ( short )theValue;
553+
memcpy( data, &s, size );
554+
break;
555+
case QgsRasterBlock::UInt32:
556+
ui = ( unsigned int )theValue;
557+
memcpy( data, &ui, size );
558+
break;
559+
case QgsRasterBlock::Int32:
560+
i = ( int )theValue;
561+
memcpy( data, &i, size );
562+
break;
563+
case QgsRasterBlock::Float32:
564+
f = ( float )theValue;
565+
memcpy( data, &f, size );
566+
break;
567+
case QgsRasterBlock::Float64:
568+
d = ( double )theValue;
569+
memcpy( data, &d, size );
570+
break;
571+
default:
572+
QgsDebugMsg( "Data type is not supported" );
573+
}
574+
return ba;
575+
}

‎src/core/raster/qgsrasterblock.h

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -92,41 +92,43 @@ class CORE_EXPORT QgsRasterBlock
9292
//bool isValid() const { return mValid; }
9393
bool isEmpty() const;
9494

95+
// Return data type size in bytes
9596
static int typeSize( int dataType )
9697
{
9798
// Modified and extended copy from GDAL
9899
switch ( dataType )
99100
{
100101
case Byte:
101-
return 8;
102+
return 1;
102103

103104
case UInt16:
104105
case Int16:
105-
return 16;
106+
return 2;
106107

107108
case UInt32:
108109
case Int32:
109110
case Float32:
110111
case CInt16:
111-
return 32;
112+
return 4;
112113

113114
case Float64:
114115
case CInt32:
115116
case CFloat32:
116-
return 64;
117+
return 8;
117118

118119
case CFloat64:
119-
return 128;
120+
return 16;
120121

121122
case ARGB32:
122123
case ARGB32_Premultiplied:
123-
return 32;
124+
return 4;
124125

125126
default:
126127
return 0;
127128
}
128129
}
129130

131+
// Data type in bytes
130132
int dataTypeSize( int bandNo ) const
131133
{
132134
Q_UNUSED( bandNo );
@@ -165,6 +167,9 @@ class CORE_EXPORT QgsRasterBlock
165167
* @return true if value is nodata */
166168
bool isNoDataValue( double value ) const;
167169

170+
// get byte array representing no data value
171+
static QByteArray valueBytes( DataType theDataType, double theValue );
172+
168173
/** \brief Read a single value
169174
* @param row row index
170175
* @param column column index
@@ -218,6 +223,21 @@ class CORE_EXPORT QgsRasterBlock
218223
* @return true on success */
219224
bool setColor( int row, int column, QRgb color );
220225

226+
/** \brief Set no data on pixel
227+
* @param row row index
228+
* @param column column index
229+
* @return true on success */
230+
bool setIsNoData( int row, int column );
231+
232+
/** \brief Set no data on pixel
233+
* @param index data matrix index
234+
* @return true on success */
235+
bool setIsNoData( size_t index );
236+
237+
/** \brief Set the whole block to no data
238+
* @return true on success */
239+
bool setIsNoData( );
240+
221241
/** \brief Set color on index (indexed line by line)
222242
* @param index data matrix index
223243
* @param color the color to be set, QRgb value
@@ -289,7 +309,6 @@ class CORE_EXPORT QgsRasterBlock
289309
static QImage::Format imageFormat( QgsRasterBlock::DataType theDataType );
290310
static DataType dataType( QImage::Format theFormat );
291311

292-
293312
// Valid
294313
//bool isValid;
295314

‎src/core/raster/qgsrasterdataprovider.cpp

Lines changed: 124 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -46,103 +46,158 @@ double QgsRasterDataProvider::noDataValue( int bandNo ) const
4646
return mInternalNoDataValue.value( bandNo -1 );
4747
}
4848

49-
#if 0
50-
void QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle
51-
const & viewExtent, int width,
52-
int height,
53-
QgsCoordinateReferenceSystem theSrcCRS,
54-
QgsCoordinateReferenceSystem theDestCRS,
55-
void *data )
49+
QgsRasterBlock * QgsRasterDataProvider::block( int theBandNo, QgsRectangle const & theExtent, int theWidth, int theHeight )
5650
{
57-
QgsDebugMsg( "Entered" );
58-
QgsDebugMsg( "viewExtent = " + viewExtent.toString() );
51+
QgsDebugMsg( QString( "theBandNo = %1 theWidth = %2 theHeight = %3" ).arg( theBandNo ).arg( theWidth ).arg( theHeight ) );
52+
QgsDebugMsg( QString( "theExtent = %1" ).arg( theExtent.toString() ) );
53+
54+
QgsRasterBlock *block = new QgsRasterBlock( dataType( theBandNo ), theWidth, theHeight, noDataValue( theBandNo ) );
5955

60-
if ( ! theSrcCRS.isValid() || ! theDestCRS.isValid() || theSrcCRS == theDestCRS )
56+
if ( block->isEmpty() )
6157
{
62-
readBlock( bandNo, viewExtent, width, height, data );
63-
return;
58+
QgsDebugMsg( "Couldn't create raster block" );
59+
return block;
6460
}
6561

66-
QTime time;
67-
time.start();
62+
// Read necessary extent only
63+
QgsRectangle tmpExtent = extent().intersect( &theExtent );
6864

69-
double mMaxSrcXRes = 0;
70-
double mMaxSrcYRes = 0;
65+
if ( tmpExtent.isEmpty() )
66+
{
67+
QgsDebugMsg( "Extent outside provider extent" );
68+
block->setIsNoData();
69+
return block;
70+
}
7171

72-
if ( capabilities() & QgsRasterDataProvider::ExactResolution )
72+
double xRes = theExtent.width() / theWidth;
73+
double yRes = theExtent.height() / theHeight;
74+
double tmpXRes, tmpYRes;
75+
double providerXRes = 0;
76+
double providerYRes = 0;
77+
if ( capabilities() & ExactResolution )
7378
{
74-
mMaxSrcXRes = extent().width() / xSize();
75-
mMaxSrcYRes = extent().height() / ySize();
79+
providerXRes = extent().width() / xSize();
80+
providerYRes = extent().height() / ySize();
81+
tmpXRes = qMax( providerXRes, xRes );
82+
tmpYRes = qMax( providerYRes, yRes );
83+
if ( doubleNear( tmpXRes, xRes ) ) tmpXRes = xRes;
84+
if ( doubleNear( tmpYRes, yRes ) ) tmpYRes = yRes;
7685
}
86+
else
87+
{
88+
tmpXRes = xRes;
89+
tmpYRes = yRes;
90+
}
91+
92+
if ( tmpExtent != theExtent ||
93+
tmpXRes > xRes || tmpYRes > yRes )
94+
{
95+
// Read smaller extent or lower resolution
96+
97+
// Calculate row/col limits (before tmpExtent is aligned)
98+
int fromRow = qRound(( theExtent.yMaximum() - tmpExtent.yMaximum() ) / yRes );
99+
int toRow = qRound(( theExtent.yMaximum() - tmpExtent.yMinimum() ) / yRes ) - 1;
100+
int fromCol = qRound(( tmpExtent.xMinimum() - theExtent.xMinimum() ) / xRes ) ;
101+
int toCol = qRound(( tmpExtent.xMaximum() - theExtent.xMinimum() ) / xRes ) - 1;
77102

78-
QgsRasterProjector myProjector( theSrcCRS, theDestCRS, viewExtent, height, width, mMaxSrcXRes, mMaxSrcYRes, extent() );
103+
QgsDebugMsg( QString( "fromRow = %1 toRow = %2 fromCol = %3 toCol = %4" ).arg( fromRow ).arg( toRow ).arg( fromCol ).arg( toCol ) );
104+
105+
if ( fromRow < 0 || fromRow >= theHeight || toRow < 0 || toRow >= theHeight ||
106+
fromCol < 0 || fromCol >= theWidth || toCol < 0 || toCol >= theWidth )
107+
{
108+
// Should not happen
109+
QgsDebugMsg( "Row or column limits out of range" );
110+
return block;
111+
}
79112

80-
QgsDebugMsg( QString( "create projector time (ms): %1" ).arg( time.elapsed() ) );
113+
// If lower source resolution is used, the extent must beS aligned to original
114+
// resolution to avoid possible shift due to resampling
115+
if ( tmpXRes > xRes )
116+
{
117+
int col = floor(( tmpExtent.xMinimum() - extent().xMinimum() ) / providerXRes );
118+
tmpExtent.setXMinimum( extent().xMinimum() + col * providerXRes );
119+
col = ceil(( tmpExtent.xMaximum() - extent().xMinimum() ) / providerXRes );
120+
tmpExtent.setXMaximum( extent().xMinimum() + col * providerXRes );
121+
}
122+
if ( tmpYRes > yRes )
123+
{
124+
int row = floor(( extent().yMaximum() - tmpExtent.yMaximum() ) / providerYRes );
125+
tmpExtent.setYMaximum( extent().yMaximum() - row * providerYRes );
126+
row = ceil(( extent().yMaximum() - tmpExtent.yMinimum() ) / providerYRes );
127+
tmpExtent.setYMinimum( extent().yMaximum() - row * providerYRes );
128+
}
129+
int tmpWidth = qRound( tmpExtent.width() / tmpXRes );
130+
int tmpHeight = qRound( tmpExtent.height() / tmpYRes );
131+
tmpXRes = tmpExtent.width() / tmpWidth;
132+
tmpYRes = tmpExtent.height() / tmpHeight;
81133

82-
// TODO: init data by nulls
134+
QgsDebugMsg( QString( "Reading smaller block tmpWidth = %1 theHeight = %2" ).arg( tmpWidth ).arg( tmpHeight ) );
135+
QgsDebugMsg( QString( "tmpExtent = %1" ).arg( tmpExtent.toString() ) );
83136

84-
// If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers
85-
if ( myProjector.srcRows() <= 0 || myProjector.srcCols() <= 0 )
86-
return;
137+
block->setIsNoData();
87138

88-
// Allocate memory for not projected source data
89-
size_t mySize = dataTypeSize( bandNo ) / 8;
90-
void *mySrcData = malloc( mySize * myProjector.srcRows() * myProjector.srcCols() );
139+
QgsRasterBlock *tmpBlock = new QgsRasterBlock( dataType( theBandNo ), tmpWidth, tmpHeight, noDataValue( theBandNo ) );
91140

92-
time.restart();
141+
readBlock( theBandNo, tmpExtent, tmpWidth, tmpHeight, tmpBlock->data() );
93142

94-
readBlock( bandNo, myProjector.srcExtent(), myProjector.srcCols(), myProjector.srcRows(), mySrcData );
143+
int pixelSize = dataTypeSize( theBandNo );
95144

96-
QgsDebugMsg( QString( "read not projected block time (ms): %1" ).arg( time.elapsed() ) );
97-
time.restart();
145+
double xMin = theExtent.xMinimum();
146+
double yMax = theExtent.yMaximum();
147+
double tmpXMin = tmpExtent.xMinimum();
148+
double tmpYMax = tmpExtent.yMaximum();
98149

99-
// Project data from source
100-
int mySrcRow;
101-
int mySrcCol;
102-
int mySrcOffset;
103-
int myDestOffset;
104-
for ( int r = 0; r < height; r++ )
105-
{
106-
for ( int c = 0; c < width; c++ )
150+
for ( int row = fromRow; row <= toRow; row++ )
107151
{
108-
myProjector.srcRowCol( r, c, &mySrcRow, &mySrcCol );
109-
mySrcOffset = mySize * ( mySrcRow * myProjector.srcCols() + mySrcCol );
110-
myDestOffset = mySize * ( r * width + c );
111-
// retype to char is just to avoid g++ warning
112-
memcpy(( char* ) data + myDestOffset, ( char* )mySrcData + mySrcOffset, mySize );
113-
}
114-
}
115-
QgsDebugMsg( QString( "reproject block time (ms): %1" ).arg( time.elapsed() ) );
152+
double y = yMax - ( row + 0.5 ) * yRes;
153+
int tmpRow = floor(( tmpYMax - y ) / tmpYRes );
116154

117-
free( mySrcData );
118-
}
119-
#endif
155+
for ( int col = fromCol; col <= toCol; col++ )
156+
{
157+
double x = xMin + ( col + 0.5 ) * xRes;
158+
int tmpCol = floor(( x - tmpXMin ) / tmpXRes );
120159

121-
//void * QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & extent, int width, int height )
122-
QgsRasterBlock * QgsRasterDataProvider::block( int bandNo, QgsRectangle const & extent, int width, int height )
123-
{
124-
QgsDebugMsg( QString( "bandNo = %1 width = %2 height = %3" ).arg( bandNo ).arg( width ).arg( height ) );
160+
if ( tmpRow < 0 || tmpRow >= tmpHeight || tmpCol < 0 || tmpCol >= tmpWidth )
161+
{
162+
QgsDebugMsg( "Source row or column limits out of range" );
163+
block->setIsNoData(); // so that the problem becomes obvious and fixed
164+
delete tmpBlock;
165+
return block;
166+
}
125167

126-
//void * data = QgsMalloc( dataTypeSize( bandNo ) * width * height );
168+
size_t tmpIndex = tmpRow * tmpWidth + tmpCol;
169+
size_t index = row * theWidth + col;
127170

128-
QgsRasterBlock *block = new QgsRasterBlock( dataType( bandNo ), width, height, noDataValue( bandNo ) );
171+
char *tmpBits = tmpBlock->bits( tmpIndex );
172+
char *bits = block->bits( index );
173+
if ( !tmpBits )
174+
{
175+
QgsDebugMsg( QString( "Cannot get input block data tmpRow = %1 tmpCol = %2 tmpIndex = %3." ).arg( tmpRow ).arg( tmpCol ).arg( tmpIndex ) );
176+
continue;
177+
}
178+
if ( !bits )
179+
{
180+
QgsDebugMsg( "Cannot set output block data." );
181+
continue;
182+
}
183+
memcpy( bits, tmpBits, pixelSize );
184+
}
185+
}
129186

130-
if ( block->isEmpty() )
187+
delete tmpBlock;
188+
}
189+
else
131190
{
132-
QgsDebugMsg( "Couldn't create raster block" );
133-
return block;
191+
readBlock( theBandNo, theExtent, theWidth, theHeight, block->data() );
134192
}
135193

136-
readBlock( bandNo, extent, width, height, block->data() );
137-
138194
// apply user no data values
139195
// TODO: there are other readBlock methods where no data are not applied
140-
QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( bandNo );
196+
QList<QgsRasterBlock::Range> myNoDataRangeList = userNoDataValue( theBandNo );
141197
if ( !myNoDataRangeList.isEmpty() )
142198
{
143-
//QgsRasterBlock::DataType type = dataType( bandNo );
144-
double myNoDataValue = noDataValue( bandNo );
145-
size_t size = width * height;
199+
double myNoDataValue = noDataValue( theBandNo );
200+
size_t size = theWidth * theHeight;
146201
for ( size_t i = 0; i < size; i++ )
147202
{
148203
double value = block->value( i );
@@ -308,58 +363,6 @@ QString QgsRasterDataProvider::lastErrorFormat()
308363
return "text/plain";
309364
}
310365

311-
QByteArray QgsRasterDataProvider::noValueBytes( int theBandNo )
312-
{
313-
int type = dataType( theBandNo );
314-
size_t size = QgsRasterBlock::typeSize( dataType( theBandNo ) ) / 8;
315-
QByteArray ba;
316-
ba.resize(( int )size );
317-
char * data = ba.data();
318-
double noval = noDataValue( theBandNo - 1 );
319-
unsigned char uc;
320-
unsigned short us;
321-
short s;
322-
unsigned int ui;
323-
int i;
324-
float f;
325-
double d;
326-
// TODO: define correct data types (typedef) like in GDAL
327-
switch ( type )
328-
{
329-
case QgsRasterBlock::Byte:
330-
uc = ( unsigned char )noval;
331-
memcpy( data, &uc, size );
332-
break;
333-
case QgsRasterBlock::UInt16:
334-
us = ( unsigned short )noval;
335-
memcpy( data, &us, size );
336-
break;
337-
case QgsRasterBlock::Int16:
338-
s = ( short )noval;
339-
memcpy( data, &s, size );
340-
break;
341-
case QgsRasterBlock::UInt32:
342-
ui = ( unsigned int )noval;
343-
memcpy( data, &ui, size );
344-
break;
345-
case QgsRasterBlock::Int32:
346-
i = ( int )noval;
347-
memcpy( data, &i, size );
348-
break;
349-
case QgsRasterBlock::Float32:
350-
f = ( float )noval;
351-
memcpy( data, &f, size );
352-
break;
353-
case QgsRasterBlock::Float64:
354-
d = ( double )noval;
355-
memcpy( data, &d, size );
356-
break;
357-
default:
358-
QgsLogger::warning( "GDAL data type is not supported" );
359-
}
360-
return ba;
361-
}
362-
363366
bool QgsRasterDataProvider::hasPyramids()
364367
{
365368
QList<QgsRasterPyramid> myPyramidList = buildPyramidList();
@@ -401,7 +404,7 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo )
401404
int myNXBlocks = ( xSize() + xBlockSize() - 1 ) / xBlockSize();
402405
int myNYBlocks = ( ySize() + yBlockSize() - 1 ) / yBlockSize();
403406

404-
void *myData = CPLMalloc( xBlockSize() * yBlockSize() * ( dataTypeSize( theBandNo ) / 8 ) );
407+
void *myData = CPLMalloc( xBlockSize() * yBlockSize() * ( dataTypeSize( theBandNo ) ) );
405408

406409
// unfortunately we need to make two passes through the data to calculate stddev
407410
bool myFirstIterationFlag = true;
@@ -659,7 +662,7 @@ QgsRasterBandStats QgsRasterDataProvider::bandStatistics( int theBandNo,
659662
int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
660663
int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
661664

662-
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( QgsRasterBlock::typeSize( dataType( theBandNo ) ) / 8 ) );
665+
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( QgsRasterBlock::typeSize( dataType( theBandNo ) ) ) );
663666

664667
double myXRes = myExtent.width() / myWidth;
665668
double myYRes = myExtent.height() / myHeight;
@@ -935,7 +938,7 @@ QgsRasterHistogram QgsRasterDataProvider::histogram( int theBandNo,
935938
int myNXBlocks = ( myWidth + myXBlockSize - 1 ) / myXBlockSize;
936939
int myNYBlocks = ( myHeight + myYBlockSize - 1 ) / myYBlockSize;
937940

938-
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( QgsRasterBlock::typeSize( dataType( theBandNo ) ) / 8 ) );
941+
void *myData = CPLMalloc( myXBlockSize * myYBlockSize * ( QgsRasterBlock::typeSize( dataType( theBandNo ) ) ) );
939942

940943
double myXRes = myExtent.width() / myWidth;
941944
double myYRes = myExtent.height() / myHeight;

‎src/core/raster/qgsrasterdataprovider.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,12 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
179179
// TODO: Get the file masks supported by this provider, suitable for feeding into the file open dialog box
180180

181181
/** Returns data type for the band specified by number */
182-
virtual QgsRasterBlock::DataType dataType( int bandNo ) const
183-
{
184-
return srcDataType( bandNo );
185-
}
182+
virtual QgsRasterBlock::DataType dataType( int bandNo ) const = 0;
186183

187184
/** Returns source data type for the band specified by number,
188185
* source data type may be shorter than dataType
189186
*/
190-
virtual QgsRasterBlock::DataType srcDataType( int bandNo ) const
191-
{
192-
Q_UNUSED( bandNo );
193-
return QgsRasterBlock::UnknownDataType;
194-
}
187+
virtual QgsRasterBlock::DataType srcDataType( int bandNo ) const = 0;
195188

196189
/** Returns data type for the band specified by number */
197190
virtual int colorInterpretation( int theBandNo ) const
@@ -289,15 +282,8 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
289282
virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data )
290283
{ Q_UNUSED( bandNo ); Q_UNUSED( viewExtent ); Q_UNUSED( width ); Q_UNUSED( height ); Q_UNUSED( data ); }
291284

292-
/** read block of data using give extent and size */
293-
// @note not available in python bindings
294-
//virtual void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS, void *data );
295-
296285
/** Read block of data using given extent and size. */
297-
// @note not available in python bindings
298-
//virtual void *readBlock( int bandNo, QgsRectangle const & extent, int width, int height );
299-
300-
virtual QgsRasterBlock *block( int bandNo, const QgsRectangle &extent, int width, int height );
286+
virtual QgsRasterBlock *block( int theBandNo, const QgsRectangle &theExtent, int theWidth, int theHeight );
301287

302288
/* Read a value from a data block at a given index. */
303289
virtual double readValue( void *data, int type, int index );
@@ -528,9 +514,6 @@ class CORE_EXPORT QgsRasterDataProvider : public QgsDataProvider, public QgsRast
528514
static QString makeTableCell( const QString & value );
529515
static QString makeTableCells( const QStringList & values );
530516

531-
/** \brief Set null value in char */
532-
QByteArray noValueBytes( int theBandNo );
533-
534517
/** Time stamp of data source in the moment when data/metadata were loaded by provider */
535518
virtual QDateTime timestamp() const { return mTimestamp; }
536519

‎src/core/raster/qgsrasterfilewriter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ QgsRasterFileWriter::WriterError QgsRasterFileWriter::writeImageRaster( QgsRaste
437437
iter->setMaximumTileWidth( mMaxTileWidth );
438438
iter->setMaximumTileHeight( mMaxTileHeight );
439439

440-
//void* data = VSIMalloc( QgsRasterBlock::typeSize( inputDataType ) / 8 * mMaxTileWidth * mMaxTileHeight );
440+
//void* data = VSIMalloc( QgsRasterBlock::typeSize( inputDataType ) * mMaxTileWidth * mMaxTileHeight );
441441
void* redData = VSIMalloc( mMaxTileWidth * mMaxTileHeight );
442442
void* greenData = VSIMalloc( mMaxTileWidth * mMaxTileHeight );
443443
void* blueData = VSIMalloc( mMaxTileWidth * mMaxTileHeight );

‎src/core/raster/qgsrasterlayer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2819,7 +2819,7 @@ QString QgsRasterLayer::projectionWkt()
28192819
#if 0
28202820
void *QgsRasterLayer::readData( int bandNo, QgsRasterViewPort *viewPort )
28212821
{
2822-
int size = mDataProvider->dataTypeSize( bandNo ) / 8;
2822+
int size = mDataProvider->dataTypeSize( bandNo );
28232823

28242824
#if 0
28252825
QgsDebugMsg( "calling RasterIO with " +

‎src/core/raster/qgsrasterprojector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,7 @@ QgsRasterBlock * QgsRasterProjector::block( int bandNo, QgsRectangle const & ex
734734
return outputBlock;
735735
}
736736

737-
size_t pixelSize = QgsRasterBlock::typeSize( mInput->dataType( bandNo ) ) / 8;
737+
size_t pixelSize = QgsRasterBlock::typeSize( mInput->dataType( bandNo ) );
738738

739739
if ( !outputBlock->reset( QgsRasterBlock::ARGB32_Premultiplied, width, height ) )
740740
{

‎src/gui/raster/qgsmultibandcolorrendererwidget.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ QgsMultiBandColorRendererWidget::QgsMultiBandColorRendererWidget( QgsRasterLayer
3535
mMinMaxWidget = new QgsRasterMinMaxWidget( layer, this );
3636
mMinMaxWidget->setExtent( extent );
3737
layout()->addWidget( mMinMaxWidget );
38-
connect( mMinMaxWidget, SIGNAL( load( int, double, double ) ),
39-
this, SLOT( loadMinMax( int, double, double ) ) );
38+
connect( mMinMaxWidget, SIGNAL( load( int, double, double, int ) ),
39+
this, SLOT( loadMinMax( int, double, double, int ) ) );
4040

4141
connect( mRedBandComboBox, SIGNAL( currentIndexChanged( int ) ),
4242
this, SLOT( onBandChanged( int ) ) );
@@ -191,7 +191,7 @@ void QgsMultiBandColorRendererWidget::onBandChanged( int index )
191191
mMinMaxWidget->setBands( myBands );
192192
}
193193

194-
void QgsMultiBandColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax )
194+
void QgsMultiBandColorRendererWidget::loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin )
195195
{
196196
QgsDebugMsg( QString( "theBandNo = %1 theMin = %2 theMax = %3" ).arg( theBandNo ).arg( theMin ).arg( theMax ) );
197197

‎src/gui/raster/qgsmultibandcolorrendererwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class GUI_EXPORT QgsMultiBandColorRendererWidget: public QgsRasterRendererWidget
4848
int selectedBand( int index = 0 );
4949

5050
public slots:
51-
void loadMinMax( int theBandNo, double theMin, double theMax );
51+
void loadMinMax( int theBandNo, double theMin, double theMax, int theOrigin );
5252

5353
private slots:
5454
//void on_mLoadPushButton_clicked();

‎src/providers/gdal/qgsgdalprovider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ void QgsGdalProvider::readBlock( int theBandNo, QgsRectangle const & theExtent,
378378
QgsDebugMsg( QString( "transform : %1" ).arg( mGeoTransform[i] ) );
379379
}
380380

381-
int dataSize = dataTypeSize( theBandNo ) / 8;
381+
int dataSize = dataTypeSize( theBandNo );
382382

383383
// fill with null values
384-
QByteArray ba = noValueBytes( theBandNo );
384+
QByteArray ba = QgsRasterBlock::valueBytes( dataType( theBandNo ), noDataValue( theBandNo ) );
385385
char *nodata = ba.data();
386386
char *block = ( char * ) theBlock;
387387
for ( int i = 0; i < thePixelWidth * thePixelHeight; i++ )
@@ -835,7 +835,7 @@ QMap<int, void *> QgsGdalProvider::identify( const QgsPoint & point )
835835
// Outside the raster
836836
for ( int i = 1; i <= GDALGetRasterCount( mGdalDataset ); i++ )
837837
{
838-
void * data = VSIMalloc( dataTypeSize( i ) / 8 );
838+
void * data = VSIMalloc( dataTypeSize( i ) );
839839
QgsRasterBlock::writeValue( data, dataType( i ), 0, noDataValue( i ) );
840840
results.insert( i, data );
841841
}
@@ -884,7 +884,7 @@ QMap<int, void *> QgsGdalProvider::identify( const QgsPoint & point )
884884
}
885885
}
886886
#endif
887-
int typeSize = dataTypeSize( i ) / 8;
887+
int typeSize = dataTypeSize( i );
888888
void * tmpData = VSIMalloc( typeSize * width * height );
889889

890890
CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, width, height,

‎src/providers/grass/qgsgrassrasterprovider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ QgsGrassRasterProvider::QgsGrassRasterProvider( QString const & uri )
128128
// memory, not too small to result in too many calls to readBlock -> qgis.d.rast
129129
// for statistics
130130
int cache_size = 10000000; // ~ 10 MB
131-
mYBlockSize = cache_size / ( dataTypeSize( dataType( 1 ) ) / 8 ) / mCols;
131+
mYBlockSize = cache_size / ( dataTypeSize( dataType( 1 ) ) ) / mCols;
132132
if ( mYBlockSize > mRows )
133133
{
134134
mYBlockSize = mRows;
@@ -232,7 +232,7 @@ void QgsGrassRasterProvider::readBlock( int bandNo, int xBlock, int yBlock, void
232232
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
233233
// byteCount() in Qt >= 4.6
234234
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
235-
int size = mCols * mYBlockSize * dataTypeSize( bandNo ) / 8;
235+
int size = mCols * mYBlockSize * dataTypeSize( bandNo );
236236
QgsDebugMsg( QString( "mCols = %1 mYBlockSize = %2 dataTypeSize = %3" ).arg( mCols ).arg( mYBlockSize ).arg( dataTypeSize( bandNo ) ) );
237237
if ( size != data.size() )
238238
{
@@ -279,7 +279,7 @@ void QgsGrassRasterProvider::readBlock( int bandNo, QgsRectangle const & viewEx
279279
QgsDebugMsg( QString( "%1 bytes read from modules stdout" ).arg( data.size() ) );
280280
// byteCount() in Qt >= 4.6
281281
//int size = image->byteCount() < data.size() ? image->byteCount() : data.size();
282-
int size = pixelWidth * pixelHeight * dataTypeSize( bandNo ) / 8;
282+
int size = pixelWidth * pixelHeight * dataTypeSize( bandNo );
283283
if ( size != data.size() )
284284
{
285285
QMessageBox::warning( 0, QObject::tr( "Warning" ),
@@ -439,7 +439,7 @@ QMap<int, void *> QgsGrassRasterProvider::identify( const QgsPoint & thePoint )
439439
QgsDebugMsg( "Cannot convert string to double" );
440440
}
441441
}
442-
void * data = malloc( dataTypeSize( 1 ) / 8 );
442+
void * data = malloc( dataTypeSize( 1 ) );
443443
QgsRasterBlock::writeValue( data, dataType( 1 ), 0, value );
444444

445445
results.insert( 1, data );

‎src/providers/wcs/qgswcsprovider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
503503
QgsDebugMsg( "Entered" );
504504

505505
// TODO: set block to null values, move that to function and call only if fails
506-
memset( block, 0, pixelWidth * pixelHeight * QgsRasterBlock::typeSize( dataType( bandNo ) ) / 8 );
506+
memset( block, 0, pixelWidth * pixelHeight * QgsRasterBlock::typeSize( dataType( bandNo ) ) );
507507

508508
// Requested extent must at least partialy overlap coverage extent, otherwise
509509
// server gives error. QGIS usually does not request blocks outside raster extent
@@ -579,7 +579,7 @@ void QgsWcsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, in
579579
// Rotate counter clockwise
580580
// If GridOffsets With GeoServer,
581581
QgsDebugMsg( tr( "Rotating raster" ) );
582-
int pixelSize = QgsRasterBlock::typeSize( dataType( bandNo ) ) / 8;
582+
int pixelSize = QgsRasterBlock::typeSize( dataType( bandNo ) );
583583
QgsDebugMsg( QString( "pixelSize = %1" ).arg( pixelSize ) );
584584
int size = width * height * pixelSize;
585585
void * tmpData = malloc( size );
@@ -1643,7 +1643,7 @@ QMap<int, void *> QgsWcsProvider::identify( const QgsPoint & thePoint )
16431643
// Outside the raster
16441644
for ( int i = 1; i <= bandCount(); i++ )
16451645
{
1646-
void * data = VSIMalloc( dataTypeSize( i ) / 8 );
1646+
void * data = VSIMalloc( dataTypeSize( i ) );
16471647
QgsRasterBlock::writeValue( data, dataType( i ), 0, noDataValue( i ) );
16481648
results.insert( i, data );
16491649
}
@@ -1708,7 +1708,7 @@ QMap<int, void *> QgsWcsProvider::identify( const QgsPoint & thePoint )
17081708
{
17091709
GDALRasterBandH gdalBand = GDALGetRasterBand( mCachedGdalDataset, i );
17101710

1711-
void * data = VSIMalloc( dataTypeSize( i ) / 8 );
1711+
void * data = VSIMalloc( dataTypeSize( i ) );
17121712
CPLErr err = GDALRasterIO( gdalBand, GF_Read, col, row, 1, 1,
17131713
data, 1, 1, ( GDALDataType ) mGdalDataType[i-1], 0, 0 );
17141714

0 commit comments

Comments
 (0)
Please sign in to comment.