Beispiel #1
0
Picture frame(const Picture& p)
{
	Picture r;
	r.init(p.height + 2, p.width + 2);

	for(int i = 1; i < r.height -1 ; ++i) {
		r.position(i, 0) = '|';
		r.position(i, r.width - 1) = '|';
	}

	for(int j = 1; j < r.width -1 ; ++j) {
			r.position(0, j) = '-';
			r.position(r.height - 1, j) = '-';
	}

	r.position(0, 0) = '+';
	r.position(0, r.width-1) = '+';
	r.position(r.height - 1, 0) = '+';
	r.position(r.height - 1, r.width - 1) = '+';

	r.copyblock(1, 1, p);

	return r;
}
Beispiel #2
0
/*********************************************************
 *                          draw                         *
 *********************************************************/
void Menu::draw(int pos)
{
   Font fnt;
   Options opt;
   fnt.defineFont(opt.getDefaultFont(), 10);
   fnt.defineFontAlign(Font::ALIGN_LEFT);
   fnt.defineFontStyle(Font::STYLE_NORMAL);

   /* Define Coordinates */
   int x1 = x;
   int x2 = x1 + (maxCharac)*(fnt.getIncCP()+1)+4; 
   int y1 = y;
   int y2 = (((int)list.size()-numPictures) * ITEM_HEIGHT) + 
                                         y1 + 5; /* bizarre from DOS version */
   
   /* Verify Sides */
   if(x2 > wWidth-1)
   {
      x1 = (wWidth-1) - (x2 - x1);
      x2 = wWidth-1;
      x = x1;
   }
   if(y2 > wHeight-1)
   {
      y1 = (wHeight-1) - (y2 - y1);
      y2 = wHeight-1;
      y = y1;
   }

   /* Draw the Menu */
   color_Set(colors.colorMenu.R, colors.colorMenu.G,
             colors.colorMenu.B, colors.colorMenu.A);
   rectangle_Fill(wSurface,x1+1,y1+1,x2-1,y2-1);
   color_Set(colors.colorCont[2].R, colors.colorCont[2].G,
             colors.colorCont[2].B, colors.colorCont[2].A);
   rectangle_Oval(wSurface,x1,y1,x2,y2,colors.colorCont[1].R,
                  colors.colorCont[1].G, colors.colorCont[1].B,
                  colors.colorCont[1].A);
      /*itens*/  
   int xa = x1+4;
   int ya = y1+3;
   int med = (ITEM_HEIGHT - 10) / 2;
   GuiObject* item;

   std::list<GuiObject*>::iterator it;
   for(it=list.begin(); it != list.end(); it++)
   {
      item = (*it);
      /* Treat Pictures */
      if(item->type == Farso::OBJECT_PICTURE)
      {
         Picture* pic = (Picture*)item;
         pic->setCoordinate(xa, ya+med+1, xa+10, ya+10+med+1);
         pic->draw();
         /* The next text will be translated right */
         xa = x1+15;
      }
      /* treat Texts */
      else if(item->type == Farso::OBJECT_TEXT_BOX)
      {
         color_Set(colors.colorText.R,
               colors.colorText.G,
               colors.colorText.B,
               colors.colorText.A);

         /* Menu Texts */
         if (item->getText().compare("-"))
         {
            if (item->isAvailable()) 
            {
               fnt.write(wSurface,xa,ya+med,item->getText());
            }
            else
            {
               color_Set(colors.colorCont[2].R, colors.colorCont[2].G,
                     colors.colorCont[2].B, colors.colorCont[2].A);
               fnt.write(wSurface,xa+1,ya+med+1,item->getText());
               color_Set(colors.colorCont[1].R, colors.colorCont[1].G,
                     colors.colorCont[1].B, colors.colorCont[1].A);
               fnt.write(wSurface,xa,ya+med,item->getText());
            }
         } 

         /* Menu Separators */
         else 
         {
            color_Set(colors.colorCont[1].R, colors.colorCont[1].G,
                  colors.colorCont[1].B, colors.colorCont[1].A);
            rectangle_2Colors(wSurface,xa-2,ya+6,x2-2,ya+7,
                  colors.colorCont[0].R,
                  colors.colorCont[0].G,colors.colorCont[0].B,
                  colors.colorCont[0].A);
         }
         xa = x1+4;
         ya += ITEM_HEIGHT;
      }
   }
  
}
Beispiel #3
0
void ScrollBar::setBackgroundImage( const Picture& pixmap )
{
	_d->texture = pixmap;
  _d->textureRect = Rect( Point(0,0), pixmap.getSize() );
}
Beispiel #4
0
void ScrollBar::setSliderImage( const Picture& pixmap, const ElementState state )
{
  (state == stNormal ? _d->sliderPictureUp : _d->sliderPictureDown ) = pixmap;
	_d->sliderTextureRect = Rect( Point(0,0), pixmap.getSize() );
}
void AdaptiveTemporalReduce(Video *src, double *gradient, int time, char *output_folder)
{
	double ratio = (src->GetTime() / time);
	int *selected = new int[src->GetTime()];
	for (int t = 0; t < src->GetTime(); t++)
		selected[t] = 0;

	double *acMotion = NULL;
	double *mapping = NULL;
	int *left_idices = NULL;
	int shot_num = src->GetTime();
	int left_time;
	while (shot_num>0)
	{
		shot_num = 0;
		left_time = time;
		
		int left_frames = 0;		
		for (int t = 0; t < src->GetTime(); t++)
		{
			if (selected[t]==0)
				left_frames++;
		}

		if (left_idices!=NULL)
			delete [] left_idices;
		left_idices = new int[left_frames];		

		if (acMotion!=NULL)
			delete [] acMotion;
		acMotion = new double[left_frames];
		int cur_frame = 0;
		for (int t = 0; t < src->GetTime(); t++)
		{
			if (selected[t]==0)
			{
				left_idices[cur_frame] = t;
				
				if (cur_frame==0)
					acMotion[cur_frame] = gradient[t];
				else
					acMotion[cur_frame] = acMotion[cur_frame-1]+gradient[t];

				cur_frame++;
			}
			else
			{
				left_time--;
			}			
		}
	
		if (mapping!=NULL)
			delete [] mapping;
		mapping = new double[left_frames];
		for (int t = 0; t < left_frames; t++)
		{
			mapping[t] = (acMotion[t]-acMotion[0])/
							(acMotion[left_frames-1]-acMotion[0])*left_time;


			double bound = ceil(mapping[t-1])+1+((ceil(mapping[t-1])-mapping[t-1])+1);
			if (mapping[t]>bound)
			{
				selected[left_idices[t]] = 1;
				shot_num++;
			}
		}

	}

	delete [] acMotion;

	cout << "Reducing video from " << src->GetTime() 
		 << " frames to " << time << " frames..." << endl;
	
	int *frame_ids_left = new int[left_time];
	frame_ids_left[0] = left_idices[0];
	int last_sid = 0;
	
	for (int t = 1; t < left_time; t++)
	{
		for (int tt = last_sid+1; tt < src->GetTime()-time+left_time; tt++)
		{
			if (mapping[tt]==t)
			{
				frame_ids_left[t] = left_idices[tt];
				last_sid = tt-1;
				break;
			}
			if (mapping[tt]>t)
			{
				/*
				double lweight = t-mapping[tt-1];
				double rweight = mapping[tt]-t;
				
				frames[t] = *(InterpolateFrame(src->GetFrame(tt-1),
											   lweight/(lweight+rweight),
											   src->GetFrame(tt),
											   rweight/(lweight+rweight)));

			    last_sid = tt-2;
			    */
				
				if (t-mapping[tt-1]<=mapping[tt]-t)
				{
					frame_ids_left[t] = left_idices[tt-1];
					last_sid = tt-1;
				} else
				{
					frame_ids_left[t] = left_idices[tt];
					last_sid = tt;
				}

				break;
				
			}
		}
	}

	delete [] left_idices;
	delete [] mapping;

	int *frame_ids_selected = new int[time-left_time];
	int cur_frame = 0;
	for (int t = 0; t < src->GetTime(); t++)
	{
		if (selected[t]>0)
		{
			frame_ids_selected[cur_frame] = t;
			cur_frame++;
		}
	}

	delete [] selected;

	int cur_left = 0;
	int cur_selected = 0;
	Picture *frame;
	for (int t = 0; t < time; t++)
	{
		char framename[512] = {'\0'};
		char buf[512] = {'\0'};
		strcat(framename,output_folder);
		strcat(framename,itoa(t,buf,10));
		strcat(framename,".ppm");
	 
		if ((frame_ids_left[cur_left]<frame_ids_selected[cur_selected]) &&
			(cur_left<left_time && cur_selected<time-left_time))
		{
			frame = src->GetFrame(frame_ids_left[cur_left]);
			cur_left++;
		}
		else if ((frame_ids_left[cur_left]>frame_ids_selected[cur_selected]) &&
			(cur_left<left_time && cur_selected<time-left_time))
		{
			frame = src->GetFrame(frame_ids_selected[cur_selected]);
			cur_selected++;
		}
		else if ((cur_left<left_time) && cur_selected==time-left_time)
		{
			frame = src->GetFrame(frame_ids_left[cur_left]);
			cur_left++;
		}
		else if ((cur_left==left_time) && cur_selected<time-left_time)
		{
			frame = src->GetFrame(frame_ids_selected[cur_selected]);
			cur_selected++;
		}

		frame->Save(framename);
	}

	delete [] frame_ids_left;
	delete [] frame_ids_selected;
}
Beispiel #6
0
void Mediator::nextStep()
{
	DWORD tm = GetTickCount();
	prevImage = curImage;
	DWORD tm1 = GetTickCount();

	bitmap *bitMap = frameReader.nextFrame();
	Picture basePic(width, height, 3);
	basePic.copyPic(bitMap->data);

	basePic = picConverter.fixDistortions(converter, basePic);
	Picture smallGreyPic = picConverter.convertColor(basePic);
	if (downscale > 1.05)
	{
		smallGreyPic = picConverter.downscale(smallGreyPic, downscale);
	}
	Picture curImage1 = smallGreyPic;//.getRectMiddle(0);// - gauss.apply(smallGreyPic);/*gauss.apply(smallGreyPic);*/
	Capture_Log::getInstance()->log_write("Preprocess time is %d\n", GetTickCount() - tm1);

	Homography h**o = homoEstimator.getHomography(prevImage.getWidth() != 0 ? prevImage : curImage1, curImage1, stepSize);
	h**o.applyDownscale(1.0 / (double)downscale);

	Homography clearHomo = kalmanHomo.observe(h**o);
	
	
	Matrix clearHomoMatrix = clearHomo.getHomoMatrix3x3();
	Matrix clHomoObr = clearHomoMatrix.obratn();
	Matrix homoMatr = h**o.getHomoMatrix3x3();
	Matrix HnoiseMatr = clHomoObr * homoMatr;

	Capture_Log::getInstance()->log_write("\n\n\n");
	Capture_Log::getInstance()->log_write("Estimated h**o is\n");
	h**o.printLog();

	Capture_Log::getInstance()->log_write("Kalman h**o is\n");
	clearHomo.printLog();

	Capture_Log::getInstance()->log_write("Kalman obratn h**o is\n");
	dif_lib::print(clHomoObr);

	Capture_Log::getInstance()->log_write("Noise h**o is\n");
	dif_lib::print(HnoiseMatr);

//	curHomo = Homography(HnoiseMatr);
	Capture_Log::getInstance()->log_write("Check base h**o is\n");
	dif_lib::print(clearHomoMatrix * HnoiseMatr);
	curHomo.printLog();
	Capture_Log::getInstance()->log_write("\n\n\n");
	
	

/*	Homography homoE = Homography();
	curHomo = homoE * beta1 + h**o * alpha1 + curHomo * (1 - alpha1 - beta1);*/

//	curImage = curImage1;
	curImage = picConverter.applyHomo(curImage1, curHomo);

	if (prevPic.getWidth() == 0)
	{
		prevPic = basePic.clone();
	}
	Gaussian gs(width, height, 2.0);
	if (0 && params.debug && bitMap->data && prevPic.getWidth() > 0)
	{
//		Capture_Log::getInstance()->log_write("Gaussian full time is %d\n", GetTickCount() - tm);
		static int frameId = 0;
		char name1[11] = "filea.jpeg";
		char name2[12] = "fileaa.jpeg";
		name1[4] += frameId;
		name2[4] += frameId;
		frameId++;
/*		Picture pic0 = gs.apply(prevPic);
		Picture pic1 = picConverter.applyHomo(basePic, h**o);
		Picture pic = gs.apply(pic1);
		double dist = tester.imgDistace(pic0.getPictureChar(), pic.getPictureChar(), 3);*/
		frameReader.saveFrame(curImage1.getPictureChar(), smallGreyPic.getWidth(), smallGreyPic.getHeight(), smallGreyPic.getColors(), name1);
/*		frameReader.saveFrame(pic.getPictureChar(), width, height, 3, name2);
		Capture_Log::getInstance()->log_write("Pictures distance is %.2f\n", dist);*/
	}

//	Picture img = gs.apply(basePic);
	tm1 = GetTickCount();
	convImage = picConverter.applyHomo(basePic, curHomo);
	Capture_Log::getInstance()->log_write("H**o time is %d\n", GetTickCount() - tm1);
	tm1 = GetTickCount();
//	convImage = gauss.apply(convImage);
	Capture_Log::getInstance()->log_write("Gauss time is %d\n", GetTickCount() - tm1);

	if (params.debug)
	{
		laplas = basePic.clone();//picConverter.convertGrey(curImage1/* - gs.apply(curImage1)*/, 3);//convImage;// - gs.apply(convImage);
	}
	else
	{
		laplas = convImage;
	}


	tm1 = GetTickCount();
	Picture rect = convImage.getRectMiddle(bandWidth);
	frameReader.saveFrame(rect.getPictureChar(), rect.getWidth(), rect.getHeight(), 3);
	
/*	rect = basePic.getRectMiddle(bandWidth);
	frameReader.saveFrame(rect.getPictureChar(), rect.getWidth(), rect.getHeight(), 3);*/

	Capture_Log::getInstance()->log_write("Save time is %d\n", GetTickCount() - tm1);

//	prevPic = basePic.clone();
	bitmap_release(bitMap);
	Capture_Log::getInstance()->log_write("Step time is %d\n\n\n", GetTickCount() - tm);
}
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);

  }
}
Beispiel #8
0
const Picture& Road::picture( const city::AreaInfo& areaInfo) const
{
  if( areaInfo.city.isNull() )
    return Picture::getInvalid();

  Tilemap& tmap = areaInfo.city->tilemap();
  int directionFlags = 0;  // bit field, N=1, E=2, S=4, W=8
  if (!areaInfo.tiles().empty())
  {
    for( auto tile : areaInfo.tiles() )
    {
      const TilePos& epos = tile->epos();

      if( tile->getFlag( Tile::tlRoad ) || tile->overlay().is<Road>() )
      {
        const TilePos& p = areaInfo.pos;
        if( epos == p.northnb() ) directionFlags |= road2north; // road to the north
        else if ( epos == p.southnb() ) directionFlags |= road2south; // road to the south
        else if ( epos == p.eastnb() ) directionFlags |= road2east; // road to the east
        else if ( epos == p.westnb() ) directionFlags |= road2west; // road to the west
      }
    }
  }

  TilesArray roads;
  if( areaInfo.city.isValid() )
    roads = tmap.getNeighbors( areaInfo.pos, Tilemap::FourNeighbors );

  for( auto tile : roads )
  {
    const TilePos& epos = tile->epos();
    const TilePos& p = areaInfo.pos;
    if( tile->getFlag( Tile::tlRoad ) || tile->overlay().is<Road>() )
    {
      if      (epos.j() > p.j()) { directionFlags |= road2north; } // road to the north
      else if (epos.j() < p.j()) { directionFlags |= road2south; } // road to the south
      else if (epos.i() > p.i()) { directionFlags |= road2east; } // road to the east
      else if (epos.i() < p.i()) { directionFlags |= road2west; } // road to the west
    }
  }

  const TilePos& p = areaInfo.pos;
  if( areaInfo.city.isValid() )
  {
    int mapBorder = tmap.size()-1;
    if( p.i() == 0 )         { directionFlags |= road2west; }
    if( p.i() == mapBorder ) { directionFlags |= road2east; }
    if( p.j() == 0 )         { directionFlags |= road2south; }
    if( p.j() == mapBorder ) { directionFlags |= road2north; }
  }

  int index=0;
  if( _paved == 0 )
  {
    switch (directionFlags)
    {
    case 0: index = 101; break; // no road!
    case 1: // North
    {
      index = 101;
      _changeIndexIfAqueduct( areaInfo, index, 120 );
    }
    break;
    case 2: // East
    {
      index = 102;
      _changeIndexIfAqueduct( areaInfo, index, 119 );
    }
    break;
    case 4: // South
    {
      index = 103;
      _changeIndexIfAqueduct( areaInfo, index, 120 );
    }
    break;
    case 8: // West
    {
      index = 104;
      _changeIndexIfAqueduct( areaInfo, index, 119 );
    }
    break;
    case 3: index = 97;  break; // North+East
    case 5: // 93/95 // North+South
    {
      index = 93+2*((p.i() + p.j()) % 2);
      _changeIndexIfAqueduct( areaInfo, index, 120);
    }
    break;
    case 6: index = 98;  break; // East+South
    case 7: index = 106; break; // North+East+South
    case 9: index = 100; break; // North+West
    case 10: // 94/96 // East+West
    {
      index = 94+2*((p.i() + p.j())%2);
      _changeIndexIfAqueduct( areaInfo, index, 119);
    }
    break;
    case 11: index = 109; break; // North+East+West
    case 12: index = 99; break;  // South+West
    case 13: index = 108; break; // North+South+West
    case 14: index = 107; break; // East+South+West
    case 15: index = 110; break; // North+East+South+West
    }
  }
  else
  {
    switch (directionFlags)
    {
    case 0: index = 52; break; // no road!
    case 1: index = 52+4*((p.i() + p.j())%2); break; // North
    case 2: index = 53; break; // East
    case 4: index = 54; break; // South
    case 8: index = 55; break; // West
    case 3: index = 48;  break; // North+East
    case 5: index = 44+2*((p.i() + p.j())%2); break;  // 93/95 // North+South
    case 6: index = 49;  break; // East+South
    case 9: index = 51; break; // North+West
    case 10: index = 45+2*((p.i() + p.j())%2); break;  // 94/96 // East+West
    case 12: index = 50; break;  // South+West

    case 7: index = 57; break;
    case 11: index = 60; break;
    case 13: index = 59; break;
    case 14: index = 58; break;
      //index = 78 + (p.i() + p.j()) % 14; break;

    case 15: index = 61; break;
    }
  }

  static Picture ret;
  ret.load( ResourceGroup::road, index);

  return ret;
}
Beispiel #9
0
void LoaderHelper::decodeTerrain( Tile &oTile, PlayerCityPtr city, unsigned int forceId )
{
  int changeId = 0;
  unsigned int imgId = oTile.originalImgId();
  object::Type ovType = object::unknown;
  if( oTile.getFlag( Tile::tlRoad ) )   // road
  {
    ovType = object::road;
    Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) );
    oTile.setPicture( pic );
    changeId = imgid::fromResource( pic.name() );
  }
  else if( oTile.getFlag( Tile::tlTree ) )
  {
    ovType = object::tree;
    Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) );
    oTile.setPicture( pic );
    changeId = imgid::fromResource( pic.name() );
  }
  else if( oTile.getFlag( Tile::tlMeadow ) )
  {
    /*bool oldgfx = !SETTINGS_VALUE( c3gfx ).toString().empty();
    oldgfx |= SETTINGS_VALUE( oldgfx ).toBool();
    if( !oldgfx )
    {
      Picture pic = MetaDataHolder::randomPicture( objects::meadow, Size(1) );
      oTile.setPicture( pic );
      changeId = imgid::fromResource( pic.name() );
    }*/
  } 
  else if( imgId >= 0x29c && imgId <= 0x2a1 ) //aqueduct
  {
    ovType = object::aqueduct;
    Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) );
    oTile.setPicture( pic );
    oTile.setFlag( Tile::clearAll, true );
    changeId = imgid::fromResource( pic.name() );
  }
  else if( imgId >= 372 && imgId <= 427 )
  {
    oTile.setFlag( Tile::tlCoast, true );
    if( imgId >= 388 )
      oTile.setFlag( Tile::tlRubble, true );
  }
  else if( imgId >= 863 && imgId <= 870 )
  {
    Picture pic = MetaDataHolder::randomPicture( object::terrain, Size(1) );
    oTile.setPicture( pic );
    oTile.setFlag( Tile::clearAll, true );    
    changeId = imgid::fromResource( pic.name() );
    oTile.setOriginalImgId( changeId );
  }
  else
  {
    unsigned id = forceId > 0 ? forceId : oTile.originalImgId();
    ovType = convImgId2ovrType( id );
  }

  if( ovType == object::unknown )
    return;

  OverlayPtr overlay; // This is the overlay object, if any
  overlay = TileOverlayFactory::instance().create( ovType );
  if( ovType == object::elevation )
  {
    std::string elevationPicName = imgid::toResource( oTile.originalImgId() );
    overlay->setPicture( Picture( elevationPicName ) );
  }

  if( overlay != NULL )
  {
    //Logger::warning( "Building at ( %d, %d ) with ID: %x", oTile.i(), oTile.j(), oTile.originalImgId() );
    if( oTile.overlay().isValid() )
      return;

    city::AreaInfo info( city, oTile.pos() );
    overlay->build( info );
    city->addOverlay( overlay );
  }  

  if( changeId > 0 )
  {
    oTile.setOriginalImgId( changeId );
  }
}