unpremul.setConfig(info);
unpremul.allocPixels();
- // Unpremultiply without changing native byte order.
SkAutoLockPixels lockSrc(bitmap), lockDst(unpremul);
const SkPMColor* src = (SkPMColor*)bitmap.getPixels();
uint32_t* dst = (uint32_t*)unpremul.getPixels();
for (size_t i = 0; i < bitmap.getSize()/4; i++) {
- const U8CPU a = SkGetPackedA32(src[i]);
- const SkUnPreMultiply::Scale s = SkUnPreMultiply::GetScale(a);
- dst[i] = SkPackARGB32NoCheck(a,
- SkUnPreMultiply::ApplyScale(s, SkGetPackedR32(src[i])),
- SkUnPreMultiply::ApplyScale(s, SkGetPackedG32(src[i])),
- SkUnPreMultiply::ApplyScale(s, SkGetPackedB32(src[i])));
+ dst[i] = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(src[i]);
}
bitmap.swap(unpremul);
}
static SkColor PMColorToColor(SkPMColor c);
+ static uint32_t UnPreMultiplyPreservingByteOrder(SkPMColor c);
+
private:
static const uint32_t gTable[256];
};
ApplyScale(scale, SkGetPackedB32(c)));
}
+uint32_t SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(SkPMColor c) {
+ const U8CPU a = SkGetPackedA32(c);
+ const Scale scale = GetScale(a);
+ return SkPackARGB32NoCheck(a,
+ ApplyScale(scale, SkGetPackedR32(c)),
+ ApplyScale(scale, SkGetPackedG32(c)),
+ ApplyScale(scale, SkGetPackedB32(c)));
+}
+
const uint32_t SkUnPreMultiply::gTable[] = {
0x00000000, 0xFF000000, 0x7F800000, 0x55000000, 0x3FC00000, 0x33000000, 0x2A800000, 0x246DB6DB,
0x1FE00000, 0x1C555555, 0x19800000, 0x172E8BA3, 0x15400000, 0x139D89D9, 0x1236DB6E, 0x11000000,
virtual bool onDecode(SkStream* stream, SkBitmap* bm, Mode);
};
-// Returns an unpremultiplied version of color. It will have the same ordering and size as an
-// SkPMColor, but the alpha will not be premultiplied.
-static SkPMColor unpremultiply_pmcolor(SkPMColor color) {
- U8CPU a = SkGetPackedA32(color);
- const SkUnPreMultiply::Scale scale = SkUnPreMultiply::GetScale(a);
- return SkPackARGB32NoCheck(a,
- SkUnPreMultiply::ApplyScale(scale, SkGetPackedR32(color)),
- SkUnPreMultiply::ApplyScale(scale, SkGetPackedG32(color)),
- SkUnPreMultiply::ApplyScale(scale, SkGetPackedB32(color)));
-}
-
#define BITMAP_INFO (kCGBitmapByteOrder32Big | kCGImageAlphaPremultipliedLast)
bool SkImageDecoder_CG::onDecode(SkStream* stream, SkBitmap* bm, Mode mode) {
for (int i = 0; i < width; ++i) {
for (int j = 0; j < height; ++j) {
uint32_t* addr = bm->getAddr32(i, j);
- *addr = unpremultiply_pmcolor(*addr);
+ *addr = SkUnPreMultiply::UnPreMultiplyPreservingByteOrder(*addr);
}
}
bm->setAlphaType(kUnpremul_SkAlphaType);