// Author: A. Torpy
// Written: 13 Sept 2012
hvar hAM
set hAM
int nx ny
set nx
set ny
assert > "Attributes map is not initialised!"
// ask user for output filename
filesel fs
filesel.Init &fs false NULL "Bitmap image (*.bmp)|*.bmp|8-bit RAW file (*.raw)|*.raw|" "bmp" NULL
if >
return -1
endif
string FileName
set FileName
// create an output map
map TempMap
assert "Cannot initialise temp map!"
int i j
set i 0
set j 0
buffer buf
buffer.InitByType &buf 256 ushort
ushort us
byte b
progbox pb
progbox.SetTitle &pb "Converting attributes map to 8-bit"
progbox.ShowWnd &pb
int64 p pmax
set p 0
set pmax ny>
do
set i 0
do
progbox.SetProgress &pb pmax
map.GetPixel hAM i j &us
set b
map.SetPixel &TempMap i j &b
buffer.SetValue &buf b us
while nx>
while ny>
assert "Error saving file!"
// now compile palette list
voidptr fp
set fp " palette.txt"> "w">
assert fp "Cannot create palette file!"
int k
string s
do
set us 0
buffer.GetValue &buf k us
if
set s "\n">>>
fwrite fp s
endif
while 256>
fclose fp
MessageBox "File saved OK" 0x40
return 0