aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar sugoi <sugoi@chromium.org>2014-10-09 05:27:23 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-10-09 05:27:23 -0700
commitce686270f533b9d741ef85661ef9d78517a01b86 (patch)
treec89179e16db02dfea5042aa51fff79fc129e643d /include
parent9e61bb7815b133bc40ea7b00fccc853f4b728e3c (diff)
Adding 3D lut color filter
Included in this cl is support for 3D textures. BUG=skia: Review URL: https://codereview.chromium.org/580863004
Diffstat (limited to 'include')
-rw-r--r--include/effects/SkColorCubeFilter.h79
1 files changed, 79 insertions, 0 deletions
diff --git a/include/effects/SkColorCubeFilter.h b/include/effects/SkColorCubeFilter.h
new file mode 100644
index 0000000000..2cfee45e9c
--- /dev/null
+++ b/include/effects/SkColorCubeFilter.h
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkColorCubeFilter_DEFINED
+#define SkColorCubeFilter_DEFINED
+
+#include "SkColorFilter.h"
+#include "SkData.h"
+
+class SK_API SkColorCubeFilter : public SkColorFilter {
+public:
+ /** cubeData must containt a 3D data in the form of cube of the size:
+ * cubeDimension * cubeDimension * cubeDimension * sizeof(SkColor)
+ * This cube contains a transform where (x,y,z) maps to the (r,g,b).
+ * The alpha components of the colors are ignored (treated as 0xFF).
+ */
+ static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
+
+ virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const SK_OVERRIDE;
+ virtual uint32_t getFlags() const SK_OVERRIDE;
+
+#if SK_SUPPORT_GPU
+ virtual GrFragmentProcessor* asFragmentProcessor(GrContext*) const SK_OVERRIDE;
+#endif
+
+ SK_TO_STRING_OVERRIDE()
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
+
+protected:
+ SkColorCubeFilter(SkData* cubeData, int cubeDimension);
+#ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
+ SkColorCubeFilter(SkReadBuffer& buffer);
+#endif
+ virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
+
+private:
+ /** The cache is initialized on-demand when getProcessingLuts is called.
+ */
+ class ColorCubeProcesingCache {
+ public:
+ ColorCubeProcesingCache(int cubeDimension);
+
+ void getProcessingLuts(const int* (*colorToIndex)[2],
+ const SkScalar* (*colorToFactors)[2],
+ const SkScalar** colorToScalar);
+
+ int cubeDimension() const { return fCubeDimension; }
+
+ private:
+ // Working pointers. If any of these is NULL,
+ // we need to recompute the corresponding cache values.
+ int* fColorToIndex[2];
+ SkScalar* fColorToFactors[2];
+ SkScalar* fColorToScalar;
+
+ SkAutoMalloc fLutStorage;
+
+ const int fCubeDimension;
+
+ // Make sure we only initialize the caches once.
+ SkMutex fLutsMutex;
+ bool fLutsInited;
+
+ static void initProcessingLuts(ColorCubeProcesingCache* cache);
+ };
+
+ SkAutoDataUnref fCubeData;
+ int32_t fUniqueID;
+
+ mutable ColorCubeProcesingCache fCache;
+
+ typedef SkColorFilter INHERITED;
+};
+
+#endif