void PictureBank::Impl::setPicture( const std::string &name, const Picture& pic )
{
  int dot_pos = name.find_last_of('.');
  std::string rcname = name.substr(0, dot_pos);

  // first: we deallocate the current picture, if any
  unsigned int picId = Hash( rcname );
  Picture* ptrPic = 0;
  Impl::ItPicture it = resources.find( picId );
  if( it != resources.end() )
  {
    //SDL_DestroyTexture( it->second.texture() );
    if( it->second.texture() > 0 )
      txCounters[ it->second.texture() ]--;

    ptrPic = &it->second;
  }
  else
  {
    resources[ picId ] = Picture();
    ptrPic = &resources[ picId ];
  }

  *ptrPic = pic;
  if( pic.texture() > 0 )
    txCounters[ pic.texture() ]++;

  Point offset( 0, 0 );

  // decode the picture name => to set the offset manually
  Point pic_info = PictureInfoBank::instance().getOffset( rcname );

  if( pic_info == PictureInfoBank::instance().getDefaultOffset( PictureInfoBank::tileOffset ) )
  {
    // this is a tiled picture=> automatic offset correction
    int cw = gfx::tilemap::cellSize().width() * 2;
    int ch = gfx::tilemap::cellSize().width() / 2;
    offset.setY( pic.height()-ch*( (pic.width()+2)/cw ) );   // (w+2)/60 is the size of the tile: (1x1, 2x2, 3x3, ...)
  }
  else if( pic_info == PictureInfoBank::instance().getDefaultOffset( PictureInfoBank::walkerOffset ) )
  {
     // this is a walker picture=> automatic offset correction
     offset = Point( -pic.width()/2, int(pic.height()*3./4.) );
  }
  else
  {
     offset = pic_info;
  }

  ptrPic->setOffset( offset );
  ptrPic->setName( rcname );
}
Beispiel #2
0
void
embryo::savePNG(ostream& inStream, const Picture& inPicture) {
  // Setup libpng
  png_structp lPngPtr = png_create_write_struct(PNG_LIBPNG_VER_STRING, 0, 0, 0);
  if (!lPngPtr)
    throw Exception("Out of memory");

  png_infop lInfoPtr = png_create_info_struct(lPngPtr);
  if (!lInfoPtr) {
    png_destroy_write_struct(&lPngPtr, 0);
    throw Exception("Out of memory");
  }

  png_set_error_fn(lPngPtr, 0, &errorCallback, &warningCallback);
  png_set_write_fn(lPngPtr, &inStream, &writeDataCallback, &flushCallback);

  // Setup and write the picture infos
  png_set_IHDR(lPngPtr, lInfoPtr,
                 inPicture.width(),
                 inPicture.height(),
                 8,
                 PNG_COLOR_TYPE_GRAY,
                 PNG_INTERLACE_NONE,
                 PNG_COMPRESSION_TYPE_DEFAULT,
                 PNG_FILTER_TYPE_DEFAULT);
  png_write_info(lPngPtr, lInfoPtr);
 
  // Write the picture datas
  png_bytep lRasterRow = new png_byte[inPicture.width()];
  const double* lSrc = inPicture.pixels();

  for(size_t i = 0; i < inPicture.height(); ++i) {
    png_bytep lDst = lRasterRow;
    for(size_t j = inPicture.width(); j != 0; ++lSrc, ++lDst, --j)
      (*lDst) = 255.0 * (*lSrc);

    png_write_row(lPngPtr, lRasterRow);
  }

  png_write_end(lPngPtr, lInfoPtr);

  // Job done
  delete[] lRasterRow;
  png_destroy_write_struct(&lPngPtr, &lInfoPtr);
}
void EmpireMapWindow::Impl::drawCities(Engine& painter)
{
    world::CityList cities = city->empire()->cities();
    Point location;
    Picture pic;
    for( auto city : cities )
    {
        location = city->location();
        pic = city->picture();
        painter.draw( city->pictures(), offset + location - Point( pic.width() / 2, pic.height() / 2 ) );
#ifdef DEBUG
        drawCell( painter, offset + location - Point( 10, 10 ), 20, DefaultColors::red );
#endif
    }
}
void CMonitoringUI::handle1(Poco::Notification* pNf)
{
	poco_check_ptr(pNf);
	Picture *pImg = NULL;
	//CaptureNotify::handle1(pNf);
	//CaptureNotify::handle1(pNf, &pImg);
	Notification::Ptr pf(pNf);
	poco_check_ptr(pf.get());
	CaptureNotification::Ptr nf = pf.cast<CaptureNotification>();
	poco_check_ptr(nf.get());
	Picture::Ptr pic(nf->data());
	poco_check_ptr(pic.get());
	pImg = pic.get();
	CapBitmapData capdata((const BYTE *)pImg->data(), pImg->width() * pImg->height() * 3, pImg->width(), pImg->height());
	Camera::MirrorDIB((const char *)capdata.getData(), capdata.getWidth(), capdata.getHeigth(), false, 24);
	m_capdata.push(capdata);		
	//delete pImg;
}
static jint android_graphics_Picture_getHeight(JNIEnv* env, jobject, jlong pictureHandle) {
    Picture* pict = reinterpret_cast<Picture*>(pictureHandle);
    return static_cast<jint>(pict->height());
}
Beispiel #6
0
void SdlEngine::loadPicture(Picture& ioPicture, bool streaming)
{
  if( !ioPicture.surface() )
  {
    Size size = ioPicture.size();
    Logger::warning( StringHelper::format( 0xff, "SdlEngine:: can't make surface, size=%dx%d", size.width(), size.height() ) );
  }

  SDL_Texture* tx = 0;
  if( streaming )
  {
    tx = SDL_CreateTexture(_d->renderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, ioPicture.width(), ioPicture.height() );
  }
  else
  {
    tx = SDL_CreateTextureFromSurface(_d->renderer, ioPicture.surface());
  }

  if( !tx )
  {
    Logger::warning( "SdlEngine: cannot create texture from surface" + ioPicture.name() );
  }

  ioPicture.init( tx, ioPicture.surface(), 0 );

  if( streaming )
  {
    ioPicture.update();
  }

  SDL_SetTextureBlendMode( ioPicture.texture(), SDL_BLENDMODE_BLEND );
  SDL_SetSurfaceBlendMode( ioPicture.surface(), SDL_BLENDMODE_BLEND );
}
Beispiel #7
0
void Garden::setPicture(Picture picture)
{
  Construction::setPicture( picture );
  _flat = picture.width()/ (float)picture.height() >= 1.7f;
}
void RenderContext::draw_background( litehtml::uint_ptr hdc, const litehtml::background_paint& bg )
{
  /*cairo_save(cr);
  apply_clip(cr);

  rounded_rectangle(cr, bg.border_box, bg.border_radius);
  cairo_clip(cr);
  */
  //cr->fill( NColor( bg.color.alpha, bg.color.red, bg.color.green, bg.color.blue ),
  //          Rect( bg.clip_box.x, bg.clip_box.y, bg.clip_box.x+bg.clip_box.width, bg.clip_box.y+bg.clip_box.height) );

  litehtml::tstring url;
  make_url(bg.image.c_str(), bg.baseurl.c_str(), url);

  //lock_images_cache();
  ImagesMap::iterator img_i = m_images.find(url.c_str());
  if(img_i != m_images.end() && img_i->second.isValid())
  {
    Picture bgbmp = img_i->second;

    Picture new_img;
    if(bg.image_size.width != bgbmp.width() || bg.image_size.height != bgbmp.height())
    {
      //new_img = bgbmp->scale_simple(bg.image_size.width, bg.image_size.height, Gdk::INTERP_BILINEAR);
      bgbmp = new_img;
    }

   /* cairo_surface_t* img = surface_from_pixbuf(bgbmp);
    cairo_pattern_t *pattern = cairo_pattern_create_for_surface(img);
    cairo_matrix_t flib_m;
    cairo_matrix_init_identity(&flib_m);
    cairo_matrix_translate(&flib_m, -bg.position_x, -bg.position_y);
    cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
    cairo_pattern_set_matrix (pattern, &flib_m);
*/
    switch(bg.repeat)
    {
    case litehtml::background_repeat_no_repeat:
      //cr->draw( bgbmp, Point( bg.position_x, bg.position_y ), Size( bgbmp.width(), bgbmp.height() ) );
      break;

    case litehtml::background_repeat_repeat_x:
      /*cairo_set_source(cr, pattern);
      cairo_rectangle(cr, bg.clip_box.left(), bg.position_y, bg.clip_box.width, bgbmp->get_height());
      cairo_fill(cr);*/
      break;

    case litehtml::background_repeat_repeat_y:
      /*cairo_set_source(cr, pattern);
      cairo_rectangle(cr, bg.position_x, bg.clip_box.top(), bgbmp->get_width(), bg.clip_box.height);
      cairo_fill(cr);*/
      break;

    case litehtml::background_repeat_repeat:
      /*cairo_set_source(cr, pattern);
      cairo_rectangle(cr, bg.clip_box.left(), bg.clip_box.top(), bg.clip_box.width, bg.clip_box.height);
      cairo_fill(cr);
      */
      break;
    }

    //cairo_pattern_destroy(pattern);
    //cairo_surface_destroy(img);

  }
}