diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-04-02 12:33:57 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-04-07 11:52:43 +0200 |
commit | c27d2e9145be8972e5d2174fb3f317dc08930074 (patch) | |
tree | bc8063b6e69956c553edfca0a2d5d2d551785b4c /vcl/skia | |
parent | 912773d521fd6b8ff90d27f7bd3f5a46fd0df582 (diff) |
optimize bit depth conversions to/from Skia where possible
Skia has an optimized function for RGB->RGBA conversion that
we are going to do often because 24bpp is the most common LO
image format. The function is private, so patch that.
Also optimize 32bpp->8bpp conversion with gray palette.
Change-Id: I48b06f80d5ca9e1c8e3ee51da61e87541bd83d5a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91768
Tested-by: Jenkins
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'vcl/skia')
-rw-r--r-- | vcl/skia/salbmp.cxx | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/vcl/skia/salbmp.cxx b/vcl/skia/salbmp.cxx index f0bffb500194..c000b391eaa2 100644 --- a/vcl/skia/salbmp.cxx +++ b/vcl/skia/salbmp.cxx @@ -32,6 +32,7 @@ #include <SkImage.h> #include <SkPixelRef.h> #include <SkSurface.h> +#include <SkSwizzle.h> #include <skia/utils.hxx> #include <skia/zone.hxx> @@ -387,19 +388,16 @@ SkBitmap SkiaSalBitmap::GetAsSkBitmap() const else if (mBitCount == 24) { // Convert 24bpp RGB/BGR to 32bpp RGBA/BGRA. - std::unique_ptr<sal_uInt8[]> data( - new sal_uInt8[mPixelsSize.Height() * mPixelsSize.Width() * 4]); - sal_uInt8* dest = data.get(); + std::unique_ptr<uint32_t[]> data( + new uint32_t[mPixelsSize.Height() * mPixelsSize.Width()]); + uint32_t* dest = data.get(); for (long y = 0; y < mPixelsSize.Height(); ++y) { const sal_uInt8* src = mBuffer.get() + mScanlineSize * y; - for (long x = 0; x < mPixelsSize.Width(); ++x) - { - *dest++ = *src++; - *dest++ = *src++; - *dest++ = *src++; - *dest++ = 0xff; - } + // This also works as BGR to BGRA (the function extends 3 bytes to 4 + // by adding 0xFF alpha, so position of B and R doesn't matter). + SkExtendRGBToRGBA(dest, src, mPixelsSize.Width()); + dest += mPixelsSize.Width(); } if (!bitmap.installPixels( SkImageInfo::MakeS32(mPixelsSize.Width(), mPixelsSize.Height(), @@ -647,6 +645,17 @@ void SkiaSalBitmap::EnsureBitmapData() } } } + else if (mBitCount == 8 && mPalette.IsGreyPalette()) + { + for (long y = 0; y < mSize.Height(); ++y) + { + const uint8_t* src = static_cast<uint8_t*>(mBitmap.getAddr(0, y)); + sal_uInt8* dest = mBuffer.get() + mScanlineSize * y; + // no actual data conversion, use one color channel as the gray value + for (long x = 0; x < mSize.Width(); ++x) + dest[x] = src[x * 4]; + } + } else { std::unique_ptr<vcl::ScanlineWriter> pWriter |