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

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

Issue 2004203003: fix rotated and alpha bitmaps (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"
11 #include "core/fpdfapi/fpdf_page/pageint.h" 11 #include "core/fpdfapi/fpdf_page/pageint.h"
12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" 12 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h"
13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 13 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h" 14 #include "core/fpdfapi/fpdf_parser/include/cpdf_stream_acc.h"
15 #include "core/fxge/skia/fx_skia_device.h" 15 #include "core/fxge/skia/fx_skia_device.h"
16 16
17 #include "third_party/skia/include/core/SkCanvas.h" 17 #include "third_party/skia/include/core/SkCanvas.h"
18 #include "third_party/skia/include/core/SkColorFilter.h"
18 #include "third_party/skia/include/core/SkColorPriv.h" 19 #include "third_party/skia/include/core/SkColorPriv.h"
19 #include "third_party/skia/include/core/SkPaint.h" 20 #include "third_party/skia/include/core/SkPaint.h"
20 #include "third_party/skia/include/core/SkPath.h" 21 #include "third_party/skia/include/core/SkPath.h"
21 #include "third_party/skia/include/core/SkPictureRecorder.h" 22 #include "third_party/skia/include/core/SkPictureRecorder.h"
22 #include "third_party/skia/include/core/SkStream.h" 23 #include "third_party/skia/include/core/SkStream.h"
23 #include "third_party/skia/include/core/SkTypeface.h" 24 #include "third_party/skia/include/core/SkTypeface.h"
24 #include "third_party/skia/include/effects/SkDashPathEffect.h" 25 #include "third_party/skia/include/effects/SkDashPathEffect.h"
25 #include "third_party/skia/include/effects/SkGradientShader.h" 26 #include "third_party/skia/include/effects/SkGradientShader.h"
26 #include "third_party/skia/include/pathops/SkPathOps.h" 27 #include "third_party/skia/include/pathops/SkPathOps.h"
27 28
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1005 int blend_type) { 1006 int blend_type) {
1006 SkColorType colorType; 1007 SkColorType colorType;
1007 void* buffer = pSource->GetBuffer(); 1008 void* buffer = pSource->GetBuffer();
1008 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage; 1009 std::unique_ptr<uint8_t, FxFreeDeleter> dst8Storage;
1009 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage; 1010 std::unique_ptr<uint32_t, FxFreeDeleter> dst32Storage;
1010 int width = pSource->GetWidth(); 1011 int width = pSource->GetWidth();
1011 int height = pSource->GetHeight(); 1012 int height = pSource->GetHeight();
1012 int rowBytes = pSource->GetPitch(); 1013 int rowBytes = pSource->GetPitch();
1013 switch (pSource->GetBPP()) { 1014 switch (pSource->GetBPP()) {
1014 case 1: { 1015 case 1: {
1015 uint8_t zero = pSource->IsAlphaMask() ? 0xFF : 0x00;
1016 uint8_t one = zero ^ 0xFF;
1017 dst8Storage.reset(FX_Alloc2D(uint8_t, width, height)); 1016 dst8Storage.reset(FX_Alloc2D(uint8_t, width, height));
1018 uint8_t* dst8Pixels = dst8Storage.get(); 1017 uint8_t* dst8Pixels = dst8Storage.get();
1019 for (int y = 0; y < height; ++y) { 1018 for (int y = 0; y < height; ++y) {
1020 const uint8_t* srcRow = 1019 const uint8_t* srcRow =
1021 static_cast<const uint8_t*>(buffer) + y * rowBytes; 1020 static_cast<const uint8_t*>(buffer) + y * rowBytes;
1022 uint8_t* dstRow = dst8Pixels + y * width; 1021 uint8_t* dstRow = dst8Pixels + y * width;
1023 for (int x = 0; x < width; ++x) 1022 for (int x = 0; x < width; ++x)
1024 dstRow[x] = srcRow[x >> 3] & (1 << (~x & 0x07)) ? one : zero; 1023 dstRow[x] = srcRow[x >> 3] & (1 << (~x & 0x07)) ? 0xFF : 0x00;
1025 } 1024 }
1026 buffer = dst8Storage.get(); 1025 buffer = dst8Storage.get();
1027 rowBytes = width; 1026 rowBytes = width;
1028 colorType = SkColorType::kGray_8_SkColorType; 1027 colorType = pSource->IsAlphaMask() ? SkColorType::kAlpha_8_SkColorType
1028 : SkColorType::kGray_8_SkColorType;
1029 } break; 1029 } break;
1030 case 8: 1030 case 8:
1031 colorType = SkColorType::kGray_8_SkColorType; 1031 colorType = SkColorType::kGray_8_SkColorType;
1032 break; 1032 break;
1033 case 24: { 1033 case 24: {
1034 dst32Storage.reset(FX_Alloc2D(uint32_t, width, height)); 1034 dst32Storage.reset(FX_Alloc2D(uint32_t, width, height));
1035 uint32_t* dst32Pixels = dst32Storage.get(); 1035 uint32_t* dst32Pixels = dst32Storage.get();
1036 for (int y = 0; y < height; ++y) { 1036 for (int y = 0; y < height; ++y) {
1037 const uint8_t* srcRow = 1037 const uint8_t* srcRow =
1038 static_cast<const uint8_t*>(buffer) + y * rowBytes; 1038 static_cast<const uint8_t*>(buffer) + y * rowBytes;
1039 uint32_t* dstRow = dst32Pixels + y * width; 1039 uint32_t* dstRow = dst32Pixels + y * width;
1040 for (int x = 0; x < width; ++x) 1040 for (int x = 0; x < width; ++x)
1041 dstRow[x] = SkPackARGB32(0xFF, srcRow[x * 3 + 2], srcRow[x * 3 + 1], 1041 dstRow[x] = SkPackARGB32(0xFF, srcRow[x * 3 + 2], srcRow[x * 3 + 1],
1042 srcRow[x * 3 + 0]); 1042 srcRow[x * 3 + 0]);
1043 } 1043 }
1044 buffer = dst32Storage.get(); 1044 buffer = dst32Storage.get();
1045 rowBytes = width * sizeof(uint32_t); 1045 rowBytes = width * sizeof(uint32_t);
1046 colorType = SkColorType::kN32_SkColorType; 1046 colorType = SkColorType::kN32_SkColorType;
1047 } break; 1047 } break;
1048 case 32: 1048 case 32:
1049 colorType = SkColorType::kN32_SkColorType; 1049 colorType = SkColorType::kN32_SkColorType;
1050 break; 1050 break;
1051 default: 1051 default:
1052 colorType = SkColorType::kUnknown_SkColorType; 1052 colorType = SkColorType::kUnknown_SkColorType;
1053 } 1053 }
1054 SkImageInfo imageInfo = 1054 SkImageInfo imageInfo = SkImageInfo::Make(
1055 SkImageInfo::Make(width, height, colorType, kOpaque_SkAlphaType); 1055 width, height, colorType,
1056 pSource->IsAlphaMask() ? kPremul_SkAlphaType : kOpaque_SkAlphaType);
1056 SkBitmap skBitmap; 1057 SkBitmap skBitmap;
1057 skBitmap.installPixels(imageInfo, buffer, rowBytes, 1058 skBitmap.installPixels(imageInfo, buffer, rowBytes,
1058 nullptr, /* TODO(caryclark) : set color table */ 1059 nullptr, /* TODO(caryclark) : set color table */
1059 nullptr, nullptr); 1060 nullptr, nullptr);
1060 m_pCanvas->save(); 1061 m_pCanvas->save();
1061 bool landscape = !pMatrix->a; 1062 SkMatrix skMatrix;
1062 if (landscape)
1063 m_pCanvas->translate(m_pCanvas->imageInfo().width(), 0);
1064 else
1065 m_pCanvas->translate(pMatrix->e, pMatrix->f + pMatrix->d);
1066
1067 SkMatrix skMatrix = SkMatrix::MakeScale(1.f / width, 1.f / height);
1068 m_pCanvas->concat(skMatrix);
1069 const CFX_Matrix& m = *pMatrix; 1063 const CFX_Matrix& m = *pMatrix;
1070 // note that PDF's y-axis goes up; Skia's y-axis goes down 1064 skMatrix.setAll(m.a / width, -m.c / height, m.c + m.e, m.b / width,
1071 if (landscape) 1065 -m.d / height, m.d + m.f, 0, 0, 1);
1072 skMatrix.setAll(-m.a, -m.b, m.e, m.c, m.d, m.f, 0, 0, 1);
1073 else
1074 skMatrix.setAll(m.a, m.b, 0, -m.c, -m.d, 0, 0, 0, 1);
1075 m_pCanvas->concat(skMatrix); 1066 m_pCanvas->concat(skMatrix);
1076 SkPaint paint; 1067 SkPaint paint;
1077 paint.setAntiAlias(true); 1068 paint.setAntiAlias(true);
1078 paint.setFilterQuality(kHigh_SkFilterQuality); 1069 if (pSource->IsAlphaMask()) {
1070 paint.setColorFilter(
1071 SkColorFilter::MakeModeFilter(argb, SkXfermode::kSrc_Mode));
1072 }
1073 // paint.setFilterQuality(kHigh_SkFilterQuality);
dsinclair 2016/05/25 00:40:18 Remove if not needed.
caryclark 2016/05/25 13:17:20 It's needed some of the time, for some conditions
1079 paint.setXfermodeMode(GetSkiaBlendMode(blend_type)); 1074 paint.setXfermodeMode(GetSkiaBlendMode(blend_type));
1080 paint.setAlpha(bitmap_alpha); 1075 paint.setAlpha(bitmap_alpha);
1081 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint); 1076 m_pCanvas->drawBitmap(skBitmap, 0, 0, &paint);
1082 m_pCanvas->restore(); 1077 m_pCanvas->restore();
1083 return TRUE; 1078 return TRUE;
1084 } 1079 }
1085 1080
1086 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) { 1081 FX_BOOL CFX_SkiaDeviceDriver::ContinueDIBits(void* pHandle, IFX_Pause* pPause) {
1087 if (!m_pBitmap->GetBuffer()) 1082 if (!m_pBitmap->GetBuffer())
1088 return TRUE; 1083 return TRUE;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 SetDeviceDriver(pDriver); 1137 SetDeviceDriver(pDriver);
1143 return true; 1138 return true;
1144 } 1139 }
1145 1140
1146 CFX_FxgeDevice::~CFX_FxgeDevice() { 1141 CFX_FxgeDevice::~CFX_FxgeDevice() {
1147 if (m_bOwnedBitmap && GetBitmap()) 1142 if (m_bOwnedBitmap && GetBitmap())
1148 delete GetBitmap(); 1143 delete GetBitmap();
1149 } 1144 }
1150 1145
1151 #endif 1146 #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