It works very well and has helped me out a few times ;D.
Information is printed on screen AND saved in the pal.bmp and pal.txt files.
You can specify how large the squares of colour are. The text table lists the colour values as uinteger and as hex.
You must specify a valid bitmap file in the command prompt, or you can simply drag a bitmap image onto the compiled program.
No external libraries necessary, just compile the code (preferably with the -s gui parameter).
Code: Select all
#include "file.bi"
#include "windows.bi"
'functions from my personal library, ported over
function getbmpwidth(byval bitmapFile as string) as long
dim as long bmpwidth
dim as integer fileno = freefile
if open(bitmapFile for binary access read as #fileno) <> 0 then return -1
get #fileno, 19, bmpwidth
close #fileno: return bmpwidth
end function
function getbmpheight(byval bitmapFile as string) as long
dim as long bmpheight
dim as integer fileno = freefile
if open(bitmapFile for binary access read as #fileno) <> 0 then return -1
get #fileno, 23, bmpheight
close #fileno: return bmpheight
end function
function getimage(byval pathOfBitmap as string) as any ptr
dim ret as any ptr = imagecreate(getbmpwidth(pathOfBitmap), getbmpheight(pathOfBitmap))
bload pathOfBitmap, ret
return ret
end function
if fileexists(command(1)) = 0 then
MessageBox(0, "Please pass a bitmap image path to the command-line!", "Error!", MB_ICONERROR)
system
endif
if getbmpwidth(command(1)) = 0 or getbmpheight(command(1)) = 0 then
MessageBox(0, "The file provided was not a valid bitmap file!", "Error!", MB_ICONERROR)
system
endif
screenres 400, 400, 32
dim as ulong ptr imgptr = getimage(command(1))
redim as ulong colours(1 to 1)
for y as ulongint = 0 to getbmpheight(command(1))-1
for x as ulongint = 0 to getbmpwidth(command(1))-1
dim as ulong col = point(x, y, imgptr)
for i as ulongint = 1 to ubound(colours)
if colours(i) = col then exit for
if colours(i) <> col and i = ubound(colours) then
redim preserve colours(1 to ubound(colours)+1)
colours(ubound(colours)) = col
endif
next
next
next
for i as ulongint = 1 to ubound(colours)
print colours(i) & " = " & hex(colours(i))
next
open "pal.txt" for output as #1
for i as ulongint = 1 to ubound(colours)
print #1, colours(i) & " = " & hex(colours(i))
next
close #1
sleep
dim as ubyte coloursize
do
cls
input "How big should the squares of colour be?", coloursize
loop while coloursize = 0
cls
dim as ulong ptr pal = imagecreate(coloursize*ubound(colours), coloursize)
for i as ulongint = 1 to ubound(colours)
line pal, (coloursize*(i-1), 0)-((coloursize*i)-1, coloursize-1), colours(i), BF
next
put (0, 0), pal, pset
bsave "pal.bmp", pal
sleep
system
Note: strangely I compile on Windows 10 and UAC automatically is enabled for the resulting program. No idea why.