Optimize pixels rotation in wxImage::Rotate90().
Rotate the image by entire strips instead of doing it pixel by pixel. This seems to result in about 50% performance gain. Closes #12739. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66309 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1089,12 +1089,22 @@ wxImage wxImage::Rotate90( bool clockwise ) const
|
|||||||
}
|
}
|
||||||
|
|
||||||
unsigned char *data = image.GetData();
|
unsigned char *data = image.GetData();
|
||||||
const unsigned char *source_data = M_IMGDATA->m_data;
|
|
||||||
unsigned char *target_data;
|
unsigned char *target_data;
|
||||||
|
|
||||||
|
// we rotate the image in 21-pixel (63-byte) wide strips
|
||||||
|
// to make better use of cpu cache - memory transfers
|
||||||
|
// (note: while much better than single-pixel "strips",
|
||||||
|
// our vertical strips will still generally straddle cachelines)
|
||||||
|
for (long ii = 0; ii < width; )
|
||||||
|
{
|
||||||
|
long next_ii = wxMin(ii + 21, width);
|
||||||
|
|
||||||
for (long j = 0; j < height; j++)
|
for (long j = 0; j < height; j++)
|
||||||
{
|
{
|
||||||
for (long i = 0; i < width; i++)
|
const unsigned char *source_data
|
||||||
|
= M_IMGDATA->m_data + (j*width + ii)*3;
|
||||||
|
|
||||||
|
for (long i = ii; i < next_ii; i++)
|
||||||
{
|
{
|
||||||
if ( clockwise )
|
if ( clockwise )
|
||||||
{
|
{
|
||||||
@@ -1102,13 +1112,16 @@ wxImage wxImage::Rotate90( bool clockwise ) const
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
target_data = data + ((height*(width-1)) + j - (i*height))*3;
|
target_data = data + ((height*(width - 1 - i)) + j)*3;
|
||||||
}
|
}
|
||||||
memcpy( target_data, source_data, 3 );
|
memcpy( target_data, source_data, 3 );
|
||||||
source_data += 3;
|
source_data += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ii = next_ii;
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned char *source_alpha = M_IMGDATA->m_alpha;
|
const unsigned char *source_alpha = M_IMGDATA->m_alpha;
|
||||||
|
|
||||||
if ( source_alpha )
|
if ( source_alpha )
|
||||||
|
Reference in New Issue
Block a user