blob: 4bdb9802e0aa7dd76870be3b101f33078e81f56d [file] [log] [blame]
reed@android.com8a1c16f2008-12-17 15:59:43 +00001/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17
18
19
20#ifndef SkUnPreMultiply_DEFINED
21#define SkUnPreMultiply_DEFINED
22
23#include "SkColor.h"
24
25class SkUnPreMultiply {
26public:
27 typedef uint32_t Scale;
28
29 // index this table with alpha [0..255]
30 static const Scale* GetScaleTable() {
31 return gTable;
32 }
33
34 static Scale GetScale(U8CPU alpha) {
35 SkASSERT(alpha <= 255);
36 return gTable[alpha];
37 }
38
39 /** Usage:
40
41 const Scale* table = SkUnPreMultiply::GetScaleTable();
42
43 for (...) {
44 unsigned a = ...
45 SkUnPreMultiply::Scale scale = table[a];
46
47 red = SkUnPreMultiply::ApplyScale(scale, red);
48 ...
49 // now red is unpremultiplied
50 }
51 */
52 static U8CPU ApplyScale(Scale scale, U8CPU component) {
53 SkASSERT(component <= 255);
54 return (scale * component + (1 << 23)) >> 24;
55 }
56
57 static SkColor PMColorToColor(SkPMColor c);
58
59private:
60 static const uint32_t gTable[256];
61};
62
63#endif