aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-15 22:24:58 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-01-15 22:24:58 +0000
commitb06faacaf13b9b5c47b8526492ad155bdce3863b (patch)
tree80c90789122a3efef15a2998d95a953b982cae24
parent6a18079de8a39cf8438d60e51b3de2cd3a7edf00 (diff)
Factor out UnPreMultiplyPreservingByteOrder
BUG= R=reed@google.com Author: mtklein@google.com Review URL: https://codereview.chromium.org/130303005 git-svn-id: http://skia.googlecode.com/svn/trunk@13103 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r--dm/DMWriteTask.cpp8
-rw-r--r--include/core/SkUnPreMultiply.h2
-rw-r--r--src/core/SkUnPreMultiply.cpp9
-rw-r--r--src/ports/SkImageDecoder_CG.cpp13
4 files changed, 13 insertions, 19 deletions
diff --git a/dm/DMWriteTask.cpp b/dm/DMWriteTask.cpp
index 11a71faed6..faa20a2cc3 100644
--- a/dm/DMWriteTask.cpp
+++ b/dm/DMWriteTask.cpp
@@ -137,17 +137,11 @@ bool WriteTask::Expectations::check(const Task& task, SkBitmap bitmap) const {
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);
}
diff --git a/include/core/SkUnPreMultiply.h b/include/core/SkUnPreMultiply.h
index 4fa5d579e9..16181ce4e6 100644
--- a/include/core/SkUnPreMultiply.h
+++ b/include/core/SkUnPreMultiply.h
@@ -49,6 +49,8 @@ public:
static SkColor PMColorToColor(SkPMColor c);
+ static uint32_t UnPreMultiplyPreservingByteOrder(SkPMColor c);
+
private:
static const uint32_t gTable[256];
};
diff --git a/src/core/SkUnPreMultiply.cpp b/src/core/SkUnPreMultiply.cpp
index ad87f8af14..6245e96429 100644
--- a/src/core/SkUnPreMultiply.cpp
+++ b/src/core/SkUnPreMultiply.cpp
@@ -17,6 +17,15 @@ SkColor SkUnPreMultiply::PMColorToColor(SkPMColor c) {
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,
diff --git a/src/ports/SkImageDecoder_CG.cpp b/src/ports/SkImageDecoder_CG.cpp
index 9b93f81112..beb6ed11e4 100644
--- a/src/ports/SkImageDecoder_CG.cpp
+++ b/src/ports/SkImageDecoder_CG.cpp
@@ -50,17 +50,6 @@ protected:
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) {
@@ -118,7 +107,7 @@ 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);