| 1 | /* |
| 2 | * Copyright 2019 Google LLC |
| 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 | /************************************************************************************************** |
| 9 | *** This file was autogenerated from GrRGBToHSLFilterEffect.fp; do not modify. |
| 10 | **************************************************************************************************/ |
| 11 | #ifndef GrRGBToHSLFilterEffect_DEFINED |
| 12 | #define GrRGBToHSLFilterEffect_DEFINED |
| 13 | #include "include/core/SkTypes.h" |
| 14 | #include "include/core/SkM44.h" |
| 15 | |
| 16 | #include "src/gpu/GrCoordTransform.h" |
| 17 | #include "src/gpu/GrFragmentProcessor.h" |
| 18 | class GrRGBToHSLFilterEffect : public GrFragmentProcessor { |
| 19 | public: |
| 20 | #include "include/private/SkColorData.h" |
| 21 | |
| 22 | SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& c) const override { |
| 23 | const auto p = (c.fG < c.fB) ? SkPMColor4f{c.fB, c.fG, -1, 2 / 3.f} |
| 24 | : SkPMColor4f{c.fG, c.fB, 0, -1 / 3.f}, |
| 25 | q = (c.fR < p[0]) ? SkPMColor4f{p[0], c.fR, p[1], p[3]} |
| 26 | : SkPMColor4f{c.fR, p[0], p[1], p[2]}; |
| 27 | |
| 28 | const auto eps = 0.0001f, // matching SkSL/ColorMatrix half4 epsilon |
| 29 | pmV = q[0], pmC = pmV - std::min(q[1], q[2]), pmL = pmV - pmC * 0.5f, |
| 30 | H = std::abs(q[3] + (q[1] - q[2]) / (pmC * 6 + eps)), |
| 31 | S = pmC / (c.fA + eps - std::abs(pmL * 2 - c.fA)), L = pmL / (c.fA + eps); |
| 32 | |
| 33 | return {H, S, L, c.fA}; |
| 34 | } |
| 35 | static std::unique_ptr<GrFragmentProcessor> Make() { |
| 36 | return std::unique_ptr<GrFragmentProcessor>(new GrRGBToHSLFilterEffect()); |
| 37 | } |
| 38 | GrRGBToHSLFilterEffect(const GrRGBToHSLFilterEffect& src); |
| 39 | std::unique_ptr<GrFragmentProcessor> clone() const override; |
| 40 | const char* name() const override { return "RGBToHSLFilterEffect" ; } |
| 41 | |
| 42 | private: |
| 43 | GrRGBToHSLFilterEffect() |
| 44 | : INHERITED(kGrRGBToHSLFilterEffect_ClassID, |
| 45 | (OptimizationFlags)(kConstantOutputForConstantInput_OptimizationFlag | |
| 46 | kPreservesOpaqueInput_OptimizationFlag)) {} |
| 47 | GrGLSLFragmentProcessor* onCreateGLSLInstance() const override; |
| 48 | void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override; |
| 49 | bool onIsEqual(const GrFragmentProcessor&) const override; |
| 50 | GR_DECLARE_FRAGMENT_PROCESSOR_TEST |
| 51 | typedef GrFragmentProcessor INHERITED; |
| 52 | }; |
| 53 | #endif |
| 54 | |