aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkUnPreMultiplyPriv.h
blob: f25e78f96a5920a548e1625fa2166033b4ff603a (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
/*
 * Copyright 2017 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef SkUnPreMultiplyPriv_DEFINED
#define SkUnPreMultiplyPriv_DEFINED

#include "SkColor.h"
#include "SkUnPreMultiply.h"

template <bool kSwapRB>
void SkUnpremultiplyRow(uint32_t* dst, const uint32_t* src, int count) {
    const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();

    for (int i = 0; i < count; i++) {
        uint32_t c = *src++;
        uint8_t r, g, b, a;
        if (kSwapRB) {
            r = (c >> 16) & 0xFF;
            g = (c >>  8) & 0xFF;
            b = (c >>  0) & 0xFF;
            a = (c >> 24) & 0xFF;
        } else {
            r = (c >>  0) & 0xFF;
            g = (c >>  8) & 0xFF;
            b = (c >> 16) & 0xFF;
            a = (c >> 24) & 0xFF;
        }

        if (0 != a && 255 != a) {
            SkUnPreMultiply::Scale scale = table[a];
            r = SkUnPreMultiply::ApplyScale(scale, r);
            g = SkUnPreMultiply::ApplyScale(scale, g);
            b = SkUnPreMultiply::ApplyScale(scale, b);
        }

        *dst++ = (r << 0) | (g << 8) | (b << 16) | (a << 24);
    }
}

#endif