Revision: 128
http://hdrflow.svn.sourceforge.net/hdrflow/?rev=128&view=rev
Author: glslang
Date: 2007-05-19 11:42:13 -0700 (Sat, 19 May 2007)
Log Message:
-----------
+ proper VM olibs merge
Modified Paths:
--------------
lib/openlibraries/src/openimagelib/il/utility.cpp
Modified: lib/openlibraries/src/openimagelib/il/utility.cpp
===================================================================
--- lib/openlibraries/src/openimagelib/il/utility.cpp 2007-05-19 17:38:22 UTC (rev 127)
+++ lib/openlibraries/src/openimagelib/il/utility.cpp 2007-05-19 18:42:13 UTC (rev 128)
@@ -73,6 +73,44 @@
lut[ i ] = static_cast<unsigned short>( floorf( val + 0.5f ) );
}
}
+
+ void float2rgbe( float red, float green, float blue, unsigned char rgbe[ 4 ] )
+ {
+ float v = red;
+ if( v < green ) v = green;
+ if( v < blue ) v = blue;
+
+ if( v < ( std::numeric_limits<float>::min )( ) )
+ {
+ rgbe[ 0 ] = rgbe[ 1 ] = rgbe[ 2 ] = rgbe[ 3 ] = 0;
+ }
+ else
+ {
+ int exponent;
+ v = frexp( v, &exponent ) * 256.0f / v;
+
+ rgbe[ 0 ] = static_cast<unsigned char>( red * v );
+ rgbe[ 1 ] = static_cast<unsigned char>( green * v );
+ rgbe[ 2 ] = static_cast<unsigned char>( blue * v );
+ rgbe[ 3 ] = static_cast<unsigned char>( exponent + 128 );
+ }
+ }
+
+ void rgbe2float( unsigned char rgbe[ 4 ], float& red, float& green, float& blue )
+ {
+ if( rgbe[ 3 ] )
+ {
+ float f = ldexp( 1.0f, rgbe[ 3 ] - ( 128 + 8 ) );
+
+ red = rgbe[ 0 ] * f;
+ green = rgbe[ 1 ] * f;
+ blue = rgbe[ 2 ] * f;
+ }
+ else
+ {
+ red = green = blue = 0.0f;
+ }
+ }
}
// The following private functions are a bit rough and shouldn't be exposed publicly
@@ -115,6 +153,7 @@
typedef image< unsigned char, r16g16b16a16log > r16g16b16a16log_image_type;
typedef image< unsigned char, r32g32b32f > r32g32b32f_image_type;
typedef image< unsigned char, r32g32b32a32f > r32g32b32a32f_image_type;
+typedef image< unsigned char, rgbe > rgbe_image_type;
typedef image< unsigned char, yuv444p > yuv444p_image_type;
typedef image< unsigned char, yuv444 > yuv444_image_type;
typedef image< unsigned char, yuv422 > yuv422_image_type;
@@ -195,6 +234,8 @@
dst_img = image_type_ptr( new image_type( r32g32b32f_image_type( width, height, 1 ) ) );
else if( pf == L"r32g32b32a32f" )
dst_img = image_type_ptr( new image_type( r32g32b32a32f_image_type( width, height, 1 ) ) );
+ else if( pf == L"rgbe" )
+ dst_img = image_type_ptr( new image_type( rgbe_image_type( width, height, 1 ) ) );
else if ( pf == L"yuv444p" )
dst_img = image_type_ptr( new image_type( yuv444p_image_type( width, height, 1 ) ) );
else if ( pf == L"yuv444" )
@@ -1509,7 +1550,6 @@
*( dst + 2 ) = static_cast<unsigned char>( opl::fast_floorf( *src++ ) );
*( dst + 1 ) = static_cast<unsigned char>( opl::fast_floorf( *src++ ) );
*( dst + 0 ) = static_cast<unsigned char>( opl::fast_floorf( *src++ ) );
-
*( dst + 3 ) = 255;
dst += 4;
@@ -1524,6 +1564,80 @@
return dst_img;
}
+static image_type_ptr rgbe_to_r32g32b32f( image_type_ptr src_img, const std::wstring &format )
+{
+ size_type width = src_img->width( );
+ size_type height = src_img->height( );
+
+ image_type_ptr dst_img = allocate( src_img, format );
+ if( dst_img != 0 )
+ {
+ pointer src = src_img->data( );
+ size_type src_pitch = src_img->pitch( );
+ float* dst = ( float* ) dst_img->data( );
+ size_type dst_pitch = dst_img->pitch( );
+
+ pointer sptr = src;
+ float* dptr = dst;
+
+ size_type orig_width = width;
+
+ while( height-- )
+ {
+ while( width-- )
+ {
+ rgbe2float( src, *( dst + 0 ), *( dst + 1 ), *( dst + 2 ) );
+
+ dst += 3;
+ src += 4;
+ }
+
+ dst = dptr += dst_pitch;
+ src = sptr += src_pitch;
+ width = orig_width;
+ }
+ }
+
+ return dst_img;
+}
+
+static image_type_ptr r32g32b32f_to_rgbe( image_type_ptr src_img, const std::wstring &format )
+{
+ size_type width = src_img->width( );
+ size_type height = src_img->height( );
+
+ image_type_ptr dst_img = allocate( src_img, format );
+ if( dst_img != 0 )
+ {
+ float* src = ( float* )src_img->data( );
+ size_type src_pitch = src_img->pitch( );
+ pointer dst = dst_img->data( );
+ size_type dst_pitch = dst_img->pitch( );
+
+ float* sptr = src;
+ pointer dptr = dst;
+
+ size_type orig_width = width;
+
+ while( height-- )
+ {
+ while( width-- )
+ {
+ float2rgbe( *( src + 0 ), *( src + 1 ), *( src + 2 ), dst );
+
+ dst += 4;
+ src += 3;
+ }
+
+ dst = dptr += dst_pitch;
+ src = sptr += src_pitch;
+ width = orig_width;
+ }
+ }
+
+ return dst_img;
+}
+
inline bool is_rgb_packed( const std::wstring &pf )
{
return pf == L"a8b8g8r8" || pf == L"a8r8g8b8" || pf == L"b8g8r8" || pf == L"b8g8r8a8" || pf == L"r8g8b8" || pf == L"r8g8b8a8";
@@ -1798,6 +1912,13 @@
else if( dst_pf == L"ldr8" ) // stub colour space for straight truncation to LDR data.
return r32g32b32f_to_b8g8r8a8( src, L"b8g8r8a8" );
}
+ else if( src_pf == L"rgbe" )
+ {
+ if( dst_pf == L"b8g8r8a8" )
+ return tm_linear( rgbe_to_r32g32b32f( src, L"r32g32b32f" ) );
+ else if( dst_pf == L"r32g32b32f" )
+ return rgbe_to_r32g32b32f( src, L"r32g32b32f" );
+ }
else if ( src_pf == L"yuv444" )
{
if ( dst_pf == L"r8g8b8" )
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|