For Images of 8bit colour depth and below, you can directly manipulate a
DIB, palette - that is as instant as it gets.
You can easily drag the colour/lightness in real time, for example.
It would be a simple matter to convert higher colur depths for the
purposes of a preview, and then do the real calculation on a pixel basis
for the real result.
Proviso - there is apparently a Palette Handle leaked when
TBitmap::PixelFormat = pf8bit is called
So, you must use an Assign to a pre-prepared 8 bit TBitmap
E.g here is some example code
PLogPalette pal = NULL;
HPALETTE hpal;
int i;
try
{
pal = (PLogPalette) malloc( sizeof(TLogPalette) +
sizeof(TPalet{*word*249}try) * 256);
pal->palVersion = 0x300;
pal->palNumEntries = 256;
for (i = 0 ; i < 256 ; i++)
{
pal->palPalEntry[i].peRed = random(255);
pal->palPalEntry[i].peGreen = random(255);
pal->palPalEntry[i].peBlue = random(255);
}
hpal = CreatePalette(pal);
if (hpal)
{
Bitmap->Palette = hpal;
}
}
__finally
{
delete pal;
}
Have a look at GetDIBColorTable:
example -
// saved palettes
RGBQUAD OldPalette[256];
RGBQUAD NewPalette[256];
// get the old palette
GetDIBColorTable(Image1->Canvas->Handle, 0, 256, OldPalette);
/* now munge the new palette */
for (int i = 0 ; i < 256 ; i++)
{
NewPalette[i].rgbBlue = (short) (ScrollBar1->Position *
OldPalette[i].rgbBlue / 255);
NewPalette[i].rgbGreen = (short) (ScrollBar1->Position *
OldPalette[i].rgbGreen / 255);
NewPalette[i].rgbRed = (short) (ScrollBar1->Position *
OldPalette[i].rgbRed / 255);
}
SetDIBColorTable(Image1->Canvas->Handle, 0, 256, NewPalette);
Image1->Invalidate();
//-------------------------------------------------------------------------
--
/* cache old palette */
GetDIBColorTable(Image1->Canvas->Handle, 0, 256, OldPalette);
You get the idea.
If you like this, you can owe me a beer.
Quote
Dean wrote:
> Hi,
> I am developing an image processing app and want to add a
> contrast/brightness tool similar to that seen in Scion Image which has
> contrast and brightness sliders which when moved change the appearance
> of a b&w image in a flicker free manner. I use a short int buffer to
> hold the image data which can have values typically from -500 to 5000,
> and a lookup table to map the values down to 0-255 gray scale onto a
> Bitmap for bitblitting (?) onto a PaintBox canvas. My guess is that
> there is some kind of color palette (?) that can be modified to change
> the appearance of the bitmap quickly and then modify the lookup table
> after the user is done but I don't know where to begin...
> Dean
|
|
patrickmmartin.vcf
< 1K
Download
|