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 13 template <bool kSwapRB> 14 void SkUnpremultiplyRow(uint32_t* dst, const uint32_t* src, int count) { 15 const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable(); 16 17 for (int i = 0; i < count; i++) { 18 uint32_t c = *src++; 19 uint8_t r, g, b, a; 20 if (kSwapRB) { 21 r = (c >> 16) & 0xFF; 22 g = (c >> 8) & 0xFF; 23 b = (c >> 0) & 0xFF; 24 a = (c >> 24) & 0xFF; 25 } else { 26 r = (c >> 0) & 0xFF; 27 g = (c >> 8) & 0xFF; 28 b = (c >> 16) & 0xFF; 29 a = (c >> 24) & 0xFF; 30 } 31 32 if (0 != a && 255 != a) { 33 SkUnPreMultiply::Scale scale = table[a]; 34 r = SkUnPreMultiply::ApplyScale(scale, r); 35 g = SkUnPreMultiply::ApplyScale(scale, g); 36 b = SkUnPreMultiply::ApplyScale(scale, b); 37 } 38 39 *dst++ = (r << 0) | (g << 8) | (b << 16) | (a << 24); 40 } 41 } 42 43 #endif 44