Weight pixels by their respective alpha value in wxImage::ResampleBox
Without this weighting, even the color value of invisible pixels with a zero alpha would influence the result. Closes #17724.
This commit is contained in:
parent
7684f92083
commit
b99ad85b6f
@ -114,6 +114,7 @@ All (GUI):
|
||||
- Fix calculating point position in wxDataViewCtrl::HitTest().
|
||||
- Fix position of the rectangle returned by wxDataViewCtrl::GetItemRect().
|
||||
- Add wxDataViewRenderer::GetAccessibleDescription().
|
||||
- Improve wxImage::Scale() handling of pixels with alpha channel (Tim Kosse).
|
||||
|
||||
wxGTK:
|
||||
|
||||
|
@ -659,23 +659,48 @@ wxImage wxImage::ResampleBox(int width, int height) const
|
||||
// Calculate the actual index in our source pixels
|
||||
src_pixel_index = j * M_IMGDATA->m_width + i;
|
||||
|
||||
sum_r += src_data[src_pixel_index * 3 + 0];
|
||||
sum_g += src_data[src_pixel_index * 3 + 1];
|
||||
sum_b += src_data[src_pixel_index * 3 + 2];
|
||||
if ( src_alpha )
|
||||
if (src_alpha)
|
||||
{
|
||||
sum_r += src_data[src_pixel_index * 3 + 0] * src_alpha[src_pixel_index];
|
||||
sum_g += src_data[src_pixel_index * 3 + 1] * src_alpha[src_pixel_index];
|
||||
sum_b += src_data[src_pixel_index * 3 + 2] * src_alpha[src_pixel_index];
|
||||
sum_a += src_alpha[src_pixel_index];
|
||||
}
|
||||
else
|
||||
{
|
||||
sum_r += src_data[src_pixel_index * 3 + 0];
|
||||
sum_g += src_data[src_pixel_index * 3 + 1];
|
||||
sum_b += src_data[src_pixel_index * 3 + 2];
|
||||
}
|
||||
|
||||
averaged_pixels++;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the average from the sum and number of averaged pixels
|
||||
dst_data[0] = (unsigned char)(sum_r / averaged_pixels);
|
||||
dst_data[1] = (unsigned char)(sum_g / averaged_pixels);
|
||||
dst_data[2] = (unsigned char)(sum_b / averaged_pixels);
|
||||
dst_data += 3;
|
||||
if ( src_alpha )
|
||||
if (src_alpha)
|
||||
{
|
||||
if (sum_a)
|
||||
{
|
||||
dst_data[0] = (unsigned char)(sum_r / sum_a);
|
||||
dst_data[1] = (unsigned char)(sum_g / sum_a);
|
||||
dst_data[2] = (unsigned char)(sum_b / sum_a);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst_data[0] = 0;
|
||||
dst_data[1] = 0;
|
||||
dst_data[2] = 0;
|
||||
}
|
||||
*dst_alpha++ = (unsigned char)(sum_a / averaged_pixels);
|
||||
}
|
||||
else
|
||||
{
|
||||
dst_data[0] = (unsigned char)(sum_r / averaged_pixels);
|
||||
dst_data[1] = (unsigned char)(sum_g / averaged_pixels);
|
||||
dst_data[2] = (unsigned char)(sum_b / averaged_pixels);
|
||||
}
|
||||
dst_data += 3;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user