How to change the red with blue in the RGB image and keep the brightness?

I am reading a 24 bit bitmap:

var P: PByteArray;
...
for y:=0 to Bmp.Height-1 do begin
    P := Bmp.ScanLine[y];
    for x:=0 to Bmp.Width-1 do begin
      R := P[3*x+2];
      G := P[3*x+1];
      B := P[3*x  ];

Now I will change the RGB to BGR:

      P[3*x+2] := B;
      P[3*x+1] := G;
      P[3*x  ] := R;

So, if I had something red in my image, now it is blue and blue is red. But the problem is brightness changes, and the new image is darker or brighter than the original image. How can I make my output image bright / dark like an input image?

+4
source share
1 answer

RGB HSL.
colorwheel ( Hue, . ), RGB.
.

Delphi , : VCL.GraphUtil.

:
procedure ColorRGBToHLS(clrRGB: TColorRef; var Hue, Luminance, Saturation: Word);
 function ColorHLSToRGB(Hue, Luminance, Saturation: Word): TColorRef;.

Hue

0 . . , GraphUtils, 256 , :

  • 0
  • 20
  • 40
  • 80
  • Cyan 120
  • Blue 160
  • 180
  • Magenta 200
  • 220

, Embarcadero HLS HSL, .

+1

All Articles