Recent

Author Topic: Bitmap(or BGRAbitmap) invert color, contrast  (Read 6074 times)

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Bitmap(or BGRAbitmap) invert color, contrast
« on: June 30, 2013, 10:45:37 am »
How to: invert color, set contrast.
Thank you very much,
Regards!
p.s. I tried to find(fast) but unsuccessful...

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Bitmap(or BGRAbitmap) invert color, contrast
« Reply #1 on: June 30, 2013, 12:40:36 pm »
Amazing BGRAbitmap!!! Wonderful!
---------
  p := myBGRAbmp.Data;//p -> pbgrapixel
  for n := myBGRAbmp.NbPixels-1 downto 0 do
  begin
    p^.red := not p^.red;  //invert red canal
    p^.green:= not p^.green; //invert green canal
    p^.blue:= not p^.blue; //invert blue canal
    inc(p);
  end;
---------     
So easy....
BGRAcontrols, team, thank you very much!
Regards!
p.s. Idea: http://wiki.freepascal.org/BGRABitmap#Direct_access_to_pixels

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Bitmap(or BGRAbitmap) invert color, contrast
« Reply #2 on: July 18, 2013, 02:40:03 pm »
By the way, you can use the following functions:
Code: [Select]
    procedure Negative; override;
    procedure NegativeRect(ABounds: TRect); override;
    procedure LinearNegative; override;
    procedure LinearNegativeRect(ABounds: TRect); override;
    procedure InplaceGrayscale; override;
    procedure InplaceGrayscale(ABounds: TRect); override;
LinearNegative is what you have done yourself. Negative uses gamma correction to have a more accurate negative regarding actual perceived luminosity.
Conscience is the debugger of the mind

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Bitmap(or BGRAbitmap) invert color, contrast
« Reply #3 on: July 18, 2013, 07:26:55 pm »
Thank you very much, circular!
Can you suggest some links to find out more about gamma correction, grayscale, etc?
Best regards!
p.s. You mentioned also:BlendImage, alpha channel...
       My knowledge of graphics is very poorly, unfortunately...
Thanks

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Bitmap(or BGRAbitmap) invert color, contrast
« Reply #4 on: July 19, 2013, 04:53:34 pm »
The article of Wikipedia about gamma correction is quite good:
http://en.wikipedia.org/wiki/Gamma_correction

About grayscale, well, it is simple: each primary color (red/green/blue) has a different luminosity, so to compute the resulting luminosity, you need to add those components with a different factor (weight) for each of them. Note that with gamma correction, it is a bit more complicated.

To make a gray color, you need to set the same value for red/green/blue, so you set them to the value you just computed before.

The alpha channel is the A in BGRA. It is the opacity of the pixels. When using BlendImage, it is not necessary to compute the "over" operation if pixels are opaque, because drawing opaque pixels is like replacing the pixels. Otherwise it is needed to do alpha blending:
http://en.wikipedia.org/wiki/Alpha_blending

The BlendImageOver function does the alpha blending.

Note that those functions BlendImage and BlendImageOver are designed to do complex blending modes, like those used when merging layers to get visual effects:
https://www.youtube.com/watch?v=Lewg3iYkln8

Otherwise you just need to use the PutImage function which provides basic blending modes with the draw mode parameter (replacing the pixels without blending, drawing with transparency, drawing without gamma correction and xor mode).
Conscience is the debugger of the mind

exdatis

  • Hero Member
  • *****
  • Posts: 668
    • exdatis
Re: Bitmap(or BGRAbitmap) invert color, contrast
« Reply #5 on: July 20, 2013, 09:36:26 am »
Oh, thank you very much, circular!!!
Best regards!
p.s. now I do not have to wander and explore...

circular

  • Hero Member
  • *****
  • Posts: 4181
    • Personal webpage
Re: Bitmap(or BGRAbitmap) invert color, contrast
« Reply #6 on: July 20, 2013, 07:22:21 pm »
You're welcome  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018