Index: gm/colorprofile.cpp |
diff --git a/gm/colorprofile.cpp b/gm/colorprofile.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..124e36c5c96af8bef6e44ccd945b6f38ece6564f |
--- /dev/null |
+++ b/gm/colorprofile.cpp |
@@ -0,0 +1,130 @@ |
+/* |
+ * Copyright 2013 Google Inc. |
+ * |
+ * Use of this source code is governed by a BSD-style license that can be |
+ * found in the LICENSE file. |
+ */ |
+ |
+#include "gm.h" |
+#include "SkColorProfileFilter.h" |
+#include "SkBitmapSource.h" |
+#include "SkGradientShader.h" |
+ |
+namespace skiagm { |
+ |
+static SkShader* MakeLinear() { |
+ static const SkPoint pts[2] = { |
+ { 0, 0 }, |
+ { SkIntToScalar(80), SkIntToScalar(80) } |
+ }; |
+ static const SkColor colors[] = { SK_ColorYELLOW, SK_ColorBLUE }; |
+ return SkGradientShader::CreateLinear( |
+ pts, colors, NULL, 2, SkShader::kRepeat_TileMode, 0, &SkMatrix::I()); |
+} |
+ |
+class ColorProfileGM : public GM { |
+public: |
+ ColorProfileGM() : fInitialized(false) { |
+ this->setBGColor(0xFF000000); |
+ } |
+ |
+protected: |
+ virtual SkString onShortName() { |
+ return SkString("colorprofile"); |
+ } |
+ |
+ void make_bitmaps() { |
+ make_bitmap(); |
+ make_3Dlut(&f3DLut4, 4, true, false, false); |
+ make_3Dlut(&f3DLut8, 8, false, true, false); |
+ make_3Dlut(&f3DLut16, 16, false, true, true); |
+ make_3Dlut(&f3DLut32, 32, true, true, false); |
+ make_3Dlut(&f3DLut64, 64, true, false, true); |
+ } |
+ |
+ void make_bitmap() { |
+ fBitmap.allocN32Pixels(80, 80); |
+ SkCanvas canvas(fBitmap); |
+ canvas.clear(0x00000000); |
+ SkPaint paint; |
+ paint.setAntiAlias(true); |
+ SkShader* shader = MakeLinear(); |
+ paint.setShader(shader); |
+ SkRect r = { 0, 0, SkIntToScalar(80), SkIntToScalar(80) }; |
+ canvas.drawRect(r, paint); |
+ shader->unref(); |
+ } |
+ |
+ void make_3Dlut(SkBitmap* bitmap, int size, bool invR, bool invG, bool invB) { |
+ bitmap->allocN32Pixels(size, size * size); |
+ SkColor* pixels = (SkColor*)bitmap->getPixels(); |
+ 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]); |
+ } |
+ } |
+ } |
+ bitmap->setIs3DLut(true); |
+ } |
+ |
+ virtual SkISize onISize() { |
+ return SkISize::Make(500, 100); |
+ } |
+ |
+ void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) { |
+ canvas->save(); |
+ canvas->translate(SkIntToScalar(x), SkIntToScalar(y)); |
+ canvas->clipRect(SkRect::MakeWH(SkIntToScalar(fBitmap.width()), |
+ SkIntToScalar(fBitmap.height()))); |
+ canvas->drawBitmap(fBitmap, 0, 0, &paint); |
+ canvas->restore(); |
+ } |
+ |
+ virtual void onDraw(SkCanvas* canvas) { |
+ if (!fInitialized) { |
+ make_bitmaps(); |
+ fInitialized = true; |
+ } |
+ canvas->clear(0x00000000); |
+ SkPaint paint; |
+ paint.setColorFilter(SkColorProfileFilter::Create(f3DLut4))->unref(); |
+ drawClippedBitmap(canvas, 10, 10, paint); |
+ |
+ paint.setColorFilter(SkColorProfileFilter::Create(f3DLut8))->unref(); |
+ drawClippedBitmap(canvas, 110, 10, paint); |
+ |
+ paint.setColorFilter(SkColorProfileFilter::Create(f3DLut16))->unref(); |
+ drawClippedBitmap(canvas, 210, 10, paint); |
+ |
+ paint.setColorFilter(SkColorProfileFilter::Create(f3DLut32))->unref(); |
+ drawClippedBitmap(canvas, 310, 10, paint); |
+ |
+ paint.setColorFilter(SkColorProfileFilter::Create(f3DLut64))->unref(); |
+ drawClippedBitmap(canvas, 410, 10, paint); |
+ } |
+ |
+private: |
+ typedef GM INHERITED; |
+ SkBitmap fBitmap, f3DLut4, f3DLut8, f3DLut16, f3DLut32, f3DLut64; |
+ bool fInitialized; |
+}; |
+ |
+////////////////////////////////////////////////////////////////////////////// |
+ |
+static GM* MyFactory(void*) { return new ColorProfileGM; } |
+static GMRegistry reg(MyFactory); |
+ |
+} |