Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » Draw, Display, Images, Bitmaps, Icons » Image: Rescale proportional propose:
Image: Rescale proportional propose: [message #26946] Fri, 11 June 2010 16:44 Go to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello All,


I propose to add 2 function in ImageScale (draw package) file:
Image RescaleProportional(Image &p_image, Size &p_rsz){
	if(!p_image)
		return Image();
	
	Size v_isz = p_image.GetSize();
	Size v_fsz = p_rsz;
	bool v_resize = false;
	
	v_fsz.cy = v_isz.cy * p_rsz.cx / v_isz.cx; // rescale proportional by x
	v_fsz.cx = v_isz.cx * p_rsz.cy / v_isz.cy; // rescale proportional by y
	
	if((v_isz.cx == p_rsz.cx)&&(v_isz.cy <= p_rsz.cy)||(v_isz.cy == p_rsz.cy)&&(v_isz.cx <= p_rsz.cx)){
		// the image do not need to rescale!
		v_resize = false;
	}else if(v_fsz.cx > p_rsz.cx){ // adjust x, y already rescaled by x
		v_fsz.cx = p_rsz.cx;
		v_resize = true;
	}else if (v_fsz.cy > p_rsz.cy){ // adjust y, x already rescaled by y
		v_resize = true;
		v_fsz.cy = p_rsz.cy;
	}else // check if after rescale the size is same as p_rsz
		v_resize = ((v_fsz.cx == p_rsz.cx)||(v_fsz.cy == p_rsz.cy));
	
	if(v_resize){
		ImageRaster v_isrc(p_image);
		ImageEncoder v_m;
		Rescale(v_m, fsz, v_isrc, isz);
		return v_m;
	}else
		return Image(p_image);
}

Image RescaleProportionalMax(Image &p_image, Size &p_rsz){
	if(!p_image)
		return Image();
	
	Size v_isz = p_image.GetSize();
	
	if((v_isz.cx<=p_rsz.cx)&&(v_isz.cy<=p_rsz.cy)){
		return Image(p_image);
	}
	
	return RescaleProportional(p_image, p_rsz);
}


Best regards, Ion Lupascu (tojocky)
Re: Image: Rescale proportional propose: [message #26947 is a reply to message #26946] Fri, 11 June 2010 17:12 Go to previous message
sergeynikitin is currently offline  sergeynikitin
Messages: 748
Registered: January 2008
Location: Moscow, Russia
Contributor

Let see there:
http://www.ultimatepp.org/forum/index.php?t=msg&goto=240 43&&srch=PropRescale#msg_24043

In my opinion Mirek gave an elegant solution.


SergeyNikitin<U++>( linux, wine )
{
    under( Ubuntu || Debian || Raspbian );
}

[Updated on: Fri, 11 June 2010 17:14]

Report message to a moderator

Previous Topic: TopWindow content to image
Next Topic: Some simple way to convert Image into 1bpp raw data in memory?
Goto Forum:
  


Current Time: Fri Mar 29 15:37:21 CET 2024

Total time taken to generate the page: 0.02445 seconds