Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Unified Diff: src/effects/SkGammaColorFilter.cpp

Issue 2190573002: Add SkGammaColorFilter (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: ?? Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/effects/SkGammaColorFilter.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/effects/SkGammaColorFilter.cpp
diff --git a/src/effects/SkGammaColorFilter.cpp b/src/effects/SkGammaColorFilter.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..eba8e320d8fa2b2df52ba12f723642f128a2f7e7
--- /dev/null
+++ b/src/effects/SkGammaColorFilter.cpp
@@ -0,0 +1,56 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkGammaColorFilter.h"
+
+#include "SkReadBuffer.h"
+#include "SkString.h"
+
+#if SK_SUPPORT_GPU
+#include "effects/GrGammaEffect.h"
+#endif
+
+void SkGammaColorFilter::filterSpan(const SkPMColor src[], int count,
+ SkPMColor dst[]) const {
+ // Gamma-correcting bytes to bytes is pretty questionable.
+ SkASSERT(0);
+ for (int i = 0; i < count; ++i) {
+ SkPMColor c = src[i];
+
+ // TODO: implement cpu gamma correction?
+ dst[i] = c;
+ }
+}
+
+sk_sp<SkColorFilter> SkGammaColorFilter::Make(SkScalar gamma) {
+ return sk_sp<SkColorFilter>(new SkGammaColorFilter(gamma));
+}
+
+SkGammaColorFilter::SkGammaColorFilter(SkScalar gamma) : fGamma(gamma) {}
+
+sk_sp<SkFlattenable> SkGammaColorFilter::CreateProc(SkReadBuffer& buffer) {
+ SkScalar gamma = buffer.readScalar();
+
+ return Make(gamma);
+}
+
+void SkGammaColorFilter::flatten(SkWriteBuffer& buffer) const {
+ this->INHERITED::flatten(buffer);
+ buffer.writeScalar(fGamma);
+}
+
+#ifndef SK_IGNORE_TO_STRING
+void SkGammaColorFilter::toString(SkString* str) const {
+ str->appendf("SkGammaColorFilter (%.2f)", fGamma);
+}
+#endif
+
+#if SK_SUPPORT_GPU
+sk_sp<GrFragmentProcessor> SkGammaColorFilter::asFragmentProcessor(GrContext*) const {
+ return GrGammaEffect::Make(fGamma);
+}
+#endif
« no previous file with comments | « include/effects/SkGammaColorFilter.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698