Home | History | Annotate | Download | only in core
      1 /*
      2  * Copyright 2018 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 SkColorSpaceXformSteps_DEFINED
      9 #define SkColorSpaceXformSteps_DEFINED
     10 
     11 #include "SkColorSpace.h"
     12 #include "SkImageInfo.h"
     13 
     14 class SkRasterPipeline;
     15 
     16 struct SkColorSpaceXformSteps {
     17     struct Flags {
     18         bool unpremul         = false;
     19         bool linearize        = false;
     20         bool gamut_transform  = false;
     21         bool encode           = false;
     22         bool premul           = false;
     23 
     24         uint32_t mask() const {
     25             return (unpremul        ?  1 : 0)
     26                  | (linearize       ?  2 : 0)
     27                  | (gamut_transform ?  4 : 0)
     28                  | (encode          ?  8 : 0)
     29                  | (premul          ? 16 : 0);
     30         }
     31     };
     32 
     33     SkColorSpaceXformSteps(SkColorSpace* src, SkAlphaType srcAT,
     34                            SkColorSpace* dst, SkAlphaType dstAT);
     35 
     36     void apply(float rgba[4]) const;
     37     void apply(SkRasterPipeline*, bool src_is_normalized) const;
     38 
     39     void apply(SkRasterPipeline* p, SkColorType srcCT) const {
     40     #if 0
     41         this->apply(p, srcCT < kRGBA_F16_SkColorType);
     42     #else
     43         // F16Norm is normalized, but to make diffing with F16 easier we
     44         // intentionally take the slower, non-normalized path here.
     45         this->apply(p, srcCT < kRGBA_F16Norm_SkColorType);
     46     #endif
     47     }
     48 
     49     Flags flags;
     50 
     51     bool srcTF_is_sRGB,
     52          dstTF_is_sRGB;
     53     skcms_TransferFunction srcTF,     // Apply for linearize.
     54                            dstTFInv;  // Apply for encode.
     55     float src_to_dst_matrix[9];       // Apply this 3x3 column-major matrix for gamut_transform.
     56 };
     57 
     58 #endif//SkColorSpaceXformSteps_DEFINED
     59