Revision: 312
http://hdrflow.svn.sourceforge.net/hdrflow/?rev=312&view=rev
Author: glslang
Date: 2007-09-23 06:00:10 -0700 (Sun, 23 Sep 2007)
Log Message:
-----------
+ adds proper rescaling of viewport image
Modified Paths:
--------------
trunk/app/HDRFlow/Viewer.cpp
Modified: trunk/app/HDRFlow/Viewer.cpp
===================================================================
--- trunk/app/HDRFlow/Viewer.cpp 2007-09-23 12:08:24 UTC (rev 311)
+++ trunk/app/HDRFlow/Viewer.cpp 2007-09-23 13:00:10 UTC (rev 312)
@@ -11,12 +11,63 @@
namespace
{
- void calculate_dimensions( ml::frame_type_ptr frame, int& phy_w, int& phy_h, int& req_w, int& req_h )
+ void calculate_dimensions( ml::frame_type_ptr frame, float zoom_level, int& phy_w, int& phy_h, int& req_w, int& req_h )
{
+ il::image_type_ptr im = frame->get_image( );
+
+ float ar = frame->aspect_ratio( );
+ phy_w = im->width( );
+ phy_h = im->height( );
+
+ req_h = phy_h;
+ req_w = int( req_h * ar );
+ req_h = int( zoom_level * req_h );
+ req_w = int( zoom_level * req_w );
}
- void paint_image( il::image_type_ptr im, int width, int height )
+ void calculate_geometry( int req_w, int req_h, int view_width, int view_height, float zoom_level, int& x, int& y, int& width, int& height )
{
+ float ar = float( req_w ) / float( req_h );
+ if( view_height * ar <= view_width )
+ {
+ width = int( view_height * ar );
+ height = view_height;
+ }
+ else
+ {
+ width = view_width;
+ height = int( view_width / ar );
+ }
+
+ if( width < view_width )
+ {
+ x = ( view_width - width ) / 2;
+ }
+ else
+ {
+ x = int( ( view_width - width ) / 2 );
+ if( x < 0 && width + x < view_width )
+ x = view_width - width;
+ if( x > 0 )
+ x = 0;
+ }
+
+ if( height < view_height )
+ {
+ y = ( view_height - height ) / 2;
+ }
+ else
+ {
+ y = int( ( view_height - height ) / 2 );
+ if( y < 0 && height + y < view_height )
+ y = view_width - height;
+ if( y > 0 )
+ y = 0;
+ }
+ }
+
+ void paint_image( il::image_type_ptr im, int width, int height, int x, int y, int mw, int mh )
+ {
int phy_w = im->width( );
int phy_h = im->height( );
@@ -49,8 +100,10 @@
glTexParameteri( target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
glTexImage2D( target, 0, internal_format, phy_w, phy_h, 0, format, type, im->data( ) );
- float off_x = width * 0.5f - phy_w * 0.5f;
- float off_y = height * 0.5f - phy_h * 0.5f;
+ float off_x = x;
+ float off_y = y;
+ float req_w = mw;
+ float req_h = mh;
glMatrixMode( GL_PROJECTION );
glPushMatrix( );
@@ -61,7 +114,11 @@
glPushMatrix( );
glLoadIdentity( );
- glTranslatef( off_x, off_y, 0.0f );
+ glTranslatef( off_x, height - off_y - req_h, 0.0f );
+
+ float sw = req_w / phy_w;
+ float sh = req_h / phy_h;
+ glScalef( sw, sh, 1.0f );
if( !im->is_flipped( ) )
{
@@ -127,7 +184,15 @@
il::image_type_ptr im = media->get_image( );
if( !im ) return;
- paint_image( im, width, height );
+ int phy_w, phy_h;
+ int req_w, req_h;
+ int x, y;
+ int mw, mh;
+
+ calculate_dimensions( media->frame( ), 1.0f, phy_w, phy_h, req_w, req_h );
+ calculate_geometry( req_w, req_h, width, height, 1.0f, x, y, mw, mh );
+
+ paint_image( im, width, height, x, y, mw, mh );
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|