Use dedicated WIC methods to get sub-bitmap of IWICBitmap
Using IWICBitmapClipper it is possible to get a clipped version of the source bitmap so it should be used instead of manual way with extracting pixels to the memory.
This commit is contained in:
@@ -2601,26 +2601,16 @@ public:
|
|||||||
|
|
||||||
wxD2DBitmapResourceHolder* GetSubBitmap(wxDouble x, wxDouble y, wxDouble w, wxDouble h) const
|
wxD2DBitmapResourceHolder* GetSubBitmap(wxDouble x, wxDouble y, wxDouble w, wxDouble h) const
|
||||||
{
|
{
|
||||||
|
wxCOMPtr<IWICBitmapClipper> clipper;
|
||||||
|
HRESULT hr = wxWICImagingFactory()->CreateBitmapClipper(&clipper);
|
||||||
|
wxCHECK2_HRESULT_RET(hr, NULL);
|
||||||
|
|
||||||
WICRect r = { (INT)x, (INT)y, (INT)w, (INT)h };
|
WICRect r = { (INT)x, (INT)y, (INT)w, (INT)h };
|
||||||
|
hr = clipper->Initialize(m_srcBitmap, &r);
|
||||||
WICPixelFormatGUID fmt;
|
wxCHECK2_HRESULT_RET(hr, NULL);
|
||||||
m_srcBitmap->GetPixelFormat(&fmt);
|
|
||||||
wxASSERT_MSG(fmt == GUID_WICPixelFormat32bppPBGRA || fmt == GUID_WICPixelFormat32bppBGR, "Unsupported pixel format");
|
|
||||||
|
|
||||||
UINT bufStride = 4 * r.Width;
|
|
||||||
UINT bufSize = 4 * r.Width * r.Height;
|
|
||||||
BYTE* pixBuffer = new BYTE[bufSize];
|
|
||||||
HRESULT hr = m_srcBitmap->CopyPixels(&r, bufStride, bufSize, pixBuffer);
|
|
||||||
if ( FAILED(hr) )
|
|
||||||
{
|
|
||||||
delete[] pixBuffer;
|
|
||||||
wxFAILED_HRESULT_MSG(hr);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxCOMPtr<IWICBitmap> subBmp;
|
wxCOMPtr<IWICBitmap> subBmp;
|
||||||
hr = wxWICImagingFactory()->CreateBitmapFromMemory(r.Width, r.Height, fmt, bufStride, bufSize, pixBuffer, &subBmp);
|
hr = wxWICImagingFactory()->CreateBitmapFromSource(clipper, WICBitmapNoCache, &subBmp);
|
||||||
delete[] pixBuffer;
|
|
||||||
wxCHECK2_HRESULT_RET(hr, NULL);
|
wxCHECK2_HRESULT_RET(hr, NULL);
|
||||||
|
|
||||||
return new wxD2DBitmapResourceHolder(subBmp);
|
return new wxD2DBitmapResourceHolder(subBmp);
|
||||||
|
Reference in New Issue
Block a user