Recent

Author Topic: Pixel brightness in BGRABitmap  (Read 4753 times)

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Pixel brightness in BGRABitmap
« on: December 07, 2012, 02:12:01 pm »

Hi all,
Is there any method to get the pixel brightness in BGRABitmap?
Thanks.

ausdigi

  • Jr. Member
  • **
  • Posts: 52
  • Programmer
    • RNR
Re: Pixel brightness in BGRABitmap
« Reply #1 on: January 08, 2013, 01:04:33 am »
The individual R, G & B components are the pixel brightnesses of each color pixel - you could just add them up (then average maybe). To get a value more related to human perception you could convert to HSL (just fairly simple maths - numerous examples out there) and chose the "L" component.

I'm assuming you know how to get the RGB values from a particular pixel as I don't know off my head how to in Lazarus.

PS. Sorry nobody answered this simple question
Win10/64: CT 5.7 32&64

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Pixel brightness in BGRABitmap
« Reply #2 on: January 08, 2013, 07:16:10 am »
@IndianaJones - go to BGRABitmapTypes unit, to the section { Color functions } , maybe you will find something (there is GetIntensity, GetLightness etc)

circular

  • Hero Member
  • *****
  • Posts: 4471
    • Personal webpage
Re: Pixel brightness in BGRABitmap
« Reply #3 on: January 14, 2013, 02:23:01 pm »
SetIntensity/GetIntensity is about the brightness without turning the color into white, and SetLightness/GetLightness is about the brightness including whiteness.

Here are all color functions :

Code: [Select]
{ Color functions }
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;
operator - (const c1, c2: TColorF): TColorF; inline;
operator + (const c1, c2: TColorF): TColorF; inline;
operator * (const c1, c2: TColorF): TColorF; inline;
operator * (const c1: TColorF; factor: single): TColorF; inline;
function ColorF(red,green,blue,alpha: single): TColorF;
function BGRAToStr(c: TBGRAPixel): string;
function StrToBGRA(str: string): TBGRAPixel;
function StrToBGRA(str: string; DefaultColor: TBGRAPixel): TBGRAPixel;

Color constants :
Code: [Select]
const
  BGRAPixelTransparent: TBGRAPixel = (blue: 0; green: 0; red: 0; alpha: 0);
  BGRAWhite: TBGRAPixel = (blue: 255; green: 255; red: 255; alpha: 255);
  BGRABlack: TBGRAPixel = (blue: 0; green: 0; red: 0; alpha: 255);

  { This color is needed for drawing black shapes on the standard TCanvas, because
    when drawing with pure black, there is no way to know if something has been
    drawn or if it is transparent }
  clBlackOpaque = TColor($010000);

