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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/effects/SkLightingImageFilter.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2013 Google Inc. 3 * Copyright 2013 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "Test.h" 9 #include "Test.h"
10 #include "SkBicubicImageFilter.h"
11 #include "SkBitmap.h"
12 #include "SkBitmapDevice.h"
13 #include "SkBitmapSource.h"
14 #include "SkCanvas.h"
10 #include "SkColorMatrixFilter.h" 15 #include "SkColorMatrixFilter.h"
11 #include "SkColorFilterImageFilter.h" 16 #include "SkColorFilterImageFilter.h"
17 #include "SkDeviceImageFilterProxy.h"
18 #include "SkLightingImageFilter.h"
12 #include "SkRect.h" 19 #include "SkRect.h"
13 20
14 class ImageFilterTest { 21 class ImageFilterTest {
15 public: 22 public:
23 static const int kBitmapSize = 4;
24
25 static void make_small_bitmap(SkBitmap& bitmap) {
26 bitmap.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSize);
27 bitmap.allocPixels();
28 SkBitmapDevice device(bitmap);
29 SkCanvas canvas(&device);
30 canvas.clear(0x00000000);
31 SkPaint darkPaint;
32 darkPaint.setColor(0xFF804020);
33 SkPaint lightPaint;
34 lightPaint.setColor(0xFF244484);
35 const int i = kBitmapSize / 4;
36 for (int y = 0; y < kBitmapSize; y += i) {
37 for (int x = 0; x < kBitmapSize; x += i) {
38 canvas.save();
39 canvas.translate(SkIntToScalar(x), SkIntToScalar(y));
40 canvas.drawRect(SkRect::MakeXYWH(0, 0, i, i), darkPaint);
41 canvas.drawRect(SkRect::MakeXYWH(i, 0, i, i), lightPaint);
42 canvas.drawRect(SkRect::MakeXYWH(0, i, i, i), lightPaint);
43 canvas.drawRect(SkRect::MakeXYWH(i, i, i, i), darkPaint);
44 canvas.restore();
45 }
46 }
47 }
16 48
17 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) { 49 static SkImageFilter* make_scale(float amount, SkImageFilter* input = NULL) {
18 SkScalar s = SkFloatToScalar(amount); 50 SkScalar s = SkFloatToScalar(amount);
19 SkScalar matrix[20] = { s, 0, 0, 0, 0, 51 SkScalar matrix[20] = { s, 0, 0, 0, 0,
20 0, s, 0, 0, 0, 52 0, s, 0, 0, 0,
21 0, 0, s, 0, 0, 53 0, 0, s, 0, 0,
22 0, 0, 0, s, 0 }; 54 0, 0, 0, s, 0 };
23 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix)); 55 SkAutoTUnref<SkColorFilter> filter(new SkColorMatrixFilter(matrix));
24 return SkColorFilterImageFilter::Create(filter, input); 56 return SkColorFilterImageFilter::Create(filter, input);
25 } 57 }
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL)); 95 REPORTER_ASSERT(reporter, true == gray->asColorFilter(NULL));
64 } 96 }
65 97
66 { 98 {
67 // Check that a color filter image filter with a crop rect cannot 99 // Check that a color filter image filter with a crop rect cannot
68 // be expressed as a color filter. 100 // be expressed as a color filter.
69 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100); 101 SkIRect cropRect = SkIRect::MakeXYWH(0, 0, 100, 100);
70 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropR ect)); 102 SkAutoTUnref<SkImageFilter> grayWithCrop(make_grayscale(NULL, &cropR ect));
71 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL) ); 103 REPORTER_ASSERT(reporter, false == grayWithCrop->asColorFilter(NULL) );
72 } 104 }
105
106 {
107 // Tests pass by not asserting
108 SkBitmap bitmap, result;
109 make_small_bitmap(bitmap);
110 result.setConfig(SkBitmap::kARGB_8888_Config, kBitmapSize, kBitmapSi ze);
111 result.allocPixels();
112
113 {
114 // This tests for :
115 // 1 ) location at (0,0,1)
116 SkPoint3 location(0, 0, SK_Scalar1);
117 // 2 ) location and target at same value
118 SkPoint3 target(location.fX, location.fY, location.fZ);
119 // 3 ) large negative specular exponent value
120 SkScalar specularExponent = SkFloatToScalar(-1000);
121
122 SkPaint paint;
123 paint.setImageFilter(SkLightingImageFilter::CreateSpotLitSpecula r(
124 location, target, specularExponent, SkFloatToScalar(180) ,
125 0xFFFFFFFF, SK_Scalar1, SK_Scalar1, SK_Scalar1,
126 new SkBitmapSource(bitmap)))->unref();
127 SkCanvas canvas(result);
128 SkRect r = SkRect::MakeWH(kBitmapSize, kBitmapSize);
129 canvas.drawRect(r, paint);
130 }
131
132 {
133 // This tests for scale bringing width to 0
134 SkSize scale = SkSize::Make(SkFloatToScalar(-0.001), SK_Scalar1) ;
135 SkAutoTUnref<SkBicubicImageFilter> bicubic(
136 SkBicubicImageFilter::CreateMitchell(
137 scale, new SkBitmapSource(bitmap)));
138 SkBitmapDevice device(bitmap);
139 SkDeviceImageFilterProxy proxy(&device);
140 SkIPoint loc = SkIPoint::Make(0, 0);
141 // An empty input should early return and return false
142 REPORTER_ASSERT(reporter,
143 !bicubic->filterImage(&proxy, bitmap, SkMatrix::I(), &result , &loc));
144 }
145 }
73 } 146 }
74 }; 147 };
75 148
76 149
77 #include "TestClassDef.h" 150 #include "TestClassDef.h"
78 DEFINE_TESTCLASS("ImageFilterTest", ImageFilterTestClass, ImageFilterTest::Test) 151 DEFINE_TESTCLASS("ImageFilterTest", ImageFilterTestClass, ImageFilterTest::Test)
OLDNEW
« 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