|
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);
}
*****************************************************************
|