typedef struct rif { // "lifV0001" // "rifV0001" char magic_num[8]; // Big Endian. UTF-8 Encoded. 6C 69 66 56 30 30 30 31 uint64_t width; // Big Endian uint8_t format; uint8_t data[]; } rif_t; #define RIF_MAGIC_LITTLE {'l', 'i', 'f', 'V', '0', '0', '0', '1'} #define RIF_MAGIC_BIG {'r', 'i', 'f', 'V', '0', '0', '0', '1'} #define RIF_FORMAT_R8G8B8 0 #define RIF_FORMAT_R8G8B8A8 1 // TODO detect endianess - this breaks on big endian systems. void write_rif_little(char* path, uint32_t width, uint32_t size, uint8_t format, void* data) { // TODO is this better than just hardcoding 17? const uint32_t header_size = sizeof(rif_t) - sizeof(uint8_t*); const uint64_t img_size = header_size + size; rif_t* img = malloc(img_size); char magic[] = RIF_MAGIC_LITTLE; memcpy(&img->magic_num, magic, 8); img->width = width; img->format = format; memcpy(&img->data, data, size); FILE* output_file = fopen(path, "w"); fwrite(img, 1, img_size, output_file); free(img); }