Recent

Author Topic: [SOLVED] Lighter and darker color  (Read 5388 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
[SOLVED] Lighter and darker color
« on: September 24, 2012, 07:42:36 pm »
Hi,

I don't know nothing about RGB, so how can I make lighter and darker (e.g. in percent) version of some color? Has bgrabitmap functions for that?

Regards
« Last Edit: September 24, 2012, 09:29:05 pm by Dibo »

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Lighter and darker color
« Reply #1 on: September 24, 2012, 08:56:39 pm »
Yes, there is ApplyLightnessFast(color: TBGRAPixel; lightness: word): TBGRAPixel
where lightness is the relative lightness to be applied.

32768 means no change
65535 mean white
0 means black
Conscience is the debugger of the mind

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Lighter and darker color
« Reply #2 on: September 24, 2012, 08:58:23 pm »
You can also use GetLightness and SetLightness to define precisely the lightness you want.

Here is the list of pixel functions, extracted from BGRABitmapTypes :
Code: [Select]
function GetIntensity(c: TExpandedPixel): word; inline;
function SetIntensity(c: TExpandedPixel; intensity: word): TExpandedPixel;
function GetLightness(c: TExpandedPixel): word; inline;
function SetLightness(c: TExpandedPixel; lightness: word): TExpandedPixel;
function ApplyLightnessFast(color: TBGRAPixel; lightness: word): TBGRAPixel; inline;
function ApplyIntensityFast(color: TBGRAPixel; lightness: longword): TBGRAPixel;
function CombineLightness(lightness1,lightness2: integer): integer;
function BGRAToHSLA(c: TBGRAPixel): THSLAPixel;
function ExpandedToHSLA(ec: TExpandedPixel): THSLAPixel; inline;
function BGRAToGSBA(c: TBGRAPixel): THSLAPixel;
function HSLAToExpanded(c: THSLAPixel): TExpandedPixel;
function HSLAToBGRA(c: THSLAPixel): TBGRAPixel;
function GtoH(ghue: word): word;
function HtoG(hue: word): word;
function HueDiff(h1, h2: word): word;
function GetHue(ec: TExpandedPixel): word;
function ColorImportance(ec: TExpandedPixel): word;
function GSBAToBGRA(c: THSLAPixel): TBGRAPixel;
function GSBAToHSLA(c: THSLAPixel): THSLAPixel;
function GammaExpansion(c: TBGRAPixel): TExpandedPixel; inline;
function GammaCompression(ec: TExpandedPixel): TBGRAPixel; inline;
function GammaCompression(red,green,blue,alpha: word): TBGRAPixel; inline;
function BGRAToGrayscale(c: TBGRAPixel): TBGRAPixel;
function GrayscaleToBGRA(lightness: word): TBGRAPixel;
function MergeBGRA(const colors: array of TBGRAPixel): TBGRAPixel; overload;
function MergeBGRAWithGammaCorrection(c1: TBGRAPixel; weight1: byte; c2: TBGRAPixel; weight2: byte): TBGRAPixel;
function MergeBGRA(c1, c2: TBGRAPixel): TBGRAPixel; overload;
function MergeBGRA(c1: TBGRAPixel; weight1: integer; c2: TBGRAPixel; weight2: integer): TBGRAPixel; overload;
function MergeBGRA(ec1, ec2: TExpandedPixel): TExpandedPixel; overload;
function BGRA(red, green, blue, alpha: byte): TBGRAPixel; overload; inline;
function BGRA(red, green, blue: byte): TBGRAPixel; overload; inline;
function HSLA(hue, saturation, lightness, alpha: word): THSLAPixel; overload; inline;
function HSLA(hue, saturation, lightness: word): THSLAPixel; overload; inline;
function ColorToBGRA(color: TColor): TBGRAPixel; overload;
function ColorToBGRA(color: TColor; opacity: byte): TBGRAPixel; overload;
function BGRAToFPColor(AValue: TBGRAPixel): TFPColor; inline;
function FPColorToBGRA(AValue: TFPColor): TBGRAPixel;
function BGRAToColor(c: TBGRAPixel): TColor;
operator = (const c1, c2: TBGRAPixel): boolean; inline;
function ExpandedDiff(ec1, ec2: TExpandedPixel): word;
function BGRAWordDiff(c1, c2: TBGRAPixel): word;
function BGRADiff(c1, c2: TBGRAPixel): byte;
function BGRAToStr(c: TBGRAPixel): string;
function StrToBGRA(str: string): TBGRAPixel;
function StrToBGRA(str: string; DefaultColor: TBGRAPixel): TBGRAPixel;
« Last Edit: September 24, 2012, 09:00:26 pm by circular »
Conscience is the debugger of the mind

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: Lighter and darker color
« Reply #3 on: September 24, 2012, 09:28:50 pm »
Thanks! This is what I needed!

Dibo

  • Hero Member
  • *****
  • Posts: 1048
Re: [SOLVED] Lighter and darker color
« Reply #4 on: September 26, 2012, 08:29:00 pm »
I'm testing those functions now.

1. How to cast / convert TExpandedBGRAPixer returned by SetLightnes to standard TBGRAPixel? I see ExpandedToHSLA, but no ExpandedToBGRA.
2. What means 65535 (white)? How much ligthnes it is (in percent)?

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: [SOLVED] Lighter and darker color
« Reply #5 on: September 26, 2012, 10:37:46 pm »
1.
Code: [Select]
function GammaExpansion(c: TBGRAPixel): TExpandedPixel; inline;
function GammaCompression(ec: TExpandedPixel): TBGRAPixel; inline;

For ApplyLightnessFast, it is not really the lightness level but a gradient from black to supplied color and supplied color to white.

For GetLightness and SetLightness, it is as much as possible : 0 means 0% of lightness and 65535 means 100% of lightness and in between a linear progression of lightness %.
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018