[QGIS Commit] r14684 - in branches/raster-providers/src: core
core/raster providers/wms
svn_qgis at osgeo.org
svn_qgis at osgeo.org
Mon Nov 15 06:31:36 EST 2010
Author: rblazek
Date: 2010-11-15 03:31:35 -0800 (Mon, 15 Nov 2010)
New Revision: 14684
Modified:
branches/raster-providers/src/core/qgsrasterdataprovider.h
branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
branches/raster-providers/src/core/raster/qgsrasterlayer.h
branches/raster-providers/src/providers/wms/qgswmsprovider.cpp
branches/raster-providers/src/providers/wms/qgswmsprovider.h
Log:
wms swithed from draw() to readBlock using ARGBDataType
Modified: branches/raster-providers/src/core/qgsrasterdataprovider.h
===================================================================
--- branches/raster-providers/src/core/qgsrasterdataprovider.h 2010-11-15 11:12:03 UTC (rev 14683)
+++ branches/raster-providers/src/core/qgsrasterdataprovider.h 2010-11-15 11:31:35 UTC (rev 14684)
@@ -80,7 +80,8 @@
/*! Complex Int32 */ CInt32 = 9,
/*! Complex Float32 */ CFloat32 = 10,
/*! Complex Float64 */ CFloat64 = 11,
- TypeCount = 12 /* maximum type # + 1 */
+ /*! Color, alpha, red, green, blue, 4 bytes */ ARGBDataType = 12,
+ TypeCount = 13 /* maximum type # + 1 */
};
// This is modified copy of GDALColorInterp
@@ -195,6 +196,9 @@
case CFloat64:
return 128;
+ case ARGBDataType:
+ return 32;
+
default:
return 0;
}
@@ -206,7 +210,7 @@
/** Get numbur of bands */
virtual int bandCount() const {
- return 0;
+ return 1;
}
/** Returns data type for the band specified by number */
Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.cpp
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.cpp 2010-11-15 11:12:03 UTC (rev 14683)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.cpp 2010-11-15 11:31:35 UTC (rev 14684)
@@ -376,6 +376,13 @@
{
QgsDebugMsg( "theBandNo = " + QString::number(theBandNo) );
QgsDebugMsg( "mRasterType = " + QString::number(mRasterType) );
+ if ( mRasterType == ColorLayer )
+ {
+ // Statistics have no sense for ColorLayer
+ QgsRasterBandStats myNullReturnStats;
+ return myNullReturnStats;
+ }
+
// check if we have received a valid band number
if (( mDataProvider->bandCount() < theBandNo ) && mRasterType != Palette )
{
@@ -969,13 +976,14 @@
// Provider mode: See if a provider key is specified, and if so use the provider instead
- QgsDebugMsg( "Checking for provider key." );
+ QgsDebugMsg( "Checking for provider capability." );
- //if ( !mProviderKey.isEmpty() )
+ // Some providers were returning QImage directly, not they are passing ARGB data - ARGBDataType
if ( mDataProvider->capabilities() & QgsRasterDataProvider::Draw )
{
QgsDebugMsg( "Wanting a '" + mProviderKey + "' provider to draw this." );
+ // TODO this should be probably moved to WMS?
mDataProvider->setDpi( rendererContext.rasterScaleFactor() * 25.4 * rendererContext.scaleFactor() );
//fetch image in several parts if it is too memory consuming
@@ -1037,6 +1045,7 @@
//QImage::setAlphaChannel does not work quite as expected so set each pixel individually
//Currently this is only done for WMS images, which should be small enough not to impact performance
+ // TODO this should be probably moved to WMS?
if ( mTransparencyLevel != 255 ) //improve performance if layer transparency not altered
{
QImage* transparentImageCopy = new QImage( *image ); //copy image if there is user transparency
@@ -1232,6 +1241,18 @@
theQgsMapToPixel );
}
break;
+ case SingleBandColorDataStyle:
+ //check the band is set!
+ if ( mGrayBandName == TRSTRING_NOT_SET )
+ {
+ break;
+ }
+ else
+ {
+ drawSingleBandColorData( theQPainter, theRasterViewPort,
+ theQgsMapToPixel, bandNumber( mGrayBandName ) );
+ break;
+ }
default:
break;
@@ -1271,6 +1292,9 @@
case MultiBandColor:
return QString( "MultiBandColor" );//no need to tr() this its not shown in ui
break;
+ case SingleBandColorDataStyle:
+ return QString( "SingleBandColorDataStyle" );//no need to tr() this its not shown in ui
+ break;
default:
break;
}
@@ -2524,10 +2548,16 @@
//decide what type of layer this is...
//TODO Change this to look at the color interp and palette interp to decide which type of layer it is
+ QgsDebugMsg("bandCount = " + QString::number( mDataProvider->bandCount()));
+ QgsDebugMsg("dataType = " + QString::number( mDataProvider->dataType( 1 )));
if (( mDataProvider->bandCount() > 1 ) )
{
mRasterType = Multiband;
}
+ else if ( mDataProvider->dataType( 1 ) == QgsRasterDataProvider::ARGBDataType )
+ {
+ mRasterType = ColorLayer;
+ }
//TODO hasBand is really obsolete and only used in the Palette instance, change to new function hasPalette(int)
//else if ( hasBand( "Palette" ) ) //don't tr() this its a gdal word!
// not sure if is worth to add colorTable capability - CT can be empty in any case
@@ -2540,8 +2570,15 @@
mRasterType = GrayOrUndefined;
}
- if ( mRasterType == Palette )
+ QgsDebugMsg("mRasterType = " + QString::number(mRasterType));
+ if ( mRasterType == ColorLayer )
{
+ QgsDebugMsg("Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number ( SingleBandColorDataStyle ) );
+ mDrawingStyle = SingleBandColorDataStyle;
+ mGrayBandName = bandName( 1 ); //sensible default
+ }
+ else if ( mRasterType == Palette )
+ {
mRedBandName = TRSTRING_NOT_SET; // sensible default
mGreenBandName = TRSTRING_NOT_SET; // sensible default
mBlueBandName = TRSTRING_NOT_SET;// sensible default
@@ -2789,8 +2826,14 @@
{
mDrawingStyle = MultiBandColor;
}
- else
+ else if ( theDrawingStyleQString == "SingleBandColorDataStyle" )//no need to tr() this its not shown in ui
{
+ QgsDebugMsg("Setting mDrawingStyle to SingleBandColorDataStyle " + QString::number ( SingleBandColorDataStyle ) );
+ mDrawingStyle = SingleBandColorDataStyle;
+ QgsDebugMsg("Setted mDrawingStyle to " + QString::number ( mDrawingStyle ) );
+ }
+ else
+ {
mDrawingStyle = UndefinedDrawingStyle;
}
}
@@ -3708,6 +3751,25 @@
// Private methods
//
/////////////////////////////////////////////////////////
+void QgsRasterLayer::drawSingleBandColorData( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
+ const QgsMapToPixel* theQgsMapToPixel, int theBandNo )
+{
+ QgsDebugMsg( "entered." );
+
+ QgsRasterImageBuffer imageBuffer( mDataProvider, theBandNo, theQPainter, theRasterViewPort, theQgsMapToPixel, &mGeoTransform[0] );
+ imageBuffer.reset();
+
+ QRgb* imageScanLine = 0;
+ void* rasterScanLine = 0;
+
+ while ( imageBuffer.nextScanLine( &imageScanLine, &rasterScanLine ) )
+ {
+ int size = theRasterViewPort->drawableAreaXDim * 4;
+ memcpy( imageScanLine, rasterScanLine, size );
+ }
+
+}
+
void QgsRasterLayer::drawMultiBandColor( QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,
const QgsMapToPixel* theQgsMapToPixel )
{
Modified: branches/raster-providers/src/core/raster/qgsrasterlayer.h
===================================================================
--- branches/raster-providers/src/core/raster/qgsrasterlayer.h 2010-11-15 11:12:03 UTC (rev 14683)
+++ branches/raster-providers/src/core/raster/qgsrasterlayer.h 2010-11-15 11:31:35 UTC (rev 14684)
@@ -241,8 +241,8 @@
//added in 1.6 to fix naming glitch
MultiBandSingleBandGray = MultiBandSingleGandGray, // a layer containing 2 or more bands, but a single band drawn as a range of gray colors
MultiBandSingleBandPseudoColor, //a layer containing 2 or more bands, but a single band drawn using a pseudocolor algorithm
- MultiBandColor //a layer containing 2 or more bands, mapped to RGB color space.
- //In the case of a multiband with only two bands, one band will be mapped to more than one color.
+ MultiBandColor, //a layer containing 2 or more bands, mapped to RGB color space. In the case of a multiband with only two bands, one band will be mapped to more than one color.
+ SingleBandColorDataStyle // ARGB values rendered directly
};
/** \brief This enumerator describes the type of raster layer */
@@ -250,7 +250,8 @@
{
GrayOrUndefined,
Palette,
- Multiband
+ Multiband,
+ ColorLayer
} ;
/** \brief A list containing on ContrastEnhancement object per raster band in this raster layer */
@@ -713,6 +714,11 @@
//
// Private methods
//
+ /** \brief Drawing routine for color type data */
+ void drawSingleBandColorData( QPainter * theQPainter,
+ QgsRasterViewPort * theRasterViewPort,
+ const QgsMapToPixel* theQgsMapToPixel,
+ int theBandNoInt );
/** \brief Drawing routine for multiband image */
void drawMultiBandColor( QPainter * theQPainter,
Modified: branches/raster-providers/src/providers/wms/qgswmsprovider.cpp
===================================================================
--- branches/raster-providers/src/providers/wms/qgswmsprovider.cpp 2010-11-15 11:12:03 UTC (rev 14683)
+++ branches/raster-providers/src/providers/wms/qgswmsprovider.cpp 2010-11-15 11:31:35 UTC (rev 14684)
@@ -489,7 +489,9 @@
//MH: jpeg does not support transparency and some servers complain if jpg and transparent=true
if ( !imageMimeType.contains( "jpeg", Qt::CaseInsensitive ) && !imageMimeType.contains( "jpg", Qt::CaseInsensitive ) )
{
- url += "&TRANSPARENT=true";
+ // some servers giving error for 'true' (lowercase)
+ //url += "&TRANSPARENT=true";
+ url += "&TRANSPARENT=TRUE";
}
mGetFeatureInfoUrlBase = mIgnoreGetFeatureInfoUrl ? mBaseUrl : getFeatureInfoUrl();
@@ -676,6 +678,30 @@
return cachedImage;
}
+void QgsWmsProvider::readBlock( int bandNo, QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight, void *block )
+{
+ QgsDebugMsg( "Entered" );
+ // TODO: optimize to avoid writing to QImage
+ QImage* image = draw( viewExtent, pixelWidth, pixelHeight );
+
+ if ( ! image ) { // should not happen
+ QgsDebugMsg( "image is NULL" );
+ return;
+ }
+ QgsDebugMsg( QString("image height = %1 bytesPerLine = %2").arg(image->height() ) . arg ( image->bytesPerLine() ) ) ;
+ int myExpectedSize = pixelWidth * pixelHeight * 4;
+ int myImageSize = image->height() * image->bytesPerLine();
+ if ( myExpectedSize != myImageSize ) { // should not happen
+ QgsDebugMsg( "unexpected image size" );
+ return;
+ }
+
+ uchar * ptr = image->bits( ) ;
+ memcpy( block, ptr, myExpectedSize );
+ // do not delete the image, it is handled by draw()
+ //delete image;
+}
+
void QgsWmsProvider::tileReplyFinished()
{
QNetworkReply *reply = qobject_cast<QNetworkReply*>( sender() );
@@ -947,6 +973,16 @@
mCapabilitiesReply = 0;
}
+int QgsWmsProvider::dataType( int bandNo ) const
+{
+ return QgsRasterDataProvider::ARGBDataType;
+}
+
+int QgsWmsProvider::bandCount() const
+{
+ return 1;
+}
+
void QgsWmsProvider::capabilitiesReplyProgress( qint64 bytesReceived, qint64 bytesTotal )
{
emit statusChanged( tr( "%1 of %2 bytes of capabilities downloaded." ).arg( bytesReceived ).arg( bytesTotal < 0 ? QString( "unknown number of" ) : QString::number( bytesTotal ) ) );
@@ -2109,7 +2145,8 @@
int QgsWmsProvider::capabilities() const
{
- int capability = 0;
+ //int capability = QgsRasterDataProvider::Draw;
+ int capability = QgsRasterDataProvider::Data;
bool canIdentify = false;
QgsDebugMsg( "entering." );
@@ -2144,7 +2181,7 @@
}
}
- QgsDebugMsg( "exiting with '" + QString( capability ) + "'." );
+ //QgsDebugMsg( "exiting with '" + QString( capability ) + "'." );
return capability;
}
@@ -2784,7 +2821,6 @@
return QgsCoordinateReferenceSystem();
}
-
QString QgsWmsProvider::lastErrorTitle()
{
return mErrorCaption;
Modified: branches/raster-providers/src/providers/wms/qgswmsprovider.h
===================================================================
--- branches/raster-providers/src/providers/wms/qgswmsprovider.h 2010-11-15 11:12:03 UTC (rev 14683)
+++ branches/raster-providers/src/providers/wms/qgswmsprovider.h 2010-11-15 11:31:35 UTC (rev 14684)
@@ -459,6 +459,9 @@
*/
QImage *draw( QgsRectangle const & viewExtent, int pixelWidth, int pixelHeight );
+ void readBlock( int bandNo, QgsRectangle const & viewExtent, int width, int height, void *data );
+
+
/** Return the extent for this data layer
*/
virtual QgsRectangle extent();
@@ -524,6 +527,11 @@
*/
int capabilities() const;
+ int dataType ( int bandNo ) const;
+ int bandCount() const;
+
+
+
/**
* Get metadata in a format suitable for feeding directly
* into a subset of the GUI raster properties "Metadata" tab.
More information about the QGIS-commit
mailing list