Logo Search packages:      
Sourcecode: qgis version File versions

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

Drawing routine for paletted multiband image.

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 1575 of file qgsrasterlayer.cpp.

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

Referenced by draw().

{
#ifdef QGISDEBUG
  std::cout << "QgsRasterLayer::drawPalettedMultiBandColor 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;

        int myRedValueInt = 0;  //color 1 int
        int myGreenValueInt = 0;  //color 2 int
        int myBlueValueInt = 0; //color 3 int

        //check for alternate color mappings
        if (redBandNameQString == redTranslatedQString)
          myRedValueInt = c1;
        else if (redBandNameQString == greenTranslatedQString)
          myRedValueInt = c2;
        else if (redBandNameQString == blueTranslatedQString)
          myRedValueInt = c3;

        if (greenBandNameQString == redTranslatedQString)
          myGreenValueInt = c1;
        else if (greenBandNameQString == greenTranslatedQString)
          myGreenValueInt = c2;
        else if (greenBandNameQString == blueTranslatedQString)
          myGreenValueInt = c3;

        if (blueBandNameQString == redTranslatedQString)
          myBlueValueInt = c1;
        else if (blueBandNameQString == greenTranslatedQString)
          myBlueValueInt = c2;
        else if (blueBandNameQString == blueTranslatedQString)
          myBlueValueInt = c3;

        if (invertHistogramFlag)
        {
          myRedValueInt = 255 - myRedValueInt;
          myGreenValueInt = 255 - myGreenValueInt;
          myBlueValueInt = 255 - myBlueValueInt;

        }
        //set the pixel based on the above color mappings
        myQImage.setPixel(myRowInt, myColumnInt, qRgba(myRedValueInt, myGreenValueInt, myBlueValueInt, 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);
//                         myQImage);
//>>>>>>> 1.98.2.9
}


Generated by  Doxygen 1.6.0   Back to index