【问题标题】:Overlaying an yuv Image over another image将 yuv 图像覆盖在另一个图像上
【发布时间】:2017-07-27 19:43:40
【问题描述】:

我想将一个 yuv 图像覆盖在另一个 yuv 图像上。假设如果有 640x 480 图像,我想在源图像的右下方叠加一个小尺寸图像。 请帮忙。

【问题讨论】:

  • YUV 图像有很多变体,平面和双平面图像,全彩色或缩小彩色信息(例如 422 或 420)。您能否更具体地介绍一下手头的格式?
  • 嗨 Codo ...你能不能给一些关于 yuv 420 刨床的想法
  • 你会为每种图像格式重新提出这个问题吗?
  • 没有 .. 但是交错格式会有什么不同

标签: c image-processing


【解决方案1】:

平面 YUV 420 图像由 640 x 480 字节的 Y 样本、320 x 240 字节的 U 样本和 320 x 240 字节的 V 样本组成。由于每个 2x2 块(而不是每个像素)只存在颜色信息,我假设所有图像大小和位置都是 2 的倍数。(否则会变得更加复杂。)

此外,我假设在 Y 和 U 之间或 U 和 V 样本之间的行尾没有填充。

void copyRect(unsigned char* targetImage, int targetWidth, int targetHeight, 
    unsigned char* sourceImage, int sourceWidth, int sourceHeight,
    int sourceLeft, int sourceTop,
    int width, int height,
    int targetLeft, int targetTop)
{
    // Y samples
    unsigned char* tgt = targetImage + targetTop * targetWidth + targetLeft;
    unsigned char* src = sourceImage + sourceTop * sourceWidth + sourceLeft;
    for (int i = 0; i < height; i++) {
        memcpy(tgt, src, width);
        tgt += targetWidth;
        src += sourceWidth;
    }

    // U samples
    tgt = targetImage + targetHeight * targetWidth
        + (targetTop / 2) * (targetWidth / 2) + (targetLeft / 2);
    src = sourceImage + sourceHeight * sourceWidth
        + (sourceTop / 2) * (sourceWidth / 2) + (sourceLeft / 2);
    for (int i = 0; i < height / 2; i++) {
        memcpy(tgt, src, width / 2);
        tgt += targetWidth / 2;
        src += sourceWidth / 2;
    }

    // V samples
    tgt = targetImage + targetHeight * targetWidth + (targetHeight / 2) * (targetWidth / 2)
        + (targetTop / 2) * (targetWidth / 2) + (targetLeft / 2);
    src = sourceImage + sourceHeight * sourceWidth + (sourceHeight / 2) * (sourceWidth / 2)
        + (sourceTop / 2) * (sourceWidth / 2) + (sourceLeft / 2);
    for (int i = 0; i < height / 2; i++) {
        memcpy(tgt, src, width / 2);
        tgt += targetWidth / 2;
        src += sourceWidth / 2;
    }
}

我从未尝试编译代码。所以没有保证。

参数为:

targetImage:目标图片的像素数据,另一张图片复制到的地方

targetWidth, targetHeigt:目标图片的尺寸

sourceImage:源图片的像素数据,一部分复制到另一张图片中

sourceWidth, sourceHeight:源图片的尺寸

sourceLeft, sourceTop:要复制的区域的源图像的左上角

width,height:要复制的区域大小

targetLeft, targetTop:目标图像中的左上角位置,该区域被复制到该位置

【讨论】:

  • Codo,你怎么从来没有尝试过编译这段代码?你的意思是你只是坐下来从头开始写? :)
  • 是的。我刚刚发现并纠正了小错误并添加了参数说明。
猜你喜欢
  • 2011-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-05
  • 2019-12-05
  • 2019-03-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多