2 * Copyright 2014 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
8 #ifndef SkColorCubeFilter_DEFINED
9 #define SkColorCubeFilter_DEFINED
11 #include "SkColorFilter.h"
14 class SK_API SkColorCubeFilter : public SkColorFilter {
16 /** cubeData must containt a 3D data in the form of cube of the size:
17 * cubeDimension * cubeDimension * cubeDimension * sizeof(SkColor)
18 * This cube contains a transform where (x,y,z) maps to the (r,g,b).
19 * The alpha components of the colors are ignored (treated as 0xFF).
21 static SkColorFilter* Create(SkData* cubeData, int cubeDimension);
23 virtual void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const SK_OVERRIDE;
24 virtual uint32_t getFlags() const SK_OVERRIDE;
27 virtual GrFragmentProcessor* asFragmentProcessor(GrContext*) const SK_OVERRIDE;
30 SK_TO_STRING_OVERRIDE()
31 SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkColorCubeFilter)
34 SkColorCubeFilter(SkData* cubeData, int cubeDimension);
35 #ifdef SK_SUPPORT_LEGACY_DEEPFLATTENING
36 SkColorCubeFilter(SkReadBuffer& buffer);
38 virtual void flatten(SkWriteBuffer&) const SK_OVERRIDE;
41 /** The cache is initialized on-demand when getProcessingLuts is called.
43 class ColorCubeProcesingCache {
45 ColorCubeProcesingCache(int cubeDimension);
47 void getProcessingLuts(const int* (*colorToIndex)[2],
48 const SkScalar* (*colorToFactors)[2],
49 const SkScalar** colorToScalar);
51 int cubeDimension() const { return fCubeDimension; }
54 // Working pointers. If any of these is NULL,
55 // we need to recompute the corresponding cache values.
56 int* fColorToIndex[2];
57 SkScalar* fColorToFactors[2];
58 SkScalar* fColorToScalar;
60 SkAutoMalloc fLutStorage;
62 const int fCubeDimension;
64 // Make sure we only initialize the caches once.
68 static void initProcessingLuts(ColorCubeProcesingCache* cache);
71 SkAutoDataUnref fCubeData;
74 mutable ColorCubeProcesingCache fCache;
76 typedef SkColorFilter INHERITED;