Logo Search packages:      
Sourcecode: qgis version File versions

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

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

This method is used to render a paletted raster layer as a colour 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.

Definition at line 1242 of file qgsrasterlayer.cpp.

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

{
#ifdef QGISDEBUG
  std::cout << "QgsRasterLayer::drawPalettedSingleBandColor called" << std::endl;
#endif

  GDALRasterBand *myGdalBand = gdalDataset->GetRasterBand(theBandNoInt);
  GDALDataType myDataType = myGdalBand->GetRasterDataType();
  void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );
  QgsColorTable *myColorTable = colorTable ( theBandNoInt );

  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;

      if (invertHistogramFlag)
      {
        c1 = 255 - c1;
        c2 = 255 - c2;
        c3 = 255 - c3;
      }
      //set the pixel based on the above color mappings
      myQImage.setPixel(myRowInt, myColumnInt, qRgba(c1, c2, c3, transparencyLevelInt));
    }
  }
  //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);
  CPLFree(myGdalScanData);
}


Generated by  Doxygen 1.6.0   Back to index