C++Builder Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
C++빌더 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
메신저 프로젝트
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

C++빌더 Q&A
C++Builder Programming Q&A
[8869] [질문] Indexed Color 저장하는 방법 (2)
초짜 [syleejin] 1129 읽음    2001-07-09 18:35
지금까지의 질문/답변은 [Q1]/[A1]이구요
이번 질문은 [Q2] 랍니다.

[Q1]
: : 24bpp의 bitmap(In24bpp)을 8bpp(indexed color,Out8bppNOED)로 저장하려고 합니다.
: : 이때 팔레트는 Ref8bpp의 bitmap에서 가져오구요.
: : 아래처럼 했더니 칼라가 제대로 안나오는군요.
: : 아무래도 팔레트 처리를 잘못한듯한데
: : 팔레트를 읽어서 기록하는 방법을 좀 알려주세요.
: :
: : *****************************************************************
: : 구조체정의:
: :       struct IO{
: :             AnsiString filename;
: :             Graphics::TBitmap *pBitmap;
: :             LPPALETTEENTRY lppe;
: :       }In24bpp,Ref8bpp,Out8bppNOED,Out8bppED;
: : *****************************************************************
: :
: : void __fastcall TmainForm::N24bpp8bpp1Click(TObject *Sender)
: : {
: :       Out8bppNOED.pBitmap->Width = In24bpp.pBitmap->Width;
: :       Out8bppNOED.pBitmap->Height = In24bpp.pBitmap->Height;
: :       Out8bppNOED.pBitmap->PixelFormat = pf8bit;
: :
: :       HPALETTE hpal;
: :       hpal = Ref8bpp.pBitmap->Palette;
: :       GetPaletteEntries(hpal,0,256,Out8bppNOED.lppe);
: :
: :       hpal = Out8bppNOED.pBitmap->Palette;
: :       SetPaletteEntries(hpal,0,256,Out8bppNOED.lppe);
: :
: :       Byte       *bPtr, *oPtr, *rPtr;
: :       for (int y = 0 ; y < Out8bppNOED.pBitmap->Height ; y++)
: :       {
: :             oPtr = (Byte *)Out8bppNOED.pBitmap->ScanLine[y];
: :             //rPtr = (Byte *)Ref8bpp.pBitmap->ScanLine[y];
: :             for (int x = 0; x < Out8bppNOED.pBitmap->Width ; x++)
: :             {
: :                   //search the best matching Color in LUT
: :                   oPtr[x] = GetNearestPaletteIndex(hpal,In24bpp.pBitmap->Canvas->Pixels[x][y]);
: :             }
: :       }
: :       Out8bppNOED.pBitmap->Transparent = true;
: :       Out8bppNOED.pBitmap->TransparentMode = tmAuto;
: :       Image1->Canvas->Draw(0,0,Out8bppNOED.pBitmap);
: : }
: : *****************************************************************

[A1]
방태윤 님이 쓰신 글 :
: 실행해보니 코드에는 문제가 없는듯합니다.잘 되던데요...^^
:
: 24비트bmp를 8비트로 변환할때
: indexed color(팔레트가 인덱스되어있다는뜻이지요?)를 쓰면
: 화질손상이 오는것은 당연하다고 생각합니다.
: indexed 안된 팔레트를 사용해보십시요.
:
: 저의경험을 말씀드립니다,참고만하십시요.
: 24비트의그림의 각픽셀의 값을 셉니다.
: 예를들면 빨강이 몇개,파랑이 몇개,0xef1a102 몇개 ...이런식으로
: 모든픽셀의 색상값을 셉니다.
: 그중에 많이 쓰인 색상 256개를 꺼내서 그색상만으로 팔레트를 만듭니다.
:
: 색상표처럼 많은색상이있는 그림에는 전혀 효과가 없겠지만
: 사진같은 그림은 매우 근접하게 팔레트를 만들수 있습니다.끝.
:
:

[Q2]
제 프로그램에서는 indexed color를 반드시 사용해야 하기 때문에 팔레트를 만들어야 됩니다.
팔레트의 손상이 아니라 팔레트 쓰기 자체가 제대로 안되는 듯합니다.
여러 책을 참조한 결과 CreatePalette를 이용해 봤더니 이미지는 제대로 나오는데요
실행시키면 Disassembly pane(CPU Window)가 뜨면서 프로그램이 뜨는군요. (ㅜㅜ)
Windows programming을 뛰어넘고 bcb에 도전한게 후회스럽기도 하고
암튼 답변 부탁드려요.
///////////////////////////////////////////////////////////////////
void __fastcall TmainForm::N24bpp8bppED1Click(TObject *Sender)
{
     Out8bppED.pBitmap->Width = In24bpp.pBitmap->Width;
     Out8bppED.pBitmap->Height = In24bpp.pBitmap->Height;
     Out8bppED.pBitmap->PixelFormat = pf8bit;

     /////////// Setting Palette of Out8bppED.pBitmap ////////////

     HPALETTE hpalRef = Ref8bpp.pBitmap->Palette;
     GetPaletteEntries(hpalRef,0,256,Out8bppED.lppe);
     HPALETTE hpalOut = Out8bppED.pBitmap->Palette;
     SetPaletteEntries(hpalOut,0,256,Out8bppED.lppe);

     LogPal SysPal;
     SysPal.lPal->palVersion = 0x300;
     SysPal.lPal->palNumEntries = 256;
     GetPaletteEntries(Ref8bpp.pBitmap->Palette,0,256,SysPal.lPal->palPalEntry);
     Out8bppED.pBitmap->Palette = CreatePalette(SysPal.lPal);
     DeleteObject(SysPal.lPal);

     Byte       *bPtr, *oPtr, *rPtr;
     for (int y = 0 ; y < Out8bppED.pBitmap->Height ; y++)
     {
           oPtr = (Byte *)Out8bppED.pBitmap->ScanLine[y];
           rPtr = (Byte *)Ref8bpp.pBitmap->ScanLine[y];
           for (int x = 0; x < Out8bppED.pBitmap->Width ; x++)
           {
                 oPtr[x] = GetNearestPaletteIndex(Ref8bpp.pBitmap->Palette,
                                                                           In24bpp.pBitmap->Canvas->Pixels[x][y]);
           }
     }

     Out8bppED.pBitmap->Transparent = true;
     Out8bppED.pBitmap->TransparentMode = tmAuto;
     Image1->Canvas->Draw(0,0,Out8bppED.pBitmap);
}

////////////////////////////////////////////////////////////////

+ -

관련 글 리스트
8869 [질문] Indexed Color 저장하는 방법 (2) 초짜 1129 2001/07/09
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.