31
31
#include < QImage>
32
32
#include < QPainter>
33
33
34
- // QgsRasterRenderer::QgsRasterRenderer( QgsRasterFace* input, const QString& type ): mInput( input ),
35
34
QgsRasterRenderer::QgsRasterRenderer ( QgsRasterFace* input, const QString& type ): QgsRasterFace( input ),
36
35
mType( type ), mZoomedInResampler( 0 ), mZoomedOutResampler( 0 ), mOpacity( 1.0 ), mRasterTransparency( 0 ),
37
36
mAlphaBand( -1 ), mInvertColor( false ), mMaxOversampling( 2.0 )
@@ -42,167 +41,6 @@ QgsRasterRenderer::~QgsRasterRenderer()
42
41
{
43
42
}
44
43
45
- /*
46
- void QgsRasterRenderer::startRasterRead( int bandNumber, QgsRasterViewPort* viewPort, const QgsMapToPixel* mapToPixel, double& oversamplingX, double& oversamplingY )
47
- {
48
- if ( !viewPort || !mapToPixel || !mInput )
49
- {
50
- return;
51
- }
52
-
53
- //remove any previous part on that band
54
- removePartInfo( bandNumber );
55
-
56
- //calculate oversampling factor
57
- double oversampling = 1.0; //approximate global oversampling factor
58
-
59
- if ( mZoomedInResampler || mZoomedOutResampler )
60
- {
61
- QgsRectangle providerExtent = mInput->extent();
62
- if ( viewPort->mSrcCRS.isValid() && viewPort->mDestCRS.isValid() && viewPort->mSrcCRS != viewPort->mDestCRS )
63
- {
64
- QgsCoordinateTransform t( viewPort->mSrcCRS, viewPort->mDestCRS );
65
- providerExtent = t.transformBoundingBox( providerExtent );
66
- }
67
- double pixelRatio = mapToPixel->mapUnitsPerPixel() / ( providerExtent.width() / mInput->xSize() );
68
- oversampling = ( pixelRatio > mMaxOversampling ) ? mMaxOversampling : pixelRatio;
69
- }
70
-
71
- //set oversampling back to 1.0 if no resampler for zoomed in / zoomed out (nearest neighbour)
72
- if (( oversampling < 1.0 && !mZoomedInResampler ) || ( oversampling > 1.0 && !mZoomedOutResampler ) )
73
- {
74
- oversampling = 1.0;
75
- }
76
-
77
- //split raster into small portions if necessary
78
- RasterPartInfo pInfo;
79
- pInfo.nCols = viewPort->drawableAreaXDim;
80
- pInfo.nRows = viewPort->drawableAreaYDim;
81
-
82
- //effective oversampling factors are different to global one because of rounding
83
- oversamplingX = (( double )pInfo.nCols * oversampling ) / viewPort->drawableAreaXDim;
84
- oversamplingY = (( double )pInfo.nRows * oversampling ) / viewPort->drawableAreaYDim;
85
-
86
- int totalMemoryUsage = pInfo.nCols * oversamplingX * pInfo.nRows * oversamplingY * mInput->dataTypeSize( bandNumber );
87
- int parts = totalMemoryUsage / 100000000 + 1;
88
- int nPartsPerDimension = sqrt(( double ) parts );
89
- pInfo.nColsPerPart = pInfo.nCols / nPartsPerDimension;
90
- pInfo.nRowsPerPart = pInfo.nRows / nPartsPerDimension;
91
- pInfo.currentCol = 0;
92
- pInfo.currentRow = 0;
93
- pInfo.data = 0;
94
- pInfo.prj = 0;
95
- mRasterPartInfos.insert( bandNumber, pInfo );
96
- }
97
-
98
- bool QgsRasterRenderer::readNextRasterPart( int bandNumber, double oversamplingX, double oversamplingY, QgsRasterViewPort* viewPort,
99
- int& nCols, int& nRows, int& nColsRaster, int& nRowsRaster, void** rasterData, int& topLeftCol, int& topLeftRow )
100
- {
101
- if ( !viewPort )
102
- {
103
- return false;
104
- }
105
-
106
- //get partinfo
107
- QMap<int, RasterPartInfo>::iterator partIt = mRasterPartInfos.find( bandNumber );
108
- if ( partIt == mRasterPartInfos.end() )
109
- {
110
- return false;
111
- }
112
-
113
- RasterPartInfo& pInfo = partIt.value();
114
-
115
- //remove last data block
116
- CPLFree( pInfo.data );
117
- pInfo.data = 0;
118
- delete pInfo.prj;
119
- pInfo.prj = 0;
120
-
121
- //already at end
122
- if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow == pInfo.nRows )
123
- {
124
- return false;
125
- }
126
-
127
- //read data block
128
- nCols = qMin( pInfo.nColsPerPart, pInfo.nCols - pInfo.currentCol );
129
- nRows = qMin( pInfo.nRowsPerPart, pInfo.nRows - pInfo.currentRow );
130
- int typeSize = mInput->dataTypeSize( bandNumber ) / 8;
131
-
132
- //get subrectangle
133
- QgsRectangle viewPortExtent = viewPort->mDrawnExtent;
134
- double xmin = viewPortExtent.xMinimum() + pInfo.currentCol / ( double )pInfo.nCols * viewPortExtent.width();
135
- double xmax = viewPortExtent.xMinimum() + ( pInfo.currentCol + nCols ) / ( double )pInfo.nCols * viewPortExtent.width();
136
- double ymin = viewPortExtent.yMaximum() - ( pInfo.currentRow + nRows ) / ( double )pInfo.nRows * viewPortExtent.height();
137
- double ymax = viewPortExtent.yMaximum() - pInfo.currentRow / ( double )pInfo.nRows * viewPortExtent.height();
138
- QgsRectangle blockRect( xmin, ymin, xmax, ymax );
139
-
140
- if ( viewPort->mSrcCRS.isValid() && viewPort->mDestCRS.isValid() && viewPort->mSrcCRS != viewPort->mDestCRS )
141
- {
142
- pInfo.prj = new QgsRasterProjector( viewPort->mSrcCRS,
143
- viewPort->mDestCRS, blockRect, nRows, nCols, 0, 0, mInput->extent() );
144
-
145
- // If we zoom out too much, projector srcRows / srcCols maybe 0, which can cause problems in providers
146
- if ( pInfo.prj->srcRows() <= 0 || pInfo.prj->srcCols() <= 0 )
147
- {
148
- delete pInfo.prj;
149
- pInfo.prj = 0;
150
- return false;
151
- }
152
-
153
- blockRect = pInfo.prj->srcExtent();
154
- }
155
-
156
- if ( pInfo.prj )
157
- {
158
- nColsRaster = pInfo.prj->srcCols() * oversamplingX;
159
- nRowsRaster = pInfo.prj->srcRows() * oversamplingY;
160
- }
161
- else
162
- {
163
- nColsRaster = nCols * oversamplingX;
164
- nRowsRaster = nRows * oversamplingY;
165
- }
166
- //pInfo.data = VSIMalloc( typeSize * nColsRaster * nRowsRaster );
167
- //mInput->readBlock( bandNumber, blockRect, nColsRaster, nRowsRaster, pInfo.data );
168
- pInfo.data = mInput->readBlock( bandNumber, blockRect, nColsRaster, nRowsRaster );
169
-
170
- *rasterData = pInfo.data;
171
- topLeftCol = pInfo.currentCol;
172
- topLeftRow = pInfo.currentRow;
173
-
174
- pInfo.currentCol += nCols;
175
- if ( pInfo.currentCol == pInfo.nCols && pInfo.currentRow + nRows == pInfo.nRows ) //end of raster
176
- {
177
- pInfo.currentRow = pInfo.nRows;
178
- }
179
- else if ( pInfo.currentCol == pInfo.nCols ) //start new row
180
- {
181
- pInfo.currentCol = 0;
182
- pInfo.currentRow += pInfo.nRowsPerPart;
183
- }
184
-
185
- return true;
186
- }
187
-
188
- void QgsRasterRenderer::stopRasterRead( int bandNumber )
189
- {
190
- removePartInfo( bandNumber );
191
- }
192
-
193
- void QgsRasterRenderer::removePartInfo( int bandNumber )
194
- {
195
- QMap<int, RasterPartInfo>::iterator partIt = mRasterPartInfos.find( bandNumber );
196
- if ( partIt != mRasterPartInfos.end() )
197
- {
198
- RasterPartInfo& pInfo = partIt.value();
199
- CPLFree( pInfo.data );
200
- delete pInfo.prj;
201
- mRasterPartInfos.remove( bandNumber );
202
- }
203
- }
204
- */
205
-
206
44
bool QgsRasterRenderer::usesTransparency ( QgsCoordinateReferenceSystem& srcSRS, QgsCoordinateReferenceSystem& dstSRS ) const
207
45
{
208
46
// transparency is always used if on-the-fly reprojection is enabled
@@ -220,89 +58,6 @@ void QgsRasterRenderer::setRasterTransparency( QgsRasterTransparency* t )
220
58
mRasterTransparency = t;
221
59
}
222
60
223
- /*
224
- void QgsRasterRenderer::drawImage( QPainter* p, QgsRasterViewPort* viewPort, const QImage& img, int topLeftCol, int topLeftRow,
225
- int nCols, int nRows, double oversamplingX, double oversamplingY ) const
226
- {
227
- if ( !p || !viewPort )
228
- {
229
- return;
230
- }
231
-
232
- //get QgsRasterProjector
233
- QgsRasterProjector* prj = 0;
234
- QMap<int, RasterPartInfo>::const_iterator partInfoIt = mRasterPartInfos.constBegin();
235
- if ( partInfoIt != mRasterPartInfos.constEnd() )
236
- {
237
- prj = partInfoIt->prj;
238
- }
239
-
240
- //top left position in device coords
241
- QPoint tlPoint = QPoint( viewPort->topLeftPoint.x() + topLeftCol, viewPort->topLeftPoint.y() + topLeftRow );
242
-
243
- //resample and draw image
244
- if (( mZoomedInResampler || mZoomedOutResampler ) && !doubleNear( oversamplingX, 1.0 ) && !doubleNear( oversamplingY, 1.0 ) )
245
- {
246
- QImage dstImg;
247
- if ( prj )
248
- {
249
- dstImg = QImage( prj->srcCols(), prj->srcRows(), QImage::Format_ARGB32_Premultiplied );
250
- }
251
- else
252
- {
253
- dstImg = QImage( nCols, nRows, QImage::Format_ARGB32_Premultiplied );
254
- }
255
- if ( mZoomedInResampler && oversamplingX < 1.0 )
256
- {
257
- mZoomedInResampler->resample( img, dstImg );
258
- }
259
- else if ( mZoomedOutResampler && oversamplingX > 1.0 )
260
- {
261
- mZoomedOutResampler->resample( img, dstImg );
262
- }
263
-
264
- if ( prj )
265
- {
266
- QImage projectedImg( nCols, nRows, QImage::Format_ARGB32_Premultiplied );
267
- projectImage( dstImg, projectedImg, prj );
268
- p->drawImage( tlPoint, projectedImg );
269
- }
270
- else
271
- {
272
- p->drawImage( tlPoint, dstImg );
273
- }
274
- }
275
- else //use original image
276
- {
277
- if ( prj )
278
- {
279
- QImage projectedImg( nCols, nRows, QImage::Format_ARGB32_Premultiplied );
280
- projectImage( img, projectedImg, prj );
281
- p->drawImage( tlPoint, projectedImg );
282
- }
283
- else
284
- {
285
- p->drawImage( tlPoint, img );
286
- }
287
- }
288
- }
289
-
290
- void QgsRasterRenderer::projectImage( const QImage& srcImg, QImage& dstImage, QgsRasterProjector* prj ) const
291
- {
292
- int nRows = dstImage.height();
293
- int nCols = dstImage.width();
294
- int srcRow, srcCol;
295
- for ( int i = 0; i < nRows; ++i )
296
- {
297
- for ( int j = 0; j < nCols; ++j )
298
- {
299
- prj->srcRowCol( i, j, &srcRow, &srcCol );
300
- dstImage.setPixel( j, i, srcImg.pixel( srcCol, srcRow ) );
301
- }
302
- }
303
- }
304
- */
305
-
306
61
void QgsRasterRenderer::_writeXML ( QDomDocument& doc, QDomElement& rasterRendererElem ) const
307
62
{
308
63
if ( rasterRendererElem.isNull () )
0 commit comments