Allow 0-width SkBitmap in setConfig.

Previously, SkBitmap::setConfig would allow zero height, but not zero
width.  This is changed for consistancy.

A unit test was added.

BUG=
R=reed@google.com, scroggo@google.com

Review URL: https://codereview.chromium.org/111953004

git-svn-id: http://skia.googlecode.com/svn/trunk@12673 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
halcanary@google.com 2013-12-13 18:29:51 +00:00
parent 0daa1adb03
commit 4428734907
3 changed files with 32 additions and 1 deletions

View File

@ -32,6 +32,7 @@
'../tests/AnnotationTest.cpp', '../tests/AnnotationTest.cpp',
'../tests/ARGBImageEncoderTest.cpp', '../tests/ARGBImageEncoderTest.cpp',
'../tests/AtomicTest.cpp', '../tests/AtomicTest.cpp',
'../tests/BitmapTest.cpp',
'../tests/BitmapCopyTest.cpp', '../tests/BitmapCopyTest.cpp',
'../tests/BitmapGetColorTest.cpp', '../tests/BitmapGetColorTest.cpp',
'../tests/BitmapHasherTest.cpp', '../tests/BitmapHasherTest.cpp',

View File

@ -298,7 +298,7 @@ bool SkBitmap::setConfig(Config config, int width, int height, size_t rowBytes,
} }
if (rowBytes == 0) { if (rowBytes == 0) {
rowBytes = SkBitmap::ComputeRowBytes(config, width); rowBytes = SkBitmap::ComputeRowBytes(config, width);
if (0 == rowBytes && kNo_Config != config) { if (0 == rowBytes && kNo_Config != config && width > 0) {
goto BAD_CONFIG; goto BAD_CONFIG;
} }
} }

30
tests/BitmapTest.cpp Normal file
View File

@ -0,0 +1,30 @@
/*
* Copyright 2013 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkBitmap.h"
#include "Test.h"
#include "TestClassDef.h"
/**
* This test contains basic sanity checks concerning bitmaps.
*/
DEF_TEST(Bitmap, reporter) {
const SkBitmap::Config conf = SkBitmap::kARGB_8888_Config;
// Zero-sized bitmaps are allowed
for (int width = 0; width < 2; ++width) {
for (int height = 0; height < 2; ++height) {
SkBitmap bm;
bool setConf = bm.setConfig(conf, width, height);
REPORTER_ASSERT(reporter, setConf);
if (setConf) {
REPORTER_ASSERT(reporter, bm.allocPixels(NULL));
}
REPORTER_ASSERT(reporter, (width & height) != bm.empty());
}
}
}