2011-07-08 92 views
0

我想覆蓋另一個yuv圖像上的yuv圖像。假設如果有640x480圖像,我想在源圖像的右下方覆蓋一個小尺寸的圖像。 請幫忙。覆蓋另一個圖像上的yuv圖像

+0

YUV圖像,平面和雙平面圖像,完整或減少的顏色信息(如422或420)有許多變體。你能否更具體地瞭解手頭的格式? – Codo

+0

嗨Codo ...你可以請現在給yuv 420刨牀一些想法 – arccc

+0

你打算重新問這個問題的每個圖像格式? –

回答

2

平面YUV 420圖像由Y樣本的640 x 480字節組成,其後是320 x 240字節的U樣本和320 x 240字節的V樣本。由於每個2x2塊(而不是每個像素)只存在顏色信息,因此我將假設所有圖像尺寸ond位置都是2的倍數。(否則它會變得更加複雜。)

此外,I我們假設在一行的末尾沒有填充,在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:目標圖像,其中,所述其它圖像被複制到

targetWidthtargetHeigt的像素數據:對象圖像的尺寸

sourceImage:源圖像的像素數據,其中一部分被複制到其他圖像中

sourceWidth,sourceHeight:源圖像的尺寸

sourceLeftsourceTop:區域的源圖像內的左上位置被複制

寬度高度:的大小要複製的區域

targetLefttargetTop:目標圖像中左上方的位置,其中區域被複制到

+0

科多,你怎麼從來沒有試圖編譯這個代碼?你的意思是你坐下來從頭上寫下來? :) – Ulterior

+0

是的。我剛剛發現並糾正了一些小錯誤,並添加了對這些參數的描述。 – Codo