不知道YCrCb数据和奇场,偶场的关系,搞了半天没搞出来。 下面是我写的程序,720*525,数据放在szBMPData里了。 FILE *file; int i,j; double Y0,Y1,Cr,Cb; BYTE byWrite[6]; double fWrite[6];
file = fopen(dlg.GetPathName(),"r+"); nSeekPos = 54; byWrite[2] = 0; fseek(file,nSeekPos,SEEK_SET); for(i=0;i<525;i++) { for(j=0;j<360;j++) { //byWrite[0] = m_szBMPData[i*1440 + 1440 - j*2-1]; //byWrite[1] = m_szBMPData[i*1440 + 1440 - j*2];
Y0 = m_szBMPData[i*1440 + 1440 - j*4]; Y1 = m_szBMPData[i*1440 + 1440 - j*4-2]; Cb = m_szBMPData[i*1440 + 1440 - j*4-1]; Cr = m_szBMPData[i*1440 + 1440 - j*4-3];
/*Cr = m_szBMPData[i*1440 + 1440 - j*4]; Cb = m_szBMPData[i*1440 + 1440 - j*4-2]; Y0 = m_szBMPData[i*1440 + 1440 - j*4-1]; Y1= m_szBMPData[i*1440 + 1440 - j*4-3];*/ /* C = Y - 16; D = U - 128;U (Cb) E = V - 128;V (Cr) R = clip( round( 1.164383 * C + 1.596027 * E ) ) G = clip( round( 1.164383 * C - (0.391762 * D) - (0.812968 * E) ) ) B = clip( round( 1.164383 * C + 2.017232 * D ) ) */ fWrite[2]=1.164383*(Y0-16)+1.596027*(Cr-128);//r fWrite[1]=1.164383*(Y0-16)-0.812968*(Cr-128)-0.391762*(Cb-128);//G fWrite[0]=1.164383*(Y0-16)+1.596027*(Cr-128);//B
fWrite[5]=1.164383*(Y1-16)+1.596027*(Cr-128);//r fWrite[4]=1.164383*(Y1-16)-0.812968*(Cr-128)-0.391762*(Cb-128);//G fWrite[3]=1.164383*(Y1-16)+1.596027*(Cr-128);//B for(int k=0;k<6;k++) { byWrite[k] = (BYTE)fWrite[k]; } if(!feof(file)) { fwrite(byWrite,6,1,file); } else { break; } } } fclose(file);
|