R = 1.164 * (Y-16) + + 1.596 * (V-128) final : 5 bit
G = 1.164 * (Y-16) - 0.391 * (U-128) - 0.813 * (V-128) final : 6 bit
B = 1.164 * (Y-16) + 2.018 * (U-128) final : 5 bit
R.G.B Range : (Y.U.V are 8 bits):
max : B : 1.164 * (255-16) + 2.018 * (255-128) = 534.482
min : G : 1.164 * (0 - 16) - 0.391 * (255-128) - 0.813 * (255-128) = -171.832
所以 8 bit YUV 轉成 RGB 後,最高只有到
take advantage of the final 5-6-5 bits.
source not need to be 8 bits.
R = ( 1.164 * (Y-16) + + 1.596 * (V-128) )/8 final : 5 bit
G = ( 1.164 * (Y-16) - 0.391 * (U-128) - 0.813 *(V-128) )/4 final : 6 bit
B = ( 1.164 * (Y-16) + 2.018 * (U-128) )/8 final : 5 bit
變成:
R = 0.1455 * (Y-16) + + 0.1995 * (V-128) final : 5 bit
G = 0.291 * (Y-16) - 0.09775 * (U-128) - 0.04575 *(V-128) final : 6 bit
B = 0.1455 * (Y-16) + 0.25225 * (U-128) final : 5 bit
目標是希望..
word rgb565 = ( RY[Y]+RV[V] ) | ( GY[Y]+GU[U]+GV[V] ) | ( BY[Y]+BU[U] )
因為是 YUV420 ,最好是..(U.V矩陣 的HighWord和LowWord一樣)
問題:如何確保 + 後不會16 bit overfload ?
DWORD rgb565x2 =( (RYL[Y1]|RYH[Y2])+RV[V] ) |
( (GYL[Y1]|GYG[Y2])+GU[U]+GV[V] ) |
( (BYL[Y1]|BYH[Y2])+BU[U] )
if possible 再共用下一個scanline (因為是 YUV420)..
但是好像無法保證不會overflow (saturation)。
RP=RV[v];
GP=GU[U]+GV[V];
BP=BU[U];
DWORD rgb565x2linea =( (RYL[Y1a]|RYH[Y2a])+RP ) |
( (GYL[Y1a]|GYG[Y2a])+GP ) |
( (BYL[Y1a]|BYH[Y2a])+BP );
DWORD rgb565x2lineb =( (RYL[Y1b]|RYH[Y2b])+RP ) |
( (GYL[Y1b]|GYG[Y2b])+GP ) |
( (BYL[Y1b]|BYH[Y2b])+BP );
回到:
word rgb565 = ( RY[Y]+RV[V] ) | ( GY[Y]+GU[U]+GV[V] ) | ( BY[Y]+BU[U] )
ref http://msdn.microsoft.com/en-us/library/ms867704.aspx
沒有留言:
張貼留言