C Example

<< Click to Display Table of Contents >>

Navigation:  FIF2 Binary File Format Specification >

C Example

#define FIF2_MAGIC "FIF2"
 
/* FIF2 fixed header: 64 bytes */
typedef struct
{
    char     magic[4];              /* "FIF2" */
 
    uint8_t  major_version;         /* breaking format version */
    uint8_t  minor_version;         /* compatible feature version */
    uint16_t header_size;           /* usually 64 */
 
    uint32_t file_size;             /* total file size, 0 if unknown */
    uint32_t flags;                 /* global format flags */
 
    uint32_t width;                 /* output image width */
    uint32_t height;                /* output image height */
 
    int16_t  canvas_x;              /* optional image origin X */
    int16_t  canvas_y;              /* optional image origin Y */
 
    uint16_t channels;              /* 1, 3, 4, etc. */
    uint16_t bits_per_channel;      /* 8, 10, 12, 16, 32 */
 
    uint16_t color_model;           /* grayscale, RGB, RGBA, YCbCr */
    uint16_t transfer_function;     /* sRGB, linear, HDR, gamma */
    uint16_t primaries;             /* sRGB, Rec.709, Rec.2020 */
    uint16_t alpha_mode;            /* none, straight, premultiplied */
 
    uint16_t default_iterations;    /* recommended decode iterations */
    uint16_t max_iterations;        /* decoder safety limit */
    float    convergence_epsilon;   /* optional convergence threshold */
 
    uint32_t chunk_table_offset;    /* offset to chunk directory */
    uint32_t chunk_count;           /* number of chunks */
 
    uint32_t header_crc32;          /* checksum of header */
    uint32_t reserved;              /* must be 0 */
 
} FIF2Header;

 

 

/* Chunk directory entry */

typedef struct

{

    char     chunk_id[4];           /* "META", "PART", "XFRM", etc. */

    uint32_t offset;                /* byte offset of chunk data */

    uint32_t size;                  /* chunk data size in bytes */

    uint32_t flags;                 /* compression/encryption/etc. */

    uint32_t crc32;                 /* chunk checksum */

 

} FIF2ChunkEntry;

 

 

/* Partition information chunk: "PART" */

typedef struct

{

    uint16_t partition_type;         /* fixed, quadtree, adaptive */

    uint16_t range_block_width;

    uint16_t range_block_height;

    uint16_t domain_block_width;

    uint16_t domain_block_height;

    uint16_t max_quadtree_depth;

    uint32_t block_count;

 

} FIF2PartitionChunk;

 

 

/* Single fractal transform record */

typedef struct

{

    uint32_t domain_x;

    uint32_t domain_y;

    uint32_t range_x;

    uint32_t range_y;

 

    uint16_t domain_width;

    uint16_t domain_height;

    uint16_t range_width;

    uint16_t range_height;

 

    uint8_t  transform_type;        /* rotate/mirror mode */

    uint8_t  channel;               /* target channel */

    uint16_t reserved;

 

    float    contrast;

    float    brightness;

    float    error;

 

} FIF2TransformRecord;

 

 

/* Transform chunk: "XFRM" */

typedef struct

{

    uint32_t transform_count;

    uint32_t record_size;

 

    /* Followed by FIF2TransformRecord records */

 

} FIF2TransformChunk;

 

 

enum FIF2ColorModel

{

    FIF2_COLOR_GRAY  = 0,

    FIF2_COLOR_RGB   = 1,

    FIF2_COLOR_RGBA  = 2,

    FIF2_COLOR_YCBCR = 3

};

 

enum FIF2TransformType

{

    FIF2_TRANSFORM_NONE      = 0,

    FIF2_TRANSFORM_ROT90     = 1,

    FIF2_TRANSFORM_ROT180    = 2,

    FIF2_TRANSFORM_ROT270    = 3,

    FIF2_TRANSFORM_MIRROR_X  = 4,

    FIF2_TRANSFORM_MIRROR_Y  = 5

};