1 /* 2 * 3 * WKTRaster - Raster Types for PostGIS 4 * http://trac.osgeo.org/postgis/wiki/WKTRaster 5 * 6 * Copyright (C) 2011-2013 Regents of the University of California 7 * <bkpark@ucdavis.edu> 8 * Copyright (C) 2010-2011 Jorge Arevalo <jorge.arevalo@deimos-space.com> 9 * Copyright (C) 2010-2011 David Zwarg <dzwarg@azavea.com> 10 * Copyright (C) 2009-2011 Pierre Racine <pierre.racine@sbf.ulaval.ca> 11 * Copyright (C) 2009-2011 Mateusz Loskot <mateusz@loskot.net> 12 * Copyright (C) 2008-2009 Sandro Santilli <strk@kbt.io> 13 * 14 * This program is free software; you can redistribute it and/or 15 * modify it under the terms of the GNU General Public License 16 * as published by the Free Software Foundation; either version 2 17 * of the License, or (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program; if not, write to the Free Software Foundation, 26 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 27 * 28 */ 29 30 #ifndef RT_SERIALIZE_H_INCLUDED 31 #define RT_SERIALIZE_H_INCLUDED 32 33 #include "librtcore.h" 34 35 #define BANDTYPE_FLAGS_MASK 0xF0 36 #define BANDTYPE_PIXTYPE_MASK 0x0F 37 #define BANDTYPE_FLAG_OFFDB (1<<7) 38 #define BANDTYPE_FLAG_HASNODATA (1<<6) 39 #define BANDTYPE_FLAG_ISNODATA (1<<5) 40 #define BANDTYPE_FLAG_RESERVED3 (1<<4) 41 42 #define BANDTYPE_PIXTYPE(x) ((x)&BANDTYPE_PIXTYPE_MASK) 43 #define BANDTYPE_IS_OFFDB(x) ((x)&BANDTYPE_FLAG_OFFDB) 44 #define BANDTYPE_HAS_NODATA(x) ((x)&BANDTYPE_FLAG_HASNODATA) 45 #define BANDTYPE_IS_NODATA(x) ((x)&BANDTYPE_FLAG_ISNODATA) 46 47 #if POSTGIS_DEBUG_LEVEL > 2 48 char* 49 d_binary_to_hex(const uint8_t * const raw, uint32_t size, uint32_t *hexsize); 50 51 void 52 d_print_binary_hex(const char* msg, const uint8_t * const raw, uint32_t size); 53 54 size_t 55 d_binptr_to_pos(const uint8_t * const ptr, const uint8_t * const end, size_t size); 56 57 #define CHECK_BINPTR_POSITION(ptr, end, size, pos) \ 58 { if (pos != d_binptr_to_pos(ptr, end, size)) { \ 59 fprintf(stderr, "Check of binary stream pointer position failed on line %d\n", __LINE__); \ 60 fprintf(stderr, "\tactual = %lu, expected = %lu\n", (long unsigned)d_binptr_to_pos(ptr, end, size), (long unsigned)pos); \ 61 } } 62 63 #else 64 65 #define CHECK_BINPTR_POSITION(ptr, end, size, pos) ((void)0); 66 67 #endif /* if POSTGIS_DEBUG_LEVEL > 2 */ 68 69 #ifdef OPTIMIZE_SPACE 70 71 /* 72 * Set given number of bits of the given byte, 73 * starting from given bitOffset (from the first) 74 * to the given value. 75 * 76 * Examples: 77 * char ch; 78 * ch=0; setBits(&ch, 1, 1, 0) -> ch==8 79 * ch=0; setBits(&ch, 3, 2, 1) -> ch==96 (0x60) 80 * 81 * Note that number of bits set must be <= 8-bitOffset 82 * 83 */ 84 void 85 setBits(char* ch, double val, int bits, int bitOffset); 86 87 #endif /* ifdef OPTIMIZE_SPACE */ 88 89 void 90 swap_char(uint8_t *a, uint8_t *b); 91 92 void 93 flip_endian_16(uint8_t *d); 94 95 void 96 flip_endian_32(uint8_t *d); 97 98 void 99 flip_endian_64(uint8_t *d); 100 101 uint8_t 102 isMachineLittleEndian(void); 103 104 uint8_t 105 read_uint8(const uint8_t** from); 106 107 /* unused up to now 108 void 109 write_uint8(uint8_t** from, uint8_t v); 110 */ 111 112 int8_t 113 read_int8(const uint8_t** from); 114 115 /* unused up to now 116 void 117 write_int8(uint8_t** from, int8_t v); 118 */ 119 120 uint16_t 121 read_uint16(const uint8_t** from, uint8_t littleEndian); 122 123 void 124 write_uint16(uint8_t** to, uint8_t littleEndian, uint16_t v); 125 126 int16_t 127 read_int16(const uint8_t** from, uint8_t littleEndian); 128 129 /* unused up to now 130 void 131 write_int16(uint8_t** to, uint8_t littleEndian, int16_t v); 132 */ 133 134 uint32_t 135 read_uint32(const uint8_t** from, uint8_t littleEndian); 136 137 /* unused up to now 138 void 139 write_uint32(uint8_t** to, uint8_t littleEndian, uint32_t v); 140 */ 141 142 int32_t 143 read_int32(const uint8_t** from, uint8_t littleEndian); 144 145 /* unused up to now 146 void 147 write_int32(uint8_t** to, uint8_t littleEndian, int32_t v); 148 */ 149 150 float 151 read_float32(const uint8_t** from, uint8_t littleEndian); 152 153 /* unused up to now 154 void 155 write_float32(uint8_t** from, uint8_t littleEndian, float f); 156 */ 157 158 double 159 read_float64(const uint8_t** from, uint8_t littleEndian); 160 161 /* unused up to now 162 void 163 write_float64(uint8_t** to, uint8_t littleEndian, double v); 164 */ 165 166 #endif /* RT_SERIALIZE_H_INCLUDED */ 167