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

MAGICS_NO_EXPORT bool KMLDriver::renderPixmap ( float  x0,
float  y0,
float  x1,
float  y1,
int  w,
int  h,
unsigned char *  pixmap,
int  ,
bool   
) const [private, virtual]

render pixmaps

This method renders pixmaps. These are used for cell shading and raster input (GIFs and PNGs).

See also:
renderCellArray()
param x0 x of lower corner param y0 y of lower corner param x1 x of higher corner param y1 y of higher corner param w width of pixmap param h height of pixmap param pixmap contents

Reimplemented from magics::BaseDriver.

Definition at line 676 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 Image import uses GD -> for better results use Cairo backend."<< endl;
      stringstream out;
      out << 15 * kml_output_resource_list_.size();
      const string filename = "KML_overlay_"+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_ << "<styleUrl>#hiker-icon</styleUrl>\n"
            << "<color>"<<hex;
            if(a>15)    pFile_ <<a;
            else        pFile_ <<"0"<< a << dec;
      pFile_ << "ffffff</color>\n"
            << "<visibility>1</visibility>\n"
            << "<color>"<<hex;
                  if(a>15)    pFile_ <<a;
                  else        pFile_ <<"0"<< a << dec;
      pFile_ << "FFFFFF</color>\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>"<<y0<<"</north>\n"
            << "   <south>"<<y1<<"</south>\n"
            << "   <east>"<<x1<<"</east>\n"
            << "   <west>"<<x0<<"</west>\n"
            << "   <rotation>0</rotation>\n"
            << "</LatLonBox>\n";


      gdImagePtr im = gdImageCreateTrueColor(w,h);
      unsigned char *p = pixmap;
      gdImageColorAllocateAlpha(im, 255, 255, 255, 127);

      for(int i=h-1;i>=0;i--)
      {
            for(int j=0;j<w; j++)
            {
                  const int r = (int) *(p++);
                  const int g = (int) *(p++);
                  const int b = (int) *(p++);
                  const int col = gdImageColorResolveAlpha(im,r,g,b,0);
                  gdImageSetPixel(im, w, h, col);
            }
      }
      gdImageDestroy(im);
      gdImageAlphaBlending(im, 1);
      gdImageSaveAlpha(im, 1); // save transparency

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

      pFile_      << "</GroundOverlay>\n";
#endif
#else
      stringstream out;
      out << 15 * kml_output_resource_list_.size();
      string filename = "KML_overlay_"+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[Time: "<<currentLayer_<<"]]></name>\n";
      }

      const int a = (int)(getTransparency() * 2.55);
      pFile_      << "<styleUrl>#hiker-icon</styleUrl>\n"
            << "<color>"<<hex;
            if(a>15)    pFile_ <<a;
            else        pFile_ <<"0"<< a << dec;
      pFile_ << "ffffff</color>\n"
            << "<visibility>1</visibility>\n"
            << "<color>"<<hex;
            if(a>15)    pFile_ <<a;
            else        pFile_ <<"0"<< a << dec;
      pFile_ << "FFFFFF</color>\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>"<<y0<<"</north>\n"
            << "   <south>"<<y1<<"</south>\n"
            << "   <east>"<<x1<<"</east>\n"
            << "   <west>"<<x0<<"</west>\n"
            << "   <rotation>0</rotation>\n"
            << "</LatLonBox>\n";

      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_);

      unsigned char *p = pixmap;
      const float dx =  (x1 - x0)/w;
      const float dy = -(y1 - y0)/h;   // Minus needed for Y axis correction

      const float X0 = x0;
      const float Y0 = y0;

      for(int i=h-1;i>=0;i--)
      {
            for(int j=0;j<w; x0+=dx,j++)
            {
                  const float r = *(p++);
                  const float g = *(p++);
                  const float b = *(p++);

                  if( (r*g*b) > 0)
                  {
                        cairo_set_source_rgba(cr_,r,g,b,0.5);

                        const float x0 = X0+(j*dx)+.5;
                        const float y0 = Y0+(i*dy)+.5;
                        cairo_rectangle (cr_, x0,y0,dx,-dy);
                        cairo_stroke_preserve(cr_);
                        cairo_fill (cr_);
                  }
            }
            x0 = X0;
            y0 += dy;
      }
      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