Friday, August 24, 2012

Converting from a hex-string color to its rgbvalue

There are several ways to specify color when one plots using gnuplot.Among them hex-string (like "#0000ff") and rgbvalue (like "256") specification is very important. In this post we will talk about converting from a hex-string color to its rgbvalue (the inversion will be talked in another post).

reset
#pick the red color hex string out
red(colorstring)= colorstring[2:3]
#pick the green color hex string out
green(colorstring)=colorstring[4:5]
#pick the blue color hex string out
blue(colorstring)=colorstring[6:7]
#convert a hex string to its dec format
hex2dec(hex)=gprintf("%0.f",int('0X'.hex))
#calculate the rgb value from the r,g,b weight
rgb(r,g,b) = 65536*int(r)+256*int(g)+int(b)
#convert the hex color string to its rgb value.
hex2rgbvalue(color)=rgb(\
                        hex2dec(red(color)),\
                        hex2dec(green(color)),\
                        hex2dec(blue(color))\
                        ) 
set term png
set output "hex_string2rgbvalue.png"
plot 'color.dat' u 1:2:(hex2rgbvalue(stringcolumn(3)))\
              w lp pt 7 ps 3 lc rgb variable notitle
set output

File 'color.dat' has content like the following:
0 1 #ff0000
1 2 #00ff00
2 3 #0000ff
3 4 #ff00ff
4 5 #ffff00
5 6 #00ffff
0 6 #00ffff
1 5 #ffff00
2 4 #ff00ff
3 3 #0000ff
4 2 #00ff00
5 1 #ff0000

The output file 'hex_string2rgbvalue.png' looks like this:
Fig.1 Converting from a hex-string color to its rgb-value

8 comments:

  1. Nice article. It's very helpful to me. Thank you for share with us. Can you please check my rgba color picker online tool.

    ReplyDelete
  2. Nice article. It's very helpful to me. Thank you for share with us. Can you please check my hexadecimal color codes online tool.

    ReplyDelete
  3. There is a magnificent portrayal of each vital concern and that too in a compact way. Creator did his employment superbly. He prevails to convey his contemplations with best of his insight and I am truly exceptionally inspired with his endeavors. png to svg

    ReplyDelete
  4. Super Vectorizer automatically converts PNG files to SVG graphics on Mac and make the svg results easier to edit and adjust. png to svg

    ReplyDelete
  5. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. hex to decimal conversion

    ReplyDelete
  6. Compre documentos en línea, documentos originales y registrados.
    Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

    Comprar permiso de residencia,
    permiso de residenciareal y falso en línea,
    Compre licencia de conducir en línea,
    Compre una licencia de conducir española falsa en línea,
    Comprar tarjeta de identificación,
    Licencia de conducir real y falsa,
    Compre pasaporte real en línea,

    Visit Here fpr more information. :- https://permisodeespana.com/licencia-de-conducir-espanola/
    Address: 56 Guild Street, London, EC4A 3WU (UK)
    Email: contact@permisodeespana.com
    WhatsApp: +443455280186

    ReplyDelete
  7. Gnuplot Surprising: Converting From A Hex-String Color To Its Rgbvalue >>>>> Download Now

    >>>>> Download Full

    Gnuplot Surprising: Converting From A Hex-String Color To Its Rgbvalue >>>>> Download LINK

    >>>>> Download Now

    Gnuplot Surprising: Converting From A Hex-String Color To Its Rgbvalue >>>>> Download Full

    >>>>> Download LINK GT

    ReplyDelete

Creative Commons License
Except as otherwise noted, the content of this page is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.