OLD | NEW |
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 "SkAlphaThresholdFilter.h" |
9 #include "SkBitmapSource.h" | 9 #include "SkBitmapSource.h" |
10 #include "SkBlurImageFilter.h" | 10 #include "SkBlurImageFilter.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 #include "SkTestImageFilters.h" | 32 #include "SkTestImageFilters.h" |
33 #include "SkTileImageFilter.h" | 33 #include "SkTileImageFilter.h" |
34 #include "SkView.h" | 34 #include "SkView.h" |
35 #include "SkXfermodeImageFilter.h" | 35 #include "SkXfermodeImageFilter.h" |
36 #include <stdio.h> | 36 #include <stdio.h> |
37 #include <time.h> | 37 #include <time.h> |
38 | 38 |
39 //#define SK_ADD_RANDOM_BIT_FLIPS | 39 //#define SK_ADD_RANDOM_BIT_FLIPS |
40 //#define SK_FUZZER_IS_VERBOSE | 40 //#define SK_FUZZER_IS_VERBOSE |
41 | 41 |
42 static const uint32_t kSeed = (uint32_t)(time(NULL)); | 42 static const uint32_t kSeed = (uint32_t)(time(nullptr)); |
43 static SkRandom gRand(kSeed); | 43 static SkRandom gRand(kSeed); |
44 static bool return_large = false; | 44 static bool return_large = false; |
45 static bool return_undef = false; | 45 static bool return_undef = false; |
46 | 46 |
47 static const int kBitmapSize = 24; | 47 static const int kBitmapSize = 24; |
48 | 48 |
49 static int R(float x) { | 49 static int R(float x) { |
50 return (int)floor(SkScalarToFloat(gRand.nextUScalar1()) * x); | 50 return (int)floor(SkScalarToFloat(gRand.nextUScalar1()) * x); |
51 } | 51 } |
52 | 52 |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 *cubeDimension = size; | 238 *cubeDimension = size; |
239 } | 239 } |
240 return data; | 240 return data; |
241 } | 241 } |
242 | 242 |
243 static void drawSomething(SkCanvas* canvas) { | 243 static void drawSomething(SkCanvas* canvas) { |
244 SkPaint paint; | 244 SkPaint paint; |
245 | 245 |
246 canvas->save(); | 246 canvas->save(); |
247 canvas->scale(0.5f, 0.5f); | 247 canvas->scale(0.5f, 0.5f); |
248 canvas->drawBitmap(make_bitmap(), 0, 0, NULL); | 248 canvas->drawBitmap(make_bitmap(), 0, 0, nullptr); |
249 canvas->restore(); | 249 canvas->restore(); |
250 | 250 |
251 paint.setAntiAlias(true); | 251 paint.setAntiAlias(true); |
252 | 252 |
253 paint.setColor(SK_ColorRED); | 253 paint.setColor(SK_ColorRED); |
254 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2
), SkIntToScalar(kBitmapSize/3), paint); | 254 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2
), SkIntToScalar(kBitmapSize/3), paint); |
255 paint.setColor(SK_ColorBLACK); | 255 paint.setColor(SK_ColorBLACK); |
256 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); | 256 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); |
257 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k
BitmapSize/4), paint); | 257 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k
BitmapSize/4), paint); |
258 } | 258 } |
259 | 259 |
260 static SkImageFilter* make_image_filter(bool canBeNull = true) { | 260 static SkImageFilter* make_image_filter(bool canBeNull = true) { |
261 SkImageFilter* filter = 0; | 261 SkImageFilter* filter = 0; |
262 | 262 |
263 // Add a 1 in 3 chance to get a NULL input | 263 // Add a 1 in 3 chance to get a nullptr input |
264 if (canBeNull && (R(3) == 1)) { return filter; } | 264 if (canBeNull && (R(3) == 1)) { return filter; } |
265 | 265 |
266 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, | 266 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, |
267 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, | 267 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, |
268 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, | 268 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, |
269 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; | 269 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; |
270 | 270 |
271 switch (R(NUM_FILTERS)) { | 271 switch (R(NUM_FILTERS)) { |
272 case ALPHA_THRESHOLD: | 272 case ALPHA_THRESHOLD: |
273 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma
ke_scalar()); | 273 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma
ke_scalar()); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 SkPerlinNoiseShader::CreateTurbulence( | 373 SkPerlinNoiseShader::CreateTurbulence( |
374 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); | 374 make_scalar(true), make_scalar(true), R(10.0f), make_scalar())); |
375 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), | 375 SkImageFilter::CropRect cropR(SkRect::MakeWH(SkIntToScalar(kBitmapSize), |
376 SkIntToScalar(kBitmapSize))
); | 376 SkIntToScalar(kBitmapSize))
); |
377 filter = SkRectShaderImageFilter::Create(shader, &cropR); | 377 filter = SkRectShaderImageFilter::Create(shader, &cropR); |
378 } | 378 } |
379 break; | 379 break; |
380 case DROP_SHADOW: | 380 case DROP_SHADOW: |
381 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m
ake_scalar(true), | 381 filter = SkDropShadowImageFilter::Create(make_scalar(), make_scalar(), m
ake_scalar(true), |
382 make_scalar(true), make_color(), make_shadow_mode(), make_im
age_filter(), | 382 make_scalar(true), make_color(), make_shadow_mode(), make_im
age_filter(), |
383 NULL); | 383 nullptr); |
384 break; | 384 break; |
385 case MORPHOLOGY: | 385 case MORPHOLOGY: |
386 if (R(2) == 1) { | 386 if (R(2) == 1) { |
387 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz
e)), | 387 filter = SkDilateImageFilter::Create(R(static_cast<float>(kBitmapSiz
e)), |
388 R(static_cast<float>(kBitmapSize)), make_image_filter()); | 388 R(static_cast<float>(kBitmapSize)), make_image_filter()); |
389 } else { | 389 } else { |
390 filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize
)), | 390 filter = SkErodeImageFilter::Create(R(static_cast<float>(kBitmapSize
)), |
391 R(static_cast<float>(kBitmapSize)), make_image_filter()); | 391 R(static_cast<float>(kBitmapSize)), make_image_filter()); |
392 } | 392 } |
393 break; | 393 break; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 } | 514 } |
515 | 515 |
516 private: | 516 private: |
517 typedef SkView INHERITED; | 517 typedef SkView INHERITED; |
518 }; | 518 }; |
519 | 519 |
520 ////////////////////////////////////////////////////////////////////////////// | 520 ////////////////////////////////////////////////////////////////////////////// |
521 | 521 |
522 static SkView* MyFactory() { return new ImageFilterFuzzView; } | 522 static SkView* MyFactory() { return new ImageFilterFuzzView; } |
523 static SkViewRegister reg(MyFactory); | 523 static SkViewRegister reg(MyFactory); |
OLD | NEW |