Optimize wxImage::Rotate90() by rotating alpha separately.
Bringing the alpha rotation out in a separate loop results in an approximatively 10% performance improvement. Closes #12712. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66254 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
a6bf0c9533
commit
89a1395ebc
@ -1091,33 +1091,45 @@ wxImage wxImage::Rotate90( bool clockwise ) const
|
||||
unsigned char *data = image.GetData();
|
||||
const unsigned char *source_data = M_IMGDATA->m_data;
|
||||
unsigned char *target_data;
|
||||
unsigned char *alpha_data = image.GetAlpha();
|
||||
const unsigned char *source_alpha = M_IMGDATA->m_alpha;
|
||||
unsigned char *target_alpha = 0 ;
|
||||
|
||||
for (long j = 0; j < height; j++)
|
||||
{
|
||||
for (long i = 0; i < width; i++)
|
||||
{
|
||||
if (clockwise)
|
||||
if ( clockwise )
|
||||
{
|
||||
target_data = data + (((i+1)*height) - j - 1)*3;
|
||||
if (source_alpha)
|
||||
target_alpha = alpha_data + (((i+1)*height) - j - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
target_data = data + ((height*(width-1)) + j - (i*height))*3;
|
||||
if (source_alpha)
|
||||
target_alpha = alpha_data + ((height*(width-1)) + j - (i*height));
|
||||
}
|
||||
memcpy( target_data, source_data, 3 );
|
||||
source_data += 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (source_alpha)
|
||||
const unsigned char *source_alpha = M_IMGDATA->m_alpha;
|
||||
|
||||
if ( source_alpha )
|
||||
{
|
||||
unsigned char *alpha_data = image.GetAlpha();
|
||||
unsigned char *target_alpha = 0 ;
|
||||
|
||||
for (long j = 0; j < height; j++)
|
||||
{
|
||||
for (long i = 0; i < width; i++)
|
||||
{
|
||||
memcpy( target_alpha, source_alpha, 1 );
|
||||
source_alpha += 1;
|
||||
if ( clockwise )
|
||||
{
|
||||
target_alpha = alpha_data + (((i+1)*height) - j - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
target_alpha = alpha_data + ((height*(width-1)) + j - (i*height));
|
||||
}
|
||||
|
||||
*target_alpha = *source_alpha++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user