diff --git a/src/qgsrasterlayer.cpp b/src/qgsrasterlayer.cpp index 6406ab13d9d..c09f11902b0 100644 --- a/src/qgsrasterlayer.cpp +++ b/src/qgsrasterlayer.cpp @@ -15,7 +15,6 @@ * * ***************************************************************************/ /* $Id$ */ -#include #include #include @@ -62,18 +61,10 @@ void QgsRasterLayer::draw(QPainter * p, QgsRect * viewExtent, QgsCoordinateTrans { //std::cout << "QgsRasterLayer::draw()" << std::endl; //std::cout << "gdalDataset->GetRasterCount(): " << gdalDataset->GetRasterCount() << std::endl; - std::cout << "Layer extent: " << layerExtent.stringRep() << std::endl; + //std::cout << "Layer extent: " << layerExtent.stringRep() << std::endl; // clip raster extent to view extent QgsRect rasterExtent = viewExtent->intersect(&layerExtent); - std::cout << "viewXMin: " << viewExtent->xMin() <yMax() <xMax() <yMin() <((layerExtent.yMax() - viewExtent->yMax()) / fabs(adfGeoTransform[5])); rYOff = rYOff >? 0; - std::cout << "rXOff: " << rXOff <transform(rasterExtent.xMin(), rasterExtent.yMax()); QgsPoint bottomRight = cXf->transform(rasterExtent.xMax(), rasterExtent.yMin()); - int lXSize = bottomRight.xToInt() - topLeft.xToInt(); int lYSize = bottomRight.yToInt() - topLeft.yToInt(); - std::cout << "xMin: " << layerExtent.xMin() <GetRasterCount(); i++) { GDALRasterBand *gdalBand = gdalDataset->GetRasterBand( i ); //std::cout << "gdalBand->GetOverviewCount(): " << gdalBand->GetOverviewCount() <GetXSize() - nXOff; - //int nYSize = gdalBand->GetYSize() - nYOff; // make sure we don't exceed size of raster rXSize = rXSize GetXSize(); rYSize = rYSize GetYSize(); - std::cout << "rXSize: " << rXSize <RasterIO( GF_Read, rXOff, rYOff, rXSize, rYSize, scandata, lXSize, lYSize, GDT_UInt32, 0, 0 ); + + QString colorInterp = GDALGetColorInterpretationName(gdalBand->GetColorInterpretation()); + if ( colorInterp == "Palette") { + // print each point in scandata using color looked up in color table + GDALColorTable *colorTable = gdalBand->GetColorTable(); - GDALColorTable *colorTable = gdalBand->GetColorTable(); - - // print each point in scandata using color looked up in color table - for (int y = 0; y < lYSize; y++) { - for (int x =0; x < lXSize; x++) { - const GDALColorEntry *colorEntry = GDALGetColorEntry(colorTable, scandata[y*lXSize + x]); - p->setPen(QColor(colorEntry->c1, colorEntry->c2, colorEntry->c3)); - p->drawPoint(topLeft.xToInt() + x, topLeft.yToInt() + y); + for (int y = 0; y < lYSize; y++) { + for (int x =0; x < lXSize; x++) { + const GDALColorEntry *colorEntry = GDALGetColorEntry(colorTable, scandata[y*lXSize + x]); + p->setPen(QColor(colorEntry->c1, colorEntry->c2, colorEntry->c3)); + p->drawPoint(topLeft.xToInt() + x, topLeft.yToInt() + y); + } + } + } else if ( colorInterp == "Red" ) { + // print each point in scandata as the red part of an rgb value + for (int y = 0; y < lYSize; y++) { + for (int x =0; x < lXSize; x++) { + p->setPen(QColor(scandata[y*lXSize + x], 0, 0)); + p->drawPoint(topLeft.xToInt() + x, topLeft.yToInt() + y); + } + } + } else if ( colorInterp == "Green" ) { + // print each point in scandata as the green part of an rgb value + p->setRasterOp(Qt::XorROP); + for (int y = 0; y < lYSize; y++) { + for (int x =0; x < lXSize; x++) { + p->setPen(QColor(0, scandata[y*lXSize + x], 0)); + p->drawPoint(topLeft.xToInt() + x, topLeft.yToInt() + y); + } } + p->setRasterOp(Qt::CopyROP); + } else if ( colorInterp == "Blue" ) { + // print each point in scandata as the blue part of an rgb value + p->setRasterOp(Qt::XorROP); + for (int y = 0; y < lYSize; y++) { + for (int x =0; x < lXSize; x++) { + p->setPen(QColor(0, 0, scandata[y*lXSize + x])); + p->drawPoint(topLeft.xToInt() + x, topLeft.yToInt() + y); + } + } + p->setRasterOp(Qt::CopyROP); + } else { + // do nothing } - + CPLFree(scandata); } }