VGA to HTML Hex Table

User projects written in or related to FreeBASIC.
Posts: 71
Joined: Oct 24, 2009 13:45

VGA to HTML Hex Table

Postby DCrawshawJr » Feb 11, 2018 21:42

I've been working on a number of projects in many languages (PHP, MySqli, and now Python), and I've got a bunch of old FreeBasic RPG tiles that I'd like to transfer over to work with modern programming languages.

So, what I've done is convert each of the 256 VGA color codes into an HTML hex value. A pain in the butt to do, but thank God for GIMP, where you can use the eyedropper to click on any pixel on the screen, and it will show you it's corresponding HTML hex value.

I wrote a small program in FreeBasic that displays all the VGA colors, then I went to work on the hex values.

You can download the table here:

Hope this helps!
Posts: 4686
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: VGA to HTML Hex Table

Postby dodicat » Feb 11, 2018 22:40

Here is a simple picker for windows.

Code: Select all


Type screenpoint
    As long x,y
End Type
'Windows job lot :
Extern "windows" Lib "user32"
Declare Function GetDC Alias "GetDC" (Byval As Any Ptr) As Any Ptr
Declare Function PopBeep Alias "MessageBeep" (Byval As long) As long
End Extern
Extern "windows" Lib "gdi32"
Declare Function _point Alias "GetPixel"(Byval As Any Ptr,Byval As long,Byval As long) As Ulong
End Extern
Declare Function _getmouse Alias "GetCursorPos" (Byval As Any Pointer) As long
Declare Function NoConsole Alias "FreeConsole" () As long
Declare Function SetWindowTheme Lib "UxTheme.dll" Alias "SetWindowTheme"(As Any Ptr,As zstring Ptr,As zstring Ptr) As Long

Dim Shared As integer xres,yres
function HTML(v as ulong) as string
    dim as string hx=hex(v)
    swap hx[0],hx[4]
    swap hx[1],hx[5]
return hx
end function
Dim As Any Ptr MyScreen = GetDC(0)
Dim As Ulong v

Screenres 200,200,32,,&h20 or &h40 or &h80
Dim Win As Any Ptr=screenptr
Var Ip = Cptr(Integer Ptr,@Win )
Screencontrol 2,*Ip
SetWindowTheme(win," "," ")
Windowtitle "[   MOVE    ]"
Screeninfo xres,yres
width xres\8,yres\16
Dim As Ubyte r,g,b
Color ,RGB (236,233,216)
Dim As screenpoint m
dim as string key,s="  " +chr(13)+chr(10),msg="<space> to save a colour"
dim as long counter
dim as integer x,y
redim as ulong c(0)
    if key=" "  then
        redim preserve c(1 to counter)
var bb=string(3-len(str(b)),"0")+str(b),rr=string(3-len(str(r)),"0")+str(r),gg=string(3-len(str(g)),"0")+str(g)
var sp=string(6-len(hex(v))," ")
        s+= "RGB (" & bb &"," & gg &"," & rr &")"+ "   HEX &h"+hex(v)+sp+"   HTML #"+HTML(v) +chr(13)+chr(10)
    end if
    _getmouse @m
    screencontrol 0,x,y
'if m.x>x and m.x<x+xres and m.y>y and m.y<y+yres then msg="" else msg="<space> to save a colour"
    Locate 1,1
    Color 0
    print "X,Y   ";str(m.x);",";str(m.y)
    Print "Red   ";b
    Print "Green ";g
    Print "Blue  ";r
    locate 10,1
    print "HEX   &h";hex(v,6)
    draw string(0,180),msg,rgb(0,0,0)
    print "HTML   #";HTML(v)
    r= Cptr(Ubyte Ptr,@v)[2] 'Or just use the standard r,g,b extract method
    g= Cptr(Ubyte Ptr,@v)[1] 'but this method is a tad faster
    b= Cptr(Ubyte Ptr,@v)[0]
    Sleep 1,1
Loop Until key=Chr(255,107) or key=chr(27)
 if s<>"  " +chr(13)+chr(10) then
screenres 800,700,32
width 800\8,700\16
windowtitle "Colours picked  (" & counter &" colours)."
print s
for z as long=1 to ubound(c)
    next z
var f=freefile
open "colours.txt" for output as #f
print #f,s
close #f
dim as long i=instrrev(s,"\")
s=mid(s,1,i) + "colours.txt"
print "printed to ";s
print "Press a key to exit"
end if
Posts: 71
Joined: Oct 24, 2009 13:45

Re: VGA to HTML Hex Table

Postby DCrawshawJr » Feb 11, 2018 23:54

That is AWESOME. Thanks!
Posts: 171
Joined: Sep 30, 2017 3:22

Re: VGA to HTML Hex Table

Postby sancho3 » Feb 12, 2018 0:07

I am sorry that you worked so hard with Gimp and point and click.
Have a look at the Palette command in FreeBASIC and the Get option for it.
I just built a color picker tool and looked for an easy way to find the default palette colors and came accross Palette Get.
If the Get option is specified, Palette retrieves instead of setting color values for the current palette.
Site Admin
Posts: 5877
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: VGA to HTML Hex Table

Postby counting_pine » Feb 13, 2018 14:11

For what it's worth, DOSBox's VGA palette is stored in the vga_palette[][] array here, in case you want something slightly more official to check it against: ... s.cpp#l329
(Just note that it's stored in bytes, in R,G,B order, with a range 0..3f)

We also have FreeBASIC's VGA palette here in an image: /wiki/GfxDefPalettes, but no text form. (I'm not sure how we settled on the last two bits in our palette..)
We store the values somewhat opaquely in a 768-byte binary file in our repo: ... b2/gfxdata

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 5 guests