aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2016-07-28 09:20:33 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-28 09:20:33 -0700
commita408c8fb6d367d494437b8709fdfa8c822267e6e (patch)
tree6f334aa5d42fb143607ccc88e758c710c18aa5a4 /include
parent9c18546b78f9406a73b681d81be63afcf80d30a8 (diff)
Add SkGammaColorFilter
WDYT about this as a means of replacing GrContext::applyGamma with a normal SkCanvas::drawImage? GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2190573002 Review-Url: https://codereview.chromium.org/2190573002
Diffstat (limited to 'include')
-rw-r--r--include/effects/SkGammaColorFilter.h48
1 files changed, 48 insertions, 0 deletions
diff --git a/include/effects/SkGammaColorFilter.h b/include/effects/SkGammaColorFilter.h
new file mode 100644
index 0000000000..308926a3ab
--- /dev/null
+++ b/include/effects/SkGammaColorFilter.h
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkGammaColorFilter_DEFINED
+#define SkGammaColorFilter_DEFINED
+
+#include "SkColorFilter.h"
+#include "SkRefCnt.h"
+
+// This colorfilter can be used to perform pixel-by-pixel conversion between linear and
+// power-law color spaces. A gamma of 2.2 is interpreted to mean convert from sRGB to linear
+// while a gamma of 1/2.2 is interpreted to mean convert from linear to sRGB. Any other
+// values are just directly applied (i.e., out = in^gamma)
+//
+// More complicated color space mapping (i.e., ICC profiles) should be handled via the
+// SkColorSpace object.
+class SK_API SkGammaColorFilter : public SkColorFilter {
+public:
+ static sk_sp<SkColorFilter> Make(SkScalar gamma);
+
+#ifdef SK_SUPPORT_LEGACY_COLORFILTER_PTR
+ static SkColorFilter* Create(SkScalar gamma) { return Make(gamma).release(); }
+#endif
+
+ void filterSpan(const SkPMColor src[], int count, SkPMColor[]) const override;
+
+#if SK_SUPPORT_GPU
+ sk_sp<GrFragmentProcessor> asFragmentProcessor(GrContext*) const override;
+#endif
+
+ SK_TO_STRING_OVERRIDE()
+ SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkLumaColorFilter)
+
+protected:
+ void flatten(SkWriteBuffer&) const override;
+
+private:
+ SkGammaColorFilter(SkScalar gamma);
+
+ SkScalar fGamma;
+ typedef SkColorFilter INHERITED;
+};
+
+#endif