Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkUnPreMultiply.h
Go to the documentation of this file.
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
14
15#include <cstdint>
16
18public:
19 typedef uint32_t Scale;
20
21 // index this table with alpha [0..255]
22 static const Scale* GetScaleTable() {
23 return gTable;
24 }
25
26 static Scale GetScale(U8CPU alpha) {
27 SkASSERT(alpha <= 255);
28 return gTable[alpha];
29 }
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 static U8CPU ApplyScale(Scale scale, U8CPU component) {
45 SkASSERT(component <= 255);
46 return (scale * component + (1 << 23)) >> 24;
47 }
48
49 static SkColor PMColorToColor(SkPMColor c);
50
51private:
52 static const uint32_t gTable[256];
53};
54
55#endif
#define SK_API
Definition SkAPI.h:35
#define SkASSERT(cond)
Definition SkAssert.h:116
unsigned U8CPU
Definition SkCPUTypes.h:18
uint32_t SkColor
Definition SkColor.h:37
uint32_t SkPMColor
Definition SkColor.h:205
static const Scale * GetScaleTable()
static U8CPU ApplyScale(Scale scale, U8CPU component)
static Scale GetScale(U8CPU alpha)
const Scalar scale