Recent

Author Topic: "TColorToFPColor" to "TColorRefToFPColor" function rename in Graphics unit  (Read 859 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 405
The Graphics unit contains the following functions:
Code: Pascal  [Select][+][-]
  1. function FPColorToTColorRef(const FPColor: TFPColor): TColorRef;
  2. begin
  3.   Result:=((FPColor.Red shr 8) and $ff)
  4.        or (FPColor.Green and $ff00)
  5.        or ((FPColor.Blue shl 8) and $ff0000);
  6. end;
  7.  
  8. function FPColorToTColor(const FPColor: TFPColor): TColor;
  9. begin
  10.   Result:=TColor(FPColorToTColorRef(FPColor));
  11. end;
  12.  
  13. function TColorToFPColor(const c: TColorRef): TFPColor;
  14. begin
  15.   Result.Red:=(c and $ff);
  16.   Result.Red:=Result.Red+(Result.Red shl 8);
  17.   Result.Green:=(c and $ff00);
  18.   Result.Green:=Result.Green+(Result.Green shr 8);
  19.   Result.Blue:=(c and $ff0000) shr 8;
  20.   Result.Blue:=Result.Blue+(Result.Blue shr 8);
  21.   Result.Alpha:=FPImage.alphaOpaque;
  22. end;
  23.  
  24. function TColorToFPColor(const c: TColor): TFPColor;
  25. begin
  26.   Result:=TColorToFPColor(TColorRef(c));
  27. end;
  28.  

Notice that the unit has:
FPColorToTColor to convert TFPColor to TColor.
TColorToFPColor to convert TColor to TFPColor.
Everything is fine with that. The problem appears when converting between TFPColor and TColorRef.
The unit has FPColorToTColorRef to convert TFPColor to TColorRef, but when it comes to converting TColorRef to TFPColor the function name is TColorToFPColor, not TColorRefToFPColor, which is the same name as above.
Not only that the function name is not intuitive but looking at the LCL interfaces I think it may be a source of misunderstandings(bugs).
Might be a good idea to change the name of the function "TColorToFPColor(const c: TColorRef): TFPColor;" to "TColorRefToFPColor" so that the names would be consistent.

Thaddy

  • Hero Member
  • *****
  • Posts: 14205
  • Probably until I exterminate Putin.
That's the weirdest thing I have seen in FreePascal code for years, and yes It exists.
That whole lot should be removed. There is no such thing as a fpcolor (apparently there is but it should not be there).
It is a simple byte reduction and expansion to/from RGB and not even written in optimal code. And It does not do color weight.
Silly coding.
« Last Edit: March 07, 2023, 04:19:24 pm by Thaddy »
Specialize a type, not a var.

PascalDragon

  • Hero Member
  • *****
  • Posts: 5446
  • Compiler Developer
That whole lot should be removed. There is no such thing as a fpcolor (apparently there is but it should not be there).
It is a simple byte reduction and expansion to/from RGB and not even written in optimal code. And It does not do color weight.

TFPColor is the color type used by FCL-Image while the LCL's graphics related code uses TColor. As LCL's graphics related code interacts with FCL-Image these functions are necessary and they're required in the Graphics unit, because FCL-Image doesn't know about the TColor type.

 

TinyPortal © 2005-2018