Logo Search packages:      
Sourcecode: qgis version File versions

void QgsRasterLayer::drawPalettedSingleBandGray ( QPainter *  theQPainter,
RasterViewPort theRasterViewPort,
int  theBandNoInt,
QString  theColorQString 
) [private]

Drawing routine for paletted image, rendered as a single band image in grayscale.

This method is used to render a paletted raster layer as a gray image.

Parameters:
theQPainter - pointer to the QPainter onto which the layer should be drawn.
theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file.
theGdalBand - pointer to the GDALRasterBand which should be rendered.
theColorQString - QString containing either 'Red' 'Green' or 'Blue' indicating which part of the rgb triplet will be used to render gray.

Definition at line 1297 of file qgsrasterlayer.cpp.

References RasterBandStats::colorTable, RasterViewPort::drawableAreaXDimInt, RasterViewPort::drawableAreaYDimInt, filterLayer(), gdalDataset, getRasterBandStats(), invertHistogramFlag, noDataValueDouble, readData(), readValue(), RasterViewPort::topLeftPoint, and transparencyLevelInt.

Referenced by draw().

{
#ifdef QGISDEBUG
  std::cout << "QgsRasterLayer::drawPalettedSingleBandGray called" << std::endl;
#endif
  RasterBandStats myRasterBandStats = getRasterBandStats(theBandNoInt);
  GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
  GDALDataType myDataType = myGdalBand->GetRasterDataType();
  void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
  QgsColorTable *myColorTable = &(myRasterBandStats.colorTable);

  QImage myQImage = QImage(theRasterViewPort->drawableAreaXDimInt, theRasterViewPort->drawableAreaYDimInt, 32);
  myQImage.fill(0);
  myQImage.setAlphaBuffer(true);

  for (int myColumnInt = 0; myColumnInt < theRasterViewPort->drawableAreaYDimInt; ++myColumnInt)
  {
    for (int myRowInt = 0; myRowInt < theRasterViewPort->drawableAreaXDimInt; ++myRowInt)
    {
      double myValDouble = readValue ( myGdalScanData, myDataType,
                                       myColumnInt * theRasterViewPort->drawableAreaXDimInt + myRowInt );

      if ( myValDouble == noDataValueDouble || myValDouble != myValDouble ) continue; // NULL

      int c1, c2, c3;
      bool found = myColorTable->color ( myValDouble, &c1, &c2, &c3 );
      if ( !found ) continue;

      int myGrayValueInt = 0; //color 1 int

      if (theColorQString == redTranslatedQString)
      {
        myGrayValueInt = c1;
      }
      else if (theColorQString == greenTranslatedQString)
      {
        myGrayValueInt = c2;
      }
      else if (theColorQString == blueTranslatedQString)
      {
        myGrayValueInt = c3;
      }

      if (invertHistogramFlag)
      {
        myGrayValueInt = 255 - myGrayValueInt;
      }

      //set the pixel based on the above color mappings
      myQImage.setPixel(myRowInt, myColumnInt, qRgba(myGrayValueInt, myGrayValueInt, myGrayValueInt, transparencyLevelInt));
    }
  }
  CPLFree ( myGdalScanData );

  //render any inline filters
  filterLayer(&myQImage);

  //part of the experimental transaparency support
  theQPainter->drawImage(static_cast<int>(theRasterViewPort->topLeftPoint.x()),
                         static_cast<int>(theRasterViewPort->topLeftPoint.y()),
                         myQImage);
}


Generated by  Doxygen 1.6.0   Back to index