Blame gegl/buffer/gegl-buffer-index.h

Packit Service 2781ba
#ifndef __GEGL_BUFFER_INDEX_H
Packit Service 2781ba
#define __GEGL_BUFFER_INDEX_H
Packit Service 2781ba
/* File format building blocks
Packit Service 2781ba
Packit Service 2781ba
GeglBuffer on disk representation
Packit Service 2781ba
=================================
Packit Service 2781ba
Packit Service 2781ba
*/
Packit Service 2781ba
Packit Service 2781ba
Packit Service 2781ba
/* Increase this number when the structures change.*/
Packit Service 2781ba
#define GEGL_FILE_SPEC_REV     0
Packit Service 2781ba
#define GEGL_MAGIC             {'G','E','G','L'}
Packit Service 2781ba
Packit Service 2781ba
#define GEGL_FLAG_TILE         1
Packit Service 2781ba
#define GEGL_FLAG_FREE_TILE    0xf+2
Packit Service 2781ba
Packit Service 2781ba
/* a VOID message, indicating that the specified tile has been rewritten */
Packit Service 2781ba
#define GEGL_FLAG_INVALIDATED  2
Packit Service 2781ba
Packit Service 2781ba
/* these flags are used for the header, the lower bits of the
Packit Service 2781ba
 * header store the revision
Packit Service 2781ba
 */
Packit Service 2781ba
#define GEGL_FLAG_LOCKED       (1<<(8+0))
Packit Service 2781ba
#define GEGL_FLAG_FLUSHED      (1<<(8+1))
Packit Service 2781ba
#define GEGL_FLAG_IS_HEADER    (1<<(8+3))
Packit Service 2781ba
Packit Service 2781ba
/* The default header we expect to see on a file is that it is
Packit Service 2781ba
 * flushed, and has the revision the file conforms to written
Packit Service 2781ba
 * to it.
Packit Service 2781ba
 */
Packit Service 2781ba
#define  GEGL_FLAG_HEADER    (GEGL_FLAG_FLUSHED  |\
Packit Service 2781ba
                              GEGL_FLAG_IS_HEADER|\
Packit Service 2781ba
                              GEGL_FILE_SPEC_REV)
Packit Service 2781ba
Packit Service 2781ba
/*
Packit Service 2781ba
 * This header is the first 256 bytes of the GEGL buffer.
Packit Service 2781ba
 */
Packit Service 2781ba
typedef struct {
Packit Service 2781ba
  gchar   magic[4];    /* - a 4 byte identifier */
Packit Service 2781ba
  guint32 flags;       /* the header flags is used to encode state and revision
Packit Service 2781ba
                          */
Packit Service 2781ba
  guint64 next;        /* offset to first GeglBufferBlock */
Packit Service 2781ba
Packit Service 2781ba
  guint32 tile_width;
Packit Service 2781ba
  guint32 tile_height;
Packit Service 2781ba
  guint16 bytes_per_pixel;
Packit Service 2781ba
Packit Service 2781ba
  gchar   description[64]; /* GEGL stores the string of the babl format
Packit Service 2781ba
                            * here, as well as after the \0 a debug string
Packit Service 2781ba
                            * describing the buffer.
Packit Service 2781ba
                            */
Packit Service 2781ba
Packit Service 2781ba
  /* the ROI could come as a separate block */
Packit Service 2781ba
  gint32  x;               /* indication of bounding box for tiles stored. */
Packit Service 2781ba
  gint32  y;               /* this isn't really needed as each GeglBuffer as */
Packit Service 2781ba
  guint32 width;           /* represented on disk doesn't really have any */
Packit Service 2781ba
  guint32 height;          /* dimension restriction. */
Packit Service 2781ba
Packit Service 2781ba
  guint32 rev;             /* if it changes on disk it means the index has changed */
Packit Service 2781ba
Packit Service 2781ba
  gint32  padding[36];     /* Pad the structure to be 256 bytes long */
Packit Service 2781ba
} GeglBufferHeader;
Packit Service 2781ba
Packit Service 2781ba
/* the revision of the format is stored in the flags of the header in the
Packit Service 2781ba
 * lower 8 bits
Packit Service 2781ba
 */
Packit Service 2781ba
#define gegl_buffer_header_get_rev(header)  (((GeglBufferHeader*)(header))->flags&0xff)
Packit Service 2781ba
Packit Service 2781ba
/* The GeglBuffer index is written to the file as a linked list of
Packit Service 2781ba
 * GeglBufferBlock's, each block encodes it's own length and the offset
Packit Service 2781ba
 * of the file which the next block can be found. The last block in the
Packit Service 2781ba
 * list has the next offset set to 0.
Packit Service 2781ba
 */
