| OLD | NEW |
| (Empty) | |
| 1 /* palette_neon_intrinsics.c - NEON optimised palette expansion functions |
| 2 * |
| 3 * Copyright (c) 2017 ARM Limited |
| 4 * Copyright (c) 2017 Glenn Randers-Pehrson |
| 5 * Written by Richard Townsend <Richard.Townsend@arm.com>, February 2017. |
| 6 * |
| 7 * This code is released under the libpng license. |
| 8 * For conditions of distribution and use, see the disclaimer |
| 9 * and license in png.h |
| 10 */ |
| 11 |
| 12 #include "../pngpriv.h" |
| 13 |
| 14 #if PNG_ARM_NEON_IMPLEMENTATION == 1 |
| 15 |
| 16 #include <arm_neon.h> |
| 17 |
| 18 /* Build an RGBA palette from the RGB and separate alpha palettes. */ |
| 19 void |
| 20 png_riffle_palette(png_structrp png_ptr, png_row_infop row_info) |
| 21 { |
| 22 png_const_colorp palette = png_ptr->palette; |
| 23 png_bytep riffled_palette = png_ptr->row_tmp_palette; |
| 24 png_const_bytep trans_alpha = png_ptr->trans_alpha; |
| 25 int num_trans = png_ptr->num_trans; |
| 26 |
| 27 int i; |
| 28 for (i = 0; i < (1 << row_info->bit_depth); i++) { |
| 29 riffled_palette[(i << 2) + 0] = palette[i].red; |
| 30 riffled_palette[(i << 2) + 1] = palette[i].green; |
| 31 riffled_palette[(i << 2) + 2] = palette[i].blue; |
| 32 if (i >= num_trans) { |
| 33 riffled_palette[(i << 2) + 3] = 0xff; |
| 34 } else { |
| 35 riffled_palette[(i << 2) + 3] = trans_alpha[i]; |
| 36 } |
| 37 } |
| 38 } |
| 39 |
| 40 /* Expands a palettized row into RGBA. */ |
| 41 int |
| 42 png_do_expand_palette_neon(png_structrp png_ptr, png_row_infop row_info, |
| 43 png_const_bytep row, const png_bytepp ssp, const png_bytepp ddp) |
| 44 { |
| 45 |
| 46 png_uint_32 row_width = row_info->width; |
| 47 const png_uint_32 *riffled_palette = (const png_uint_32*)png_ptr->row_tmp_pal
ette; |
| 48 int i; |
| 49 |
| 50 if (row_width >= 4) { |
| 51 /* This function originally gets the last byte of the output row |
| 52 The NEON part writes forward from a given position, so we have |
| 53 to seek this back by 4 pixels x 4 bytes, for a total offset of 16. |
| 54 We should only update the output pointer if the loop's going to run.*/ |
| 55 *ddp = *ddp - 15; |
| 56 } |
| 57 |
| 58 for(i = 0; i < row_width; i += 4) { |
| 59 uint32x4_t cur; |
| 60 png_bytep sp = *ssp - i, dp = *ddp - (i << 2); |
| 61 cur = vld1q_dup_u32 (riffled_palette + *(sp - 3)); |
| 62 cur = vld1q_lane_u32(riffled_palette + *(sp - 2), cur, 1); |
| 63 cur = vld1q_lane_u32(riffled_palette + *(sp - 1), cur, 2); |
| 64 cur = vld1q_lane_u32(riffled_palette + *(sp), cur, 3); |
| 65 vst1q_u32((void *)dp, cur); |
| 66 } |
| 67 if (i != row_width) { |
| 68 i -= 4; /* Remove the amount that wasn't processed */ |
| 69 } |
| 70 |
| 71 /* Decrement output pointers. */ |
| 72 *ssp = *ssp - i; |
| 73 *ddp = *ddp - (i << 2); |
| 74 return i; |
| 75 } |
| 76 |
| 77 #endif /* PNG_ARM_NEON_IMPLEMENTATION */ |
| OLD | NEW |