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
This commit is contained in:
commit-bot@chromium.org 2014-02-13 22:30:38 +00:00
parent fa9e5fa42a
commit d5414e5efe

View File

@ -253,7 +253,14 @@ static bool validate_alphaType(SkColorType colorType, SkAlphaType alphaType,
return true; 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 // require that rowBytes fit in 31bits
int64_t mrb = info.minRowBytes64(); int64_t mrb = info.minRowBytes64();
if ((int32_t)mrb != mrb) { if ((int32_t)mrb != mrb) {
@ -1619,6 +1626,13 @@ SkBitmap::RLEPixels::~RLEPixels() {
#ifdef SK_DEBUG #ifdef SK_DEBUG
void SkBitmap::validate() const { void SkBitmap::validate() const {
fInfo.validate(); 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)); SkASSERT(fInfo.validRowBytes(fRowBytes));
uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImmutable_Flag; uint8_t allFlags = kImageIsOpaque_Flag | kImageIsVolatile_Flag | kImageIsImmutable_Flag;
#ifdef SK_BUILD_FOR_ANDROID #ifdef SK_BUILD_FOR_ANDROID