[Hdrflow-svn] SF.net SVN: hdrflow: [80] lib/openlibraries/src
Status: Pre-Alpha
Brought to you by:
glslang
|
From: <gl...@us...> - 2007-04-13 22:04:27
|
Revision: 80
http://hdrflow.svn.sourceforge.net/hdrflow/?rev=80&view=rev
Author: glslang
Date: 2007-04-13 15:04:25 -0700 (Fri, 13 Apr 2007)
Log Message:
-----------
+ bug fixes
Modified Paths:
--------------
lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.cpp
lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.opl
lib/openlibraries/src/openimagelib/il/utility.cpp
lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp
Modified: lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.cpp
===================================================================
--- lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.cpp 2007-04-13 10:28:42 UTC (rev 79)
+++ lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.cpp 2007-04-13 22:04:25 UTC (rev 80)
@@ -36,7 +36,6 @@
typedef il::image_type::size_type size_type;
#ifdef HAVE_OPENEXR
-
// From ILM OpenEXR examples.
float knee (double x, double f)
{ return float( Imath::Math<double>::log( x * f + 1 ) / f ); }
@@ -110,7 +109,7 @@
return ( unsigned char ) ( v + d[ y & 3 ][ x & 3 ] );
}
- void compute_fog_color( const image_type_ptr& im, int bs, float& fog_r, float& fog_g, float& fog_b )
+ void compute_fog_color( const image_type_ptr& im, float& fog_r, float& fog_g, float& fog_b )
{
fog_r = fog_g = fog_b = 0.0f;
@@ -119,7 +118,7 @@
{
for( int j = 0; j < im->width( ); ++j )
{
- for( int k = 0; k < bs; ++k )
+ for( int k = 0; k < 3; ++k )
{
half h;
@@ -137,49 +136,36 @@
fog_b /= im->width( ) * im->height( );
}
- image_type_ptr convert_to_half( const image_type_ptr& im, int& bs )
+ image_type_ptr convert_to_half( const image_type_ptr& im )
{
- typedef il::image<unsigned char, il::r16g16b16f> r16g16b16f_image_type;
- typedef il::image<unsigned char, il::r16g16b16a16f> r16g16b16a16f_image_type;
-
- if( !( im->pf( ) == L"r32g32b32f" || im->pf( ) == L"r32g32b32a32f" ) )
- {
- if( im->pf( ) == L"r16g16b16f" )
- bs = 3;
- else if( im->pf( ) == L"r16g16b16a16f" )
- bs = 4;
-
+ if( im->pf( ) == L"r16g16b16f" )
return im;
- }
- image_type_ptr new_im;
- if( im->pf( ) == L"r32g32b32f" )
- {
- new_im = il::allocate( L"r16g16b16f", im->width( ), im->height( ) );
- bs = 3;
- }
- else if( im->pf( ) == L"r32g32b32a32f" )
- {
- new_im = il::allocate( L"r16g16b16a16f", im->width( ), im->height( ) );
- bs = 4;
- }
+ size_type width = im->width( );
+ size_type height = im->height( );
- image_type::const_pointer src_im = im->data( );
- image_type::pointer dst_im = new_im->data( );
+ image_type_ptr new_im = il::allocate( L"r16g16b16f", im->width( ), im->height( ) );
+
+ image_type::const_pointer src = im->data( );
+ image_type::pointer dst = new_im->data( );
- int f_block_inc = sizeof( float ) * bs;
- int i_block_inc = sizeof( unsigned short ) * bs;
+ int src_pitch = ( im->pitch( ) - im->linesize( ) ) * sizeof( float );
+ int dst_pitch = ( new_im->pitch( ) - new_im->linesize( ) ) * sizeof( unsigned short );
- for( int i = 0; i < im->height( ); ++i )
+ for( int i = 0; i < height; ++i )
{
- for( int j = 0; j < im->width( ); ++j )
+ for( int j = 0; j < width; ++j )
{
- for( int k = 0; k < bs; ++k )
- ( ( unsigned short* ) dst_im )[ k ] = Imf::floatToHalf( ( ( const float* ) src_im )[ k ] ).bits( );
-
- src_im += f_block_inc;
- dst_im += i_block_inc;
+ ( ( unsigned short* ) dst )[ 0 ] = Imf::floatToHalf( ( ( const float* ) src )[ 0 ] ).bits( );
+ ( ( unsigned short* ) dst )[ 1 ] = Imf::floatToHalf( ( ( const float* ) src )[ 1 ] ).bits( );
+ ( ( unsigned short* ) dst )[ 2 ] = Imf::floatToHalf( ( ( const float* ) src )[ 2 ] ).bits( );
+
+ src += 3 * sizeof( float );
+ dst += 3 * sizeof( unsigned short );
}
+
+ src += src_pitch;
+ dst += dst_pitch;
}
return new_im;
@@ -187,53 +173,55 @@
image_type_ptr tm_ilm_exr( const image_type_ptr& im, float exposure, float defog, float kneeLow, float kneeHigh )
{
- if( !( im->pf( ) == L"r16g16b16f" ||
- im->pf( ) == L"r16g16b16a16f" ||
- im->pf( ) == L"r32g32b32f" ||
- im->pf( ) == L"r32g32b32a32f" ) )
- return image_type_ptr( );
+ image_type_ptr dst_img = im;
+
+ if( im->pf( ) == L"r16g16b16f" || im->pf( ) == L"r32g32b32f" )
+ {
+ image_type_ptr half_im = convert_to_half( im );
- int bs;
- image_type_ptr half_im = convert_to_half( im, bs );
+ float fog_r, fog_g, fog_b;
+ compute_fog_color( half_im, fog_r, fog_g, fog_b );
- float fog_r, fog_g, fog_b;
- compute_fog_color( half_im, bs, fog_r, fog_g, fog_b );
+ halfFunction<float> r_gamma( gamma( exposure, defog * fog_r, kneeLow, kneeHigh ), -HALF_MAX, HALF_MAX );
+ halfFunction<float> g_gamma( gamma( exposure, defog * fog_g, kneeLow, kneeHigh ), -HALF_MAX, HALF_MAX );
+ halfFunction<float> b_gamma( gamma( exposure, defog * fog_b, kneeLow, kneeHigh ), -HALF_MAX, HALF_MAX );
- halfFunction<float> r_gamma( gamma( exposure, defog * fog_r, kneeLow, kneeHigh ), -HALF_MAX, HALF_MAX );
- halfFunction<float> g_gamma( gamma( exposure, defog * fog_g, kneeLow, kneeHigh ), -HALF_MAX, HALF_MAX );
- halfFunction<float> b_gamma( gamma( exposure, defog * fog_b, kneeLow, kneeHigh ), -HALF_MAX, HALF_MAX );
+ size_type width = im->width( );
+ size_type height = im->height( );
- image_type_ptr new_im;
- if( bs == 3 )
- new_im = il::allocate( L"r8g8b8", im->width( ), im->height( ) );
- else if( bs == 4 )
- new_im = il::allocate( L"r8g8b8a8", im->width( ), im->height( ) );
+ dst_img = il::allocate( L"b8g8r8a8", width, height );
- image_type::const_pointer src_im = half_im->data( );
- image_type::pointer dst_im = new_im->data( );
+ image_type::const_pointer src = half_im->data( );
+ image_type::pointer dst = dst_img->data( );
- for( int i = 0; i < new_im->height( ); ++i )
- {
- for( int j = 0; j < new_im->width( ); ++j )
+ size_type src_pitch = ( half_im->pitch( ) - half_im->linesize( ) ) * sizeof( unsigned short );
+ size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
+
+ for( int i = 0; i < height; ++i )
{
- for( int k = 0; k < bs; ++k )
+ for( int j = 0; j < width; ++j )
{
- half h;
-
- h.setBits( ( ( unsigned short* ) src_im )[ 0 ] );
-
- *dst_im = dither( r_gamma( h ), j, i );
-
- src_im += sizeof( unsigned short );
- dst_im += sizeof( unsigned char );
+ half h0, h1, h2;
+
+ h0.setBits( ( ( unsigned short* ) src )[ 0 ] ); src += sizeof( unsigned short );
+ h1.setBits( ( ( unsigned short* ) src )[ 0 ] ); src += sizeof( unsigned short );
+ h2.setBits( ( ( unsigned short* ) src )[ 0 ] ); src += sizeof( unsigned short );
+
+ *dst++ = dither( r_gamma( h2 ), j, i );
+ *dst++ = dither( g_gamma( h1 ), j, i );
+ *dst++ = dither( b_gamma( h0 ), j, i );
+ *dst++ = 255;
}
+
+ src += src_pitch;
+ dst += dst_pitch;
}
}
- return new_im;
+ return dst_img;
}
-
#endif
+
// Ferwerda et al TVI functions.
float tp( float L )
{
Modified: lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.opl
===================================================================
--- lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.opl 2007-04-13 10:28:42 UTC (rev 79)
+++ lib/openlibraries/src/openeffectslib/plugins/tonemap/tonemap_plugin.opl 2007-04-13 22:04:25 UTC (rev 80)
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<openlibraries version="1.0">
<!-- plugins go here -->
- <openeffectslib name="oel" version="0.1.0">
- <plugin name="OpenLibraries tonemap plugin" type="filter" extension='"tm_linear", "tm_ilm_exr". "tm_ferwerda"' merit="0" filename='"libopeneffectslib_tonemap.so", "libopeneffectslib_tonemap.dylib", "openeffectslib_tonemap-vc80-d-0_4_0.dll", "openeffectslib_tonemap-vc80-r-0_4_0.dll"'/>
- </openeffectslib>
+ <openmedialib name="oel" version="0.1.0">
+ <plugin name="OpenLibraries tonemap plugin" type="filter" extension='"tm_linear", "tm_ilm_exr", "tm_ferwerda"' merit="0" filename='"libopeneffectslib_tonemap.so", "libopeneffectslib_tonemap.dylib", "openeffectslib_tonemap-vc80-d-0_4_0.dll", "openeffectslib_tonemap-vc80-r-0_4_0.dll"'/>
+ </openmedialib>
</openlibraries>
Modified: lib/openlibraries/src/openimagelib/il/utility.cpp
===================================================================
--- lib/openlibraries/src/openimagelib/il/utility.cpp 2007-04-13 10:28:42 UTC (rev 79)
+++ lib/openlibraries/src/openimagelib/il/utility.cpp 2007-04-13 22:04:25 UTC (rev 80)
@@ -1853,7 +1853,7 @@
return dst_img;
}
-// Free function to truncate 32-bit float to b8g8r8a8. intention is to perform all tonemaps at the float level and convert to 8-bit only if needed.
+// Truncates 32-bit float to b8g8r8a8. The intention is to perform all tonemaps at the float level and convert to 8-bit only when needed.
// Assumes normalise( im, 255.0f ) has already been called.
static image_type_ptr r32g32b32f_to_b8g8r8a8( image_type_ptr src_img, const std::wstring &format )
{
@@ -1877,9 +1877,9 @@
{
while( width-- )
{
+ *( dst + 2 ) = static_cast<unsigned char>( *src++ );
+ *( dst + 1 ) = static_cast<unsigned char>( *src++ );
*( dst + 0 ) = static_cast<unsigned char>( *src++ );
- *( dst + 1 ) = static_cast<unsigned char>( *src++ );
- *( dst + 2 ) = static_cast<unsigned char>( *src++ );
*( dst + 3 ) = 255;
dst += 4;
Modified: lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp
===================================================================
--- lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp 2007-04-13 10:28:42 UTC (rev 79)
+++ lib/openlibraries/src/openimagelib/plugins/exr/exr_plugin.cpp 2007-04-13 22:04:25 UTC (rev 80)
@@ -22,11 +22,6 @@
void destroy( il::image_type* im )
{ delete im; }
- std::wstring exr_image_type_to_image_type( )
- {
- return L"r32g32b32f";
- }
-
il::image_type_ptr load_exr( const fs::path& path )
{
Imf::RgbaInputFile file( path.native_file_string( ).c_str( ) );
@@ -41,21 +36,17 @@
file.setFrameBuffer( &exr_texels[ 0 ][ 0 ], 1, width );
file.readPixels( dw.min.y, dw.max.y );
- il::image_type_ptr im = il::allocate( exr_image_type_to_image_type( ), width, height );
+ il::image_type_ptr im = il::allocate( L"r32g32b32f", width, height );
il::image_type::pointer texels = im->data( );
for( int j = 0; j < height; ++j )
{
for( int i = 0; i < width; ++i )
{
- half h0 = exr_texels[ j ][ i ].r;
- half h1 = exr_texels[ j ][ i ].g;
- half h2 = exr_texels[ j ][ i ].b;
-
- ( ( float* ) texels )[ 0 ] = ImfHalfToFloat( ( ImfHalf ) h0 );
- ( ( float* ) texels )[ 1 ] = ImfHalfToFloat( ( ImfHalf ) h1 );
- ( ( float* ) texels )[ 2 ] = ImfHalfToFloat( ( ImfHalf ) h2 );
-
+ ( ( float* ) texels )[ 0 ] = exr_texels[ j ][ i ].r;
+ ( ( float* ) texels )[ 1 ] = exr_texels[ j ][ i ].g;
+ ( ( float* ) texels )[ 2 ] = exr_texels[ j ][ i ].b;
+
texels += 3 * sizeof( float );
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|