Index: samplecode/SampleFilterFuzz.cpp |
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp |
index e073f80b0c1c16651cd2eb47d2dc0ce6aadc6582..6ddc87c9d902d0a7ec2b9a473685a951fcf03fd8 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<SkColorFilter> 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; |