@@ -122,9 +122,8 @@ class CORE_EXPORT QgsRasterBlock
122
122
}
123
123
124
124
// Data type in bytes
125
- int dataTypeSize ( int bandNo ) const
125
+ int dataTypeSize ( ) const
126
126
{
127
- Q_UNUSED ( bandNo );
128
127
return typeSize ( mDataType );
129
128
}
130
129
@@ -150,31 +149,26 @@ class CORE_EXPORT QgsRasterBlock
150
149
* @return true if the block may contain no data */
151
150
bool hasNoData () const ;
152
151
153
- /* * Return no data value.
152
+ /* * Return no data value. If the block does not have a no data value the
153
+ * returned value is undefined.
154
154
* @return No data value */
155
155
double noDataValue () const { return mNoDataValue ; }
156
156
157
- /* * Set no data value.
158
- * @param noDataValue the value to be considered no data
159
- */
160
- // void setNoDataValue( double noDataValue ) { mNoDataValue = noDataValue; }
161
-
162
- /* * Test if value is nodata comparing to noDataValue
163
- * @param value tested value
164
- * @param noDataValue no data value
165
- * @return true if value is nodata */
166
- static bool isNoDataValue ( double value, double noDataValue );
167
-
168
- // get byte array representing no data value
157
+ /* * Get byte array representing a value.
158
+ * @param theDataType data type
159
+ * @param theValue value
160
+ * @return byte array representing the value */
169
161
static QByteArray valueBytes ( QGis::DataType theDataType, double theValue );
170
162
171
- /* * \brief Read a single value
163
+ /* * \brief Read a single value if type of block is numeric. If type is color,
164
+ * returned value is undefined.
172
165
* @param row row index
173
166
* @param column column index
174
167
* @return value */
175
168
double value ( int row, int column ) const ;
176
169
177
- /* * \brief Read a single value
170
+ /* * \brief Read a single value if type of block is numeric. If type is color,
171
+ * returned value is undefined.
178
172
* @param index data matrix index
179
173
* @return value */
180
174
double value ( size_t index ) const ;
@@ -221,6 +215,12 @@ class CORE_EXPORT QgsRasterBlock
221
215
* @return true on success */
222
216
bool setColor ( int row, int column, QRgb color );
223
217
218
+ /* * \brief Set color on index (indexed line by line)
219
+ * @param index data matrix index
220
+ * @param color the color to be set, QRgb value
221
+ * @return true on success */
222
+ bool setColor ( size_t index, QRgb color );
223
+
224
224
/* * \brief Set no data on pixel
225
225
* @param row row index
226
226
* @param column column index
@@ -240,12 +240,6 @@ class CORE_EXPORT QgsRasterBlock
240
240
* @return true on success */
241
241
bool setIsNoDataExcept ( const QRect & theExceptRect );
242
242
243
- /* * \brief Set color on index (indexed line by line)
244
- * @param index data matrix index
245
- * @param color the color to be set, QRgb value
246
- * @return true on success */
247
- bool setColor ( size_t index, QRgb color );
248
-
249
243
/* * \brief Get pointer to data
250
244
* @param row row index
251
245
* @param column column index
@@ -255,10 +249,13 @@ class CORE_EXPORT QgsRasterBlock
255
249
256
250
/* * \brief Get pointer to data
257
251
* @param index data matrix index
258
- * @return pointer to data
259
- */
252
+ * @return pointer to data */
260
253
char * bits ( size_t index );
261
254
255
+ /* * \brief Get pointer to data
256
+ * @return pointer to data */
257
+ char * bits ();
258
+
262
259
/* * \brief Print double value with all necessary significant digits.
263
260
* It is ensured that conversion back to double gives the same number.
264
261
* @param value the value to be printed
@@ -267,32 +264,17 @@ class CORE_EXPORT QgsRasterBlock
267
264
268
265
/* * \brief Convert data to different type.
269
266
* @param destDataType dest data type
270
- * @return true on success
271
- */
267
+ * @return true on success */
272
268
bool convert ( QGis::DataType destDataType );
273
269
270
+ /* * \brief Get image if type is color.
271
+ * @return image */
274
272
QImage image () const ;
275
- bool setImage ( const QImage * image );
276
-
277
- /* * Create a new image with extraneous data, such data may be used
278
- * after the image is destroyed. The memory is not initialized.
279
- */
280
- // TODO: remove, no more necessary with QgsRasterBlock
281
- QImage * createImage ( int width, int height, QImage::Format format );
282
-
283
- // TODO: remove this direct access to data, it was used in transition period
284
- void * data () { if ( mData ) return mData ; return mImage ->bits (); }
285
-
286
273
287
- // TODO: move to private, currently used by file writer
288
- /* * \brief Convert block of data from one type to another. Original block memory
289
- * is not release.
290
- * @param srcData source data
291
- * @param srcDataType source data type
292
- * @param destDataType dest data type
293
- * @param size block size (width * height)
294
- * @return block of data in destDataType */
295
- static void * convert ( void *srcData, QGis::DataType srcDataType, QGis::DataType destDataType, size_t size );
274
+ /* * \brief set image.
275
+ * @param image image
276
+ * @return true on success */
277
+ bool setImage ( const QImage * image );
296
278
297
279
inline static double readValue ( void *data, QGis::DataType type, size_t index );
298
280
@@ -321,13 +303,30 @@ class CORE_EXPORT QgsRasterBlock
321
303
static QImage::Format imageFormat ( QGis::DataType theDataType );
322
304
static QGis::DataType dataType ( QImage::Format theFormat );
323
305
306
+ /* * Test if value is nodata comparing to noDataValue
307
+ * @param value tested value
308
+ * @param noDataValue no data value
309
+ * @return true if value is nodata */
310
+ static bool isNoDataValue ( double value, double noDataValue );
311
+
324
312
/* * Test if value is nodata for specific band
325
313
* @param value tested value
326
314
* @return true if value is nodata */
327
315
bool isNoDataValue ( double value ) const ;
328
316
317
+ /* * Allocate no data bitmap
318
+ * @return true on success */
329
319
bool createNoDataBitmap ();
330
320
321
+ /* * \brief Convert block of data from one type to another. Original block memory
322
+ * is not release.
323
+ * @param srcData source data
324
+ * @param srcDataType source data type
325
+ * @param destDataType dest data type
326
+ * @param size block size (width * height)
327
+ * @return block of data in destDataType */
328
+ static void * convert ( void *srcData, QGis::DataType srcDataType, QGis::DataType destDataType, size_t size );
329
+
331
330
// Valid
332
331
bool mValid ;
333
332
@@ -363,6 +362,7 @@ class CORE_EXPORT QgsRasterBlock
363
362
364
363
// number of bytes in mNoDataBitmap row
365
364
int mNoDataBitmapWidth ;
365
+
366
366
// total size in bytes of mNoDataBitmap
367
367
size_t mNoDataBitmapSize ;
368
368
@@ -372,19 +372,11 @@ class CORE_EXPORT QgsRasterBlock
372
372
373
373
inline double QgsRasterBlock::readValue ( void *data, QGis::DataType type, size_t index )
374
374
{
375
- #if 0
376
- if ( !mInput )
377
- {
378
- return 0;
379
- }
380
-
381
375
if ( !data )
382
376
{
383
- return mInput->noDataValue ();
377
+ return std::numeric_limits< double >:: quiet_NaN ();
384
378
}
385
- #endif
386
379
387
- // TODO: define QGIS types to avoid cpl_port.h
388
380
switch ( type )
389
381
{
390
382
case QGis::Byte:
@@ -409,12 +401,10 @@ inline double QgsRasterBlock::readValue( void *data, QGis::DataType type, size_t
409
401
return ( double )(( double * )data )[index];
410
402
break ;
411
403
default :
412
- // QgsMessageLog::logMessage( tr ( "GDAL data type %1 is not supported" ).arg( type ), tr( "Raster" ) );
404
+ QgsDebugMsg ( QString ( " Data type %1 is not supported" ).arg ( type ) );
413
405
break ;
414
406
}
415
407
416
- // TODO: noDataValue is per band
417
- // return mInput->noDataValue();
418
408
return std::numeric_limits<double >::quiet_NaN ();
419
409
}
420
410
@@ -446,31 +436,19 @@ inline void QgsRasterBlock::writeValue( void *data, QGis::DataType type, size_t
446
436
(( double * )data )[index] = value;
447
437
break ;
448
438
default :
449
- // QgsMessageLog::logMessage( tr ( "GDAL data type %1 is not supported" ).arg( type ), tr( "Raster" ) );
439
+ QgsDebugMsg ( QString ( " Data type %1 is not supported" ).arg ( type ) );
450
440
break ;
451
441
}
452
442
}
453
443
454
444
inline double QgsRasterBlock::value ( size_t index ) const
455
445
{
456
- /* if ( index >= ( size_t )mWidth*mHeight )
457
- {
458
- QgsDebugMsg( QString( "Index %1 out of range (%2 x %3)" ).arg( index ).arg( mWidth ).arg( mHeight ) );
459
- return mNoDataValue;
460
- }*/
461
446
return readValue ( mData , mDataType , index );
462
447
}
463
448
464
449
inline bool QgsRasterBlock::isNoDataValue ( double value ) const
465
450
{
466
- // More precise would be qIsNaN(value) && qIsNaN(noDataValue(bandNo)), but probably
467
- // not important and slower
468
- if ( qIsNaN ( value ) ||
469
- qgsDoubleNear ( value, mNoDataValue ) )
470
- {
471
- return true ;
472
- }
473
- return false ;
451
+ return qIsNaN ( value ) || qgsDoubleNear ( value, mNoDataValue );
474
452
}
475
453
476
454
#endif
0 commit comments