PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches
rt_serialize.h
Go to the documentation of this file.
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
48char*
49d_binary_to_hex(const uint8_t * const raw, uint32_t size, uint32_t *hexsize);
50
51void
52d_print_binary_hex(const char* msg, const uint8_t * const raw, uint32_t size);
53
54size_t
55d_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 */
84void
85setBits(char* ch, double val, int bits, int bitOffset);
86
87#endif /* ifdef OPTIMIZE_SPACE */
88
89void
90swap_char(uint8_t *a, uint8_t *b);
91
92void
93flip_endian_16(uint8_t *d);
94
95void
96flip_endian_32(uint8_t *d);
97
98void
99flip_endian_64(uint8_t *d);
100
101uint8_t
103
104uint8_t
105read_uint8(const uint8_t** from);
106
107/* unused up to now
108void
109write_uint8(uint8_t** from, uint8_t v);
110*/
111
112int8_t
113read_int8(const uint8_t** from);
114
115/* unused up to now
116void
117write_int8(uint8_t** from, int8_t v);
118*/
119
120uint16_t
121read_uint16(const uint8_t** from, uint8_t littleEndian);
122
123void
124write_uint16(uint8_t** to, uint8_t littleEndian, uint16_t v);
125
126int16_t
127read_int16(const uint8_t** from, uint8_t littleEndian);
128
129/* unused up to now
130void
131write_int16(uint8_t** to, uint8_t littleEndian, int16_t v);
132*/
133
134uint32_t
135read_uint32(const uint8_t** from, uint8_t littleEndian);
136
137/* unused up to now
138void
139write_uint32(uint8_t** to, uint8_t littleEndian, uint32_t v);
140*/
141
142int32_t
143read_int32(const uint8_t** from, uint8_t littleEndian);
144
145/* unused up to now
146void
147write_int32(uint8_t** to, uint8_t littleEndian, int32_t v);
148*/
149
150float
151read_float32(const uint8_t** from, uint8_t littleEndian);
152
153/* unused up to now
154void
155write_float32(uint8_t** from, uint8_t littleEndian, float f);
156*/
157
158double
159read_float64(const uint8_t** from, uint8_t littleEndian);
160
161/* unused up to now
162void
163write_float64(uint8_t** to, uint8_t littleEndian, double v);
164*/
165
166#endif /* RT_SERIALIZE_H_INCLUDED */
This library is the generic raster handling section of PostGIS.
void swap_char(uint8_t *a, uint8_t *b)
uint8_t isMachineLittleEndian(void)
void flip_endian_32(uint8_t *d)
void flip_endian_16(uint8_t *d)
uint8_t read_uint8(const uint8_t **from)
void write_uint16(uint8_t **to, uint8_t littleEndian, uint16_t v)
double read_float64(const uint8_t **from, uint8_t littleEndian)
float read_float32(const uint8_t **from, uint8_t littleEndian)
void flip_endian_64(uint8_t *d)
int8_t read_int8(const uint8_t **from)
int16_t read_int16(const uint8_t **from, uint8_t littleEndian)
int32_t read_int32(const uint8_t **from, uint8_t littleEndian)
uint32_t read_uint32(const uint8_t **from, uint8_t littleEndian)
uint16_t read_uint16(const uint8_t **from, uint8_t littleEndian)