1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/include/core/SkUnPreMultiply.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,58 @@ 1.4 + 1.5 +/* 1.6 + * Copyright 2008 The Android Open Source Project 1.7 + * 1.8 + * Use of this source code is governed by a BSD-style license that can be 1.9 + * found in the LICENSE file. 1.10 + */ 1.11 + 1.12 + 1.13 + 1.14 + 1.15 + 1.16 +#ifndef SkUnPreMultiply_DEFINED 1.17 +#define SkUnPreMultiply_DEFINED 1.18 + 1.19 +#include "SkColor.h" 1.20 + 1.21 +class SK_API SkUnPreMultiply { 1.22 +public: 1.23 + typedef uint32_t Scale; 1.24 + 1.25 + // index this table with alpha [0..255] 1.26 + static const Scale* GetScaleTable() { 1.27 + return gTable; 1.28 + } 1.29 + 1.30 + static Scale GetScale(U8CPU alpha) { 1.31 + SkASSERT(alpha <= 255); 1.32 + return gTable[alpha]; 1.33 + } 1.34 + 1.35 + /** Usage: 1.36 + 1.37 + const Scale* table = SkUnPreMultiply::GetScaleTable(); 1.38 + 1.39 + for (...) { 1.40 + unsigned a = ... 1.41 + SkUnPreMultiply::Scale scale = table[a]; 1.42 + 1.43 + red = SkUnPreMultiply::ApplyScale(scale, red); 1.44 + ... 1.45 + // now red is unpremultiplied 1.46 + } 1.47 + */ 1.48 + static U8CPU ApplyScale(Scale scale, U8CPU component) { 1.49 + SkASSERT(component <= 255); 1.50 + return (scale * component + (1 << 23)) >> 24; 1.51 + } 1.52 + 1.53 + static SkColor PMColorToColor(SkPMColor c); 1.54 + 1.55 + static uint32_t UnPreMultiplyPreservingByteOrder(SkPMColor c); 1.56 + 1.57 +private: 1.58 + static const uint32_t gTable[256]; 1.59 +}; 1.60 + 1.61 +#endif