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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 300153002: Adding new filters to fuzzer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 7 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
« no previous file with comments | « no previous file | 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 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 #include "SampleCode.h" 7 #include "SampleCode.h"
8 #include "SkAlphaThresholdFilter.h"
8 #include "SkBicubicImageFilter.h" 9 #include "SkBicubicImageFilter.h"
9 #include "SkBitmapDevice.h" 10 #include "SkBitmapDevice.h"
10 #include "SkBitmapSource.h" 11 #include "SkBitmapSource.h"
11 #include "SkBlurImageFilter.h" 12 #include "SkBlurImageFilter.h"
12 #include "SkCanvas.h" 13 #include "SkCanvas.h"
13 #include "SkColorFilter.h" 14 #include "SkColorFilter.h"
14 #include "SkColorFilterImageFilter.h" 15 #include "SkColorFilterImageFilter.h"
15 #include "SkComposeImageFilter.h" 16 #include "SkComposeImageFilter.h"
16 #include "SkData.h" 17 #include "SkData.h"
17 #include "SkDisplacementMapEffect.h" 18 #include "SkDisplacementMapEffect.h"
18 #include "SkDropShadowImageFilter.h" 19 #include "SkDropShadowImageFilter.h"
19 #include "SkFlattenableSerialization.h" 20 #include "SkFlattenableSerialization.h"
20 #include "SkLightingImageFilter.h" 21 #include "SkLightingImageFilter.h"
21 #include "SkMagnifierImageFilter.h" 22 #include "SkMagnifierImageFilter.h"
23 #include "SkMatrixImageFilter.h"
24 #include "SkMatrixConvolutionImageFilter.h"
22 #include "SkMergeImageFilter.h" 25 #include "SkMergeImageFilter.h"
23 #include "SkMorphologyImageFilter.h" 26 #include "SkMorphologyImageFilter.h"
24 #include "SkOffsetImageFilter.h" 27 #include "SkOffsetImageFilter.h"
25 #include "SkPerlinNoiseShader.h" 28 #include "SkPerlinNoiseShader.h"
26 #include "SkPictureImageFilter.h" 29 #include "SkPictureImageFilter.h"
27 #include "SkRandom.h" 30 #include "SkRandom.h"
28 #include "SkRectShaderImageFilter.h" 31 #include "SkRectShaderImageFilter.h"
32 #include "SkTestImageFilters.h"
29 #include "SkTileImageFilter.h" 33 #include "SkTileImageFilter.h"
30 #include "SkView.h" 34 #include "SkView.h"
31 #include "SkXfermodeImageFilter.h" 35 #include "SkXfermodeImageFilter.h"
32 #include <stdio.h> 36 #include <stdio.h>
33 #include <time.h> 37 #include <time.h>
34 38
35 //#define SK_ADD_RANDOM_BIT_FLIPS 39 //#define SK_ADD_RANDOM_BIT_FLIPS
36 //#define SK_FUZZER_IS_VERBOSE 40 //#define SK_FUZZER_IS_VERBOSE
37 41
38 static const uint32_t kSeed = (uint32_t)(time(NULL)); 42 static const uint32_t kSeed = (uint32_t)(time(NULL));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 92
89 static SkScalar make_scalar(bool positiveOnly = false) { 93 static SkScalar make_scalar(bool positiveOnly = false) {
90 return make_number(positiveOnly); 94 return make_number(positiveOnly);
91 } 95 }
92 96
93 static SkRect make_rect() { 97 static SkRect make_rect() {
94 return SkRect::MakeWH(SkIntToScalar(R(static_cast<float>(kBitmapSize))), 98 return SkRect::MakeWH(SkIntToScalar(R(static_cast<float>(kBitmapSize))),
95 SkIntToScalar(R(static_cast<float>(kBitmapSize)))); 99 SkIntToScalar(R(static_cast<float>(kBitmapSize))));
96 } 100 }
97 101
102 static SkRegion make_region() {
103 SkIRect iRegion = SkIRect::MakeXYWH(SkIntToScalar(R(static_cast<float>(kBitm apSize))),
104 SkIntToScalar(R(static_cast<float>(kBitm apSize))),
105 SkIntToScalar(R(static_cast<float>(kBitm apSize))),
106 SkIntToScalar(R(static_cast<float>(kBitm apSize))));
107 return SkRegion(iRegion);
108 }
109
110 static SkMatrix make_matrix() {
111 SkMatrix m;
112 for (int i = 0; i < 9; ++i) {
113 m[i] = make_scalar();
114 }
115 return m;
116 }
117
98 static SkXfermode::Mode make_xfermode() { 118 static SkXfermode::Mode make_xfermode() {
99 return static_cast<SkXfermode::Mode>(R(SkXfermode::kLastMode+1)); 119 return static_cast<SkXfermode::Mode>(R(SkXfermode::kLastMode+1));
100 } 120 }
101 121
102 static SkColor make_color() { 122 static SkColor make_color() {
103 return (R(2) == 1) ? 0xFFC0F0A0 : 0xFF000090; 123 return (R(2) == 1) ? 0xFFC0F0A0 : 0xFF000090;
104 } 124 }
105 125
106 static SkPoint3 make_point() { 126 static SkPoint3 make_point() {
107 return SkPoint3(make_scalar(), make_scalar(), make_scalar(true)); 127 return SkPoint3(make_scalar(), make_scalar(), make_scalar(true));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint); 229 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint);
210 } 230 }
211 #endif 231 #endif
212 232
213 static SkImageFilter* make_image_filter(bool canBeNull = true) { 233 static SkImageFilter* make_image_filter(bool canBeNull = true) {
214 SkImageFilter* filter = 0; 234 SkImageFilter* filter = 0;
215 235
216 // Add a 1 in 3 chance to get a NULL input 236 // Add a 1 in 3 chance to get a NULL input
217 if (canBeNull && (R(3) == 1)) { return filter; } 237 if (canBeNull && (R(3) == 1)) { return filter; }
218 238
219 enum { BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER, XFERMODE, OFFSET, COMPOSE, 239 enum { ALPHA_THRESHOLD, BICUBIC, MERGE, COLOR, BLUR, MAGNIFIER,
240 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
220 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, 241 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
221 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; 242 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS };
222 243
223 switch (R(NUM_FILTERS)) { 244 switch (R(NUM_FILTERS)) {
245 case ALPHA_THRESHOLD:
246 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar());
247 break;
224 case BICUBIC: 248 case BICUBIC:
225 // Scale is set to 1 here so that it can fit in the DAG without resizing the output 249 // Scale is set to 1 here so that it can fit in the DAG without resizing the output
226 filter = SkBicubicImageFilter::CreateMitchell(SkSize::Make(1, 1), make_i mage_filter()); 250 filter = SkBicubicImageFilter::CreateMitchell(SkSize::Make(1, 1), make_i mage_filter());
227 break; 251 break;
228 case MERGE: 252 case MERGE:
229 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); 253 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode());
230 break; 254 break;
231 case COLOR: 255 case COLOR:
232 { 256 {
233 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ? 257 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ?
234 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) : 258 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) :
235 SkColorFilter::CreateLightingFilter(make_color(), make_color()) ); 259 SkColorFilter::CreateLightingFilter(make_color(), make_color()) );
236 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 260 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
237 } 261 }
238 break; 262 break;
239 case BLUR: 263 case BLUR:
240 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter()); 264 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
241 break; 265 break;
242 case MAGNIFIER: 266 case MAGNIFIER:
243 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true)); 267 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
244 break; 268 break;
269 case DOWN_SAMPLE:
270 filter = SkDownSampleImageFilter::Create(make_scalar());
271 break;
245 case XFERMODE: 272 case XFERMODE:
246 { 273 {
247 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(make_xfermode())); 274 SkAutoTUnref<SkXfermode> mode(SkXfermode::Create(make_xfermode()));
248 filter = SkXfermodeImageFilter::Create(mode, make_image_filter(), make_i mage_filter()); 275 filter = SkXfermodeImageFilter::Create(mode, make_image_filter(), make_i mage_filter());
249 } 276 }
250 break; 277 break;
251 case OFFSET: 278 case OFFSET:
252 filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_ image_filter()); 279 filter = SkOffsetImageFilter::Create(make_scalar(), make_scalar(), make_ image_filter());
253 break; 280 break;
281 case MATRIX:
282 filter = SkMatrixImageFilter::Create(make_matrix(),
283 (SkPaint::FilterLevel)R(4),
284 make_image_filter());
285 break;
286 case MATRIX_CONVOLUTION:
287 {
288 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize),
289 SkIntToScalar(kBitmapSize)) );
290 SkISize size = SkISize::Make(R(10)+1, R(10)+1);
291 int arraySize = size.width() * size.height();
292 SkTArray<SkScalar> kernel(arraySize);
293 for (int i = 0; i < arraySize; ++i) {
294 kernel.push_back() = make_scalar();
295 }
296 SkIPoint kernelOffset = SkIPoint::Make(R(size.width()), R(size.height()) );
297 filter = SkMatrixConvolutionImageFilter::Create(size,
298 kernel.begin(),
299 make_scalar(),
300 make_scalar(),
301 kernelOffset,
302 (SkMatrixConvolutionImag eFilter::TileMode)R(3),
303 R(2) == 1,
304 make_image_filter(),
305 &cropR);
306 }
307 break;
254 case COMPOSE: 308 case COMPOSE:
255 filter = SkComposeImageFilter::Create(make_image_filter(), make_image_fi lter()); 309 filter = SkComposeImageFilter::Create(make_image_filter(), make_image_fi lter());
256 break; 310 break;
257 case DISTANT_LIGHT: 311 case DISTANT_LIGHT:
258 filter = (R(2) == 1) ? 312 filter = (R(2) == 1) ?
259 SkLightingImageFilter::CreateDistantLitDiffuse(make_point(), 313 SkLightingImageFilter::CreateDistantLitDiffuse(make_point(),
260 make_color(), make_scalar(), make_scalar(), make_image_filter() ) : 314 make_color(), make_scalar(), make_scalar(), make_image_filter() ) :
261 SkLightingImageFilter::CreateDistantLitSpecular(make_point(), 315 SkLightingImageFilter::CreateDistantLitSpecular(make_point(),
262 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10) ), 316 make_color(), make_scalar(), make_scalar(), SkIntToScalar(R(10) ),
263 make_image_filter()); 317 make_image_filter());
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 481 }
428 482
429 private: 483 private:
430 typedef SkView INHERITED; 484 typedef SkView INHERITED;
431 }; 485 };
432 486
433 ////////////////////////////////////////////////////////////////////////////// 487 //////////////////////////////////////////////////////////////////////////////
434 488
435 static SkView* MyFactory() { return new ImageFilterFuzzView; } 489 static SkView* MyFactory() { return new ImageFilterFuzzView; }
436 static SkViewRegister reg(MyFactory); 490 static SkViewRegister reg(MyFactory);
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698