如何镜像swscale PIX_FMT_YUYV422
我正在尝试水平镜像 libswscale PIX_FMT_YUYV422 类型图像。对每行使用每像素 16 位的简单循环会导致颜色错误,例如蓝色对象是橙色。这是我的代码:
typedef unsigned short YUVPixel; // 16 bits per pixel
for (int y = 0; y < outHeight; y++)
{
YUVPixel *p1 = (YUVPixel*)pBits + y * outWidth;
YUVPixel *p2 = p1 + outWidth - 1;
for (int x = 0; x < outWidth/2; x++) // outWidth is image width in pixels
{
// packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
unsigned short tmp;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
}
然后我尝试将 YUVPixel 重新定义为 32 位类型并相应地修改我的循环。这会产生正确的颜色,但看起来相邻像素被交换了。有什么想法吗,我完全迷失了?
I'm trying to mirror libswscale PIX_FMT_YUYV422-type image horizontally. Using simple loop for each line with 16-bits per pixel results in having colors wrong, for example blue objects are orange. Here is my code:
typedef unsigned short YUVPixel; // 16 bits per pixel
for (int y = 0; y < outHeight; y++)
{
YUVPixel *p1 = (YUVPixel*)pBits + y * outWidth;
YUVPixel *p2 = p1 + outWidth - 1;
for (int x = 0; x < outWidth/2; x++) // outWidth is image width in pixels
{
// packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
unsigned short tmp;
tmp = *p1;
*p1 = *p2;
*p2 = tmp;
}
}
Then I tried redefining YUVPixel as 32-bit type and modifying my loop accordingly. This results in correct colors, but looks like neighboring pixels are swapped. Any ideas, I'm totally lost with this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用 32 位 YUVPixel 类型的方法很好,您只需确保在移动像素结构后交换该像素结构内的两个 Y 值,例如:
U 和 V 值对于整个 2 像素结构都有效, Y 值必须翻转。
Your approach using a 32bit YUVPixel type was good, you only have to make sure you swap the two Y values inside that pixel structure after moving it around, e.g.:
The U and V values are both valid for the whole 2-pixel-structure, the Y values have to be flipped.