直接进行nv21或者nv12的resize
作者:互联网
直接对nv21的数据进行resize。
这是之前项目组遗留的一段代码改过来的。结果不太好。
void Scaler::Resize_NV(const Buffer *src,
Buffer *dst){
// this function have some problem
if (src->width == dst->width && src->height == dst->height) {
memcpy(dst->data[0], src->data[0], (dst->width * dst->height * 3 / 2) * sizeof(uint8_t));
return;
}
int srcy, srcx, src_index;
int xrIntFloat_16 = (src->width << 16) / dst->width + 1;
int yrIntFloat_16 = (src->height << 16) / dst->height + 1;
uint8_t* dst_uv = dst->data[0] + dst->height * dst->width;
dst->data[1] = dst_uv;
uint8_t* src_uv = src->data[0] + src->height * src->width;
uint8_t* dst_uv_yScanline = nullptr;
uint8_t* src_uv_yScanline = nullptr;
uint8_t* dst_y_slice = dst->data[0];
uint8_t* src_y_slice = nullptr;
uint8_t* sp = nullptr;
uint8_t* dp = nullptr;
for (uint32_t y = 0; y < (dst->height & -7); ++y) {
srcy = (y * yrIntFloat_16) >> 16;
src_y_slice = src->data[0] + srcy * src->width;
if (0 == (y & 1)) {
dst_uv_yScanline = dst_uv + (y / 2) * dst->width;
src_uv_yScanline = src_uv + (srcy / 2) * src->width;
}
for (uint32_t x = 0; x < (dst->width & -7); ++x) {
srcx = (x * xrIntFloat_16) >> 16;
dst_y_slice[x] = src_y_slice[srcx];
if ((y & 1) == 0) { // y is even
if ((x & 1) == 0) { // x is even
src_index = (srcx / 2) * 2;
sp = dst_uv_yScanline + x;
dp = src_uv_yScanline + src_index;
*sp = *dp;
++sp;
++dp;
*sp = *dp;
}
}
}
dst_y_slice += dst->width;
}
dst->stride[0] = dst->width;
dst->stride[1] = dst->width;
dst->stride[2] = 0;
dst->color = src->color;
}
结果
原图
结果
这结果明显有黑色的线条,不对啊。
后面我用libyuv实现了下nv的resize。
libyuv实现nv resize
标签:src,nv21,dst,uv,uint8,height,width,nv12,resize 来源: https://www.cnblogs.com/cyssmile/p/13725506.html