Forum > LCL

"TColorToFPColor" to "TColorRefToFPColor" function rename in Graphics unit

(1/1)

lagprogramming:
The Graphics unit contains the following functions:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function FPColorToTColorRef(const FPColor: TFPColor): TColorRef;begin  Result:=((FPColor.Red shr 8) and $ff)       or (FPColor.Green and $ff00)       or ((FPColor.Blue shl 8) and $ff0000);end; function FPColorToTColor(const FPColor: TFPColor): TColor;begin  Result:=TColor(FPColorToTColorRef(FPColor));end; function TColorToFPColor(const c: TColorRef): TFPColor;begin  Result.Red:=(c and $ff);  Result.Red:=Result.Red+(Result.Red shl 8);  Result.Green:=(c and $ff00);  Result.Green:=Result.Green+(Result.Green shr 8);  Result.Blue:=(c and $ff0000) shr 8;  Result.Blue:=Result.Blue+(Result.Blue shr 8);  Result.Alpha:=FPImage.alphaOpaque;end; function TColorToFPColor(const c: TColor): TFPColor;begin  Result:=TColorToFPColor(TColorRef(c));end;  
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:
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.

PascalDragon:

--- Quote from: Thaddy on March 07, 2023, 03:22:51 pm ---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.
--- End quote ---

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.

Navigation

[0] Message Index

Go to full version