diff options
-rw-r--r-- | vcl/opengl/salbmp.cxx | 40 | ||||
-rw-r--r-- | vcl/win/gdi/salgdi2.cxx | 67 |
2 files changed, 64 insertions, 43 deletions
diff --git a/vcl/opengl/salbmp.cxx b/vcl/opengl/salbmp.cxx index fde9f199157d..bce9fb7850c0 100644 --- a/vcl/opengl/salbmp.cxx +++ b/vcl/opengl/salbmp.cxx @@ -55,28 +55,16 @@ inline bool determineTextureFormat(sal_uInt16 nBits, GLenum& nFormat, GLenum& nT nType = GL_UNSIGNED_BYTE; return true; case 16: -#ifdef _WIN32 - nFormat = GL_BGR; -#else nFormat = GL_RGB; -#endif nType = GL_UNSIGNED_SHORT_5_6_5; return true; case 24: -#ifdef _WIN32 - nFormat = GL_BGR; -#else nFormat = GL_RGB; -#endif nType = GL_UNSIGNED_BYTE; return true; case 32: -#ifdef _WIN32 - nFormat = GL_BGRA; -#else nFormat = GL_RGBA; -#endif - nType = GL_UNSIGNED_BYTE; + nType = GL_UNSIGNED_INT_8_8_8_8; return true; default: break; @@ -783,16 +771,6 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) break; case 16: { -#ifdef _WIN32 - pBuffer->mnFormat = ScanlineFormat::N16BitTcLsbMask; - ColorMaskElement aRedMask(0x00007c00); - aRedMask.CalcMaskShift(); - ColorMaskElement aGreenMask(0x000003e0); - aGreenMask.CalcMaskShift(); - ColorMaskElement aBlueMask(0x0000001f); - aBlueMask.CalcMaskShift(); - pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#else pBuffer->mnFormat = ScanlineFormat::N16BitTcMsbMask; ColorMaskElement aRedMask(0x0000f800); aRedMask.CalcMaskShift(); @@ -801,30 +779,15 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) ColorMaskElement aBlueMask(0x0000001f); aBlueMask.CalcMaskShift(); pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#endif break; } case 24: { -#ifdef _WIN32 - pBuffer->mnFormat = ScanlineFormat::N24BitTcBgr; -#else pBuffer->mnFormat = ScanlineFormat::N24BitTcRgb; -#endif break; } case 32: { -#ifdef _WIN32 - pBuffer->mnFormat = ScanlineFormat::N32BitTcBgra; - ColorMaskElement aRedMask(0x00ff0000); - aRedMask.CalcMaskShift(); - ColorMaskElement aGreenMask(0x0000ff00); - aGreenMask.CalcMaskShift(); - ColorMaskElement aBlueMask(0x000000ff); - aBlueMask.CalcMaskShift(); - pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#else pBuffer->mnFormat = ScanlineFormat::N32BitTcRgba; ColorMaskElement aRedMask(0xff000000); aRedMask.CalcMaskShift(); @@ -833,7 +796,6 @@ BitmapBuffer* OpenGLSalBitmap::AcquireBuffer( BitmapAccessMode nMode ) ColorMaskElement aBlueMask(0x0000ff00); aBlueMask.CalcMaskShift(); pBuffer->maColorMask = ColorMask(aRedMask, aGreenMask, aBlueMask); -#endif break; } } diff --git a/vcl/win/gdi/salgdi2.cxx b/vcl/win/gdi/salgdi2.cxx index 3a49ac592dde..000746bbf042 100644 --- a/vcl/win/gdi/salgdi2.cxx +++ b/vcl/win/gdi/salgdi2.cxx @@ -73,6 +73,45 @@ void WinSalGraphics::copyArea( long nDestX, long nDestY, namespace { +class ColorScanlineConverter +{ +public: + ScanlineFormat meSourceFormat; + ScanlineFormat meDestinationFormat; + + int mnComponentSize; + int mnComponentExchangeIndex; + + long mnScanlineSize; + + ColorScanlineConverter(ScanlineFormat eSourceFormat, ScanlineFormat eDestinationFormat, int nComponentSize, long nScanlineSize) + : meSourceFormat(eSourceFormat) + , meDestinationFormat(eDestinationFormat) + , mnComponentSize(nComponentSize) + , mnComponentExchangeIndex(0) + , mnScanlineSize(nScanlineSize) + { + if (meSourceFormat == ScanlineFormat::N32BitTcAbgr || + meSourceFormat == ScanlineFormat::N32BitTcArgb) + { + mnComponentExchangeIndex = 1; + } + } + + void convertScanline(sal_uInt8* pSource, sal_uInt8* pDestination) + { + for (int x = 0; x < mnScanlineSize; x += mnComponentSize) + { + for (int i = 0; i < mnComponentSize; ++i) + { + pDestination[x + i] = pSource[x + i]; + } + pDestination[x + mnComponentExchangeIndex + 0] = pSource[x + mnComponentExchangeIndex + 2]; + pDestination[x + mnComponentExchangeIndex + 2] = pSource[x + mnComponentExchangeIndex + 0]; + } + } +}; + void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) { BitmapPalette aBitmapPalette; @@ -90,11 +129,31 @@ void convertToWinSalBitmap(SalBitmap& rSalBitmap, WinSalBitmap& rWinSalBitmap) sal_uInt8* pSource(pRead->mpBits); sal_uInt8* pDestination(pWrite->mpBits); - for (long y = 0; y < pRead->mnHeight; y++) + std::unique_ptr<ColorScanlineConverter> pConverter; + + if (pRead->mnFormat == ScanlineFormat::N24BitTcRgb) + pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N24BitTcRgb, ScanlineFormat::N24BitTcBgr, + 3, pRead->mnScanlineSize)); + else if (pRead->mnFormat == ScanlineFormat::N32BitTcRgba) + pConverter.reset(new ColorScanlineConverter(ScanlineFormat::N32BitTcRgba, ScanlineFormat::N32BitTcBgra, + 4, pRead->mnScanlineSize)); + if (pConverter) + { + for (long y = 0; y < pRead->mnHeight; y++) + { + pConverter->convertScanline(pSource, pDestination); + pSource += pRead->mnScanlineSize; + pDestination += pWrite->mnScanlineSize; + } + } + else { - memcpy(pDestination, pSource, pRead->mnScanlineSize); - pSource += pRead->mnScanlineSize; - pDestination += pWrite->mnScanlineSize; + for (long y = 0; y < pRead->mnHeight; y++) + { + memcpy(pDestination, pSource, pRead->mnScanlineSize); + pSource += pRead->mnScanlineSize; + pDestination += pWrite->mnScanlineSize; + } } rWinSalBitmap.ReleaseBuffer(pWrite, BitmapAccessMode::Write); |