Board index » cppbuilder » fast Brightness/Contrast manipulation

fast Brightness/Contrast manipulation

Hello Dean,

I was wondering if you could tell how to get pixel of image. I am using BCB
to implement image processing techniques and don't know where to start. Pls.
help

Thanks

Quote
Dean wrote in message <39749552.DC087...@numog.eng.mcmaster.ca>...
>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

 

Re:fast Brightness/Contrast manipulation


use the property Pixels
Canvas->Pixels[i,j] = clBlue

Quote
seun onodipe wrote:
> Hello Dean,

> I was wondering if you could tell how to get pixel of image. I am using BCB
> to implement image processing techniques and don't know where to start. Pls.
> help

> Thanks
> Dean wrote in message <39749552.DC087...@numog.eng.mcmaster.ca>...
> >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

Re:fast Brightness/Contrast manipulation


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();

Quote
}

//---------------------------------------------------------------------------

      /* 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

Other Threads