C 复制yuv420缓冲区

C 复制yuv420缓冲区,c,image-processing,C,Image Processing,我想将yuv420P像素写入缓冲区,而不是二进制文件。 假设我在指针中存储了luma、Cb和Cr luma = output_pixel.luma; cb = output_pixel.cb; cr = output_pixel.cr; int size = lenght * width; /* this is working */ fwrite(out_pixel.luma,1,size,out_file) fwrite(out_pixel.cb,1, size>> 2,out

我想将yuv420P像素写入缓冲区,而不是二进制文件。 假设我在指针中存储了luma、Cb和Cr

luma = output_pixel.luma;
cb = output_pixel.cb;
cr = output_pixel.cr;

int size = lenght * width;

/* this is working */
fwrite(out_pixel.luma,1,size,out_file)
fwrite(out_pixel.cb,1, size>> 2,out_file)
fwrite(out_pixel.cr,1,size >>2 ,out_file)
相反,如果在缓冲区中写入thorugh memcpy,则它不起作用,如

/* this is not working */
char *buffer = (char *)malloc(sizeof(size * 1.5));
memcpy(out_pixel.luma ,buffer,size);
memcpy(out_pixel.cb + size,buffer,size >> 2);
memcpy(out_pixel.cr + size + (size >> 2),buffer,size >> 2);

PS。只需复制o/p缓冲区中的像素。

调用memcpy时,参数是相反的

啊,C的乐趣。
:)

调用memcpy时,参数是相反的

啊,C的乐趣。 :)

sizeof(size*1.5)
是错误的,这甚至可以编译吗?您是否尝试过使用
malloc(大小+2*(大小>>2))
?正如marinara所说,你把参数颠倒了,另外,看起来你应该添加到
buffer
,而不是
outpixel.*
东西。
sizeof(size*1.5)
是错误的,这是编译吗?您是否尝试过使用
malloc(大小+2*(大小>>2))
?正如marinara所说,你把参数颠倒了,另外,看起来你应该添加到
buffer
中,而不是
outpixel.*
中。