diff options
author | 2016-07-28 09:20:33 -0700 | |
---|---|---|
committer | 2016-07-28 09:20:33 -0700 | |
commit | a408c8fb6d367d494437b8709fdfa8c822267e6e (patch) | |
tree | 6f334aa5d42fb143607ccc88e758c710c18aa5a4 /src/effects/SkGammaColorFilter.cpp | |
parent | 9c18546b78f9406a73b681d81be63afcf80d30a8 (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 'src/effects/SkGammaColorFilter.cpp')
-rw-r--r-- | src/effects/SkGammaColorFilter.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/effects/SkGammaColorFilter.cpp b/src/effects/SkGammaColorFilter.cpp new file mode 100644 index 0000000000..eba8e320d8 --- /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 |