Skip to content
Permalink
Browse files

QgsRasterPipe

  • Loading branch information
blazek committed Jul 1, 2012
1 parent b34e058 commit d937dbbc1d10a33885847b5fe74a2fddcd1d99bc
@@ -163,6 +163,7 @@ SET(QGIS_CORE_SRCS
raster/qgsrasterinterface.cpp
raster/qgsrasterlayer.cpp
raster/qgsrastertransparency.cpp
raster/qgsrasterpipe.cpp
raster/qgsrastershader.cpp
raster/qgsrastershaderfunction.cpp

@@ -391,6 +392,7 @@ SET(QGIS_CORE_HDRS
raster/qgsrasterinterface.h
raster/qgsrasterlayer.h
raster/qgsrastertransparency.h
raster/qgsrasterpipe.h
raster/qgsrastershader.h
raster/qgsrastershaderfunction.h
raster/qgsrasterviewport.h
@@ -104,12 +104,15 @@ void * QgsRasterDataProvider::readBlock( int bandNo, QgsRectangle const & exten
return data;
}

QgsRasterDataProvider::QgsRasterDataProvider(): mDpi( -1 )
QgsRasterDataProvider::QgsRasterDataProvider()
: QgsRasterInterface( 0, QgsRasterInterface::ProviderRole )
, mDpi( -1 )
{
}

QgsRasterDataProvider::QgsRasterDataProvider( QString const & uri )
: QgsDataProvider( uri )
, QgsRasterInterface( 0, QgsRasterInterface::ProviderRole )
, mDpi( -1 )
{
}
@@ -26,7 +26,8 @@ QgsRasterProjector::QgsRasterProjector(
int theDestRows, int theDestCols,
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent )
: mSrcCRS( theSrcCRS )
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mCoordinateTransform( theDestCRS, theSrcCRS )
, mDestExtent( theDestExtent )
@@ -45,7 +46,8 @@ QgsRasterProjector::QgsRasterProjector(
QgsCoordinateReferenceSystem theDestCRS,
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent )
: mSrcCRS( theSrcCRS )
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
, mSrcCRS( theSrcCRS )
, mDestCRS( theDestCRS )
, mCoordinateTransform( theDestCRS, theSrcCRS )
, mExtent( theExtent )
@@ -54,13 +56,27 @@ QgsRasterProjector::QgsRasterProjector(
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::QgsRasterProjector()
: QgsRasterInterface( 0, QgsRasterInterface::ProjectorRole )
{
QgsDebugMsg( "Entered" );
}

QgsRasterProjector::~QgsRasterProjector()
{
//delete mCoordinateTransform;
//delete pHelperTop;
//delete pHelperBottom;
}

void QgsRasterProjector::setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS )
{
mSrcCRS = theSrcCRS;
mDestCRS = theDestCRS;
mCoordinateTransform.setSourceCrs( theSrcCRS );
mCoordinateTransform.setDestCRS( theDestCRS );
}

void QgsRasterProjector::calc()
{
mCPMatrix.clear();
@@ -60,10 +60,20 @@ class QgsRasterProjector : public QgsRasterInterface
double theMaxSrcXRes, double theMaxSrcYRes,
QgsRectangle theExtent
);
QgsRasterProjector();

/** \brief The destructor */
~QgsRasterProjector();

/** \brief set source and destination CRS */
void setCRS( QgsCoordinateReferenceSystem theSrcCRS, QgsCoordinateReferenceSystem theDestCRS );

/** \brief set maximum source resolution */
void setMaxSrcRes( double theMaxSrcXRes, double theMaxSrcYRes )
{
mMaxSrcXRes = theMaxSrcXRes; mMaxSrcYRes = theMaxSrcYRes;
}

/** \brief get destination point for _current_ destination position */
void destPointOnCPMatrix( int theRow, int theCol, double *theX, double *theY );

@@ -125,6 +135,9 @@ class QgsRasterProjector : public QgsRasterInterface
/** get source extent */
QgsRectangle srcExtent() { return mSrcExtent; }

/** set source extent */
void setSrcExtent( const QgsRectangle theExtent ) { mSrcExtent = theExtent; }

/** get/set source width/height */
int srcRows() { return mSrcRows; }
int srcCols() { return mSrcCols; }
@@ -20,24 +20,26 @@

#include <QByteArray>

QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input ): mInput( input )
QgsRasterInterface::QgsRasterInterface( QgsRasterInterface * input, Role role ):
mInput( input )
, mRole( role )
{
}

QgsRasterInterface::~QgsRasterInterface()
{
}

// To give to an image preallocated memory is the only way to avoid memcpy
// To give to an image preallocated memory is the only way to avoid memcpy
// when we want to keep data but delete QImage
QImage * QgsRasterInterface::createImage ( int width, int height, QImage::Format format )
QImage * QgsRasterInterface::createImage( int width, int height, QImage::Format format )
{
// Qt has its own internal function depthForFormat(), unfortunately it is not public

QImage img( 1, 1, format );

// We ignore QImage::Format_Mono and QImage::Format_MonoLSB ( depth 1)
int size = width * height * img.bytesPerLine();
uchar * data = (uchar *) malloc ( size );
uchar * data = ( uchar * ) malloc( size );
return new QImage( data, width, height, format );
}
@@ -15,8 +15,8 @@
* *
***************************************************************************/

#ifndef QGSRASTERFACE_H
#define QGSRASTERFACE_H
#ifndef QGSRASTERINTERFACE_H
#define QGSRASTERINTERFACE_H

#include <QObject>
#include <QImage>
@@ -26,16 +26,25 @@
/** \ingroup core
* Base class for processing modules.
*/
// TODO: inherit from QObject? QgsRasterDataProvider inherits already from QObject
// TODO: inherit from QObject? QgsDataProvider inherits already from QObject, multiple inheritance from QObject is not allowed
class CORE_EXPORT QgsRasterInterface //: public QObject
{

//Q_OBJECT

public:

// TODO: This is copy of QgsRasterDataProvider::DataType, the QgsRasterDataProvider
// should use this DataType
enum Role
{
UnknownRole = 0,
ProviderRole = 1,
RendererRole = 2,
ResamplerRole = 3,
ProjectorRole = 4
};

Role role() { return mRole; }

// This is modified copy of GDALDataType
enum DataType
{
@@ -51,11 +60,11 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
/*! Complex Int32 */ CInt32 = 9,
/*! Complex Float32 */ CFloat32 = 10,
/*! Complex Float64 */ CFloat64 = 11,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32 */ ARGB32 = 12,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32 */ ARGB32 = 12,
/*! Color, alpha, red, green, blue, 4 bytes the same as
QImage::Format_ARGB32_Premultiplied */ ARGB32_Premultiplied = 13,

TypeCount = 14 /* maximum type # + 1 */
};

@@ -98,7 +107,7 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return typeSize( dataType( bandNo ) );
}

QgsRasterInterface( QgsRasterInterface * input = 0 );
QgsRasterInterface( QgsRasterInterface * input = 0, Role role = UnknownRole );

virtual ~QgsRasterInterface();

@@ -128,14 +137,19 @@ class CORE_EXPORT QgsRasterInterface //: public QObject
return 0;
}

void setInput( QgsRasterInterface* input ) { mInput = input; }
/** Set input.
* Returns true if set correctly, false if cannot use that input */
virtual bool setInput( QgsRasterInterface* input ) { mInput = input; return true; }

/** Create a new image with extraneous data, such data may be used
/** Create a new image with extraneous data, such data may be used
* after the image is destroyed. The memory is not initialized.
*/
QImage * createImage ( int width, int height, QImage::Format format );
QImage * createImage( int width, int height, QImage::Format format );

//protected:

Role mRole;

// QgsRasterInterface from used as input, data are read from it
QgsRasterInterface* mInput;

0 comments on commit d937dbb

Please sign in to comment.
You can’t perform that action at this time.