Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2016 Google Inc.
      3  *
      4  * Use of this source code is governed by a BSD-style license that can be
      5  * found in the LICENSE file.
      6  */
      7 
      8 #ifndef SkColorLookUpTable_DEFINED
      9 #define SkColorLookUpTable_DEFINED
     10 
     11 #include "SkNx.h"
     12 #include "SkRefCnt.h"
     13 #include "SkTemplates.h"
     14 
     15 // TODO: scope inside SkColorLookUpTable
     16 static constexpr uint8_t kMaxColorChannels = 4;
     17 
     18 class SkColorLookUpTable : public SkRefCnt {
     19 public:
     20     static constexpr uint8_t kOutputChannels = 3;
     21 
     22     SkColorLookUpTable(uint8_t inputChannels, const uint8_t limits[]);
     23 
     24     int  inputChannels() const { return  fInputChannels; }
     25     int outputChannels() const { return kOutputChannels; }
     26 
     27     // TODO: Rename to somethingBetter(int)?
     28     int gridPoints(int dimension) const {
     29         SkASSERT(dimension >= 0 && dimension < inputChannels());
     30         return fLimits[dimension];
     31     }
     32 
     33     // Objects of this type are created in a custom fashion using sk_malloc_throw
     34     // and therefore must be sk_freed.
     35     void* operator new(size_t size) = delete;
     36     void* operator new(size_t, void* p) { return p; }
     37     void operator delete(void* p) { sk_free(p); }
     38 
     39     const float* table() const {
     40         return SkTAddOffset<const float>(this, sizeof(SkColorLookUpTable));
     41     }
     42 
     43 private:
     44     uint8_t fInputChannels;
     45     uint8_t fLimits[kMaxColorChannels];
     46 };
     47 
     48 #endif
     49