Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Side by Side Diff: core/fxge/skia/fx_skia_device.cpp

Issue 2011153002: skia: add bitmap color table support (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/fxge/include/fx_ge.h" 5 #include "core/fxge/include/fx_ge.h"
6 6
7 #if defined(_SKIA_SUPPORT_) 7 #if defined(_SKIA_SUPPORT_)
8 #include "core/fxcodec/include/fx_codec.h" 8 #include "core/fxcodec/include/fx_codec.h"
9 9
10 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h" 10 #include "core/fpdfapi/fpdf_page/cpdf_shadingpattern.h"
(...skipping 976 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 987
988 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource, 988 FX_BOOL CFX_SkiaDeviceDriver::StartDIBits(const CFX_DIBSource* pSource,
989 int bitmap_alpha, 989 int bitmap_alpha,
990 uint32_t argb, 990 uint32_t argb,
991 const CFX_Matrix* pMatrix, 991 const CFX_Matrix* pMatrix,
992 uint32_t render_flags, 992 uint32_t render_flags,
993 void*& handle, 993 void*& handle,
994 int alpha_flag, 994 int alpha_flag,
995 void* pIccTransform, 995 void* pIccTransform,
996 int blend_type) { 996 int blend_type) {
997 SkColorType colorType; 997 SkColorType colorType = pSource->IsAlphaMask()
998 ? SkColorType::kAlpha_8_SkColorType
999 : SkColorType::kGray_8_SkColorType;
1000 SkColorTable* ct = nullptr;
998 void* buffer = pSource->GetBuffer(); 1001 void* buffer = pSource->GetBuffer();
999 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; 1002 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage;
1000 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; 1003 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage;
1001 int width = pSource->GetWidth(); 1004 int width = pSource->GetWidth();
1002 int height = pSource->GetHeight(); 1005 int height = pSource->GetHeight();
1003 int rowBytes = pSource->GetPitch(); 1006 int rowBytes = pSource->GetPitch();
1004 switch (pSource->GetBPP()) { 1007 switch (pSource->GetBPP()) {
1005 case 1: { 1008 case 1: {
1006 dst8Storage.reset(FX_Alloc2D(uint8_t, width, height)); 1009 dst8Storage.reset(FX_Alloc2D(uint8_t, width, height));
1007 uint8_t* dst8Pixels = dst8Storage.get(); 1010 uint8_t* dst8Pixels = dst8Storage.get();
1008 for (int y = 0; y < height; ++y) { 1011 for (int y = 0; y < height; ++y) {
1009 const uint8_t* srcRow = 1012 const uint8_t* srcRow =
1010 static_cast<const uint8_t*>(buffer) + y * rowBytes; 1013 static_cast<const uint8_t*>(buffer) + y * rowBytes;
1011 uint8_t* dstRow = dst8Pixels + y * width; 1014 uint8_t* dstRow = dst8Pixels + y * width;
1012 for (int x = 0; x < width; ++x) 1015 for (int x = 0; x < width; ++x)
1013 dstRow[x] = srcRow[x >> 3] & (1 << (~x & 0x07)) ? 0xFF : 0x00; 1016 dstRow[x] = srcRow[x >> 3] & (1 << (~x & 0x07)) ? 0xFF : 0x00;
1014 } 1017 }
1015 buffer = dst8Storage.get(); 1018 buffer = dst8Storage.get();
1016 rowBytes = width; 1019 rowBytes = width;
1017 colorType = pSource->IsAlphaMask() ? SkColorType::kAlpha_8_SkColorType
1018 : SkColorType::kGray_8_SkColorType;
1019 } break; 1020 } break;
1020 case 8: 1021 case 8:
1021 colorType = SkColorType::kGray_8_SkColorType; 1022 if (pSource->GetPalette()) {
1023 ct = new SkColorTable(pSource->GetPalette(), pSource->GetPaletteSize());
1024 colorType = SkColorType::kIndex_8_SkColorType;
1025 }
1022 break; 1026 break;
1023 case 24: { 1027 case 24: {
1024 dst32Storage.reset(FX_Alloc2D(uint32_t, width, height)); 1028 dst32Storage.reset(FX_Alloc2D(uint32_t, width, height));
1025 uint32_t* dst32Pixels = dst32Storage.get(); 1029 uint32_t* dst32Pixels = dst32Storage.get();
1026 for (int y = 0; y < height; ++y) { 1030 for (int y = 0; y < height; ++y) {
1027 const uint8_t* srcRow = 1031 const uint8_t* srcRow =
1028 static_cast<const uint8_t*>(buffer) + y * rowBytes; 1032 static_cast<const uint8_t*>(buffer) + y * rowBytes;
1029 uint32_t* dstRow = dst32Pixels + y * width; 1033 uint32_t* dstRow = dst32Pixels + y * width;
1030 for (int x = 0; x < width; ++x) 1034 for (int x = 0; x < width; ++x)
1031 dstRow[x] = SkPackARGB32(0xFF, srcRow[x * 3 + 2], srcRow[x * 3 + 1], 1035 dstRow[x] = SkPackARGB32(0xFF, srcRow[x * 3 + 2], srcRow[x * 3 + 1],
1032 srcRow[x * 3 + 0]); 1036 srcRow[x * 3 + 0]);
1033 } 1037 }
1034 buffer = dst32Storage.get(); 1038 buffer = dst32Storage.get();
1035 rowBytes = width * sizeof(uint32_t); 1039 rowBytes = width * sizeof(uint32_t);
1036 colorType = SkColorType::kN32_SkColorType; 1040 colorType = SkColorType::kN32_SkColorType;
1037 } break; 1041 } break;
1038 case 32: 1042 case 32:
1039 colorType = SkColorType::kN32_SkColorType; 1043 colorType = SkColorType::kN32_SkColorType;
1040 break; 1044 break;
1041 default: 1045 default:
1042 colorType = SkColorType::kUnknown_SkColorType; 1046 colorType = SkColorType::kUnknown_SkColorType;
1043 } 1047 }
1044 SkImageInfo imageInfo = SkImageInfo::Make( 1048 SkImageInfo imageInfo = SkImageInfo::Make(
1045 width, height, colorType, 1049 width, height, colorType,
1046 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType); 1050 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
1047 SkBitmap skBitmap; 1051 SkBitmap skBitmap;
1048 skBitmap.installPixels(imageInfo, buffer, rowBytes, 1052 skBitmap.installPixels(imageInfo, buffer, rowBytes, ct, nullptr, nullptr);
1049 nullptr, /* TODO(caryclark) : set color table */
1050 nullptr, nullptr);
1051 m_pCanvas->save(); 1053 m_pCanvas->save();
1052 SkMatrix skMatrix; 1054 SkMatrix skMatrix;
1053 const CFX_Matrix& m = *pMatrix; 1055 const CFX_Matrix& m = *pMatrix;
1054 skMatrix.setAll(m.a / width, -m.c / height, m.c + m.e, m.b / width, 1056 skMatrix.setAll(m.a / width, -m.c / height, m.c + m.e, m.b / width,
1055 -m.d / height, m.d + m.f, 0, 0, 1); 1057 -m.d / height, m.d + m.f, 0, 0, 1);
1056 m_pCanvas->concat(skMatrix); 1058 m_pCanvas->concat(skMatrix);
1057 SkPaint paint; 1059 SkPaint paint;
1058 paint.setAntiAlias(true); 1060 paint.setAntiAlias(true);
1059 if (pSource->IsAlphaMask()) { 1061 if (pSource->IsAlphaMask()) {
1060 paint.setColorFilter( 1062 paint.setColorFilter(
1061 SkColorFilter::MakeModeFilter(argb, SkXfermode::kSrc_Mode)); 1063 SkColorFilter::MakeModeFilter(argb, SkXfermode::kSrc_Mode));
1062 } 1064 }
1063 // paint.setFilterQuality(kHigh_SkFilterQuality); 1065 // paint.setFilterQuality(kHigh_SkFilterQuality);
1064 paint.setXfermodeMode(GetSkiaBlendMode(blend_type)); 1066 paint.setXfermodeMode(GetSkiaBlendMode(blend_type));
1065 paint.setAlpha(bitmap_alpha); 1067 paint.setAlpha(bitmap_alpha);
1066 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); 1068 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint);
1067 m_pCanvas->restore(); 1069 m_pCanvas->restore();
1070 if (ct)
1071 ct->unref();
1068 return TRUE; 1072 return TRUE;
1069 } 1073 }
1070 1074
1071 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { 1075 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) {
1072 if (!m_pBitmap->GetBuffer()) 1076 if (!m_pBitmap->GetBuffer())
1073 return TRUE; 1077 return TRUE;
1074 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause); 1078 return ((CFX_ImageRenderer*)pHandle)->Continue(pPause);
1075 } 1079 }
1076 1080
1077 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) { 1081 void CFX_SkiaDeviceDriver::CancelDIBits(void* pHandle) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1127 SetDeviceDriver(pDriver); 1131 SetDeviceDriver(pDriver);
1128 return true; 1132 return true;
1129 } 1133 }
1130 1134
1131 CFX_FxgeDevice::~CFX_FxgeDevice() { 1135 CFX_FxgeDevice::~CFX_FxgeDevice() {
1132 if (m_bOwnedBitmap && GetBitmap()) 1136 if (m_bOwnedBitmap && GetBitmap())
1133 delete GetBitmap(); 1137 delete GetBitmap();
1134 } 1138 }
1135 1139
1136 #endif 1140 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698