lcmtypes_image_t.cpp
Go to the documentation of this file.
1 /**************************************************************************************************
2  Software License Agreement (BSD License)
3 
4  Copyright (c) 2011-2013, LAR toolkit developers - University of Aveiro - http://lars.mec.ua.pt
5  All rights reserved.
6 
7  Redistribution and use in source and binary forms, with or without modification, are permitted
8  provided that the following conditions are met:
9 
10  *Redistributions of source code must retain the above copyright notice, this list of
11  conditions and the following disclaimer.
12  *Redistributions in binary form must reproduce the above copyright notice, this list of
13  conditions and the following disclaimer in the documentation and/or other materials provided
14  with the distribution.
15  *Neither the name of the University of Aveiro nor the names of its contributors may be used to
16  endorse or promote products derived from this software without specific prior written permission.
17 
18  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
21  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ***************************************************************************************************/
35 #include <string.h>
36 #include "lcmtypes_image_t.h"
37 
39 static int64_t __lcmtypes_image_t_hash;
40 
42 {
43  const __lcm_hash_ptr *fp;
44  for (fp = p; fp != NULL; fp = fp->parent)
45  if (fp->v == __lcmtypes_image_t_get_hash)
46  return 0;
47 
48  const __lcm_hash_ptr cp = { p, (void*)__lcmtypes_image_t_get_hash };
49  (void) cp;
50 
51  int64_t hash = 0xe613eff149a08dbcLL
59  ;
60 
61  return (hash<<1) + ((hash>>63)&1);
62 }
63 
65 {
69  }
70 
72 }
73 
74 int __lcmtypes_image_t_encode_array(void *buf, int offset, int maxlen, const lcmtypes_image_t *p, int elements)
75 {
76  int pos = 0, thislen, element;
77 
78  for (element = 0; element < elements; element++) {
79 
80  thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].utime), 1);
81  if (thislen < 0) return thislen; else pos += thislen;
82 
83  thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].width), 1);
84  if (thislen < 0) return thislen; else pos += thislen;
85 
86  thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].height), 1);
87  if (thislen < 0) return thislen; else pos += thislen;
88 
89  thislen = __int16_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].stride), 1);
90  if (thislen < 0) return thislen; else pos += thislen;
91 
92  thislen = __int32_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].pixelformat), 1);
93  if (thislen < 0) return thislen; else pos += thislen;
94 
95  thislen = __int32_t_encode_array(buf, offset + pos, maxlen - pos, &(p[element].size), 1);
96  if (thislen < 0) return thislen; else pos += thislen;
97 
98  thislen = __byte_encode_array(buf, offset + pos, maxlen - pos, p[element].image, p[element].size);
99  if (thislen < 0) return thislen; else pos += thislen;
100 
101  }
102  return pos;
103 }
104 
105 int lcmtypes_image_t_encode(void *buf, int offset, int maxlen, const lcmtypes_image_t *p)
106 {
107  int pos = 0, thislen;
108  int64_t hash = __lcmtypes_image_t_get_hash();
109 
110  thislen = __int64_t_encode_array(buf, offset + pos, maxlen - pos, &hash, 1);
111  if (thislen < 0) return thislen; else pos += thislen;
112 
113  thislen = __lcmtypes_image_t_encode_array(buf, offset + pos, maxlen - pos, p, 1);
114  if (thislen < 0) return thislen; else pos += thislen;
115 
116  return pos;
117 }
118 
120 {
121  int size = 0, element;
122  for (element = 0; element < elements; element++) {
123 
124  size += __int64_t_encoded_array_size(&(p[element].utime), 1);
125 
126  size += __int16_t_encoded_array_size(&(p[element].width), 1);
127 
128  size += __int16_t_encoded_array_size(&(p[element].height), 1);
129 
130  size += __int16_t_encoded_array_size(&(p[element].stride), 1);
131 
132  size += __int32_t_encoded_array_size(&(p[element].pixelformat), 1);
133 
134  size += __int32_t_encoded_array_size(&(p[element].size), 1);
135 
136  size += __byte_encoded_array_size(p[element].image, p[element].size);
137 
138  }
139  return size;
140 }
141 
143 {
144  return 8 + __lcmtypes_image_t_encoded_array_size(p, 1);
145 }
146 
147 int __lcmtypes_image_t_decode_array(const void *buf, int offset, int maxlen, lcmtypes_image_t *p, int elements)
148 {
149  int pos = 0, thislen, element;
150 
151  for (element = 0; element < elements; element++) {
152 
153  thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].utime), 1);
154  if (thislen < 0) return thislen; else pos += thislen;
155 
156  thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].width), 1);
157  if (thislen < 0) return thislen; else pos += thislen;
158 
159  thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].height), 1);
160  if (thislen < 0) return thislen; else pos += thislen;
161 
162  thislen = __int16_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].stride), 1);
163  if (thislen < 0) return thislen; else pos += thislen;
164 
165  thislen = __int32_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].pixelformat), 1);
166  if (thislen < 0) return thislen; else pos += thislen;
167 
168  thislen = __int32_t_decode_array(buf, offset + pos, maxlen - pos, &(p[element].size), 1);
169  if (thislen < 0) return thislen; else pos += thislen;
170 
171  p[element].image = (uint8_t*) lcm_malloc(sizeof(uint8_t) * p[element].size);
172  thislen = __byte_decode_array(buf, offset + pos, maxlen - pos, p[element].image, p[element].size);
173  if (thislen < 0) return thislen; else pos += thislen;
174 
175  }
176  return pos;
177 }
178 
180 {
181  int element;
182  for (element = 0; element < elements; element++) {
183 
184  __int64_t_decode_array_cleanup(&(p[element].utime), 1);
185 
186  __int16_t_decode_array_cleanup(&(p[element].width), 1);
187 
188  __int16_t_decode_array_cleanup(&(p[element].height), 1);
189 
190  __int16_t_decode_array_cleanup(&(p[element].stride), 1);
191 
192  __int32_t_decode_array_cleanup(&(p[element].pixelformat), 1);
193 
194  __int32_t_decode_array_cleanup(&(p[element].size), 1);
195 
196  __byte_decode_array_cleanup(p[element].image, p[element].size);
197  if (p[element].image) free(p[element].image);
198 
199  }
200  return 0;
201 }
202 
203 int lcmtypes_image_t_decode(const void *buf, int offset, int maxlen, lcmtypes_image_t *p)
204 {
205  int pos = 0, thislen;
206  int64_t hash = __lcmtypes_image_t_get_hash();
207 
208  int64_t this_hash;
209  thislen = __int64_t_decode_array(buf, offset + pos, maxlen - pos, &this_hash, 1);
210  if (thislen < 0) return thislen; else pos += thislen;
211  if (this_hash != hash) return -1;
212 
213  thislen = __lcmtypes_image_t_decode_array(buf, offset + pos, maxlen - pos, p, 1);
214  if (thislen < 0) return thislen; else pos += thislen;
215 
216  return pos;
217 }
218 
220 {
222 }
223 
225 {
226  int element;
227  for (element = 0; element < elements; element++) {
228 
229  __int64_t_clone_array(&(p[element].utime), &(q[element].utime), 1);
230 
231  __int16_t_clone_array(&(p[element].width), &(q[element].width), 1);
232 
233  __int16_t_clone_array(&(p[element].height), &(q[element].height), 1);
234 
235  __int16_t_clone_array(&(p[element].stride), &(q[element].stride), 1);
236 
237  __int32_t_clone_array(&(p[element].pixelformat), &(q[element].pixelformat), 1);
238 
239  __int32_t_clone_array(&(p[element].size), &(q[element].size), 1);
240 
241  q[element].image = (uint8_t*) lcm_malloc(sizeof(uint8_t) * q[element].size);
242  __byte_clone_array(p[element].image, q[element].image, p[element].size);
243 
244  }
245  return 0;
246 }
247 
249 {
250  lcmtypes_image_t *q = (lcmtypes_image_t*) malloc(sizeof(lcmtypes_image_t));
252  return q;
253 }
254 
256 {
258  free(p);
259 }
static void * lcm_malloc(size_t sz)
static int __int16_t_clone_array(const int16_t *p, int16_t *q, int elements)
int __lcmtypes_image_t_encoded_array_size(const lcmtypes_image_t *p, int elements)
#define __byte_decode_array_cleanup(p, sz)
Definition: lcm_coretypes.h:79
static int __int32_t_encoded_array_size(const int32_t *p, int elements)
static int __int64_t_decode_array(const void *_buf, int offset, int maxlen, int64_t *p, int elements)
int __lcmtypes_image_t_decode_array_cleanup(lcmtypes_image_t *p, int elements)
static int __byte_encode_array(void *_buf, int offset, int maxlen, const uint8_t *p, int elements)
Definition: lcm_coretypes.h:87
int lcmtypes_image_t_decode_cleanup(lcmtypes_image_t *p)
#define __int16_t_decode_array_cleanup(p, sz)
static int __int16_t_encode_array(void *_buf, int offset, int maxlen, const int16_t *p, int elements)
int64_t __lcmtypes_image_t_get_hash(void)
int __lcmtypes_image_t_clone_array(const lcmtypes_image_t *p, lcmtypes_image_t *q, int elements)
#define __byte_hash_recursive(p)
Definition: lcm_coretypes.h:78
int __lcmtypes_image_t_encode_array(void *buf, int offset, int maxlen, const lcmtypes_image_t *p, int elements)
void lcmtypes_image_t_destroy(lcmtypes_image_t *p)
static int __int64_t_encode_array(void *_buf, int offset, int maxlen, const int64_t *p, int elements)
static int __int32_t_clone_array(const int32_t *p, int32_t *q, int elements)
static int64_t __lcmtypes_image_t_hash
static int __int32_t_decode_array(const void *_buf, int offset, int maxlen, int32_t *p, int elements)
int __lcmtypes_image_t_decode_array(const void *buf, int offset, int maxlen, lcmtypes_image_t *p, int elements)
static int __int64_t_clone_array(const int64_t *p, int64_t *q, int elements)
int lcmtypes_image_t_decode(const void *buf, int offset, int maxlen, lcmtypes_image_t *p)
static int __int16_t_decode_array(const void *_buf, int offset, int maxlen, int16_t *p, int elements)
#define __int32_t_hash_recursive(p)
int lcmtypes_image_t_encoded_size(const lcmtypes_image_t *p)
#define __int64_t_hash_recursive(p)
lcmtypes_image_t * lcmtypes_image_t_copy(const lcmtypes_image_t *p)
int lcmtypes_image_t_encode(void *buf, int offset, int maxlen, const lcmtypes_image_t *p)
static int __int32_t_encode_array(void *_buf, int offset, int maxlen, const int32_t *p, int elements)
static int __byte_encoded_array_size(const uint8_t *p, int elements)
Definition: lcm_coretypes.h:82
static int __int16_t_encoded_array_size(const int16_t *p, int elements)
int64_t __lcmtypes_image_t_hash_recursive(const __lcm_hash_ptr *p)
static int __lcmtypes_image_t_hash_computed
static int __int64_t_encoded_array_size(const int64_t *p, int elements)
#define __int16_t_hash_recursive(p)
static int __byte_decode_array(const void *_buf, int offset, int maxlen, uint8_t *p, int elements)
Definition: lcm_coretypes.h:98
#define __int32_t_decode_array_cleanup(p, sz)
const __lcm_hash_ptr * parent
Definition: lcm_coretypes.h:60
THIS IS AN AUTOMATICALLY GENERATED FILE. DO NOT MODIFY BY HAND!! Generated by LCM.
#define __int64_t_decode_array_cleanup(p, sz)
static int __byte_clone_array(const uint8_t *p, uint8_t *q, int elements)


mit_darpa_logs_player
Author(s): Miguel Oliveira
autogenerated on Mon Mar 2 2015 01:32:15