aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/pdf
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2017-07-20 14:15:25 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-20 19:10:22 +0000
commit3f4671871fac8e5439440ce756d0666bc2a96f46 (patch)
treeb8b5778bb1b1d50ce7b532dbc93c073406bd90d2 /src/pdf
parent2371da07315efc8918c7ea7666006a683323c1fb (diff)
SkPDF: handle unsupported colortypes (e.g. F16) uniformly
Change-Id: I1a9e7a749b5be9dc552608493e23a03db9b2c5b1 Reviewed-on: https://skia-review.googlesource.com/25161 Commit-Queue: Hal Canary <halcanary@google.com> Reviewed-by: Ben Wagner <bungeman@google.com>
Diffstat (limited to 'src/pdf')
-rw-r--r--src/pdf/SkPDFBitmap.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/pdf/SkPDFBitmap.cpp b/src/pdf/SkPDFBitmap.cpp
index e28800bf99..2360953a2a 100644
--- a/src/pdf/SkPDFBitmap.cpp
+++ b/src/pdf/SkPDFBitmap.cpp
@@ -128,11 +128,22 @@ static size_t pixel_count(const SkBitmap& bm) {
return SkToSizeT(bm.width()) * SkToSizeT(bm.height());
}
-static const SkBitmap& not4444(const SkBitmap& input, SkBitmap* copy) {
- if (input.colorType() != kARGB_4444_SkColorType) {
- return input;
+static const SkBitmap& supported_colortype(const SkBitmap& input, SkBitmap* copy) {
+ switch (input.colorType()) {
+ case kUnknown_SkColorType:
+ SkDEBUGFAIL("kUnknown_SkColorType");
+ case kAlpha_8_SkColorType:
+ case kRGB_565_SkColorType:
+ case kRGBA_8888_SkColorType:
+ case kBGRA_8888_SkColorType:
+ case kGray_8_SkColorType:
+ return input; // supported
+ default:
+ // if other colortypes are introduced in the future,
+ // they will hit this code.
+ break;
}
- // ARGB_4444 is rarely used, so we can do a wasteful tmp copy.
+ // Fallback for rarely used ARGB_4444 and ARGB_F16: do a wasteful tmp copy.
copy->allocPixels(input.info().makeColorType(kN32_SkColorType));
SkAssertResult(input.readPixels(copy->info(), copy->getPixels(), copy->rowBytes(), 0, 0));
copy->setImmutable();
@@ -141,18 +152,16 @@ static const SkBitmap& not4444(const SkBitmap& input, SkBitmap* copy) {
static size_t pdf_color_component_count(SkColorType ct) {
switch (ct) {
+ case kUnknown_SkColorType:
+ SkDEBUGFAIL("kUnknown_SkColorType");
+ case kAlpha_8_SkColorType:
+ case kGray_8_SkColorType:
+ return 1;
case kRGB_565_SkColorType:
- case kARGB_4444_SkColorType:
case kRGBA_8888_SkColorType:
case kBGRA_8888_SkColorType:
+ default: // converted to N32
return 3;
- case kAlpha_8_SkColorType:
- case kGray_8_SkColorType:
- return 1;
- case kUnknown_SkColorType:
- default:
- SkDEBUGFAIL("unexpected color type");
- return 0;
}
}
@@ -164,7 +173,7 @@ static void bitmap_to_pdf_pixels(const SkBitmap& bitmap, SkWStream* out) {
return;
}
SkBitmap copy;
- const SkBitmap& bm = not4444(bitmap, &copy);
+ const SkBitmap& bm = supported_colortype(bitmap, &copy);
SkColorType colorType = bm.colorType();
SkAlphaType alphaType = bm.alphaType();
switch (colorType) {
@@ -238,7 +247,7 @@ static void bitmap_alpha_to_a8(const SkBitmap& bitmap, SkWStream* out) {
return;
}
SkBitmap copy;
- const SkBitmap& bm = not4444(bitmap, &copy);
+ const SkBitmap& bm = supported_colortype(bitmap, &copy);
SkColorType colorType = bm.colorType();
switch (colorType) {
case kRGBA_8888_SkColorType: