/* 
 * $Id$
 *
 * WKTRaster - Raster Types for PostGIS
 * http://www.postgis.org/support/wiki/index.php?WKTRasterHomePage
 *
 * Copyright (C) 2009  Sandro Santilli <strk@keybit.net>
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef RT_PG_H
#define RT_PG_H

#include <stdint.h> /* for int16_t and friends */

#include "rt_api.h"

typedef struct rt_pgband8_t {
    uint8_t pixtype;
    uint8_t data[1];
} rt_pgband8;

typedef struct rt_pgband16_t {
    uint8_t pixtype;
    uint8_t pad;
    uint8_t data[1];
} rt_pgband16;

typedef struct rt_pgband32_t {
    uint8_t pixtype;
    uint8_t pad0;
    uint8_t pad1;
    uint8_t pad2;
    uint8_t data[1];
} rt_pgband32;

typedef struct rt_pgband64_t {
    uint8_t pixtype;
    uint8_t pad[7];
    uint8_t data[1];
} rt_pgband64;

typedef struct rt_pgband_t {
    uint8_t pixtype;
    uint8_t data[1];
} rt_pgband;

/* Header of PostgreSQL-stored RASTER value,
 * and binary representation of it */
typedef struct rt_pgraster_header_t {

    /*---[ 8 byte boundary ]---{ */
    uint32_t size;    /* required by postgresql: 4 bytes */
    uint16_t version; /* format version (this is version 0): 2 bytes */
    uint16_t numBands; /* Number of bands: 2 bytes */

    /* }---[ 8 byte boundary ]---{ */
    double scaleX; /* pixel width: 8 bytes */

    /* }---[ 8 byte boundary ]---{ */
    double scaleY; /* pixel height: 8 bytes */

    /* }---[ 8 byte boundary ]---{ */
    double ipX; /* insertion point X: 8 bytes */

    /* }---[ 8 byte boundary ]---{ */
    double ipY; /* insertion point Y: 8 bytes */

    /* }---[ 8 byte boundary ]---{ */
    double skewX;  /* rotation about the X axis: 8 bytes */

    /* }---[ 8 byte boundary ]---{ */
    double skewY;  /* rotation about the Y axis: 8 bytes */

    /* }---[ 8 byte boundary ]--- */
    int32_t srid; /* Spatial reference id: 4 bytes */
    uint16_t width;  /* pixel columns: 2 bytes */
    uint16_t height; /* pixel rows: 2 bytes */
} rt_pgraster_header;

typedef rt_pgraster_header rt_pgraster;

#endif /* RT_PG_H */
