2013-10-13 21 views
0

我有周圍的一些像素移動的圖像中的射函數:應用變換到NV12像I420

pixel (x, y) ===func===> pixel (X, Y) 
X = funcX(x, y) 
Y = funcY(y, x) 

我想要使用此功能在RGB,I420和NV12模式來改造整個圖像。

* RGB *:如果圖像是RGB模式,這是很明顯:

strideR = strideG = strideB = width; 

//Temporary table for the destination 
for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     toR[i][j] = j * strideR + i; 
     toG[i][j] = j * strideG + i; 
     toB[i][j] = j * strideB + i; 
    } 

//Temporary table for the source 
for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     fromR[i][j] = funcY(i, j) * strideR + funcX(i, j); 
     fromG[i][j] = funcY(i, j) * strideG + funcX(i, j); 
     fromB[i][j] = funcY(i, j) * strideB + funcX(i, j); 
    } 

for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     destR[ toR[i][j] ] = srcR[ fromR[i][j] ]; 
     destG[ toG[i][j] ] = srcG[ fromG[i][j] ]; 
     destb[ toB[i][j] ] = srcB[ fromB[i][j] ]; 
    } 

* I420 *:如果圖像是I420模式(YYYYYYYY UU VV),以下工作:

strideY = width; 
strideU = strideV = width/2; 

//Temporary table for the destination 
for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     toY[i][j] = j * strideY + i; 
     toU[i][j] = j/2 * strideU + i/2; 
     toV[i][j] = j/2 * strideV + i/2; 
    } 

//Temporary table for the source 
for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     fromY[i][j] = funcY(i, j) * strideY + funcX(i, j); 
     fromU[i][j] = funcY(i, j)/2 * strideU + funcX(i, j)/2; 
     fromV[i][j] = funcY(i, j)/2 * strideV + funcX(i, j)/2; 
    } 

    for (j = 0; j < height; j++) 
     for (i = 0; i < width; i++) { 
      destY[ toY[i][j] ] = srcY[ fromY[i][j] ]; 
      if ((i % 2 == 0) && (j % 2 == 0)) { 
       destU[ toU[i][j] ] = srcU[ fromU[i][j] ]; 
       destV[ toV[i][j] ] = srcV[ fromV[i][j] ]; 
      } 
     } 

* NV12 *:如果圖像是在NV12模式(YYYYYYYY UVUV),以下是工作:

strideY = strideUV = width; 

//Temporary table for the destination 
for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     toY[i][j] = j * strideY + i; 
     toUV[i][j] = j/2 * strideUV + i; 
    } 

//Temporary table for the source 
for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     fromY[i][j] = funcY(i, j) * strideY + funcX(i, j); 
     fromUV[i][j] = funcY(i, j)/2 * strideUV + funcX(i, j); 
    } 

for (j = 0; j < height; j++) 
    for (i = 0; i < width; i++) { 
     destY[ toY[i][j] ] = srcY[ fromY[i][j] ]; 
     if ((i % 2 == 0) && (j % 2 == 0)) { 
      destUV[ toUV[i][j] ] = srcUV[ fromUV[i][j] ]; 
      destUV[ toUV[i][j] + 1 ] = srcUV[ fromUV[i][j] + 1 ]; 
     } 
    } 

我得到的圖像,但錯誤的顏色。黑色和白色部分(又名Y部分)是正確的,但顏色部分(又稱UV部分)被改變。我究竟做錯了什麼?

回答

1

發現問題!解決方法是:

fromUV[i][j] = funcY(i, j)/2 * strideUV + ((int)(funcX(i, j)/2)) * 2; 

我需要將X/2放置到UV字節的開始處。

+0

嗨,我們有一個問題將I420轉換爲RGB,你能幫忙嗎? – Joseph