[Hdrflow-svn] SF.net SVN: hdrflow: [127] lib/openlibraries
Status: Pre-Alpha
Brought to you by:
glslang
|
From: <gl...@us...> - 2007-05-19 17:38:24
|
Revision: 127
http://hdrflow.svn.sourceforge.net/hdrflow/?rev=127&view=rev
Author: glslang
Date: 2007-05-19 10:38:22 -0700 (Sat, 19 May 2007)
Log Message:
-----------
+ installer updates
+ merge (partial) with VM olibs
Modified Paths:
--------------
lib/openlibraries/installer/openlibraries_runtime.nsi
lib/openlibraries/installer/openlibraries_sdk.nsi
lib/openlibraries/src/openimagelib/il/utility.cpp
lib/openlibraries/src/openimagelib/il/utility.hpp
lib/openlibraries/src/openimagelib/il/yuv_traits.hpp
lib/openlibraries/src/openmedialib/ml/utilities.hpp
Removed Paths:
-------------
lib/openlibraries/installer/msxml4.msi
Deleted: lib/openlibraries/installer/msxml4.msi
===================================================================
(Binary files differ)
Modified: lib/openlibraries/installer/openlibraries_runtime.nsi
===================================================================
--- lib/openlibraries/installer/openlibraries_runtime.nsi 2007-05-19 16:37:10 UTC (rev 126)
+++ lib/openlibraries/installer/openlibraries_runtime.nsi 2007-05-19 17:38:22 UTC (rev 127)
@@ -79,9 +79,6 @@
SetOverwrite on
- SetOutPath $INSTDIR
- File "msxml4.msi"
-
SetOutPath $INSTDIR\bin
File "..\src\openpluginlib\pl\Multi-threaded Release DLL\openpluginlib_pl-vc80-r-0_4_0.dll"
File "..\src\openimagelib\il\Multi-threaded Release DLL\openimagelib_il-vc80-r-0_4_0.dll"
@@ -198,14 +195,6 @@
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenLibraries" "DisplayName" "OpenLibraries"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenLibraries" "UninstallString" "$INSTDIR\uninst-openlibraries.exe"
- SetDetailsPrint textonly
- DetailPrint "Installing MSXML4..."
- SetDetailsPrint listonly
-
- ExecWait 'MsiExec.exe /qn /x{2AEBE10C-D819-4EBF-BC60-03BF2327D340}' ; uninstall MSXML4 if it's there
- ExecWait 'MsiExec.exe /qn /x{35343FF7-939B-401A-87B3-FF90A5123D88}' ; uninstall MSXML4 SP1 if it's there
- ExecWait 'MsiExec.exe /qn /i "$INSTDIR\msxml4.msi"'
-
SectionEnd
Section -post
Modified: lib/openlibraries/installer/openlibraries_sdk.nsi
===================================================================
--- lib/openlibraries/installer/openlibraries_sdk.nsi 2007-05-19 16:37:10 UTC (rev 126)
+++ lib/openlibraries/installer/openlibraries_sdk.nsi 2007-05-19 17:38:22 UTC (rev 127)
@@ -79,9 +79,6 @@
SetOverwrite on
- SetOutPath $INSTDIR
- File "msxml4.msi"
-
SetOutPath $INSTDIR\include\openlibraries-${VERSION}\openpluginlib\pl
File ..\src\openpluginlib\pl\allocatorstringstorage.h
File ..\src\openpluginlib\pl\bind_info.hpp
@@ -368,15 +365,7 @@
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenLibraries" "DisplayName" "OpenLibraries"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OpenLibraries" "UninstallString" "$INSTDIR\uninst-openlibraries.exe"
-
- SetDetailsPrint textonly
- DetailPrint "Installing MSXML4..."
- SetDetailsPrint listonly
- ExecWait 'MsiExec.exe /qn /x{2AEBE10C-D819-4EBF-BC60-03BF2327D340}' ; uninstall MSXML4 if it's there
- ExecWait 'MsiExec.exe /qn /x{35343FF7-939B-401A-87B3-FF90A5123D88}' ; uninstall MSXML4 SP1 if it's there
- ExecWait 'MsiExec.exe /qn /i "$INSTDIR\msxml4.msi"'
-
SectionEnd
Section -post
Modified: lib/openlibraries/src/openimagelib/il/utility.cpp
===================================================================
--- lib/openlibraries/src/openimagelib/il/utility.cpp 2007-05-19 16:37:10 UTC (rev 126)
+++ lib/openlibraries/src/openimagelib/il/utility.cpp 2007-05-19 17:38:22 UTC (rev 127)
@@ -73,44 +73,6 @@
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
@@ -153,7 +115,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;
typedef image< unsigned char, yuv422p > yuv422p_image_type;
@@ -233,8 +195,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" )
dst_img = image_type_ptr( new image_type( yuv444_image_type( width, height, 1 ) ) );
else if ( pf == L"yuv422" )
@@ -398,234 +360,263 @@
return result;
}
-static image_type_ptr rgb_to_yuv444( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
+static image_type_ptr yuvp_to_yuvp( const 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 )
{
- int y, u, v;
+ for ( int plane = 0; plane < 3; plane ++ )
+ {
+ size_type src_width = src_img->width( plane );
+ size_type src_height = src_img->height( plane );
- const_pointer src = src_img->data( );
- size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
- pointer dst = dst_img->data( );
- size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
+ size_type dst_width = dst_img->width( plane );
+ size_type dst_height = dst_img->height( plane );
- size_type orig_width = width;
+ const_pointer src = src_img->data( plane );
+ pointer dst = dst_img->data( plane );
- while( height -- )
- {
- width = orig_width;
+ size_type src_pitch = src_img->pitch( plane );
+ size_type dst_pitch = dst_img->pitch( plane );
+ size_type dst_rem = dst_pitch - dst_width;
- while( width -- )
+ if ( dst_width == src_width && dst_height == src_height )
{
- rgb24_to_yuv444( y, u, v, *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- *dst ++ = ( unsigned char )y;
- *dst ++ = ( unsigned char )u;
- *dst ++ = ( unsigned char )v;
+ while( dst_height -- )
+ {
+ memcpy( dst, src, dst_width );
+ dst += dst_pitch;
+ src += src_pitch;
+ }
}
+ else
+ {
+ size_type x_factor = ( src_width << 8 ) / dst_width;
+ size_type y_factor = ( src_height << 8 ) / dst_height;
- dst += dst_pitch;
- src += src_pitch;
+ for ( size_type y = 0; y < dst_height; y ++ )
+ {
+ const_pointer line = src + ( ( y * y_factor ) >> 8 ) * src_pitch;
+
+ for ( size_type x = 0; x < dst_width; x ++ )
+ *dst ++ = line[ ( x * x_factor ) >> 8 ];
+
+ dst += dst_rem;
+ }
+ }
}
}
return dst_img;
}
-static image_type_ptr yuv444_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
+static image_type_ptr yuvp_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
{
- 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 )
{
- int rgb[ 4 ] = { 255, 255, 255, 255 };
+ size_type dst_width = dst_img->width( );
+ size_type dst_height = dst_img->height( );
+
+ size_type chroma_width = src_img->width( 1 );
+ size_type chroma_height = src_img->height( 1 );
- const_pointer src = src_img->data( );
- size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+ size_type x_factor = ( chroma_width << 8 ) / dst_width;
+ size_type y_factor = ( chroma_height << 8 ) / dst_height;
+
pointer dst = dst_img->data( );
- size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
+ size_type dst_rem = dst_img->pitch( ) - dst_img->linesize( );
- size_type orig_width = width;
+ int rgb[ 4 ] = { 255, 255, 255, 255 };
+ int uv_offset;
- while( height -- )
+ for ( int y = 0; y < dst_height; y ++ )
{
- while( width -- )
+ const_pointer Y = src_img->data( 0 ) + ( y * src_img->pitch( 0 ) );
+ const_pointer U = src_img->data( 1 ) + ( ( y * y_factor ) >> 8 ) * src_img->pitch( 1 );
+ const_pointer V = src_img->data( 2 ) + ( ( y * y_factor ) >> 8 ) * src_img->pitch( 2 );
+
+ if ( a == -1 )
{
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src + 1 ), *( src + 2 ) );
- src += 3;
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
+ for ( int x = 0; x < dst_width; x ++ )
+ {
+ uv_offset = ( x * x_factor ) >> 8;
+ yuv444_to_rgb24( rgb[ r ], rgb[ g ], rgb[ b ], *Y ++, U[ uv_offset ], V[ uv_offset ] );
+ *dst ++ = ( unsigned char )( rgb[ 0 ] );
+ *dst ++ = ( unsigned char )( rgb[ 1 ] );
+ *dst ++ = ( unsigned char )( rgb[ 2 ] );
+ }
}
+ else
+ {
+ for ( int x = 0; x < dst_width; x ++ )
+ {
+ uv_offset = ( x * x_factor ) >> 8;
+ yuv444_to_rgb24( rgb[ r ], rgb[ g ], rgb[ b ], *Y ++, U[ uv_offset ], V[ uv_offset ] );
+ *dst ++ = ( unsigned char )( rgb[ 0 ] );
+ *dst ++ = ( unsigned char )( rgb[ 1 ] );
+ *dst ++ = ( unsigned char )( rgb[ 2 ] );
+ *dst ++ = ( unsigned char )( rgb[ 3 ] );
+ }
+ }
- dst += dst_pitch;
- src += src_pitch;
- width = orig_width;
+ dst += dst_rem;
}
}
return dst_img;
}
-static image_type_ptr rgb_to_yuv422( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
+static image_type_ptr rgb_to_yuvp( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
{
- 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 )
{
- int y[ 2 ], u[ 2 ], v[ 2 ];
+ size_type dst_width = dst_img->width( );
+ size_type dst_height = dst_img->height( );
+
+ size_type chroma_width = dst_img->width( 1 );
+ size_type chroma_height = dst_img->height( 1 );
+ size_type src_width = src_img->width( );
+ size_type src_height = src_img->height( );
+
+ size_type x_factor = ( chroma_width << 8 ) / src_width;
+ size_type y_factor = ( chroma_height << 8 ) / src_height;
+
const_pointer src = src_img->data( );
- size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
- pointer dst = dst_img->data( );
- size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
+ size_type src_rem = src_img->pitch( ) - src_img->linesize( );
- size_type orig_width = width;
+ int uv_offset;
- while( height -- )
+ int yuv[ 3 ];
+ int components = a == -1 ? 3 : 4;
+
+ for ( int y = 0; y < dst_height; y ++ )
{
- width = orig_width;
+ pointer Y = dst_img->data( 0 ) + ( y * dst_img->pitch( 0 ) );
+ pointer U = dst_img->data( 1 ) + ( ( y * y_factor ) >> 8 ) * dst_img->pitch( 1 );
+ pointer V = dst_img->data( 2 ) + ( ( y * y_factor ) >> 8 ) * dst_img->pitch( 2 );
- while( width > 1 )
+ for ( int x = 0; x < dst_width; x ++ )
{
- rgb24_to_yuv444( y[ 0 ], u[ 0 ], v[ 0 ], *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- rgb24_to_yuv444( y[ 1 ], u[ 1 ], v[ 1 ], *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- *dst ++ = ( unsigned char )y[ 0 ];
- *dst ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] ) >> 1 );
- *dst ++ = ( unsigned char )y[ 1 ];
- *dst ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] ) >> 1 );
- width -= 2;
+ uv_offset = ( x * x_factor ) >> 8;
+ rgb24_to_yuv444( yuv[ 0 ], yuv[ 1 ], yuv[ 2 ], src[ r ], src[ g ], src[ b ] );
+ *Y ++ = ( unsigned char )yuv[ 0 ];
+ U[ uv_offset ] = ( unsigned char )yuv[ 1 ];
+ V[ uv_offset ] = ( unsigned char )yuv[ 2 ];
+ src += components;
}
- dst += dst_pitch;
- src += src_pitch;
+ src += src_rem;
}
}
return dst_img;
}
-static image_type_ptr yuv422_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
+static image_type_ptr yuvp_to_yuv422( const 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 )
{
- int rgb[ 4 ] = { 255, 255, 255, 255 };
+ size_type dst_width = dst_img->width( ) / 2;
+ size_type dst_height = dst_img->height( );
+
+ size_type chroma_width = src_img->width( 1 );
+ size_type chroma_height = src_img->height( 1 );
- const_pointer src = src_img->data( );
- size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+ size_type x_factor = ( chroma_width << 8 ) / dst_width;
+ size_type y_factor = ( chroma_height << 8 ) / dst_height;
+
pointer dst = dst_img->data( );
- size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
+ size_type dst_rem = dst_img->pitch( ) - dst_img->linesize( );
- size_type orig_width = width;
+ int uv_offset;
- while( height -- )
+ for ( int y = 0; y < dst_height; y ++ )
{
- while( width > 1 )
+ const_pointer Y = src_img->data( 0 ) + ( y * src_img->pitch( 0 ) );
+ const_pointer U = src_img->data( 1 ) + ( ( y * y_factor ) >> 8 ) * src_img->pitch( 1 );
+ const_pointer V = src_img->data( 2 ) + ( ( y * y_factor ) >> 8 ) * src_img->pitch( 2 );
+
+ for ( int x = 0; x < dst_width; x ++ )
{
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src + 1 ), *( src + 3 ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- src += 2;
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src - 1 ), *( src + 1 ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- src += 2;
- width -= 2;
+ uv_offset = ( x * x_factor ) >> 8;
+ *dst ++ = ( unsigned char )( *Y ++ );
+ *dst ++ = ( unsigned char )( U[ uv_offset ] );
+ *dst ++ = ( unsigned char )( *Y ++ );
+ *dst ++ = ( unsigned char )( V[ uv_offset ] );
}
- dst += dst_pitch;
- src += src_pitch;
- width = orig_width;
+ dst += dst_rem;
}
}
return dst_img;
}
-static image_type_ptr yuv444_to_yuv420p( const image_type_ptr &src_img, const std::wstring &format )
+static image_type_ptr yuv422_to_yuvp( const 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 )
{
- const_pointer src = src_img->data( );
- size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
- size_type pitch = src_img->pitch( );
+ for ( int p = 0; p < 3; p ++ )
+ {
+ size_type dst_width = dst_img->width( p );
+ size_type dst_height = dst_img->height( p );
- pointer dst[ 3 ];
- size_type rem_pitch[ 3 ];
+ pointer dst = dst_img->data( p );
+ size_type dst_rem = dst_img->pitch( p ) - dst_img->linesize( p );
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 1 );
- dst[ 2 ] = dst_img->data( 2 );
+ size_type src_height = src_img->height( );
- rem_pitch[ 0 ] = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- rem_pitch[ 1 ] = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
- rem_pitch[ 2 ] = dst_img->pitch( 2 ) - dst_img->linesize( 2 );
+ size_type y_factor = ( src_height << 8 ) / dst_height;
- size_type orig_width = width / 2;
-
- while( height -- )
- {
- width = orig_width;
-
- while( width -- )
+ if ( p == 0 )
{
- if ( height % 2 == 1 )
+ for ( int y = 0; y < dst_height; y ++ )
{
- ( *dst[ 0 ] ++ ) = *src ++;
- ( *dst[ 1 ] ++ ) = ( src[ 0 ] + src[ 3 ] + src[ pitch ] + src[ pitch + 3 ] ) >> 2;
- ( *dst[ 2 ] ++ ) = ( src[ 1 ] + src[ 4 ] + src[ pitch + 1 ] + src[ pitch + 4 ] ) >> 2;
- src += 2;
- ( *dst[ 0 ] ++ ) = *src ++;
- src += 2;
+ const_pointer line = src_img->data( ) + ( y * src_img->pitch( ) );
+
+ for ( int x = 0; x < dst_width; x ++ )
+ {
+ *dst ++ = ( unsigned char )( *line );
+ line += 2;
+ }
+
+ dst += dst_rem;
}
- else
+ }
+ else
+ {
+ int uv_offset = 1 + ( p - 1 ) * 2;
+
+ size_type src_width = src_img->width( );
+ size_type x_factor = ( src_width << 8 ) / dst_width;
+
+ for ( int y = 0; y < dst_height; y ++ )
{
- ( *dst[ 0 ] ++ ) = *src;
- src += 3;
- ( *dst[ 0 ] ++ ) = *src;
- src += 3;
+ const_pointer line = src_img->data( ) + ( ( ( y * y_factor ) >> 8 ) * src_img->pitch( ) );
+
+ for ( int x = 0; x < dst_width; x ++ )
+ *dst ++ = ( unsigned char )( line[ 4 * ( ( x * x_factor ) >> 9 ) + uv_offset ] );
+
+ dst += dst_rem;
}
}
-
- dst[ 0 ] += rem_pitch[ 0 ];
- dst[ 1 ] += rem_pitch[ 1 ];
- dst[ 2 ] += rem_pitch[ 2 ];
- src += src_pitch;
}
}
return dst_img;
}
-static image_type_ptr yuv444_to_yuv422( const image_type_ptr &src_img, const std::wstring &format )
+static image_type_ptr yuv422_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -634,111 +625,44 @@
if ( dst_img != 0 )
{
+ int rgb[ 4 ] = { 255, 255, 255, 255 };
+
const_pointer src = src_img->data( );
size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
-
pointer dst = dst_img->data( );
size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
- size_type orig_width = width / 2;
+ size_type orig_width = width;
while( height -- )
{
- width = orig_width;
-
- while( width -- )
+ while( width > 1 )
{
- *dst ++ = src[ 0 ];
- *dst ++ = ( src[ 1 ] + src[ 4 ] ) >> 1;
- *dst ++ = src[ 3 ];
- *dst ++ = ( src[ 2 ] + src[ 5 ] ) >> 1;
- src += 6;
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src + 1 ), *( src + 3 ) );
+ *dst ++ = ( unsigned char )rgb[ r ];
+ *dst ++ = ( unsigned char )rgb[ g ];
+ *dst ++ = ( unsigned char )rgb[ b ];
+ if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
+ src += 2;
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src - 1 ), *( src + 1 ) );
+ *dst ++ = ( unsigned char )rgb[ r ];
+ *dst ++ = ( unsigned char )rgb[ g ];
+ *dst ++ = ( unsigned char )rgb[ b ];
+ if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
+ src += 2;
+ width -= 2;
}
dst += dst_pitch;
src += src_pitch;
- }
- }
-
- return dst_img;
-}
-
-static image_type_ptr yuv422_to_yuv420p( const 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 )
- {
- size_type src_pitch = src_img->pitch( );
- const_pointer src[ 2 ];
- src[ 0 ] = src_img->data( );
- src[ 1 ] = src_img->data( ) + src_pitch;
-
- const_pointer sptr[ 2 ];
- sptr[ 0 ] = src[ 0 ];
- sptr[ 1 ] = src[ 1 ];
-
- pointer dst[ 4 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 0 ) + dst_img->pitch( 0 );
- dst[ 2 ] = dst_img->data( 1 );
- dst[ 3 ] = dst_img->data( 2 );
-
- size_type dst_pitch[ 4 ];
- dst_pitch[ 0 ] = 2 * dst_img->pitch( 0 );
- dst_pitch[ 1 ] = 2 * dst_img->pitch( 0 );
- dst_pitch[ 2 ] = dst_img->pitch( 1 );
- dst_pitch[ 3 ] = dst_img->pitch( 2 );
-
- pointer dptr[ 4 ];
- dptr[ 0 ] = dst[ 0 ];
- dptr[ 1 ] = dst[ 1 ];
- dptr[ 2 ] = dst[ 2 ];
- dptr[ 3 ] = dst[ 3 ];
-
- // TODO: Fix this for uneven width and/or height
- size_type orig_width = width / 2;
- height /= 2;
-
- while( height -- )
- {
width = orig_width;
-
- src[ 0 ] = sptr[ 0 ];
- src[ 1 ] = sptr[ 1 ];
-
- dst[ 0 ] = dptr[ 0 ];
- dst[ 1 ] = dptr[ 1 ];
- dst[ 2 ] = dptr[ 2 ];
- dst[ 3 ] = dptr[ 3 ];
-
- while( width -- )
- {
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 1 ] ++ );
- *( dst[ 2 ] ++ ) = ( *( src[ 0 ] ++ ) + *( src[ 1 ] ++ ) ) >> 1;
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 1 ] ++ );
- *( dst[ 3 ] ++ ) = ( *( src[ 0 ] ++ ) + *( src[ 1 ] ++ ) ) >> 1;
- }
-
- sptr[ 0 ] += src_pitch << 1;
- sptr[ 1 ] += src_pitch << 1;
-
- dptr[ 0 ] += dst_pitch[ 0 ];
- dptr[ 1 ] += dst_pitch[ 1 ];
- dptr[ 2 ] += dst_pitch[ 2 ];
- dptr[ 3 ] += dst_pitch[ 3 ];
}
}
return dst_img;
}
-static image_type_ptr rgb_to_yuv422p( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
+static image_type_ptr rgb_to_yuv422( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -751,20 +675,12 @@
const_pointer src = src_img->data( );
size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+ pointer dst = dst_img->data( );
+ size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
- pointer dst[ 3 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 1 );
- dst[ 2 ] = dst_img->data( 2 );
-
- size_type dst_pitch[ 3 ];
- dst_pitch[ 0 ] = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- dst_pitch[ 1 ] = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
- dst_pitch[ 2 ] = dst_img->pitch( 2 ) - dst_img->linesize( 2 );
-
size_type orig_width = width;
- while( height > 1 )
+ while( height -- )
{
width = orig_width;
@@ -774,169 +690,117 @@
src += bytes;
rgb24_to_yuv444( y[ 1 ], u[ 1 ], v[ 1 ], *( src + r ), *( src + g ), *( src + b ) );
src += bytes;
-
- *dst[ 0 ] ++ = ( unsigned char )y[ 0 ];
- *dst[ 0 ] ++ = ( unsigned char )y[ 1 ];
-
- *dst[ 1 ] ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] ) >> 1 );
- *dst[ 2 ] ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] ) >> 1 );
-
+ *dst ++ = ( unsigned char )y[ 0 ];
+ *dst ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] ) >> 1 );
+ *dst ++ = ( unsigned char )y[ 1 ];
+ *dst ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] ) >> 1 );
width -= 2;
}
+ dst += dst_pitch;
src += src_pitch;
-
- dst[ 0 ] += dst_pitch[ 0 ];
- dst[ 1 ] += dst_pitch[ 1 ];
- dst[ 2 ] += dst_pitch[ 2 ];
-
- height --;
}
}
return dst_img;
}
-static image_type_ptr yuv422p_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
+static image_type_ptr yuvp_to_yuv444( const 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 )
{
- int rgb[ 4 ] = { 255, 255, 255, 255 };
+ size_type dst_width = dst_img->width( );
+ size_type dst_height = dst_img->height( );
+
+ size_type chroma_width = src_img->width( 1 );
+ size_type chroma_height = src_img->height( 1 );
- const_pointer src[ 3 ];
- src[ 0 ] = src_img->data( 0 );
- src[ 1 ] = src_img->data( 1 );
- src[ 2 ] = src_img->data( 2 );
+ size_type x_factor = ( chroma_width << 8 ) / dst_width;
+ size_type y_factor = ( chroma_height << 8 ) / dst_height;
- size_type src_pitch[ 3 ];
- src_pitch[ 0 ] = src_img->pitch( 0 ) - src_img->linesize( 0 );
- src_pitch[ 1 ] = src_img->pitch( 1 ) - src_img->linesize( 1 );
- src_pitch[ 2 ] = src_img->pitch( 2 ) - src_img->linesize( 2 );
-
- size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
-
pointer dst = dst_img->data( );
+ size_type dst_rem = dst_img->pitch( ) - dst_img->linesize( );
- size_type orig_width = width;
+ int uv_offset;
- while( height > 1 )
+ for ( int y = 0; y < dst_height; y ++ )
{
- while( width > 1 )
- {
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src[ 0 ] ), *( src[ 1 ] ), *( src[ 2 ] ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- src[ 0 ] += 1;
+ const_pointer Y = src_img->data( 0 ) + ( y * src_img->pitch( 0 ) );
+ const_pointer U = src_img->data( 1 ) + ( ( y * y_factor ) >> 8 ) * src_img->pitch( 1 );
+ const_pointer V = src_img->data( 2 ) + ( ( y * y_factor ) >> 8 ) * src_img->pitch( 2 );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src[ 0 ] ), *( src[ 1 ] ), *( src[ 2 ] ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- src[ 0 ] += 1;
-
- src[ 1 ] += 1;
- src[ 2 ] += 1;
-
- width -= 2;
+ for ( int x = 0; x < dst_width; x ++ )
+ {
+ uv_offset = ( x * x_factor ) >> 8;
+ *dst ++ = ( unsigned char )( *Y ++ );
+ *dst ++ = ( unsigned char )( U[ uv_offset ] );
+ *dst ++ = ( unsigned char )( V[ uv_offset ] );
}
- src[ 0 ] += src_pitch[ 0 ];
- src[ 1 ] += src_pitch[ 1 ];
- src[ 2 ] += src_pitch[ 2 ];
-
- dst += dst_pitch;
-
- width = orig_width;
- height --;
+ dst += dst_rem;
}
}
return dst_img;
}
-static image_type_ptr rgb_to_yuv420p( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
+static image_type_ptr yuv444_to_yuvp( const 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 )
{
- int y[ 4 ], u[ 4 ], v[ 4 ];
+ for ( int p = 0; p < 3; p ++ )
+ {
+ size_type dst_width = dst_img->width( p );
+ size_type dst_height = dst_img->height( p );
- const_pointer src[ 2 ];
- src[ 0 ] = src_img->data( );
- src[ 1 ] = src_img->data( ) + src_img->pitch( );
- size_type src_pitch = 2 * src_img->pitch( ) - src_img->linesize( );
+ pointer dst = dst_img->data( p );
+ size_type dst_rem = dst_img->pitch( p ) - dst_img->linesize( p );
- pointer dst[ 4 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 0 ) + dst_img->pitch( 0 );
- dst[ 2 ] = dst_img->data( 1 );
- dst[ 3 ] = dst_img->data( 2 );
+ size_type src_height = src_img->height( );
- size_type dst_pitch[ 3 ];
- dst_pitch[ 0 ] = 2 * dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- dst_pitch[ 1 ] = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
- dst_pitch[ 2 ] = dst_img->pitch( 2 ) - dst_img->linesize( 2 );
+ size_type y_factor = ( src_height << 8 ) / dst_height;
- size_type orig_width = width;
-
- while( height > 1 )
- {
- width = orig_width;
-
- while( width > 1 )
+ if ( p == 0 )
{
- rgb24_to_yuv444( y[ 0 ], u[ 0 ], v[ 0 ], *( src[ 0 ] + r ), *( src[ 0 ] + g ), *( src[ 0 ] + b ) );
- src[ 0 ] += bytes;
- rgb24_to_yuv444( y[ 1 ], u[ 1 ], v[ 1 ], *( src[ 0 ] + r ), *( src[ 0 ] + g ), *( src[ 0 ] + b ) );
- src[ 0 ] += bytes;
- rgb24_to_yuv444( y[ 2 ], u[ 2 ], v[ 2 ], *( src[ 1 ] + r ), *( src[ 1 ] + g ), *( src[ 1 ] + b ) );
- src[ 1 ] += bytes;
- rgb24_to_yuv444( y[ 3 ], u[ 3 ], v[ 3 ], *( src[ 1 ] + r ), *( src[ 1 ] + g ), *( src[ 1 ] + b ) );
- src[ 1 ] += bytes;
+ for ( int y = 0; y < dst_height; y ++ )
+ {
+ const_pointer line = src_img->data( ) + ( y * src_img->pitch( ) );
+
+ for ( int x = 0; x < dst_width; x ++ )
+ {
+ *dst ++ = ( unsigned char )( *line );
+ line += 3;
+ }
- *dst[ 0 ] ++ = ( unsigned char )y[ 0 ];
- *dst[ 0 ] ++ = ( unsigned char )y[ 1 ];
- *dst[ 1 ] ++ = ( unsigned char )y[ 2 ];
- *dst[ 1 ] ++ = ( unsigned char )y[ 3 ];
-
- *dst[ 2 ] ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] + u[ 2 ] + u[ 3 ] ) >> 2 );
- *dst[ 3 ] ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] + v[ 2 ] + v[ 3 ] ) >> 2 );
-
- width -= 2;
+ dst += dst_rem;
+ }
}
+ else
+ {
+ size_type src_width = src_img->width( );
+ size_type x_factor = ( src_width << 8 ) / dst_width;
- src[ 0 ] += src_pitch;
- src[ 1 ] += src_pitch;
+ for ( int y = 0; y < dst_height; y ++ )
+ {
+ const_pointer line = src_img->data( ) + ( ( ( y * y_factor ) >> 8 ) * src_img->pitch( ) );
- dst[ 0 ] += dst_pitch[ 0 ];
- dst[ 1 ] += dst_pitch[ 0 ];
- dst[ 2 ] += dst_pitch[ 1 ];
- dst[ 3 ] += dst_pitch[ 2 ];
+ for ( int x = 0; x < dst_width; x ++ )
+ *dst ++ = ( unsigned char )( line[ 3 * ( ( x * x_factor ) >> 8 ) + p ] );
- height -= 2;
+ dst += dst_rem;
+ }
+ }
}
}
return dst_img;
}
-typedef unsigned char uchar;
-#define assign3( dst, v1, v2, v3 ) *dst ++ = uchar( v1 ); *dst ++ = uchar( v2 ); *dst ++ = uchar( v3 );
-#define assign4( dst, v1, v2, v3, v4 ) *dst ++ = uchar( v1 ); *dst ++ = uchar( v2 ); *dst ++ = uchar( v3 ); *dst ++ = uchar( v4 );
-
-static image_type_ptr yuv420p_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
+static image_type_ptr rgb_to_yuv444( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -945,139 +809,37 @@
if ( dst_img != 0 )
{
- int rgb[ 4 ] = { 255, 255, 255, 255 };
+ int y, u, v;
- const_pointer src0 = src_img->data( 0 );
- const_pointer src1 = src_img->data( 0 ) + src_img->pitch( 0 );
- const_pointer src2 = src_img->data( 1 );
- const_pointer src3 = src_img->data( 2 );
+ const_pointer src = src_img->data( );
+ size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+ pointer dst = dst_img->data( );
+ size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
- size_type src_pitch0 = 2 * src_img->pitch( 0 ) - src_img->linesize( 0 );
- size_type src_pitch1 = src_img->pitch( 1 ) - src_img->linesize( 1 );
- size_type src_pitch2 = src_img->pitch( 2 ) - src_img->linesize( 2 );
-
- pointer dst0 = dst_img->data( );
- pointer dst1 = dst_img->data( ) + dst_img->pitch( );
-
- size_type dst_pitch = 2 * dst_img->pitch( ) - dst_img->linesize( );
-
size_type orig_width = width;
- unsigned char u, v;
-
- // TODO: Fix the chroma subsampling logic here
- while( height > 1 )
+ while( height -- )
{
- if ( a == -1 )
- {
- while( width > 1 )
- {
- //u = ( *src2 + *( src2 + chroma_pitch ) ) >> 1;
- //v = ( *src3 + *( src3 + chroma_pitch ) ) >> 1;
- u = ( *src2 );
- v = ( *src3 );
+ width = orig_width;
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2, *src3 );
- assign3( dst0, rgb[ r ], rgb[ g ], rgb[ b ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src1 ++, u, v );
- assign3( dst1, rgb[ r ], rgb[ g ], rgb[ b ] );
-
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2 ++, *src3 ++ );
- assign3( dst0, rgb[ r ], rgb[ g ], rgb[ b ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src1 ++, u, v );
- assign3( dst1, rgb[ r ], rgb[ g ], rgb[ b ] );
-
- width -= 2;
- }
-
- if ( width )
- {
- //u = ( *src2 + *( src2 + chroma_pitch ) ) >> 1;
- //v = ( *src3 + *( src3 + chroma_pitch ) ) >> 1;
- u = ( *src2 );
- v = ( *src3 );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2 ++, *src3 ++ );
- assign3( dst0, rgb[ r ], rgb[ g ], rgb[ b ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src1 ++, u, v );
- assign3( dst1, rgb[ r ], rgb[ g ], rgb[ b ] );
- }
- }
- else
+ while( width -- )
{
- while( width > 1 )
- {
- //u = ( *src2 + *( src2 + chroma_pitch ) ) >> 1;
- //v = ( *src3 + *( src3 + chroma_pitch ) ) >> 1;
- u = ( *src2 );
- v = ( *src3 );
-
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2, *src3 );
- assign4( dst0, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src1 ++, u, v );
- assign4( dst1, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
-
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2 ++, *src3 ++ );
- assign4( dst0, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src1 ++, u, v );
- assign4( dst1, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
-
- width -= 2;
- }
-
- if ( width )
- {
- //u = ( *src2 + *( src2 + chroma_pitch ) ) >> 1;
- //v = ( *src3 + *( src3 + chroma_pitch ) ) >> 1;
- u = ( *src2 );
- v = ( *src3 );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2 ++, *src3 ++ );
- assign4( dst0, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src1 ++, u, v );
- assign4( dst1, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
- }
+ rgb24_to_yuv444( y, u, v, *( src + r ), *( src + g ), *( src + b ) );
+ src += bytes;
+ *dst ++ = ( unsigned char )y;
+ *dst ++ = ( unsigned char )u;
+ *dst ++ = ( unsigned char )v;
}
- src0 += src_pitch0;
- src1 += src_pitch0;
- src2 += src_pitch1;
- src3 += src_pitch2;
-
- dst0 += dst_pitch;
- dst1 += dst_pitch;
-
- width = orig_width;
- height -= 2;
+ dst += dst_pitch;
+ src += src_pitch;
}
-
- if ( height )
- {
- if ( a != -1 )
- {
- while( width -- )
- {
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2, *src3 );
- assign3( dst0, rgb[ r ], rgb[ g ], rgb[ b ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2 ++, *src3 ++ );
- assign3( dst0, rgb[ r ], rgb[ g ], rgb[ b ] );
- }
- }
- else
- {
- while( width -- )
- {
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2, *src3 );
- assign4( dst0, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src2 ++, *src3 ++ );
- assign4( dst0, rgb[ r ], rgb[ g ], rgb[ b ], rgb[ a ] );
- }
- }
- }
}
return dst_img;
}
-static image_type_ptr rgb_to_yuv411( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
+static image_type_ptr yuv444_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -1086,7 +848,7 @@
if ( dst_img != 0 )
{
- int y[ 4 ], u[ 4 ], v[ 4 ];
+ int rgb[ 4 ] = { 255, 255, 255, 255 };
const_pointer src = src_img->data( );
size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
@@ -1097,36 +859,26 @@
while( height -- )
{
- width = orig_width;
-
- while( width > 3 )
+ while( width -- )
{
- rgb24_to_yuv444( y[ 0 ], u[ 0 ], v[ 0 ], *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- rgb24_to_yuv444( y[ 1 ], u[ 1 ], v[ 1 ], *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- rgb24_to_yuv444( y[ 2 ], u[ 2 ], v[ 2 ], *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- rgb24_to_yuv444( y[ 3 ], u[ 3 ], v[ 3 ], *( src + r ), *( src + g ), *( src + b ) );
- src += bytes;
- *dst ++ = ( unsigned char )y[ 0 ];
- *dst ++ = ( unsigned char )y[ 1 ];
- *dst ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] + u[ 2 ] + u[ 3 ] ) >> 2 );
- *dst ++ = ( unsigned char )y[ 2 ];
- *dst ++ = ( unsigned char )y[ 3 ];
- *dst ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] + v[ 2 ] + v[ 3 ] ) >> 2 );
- width -= 4;
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src + 1 ), *( src + 2 ) );
+ src += 3;
+ *dst ++ = ( unsigned char )rgb[ r ];
+ *dst ++ = ( unsigned char )rgb[ g ];
+ *dst ++ = ( unsigned char )rgb[ b ];
+ if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
}
dst += dst_pitch;
src += src_pitch;
+ width = orig_width;
}
}
return dst_img;
}
-static image_type_ptr yuv411_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
+static image_type_ptr yuv444_to_yuv422( const image_type_ptr &src_img, const std::wstring &format )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -1135,53 +887,36 @@
if ( dst_img != 0 )
{
- int rgb[ 4 ] = { 255, 255, 255, 255 };
-
const_pointer src = src_img->data( );
size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+
pointer dst = dst_img->data( );
size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
- size_type orig_width = width;
+ size_type orig_width = width / 2;
while( height -- )
{
- while( width > 3 )
+ width = orig_width;
+
+ while( width -- )
{
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src + 2 ), *( src + 5 ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src + 1 ), *( src + 2 ), *( src + 5 ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src + 3 ), *( src + 2 ), *( src + 5 ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src + 4 ), *( src + 2 ), *( src + 5 ) );
- *dst ++ = ( unsigned char )rgb[ r ];
- *dst ++ = ( unsigned char )rgb[ g ];
- *dst ++ = ( unsigned char )rgb[ b ];
- if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
+ *dst ++ = src[ 0 ];
+ *dst ++ = ( src[ 1 ] + src[ 4 ] ) >> 1;
+ *dst ++ = src[ 3 ];
+ *dst ++ = ( src[ 2 ] + src[ 5 ] ) >> 1;
src += 6;
- width -= 4;
}
dst += dst_pitch;
src += src_pitch;
- width = orig_width;
}
}
return dst_img;
}
-static image_type_ptr rgb_to_yuv411p( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
+static image_type_ptr rgb_to_yuv411( const image_type_ptr &src_img, const std::wstring &format, int bytes, int r, int g, int b )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -1193,21 +928,13 @@
int y[ 4 ], u[ 4 ], v[ 4 ];
const_pointer src = src_img->data( );
- size_type src_pitch = src_img->pitch( ) - src_img->linesize( 0 );
+ size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+ pointer dst = dst_img->data( );
+ size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
- pointer dst[ 3 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 1 );
- dst[ 2 ] = dst_img->data( 2 );
-
- size_type dst_pitch[ 3 ];
- dst_pitch[ 0 ] = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- dst_pitch[ 1 ] = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
- dst_pitch[ 2 ] = dst_img->pitch( 2 ) - dst_img->linesize( 2 );
-
size_type orig_width = width;
- while( height )
+ while( height -- )
{
width = orig_width;
@@ -1221,32 +948,24 @@
src += bytes;
rgb24_to_yuv444( y[ 3 ], u[ 3 ], v[ 3 ], *( src + r ), *( src + g ), *( src + b ) );
src += bytes;
-
- *( dst[ 0 ] ++ ) = ( unsigned char )y[ 0 ];
- *( dst[ 0 ] ++ ) = ( unsigned char )y[ 1 ];
- *( dst[ 0 ] ++ ) = ( unsigned char )y[ 2 ];
- *( dst[ 0 ] ++ ) = ( unsigned char )y[ 3 ];
-
- *dst[ 1 ] ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] + u[ 2 ] + u[ 3 ] ) >> 2 );
- *dst[ 2 ] ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] + v[ 2 ] + v[ 3 ] ) >> 2 );
-
+ *dst ++ = ( unsigned char )y[ 0 ];
+ *dst ++ = ( unsigned char )y[ 1 ];
+ *dst ++ = ( unsigned char )( ( u[ 0 ] + u[ 1 ] + u[ 2 ] + u[ 3 ] ) >> 2 );
+ *dst ++ = ( unsigned char )y[ 2 ];
+ *dst ++ = ( unsigned char )y[ 3 ];
+ *dst ++ = ( unsigned char )( ( v[ 0 ] + v[ 1 ] + v[ 2 ] + v[ 3 ] ) >> 2 );
width -= 4;
}
+ dst += dst_pitch;
src += src_pitch;
-
- dst[ 0 ] += dst_pitch[ 0 ];
- dst[ 1 ] += dst_pitch[ 1 ];
- dst[ 2 ] += dst_pitch[ 2 ];
-
- height --;
}
}
return dst_img;
}
-static image_type_ptr yuv411p_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
+static image_type_ptr yuv411_to_rgb( const image_type_ptr &src_img, const std::wstring &format, int r, int g, int b, int a )
{
size_type width = src_img->width( );
size_type height = src_img->height( );
@@ -1257,60 +976,43 @@
{
int rgb[ 4 ] = { 255, 255, 255, 255 };
- register const_pointer src0 = src_img->data( 0 );
- register const_pointer src1 = src_img->data( 1 );
- register const_pointer src2 = src_img->data( 2 );
-
- register size_type src_pitch0 = src_img->pitch( 0 ) - src_img->linesize( 0 );
- register size_type src_pitch1 = src_img->pitch( 1 ) - src_img->linesize( 1 );
- register size_type src_pitch2 = src_img->pitch( 2 ) - src_img->linesize( 2 );
-
+ const_pointer src = src_img->data( );
+ size_type src_pitch = src_img->pitch( ) - src_img->linesize( );
+ pointer dst = dst_img->data( );
size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
- register pointer dst = dst_img->data( );
-
size_type orig_width = width;
while( height -- )
{
while( width > 3 )
{
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src1, *src2 );
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src, *( src + 2 ), *( src + 5 ) );
*dst ++ = ( unsigned char )rgb[ r ];
*dst ++ = ( unsigned char )rgb[ g ];
*dst ++ = ( unsigned char )rgb[ b ];
if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
-
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src1, *src2 );
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src + 1 ), *( src + 2 ), *( src + 5 ) );
*dst ++ = ( unsigned char )rgb[ r ];
*dst ++ = ( unsigned char )rgb[ g ];
*dst ++ = ( unsigned char )rgb[ b ];
if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
-
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src1, *src2 );
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src + 3 ), *( src + 2 ), *( src + 5 ) );
*dst ++ = ( unsigned char )rgb[ r ];
*dst ++ = ( unsigned char )rgb[ g ];
*dst ++ = ( unsigned char )rgb[ b ];
if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
-
- yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *src0 ++, *src1, *src2 );
+ yuv444_to_rgb24( rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], *( src + 4 ), *( src + 2 ), *( src + 5 ) );
*dst ++ = ( unsigned char )rgb[ r ];
*dst ++ = ( unsigned char )rgb[ g ];
*dst ++ = ( unsigned char )rgb[ b ];
if ( a != -1 ) *dst ++ = ( unsigned char )rgb[ a ];
-
- src1 += 1;
- src2 += 1;
-
+ src += 6;
width -= 4;
}
- src0 += src_pitch0;
- src1 += src_pitch1;
- src2 += src_pitch2;
-
dst += dst_pitch;
-
+ src += src_pitch;
width = orig_width;
}
}
@@ -1318,129 +1020,6 @@
return dst_img;
}
-static image_type_ptr yuv411p_to_yuv444( const 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 )
- {
- register const_pointer src0 = src_img->data( 0 );
- register const_pointer src1 = src_img->data( 1 );
- register const_pointer src2 = src_img->data( 2 );
-
- register size_type src_pitch0 = src_img->pitch( 0 ) - src_img->linesize( 0 );
- register size_type src_pitch1 = src_img->pitch( 1 ) - src_img->linesize( 1 );
- register size_type src_pitch2 = src_img->pitch( 2 ) - src_img->linesize( 2 );
-
- size_type dst_pitch = dst_img->pitch( ) - dst_img->linesize( );
-
- register pointer dst = dst_img->data( );
-
- size_type orig_width = width;
-
- while( height -- )
- {
- while( width > 3 )
- {
- *dst ++ = *src0 ++;
- *dst ++ = *src1;
- *dst ++ = *src2;
-
- *dst ++ = *src0 ++;
- *dst ++ = *src1;
- *dst ++ = *src2;
-
- *dst ++ = *src0 ++;
- *dst ++ = *src1;
- *dst ++ = *src2;
-
- *dst ++ = *src0 ++;
- *dst ++ = *src1;
- *dst ++ = *src2;
-
- src1 += 1;
- src2 += 1;
-
- width -= 4;
- }
-
- src0 += src_pitch0;
- src1 += src_pitch1;
- src2 += src_pitch2;
-
- dst += dst_pitch;
-
- width = orig_width;
- }
- }
-
- return dst_img;
-}
-
-static image_type_ptr yuv411p_to_yuv420p( const 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 )
- {
- register const_pointer src0 = src_img->data( 0 );
- register const_pointer src1 = src_img->data( 1 );
- register const_pointer src2 = src_img->data( 2 );
-
- register size_type src_pitch0 = src_img->pitch( 0 ) - src_img->linesize( 0 );
- register size_type src_pitch1 = ( src_img->pitch( 1 ) - src_img->linesize( 1 ) ) + src_img->pitch( 1 );
- register size_type src_pitch2 = ( src_img->pitch( 2 ) - src_img->linesize( 2 ) ) + src_img->pitch( 2 );
-
- size_type dst_pitch0 = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- size_type dst_pitch1 = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
-
- register pointer dst0 = dst_img->data( 0 );
- register pointer dst1 = dst_img->data( 1 );
- register pointer dst2 = dst_img->data( 2 );
-
- size_type orig_width = width / 4;
-
- while( height -- )
- {
- while( width -- )
- {
- *dst0 ++ = *src0 ++;
- *dst0 ++ = *src0 ++;
- *dst0 ++ = *src0 ++;
- *dst0 ++ = *src0 ++;
- if ( height % 2 == 0 )
- {
- *dst1 ++ = *src1;
- *dst1 ++ = *src1 ++;
- *dst2 ++ = *src2;
- *dst2 ++ = *src2 ++;
- }
- }
-
- src0 += src_pitch0;
- if ( height % 2 == 0 )
- {
- src1 += src_pitch1;
- src2 += src_pitch2;
- }
-
- dst0 += dst_pitch0;
- dst1 += dst_pitch1;
- dst2 += dst_pitch1;
-
- width = orig_width;
- }
- }
-
- return dst_img;
-}
-
struct rgb_map
{
std::wstring from;
@@ -1930,6 +1509,7 @@
*( 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;
@@ -1944,425 +1524,75 @@
return dst_img;
}
-static image_type_ptr rgbe_to_r32g32b32f( image_type_ptr src_img, const std::wstring &format )
+inline bool is_rgb_packed( const std::wstring &pf )
{
- 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;
+ return pf == L"a8b8g8r8" || pf == L"a8r8g8b8" || pf == L"b8g8r8" || pf == L"b8g8r8a8" || pf == L"r8g8b8" || pf == L"r8g8b8a8";
}
-static image_type_ptr r32g32b32f_to_rgbe( image_type_ptr src_img, const std::wstring &format )
+IL_DECLSPEC image_type_ptr convert( const image_type_ptr &src, const std::wstring &dst_pf, int )
{
- size_type width = src_img->width( );
- size_type height = src_img->height( );
+ // Sanity check
+ if ( src == 0 )
+ return src;
- 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( );
+ // Get the format of the source
+ std::wstring src_pf = src->pf( );
- 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;
- }
+ // Convert
+ if ( dst_pf == src_pf )
+ {
+ return src;
}
-
- return dst_img;
-}
-
-static image_type_ptr yuv420p_to_yuv411p( const 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 )
+ else if ( is_yuv_planar( src ) && is_yuv_planar( dst_pf ) )
{
- const_pointer src[ 3 ];
- src[ 0 ] = src_img->data( 0 );
- src[ 1 ] = src_img->data( 1 );
- src[ 2 ] = src_img->data( 2 );
-
- size_type src_rem[ 3 ];
- src_rem[ 0 ] = src_img->pitch( 0 ) - src_img->linesize( 0 );
- src_rem[ 1 ] = ( src_img->pitch( 1 ) - src_img->linesize( 1 ) );
- src_rem[ 2 ] = ( src_img->pitch( 2 ) - src_img->linesize( 2 ) );
-
- pointer dst[ 3 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 1 );
- dst[ 2 ] = dst_img->data( 2 );
-
- memset( dst[ 0 ], 128, ( int )dst_img->size( ) );
-
- size_type dst_rem[ 3 ];
- dst_rem[ 0 ] = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- dst_rem[ 1 ] = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
- dst_rem[ 2 ] = dst_img->pitch( 2 ) - dst_img->linesize( 2 );
-
- size_type orig_width = width / 4;
-
- while( height -- )
- {
- width = orig_width;
-
- while( width -- )
- {
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 1 ] ++ );
- src[ 1 ] ++;
- *( dst[ 2 ] ++ ) = *( src[ 2 ] ++ );
- src[ 2 ] ++;
- }
-
- dst[ 0 ] += dst_rem[ 0 ];
- src[ 0 ] += src_rem[ 0 ];
- dst[ 1 ] += dst_rem[ 1 ];
- dst[ 2 ] += dst_rem[ 2 ];
- if ( height % 2 )
- {
- src[ 1 ] += src_rem[ 1 ];
- src[ 2 ] += src_rem[ 2 ];
- }
- else
- {
- src[ 1 ] -= src_img->linesize( 1 );
- src[ 2 ] -= src_img->linesize( 2 );
- }
- }
+ return yuvp_to_yuvp( src, dst_pf );
}
-
- return dst_img;
-}
-
-static image_type_ptr yuv420p_to_yuv422( const 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 )
+ else if ( is_yuv_planar( src ) && dst_pf == L"yuv422" )
{
- const_pointer src[ 3 ];
- src[ 0 ] = src_img->data( 0 );
- src[ 1 ] = src_img->data( 1 );
- src[ 2 ] = src_img->data( 2 );
-
- size_type src_pitch[ 3 ];
- src_pitch[ 0 ] = src_img->pitch( 0 );
- src_pitch[ 1 ] = src_img->pitch( 1 );
- src_pitch[ 2 ] = src_img->pitch( 2 );
-
- pointer dst = dst_img->data( );
- size_type dst_pitch = dst_img->pitch( );
-
- const_pointer sptr[ 3 ];
- sptr[ 0 ] = src[ 0 ];
- sptr[ 1 ] = src[ 1 ];
- sptr[ 2 ] = src[ 2 ];
-
- pointer dptr = dst;
-
- size_type orig_width = width / 2;
-
- while( height )
- {
- width = orig_width;
- dst = dptr;
- src[ 0 ] = sptr[ 0 ];
- src[ 1 ] = sptr[ 1 ];
- src[ 2 ] = sptr[ 2 ];
-
- while( width > 1 )
- {
- *dst ++ = *( src[ 0 ] ++ );
- *dst ++ = *( src[ 1 ] ++ );
- *dst ++ = *( src[ 0 ] ++ );
- *dst ++ = *( src[ 2 ] ++ );
-
- *dst ++ = *( src[ 0 ] ++ );
- *dst ++ = *( src[ 1 ] ++ );
- *dst ++ = *( src[ 0 ] ++ );
- *dst ++ = *( src[ 2 ] ++ );
-
- width -= 2;
- }
-
- dptr += dst_pitch;
- sptr[ 0 ] += src_pitch[ 0 ];
- if ( height % 2 )
- {
- sptr[ 1 ] += src_pitch[ 1 ];
- sptr[ 2 ] += src_pitch[ 2 ];
- }
-
- height --;
- }
+ return yuvp_to_yuv422( src, dst_pf );
}
-
- return dst_img;
-}
-
-static image_type_ptr yuv420p_to_yuv422p( const 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 )
+ else if ( is_yuv_planar( src ) && dst_pf == L"yuv444" )
{
- const_pointer src[ 3 ];
- src[ 0 ] = src_img->data( 0 );
- src[ 1 ] = src_img->data( 1 );
- src[ 2 ] = src_img->data( 2 );
-
- size_type src_rem[ 3 ];
- src_rem[ 0 ] = src_img->pitch( 0 ) - src_img->linesize( 0 );
- src_rem[ 1 ] = src_img->pitch( 1 ) - src_img->linesize( 1 );
- src_rem[ 2 ] = src_img->pitch( 2 ) - src_img->linesize( 2 );
-
- pointer dst[ 5 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 1 );
- dst[ 2 ] = dst_img->data( 1 ) + dst_img->pitch( 1 );
- dst[ 3 ] = dst_img->data( 2 );
- dst[ 4 ] = dst_img->data( 2 ) + dst_img->pitch( 2 );
-
- size_type dst_rem[ 5 ];
- dst_rem[ 0 ] = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- dst_rem[ 1 ] = 2 * dst_img->pitch( 1 ) - dst_img->linesize( 1 );
- dst_rem[ 2 ] = 2 * dst_img->pitch( 2 ) - dst_img->linesize( 2 );
-
- size_type orig_width = width / 2;
-
- while( height -- )
- {
- width = orig_width;
-
- while( width -- )
- {
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 1 ] );
- *( dst[ 2 ] ++ ) = *( src[ 1 ] ++ );
- *( dst[ 3 ] ++ ) = *( src[ 2 ] );
- *( dst[ 4 ] ++ ) = *( src[ 2 ] ++ );
- }
-
- dst[ 0 ] += dst_rem[ 0 ];
- dst[ 1 ] += dst_rem[ 1 ];
- dst[ 2 ] += dst_rem[ 1 ];
- dst[ 3 ] += dst_rem[ 2 ];
- dst[ 4 ] += dst_rem[ 2 ];
- src[ 0 ] += src_rem[ 0 ];
- src[ 1 ] += src_rem[ 1 ];
- src[ 2 ] += src_rem[ 2 ];
- }
+ return yuvp_to_yuv444( src, dst_pf );
}
-
- return dst_img;
-}
-
-static image_type_ptr yuv422p_to_yuv420p( const 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 )
+ else if ( is_yuv_planar( src ) && is_rgb_packed( dst_pf ) )
{
- const_pointer src[ 3 ];
- src[ 0 ] = src_img->data( 0 );
- src[ 1 ] = src_img->data( 1 );
- src[ 2 ] = src_img->data( 1 ) + src_img->pitch( 1 );
-
- size_type src_rem[ 2 ];
- src_rem[ 0 ] = src_img->pitch( 0 ) - src_img->linesize( 0 );
- src_rem[ 1 ] = 2 * src_img->pitch( 1 ) - src_img->linesize( 1 );
-
- pointer dst[ 2 ];
- dst[ 0 ] = dst_img->data( 0 );
- dst[ 1 ] = dst_img->data( 1 );
-
- size_type dst_rem[ 2 ];
- dst_rem[ 0 ] = dst_img->pitch( 0 ) - dst_img->linesize( 0 );
- dst_rem[ 1 ] = dst_img->pitch( 1 ) - dst_img->linesize( 1 );
-
- size_type orig_width = width / 2;
-
- while( height -- )
- {
- width = orig_width;
-
- while( width -- )
- {
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 1 ] ++ ) = ( *( src[ 1 ] ++ ) + *( src[ 2 ] ++ ) ) >> 1;
- }
-
- src[ 0 ] += src_rem[ 0 ];
- src[ 1 ] += src_rem[ 1 ];
- src[ 2 ] += src_rem[ 1 ];
- dst[ 0 ] += dst_rem[ 0 ];
- dst[ 1 ] += dst_rem[ 1 ];
- }
+ if ( dst_pf == L"a8b8g8r8" )
+ return yuvp_to_rgb( src, dst_pf, 3, 2, 1, 0 );
+ if ( dst_pf == L"a8r8g8b8" )
+ return yuvp_to_rgb( src, dst_pf, 1, 2, 3, 0 );
+ if ( dst_pf == L"b8g8r8" )
+ return yuvp_to_rgb( src, dst_pf, 2, 1, 0, -1 );
+ if ( dst_pf == L"b8g8r8a8" )
+ return yuvp_to_rgb( src, dst_pf, 2, 1, 0, 3 );
+ if ( dst_pf == L"r8g8b8" )
+ return yuvp_to_rgb( src, dst_pf, 0, 1, 2, -1 );
+ if ( dst_pf == L"r8g8b8a8" )
+ return yuvp_to_rgb( src, dst_pf, 0, 1, 2, 3 );
}
-
- return dst_img;
-}
-
-static image_type_ptr yuv420p_to_yuv444( const 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 )
+ else if ( is_rgb_packed( src_pf ) && is_yuv_planar( dst_pf ) )
{
- const_pointer src[ 4 ];
- src[ 0 ] = src_img->data( 0 );
- src[ 1 ] = src_img->data( 1 );
- src[ 2 ] = src_img->data( 2 );
- src[ 3 ] = src[ 0 ] + src_img->pitch( 0 );
-
- size_type src_pitch[ 3 ];
- src_pitch[ 0 ] = src_img->pitch( 0 ) * 2;
- src_pitch[ 1 ] = src_img->pitch( 1 );
- src_pitch[ 2 ] = src_img->pitch( 2 );
-
- pointer dst[ 2 ];
- size_type dst_pitch = dst_img->pitch( ) * 2;
- dst[ 0 ] = dst_img->data( );
- dst[ 1 ] = dst_img->data( ) + width * 3;
-
- const_pointer sptr[ 4 ];
- sptr[ 0 ] = src[ 0 ];
- sptr[ 1 ] = src[ 1 ];
- sptr[ 2 ] = src[ 2 ];
- sptr[ 3 ] = src[ 3 ];
-
- pointer dptr[ 2 ];
- dptr[ 0 ] = dst[ 0 ];
- dptr[ 1 ] = dst[ 1 ];
-
- size_type orig_width = width;
-
- while( height > 1 )
- {
- width = orig_width;
- dst[ 0 ] = dptr[ 0 ];
- dst[ 1 ] = dptr[ 1 ];
- src[ 0 ] = sptr[ 0 ];
- src[ 1 ] = sptr[ 1 ];
- src[ 2 ] = sptr[ 2 ];
- src[ 3 ] = sptr[ 3 ];
-
- while( width > 1 )
- {
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 1 ] );
- *( dst[ 0 ] ++ ) = *( src[ 2 ] );
-
- *( dst[ 0 ] ++ ) = *( src[ 0 ] ++ );
- *( dst[ 0 ] ++ ) = *( src[ 1 ] );
- *( dst[ 0 ] ++ ) = *( src[ 2 ] );
-
- *( dst[ 1 ] ++ ) = *( src[ 3 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 1 ] );
- *( dst[ 1 ] ++ ) = *( src[ 2 ] );
-
- *( dst[ 1 ] ++ ) = *( src[ 3 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 1 ] ++ );
- *( dst[ 1 ] ++ ) = *( src[ 2 ] ++ );
-
- width -= 2;
- }
-
- dptr[ 0 ] += dst_pitch;
- dptr[ 1 ] += dst_pitch;
- sptr[ 0 ] += src_pitch[ 0 ];
- sptr[ 1 ] += src_pitch[ 1 ];
- sptr[ 2 ] += src_pitch[ 2 ];
- sptr[ 3 ] += src_pitch[ 0 ];
-
- height -= 2;
- }
+ if ( src_pf == L"a8b8g8r8" )
+ return rgb_to_yuvp( src, dst_pf, 3, 2, 1, 0 );
+ if ( src_pf == L"a8r8g8b8" )
+ return rgb_to_yuvp( src, dst_pf, 1, 2, 3, 0 );
+ if ( src_pf == L"b8g8r8" )
+ return rgb_to_yuvp( src, dst_pf, 2, 1, 0, -1 );
+ if ( src_pf == L"b8g8r8a8" )
+ return rgb_to_yuvp( src, dst_pf, 2, 1, 0, 3 );
+ if ( src_pf == L"r8g8b8" )
+ return rgb_to_yuvp( src, dst_pf, 0, 1, 2, -1 );
+ if ( src_pf == L"r8g8b8a8" )
+ return rgb_to_yuvp( src, dst_pf, 0, 1, 2, 3 );
}
-
- return dst_img;
-}
-
-IL_DECLSPEC image_type_ptr convert( const image_type_ptr &src, const std::wstring &dst_pf, int )
-{
- // Sanity check
- if ( src == 0 )
- return src;
-
- // Get the format of the source
- std::wstring src_pf = src->pf( );
-
- // Convert
- if ( dst_pf == src_pf )
+ else if ( src_pf == L"yuv422" && is_yuv_planar( dst_pf ) )
{
- return src;
+ return yuv422_to_yuvp( src, dst_pf );
}
+ else if ( src_pf == L"yuv444" && is_yuv_planar( dst_pf ) )
+ {
+ return yuv444_to_yuvp( src, dst_pf );
+ }
else if ( src_pf == L"r8g8b8" )
{
if ( dst_pf == L"b8g8r8" )
@@ -2375,14 +1605,8 @@
return rgb_to_yuv444( src, dst_pf, 3, 0, 1, 2 );
else if ( dst_pf == L"yuv422" )
return rgb_to_yuv422( src, dst_pf, 3, 0, 1, 2 );
- else if ( dst_pf == L"yuv422p" )
- return rgb_to_yuv422p( src, dst_pf, 3, 0, 1, 2 );
- else if ( dst_pf == L"yuv420p" )
- return rgb_to_yuv420p( src, dst_pf, 3, 0, 1, 2 );
else if ( dst_pf == L"yuv411" )
return rgb_to_yuv411( src, dst_pf, 3, 0, 1, 2 );
- else if ( dst_pf == L"yuv411p" )
- return rgb_to_yuv411p( src, dst_pf, 3, 0, 1, 2 );
...
[truncated message content] |