1 /*
2  * Copyright 2017 Google Inc.
3  *
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the LICENSE file.
6  */
7 
8 #ifndef SkUnPreMultiplyPriv_DEFINED
9 #define SkUnPreMultiplyPriv_DEFINED
10 
11 #include "SkColor.h"
12 #include "SkUnPreMultiply.h"
13 
14 template <bool kSwapRB>
15 void SkUnpremultiplyRow(uint32_t* dst, const uint32_t* src, int count) {
16     const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
17 
18     for (int i = 0; i < count; i++) {
19         uint32_t c = *src++;
20         uint8_t r, g, b, a;
21         if (kSwapRB) {
22             r = (c >> 16) & 0xFF;
23             g = (c >>  8) & 0xFF;
24             b = (c >>  0) & 0xFF;
25             a = (c >> 24) & 0xFF;
26         } else {
27             r = (c >>  0) & 0xFF;
28             g = (c >>  8) & 0xFF;
29             b = (c >> 16) & 0xFF;
30             a = (c >> 24) & 0xFF;
31         }
32 
33         if (0 != a && 255 != a) {
34             SkUnPreMultiply::Scale scale = table[a];
35             r = SkUnPreMultiply::ApplyScale(scale, r);
36             g = SkUnPreMultiply::ApplyScale(scale, g);
37             b = SkUnPreMultiply::ApplyScale(scale, b);
38         }
39 
40         *dst++ = (r << 0) | (g << 8) | (b << 16) | (a << 24);
41     }
42 }
43 
44 #endif
45