저.. bitmap 24bit를 16bit로 변환이 하고싶은데요.. 제발알려주세요ㅠㅠㅠㅠㅠㅠ
제가 벌써 일주일째 이 코드를 보고있는데요..ㅠ
영 해결이 안됩니다.ㅠㅠ
제가 하고싶은것은
원래openCV를 이용해서 bmp파일을 320*240로 바꿧는데요..
24bit bmp로 저장이 되는겁니다..ㅠ
그런데 이번에 같이 프로젝트 하는 오빠가 자기가 만든 LCD는 16bit bitmap밖에 못읽는다면서..
저에게 24bit를 16bit로 변환해서 저장하랍니다ㅠㅠ
그런데 openCV에는 그런 기능이 업어요..ㅠㅠ
그래서 제가 직접 구현을 하려고 이책 저책 찾아서 저장하는것까지 했는데..
그림 색깔이 이상하게 변합니다.ㅠㅠㅠ
색좀 안변하게 할수있는방법 없을까요?
아무리 24에서16으로 변환했다지만.
이건 너무 심하게 변합니다.ㅠㅠㅠ
코드 나갑니다.ㅠ
//헤더부분 선언.
#define WIDTHBYTES(bits) (((bits) + 31) / 32 * 4)
#define RGB888_TO_RGB565(r,g,b) ((b%32) + ((g%64) << 6) + ((r%32) << 11))
CString m_FileName;
CString FileName_2;
IplImage* m_pImage;
IplImage* A;
//cpp부분 코드
CvSize size_2;
CString bmpFilename_2;
size_2.width = 320;
size_2.height = 240;
A= cvCreateImage(size_2,IPL_DEPTH_8U, 3);
cvResize(m_pImage, A);
WORD A_565[240][320];
double scale=1.3;
CvMemStorage* storage=cvCreateMemStorage(0);
IplImage* gray=cvCreateImage(cvSize(m_pImage->width,m_pImage->height),8,1);
IplImage* small_img=cvCreateImage(cvSize(cvRound(m_pImage->width/scale), cvRound(m_pImage->height/scale)),8,1);
cvCvtColor(m_pImage, gray, CV_BGR2GRAY);
cvResize(gray,small_img,CV_INTER_LINEAR);
cvEqualizeHist(small_img, small_img);
BITMAPFILEHEADER bmFileHeader;
BITMAPINFOHEADER bmInfoHeader;
// BMP 헤더
bmFileHeader.bfType = 0x4D42;
bmFileHeader.bfOffBits = (DWORD)sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
bmInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
bmInfoHeader.biWidth = 320; // 너비
bmInfoHeader.biHeight = -240; // 높이
bmInfoHeader.biPlanes = 1; //무조건1
bmInfoHeader.biBitCount = 16; // 색상 비트
bmInfoHeader.biCompression = 0; //압축여부
int rwidth=WIDTHBYTES(320*bmInfoHeader.biBitCount);
bmInfoHeader.biSizeImage = rwidth*240;
bmFileHeader.bfSize = (DWORD)( sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) + ( rwidth * 240 ) );
bmInfoHeader.biXPelsPerMeter = 3780;
bmInfoHeader.biYPelsPerMeter = 3780;
bmInfoHeader.biClrUsed = 0;
bmInfoHeader.biClrImportant = 0;
int p,q;
for(p=0; pheight; p++)
{
for(q=0; qwidth; q++)
{
A_565[p][q]=((A->imageData[p*A->widthStep + q*3]*31)/255*4)*2^11
+((A->imageData[p*A->widthStep + q*3+1]*63)/255*4)*2^5
+((A->imageData[p*A->widthStep + q*3+2]*31)/255*4);
}
}
UpdateData(TRUE);
CFile file;
bmpFilename_2.Format("%s.%s",m_FileName,"bmp");
file.Open(bmpFilename_2, CFile::shareDenyWrite | CFile::modeCreate | CFile::modeWrite );
file.Write(&bmFileHeader, sizeof(BITMAPFILEHEADER));
file.Write(&bmInfoHeader, sizeof(BITMAPINFOHEADER));
file.Write(A_565,rwidth*240);
file.Close();
AfxMessageBox(_T("\nwas saved"));
여기까지 관련코드입니다.ㅠㅠ
첨부 | 파일 크기 |
---|---|
![]() | 77.59 KB |
http://en.wikipedia.org/wiki/
http://en.wikipedia.org/wiki/Dither
디더링 알고리즘에 대해 검색해 보는건 어떨까요?
--------------------------
피할 수 있을때 즐겨라!
http://snowall.tistory.com
피할 수 있을때 즐겨라! http://melotopia.net/b
댓글 달기