OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2016 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 #include "SkGammaColorFilter.h" |
| 9 |
| 10 #include "SkReadBuffer.h" |
| 11 #include "SkString.h" |
| 12 |
| 13 #if SK_SUPPORT_GPU |
| 14 #include "effects/GrGammaEffect.h" |
| 15 #endif |
| 16 |
| 17 void SkGammaColorFilter::filterSpan(const SkPMColor src[], int count, |
| 18 SkPMColor dst[]) const { |
| 19 // Gamma-correcting bytes to bytes is pretty questionable. |
| 20 SkASSERT(0); |
| 21 for (int i = 0; i < count; ++i) { |
| 22 SkPMColor c = src[i]; |
| 23 |
| 24 // TODO: implement cpu gamma correction? |
| 25 dst[i] = c; |
| 26 } |
| 27 } |
| 28 |
| 29 sk_sp<SkColorFilter> SkGammaColorFilter::Make(SkScalar gamma) { |
| 30 return sk_sp<SkColorFilter>(new SkGammaColorFilter(gamma)); |
| 31 } |
| 32 |
| 33 SkGammaColorFilter::SkGammaColorFilter(SkScalar gamma) : fGamma(gamma) {} |
| 34 |
| 35 sk_sp<SkFlattenable> SkGammaColorFilter::CreateProc(SkReadBuffer& buffer) { |
| 36 SkScalar gamma = buffer.readScalar(); |
| 37 |
| 38 return Make(gamma); |
| 39 } |
| 40 |
| 41 void SkGammaColorFilter::flatten(SkWriteBuffer& buffer) const { |
| 42 this->INHERITED::flatten(buffer); |
| 43 buffer.writeScalar(fGamma); |
| 44 } |
| 45 |
| 46 #ifndef SK_IGNORE_TO_STRING |
| 47 void SkGammaColorFilter::toString(SkString* str) const { |
| 48 str->appendf("SkGammaColorFilter (%.2f)", fGamma); |
| 49 } |
| 50 #endif |
| 51 |
| 52 #if SK_SUPPORT_GPU |
| 53 sk_sp<GrFragmentProcessor> SkGammaColorFilter::asFragmentProcessor(GrContext*) c
onst { |
| 54 return GrGammaEffect::Make(fGamma); |
| 55 } |
| 56 #endif |
OLD | NEW |