Recent

Author Topic: How to use html colors in lazarus  (Read 7665 times)

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
How to use html colors in lazarus
« on: May 12, 2018, 12:58:40 am »
good friends.
when using the colors of this website:
https://html-color-codes.info/

Lazarus shows me other colors, but if I invest them if they work.

Code: Pascal  [Select][+][-]
  1.  // #3A01DF  //online color code html
  2.  
  3.   form1.Color:=$3A01DF;  // show another color
  4.   form1.Color:=$DF013A;  // inverted if it works, why?


How can I use the web codes in lazarus?  :(

PD: attached image

Josh

  • Hero Member
  • *****
  • Posts: 1271
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

wp

  • Hero Member
  • *****
  • Posts: 11853
Re: How to use html colors in lazarus
« Reply #2 on: May 12, 2018, 01:23:00 am »
Isn't that simply RGB color?
Almost... HTML has R and B interchanged: HTMLColor #RRGGBB, but TColor = $00BBGGRR

http://wiki.freepascal.org/Convert_color_to/from_HTML

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: How to use html colors in lazarus
« Reply #3 on: May 12, 2018, 01:34:27 am »
thanks for your help friends, I'll prove it

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: How to use html colors in lazarus
« Reply #4 on: May 12, 2018, 06:43:04 am »
Needs to be packed record or even bitpacked record.
Specialize a type, not a var.

Ericktux

  • Sr. Member
  • ****
  • Posts: 345
Re: How to use html colors in lazarus
« Reply #5 on: May 12, 2018, 07:11:07 am »
thank you very much to all, at the moment it works like this:

We integrate the unit "ATStringProc_HtmlColor.pas" which you can obtain it from:
http://wiki.freepascal.org/Convert_color_to/from_HTML

Code: Pascal  [Select][+][-]
  1. Uses
  2. ATStringProc_HtmlColor,
  3.  
  4. var
  5.   colorcito: tcolor;
  6.   num1: integer;
  7.  
  8.   Form1.Color:=SHtmlColorToColor('#0040FF', num1, colorcito);  // work fine

………
ShtmlColorToColor returns color for lazarus $FF4000

at the moment it works well  :) :)

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: How to use html colors in lazarus
« Reply #6 on: May 12, 2018, 06:13:14 pm »
Jamie that is verification vs falsification and plain wrong: It happens to work on your system.
Specialize a type, not a var.

voltag

  • Newbie
  • Posts: 3
Re: How to use html colors in lazarus
« Reply #7 on: April 18, 2021, 03:09:25 pm »
@jamie
Your code works.
I corrected your code a little.
But ATStringProc_HtmlColor its some monstrous.
Code: Pascal  [Select][+][-]
  1. uses Graphics;
  2. //...
  3. function FlipColor(Const AValue:TColor):TColor;
  4. type F = Record L,M,H,A:Byte; End;
  5. var
  6.   J:Byte;
  7. begin
  8.   //$F0 FB FF(TColor)
  9.   //#FF FB F0(HTML color)
  10.   Result := AValue;
  11.   J := F(Result).L;
  12.   F(Result).L:= F(Result).H;
  13.   F(Result).H:=J;
  14. end;
  15.  
  16. function HtmlColorToColor(S:String):TColor;
  17. var k: integer;
  18. begin
  19.   if S[1] = '#' then S[1]:= '$';
  20.   Result := FlipColor(StrToInt(S));
  21. end;
  22.  
  23. function ColorToHtml(Const AValue:Tcolor):String;
  24. begin
  25.   Result := '$'+IntTOHex(FlipColor(AValue),6);
  26. end;
  27.  
  28. //example
  29. myTColor:=HtmlColorToColor('#FFA0D2');
  30.  

It is possible that People served the parameter differently
 

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: How to use html colors in lazarus
« Reply #8 on: April 18, 2021, 05:36:41 pm »
You can use BGRABitmap



Code: Pascal  [Select][+][-]
  1. uses
  2.   BGRABitmapTypes;
  3. ...
  4. var
  5.   p: TBGRAPixel;
  6.   c: TColor;
  7. ...
  8. p.fromString('#e1e1e1');
  9. c := p;

winni

  • Hero Member
  • *****
  • Posts: 3197
Re: How to use html colors in lazarus
« Reply #9 on: April 18, 2021, 07:15:41 pm »
Hi!

Also BGRABitmap:

Code: Pascal  [Select][+][-]
  1. uses ...., BGRAbitmap, BGRADefaultBitmap;
  2. ....
  3. var  tmp : TBGRAbitmap;
  4. ....
  5. tmp.swapRedBlue;
  6. ...
  7.  

Winni

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: How to use html colors in lazarus
« Reply #10 on: April 18, 2021, 11:25:11 pm »
I use

Code: Pascal  [Select][+][-]
  1. result:=(swapendian(dword(x)) shr 8) or (x and $FF000000)

The generated code size seems about the same if I remove the redundant CONST from flipcolor, and the type of used instructions too.

(added later:)

Hmm,
Code: Pascal  [Select][+][-]
  1.   result:=rordword(swapendian(dword(x)),8);

looks shorter on x86 :-)

Quote
        movl   %eax,%edx
# Var x located in register edx
   shll   $8,%eax
   andl   $-16711936,%eax
   shrl   $8,%edx
   andl   $16711935,%edx
   orl   %edx,%eax
   roll   $16,%eax
   rorl   $8,%eax

Note that the compiler can't seem to peephole a roll  16,x with a rorl 8,x  into one rol 8,x ?
« Last Edit: April 18, 2021, 11:38:41 pm by marcov »

voltag

  • Newbie
  • Posts: 3
Re: How to use html colors in lazarus
« Reply #11 on: April 19, 2021, 12:32:27 am »
@marcov , @jamie
Thank you for discovering the wonderful bits manipulation functions.

 

TinyPortal © 2005-2018