Path: blob/master/3rdparty/libwebp/src/dsp/lossless_enc_neon.c
16348 views
// Copyright 2015 Google Inc. All Rights Reserved.1//2// Use of this source code is governed by a BSD-style license3// that can be found in the COPYING file in the root of the source4// tree. An additional intellectual property rights grant can be found5// in the file PATENTS. All contributing project authors may6// be found in the AUTHORS file in the root of the source tree.7// -----------------------------------------------------------------------------8//9// NEON variant of methods for lossless encoder10//11// Author: Skal ([email protected])1213#include "src/dsp/dsp.h"1415#if defined(WEBP_USE_NEON)1617#include <arm_neon.h>1819#include "src/dsp/lossless.h"20#include "src/dsp/neon.h"2122//------------------------------------------------------------------------------23// Subtract-Green Transform2425// vtbl?_u8 are marked unavailable for iOS arm64 with Xcode < 6.3, use26// non-standard versions there.27#if defined(__APPLE__) && defined(__aarch64__) && \28defined(__apple_build_version__) && (__apple_build_version__< 6020037)29#define USE_VTBLQ30#endif3132#ifdef USE_VTBLQ33// 255 = byte will be zeroed34static const uint8_t kGreenShuffle[16] = {351, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 13, 25536};3738static WEBP_INLINE uint8x16_t DoGreenShuffle_NEON(const uint8x16_t argb,39const uint8x16_t shuffle) {40return vcombine_u8(vtbl1q_u8(argb, vget_low_u8(shuffle)),41vtbl1q_u8(argb, vget_high_u8(shuffle)));42}43#else // !USE_VTBLQ44// 255 = byte will be zeroed45static const uint8_t kGreenShuffle[8] = { 1, 255, 1, 255, 5, 255, 5, 255 };4647static WEBP_INLINE uint8x16_t DoGreenShuffle_NEON(const uint8x16_t argb,48const uint8x8_t shuffle) {49return vcombine_u8(vtbl1_u8(vget_low_u8(argb), shuffle),50vtbl1_u8(vget_high_u8(argb), shuffle));51}52#endif // USE_VTBLQ5354static void SubtractGreenFromBlueAndRed_NEON(uint32_t* argb_data,55int num_pixels) {56const uint32_t* const end = argb_data + (num_pixels & ~3);57#ifdef USE_VTBLQ58const uint8x16_t shuffle = vld1q_u8(kGreenShuffle);59#else60const uint8x8_t shuffle = vld1_u8(kGreenShuffle);61#endif62for (; argb_data < end; argb_data += 4) {63const uint8x16_t argb = vld1q_u8((uint8_t*)argb_data);64const uint8x16_t greens = DoGreenShuffle_NEON(argb, shuffle);65vst1q_u8((uint8_t*)argb_data, vsubq_u8(argb, greens));66}67// fallthrough and finish off with plain-C68VP8LSubtractGreenFromBlueAndRed_C(argb_data, num_pixels & 3);69}7071//------------------------------------------------------------------------------72// Color Transform7374static void TransformColor_NEON(const VP8LMultipliers* const m,75uint32_t* argb_data, int num_pixels) {76// sign-extended multiplying constants, pre-shifted by 6.77#define CST(X) (((int16_t)(m->X << 8)) >> 6)78const int16_t rb[8] = {79CST(green_to_blue_), CST(green_to_red_),80CST(green_to_blue_), CST(green_to_red_),81CST(green_to_blue_), CST(green_to_red_),82CST(green_to_blue_), CST(green_to_red_)83};84const int16x8_t mults_rb = vld1q_s16(rb);85const int16_t b2[8] = {860, CST(red_to_blue_), 0, CST(red_to_blue_),870, CST(red_to_blue_), 0, CST(red_to_blue_),88};89const int16x8_t mults_b2 = vld1q_s16(b2);90#undef CST91#ifdef USE_VTBLQ92static const uint8_t kg0g0[16] = {93255, 1, 255, 1, 255, 5, 255, 5, 255, 9, 255, 9, 255, 13, 255, 1394};95const uint8x16_t shuffle = vld1q_u8(kg0g0);96#else97static const uint8_t k0g0g[8] = { 255, 1, 255, 1, 255, 5, 255, 5 };98const uint8x8_t shuffle = vld1_u8(k0g0g);99#endif100const uint32x4_t mask_rb = vdupq_n_u32(0x00ff00ffu); // red-blue masks101int i;102for (i = 0; i + 4 <= num_pixels; i += 4) {103const uint8x16_t in = vld1q_u8((uint8_t*)(argb_data + i));104// 0 g 0 g105const uint8x16_t greens = DoGreenShuffle_NEON(in, shuffle);106// x dr x db1107const int16x8_t A = vqdmulhq_s16(vreinterpretq_s16_u8(greens), mults_rb);108// r 0 b 0109const int16x8_t B = vshlq_n_s16(vreinterpretq_s16_u8(in), 8);110// x db2 0 0111const int16x8_t C = vqdmulhq_s16(B, mults_b2);112// 0 0 x db2113const uint32x4_t D = vshrq_n_u32(vreinterpretq_u32_s16(C), 16);114// x dr x db115const int8x16_t E = vaddq_s8(vreinterpretq_s8_u32(D),116vreinterpretq_s8_s16(A));117// 0 dr 0 db118const uint32x4_t F = vandq_u32(vreinterpretq_u32_s8(E), mask_rb);119const int8x16_t out = vsubq_s8(vreinterpretq_s8_u8(in),120vreinterpretq_s8_u32(F));121vst1q_s8((int8_t*)(argb_data + i), out);122}123// fallthrough and finish off with plain-C124VP8LTransformColor_C(m, argb_data + i, num_pixels - i);125}126127#undef USE_VTBLQ128129//------------------------------------------------------------------------------130// Entry point131132extern void VP8LEncDspInitNEON(void);133134WEBP_TSAN_IGNORE_FUNCTION void VP8LEncDspInitNEON(void) {135VP8LSubtractGreenFromBlueAndRed = SubtractGreenFromBlueAndRed_NEON;136VP8LTransformColor = TransformColor_NEON;137}138139#else // !WEBP_USE_NEON140141WEBP_DSP_INIT_STUB(VP8LEncDspInitNEON)142143#endif // WEBP_USE_NEON144145146