const
  //Red colors
  CSSIndianRed: TBGRAPixel = (blue: 92; green: 92; red: 205; alpha: 255);
  CSSLightCoral: TBGRAPixel = (blue: 128; green: 128; red: 240; alpha: 255);
  CSSSalmon: TBGRAPixel = (blue: 114; green: 128; red: 250; alpha: 255);
  CSSDarkSalmon: TBGRAPixel = (blue: 122; green: 150; red: 233; alpha: 255);
  CSSRed: TBGRAPixel = (blue: 0; green: 0; red: 255; alpha: 255);
  CSSCrimson: TBGRAPixel = (blue: 60; green: 20; red: 220; alpha: 255);
  CSSFireBrick: TBGRAPixel = (blue: 34; green: 34; red: 178; alpha: 255);
  CSSDarkRed: TBGRAPixel = (blue: 0; green: 0; red: 139; alpha: 255);

  //Pink colors
  CSSPink: TBGRAPixel = (blue: 203; green: 192; red: 255; alpha: 255);
  CSSLightPink: TBGRAPixel = (blue: 193; green: 182; red: 255; alpha: 255);
  CSSHotPink: TBGRAPixel = (blue: 180; green: 105; red: 255; alpha: 255);
  CSSDeepPink: TBGRAPixel = (blue: 147; green: 20; red: 255; alpha: 255);
  CSSMediumVioletRed: TBGRAPixel = (blue: 133; green: 21; red: 199; alpha: 255);
  CSSPaleVioletRed: TBGRAPixel = (blue: 147; green: 112; red: 219; alpha: 255);

  //Orange colors
  CSSLightSalmon: TBGRAPixel = (blue: 122; green: 160; red: 255; alpha: 255);
  CSSCoral: TBGRAPixel = (blue: 80; green: 127; red: 255; alpha: 255);
  CSSTomato: TBGRAPixel = (blue: 71; green: 99; red: 255; alpha: 255);
  CSSOrangeRed: TBGRAPixel = (blue: 0; green: 69; red: 255; alpha: 255);
  CSSDarkOrange: TBGRAPixel = (blue: 0; green: 140; red: 255; alpha: 255);
  CSSOrange: TBGRAPixel = (blue: 0; green: 165; red: 255; alpha: 255);

  //Yellow colors
  CSSGold: TBGRAPixel = (blue: 0; green: 215; red: 255; alpha: 255);
  CSSYellow: TBGRAPixel = (blue: 0; green: 255; red: 255; alpha: 255);
  CSSLightYellow: TBGRAPixel = (blue: 224; green: 255; red: 255; alpha: 255);
  CSSLemonChiffon: TBGRAPixel = (blue: 205; green: 250; red: 255; alpha: 255);
  CSSLightGoldenrodYellow: TBGRAPixel = (blue: 210; green: 250; red: 250; alpha: 255);
  CSSPapayaWhip: TBGRAPixel = (blue: 213; green: 239; red: 255; alpha: 255);
  CSSMoccasin: TBGRAPixel = (blue: 181; green: 228; red: 255; alpha: 255);
  CSSPeachPuff: TBGRAPixel = (blue: 185; green: 218; red: 255; alpha: 255);
  CSSPaleGoldenrod: TBGRAPixel = (blue: 170; green: 232; red: 238; alpha: 255);
  CSSKhaki: TBGRAPixel = (blue: 140; green: 230; red: 240; alpha: 255);
  CSSDarkKhaki: TBGRAPixel = (blue: 107; green: 183; red: 189; alpha: 255);

  //Purple colors
  CSSLavender: TBGRAPixel = (blue: 250; green: 230; red: 230; alpha: 255);
  CSSThistle: TBGRAPixel = (blue: 216; green: 191; red: 216; alpha: 255);
  CSSPlum: TBGRAPixel = (blue: 221; green: 160; red: 221; alpha: 255);
  CSSViolet: TBGRAPixel = (blue: 238; green: 130; red: 238; alpha: 255);
  CSSOrchid: TBGRAPixel = (blue: 214; green: 112; red: 218; alpha: 255);
  CSSFuchsia: TBGRAPixel = (blue: 255; green: 0; red: 255; alpha: 255);
  CSSMagenta: TBGRAPixel = (blue: 255; green: 0; red: 255; alpha: 255);
  CSSMediumOrchid: TBGRAPixel = (blue: 211; green: 85; red: 186; alpha: 255);
  CSSMediumPurple: TBGRAPixel = (blue: 219; green: 112; red: 147; alpha: 255);
  CSSBlueViolet: TBGRAPixel = (blue: 226; green: 43; red: 138; alpha: 255);
  CSSDarkViolet: TBGRAPixel = (blue: 211; green: 0; red: 148; alpha: 255);
  CSSDarkOrchid: TBGRAPixel = (blue: 204; green: 50; red: 153; alpha: 255);
  CSSDarkMagenta: TBGRAPixel = (blue: 139; green: 0; red: 139; alpha: 255);
  CSSPurple: TBGRAPixel = (blue: 128; green: 0; red: 128; alpha: 255);
  CSSIndigo: TBGRAPixel = (blue: 130; green: 0; red: 75; alpha: 255);
  CSSDarkSlateBlue: TBGRAPixel = (blue: 139; green: 61; red: 72; alpha: 255);
  CSSSlateBlue: TBGRAPixel = (blue: 205; green: 90; red: 106; alpha: 255);
  CSSMediumSlateBlue: TBGRAPixel = (blue: 238; green: 104; red: 123; alpha: 255);

  //Green colors
  CSSGreenYellow: TBGRAPixel = (blue: 47; green: 255; red: 173; alpha: 255);
  CSSChartreuse: TBGRAPixel = (blue: 0; green: 255; red: 127; alpha: 255);
  CSSLawnGreen: TBGRAPixel = (blue: 0; green: 252; red: 124; alpha: 255);
  CSSLime: TBGRAPixel = (blue: 0; green: 255; red: 0; alpha: 255);
  CSSLimeGreen: TBGRAPixel = (blue: 50; green: 205; red: 50; alpha: 255);
  CSSPaleGreen: TBGRAPixel = (blue: 152; green: 251; red: 152; alpha: 255);
  CSSLightGreen: TBGRAPixel = (blue: 144; green: 238; red: 144; alpha: 255);
  CSSMediumSpringGreen: TBGRAPixel = (blue: 154; green: 250; red: 0; alpha: 255);
  CSSSpringGreen: TBGRAPixel = (blue: 127; green: 255; red: 0; alpha: 255);
  CSSMediumSeaGreen: TBGRAPixel = (blue: 113; green: 179; red: 60; alpha: 255);
  CSSSeaGreen: TBGRAPixel = (blue: 87; green: 139; red: 46; alpha: 255);
  CSSForestGreen: TBGRAPixel = (blue: 34; green: 139; red: 34; alpha: 255);
  CSSGreen: TBGRAPixel = (blue: 0; green: 128; red: 0; alpha: 255);
  CSSDarkGreen: TBGRAPixel = (blue: 0; green: 100; red: 0; alpha: 255);
  CSSYellowGreen: TBGRAPixel = (blue: 50; green: 205; red: 154; alpha: 255);
  CSSOliveDrab: TBGRAPixel = (blue: 35; green: 142; red: 107; alpha: 255);
  CSSOlive: TBGRAPixel = (blue: 0; green: 128; red: 128; alpha: 255);
  CSSDarkOliveGreen: TBGRAPixel = (blue: 47; green: 107; red: 85; alpha: 255);
  CSSMediumAquamarine: TBGRAPixel = (blue: 170; green: 205; red: 102; alpha: 255);
  CSSDarkSeaGreen: TBGRAPixel = (blue: 143; green: 188; red: 143; alpha: 255);
  CSSLightSeaGreen: TBGRAPixel = (blue: 170; green: 178; red: 32; alpha: 255);
  CSSDarkCyan: TBGRAPixel = (blue: 139; green: 139; red: 0; alpha: 255);
  CSSTeal: TBGRAPixel = (blue: 128; green: 128; red: 0; alpha: 255);

  //Blue/Cyan colors
  CSSAqua: TBGRAPixel = (blue: 255; green: 255; red: 0; alpha: 255);
  CSSCyan: TBGRAPixel = (blue: 255; green: 255; red: 0; alpha: 255);
  CSSLightCyan: TBGRAPixel = (blue: 255; green: 255; red: 224; alpha: 255);
  CSSPaleTurquoise: TBGRAPixel = (blue: 238; green: 238; red: 175; alpha: 255);
  CSSAquamarine: TBGRAPixel = (blue: 212; green: 255; red: 127; alpha: 255);
  CSSTurquoise: TBGRAPixel = (blue: 208; green: 224; red: 64; alpha: 255);
  CSSMediumTurquoise: TBGRAPixel = (blue: 204; green: 209; red: 72; alpha: 255);
  CSSDarkTurquoise: TBGRAPixel = (blue: 209; green: 206; red: 0; alpha: 255);
  CSSCadetBlue: TBGRAPixel = (blue: 160; green: 158; red: 95; alpha: 255);
  CSSSteelBlue: TBGRAPixel = (blue: 180; green: 130; red: 70; alpha: 255);
  CSSLightSteelBlue: TBGRAPixel = (blue: 222; green: 196; red: 176; alpha: 255);
  CSSPowderBlue: TBGRAPixel = (blue: 230; green: 224; red: 176; alpha: 255);
  CSSLightBlue: TBGRAPixel = (blue: 230; green: 216; red: 173; alpha: 255);
  CSSSkyBlue: TBGRAPixel = (blue: 235; green: 206; red: 135; alpha: 255);
  CSSLightSkyBlue: TBGRAPixel = (blue: 250; green: 206; red: 135; alpha: 255);
  CSSDeepSkyBlue: TBGRAPixel = (blue: 255; green: 191; red: 0; alpha: 255);
  CSSDodgerBlue: TBGRAPixel = (blue: 255; green: 144; red: 30; alpha: 255);
  CSSCornflowerBlue: TBGRAPixel = (blue: 237; green: 149; red: 100; alpha: 255);
  CSSRoyalBlue: TBGRAPixel = (blue: 255; green: 105; red: 65; alpha: 255);
  CSSBlue: TBGRAPixel = (blue: 255; green: 0; red: 0; alpha: 255);
  CSSMediumBlue: TBGRAPixel = (blue: 205; green: 0; red: 0; alpha: 255);
  CSSDarkBlue: TBGRAPixel = (blue: 139; green: 0; red: 0; alpha: 255);
  CSSNavy: TBGRAPixel = (blue: 128; green: 0; red: 0; alpha: 255);
  CSSMidnightBlue: TBGRAPixel = (blue: 112; green: 25; red: 25; alpha: 255);

  //Brown colors
  CSSCornsilk: TBGRAPixel = (blue: 220; green: 248; red: 255; alpha: 255);
  CSSBlanchedAlmond: TBGRAPixel = (blue: 205; green: 235; red: 255; alpha: 255);
  CSSBisque: TBGRAPixel = (blue: 196; green: 228; red: 255; alpha: 255);
  CSSNavajoWhite: TBGRAPixel = (blue: 173; green: 222; red: 255; alpha: 255);
  CSSWheat: TBGRAPixel = (blue: 179; green: 222; red: 245; alpha: 255);
  CSSBurlyWood: TBGRAPixel = (blue: 135; green: 184; red: 222; alpha: 255);
  CSSTan: TBGRAPixel = (blue: 140; green: 180; red: 210; alpha: 255);
  CSSRosyBrown: TBGRAPixel = (blue: 143; green: 143; red: 188; alpha: 255);
  CSSSandyBrown: TBGRAPixel = (blue: 96; green: 164; red: 244; alpha: 255);
  CSSGoldenrod: TBGRAPixel = (blue: 32; green: 165; red: 218; alpha: 255);
  CSSDarkGoldenrod: TBGRAPixel = (blue: 11; green: 134; red: 184; alpha: 255);
  CSSPeru: TBGRAPixel = (blue: 63; green: 133; red: 205; alpha: 255);
  CSSChocolate: TBGRAPixel = (blue: 30; green: 105; red: 210; alpha: 255);
  CSSSaddleBrown: TBGRAPixel = (blue: 19; green: 69; red: 139; alpha: 255);
  CSSSienna: TBGRAPixel = (blue: 45; green: 82; red: 160; alpha: 255);
  CSSBrown: TBGRAPixel = (blue: 42; green: 42; red: 165; alpha: 255);
  CSSMaroon: TBGRAPixel = (blue: 0; green: 0; red: 128; alpha: 255);

  //White colors
  CSSWhite: TBGRAPixel = (blue: 255; green: 255; red: 255; alpha: 255);
  CSSSnow: TBGRAPixel = (blue: 250; green: 250; red: 255; alpha: 255);
  CSSHoneydew: TBGRAPixel = (blue: 240; green: 255; red: 250; alpha: 255);
  CSSMintCream: TBGRAPixel = (blue: 250; green: 255; red: 245; alpha: 255);
  CSSAzure: TBGRAPixel = (blue: 255; green: 255; red: 240; alpha: 255);
  CSSAliceBlue: TBGRAPixel = (blue: 255; green: 248; red: 240; alpha: 255);
  CSSGhostWhite: TBGRAPixel = (blue: 255; green: 248; red: 248; alpha: 255);
  CSSWhiteSmoke: TBGRAPixel = (blue: 245; green: 245; red: 245; alpha: 255);
  CSSSeashell: TBGRAPixel = (blue: 255; green: 245; red: 238; alpha: 255);
  CSSBeige: TBGRAPixel = (blue: 220; green: 245; red: 245; alpha: 255);
  CSSOldLace: TBGRAPixel = (blue: 230; green: 245; red: 253; alpha: 255);
  CSSFloralWhite: TBGRAPixel = (blue: 240; green: 250; red: 255; alpha: 255);
  CSSIvory: TBGRAPixel = (blue: 240; green: 255; red: 255; alpha: 255);
  CSSAntiqueWhite: TBGRAPixel = (blue: 215; green: 235; red: 250; alpha: 255);
  CSSLinen: TBGRAPixel = (blue: 230; green: 240; red: 250; alpha: 255);
  CSSLavenderBlush: TBGRAPixel = (blue: 245; green: 240; red: 255; alpha: 255);
  CSSMistyRose: TBGRAPixel = (blue: 255; green: 228; red: 255; alpha: 255);

  //Gray colors
  CSSGainsboro: TBGRAPixel = (blue: 220; green: 220; red: 220; alpha: 255);
  CSSLightGray: TBGRAPixel = (blue: 211; green: 211; red: 211; alpha: 255);
  CSSSilver: TBGRAPixel = (blue: 192; green: 192; red: 192; alpha: 255);
  CSSDarkGray: TBGRAPixel = (blue: 169; green: 169; red: 169; alpha: 255);
  CSSGray: TBGRAPixel = (blue: 128; green: 128; red: 128; alpha: 255);
  CSSDimGray: TBGRAPixel = (blue: 105; green: 105; red: 105; alpha: 255);
  CSSLightSlateGray: TBGRAPixel = (blue: 153; green: 136; red: 119; alpha: 255);
  CSSSlateGray: TBGRAPixel = (blue: 144; green: 128; red: 112; alpha: 255);
  CSSDarkSlateGray: TBGRAPixel = (blue: 79; green: 79; red: 47; alpha: 255);
  CSSBlack: TBGRAPixel = (blue: 0; green: 0; red: 0; alpha: 255);
« Last Edit: January 14, 2013, 02:24:42 pm by circular »
Conscience is the debugger of the mind

IndianaJones

  • Hero Member
  • *****
  • Posts: 509
Re: Pixel brightness in BGRABitmap
« Reply #4 on: January 14, 2013, 02:36:29 pm »
@ausdigi, @Dibo, @circular, thanks for the info and reply.

 

TinyPortal © 2005-2018