From 6a9b494553a0e5547ad1f59f54ec6147a1c0fa79 Mon Sep 17 00:00:00 2001 From: caryclark Date: Thu, 26 May 2016 14:17:39 -0700 Subject: skia: add bitmap color table support Fix 2/4/8 bits per pixel bitmaps that PDFium transposes into 8 bpp indexed. R=tsepez@chromium.org,dsinclair@chromium.org,reed@google.com Review-Url: https://codereview.chromium.org/2011153002 --- core/fxge/skia/fx_skia_device.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/core/fxge/skia/fx_skia_device.cpp b/core/fxge/skia/fx_skia_device.cpp index c4ca6f9223..e64dfd0a73 100644 --- a/core/fxge/skia/fx_skia_device.cpp +++ b/core/fxge/skia/fx_skia_device.cpp @@ -994,7 +994,10 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, int alpha_flag, void* pIccTransform, int blend_type) { - SkColorType colorType; + SkColorType colorType = pSource->IsAlphaMask() + ? SkColorType::kAlpha_8_SkColorType + : SkColorType::kGray_8_SkColorType; + SkColorTable* ct = nullptr; void* buffer = pSource->GetBuffer(); std::unique_ptr dst8Storage; std::unique_ptr dst32Storage; @@ -1014,11 +1017,12 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, } buffer = dst8Storage.get(); rowBytes = width; - colorType = pSource->IsAlphaMask() ? SkColorType::kAlpha_8_SkColorType - : SkColorType::kGray_8_SkColorType; } break; case 8: - colorType = SkColorType::kGray_8_SkColorType; + if (pSource->GetPalette()) { + ct = new SkColorTable(pSource->GetPalette(), pSource->GetPaletteSize()); + colorType = SkColorType::kIndex_8_SkColorType; + } break; case 24: { dst32Storage.reset(FX_Alloc2D(uint32_t, width, height)); @@ -1045,9 +1049,7 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, width, height, colorType, pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType); SkBitmap skBitmap; - skBitmap.installPixels(imageInfo, buffer, rowBytes, - nullptr, /* TODO(caryclark) : set color table */ - nullptr, nullptr); + skBitmap.installPixels(imageInfo, buffer, rowBytes, ct, nullptr, nullptr); m_pCanvas->save(); SkMatrix skMatrix; const CFX_Matrix& m = *pMatrix; @@ -1065,6 +1067,8 @@ FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, paint.setAlpha(bitmap_alpha); m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); m_pCanvas->restore(); + if (ct) + ct->unref(); return TRUE; } -- cgit v1.2.3