mIRC Home    About    Download    Register    News    Help

Print Thread
HTML Hex Codes to mIRC Color Codes #187612 09/10/07 03:16 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Is there a script that can convert Hex code colors to mIRC colors with even a vague degree of accuracy? Obviously, we're limited to 16 colors in mIRC, but there should be some way to at least convert the hex codes to a close equivalent in mIRC. I'd like to be able to take set of HTML text that includes stuff like <font color="#FFA61B">text</font> and make it into an equivalent mIRC color code.

Any ideas?


Invision Support
#Invision on irc.irchighway.net
Re: HTML Hex Codes to mIRC Color Codes [Re: Riamus2] #187618 09/10/07 04:30 AM
Joined: Oct 2005
Posts: 1,741
G
genius_at_work Offline
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Due to the non-relational nature of mIRC colors (there is no pattern) I think it would be very difficult (or impossible) to make an actual mathematical conversion script. I tried making a converter based on the decimal value of each mIRC color compared to the decimal value of the hex code. The results made no sense. Here is the code I used:

Code:
<mirc> <hex> <order> <dec>
; 00 FFFFFF F 16777215
; 01 000000 0 00000000
; 02 000066 1 00000102
; 03 009900 3 00039168
; 04 FF0000 B 16711680
; 05 660000 7 06684672
; 06 990099 9 10027161
; 07 FF6600 D 16737792
; 08 FFFF00 E 16776960
; 09 00FF00 5 00065280
; 10 009999 4 00039321
; 11 00FFFF 6 00065535
; 12 0000FF 2 00000255
; 13 FF00FF C 16711935
; 14 666666 8 06710886
; 15 CCCCCC A 13421772

alias hextomirc {
  var %x = $base($remove($1,$chr(35)),16,10)
  var %h = 000000,000066,0000FF,009900,009999,00FF00,00FFFF,660000,666666,990099,CCCCCC,FF0000,FF00FF,FF6600,FFFF00,FFFFFF
  var %m = 01,02,12,03,10,09,11,05,14,06,15,04,13,07,08,00

  var %i = 0, %ii = 15, %a, %b, %c
  while (%i < %ii) {
    inc %i
    %a = $base($gettok(%h,%i,44),16,10)
    %b = $base($gettok(%h,$calc(%i + 1),44),16,10)
    %c = $+(%a,-,%b)

    if (%x isnum %c) { 
      if ($calc(%x - %a) < $calc(%b - %x)) var %z = %i
      else var %z = $calc(%i + 1)
      break
    }
    else continue
  }
  echo -a Input H: $1
  echo -a Input D: %x
  echo -a Output M: $gettok(%m,%z,44) 
  echo -a Output H: $gettok(%h,%z,44)
  echo -a Output D: $base($gettok(%h,%z,44),16,10)

  if (%z != $null) return $gettok(%m,%z,44)
  else echo -a Invalid hex value
}





The most reliable method for converting from hex to mIRC colors would be to make a table of ranges to determine which hex colors should be changed into which mIRC colors.

-genius_at_work

Re: HTML Hex Codes to mIRC Color Codes [Re: genius_at_work] #187634 09/10/07 10:07 AM
Joined: Oct 2004
Posts: 8,330
Riamus2 Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Darn, that is what I was afraid of. Well, I'm not about to try doing that, so oh well.


Invision Support
#Invision on irc.irchighway.net
Re: HTML Hex Codes to mIRC Color Codes [Re: Riamus2] #195968 07/03/08 03:37 AM
Joined: Jul 2006
Posts: 107
L
LonDart Offline
Vogon poet
Offline
Vogon poet
L
Joined: Jul 2006
Posts: 107
While searching for something *completely* different, I noticed this post.
If it's been answered since, I apologize. I've forgetten how (other than it involved Excel), but I figured it out.

As you've determined, the mIRC color code is not the decimal equivalent of the hex RGB code used in HTML.
BUT it IS the decimal equivalent of the hex BGR code.
Huh?!
In other words, you have to swap the B and R pairs, e.g. FF0000 becomes 0000FF, and then convert from hex to dec.

So:
Code:
alias html2mirc {
  set %mcc $remove($1,$chr(35))
  set %mcc $+($right(%mcc,2),$mid(%mcc,3,2),$left(%mcc,2))
  set -u0 %mcc $base(%mcc,16,10)
  if ($isid) return %mcc
  else echo -ag mIRC color code for $1 is %mcc
}
Ex: /html2mirc 8000FF [returns: mIRC color code for 8000FF is 16711808]
or
$html2mirc(C60217) [returns: 1508038]

And, of course:
Code:
alias mirc2html {
  set -u0 %mcc $base($1,10,16,6)
  set -u0 %hcc $+($chr(35),$right(%mcc,2),$mid(%mcc,3,2),$left(%mcc,2))
  if ($isid) return %hcc
  else echo -ag mIRC color code $1 in HTML is %hcc
}

This just shows the essence. It's actually completely useless for changing colors in a running mIRC, but I suppose you could produce lines you could paste into the mirc.ini of a non-running client. (See Merlin's invaluable mIRC.ini Unleashed)

Happy coding... smile


LonDart