michael@0: michael@0: /* michael@0: * Copyright 2008 The Android Open Source Project michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: michael@0: michael@0: michael@0: #ifndef SkUnPreMultiply_DEFINED michael@0: #define SkUnPreMultiply_DEFINED michael@0: michael@0: #include "SkColor.h" michael@0: michael@0: class SK_API SkUnPreMultiply { michael@0: public: michael@0: typedef uint32_t Scale; michael@0: michael@0: // index this table with alpha [0..255] michael@0: static const Scale* GetScaleTable() { michael@0: return gTable; michael@0: } michael@0: michael@0: static Scale GetScale(U8CPU alpha) { michael@0: SkASSERT(alpha <= 255); michael@0: return gTable[alpha]; michael@0: } michael@0: michael@0: /** Usage: michael@0: michael@0: const Scale* table = SkUnPreMultiply::GetScaleTable(); michael@0: michael@0: for (...) { michael@0: unsigned a = ... michael@0: SkUnPreMultiply::Scale scale = table[a]; michael@0: michael@0: red = SkUnPreMultiply::ApplyScale(scale, red); michael@0: ... michael@0: // now red is unpremultiplied michael@0: } michael@0: */ michael@0: static U8CPU ApplyScale(Scale scale, U8CPU component) { michael@0: SkASSERT(component <= 255); michael@0: return (scale * component + (1 << 23)) >> 24; michael@0: } michael@0: michael@0: static SkColor PMColorToColor(SkPMColor c); michael@0: michael@0: static uint32_t UnPreMultiplyPreservingByteOrder(SkPMColor c); michael@0: michael@0: private: michael@0: static const uint32_t gTable[256]; michael@0: }; michael@0: michael@0: #endif