aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/opts/SkSwizzler_opts.h
diff options
context:
space:
mode:
authorGravatar msarett <msarett@google.com>2016-02-03 11:17:43 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2016-02-03 11:17:44 -0800
commit1e06079b259d1091b735492b2f71d9897c14c608 (patch)
tree3ee5d1852cd43576b8df65105f175a92f299e792 /src/opts/SkSwizzler_opts.h
parentffad53aa7537d9122465e68c2be9b688b3313c3f (diff)
NEON optimizations for GrayAlpha -> RGBA/BGRA Premul/Unpremul
PNG Decode Time Nexus 6P (for a test set of GrayAlpha encoded PNGs) Regular Unpremul 0.91x Zero Init Unpremul 0.92x Regular Premul 0.84x Zero Init Premul 0.86x BUG=skia:4767 GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1663623002 CQ_EXTRA_TRYBOTS=client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot Review URL: https://codereview.chromium.org/1663623002
Diffstat (limited to 'src/opts/SkSwizzler_opts.h')
-rw-r--r--src/opts/SkSwizzler_opts.h106
1 files changed, 106 insertions, 0 deletions
diff --git a/src/opts/SkSwizzler_opts.h b/src/opts/SkSwizzler_opts.h
index 27416ea9e8..f0492e7d33 100644
--- a/src/opts/SkSwizzler_opts.h
+++ b/src/opts/SkSwizzler_opts.h
@@ -98,6 +98,33 @@ static void gray_to_RGB1_portable(uint32_t dst[], const void* vsrc, int count) {
}
}
+static void grayA_to_RGBA_portable(uint32_t dst[], const void* vsrc, int count) {
+ const uint8_t* src = (const uint8_t*)vsrc;
+ for (int i = 0; i < count; i++) {
+ uint8_t g = src[0],
+ a = src[1];
+ src += 2;
+ dst[i] = (uint32_t)a << 24
+ | (uint32_t)g << 16
+ | (uint32_t)g << 8
+ | (uint32_t)g << 0;
+ }
+}
+
+static void grayA_to_rgbA_portable(uint32_t dst[], const void* vsrc, int count) {
+ const uint8_t* src = (const uint8_t*)vsrc;
+ for (int i = 0; i < count; i++) {
+ uint8_t g = src[0],
+ a = src[1];
+ src += 2;
+ g = (g*a+127)/255;
+ dst[i] = (uint32_t)a << 24
+ | (uint32_t)g << 16
+ | (uint32_t)g << 8
+ | (uint32_t)g << 0;
+ }
+}
+
#if defined(SK_ARM_HAS_NEON)
// Rounded divide by 255, (x + 127) / 255
@@ -311,6 +338,69 @@ static void gray_to_RGB1(uint32_t dst[], const void* vsrc, int count) {
gray_to_RGB1_portable(dst, src, count);
}
+template <bool kPremul>
+static void expand_grayA(uint32_t dst[], const void* vsrc, int count) {
+ const uint8_t* src = (const uint8_t*) vsrc;
+ while (count >= 16) {
+ // Load 16 pixels.
+ uint8x16x2_t ga = vld2q_u8(src);
+
+ // Premultiply if requested.
+ if (kPremul) {
+ ga.val[0] = vcombine_u8(
+ scale(vget_low_u8(ga.val[0]), vget_low_u8(ga.val[1])),
+ scale(vget_high_u8(ga.val[0]), vget_high_u8(ga.val[1])));
+ }
+
+ // Set each of the color channels.
+ uint8x16x4_t rgba;
+ rgba.val[0] = ga.val[0];
+ rgba.val[1] = ga.val[0];
+ rgba.val[2] = ga.val[0];
+ rgba.val[3] = ga.val[1];
+
+ // Store 16 pixels.
+ vst4q_u8((uint8_t*) dst, rgba);
+ src += 16*2;
+ dst += 16;
+ count -= 16;
+ }
+
+ if (count >= 8) {
+ // Load 8 pixels.
+ uint8x8x2_t ga = vld2_u8(src);
+
+ // Premultiply if requested.
+ if (kPremul) {
+ ga.val[0] = scale(ga.val[0], ga.val[1]);
+ }
+
+ // Set each of the color channels.
+ uint8x8x4_t rgba;
+ rgba.val[0] = ga.val[0];
+ rgba.val[1] = ga.val[0];
+ rgba.val[2] = ga.val[0];
+ rgba.val[3] = ga.val[1];
+
+ // Store 8 pixels.
+ vst4_u8((uint8_t*) dst, rgba);
+ src += 8*2;
+ dst += 8;
+ count -= 8;
+ }
+
+ auto proc = kPremul ? grayA_to_rgbA_portable : grayA_to_RGBA_portable;
+ proc(dst, src, count);
+}
+
+static void grayA_to_RGBA(uint32_t dst[], const void* src, int count) {
+ expand_grayA<false>(dst, src, count);
+}
+
+static void grayA_to_rgbA(uint32_t dst[], const void* src, int count) {
+ expand_grayA<true>(dst, src, count);
+}
+
#elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSSE3
template <bool kSwapRB>
@@ -482,6 +572,14 @@ static void gray_to_RGB1(uint32_t dst[], const void* vsrc, int count) {
gray_to_RGB1_portable(dst, src, count);
}
+static void grayA_to_RGBA(uint32_t dst[], const void* src, int count) {
+ grayA_to_RGBA_portable(dst, src, count);
+}
+
+static void grayA_to_rgbA(uint32_t dst[], const void* src, int count) {
+ grayA_to_rgbA_portable(dst, src, count);
+}
+
#else
static void RGBA_to_rgbA(uint32_t* dst, const void* src, int count) {
@@ -508,6 +606,14 @@ static void gray_to_RGB1(uint32_t dst[], const void* src, int count) {
gray_to_RGB1_portable(dst, src, count);
}
+static void grayA_to_RGBA(uint32_t dst[], const void* src, int count) {
+ grayA_to_RGBA_portable(dst, src, count);
+}
+
+static void grayA_to_rgbA(uint32_t dst[], const void* src, int count) {
+ grayA_to_rgbA_portable(dst, src, count);
+}
+
#endif
}