Writing to a binary file format. ACO
Posted: Sun Oct 18, 2015 5:06 am
Hi guys!
I need a bit of help.
I have a simple binary file type i need to write out from love2d, http://www.adobe.com/devnet-apps/photos ... 7411_20528 ctrl+f and do a search for aco, and you will get to the fomat spec.
It's a super simple spec, but i'm having a few issues. On the irc i've been told to get the correct data types i can use ffi, which i've done.
Oh here is a simple bin of a 2 colour aco for reference.
The two colours are called "midnight" (2,3,34) and "green fade"(48,71,61)
That's not everything i need but it's a start. Now my issues are, i have no idea how to convert the ffi data types to their binary counterpart and save it out as a file. It's proving to be a very difficult thing to search for.
And also of course, i can't just save a txt file with the binary data in it, (tried that) it needs to be a proper binary file which i have no idea how to save.
Any help you can give would be greatly appreciated!
I need a bit of help.
I have a simple binary file type i need to write out from love2d, http://www.adobe.com/devnet-apps/photos ... 7411_20528 ctrl+f and do a search for aco, and you will get to the fomat spec.
It's a super simple spec, but i'm having a few issues. On the irc i've been told to get the correct data types i can use ffi, which i've done.
Code: Select all
local ffi = require("ffi")
ffi.cdef[[
typedef struct {
double version;
double colcount;
} header;
typedef struct {
double colourid;
unsigned short int r;
unsigned short int g;
unsigned short int b;
unsigned short int undefined;
} color;
]]
colour = ffi.typeof("color")
Code: Select all
0001 0002 0000 0202 0302 2222 0000 0000
3030 4746 3d3c 0000 0002 0002 0000 0202
0302 2222 0000 0000 0009 006d 0069 0064
006e 0069 0067 0068 0074 0000 0000 3030
4746 3d3c 0000 0000 000b 0067 0072 0065
0065 006e 0020 0066 0061 0064 0065 0000
That's not everything i need but it's a start. Now my issues are, i have no idea how to convert the ffi data types to their binary counterpart and save it out as a file. It's proving to be a very difficult thing to search for.
And also of course, i can't just save a txt file with the binary data in it, (tried that) it needs to be a proper binary file which i have no idea how to save.
Any help you can give would be greatly appreciated!