我想知道是否可以使用霓虹灯向量将图像下采样 3 ?我正在尝试在纸上为此编写算法,但似乎不可能。因为当你得到例如 8 个字节时,你不能得到 3*3 像素,就没有足够的像素来完成下采样操作。根据 downsample by 2: Explaining ARM Neon Image Sampling 我考虑加载 16 字节,然后从一行加载 8 字节,然后将它们分配给 32 字节向量,然后处理该向量的 24 字节?
更新:我已经根据答案编写了示例代码,但是我在 vst1_u8 中遇到了分段错误...
inline void downsample3dOnePass( uint8_t* src, uint8_t *dst, int srcWidth)
{
// make sure rows/cols dividable by 8
int rows = ((srcWidth>>3)<<3);
// 8 pixels per row
rows=rows>>3;
for (int r = 0; r < rows; r++)
{
// load 24 pixels (grayscale)
uint8x8x3_t pixels = vld3_u8(src);
// first sum = d0 + d1
uint8x8_t firstSum = vadd_u8 ( pixels.val[0], pixels.val[1] );
// second sum = d1+d2;
uint8x8_t secondSum = vadd_u8 ( firstSum, pixels.val[2] );
// total sum = d0+d1+d2
uint8x8_t totalSum = vadd_u8(secondSum, firstSum);
// average = d0+d1+d2/8 ~9 for test
uint8x8_t totalAverage = vshr_n_u8(totalSum,3);
// store 8 bytes
vst1_u8(dst, totalAverage);
// move to next 3 rows
src+=24;
// move to next row
dst+=8;
}
}