Packit Service 2781ba
Packit Service 2781ba
typedef struct {
Packit Service 2781ba
  guint32  length; /* the length of this block */
Packit Service 2781ba
  guint32  flags;  /* flags (can be used to handle different block types
Packit Service 2781ba
                    * differently
Packit Service 2781ba
                    */
Packit Service 2781ba
  guint64  next;   /*next block element in file, this is the offset in the
Packit Service 2781ba
                    *file that the next block in the chain resides at
Packit Service 2781ba
                    */
Packit Service 2781ba
} GeglBufferBlock;
Packit Service 2781ba
Packit Service 2781ba
/* The header is followed by entries describing tiles stored in the swap,
Packit Service 2781ba
 */
Packit Service 2781ba
typedef struct {
Packit Service 2781ba
  GeglBufferBlock block; /* The block definition for this tile entry   */
Packit Service 2781ba
  guint64 offset;        /* offset into file for this tile             */
Packit Service 2781ba
  gint32  x;             /* upperleft of tile % tile_width coordinates */
Packit Service 2781ba
  gint32  y;
Packit Service 2781ba
Packit Service 2781ba
  gint32  z;             /* mipmap subdivision level of tile (0=100%)  */
Packit Service 2781ba
Packit Service 2781ba
  guint32 rev;           /* revision, if a buffer is monitored for header
Packit Service 2781ba
                            revision changes, the existing loaded index
Packit Service 2781ba
                            can be compare the revision of tiles and update
Packit Service 2781ba
                            own state when revision differs. */
Packit Service 2781ba
} GeglBufferTile;
Packit Service 2781ba
Packit Service 2781ba
/* A convenience union to allow quick and simple casting */
Packit Service 2781ba
typedef union {
Packit Service 2781ba
  guint32          length;
Packit Service 2781ba
  GeglBufferBlock  block;
Packit Service 2781ba
  GeglBufferHeader header;
Packit Service 2781ba
  GeglBufferTile   tile;
Packit Service 2781ba
} GeglBufferItem;
Packit Service 2781ba
Packit Service 2781ba
/* functions to initialize data structures */
Packit Service 2781ba
GeglBufferTile * gegl_tile_entry_new (gint x,
Packit Service 2781ba
                                      gint y,
Packit Service 2781ba
                                      gint z);
Packit Service 2781ba
Packit Service 2781ba
/* intializing the header causes the format to be written out
Packit Service 2781ba
 * as well as a hidden comment after the zero terminated format
Packit Service 2781ba
 * with additional human readable information about the header.
Packit Service 2781ba
 */
Packit Service 2781ba
void gegl_buffer_header_init (GeglBufferHeader *header,
Packit Service 2781ba
                              gint              tile_width,
Packit Service 2781ba
                              gint              tile_height,
Packit Service 2781ba
                              gint              bpp,
Packit Service 2781ba
                              const Babl*       format);
Packit Service 2781ba
Packit Service 2781ba
void gegl_tile_entry_destroy (GeglBufferTile *entry);
Packit Service 2781ba
Packit Service 2781ba
GeglBufferItem *gegl_buffer_read_header(int i,
Packit Service 2781ba
                                        goffset      *offset);
Packit Service 2781ba
GList          *gegl_buffer_read_index (int i,
Packit Service 2781ba
                                        goffset      *offset);
Packit Service 2781ba
Packit Service 2781ba
#define struct_check_padding(type, size) \
Packit Service 2781ba
  if (sizeof (type) != size) \
Packit Service 2781ba
    {\
Packit Service 2781ba
      g_warning ("%s %s is %i bytes, should be %i padding is off by: %i bytes %i ints", G_STRFUNC, #type,\
Packit Service 2781ba
         (int) sizeof (type),\
Packit Service 2781ba
         size,\
Packit Service 2781ba
         (int) sizeof (type) - size,\
Packit Service 2781ba
         (int)(sizeof (type) - size) / 4);\
Packit Service 2781ba
      return;\
Packit Service 2781ba
    }
Packit Service 2781ba
#define GEGL_BUFFER_STRUCT_CHECK_PADDING \
Packit Service 2781ba
  {struct_check_padding (GeglBufferBlock, 16);\
Packit Service 2781ba
  struct_check_padding (GeglBufferHeader, 256);}
Packit Service 2781ba
#define GEGL_BUFFER_SANITY {static gboolean done=FALSE;if(!done){GEGL_BUFFER_STRUCT_CHECK_PADDING;done=TRUE;}}
Packit Service 2781ba
Packit Service 2781ba
#endif