aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkUnPreMultiplyPriv.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/SkUnPreMultiplyPriv.h')
-rw-r--r--src/core/SkUnPreMultiplyPriv.h43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/core/SkUnPreMultiplyPriv.h b/src/core/SkUnPreMultiplyPriv.h
new file mode 100644
index 0000000000..073e239ed7
--- /dev/null
+++ b/src/core/SkUnPreMultiplyPriv.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2017 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkUnPreMultiplyPriv_DEFINED
+#define SkUnPreMultiplyPriv_DEFINED
+
+#include "SkColor.h"
+
+template <bool kSwapRB>
+void SkUnpremultiplyRow(uint32_t* dst, const uint32_t* src, int count) {
+ const SkUnPreMultiply::Scale* table = SkUnPreMultiply::GetScaleTable();
+
+ for (int i = 0; i < count; i++) {
+ uint32_t c = *src++;
+ uint8_t r, g, b, a;
+ if (kSwapRB) {
+ r = (c >> 16) & 0xFF;
+ g = (c >> 8) & 0xFF;
+ b = (c >> 0) & 0xFF;
+ a = (c >> 24) & 0xFF;
+ } else {
+ r = (c >> 0) & 0xFF;
+ g = (c >> 8) & 0xFF;
+ b = (c >> 16) & 0xFF;
+ a = (c >> 24) & 0xFF;
+ }
+
+ if (0 != a && 255 != a) {
+ SkUnPreMultiply::Scale scale = table[a];
+ r = SkUnPreMultiply::ApplyScale(scale, r);
+ g = SkUnPreMultiply::ApplyScale(scale, g);
+ b = SkUnPreMultiply::ApplyScale(scale, b);
+ }
+
+ *dst++ = (r << 0) | (g << 8) | (b << 16) | (a << 24);
+ }
+}
+
+#endif