save in own format imagej or imagej2

37 views Asked by At

I am participating in the development of a real time strategy game named 0ad. When it comes to map-making one of the coolest options is using real topographic data in image files and convert them to a heightmap own format. The problem is that it allows 16-bit (65536) heights whereas it only allows 8-bit files as import. Apparently it is not easy to fix this in its code, so I want to write a script (preferably) or a plugin in ImageJ (or ImageJ2) in order to convert a 16-bit grayscale image directly into a heightmap.

  • Is this possible with a script? (Prefer Python or Javascript) I have found no clue how to save an arbitrary binary file to write this own format.
  • If a plugin is a must, then: where to start and how the files are saved given this is not a standard image?

The technical details of the format are defined in C++ (a bit obscure for me as I am not a professional programmer) below:

PMP {
 // FILE HEADER
 char magic[4]; // == "PSMP"
 u32 version; // == 6
 u32 data_size; // == filesize-12

 // DATA SECTION
 u32 map_size; // number of patches (16x16 tiles) per side

 u16 heightmap[(mapsize*16 + 1)*(mapsize*16 + 1)]; // vertex heights with lines indexed from
                                                   // bottom to top and columns from left to right
 u32 num_terrain_textures;
 String terrain_textures[num_terrain_textures]; // filenames (no path and file ending), e.g. "cliff1"

 Patch patches[mapsize*mapsize]; // lines indexed from bottom to top, columns from left to right
 }
 
 Patch {
     Tile tiles[16*16];
 }
 
 Tile {
     u16 texture1; // index into terrain_textures[]
     u16 texture2; // index, or 0xFFFF for 'none'
     u32 priority; // Used for blending between edges of tiles with different textures. A higher priority is blended on top of a lower priority.
 }
 
 String {
     u32 length;
     char data[length]; // not NUL-terminated
}

Thanks, any help is welcome.

0

There are 0 answers