Test scaling for small images
We don't want to test small images on Gold because they are
not interested to look at. Instead, I wrote a unit test to
verify that scaling small images does not cause crashes.
BUG=skia:
Review URL: https://codereview.chromium.org/1287863004
diff --git a/tests/CodexTest.cpp b/tests/CodexTest.cpp
index 80164b2..ec6d645 100644
--- a/tests/CodexTest.cpp
+++ b/tests/CodexTest.cpp
@@ -10,6 +10,7 @@
#include "SkCodec.h"
#include "SkMD5.h"
#include "SkRandom.h"
+#include "SkScaledCodec.h"
#include "SkScanlineDecoder.h"
#include "Test.h"
@@ -281,17 +282,19 @@
SkDebugf("Missing resource '%s'\n", path);
return;
}
- SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach()));
+ SkAutoTDelete<SkCodec> codec(SkScaledCodec::NewFromStream(stream.detach()));
if (!codec) {
ERRORF(r, "Unable to create codec '%s'", path);
return;
}
// Check that the decode is successful for a variety of scales
- for (float scale = -0.05f; scale < 2.0f; scale += 0.05f) {
+ for (float scale = 0.05f; scale < 2.0f; scale += 0.05f) {
// Scale the output dimensions
SkISize scaledDims = codec->getScaledDimensions(scale);
- SkImageInfo scaledInfo = codec->getInfo().makeWH(scaledDims.width(), scaledDims.height());
+ SkImageInfo scaledInfo = codec->getInfo()
+ .makeWH(scaledDims.width(), scaledDims.height())
+ .makeColorType(kN32_SkColorType);
// Set up for the decode
size_t rowBytes = scaledDims.width() * sizeof(SkPMColor);
@@ -312,6 +315,21 @@
test_dimensions(r, "grayscale.jpg");
test_dimensions(r, "mandrill_512_q075.jpg");
test_dimensions(r, "randPixels.jpg");
+
+ // Decoding small images with very large scaling factors is a potential
+ // source of bugs and crashes. We disable these tests in Gold because
+ // tiny images are not very useful to look at.
+ // Here we make sure that we do not crash or access illegal memory when
+ // performing scaled decodes on small images.
+ test_dimensions(r, "1x1.png");
+ test_dimensions(r, "2x2.png");
+ test_dimensions(r, "3x3.png");
+ test_dimensions(r, "3x1.png");
+ test_dimensions(r, "1x1.png");
+ test_dimensions(r, "16x1.png");
+ test_dimensions(r, "1x16.png");
+ test_dimensions(r, "mandrill_16.png");
+
}
static void test_invalid(skiatest::Reporter* r, const char path[]) {