2121#include " qgsfeedback.h"
2222#include " qgsogrutils.h"
2323#include " qgsmessagelog.h"
24+
25+ #ifdef HAVE_OPENCL
26+ #include " qgsopenclutils.h"
27+ #endif
28+
2429#include < QFile>
2530#include < QDebug>
2631#include < QFileInfo>
2732#include < iterator>
2833
2934
35+
3036QgsNineCellFilter::QgsNineCellFilter ( const QString &inputFile, const QString &outputFile, const QString &outputFormat )
3137 : mInputFile( inputFile )
3238 , mOutputFile( outputFile )
@@ -157,6 +163,7 @@ gdal::dataset_unique_ptr QgsNineCellFilter::openOutputFile( GDALDatasetH inputDa
157163 return outputDataset;
158164}
159165
166+ #ifdef HAVE_OPENCL
160167
161168int QgsNineCellFilter::processRasterGPU ( const QString &source, QgsFeedback *feedback )
162169{
@@ -296,7 +303,8 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
296303 }
297304 queue.enqueueWriteBuffer ( scanLine3Buffer, CL_TRUE, 0 , bufferSize, scanLine.get () ); // row 0
298305 }
299- else // Overwrite from input, skip first and last
306+ else // Read line i + 1 and put it into scanline 3
307+ // Overwrite from input, skip first and last
300308 {
301309 if ( GDALRasterIO ( rasterBand, GF_Read, 0 , i + 1 , xSize, 1 , &scanLine[1 ], xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
302310 {
@@ -334,7 +342,7 @@ int QgsNineCellFilter::processRasterGPU( const QString &source, QgsFeedback *fee
334342 }
335343 return 0 ;
336344}
337-
345+ # endif
338346
339347int QgsNineCellFilter::processRasterCPU ( QgsFeedback *feedback )
340348{
@@ -393,7 +401,7 @@ int QgsNineCellFilter::processRasterCPU( QgsFeedback *feedback )
393401 float *resultLine = ( float * ) CPLMalloc ( sizeof ( float ) * xSize );
394402
395403 // values outside the layer extent (if the 3x3 window is on the border) are sent to the processing method as (input) nodata values
396- for ( int i = 0 ; i < ySize; ++i )
404+ for ( int yIndex = 0 ; yIndex < ySize; ++yIndex )
397405 {
398406 if ( feedback && feedback->isCanceled () )
399407 {
@@ -402,10 +410,10 @@ int QgsNineCellFilter::processRasterCPU( QgsFeedback *feedback )
402410
403411 if ( feedback )
404412 {
405- feedback->setProgress ( 100.0 * static_cast < double >( i ) / ySize );
413+ feedback->setProgress ( 100.0 * static_cast < double >( yIndex ) / ySize );
406414 }
407415
408- if ( i == 0 )
416+ if ( yIndex == 0 )
409417 {
410418 // fill scanline 1 with (input) nodata for the values above the first row and feed scanline2 with the first row
411419 for ( int a = 0 ; a < xSize + 2 ; ++a )
@@ -428,7 +436,7 @@ int QgsNineCellFilter::processRasterCPU( QgsFeedback *feedback )
428436 }
429437
430438 // Read scanline 3
431- if ( i == ySize - 1 ) // fill the row below the bottom with nodata values
439+ if ( yIndex == ySize - 1 ) // fill the row below the bottom with nodata values
432440 {
433441 for ( int a = 0 ; a < xSize + 2 ; ++a )
434442 {
@@ -437,7 +445,7 @@ int QgsNineCellFilter::processRasterCPU( QgsFeedback *feedback )
437445 }
438446 else
439447 {
440- if ( GDALRasterIO ( rasterBand, GF_Read, 0 , i + 1 , xSize, 1 , &scanLine3[1 ], xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
448+ if ( GDALRasterIO ( rasterBand, GF_Read, 0 , yIndex + 1 , xSize, 1 , &scanLine3[1 ], xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
441449 {
442450 QgsDebugMsg ( " Raster IO Error" );
443451 }
@@ -450,15 +458,16 @@ int QgsNineCellFilter::processRasterCPU( QgsFeedback *feedback )
450458
451459
452460 // j is the x axis index, skip 0 and last cell that have been filled with nodata
453- for ( int j = 0 ; j < xSize ; ++j )
461+ for ( int xIndex = 0 ; xIndex < xSize ; ++xIndex )
454462 {
455- resultLine[ j ] = processNineCellWindow ( &scanLine1[ j ], &scanLine1[ j + 1 ], &scanLine1[ j + 2 ],
456- &scanLine2[ j ], &scanLine2[ j + 1 ], &scanLine2[ j + 2 ],
457- &scanLine3[ j ], &scanLine3[ j + 1 ], &scanLine3[ j + 2 ] );
463+ // cells(x, y) x11, x21, x31, x12, x22, x32, x13, x23, x33
464+ resultLine[ xIndex ] = processNineCellWindow ( &scanLine1[ xIndex ], &scanLine1[ xIndex + 1 ], &scanLine1[ xIndex + 2 ],
465+ &scanLine2[ xIndex ], &scanLine2[ xIndex + 1 ], &scanLine2[ xIndex + 2 ],
466+ &scanLine3[ xIndex ], &scanLine3[ xIndex + 1 ], &scanLine3[ xIndex + 2 ] );
458467
459468 }
460469
461- if ( GDALRasterIO ( outputRasterBand, GF_Write, 0 , i , xSize, 1 , resultLine, xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
470+ if ( GDALRasterIO ( outputRasterBand, GF_Write, 0 , yIndex , xSize, 1 , resultLine, xSize, 1 , GDT_Float32, 0 , 0 ) != CE_None )
462471 {
463472 QgsDebugMsg ( " Raster IO Error" );
464473 }
0 commit comments