2 * Copyright (c) 2021 Samsung Electronics Co., Ltd. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in all
12 * copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 #ifdef THORVG_NEON_VECTOR_SUPPORT
27 static inline uint8x8_t ALPHA_BLEND_NEON(uint8x8_t c, uint8x8_t a)
29 uint16x8_t t = vmull_u8(c, a);
30 return vshrn_n_u16(t, 8);
34 static inline void neonRasterRGBA32(uint32_t *dst, uint32_t val, uint32_t offset, int32_t len)
36 uint32_t iterations = len / 4;
37 uint32_t neonFilled = iterations * 4;
40 uint32x4_t vectorVal = {val, val, val, val};
42 for (uint32_t i = 0; i < iterations; ++i) {
43 vst1q_u32(dst, vectorVal);
47 int32_t leftovers = len - neonFilled;
48 while (leftovers--) *dst++ = val;
52 static inline bool neonRasterTranslucentRle(SwSurface* surface, const SwRleData* rle, uint32_t color)
54 auto span = rle->spans;
56 uint8x8_t *vDst = NULL;
58 for (uint32_t i = 0; i < rle->size; ++i) {
59 auto dst = &surface->buffer[span->y * surface->stride + span->x];
62 if ((((uint32_t) dst) & 0x7) != 0) {
63 vDst = (uint8x8_t*)(dst+1);
66 vDst = (uint8x8_t*) dst;
69 if (span->coverage < 255) src = ALPHA_BLEND(color, span->coverage);
71 auto ialpha = 255 - surface->blender.alpha(src);
73 uint8x8_t vSrc = (uint8x8_t) vdup_n_u32(src);
74 uint8x8_t vIalpha = vdup_n_u8((uint8_t) ialpha);
76 uint32_t iterations = (span->len - align) / 2;
77 uint32_t left = (span->len - align) % 2;
79 //Fill not aligned byte
80 if (align) *dst = src + ALPHA_BLEND(*dst, ialpha);
82 for (uint32_t x = 0; x < iterations; ++x) vDst[x] = vadd_u8(vSrc, ALPHA_BLEND_NEON(vDst[x], vIalpha));
84 if (left) dst[span->len - 1] = src + ALPHA_BLEND(dst[span->len - 1], ialpha);