| This is an old revision of the document! Table of Contents Scripts > Convert AM to BYTE
 AboutPlease see this forum thread for more information. Script contents// Author:  A. Torpy
// Written: 13 Sept 2012
hvar hAM
set hAM <project.GetMap "AM">
int nx ny
set nx <map.GetWidth hAM>
set ny <map.GetHeight hAM>
assert <iseq 40 <map.GetMapType hAM>> "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 <not <EditUI &fs "Select output file">>
  return -1
endif
string FileName
set FileName <filesel.GetPathA &fs>
// create an output map
map TempMap
assert <map.Init &TempMap nx ny 1 1 false> "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 <mul <cast int64 nx> ny>
do
  set i 0
  do
    progbox.SetProgress &pb <incr p> pmax    
    map.GetPixel hAM i j &us
    set b <div us 255>
    map.SetPixel &TempMap i j &b
    buffer.SetValue &buf b us
  while <islt <incr i> nx>
while <islt <incr j> ny>
assert <map.SaveFile2 &TempMap FileName false true> "Error saving file!"
// now compile palette list
voidptr fp
set fp <fopen <strcat <file.TrimExt FileName> " palette.txt"> "w">
assert fp "Cannot create palette file!"
int k
string s
do
  set us 0 
  buffer.GetValue &buf k us  
  if <isgt us 0>
    set s <strcat k <strcat ": " <strcat <landtype.GetTypeNameByID us> "\n">>>
    fwrite fp s
  endif
while <islt <incr k> 256>
fclose fp
MessageBox "File saved OK" 0x40
return 0Except where otherwise noted, content on this wiki is licensed under the following license:CC Attribution-Share Alike 3.0 Unported |