Kaydet (Commit) f7d1ea37 authored tarafından Tor Lillqvist's avatar Tor Lillqvist Kaydeden (comit) Caolán McNamara

tdf#92272: We need to twiddle the bytes from BGR to RGB

As far as I see, the surfaces created in the DX canvas are of
D3DFMT_A8R8G8B8 or D3DFMT_X8R8G8B8 format, which means that the bytes
(in memory order, on little-endian Windows) are B,G,R,A/X. So if the
desired destination wants R,G,B,A, we need to swap the blue and red
bytes.

Let's hope this doesn't break anything else...

Change-Id: I1b90d2cf95418f6557cac633ec6fce27599e8a61
Reviewed-on: https://gerrit.libreoffice.org/20161Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst b8711f66
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <string.h> #include <string.h>
#include <com/sun/star/rendering/ColorComponentTag.hpp>
#include "dx_surfacebitmap.hxx" #include "dx_surfacebitmap.hxx"
#include "dx_impltools.hxx" #include "dx_impltools.hxx"
#include "dx_surfacegraphics.hxx" #include "dx_surfacegraphics.hxx"
...@@ -438,7 +440,7 @@ namespace dxcanvas ...@@ -438,7 +440,7 @@ namespace dxcanvas
// DXSurfaceBitmap::getData // DXSurfaceBitmap::getData
uno::Sequence< sal_Int8 > DXSurfaceBitmap::getData( rendering::IntegerBitmapLayout& /*bitmapLayout*/, uno::Sequence< sal_Int8 > DXSurfaceBitmap::getData( rendering::IntegerBitmapLayout& rBitmapLayout,
const geometry::IntegerRectangle2D& rect ) const geometry::IntegerRectangle2D& rect )
{ {
if(hasAlpha()) if(hasAlpha())
...@@ -483,6 +485,11 @@ namespace dxcanvas ...@@ -483,6 +485,11 @@ namespace dxcanvas
D3DLOCKED_RECT aLockedRect; D3DLOCKED_RECT aLockedRect;
if(FAILED(mpSurface->LockRect(&aLockedRect,NULL,D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY))) if(FAILED(mpSurface->LockRect(&aLockedRect,NULL,D3DLOCK_NOSYSLOCK|D3DLOCK_READONLY)))
return uno::Sequence< sal_Int8 >(); return uno::Sequence< sal_Int8 >();
D3DSURFACE_DESC aDesc;
if(FAILED(mpSurface->GetDesc(&aDesc)))
return uno::Sequence< sal_Int8 >();
assert(aDesc.Format == D3DFMT_A8R8G8B8 || aDesc.Format == D3DFMT_X8R8G8B8);
sal_uInt8 *pSrc = (sal_uInt8 *)((((BYTE *)aLockedRect.pBits)+(rect.Y1*aLockedRect.Pitch))+rect.X1); sal_uInt8 *pSrc = (sal_uInt8 *)((((BYTE *)aLockedRect.pBits)+(rect.Y1*aLockedRect.Pitch))+rect.X1);
sal_uInt8 *pDst = (sal_uInt8 *)aRes.getArray(); sal_uInt8 *pDst = (sal_uInt8 *)aRes.getArray();
...@@ -494,6 +501,24 @@ namespace dxcanvas ...@@ -494,6 +501,24 @@ namespace dxcanvas
pSrc += aLockedRect.Pitch; pSrc += aLockedRect.Pitch;
} }
if(rBitmapLayout.ColorSpace->getComponentTags().getArray()[0] == rendering::ColorComponentTag::RGB_RED &&
rBitmapLayout.ColorSpace->getComponentTags().getArray()[2] == rendering::ColorComponentTag::RGB_BLUE)
{
pDst = (sal_uInt8 *)aRes.getArray();
for(sal_uInt32 y=0; y<nHeight; ++y)
{
sal_uInt8* pPixel = pDst;
for(sal_uInt32 n = 0; n<nWidth; n++)
{
sal_uInt8 nB = pPixel[0];
pPixel[0] = pPixel[2];
pPixel[2] = nB;
pPixel += 4;
}
pDst += nSegmentSizeInBytes;
}
}
mpSurface->UnlockRect(); mpSurface->UnlockRect();
return aRes; return aRes;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment