Logo Search packages:      
Sourcecode: magics++ version File versions  Download package

MAGICS_NO_EXPORT bool KMLDriver::renderCellArray ( const Image &  image  )  const [private, virtual]

render cell arrays

This method renders cell arrays, also called images in Magics language. These are mainly used for satellite data.

sa renderPixmap()

param image Object containing an image

Reimplemented from magics::BaseDriver.

Definition at line 882 of file KMLDriver.cc.

References magics::magCompare(), and pFile_.

{
   if(render_)
   {
      if (kml_placemark_) closePlacemark();
#ifndef MAGICS_CAIRO
#ifndef MAGICS_RASTER
      Log::warning() << "Image import is not implemented for the used driver!!!" << endl; return false;
#else
Log::dev()<< "KML driver uses GD -> for better results use Cairo backend."<< endl;
      stringstream out;
      out << currentPage_;
      const string layer_name = (!currentLayer_.empty()) ? currentLayer_ : "default_page";
      const string filename = "KML_cell_overlay_"+layer_name+"_"+out.str()+".png";

      pFile_      << "<GroundOverlay>\n";
      if(layer_)
      {
            if(!currentTimeBegin_.empty())
            {
                     if(magCompare(currentTimeBegin_,currentTimeEnd_))
                     {
                        pFile_      << "<TimeStamp>\n"
                              << " <when>"<<currentTimeBegin_<<"</when>\n"
                              << "</TimeStamp>\n"
                              << "<styleUrl>#hiker-icon</styleUrl>\n";
                     }
                     else
                     {
                        pFile_      << "<TimeSpan>\n"
                              << " <begin>"<<currentTimeBegin_<<"</begin>\n"
                              << " <end>"<<currentTimeEnd_<<"</end>\n"
                              << "</TimeSpan>\n"
                              << "<styleUrl>#hiker-icon</styleUrl>\n";
                     }
            }
            pFile_      << "<name><![CDATA[Layer: "<<currentLayer_<<"]]></name>\n";
      }

      const int a = (int)(getTransparency() * 2.55);
      pFile_      << "<color>"<<hex;
            if(a>15)    pFile_ <<a;
            else        pFile_ <<"0"<< a << dec;
      pFile_ << "ffffff</color>\n"
            << "<visibility>1</visibility>\n"
            << "<Icon>\n"
            << "<href>"<<filename<<"</href>\n"
//          << "<refreshMode>onInterval</refreshMode>\n"
//          << "<refreshInterval>86400</refreshInterval>\n"
//          << "<viewBoundScale>0.75</viewBoundScale>\n"
            << "</Icon>\n"
            << "<LatLonBox>\n"
            << "   <north>"<<image.getOrigin().y()<<"</north>\n"
            << "   <south>"<<image.getOrigin().y()-image.getHeight()<<"</south>\n"
            << "   <east>"<<image.getOrigin().x()+image.getWidth()<<"</east>\n"
            << "   <west>"<<image.getOrigin().x()<<"</west>\n"
            << "   <rotation>0</rotation>\n"
            << "</LatLonBox>\n";

      ColourTable &lt = image.getColourTable();
      const int width = image.getNumberOfColumns();
      const int height = image.getNumberOfRows();

      gdImagePtr im = gdImageCreateTrueColor(width,height);
      gdImageColorAllocateAlpha(im, 255, 255, 255, 127);

      for (int i=height-1;i>=0;i--)
      {
            for(int j=0;j<width; j++)
            {
              const int in = width*i+j;
              const short c = image[in];

              if(!(lt[c]=="undefined"))
              {
                  const int r = static_cast<int>(lt[c].red()*255.);
                  const int g = static_cast<int>(lt[c].green()*255.);
                  const int b = static_cast<int>(lt[c].blue()*255.);
                  const int a = static_cast<int>(lt[c].alpha()*127.);

                  const int col = gdImageColorResolveAlpha(im,r,g,b,a);
                  gdImageSetPixel(im, j, i, col);
              }// point has colour
            }
      }

      gdImageAlphaBlending(im, 1);
      gdImageSaveAlpha(im, 1); // save transparency

      FILE *outFile = fopen(filename.c_str(),"wb");
      gdImagePng(im,outFile);
      fclose(outFile);
      gdImageDestroy(im);
      kml_output_resource_list_.push_back(filename);

      pFile_      << "</GroundOverlay>\n";
#endif
#else
      stringstream out;
      out << currentPage_;
      const string layer_name = (!currentLayer_.empty()) ? currentLayer_ : "default_page";
      string filename = "KML_cell_overlay_"+layer_name+"_"+out.str()+".png";
      string::size_type loc=0;

      while(loc != string::npos)
      {
        loc=filename.find( ":", 0);
          if( loc != string::npos ) filename.replace(loc, 1, "-");
        }

      pFile_      << "<GroundOverlay>\n";
      if(layer_)
      {
            if(!currentTimeBegin_.empty())
            {
                     if(magCompare(currentTimeBegin_,currentTimeEnd_))
                     {
                        pFile_      << "<TimeStamp>\n"
                              << " <when>"<<currentTimeBegin_<<"</when>\n"
                              << "</TimeStamp>\n"
                              << "<styleUrl>#hiker-icon</styleUrl>\n";
                     }
                     else
                     {
                        pFile_      << "<TimeSpan>\n"
                              << " <begin>"<<currentTimeBegin_<<"</begin>\n"
                              << " <end>"<<currentTimeEnd_<<"</end>\n"
                              << "</TimeSpan>\n"
                              << "<styleUrl>#hiker-icon</styleUrl>\n";
                     }
            }
            pFile_      << "<name><![CDATA[Layer: "<<currentLayer_<<"]]></name>\n";
      }

      const int a = (int)(getTransparency() * 2.55);
      pFile_      << "<color>"<<hex;
            if(a>15)    pFile_ <<a;
            else        pFile_ <<"0"<< a << dec;
      pFile_ << "ffffff</color>\n"
            << "<visibility>1</visibility>\n"
            << "<Icon>\n"
            << "<href>"<<filename<<"</href>\n"
//          << "<refreshMode>onInterval</refreshMode>\n"
//          << "<refreshInterval>86400</refreshInterval>\n"
//          << "<viewBoundScale>0.75</viewBoundScale>\n"
            << "</Icon>\n"
            << "<LatLonBox>\n"
            << "   <north>"<<image.getOrigin().y()<<"</north>\n"
            << "   <south>"<<image.getOrigin().y()-image.getHeight()<<"</south>\n"
            << "   <east>"<<image.getOrigin().x()+image.getWidth()<<"</east>\n"
            << "   <west>"<<image.getOrigin().x()<<"</west>\n"
            << "   <rotation>0</rotation>\n"
            << "</LatLonBox>\n";

      ColourTable &lt = image.getColourTable();
      const int w = image.getNumberOfColumns();
      const int h = image.getNumberOfRows();

      cairo_surface_t* surface_ = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,w,h);
      cairo_t* cr_ = cairo_create(surface_);

// \todo specify layer transparency

      // set background to transparent
//    cairo_save (cr_);
      cairo_set_source_rgba (cr_, 1.0, 1.0, 1.0, 0.0);
//    cairo_set_operator (cr_, CAIRO_OPERATOR_SOURCE);
      cairo_paint (cr_);
//    cairo_restore (cr_);

      const float dx = 1.;
      const float dy = 1.;

      for (int i=h-1;i>=0;i--)
      {
            for(int j=0;j<w; j++)
            {
              const int in = w*i+j;
              const short c = image[in];

              if(!(lt[c]=="undefined"))
              {
                  float r = lt[c].red();
                  float g = lt[c].green();
                  float b = lt[c].blue();
                  float a = lt[c].alpha();

                  if( (r*g*b>1.) || (r*g*b<0.) )
                  {
                        r = 1.;
                        g = 1.;
                        b = 1.;
                        a = 0.;
//                      Log::info()<< "PostScriptDriver-> Cellshading colour not defined in table! Colour index: "<<c<<endl;
//    PostScript will always 'overpaint' anything below missing data!!!!
//
                  }
                  cairo_set_source_rgba(cr_,r,g,b,a);

                  const float x0 = (j*dx);
                  const float y0 = (i*dy);
                  cairo_rectangle (cr_, x0,y0,dx,-dy);
                  cairo_stroke_preserve(cr_);
                  cairo_fill (cr_);
//                gdImageSetPixel(im, j, i, col);
              }// point has colour
            }
      }

      cairo_surface_write_to_png (surface_, filename.c_str());

      cairo_destroy (cr_);
      cairo_surface_destroy (surface_);

      kml_output_resource_list_.push_back(filename);
      pFile_      << "</GroundOverlay>\n";
#endif
   }
      return true;
}


Generated by  Doxygen 1.6.0   Back to index