aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/effects/SkGammaColorFilter.cpp
blob: eba8e320d8fa2b2df52ba12f723642f128a2f7e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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