저.. bitmap 24bit를 16bit로 변환이 하고싶은데요.. 제발알려주세요ㅠㅠㅠㅠㅠㅠ

rokhansol의 이미지

제가 벌써 일주일째 이 코드를 보고있는데요..ㅠ
영 해결이 안됩니다.ㅠㅠ
제가 하고싶은것은
원래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"));

여기까지 관련코드입니다.ㅠㅠ

File attachments: 
첨부파일 크기
Image icon 21679453_1284842383.jpg77.59 KB
snowall의 이미지

http://en.wikipedia.org/wiki/Dither

디더링 알고리즘에 대해 검색해 보는건 어떨까요?

--------------------------
피할 수 있을때 즐겨라!
http://snowall.tistory.com

피할 수 있을때 즐겨라! http://melotopia.net/b

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.