diff --git a/components/mbColorLib/CIEAColorPicker.pas b/components/mbColorLib/CIEAColorPicker.pas index 17fd7d7ea..e9367fb40 100644 --- a/components/mbColorLib/CIEAColorPicker.pas +++ b/components/mbColorLib/CIEAColorPicker.pas @@ -33,6 +33,7 @@ type procedure SetSelectedColor(c: TColor); override; public constructor Create(AOwner: TComponent); override; + function GetColorAtPoint(x, y: Integer): TColor; override; published property SelectedColor default clFuchsia; property LValue: integer read FL write SetLValue default 100; @@ -98,6 +99,26 @@ begin InternalDrawMarker(x, y, c); end; +{ +function TCIEAColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + l, a, b: Integer; +begin + l := round(100 * (1 - y / (Height-1))); + a := FA; + b := round(255 * (x / (Width - 1))) - 128; + Result := LabToRGB(l, a, b); +end; +} +function TCIEAColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + l, b: Integer; //Double; +begin + l := round((1 - y / (Height - 1)) * 100); + b := round((x / (Width - 1) - 0.5) * 255); + Result := LabToRGB(l, FA, b); +end; + // In the original code: for L ... for B ... LabToRGB(Round(100-L*100/255), FA, B-128); // --> x is B, y is L function TCIEAColorPicker.GetGradientColor2D(x, y: Integer): TColor; @@ -169,10 +190,12 @@ end; procedure TCIEAColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited; - mxx := x; - myy := y; if Button = mbLeft then begin + mxx := x; + myy := y; + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FSelected := GetColorAtPoint(x, y); FManual := true; Invalidate; @@ -189,7 +212,8 @@ begin begin mxx := x; myy := y; - FSelected := GetColorAtPoint(x, y); + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; if Assigned(FOnChange) then @@ -204,7 +228,8 @@ begin begin mxx := x; myy := y; - FSelected := GetColorAtPoint(x, y); + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; if Assigned(FOnChange) then @@ -215,7 +240,6 @@ end; procedure TCIEAColorPicker.Paint; begin Canvas.StretchDraw(ClientRect, FBufferBmp); - CorrectCoords(mxx, myy); DrawMarker(mxx, myy); end; diff --git a/components/mbColorLib/CIEBColorPicker.pas b/components/mbColorLib/CIEBColorPicker.pas index 9713c58d5..88bc15f36 100644 --- a/components/mbColorLib/CIEBColorPicker.pas +++ b/components/mbColorLib/CIEBColorPicker.pas @@ -36,6 +36,7 @@ type procedure SetSelectedColor(c: TColor); override; public constructor Create(AOwner: TComponent); override; + function GetColorAtPoint(x, y: Integer): TColor; override; published property AValue: integer read FA write SetAValue default -128; property BValue: integer read FB write SetBValue default 127; @@ -101,6 +102,26 @@ begin InternalDrawMarker(x, y, c); end; +{ +function TCIEBColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + l, a, b: Integer; +begin + l := round(100 * (1 - y / (Height-1))); + a := round(255 * (x / (Width - 1))) - 128; + b := FB; + Result := LabToRGB(l, a, b); +end; +} +function TCIEBColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + l, a: Double; +begin + l := (1 - y / (Height - 1)) * 100; + a := (x / (Width - 1) - 0.5) * 255; + Result := LabToRGB(l, a, FB); +end; + { In the original code: for L ... for A ... LabToRGB(Round(100-L*100/244), A-128, FB) --> x is A, y is L} function TCIEBColorPicker.GetGradientColor2D(x, y: Integer): TColor; @@ -170,20 +191,14 @@ begin end; procedure TCIEBColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); -var - R: TRect; begin inherited; - mxx := x; - myy := y; if Button = mbLeft then begin - R := ClientRect; - R.TopLeft := ClientToScreen(R.TopLeft); - R.BottomRight := ClientToScreen(R.BottomRight); - {$IFDEF DELPHI} - ClipCursor(@R); - {$ENDIF} + mxx := x; + myy := y; + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FSelected := GetColorAtPoint(x, y); FManual := true; Invalidate; @@ -196,12 +211,10 @@ begin inherited; if ssLeft in Shift then begin - {$IFDEF DELPHI} - ClipCursor(nil); - {$ENDIF} mxx := x; myy := y; - FSelected := GetColorAtPoint(x, y); + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; if Assigned(FOnChange) then @@ -216,7 +229,8 @@ begin begin mxx := x; myy := y; - FSelected := GetColorAtPoint(x, y); + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; if Assigned(FOnChange) then @@ -227,7 +241,6 @@ end; procedure TCIEBColorPicker.Paint; begin Canvas.StretchDraw(ClientRect, FBufferBmp); - CorrectCoords(mxx, myy); DrawMarker(mxx, myy); end; diff --git a/components/mbColorLib/CIELColorPicker.pas b/components/mbColorLib/CIELColorPicker.pas index f870fb63a..1f84e6ca5 100644 --- a/components/mbColorLib/CIELColorPicker.pas +++ b/components/mbColorLib/CIELColorPicker.pas @@ -33,6 +33,7 @@ type procedure SetSelectedColor(c: TColor); override; public constructor Create(AOwner: TComponent); override; + function GetColorAtPoint(X, Y: Integer): TColor; override; published property AValue: integer read FA write SetAValue default -128; property BValue: integer read FB write SetBValue default 127; @@ -99,6 +100,24 @@ begin InternalDrawMarker(x, y, c); end; +function TCIELColorPicker.GetColorAtPoint(x, y: Integer): TColor; +var + a, b: Double; +begin + a := (y / (Height - 1) - 0.5) * 255; + b := (x / (Width - 1) - 0.5) * 255; + Result := LabToRGB(FL, a, b); +end; +{ +var + a, b: Integer; +begin + a := round(255 * (y / (Height - 1))) - 128; + b := round(255 * (x / (Width - 1))) - 128; + Result := LabToRGB(FL, a, b); +end; +} + { Original code: for A ... for B ---> LabToRGB(FL, A - 128, B - 128) } function TCIELColorPicker.GetGradientColor2D(x, y: Integer): TColor; begin @@ -168,11 +187,12 @@ end; procedure TCIELColorPicker.MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); begin inherited; - mxx := x; - myy := y; if Button = mbLeft then begin - FSelected := GetColorAtPoint(x, y); + mxx := x; + myy := y; + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; end; @@ -186,7 +206,8 @@ begin begin mxx := x; myy := y; - FSelected := GetColorAtPoint(x, y); + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; if Assigned(FOnChange) then @@ -201,7 +222,8 @@ begin begin mxx := x; myy := y; - FSelected := GetColorAtPoint(x, y); + CorrectCoords(mxx, myy); + FSelected := GetColorAtPoint(mxx, myy); FManual := true; Invalidate; if Assigned(FOnChange) then diff --git a/components/mbColorLib/RGBCIEUtils.pas b/components/mbColorLib/RGBCIEUtils.pas index 0be427da9..42c739ff5 100644 --- a/components/mbColorLib/RGBCIEUtils.pas +++ b/components/mbColorLib/RGBCIEUtils.pas @@ -125,6 +125,8 @@ begin end; function XYZToRGB(space: xyz): TColor; +// see: +// https://de.mathworks.com/matlabcentral/fileexchange/28790-colorspace-transformations/content/colorspace/colorspace.html?requestedDomain=www.mathworks.com var r, g, b, x, y, z: double; begin diff --git a/components/mbColorLib/examples/fulldemo/main.lfm b/components/mbColorLib/examples/fulldemo/main.lfm index 0b28d09c5..d2fceba7d 100644 --- a/components/mbColorLib/examples/fulldemo/main.lfm +++ b/components/mbColorLib/examples/fulldemo/main.lfm @@ -43,9 +43,9 @@ object Form1: TForm1 Height = 384 Top = 6 Width = 403 - ActivePage = TabSheet9 + ActivePage = TabSheet7 Anchors = [akTop, akLeft, akRight, akBottom] - TabIndex = 9 + TabIndex = 7 TabOrder = 0 OnChange = PageControl1Change OnMouseMove = PageControl1MouseMove @@ -721,8 +721,8 @@ object Form1: TForm1 TabOrder = 2 Hue = 0 Saturation = 0 - Luminance = 73 - SelectedColor = 4802889 + Luminance = 65 + SelectedColor = 4276545 end object VColorPicker1: TVColorPicker Left = 34 @@ -1038,7 +1038,6 @@ object Form1: TForm1 Width = 100 HintFormat = 'G: %g B: %b'#13'Hex: #%hex' TabOrder = 0 - OnChange = RAxisColorPicker1Change end object GAxisColorPicker1: TGAxisColorPicker Left = 130 @@ -1048,7 +1047,6 @@ object Form1: TForm1 HintFormat = 'R: %r B: %b'#13'Hex: #%hex' TabOrder = 1 MarkerStyle = msCross - OnChange = GAxisColorPicker1Change end object BAxisColorPicker1: TBAxisColorPicker Left = 250 @@ -1058,7 +1056,6 @@ object Form1: TForm1 HintFormat = 'R: %r G: %g'#13'Hex: #%hex' TabOrder = 2 MarkerStyle = msCrossCirc - OnChange = BAxisColorPicker1Change end object CIELColorPicker1: TCIELColorPicker Left = 10 @@ -1071,7 +1068,6 @@ object Form1: TForm1 AValue = -47 BValue = -32 LValue = 88 - OnChange = CIELColorPicker1Change end object CIEAColorPicker1: TCIEAColorPicker Left = 130 @@ -1085,7 +1081,6 @@ object Form1: TForm1 AValue = 96 BValue = -78 MarkerStyle = msSquare - OnChange = CIEAColorPicker1Change end object CIEBColorPicker1: TCIEBColorPicker Left = 250 @@ -1098,7 +1093,6 @@ object Form1: TForm1 AValue = -88 BValue = 74 LValue = 88 - OnChange = CIEBColorPicker1Change end object Label10: TLabel Left = 130 @@ -1148,42 +1142,6 @@ object Form1: TForm1 Caption = 'CIEBColorPicker' ParentColor = False end - object RAxisIndicator: TShape - Left = 88 - Height = 21 - Top = 132 - Width = 22 - end - object GAxisIndicator: TShape - Left = 208 - Height = 21 - Top = 132 - Width = 22 - end - object BAxisIndicator: TShape - Left = 328 - Height = 21 - Top = 132 - Width = 22 - end - object CIEBIndicator: TShape - Left = 328 - Height = 21 - Top = 296 - Width = 22 - end - object CIEAIndicator: TShape - Left = 208 - Height = 21 - Top = 296 - Width = 22 - end - object CIELIndicator: TShape - Left = 88 - Height = 21 - Top = 296 - Width = 22 - end end end object sc: TmbColorPreview diff --git a/components/mbColorLib/examples/fulldemo/main.pas b/components/mbColorLib/examples/fulldemo/main.pas index 23fd48fe2..1bee0a0e7 100644 --- a/components/mbColorLib/examples/fulldemo/main.pas +++ b/components/mbColorLib/examples/fulldemo/main.pas @@ -20,10 +20,8 @@ type { TForm1 } TForm1 = class(TForm) - CIEBIndicator: TShape; CbShowHints: TCheckBox; CbEnabled: TCheckBox; - CIEAIndicator: TShape; Label10: TLabel; Label11: TLabel; Label12: TLabel; @@ -31,10 +29,6 @@ type Label14: TLabel; Label15: TLabel; PageControl1: TPageControl; - RAxisIndicator: TShape; - GAxisIndicator: TShape; - BAxisIndicator: TShape; - CIELIndicator: TShape; TabSheet1: TTabSheet; TabSheet2: TTabSheet; TabSheet3: TTabSheet; @@ -111,19 +105,13 @@ type Memo1: TMemo; Label9: TLabel; CbSwatchStyle: TCheckBox; - procedure BAxisColorPicker1Change(Sender: TObject); procedure CbEnabledChange(Sender: TObject); procedure CbShowHintsChange(Sender: TObject); - procedure CIEAColorPicker1Change(Sender: TObject); - procedure CIEBColorPicker1Change(Sender: TObject); - procedure CIELColorPicker1Change(Sender: TObject); - procedure GAxisColorPicker1Change(Sender: TObject); procedure HColorPicker1GetHintStr(Sender: TObject; X, Y: Integer; var AText: String); procedure PageControl1Change(Sender: TObject); procedure PageControl1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer); - procedure RAxisColorPicker1Change(Sender: TObject); procedure tb1Change(Sender: TObject); procedure tb2Change(Sender: TObject); procedure HSLColorPicker1Change(Sender: TObject); @@ -220,11 +208,6 @@ begin uc.color := hexacolorpicker1.ColorUnderCursor; end; -procedure TForm1.BAxisColorPicker1Change(Sender: TObject); -begin - BAxisIndicator.Brush.Color := BAxisColorPicker1.SelectedColor; -end; - procedure TForm1.Button1Click(Sender: TObject); begin mbColorPalette1.GeneratePalette(clblue); @@ -298,11 +281,6 @@ begin uc.color := HSLColorpicker1.ColorUnderCursor; end; -procedure TForm1.RAxisColorPicker1Change(Sender: TObject); -begin - RAxisIndicator.Brush.Color := RAxisColorPicker1.SelectedColor; -end; - procedure TForm1.OfficeColorDialogButtonClick(Sender: TObject); begin if mbOfficeColorDialog1.Execute then @@ -363,11 +341,6 @@ begin end; end; -procedure TForm1.GAxisColorPicker1Change(Sender: TObject); -begin - GAxisIndicator.Brush.Color := GAxisColorPicker1.SelectedColor; -end; - procedure TForm1.HColorPicker1GetHintStr(Sender: TObject; X, Y: Integer; var AText: String); begin @@ -389,21 +362,6 @@ begin hexacolorpicker1.NewArrowStyle := checkbox2.checked; end; -procedure TForm1.CIEAColorPicker1Change(Sender: TObject); -begin - CIEAIndicator.Brush.Color := CIEAColorPicker1.SelectedColor; -end; - -procedure TForm1.CIEBColorPicker1Change(Sender: TObject); -begin - CIEBIndicator.Brush.Color := CIEBColorPicker1.SelectedColor; -end; - -procedure TForm1.CIELColorPicker1Change(Sender: TObject); -begin - CIELIndicator.Brush.Color := CIELColorPicker1.SelectedColor; -end; - procedure TForm1.Button4Click(Sender: TObject); begin if opendialog1.Execute then