From d5414e5efe0a6a0bce0b5499e2358e2be4cb9b61 Mon Sep 17 00:00:00 2001 From: "commit-bot@chromium.org" Date: Thu, 13 Feb 2014 22:30:38 +0000 Subject: [PATCH] ensure that opaque-only colortypes always report opaque-alphatype BUG=skia: R=scroggo@google.com, djsollen@google.com, reed@google.com Author: reed@chromium.org Review URL: https://codereview.chromium.org/164233006 git-svn-id: http://skia.googlecode.com/svn/trunk@13443 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/core/SkBitmap.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/core/SkBitmap.cpp b/src/core/SkBitmap.cpp index 3418fad7f1..951bb6fe98 100644 --- a/src/core/SkBitmap.cpp +++ b/src/core/SkBitmap.cpp @@ -253,7 +253,14 @@ static bool validate_alphaType(SkColorType colorType, SkAlphaType alphaType, return true; } -bool SkBitmap::setConfig(const SkImageInfo& info, size_t rowBytes) { +bool SkBitmap::setConfig(const SkImageInfo& origInfo, size_t rowBytes) { + SkImageInfo info = origInfo; + + if (!validate_alphaType(info.fColorType, info.fAlphaType, + &info.fAlphaType)) { + return reset_return_false(this); + } + // require that rowBytes fit in 31bits int64_t mrb = info.minRowBytes64(); if ((int32_t)mrb != mrb) { @@ -1619,6 +1626,13 @@ SkBitmap::RLEPixels::~RLEPixels() { #ifdef SK_DEBUG void SkBitmap::validate() const { fInfo.validate(); + + // ImageInfo may not require this, but Bitmap ensures that opaque-only + // colorTypes report opaque for their alphatype + if (kRGB_565_SkColorType == fInfo.colorType()) { + SkASSERT(kOpaque_SkAlphaType == fInfo.alphaType()); + } + SkASSERT(fInfo.validRowBytes(fRowBytes)); uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImmutable_Flag; #ifdef SK_BUILD_FOR_ANDROID