/src/skia/include/core/SkUnPreMultiply.h
Line | Count | Source (jump to first uncovered line) |
1 | | |
2 | | /* |
3 | | * Copyright 2008 The Android Open Source Project |
4 | | * |
5 | | * Use of this source code is governed by a BSD-style license that can be |
6 | | * found in the LICENSE file. |
7 | | */ |
8 | | #ifndef SkUnPreMultiply_DEFINED |
9 | | #define SkUnPreMultiply_DEFINED |
10 | | |
11 | | #include "include/core/SkColor.h" |
12 | | #include "include/core/SkTypes.h" |
13 | | #include "include/private/base/SkCPUTypes.h" |
14 | | |
15 | | #include <cstdint> |
16 | | |
17 | | class SK_API SkUnPreMultiply { |
18 | | public: |
19 | | typedef uint32_t Scale; |
20 | | |
21 | | // index this table with alpha [0..255] |
22 | 0 | static const Scale* GetScaleTable() { |
23 | 0 | return gTable; |
24 | 0 | } |
25 | | |
26 | 0 | static Scale GetScale(U8CPU alpha) { |
27 | 0 | SkASSERT(alpha <= 255); |
28 | 0 | return gTable[alpha]; |
29 | 0 | } Unexecuted instantiation: SkUnPreMultiply::GetScale(unsigned int) Unexecuted instantiation: SkUnPreMultiply::GetScale(unsigned int) |
30 | | |
31 | | /** Usage: |
32 | | |
33 | | const Scale* table = SkUnPreMultiply::GetScaleTable(); |
34 | | |
35 | | for (...) { |
36 | | unsigned a = ... |
37 | | SkUnPreMultiply::Scale scale = table[a]; |
38 | | |
39 | | red = SkUnPreMultiply::ApplyScale(scale, red); |
40 | | ... |
41 | | // now red is unpremultiplied |
42 | | } |
43 | | */ |
44 | 0 | static U8CPU ApplyScale(Scale scale, U8CPU component) { |
45 | 0 | SkASSERT(component <= 255); |
46 | 0 | return (scale * component + (1 << 23)) >> 24; |
47 | 0 | } Unexecuted instantiation: SkUnPreMultiply::ApplyScale(unsigned int, unsigned int) Unexecuted instantiation: SkUnPreMultiply::ApplyScale(unsigned int, unsigned int) |
48 | | |
49 | | static SkColor PMColorToColor(SkPMColor c); |
50 | | |
51 | | private: |
52 | | static const uint32_t gTable[256]; |
53 | | }; |
54 | | |
55 | | #endif |