From f11c57488205faddd10dffedcd3c122aac1935ad Mon Sep 17 00:00:00 2001 From: sugoi Date: Mon, 27 Oct 2014 08:03:56 -0700 Subject: [PATCH] Adding color cube to fuzzer BUG=skia: Review URL: https://codereview.chromium.org/677713003 --- samplecode/SampleFilterFuzz.cpp | 40 ++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp index e073f80b0c..6ddc87c9d9 100644 --- a/samplecode/SampleFilterFuzz.cpp +++ b/samplecode/SampleFilterFuzz.cpp @@ -9,6 +9,7 @@ #include "SkBitmapSource.h" #include "SkBlurImageFilter.h" #include "SkCanvas.h" +#include "SkColorCubeFilter.h" #include "SkColorFilter.h" #include "SkColorFilterImageFilter.h" #include "SkComposeImageFilter.h" @@ -210,6 +211,35 @@ static const SkBitmap& make_bitmap() { return bitmap[R(2)]; } +static SkData* make_3Dlut(int* cubeDimension, bool invR, bool invG, bool invB) { + int size = 4 << R(5); + SkData* data = SkData::NewUninitialized(sizeof(SkColor) * size * size * size); + SkColor* pixels = (SkColor*)(data->writable_data()); + SkAutoMalloc lutMemory(size); + SkAutoMalloc invLutMemory(size); + uint8_t* lut = (uint8_t*)lutMemory.get(); + uint8_t* invLut = (uint8_t*)invLutMemory.get(); + const int maxIndex = size - 1; + for (int i = 0; i < size; i++) { + lut[i] = (i * 255) / maxIndex; + invLut[i] = ((maxIndex - i) * 255) / maxIndex; + } + for (int r = 0; r < size; ++r) { + for (int g = 0; g < size; ++g) { + for (int b = 0; b < size; ++b) { + pixels[(size * ((size * b) + g)) + r] = SkColorSetARGB(0xFF, + invR ? invLut[r] : lut[r], + invG ? invLut[g] : lut[g], + invB ? invLut[b] : lut[b]); + } + } + } + if (cubeDimension) { + *cubeDimension = size; + } + return data; +} + static void drawSomething(SkCanvas* canvas) { SkPaint paint; @@ -238,7 +268,7 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) { // Add a 1 in 3 chance to get a NULL input if (canBeNull && (R(3) == 1)) { return filter; } - enum { ALPHA_THRESHOLD, MERGE, COLOR, BLUR, MAGNIFIER, + enum { ALPHA_THRESHOLD, MERGE, COLOR, LUT3D, BLUR, MAGNIFIER, DOWN_SAMPLE, XFERMODE, OFFSET, MATRIX, MATRIX_CONVOLUTION, COMPOSE, DISTANT_LIGHT, POINT_LIGHT, SPOT_LIGHT, NOISE, DROP_SHADOW, MORPHOLOGY, BITMAP, DISPLACE, TILE, PICTURE, NUM_FILTERS }; @@ -258,6 +288,14 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) { filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filter()) : 0; } break; + case LUT3D: + { + int cubeDimension; + SkAutoDataUnref lut3D(make_3Dlut(&cubeDimension, (R(2) == 1), (R(2) == 1), (R(2) == 1))); + SkAutoTUnref cf(SkColorCubeFilter::Create(lut3D, cubeDimension)); + filter = cf.get() ? SkColorFilterImageFilter::Create(cf, make_image_filter()) : 0; + } + break; case BLUR: filter = SkBlurImageFilter::Create(make_scalar(true), make_scalar(true), make_image_filter()); break; -- 2.34.1