Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1539)

Unified Diff: tests/ImageFilterTest.cpp

Issue 23533042: Fixed issues found by fuzzer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/ImageFilterTest.cpp
diff --git a/tests/ImageFilterTest.cpp b/tests/ImageFilterTest.cpp
index da1a719675d1177bf83759899aca39fc28f93155..0032c7f648dcb33323a47555f10ef4649b713673 100644
--- a/tests/ImageFilterTest.cpp
+++ b/tests/ImageFilterTest.cpp
@@ -7,12 +7,44 @@
*/
#include "Test.h"
+#include "SkBicubicImageFilter.h"
+#include "SkBitmap.h"
+#include "SkBitmapDevice.h"
+#include "SkBitmapSource.h"
+#include "SkCanvas.h"
#include "SkColorMatrixFilter.h"
#include "SkColorFilterImageFilter.h"
+#include "SkDeviceImageFilterProxy.h"
+#include "SkLightingImageFilter.h"
#include "SkRect.h"
class ImageFilterTest {
public:
+ static const int kBitmapSize = 4;
+
+ static void make_small_bitmap(SkBitmap& bitmap) {
+ bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize);
+ bitmap.allocPixels();
+ SkBitmapDevice device(bitmap);
+ SkCanvas canvas(&device);
+ canvas.clear(0x00000000);
+ SkPaint darkPaint;
+ darkPaint.setColor(0xFF804020);
+ SkPaint lightPaint;
+ lightPaint.setColor(0xFF244484);
+ const int i = kBitmapSize / 4;
+ for (int y = 0; y < kBitmapSize; y += i) {
+ for (int x = 0; x < kBitmapSize; x += i) {
+ canvas.save();
+ canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
+ canvas.drawRect(SkRect::MakeXYWH(0, 0, i, i), darkPaint);
+ canvas.drawRect(SkRect::MakeXYWH(i, 0, i, i), lightPaint);
+ canvas.drawRect(SkRect::MakeXYWH(0, i, i, i), lightPaint);
+ canvas.drawRect(SkRect::MakeXYWH(i, i, i, i), darkPaint);
+ canvas.restore();
+ }
+ }
+ }
static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) {
SkScalar s = SkFloatToScalar(amount);
@@ -70,6 +102,47 @@ public:
SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropRect));
REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL));
}
+
+ {
+ // Tests pass by not asserting
+ SkBitmap bitmap, result;
+ make_small_bitmap(bitmap);
+ result.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize);
+ result.allocPixels();
+
+ {
+ // This tests for :
+ // 1 ) location at (0,0,1)
+ SkPoint3 location(0, 0, SK_Scalar1);
+ // 2 ) location and target at same value
+ SkPoint3 target(location.fX, location.fY, location.fZ);
+ // 3 ) large negative specular exponent value
+ SkScalar specularExponent = SkFloatToScalar(-1000);
+
+ SkPaint paint;
+ paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecular(
+ location, target, specularExponent, SkFloatToScalar(180),
+ 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
+ new SkBitmapSource(bitmap)))->unref();
+ SkCanvas canvas(result);
+ SkRect r = SkRect::MakeWH(kBitmapSize, kBitmapSize);
+ canvas.drawRect(r, paint);
+ }
+
+ {
+ // This tests for scale bringing width to 0
+ SkSize scale = SkSize::Make(SkFloatToScalar(-0.001), SK_Scalar1);
+ SkAutoTUnref<SkBicubicImageFilter> bicubic(
+ SkBicubicImageFilter::CreateMitchell(
+ scale, new SkBitmapSource(bitmap)));
+ SkBitmapDevice device(bitmap);
+ SkDeviceImageFilterProxy proxy(&device);
+ SkIPoint loc = SkIPoint::Make(0, 0);
+ // An empty input should early return and return false
+ REPORTER_ASSERT(reporter,
+ !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result, &loc));
+ }
+ }
}
};
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698