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

Side by Side Diff: samplecode/SampleFilterFuzz.cpp

Issue 677713003: Adding color cube to fuzzer (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fixed nit Created 6 years, 1 month 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 "SkAlphaThresholdFilter.h"
9 #include "SkBitmapSource.h" 9 #include "SkBitmapSource.h"
10 #include "SkBlurImageFilter.h" 10 #include "SkBlurImageFilter.h"
11 #include "SkCanvas.h" 11 #include "SkCanvas.h"
12 #include "SkColorCubeFilter.h"
12 #include "SkColorFilter.h" 13 #include "SkColorFilter.h"
13 #include "SkColorFilterImageFilter.h" 14 #include "SkColorFilterImageFilter.h"
14 #include "SkComposeImageFilter.h" 15 #include "SkComposeImageFilter.h"
15 #include "SkData.h" 16 #include "SkData.h"
16 #include "SkDisplacementMapEffect.h" 17 #include "SkDisplacementMapEffect.h"
17 #include "SkDropShadowImageFilter.h" 18 #include "SkDropShadowImageFilter.h"
18 #include "SkFlattenableSerialization.h" 19 #include "SkFlattenableSerialization.h"
19 #include "SkLightingImageFilter.h" 20 #include "SkLightingImageFilter.h"
20 #include "SkMagnifierImageFilter.h" 21 #include "SkMagnifierImageFilter.h"
21 #include "SkMatrixImageFilter.h" 22 #include "SkMatrixImageFilter.h"
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 static SkBitmap bitmap[2]; 204 static SkBitmap bitmap[2];
204 static bool initialized = false; 205 static bool initialized = false;
205 if (!initialized) { 206 if (!initialized) {
206 make_g_bitmap(bitmap[0]); 207 make_g_bitmap(bitmap[0]);
207 make_checkerboard_bitmap(bitmap[1]); 208 make_checkerboard_bitmap(bitmap[1]);
208 initialized = true; 209 initialized = true;
209 } 210 }
210 return bitmap[R(2)]; 211 return bitmap[R(2)];
211 } 212 }
212 213
214 static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) {
215 int size = 4 << R(5);
216 SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size );
217 SkColor* pixels = (SkColor*)(data->writable_data());
218 SkAutoMalloc lutMemory(size);
219 SkAutoMalloc invLutMemory(size);
220 uint8_t* lut = (uint8_t*)lutMemory.get();
221 uint8_t* invLut = (uint8_t*)invLutMemory.get();
222 const int maxIndex = size - 1;
223 for (int i = 0; i < size; i++) {
224 lut[i] = (i * 255) / maxIndex;
225 invLut[i] = ((maxIndex - i) * 255) / maxIndex;
226 }
227 for (int r = 0; r < size; ++r) {
228 for (int g = 0; g < size; ++g) {
229 for (int b = 0; b < size; ++b) {
230 pixels[(size * ((size * b) + g)) + r] = SkColorSetARGB(0xFF,
231 invR ? invLut[r] : lut[r],
232 invG ? invLut[g] : lut[g],
233 invB ? invLut[b] : lut[b]);
234 }
235 }
236 }
237 if (cubeDimension) {
238 *cubeDimension = size;
239 }
240 return data;
241 }
242
213 static void drawSomething(SkCanvas* canvas) { 243 static void drawSomething(SkCanvas* canvas) {
214 SkPaint paint; 244 SkPaint paint;
215 245
216 canvas->save(); 246 canvas->save();
217 canvas->scale(0.5f, 0.5f); 247 canvas->scale(0.5f, 0.5f);
218 canvas->drawBitmap(make_bitmap(), 0, 0, NULL); 248 canvas->drawBitmap(make_bitmap(), 0, 0, NULL);
219 canvas->restore(); 249 canvas->restore();
220 250
221 const char beforeStr[] = "before circle"; 251 const char beforeStr[] = "before circle";
222 const char afterStr[] = "after circle"; 252 const char afterStr[] = "after circle";
223 253
224 paint.setAntiAlias(true); 254 paint.setAntiAlias(true);
225 255
226 paint.setColor(SK_ColorRED); 256 paint.setColor(SK_ColorRED);
227 canvas->drawData(beforeStr, sizeof(beforeStr)); 257 canvas->drawData(beforeStr, sizeof(beforeStr));
228 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2 ), SkIntToScalar(kBitmapSize/3), paint); 258 canvas->drawCircle(SkIntToScalar(kBitmapSize/2), SkIntToScalar(kBitmapSize/2 ), SkIntToScalar(kBitmapSize/3), paint);
229 canvas->drawData(afterStr, sizeof(afterStr)); 259 canvas->drawData(afterStr, sizeof(afterStr));
230 paint.setColor(SK_ColorBLACK); 260 paint.setColor(SK_ColorBLACK);
231 paint.setTextSize(SkIntToScalar(kBitmapSize/3)); 261 paint.setTextSize(SkIntToScalar(kBitmapSize/3));
232 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint); 262 canvas->drawText("Picture", 7, SkIntToScalar(kBitmapSize/2), SkIntToScalar(k BitmapSize/4), paint);
233 } 263 }
234 264
235 static SkImageFilter* make_image_filter(bool canBeNull = true) { 265 static SkImageFilter* make_image_filter(bool canBeNull = true) {
236 SkImageFilter* filter = 0; 266 SkImageFilter* filter = 0;
237 267
238 // Add a 1 in 3 chance to get a NULL input 268 // Add a 1 in 3 chance to get a NULL input
239 if (canBeNull && (R(3) == 1)) { return filter; } 269 if (canBeNull && (R(3) == 1)) { return filter; }
240 270
241 enum { ALPHA_THRESHOLD, MERGE, COLOR, BLUR, MAGNIFIER, 271 enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER,
242 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, 272 DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE,
243 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, 273 DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW,
244 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; 274 MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS };
245 275
246 switch (R(NUM_FILTERS)) { 276 switch (R(NUM_FILTERS)) {
247 case ALPHA_THRESHOLD: 277 case ALPHA_THRESHOLD:
248 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar()); 278 filter = SkAlphaThresholdFilter::Create(make_region(), make_scalar(), ma ke_scalar());
249 break; 279 break;
250 case MERGE: 280 case MERGE:
251 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode()); 281 filter = SkMergeImageFilter::Create(make_image_filter(), make_image_filt er(), make_xfermode());
252 break; 282 break;
253 case COLOR: 283 case COLOR:
254 { 284 {
255 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ? 285 SkAutoTUnref<SkColorFilter> cf((R(2) == 1) ?
256 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) : 286 SkColorFilter::CreateModeFilter(make_color(), make_xfermode()) :
257 SkColorFilter::CreateLightingFilter(make_color(), make_color()) ); 287 SkColorFilter::CreateLightingFilter(make_color(), make_color()) );
258 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0; 288 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
259 } 289 }
260 break; 290 break;
291 case LUT3D:
292 {
293 int cubeDimension;
294 SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1 ), (R(2) == 1)));
295 SkAutoTUnref<SkColorFilter> cf(SkColorCubeFilter::Create(lut3D, cubeDime nsion));
296 filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filt er()) : 0;
297 }
298 break;
261 case BLUR: 299 case BLUR:
262 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter()); 300 filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter());
263 break; 301 break;
264 case MAGNIFIER: 302 case MAGNIFIER:
265 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true)); 303 filter = SkMagnifierImageFilter::Create(make_rect(), make_scalar(true));
266 break; 304 break;
267 case DOWN_SAMPLE: 305 case DOWN_SAMPLE:
268 filter = SkDownSampleImageFilter::Create(make_scalar()); 306 filter = SkDownSampleImageFilter::Create(make_scalar());
269 break; 307 break;
270 case XFERMODE: 308 case XFERMODE:
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 519 }
482 520
483 private: 521 private:
484 typedef SkView INHERITED; 522 typedef SkView INHERITED;
485 }; 523 };
486 524
487 ////////////////////////////////////////////////////////////////////////////// 525 //////////////////////////////////////////////////////////////////////////////
488 526
489 static SkView* MyFactory() { return new ImageFilterFuzzView; } 527 static SkView* MyFactory() { return new ImageFilterFuzzView; }
490 static SkViewRegister reg(MyFactory); 528 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