gusimplewhiteboard
wb_memory_image_control_status.c
Go to the documentation of this file.
1/*
2 * file wb_memory_image_control_status.c
3 *
4 * This file was generated by classgenerator from memory_image_control_status.gen.
5 * DO NOT CHANGE MANUALLY!
6 *
7 * Copyright © 2021 Callum McColl. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above
17 * copyright notice, this list of conditions and the following
18 * disclaimer in the documentation and/or other materials
19 * provided with the distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgement:
23 *
24 * This product includes software developed by Callum McColl.
25 *
26 * 4. Neither the name of the author nor the names of contributors
27 * may be used to endorse or promote products derived from this
28 * software without specific prior written permission.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
34 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
35 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
36 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
37 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
38 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
39 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
40 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 *
42 * -----------------------------------------------------------------------
43 * This program is free software; you can redistribute it and/or
44 * modify it under the above terms or under the terms of the GNU
45 * General Public License as published by the Free Software Foundation;
46 * either version 2 of the License, or (at your option) any later version.
47 *
48 * This program is distributed in the hope that it will be useful,
49 * but WITHOUT ANY WARRANTY; without even the implied warranty of
50 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
51 * GNU General Public License for more details.
52 *
53 * You should have received a copy of the GNU General Public License
54 * along with this program; if not, see http://www.gnu.org/licenses/
55 * or write to the Free Software Foundation, Inc., 51 Franklin Street,
56 * Fifth Floor, Boston, MA 02110-1301, USA.
57 *
58 */
59
60#ifndef WHITEBOARD_POSTER_STRING_CONVERSION
61#define WHITEBOARD_POSTER_STRING_CONVERSION
62#endif // WHITEBOARD_POSTER_STRING_CONVERSION
63
65#include <stdio.h>
66#include <string.h>
67#include <stdlib.h>
68#include <ctype.h>
69#include <limits.h>
70
71/* Network byte order functions */
72#pragma clang diagnostic push
73#pragma clang diagnostic ignored "-Wunused-macros"
74#if defined(__linux)
75# include <endian.h>
76# include <byteswap.h>
77#elif defined(__APPLE__)
78# include <machine/endian.h> //Needed for __BYTE_ORDER
79# include <architecture/byte_order.h> //Needed for byte swap functions
80# define bswap_16(x) NXSwapShort(x)
81# define bswap_32(x) NXSwapInt(x)
82# define bswap_64(x) NXSwapLongLong(x)
83#elif defined(ESP8266)
84# define bswap_16(x) __builtin_bswap16(x)
85# define bswap_32(x) __builtin_bswap32(x)
86# define bswap_64(x) __builtin_bswap64(x)
87#else
88 //Manually define swap macros?
89#endif
90
91#if (!defined(__BYTE_ORDER) && !defined(__LITTLE_ENDIAN)) || (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN)
92# if !defined(htonll) && !defined(ntohll)
93# define htonll(x) bswap_64(x)
94# define ntohll(x) bswap_64(x)
95# endif
96# if !defined(htonl) && !defined(ntohl)
97# define htonl(x) bswap_32(x)
98# define ntohl(x) bswap_32(x)
99# endif
100# if !defined(htons) && !defined(ntohs)
101# define htons(x) bswap_16(x)
102# define ntohs(x) bswap_16(x)
103# endif
104#else
105# if !defined(htonll) && !defined(ntohll)
106# define htonll(x) (x)
107# define ntohll(x) (x)
108# endif
109# if !defined(htonl) && !defined(ntohl)
110# define htonl(x) (x)
111# define ntohl(x) (x)
112# endif
113# if !defined(htons) && !defined(ntohs)
114# define htons(x) (x)
115# define ntohs(x) (x)
116# endif
117#endif
118#pragma clang diagnostic pop
119
120
121
125const char* wb_memory_image_control_status_description(const struct wb_memory_image_control_status* self, char* descString, size_t bufferSize)
126{
127#pragma clang diagnostic push
128#pragma clang diagnostic ignored "-Wunused-variable"
129 size_t len = 0;
130 if (len >= bufferSize) {
131 return descString;
132 }
133 len += snprintf(descString + len, bufferSize - len, "res_width=%u", self->res_width);
134 if (len >= bufferSize) {
135 return descString;
136 }
137 len = gu_strlcat(descString, ", ", bufferSize);
138 if (len >= bufferSize) {
139 return descString;
140 }
141 len += snprintf(descString + len, bufferSize - len, "res_height=%u", self->res_height);
142 if (len >= bufferSize) {
143 return descString;
144 }
145 len = gu_strlcat(descString, ", ", bufferSize);
146 if (len >= bufferSize) {
147 return descString;
148 }
149 switch (self->pixelFormat) {
150 case MI_BGRA:
151 {
152 len += snprintf(descString + len, bufferSize - len, "pixelFormat=MI_BGRA");
153 break;
154 }
155 case MI_RGBA:
156 {
157 len += snprintf(descString + len, bufferSize - len, "pixelFormat=MI_RGBA");
158 break;
159 }
160 case MI_UYV422:
161 {
162 len += snprintf(descString + len, bufferSize - len, "pixelFormat=MI_UYV422");
163 break;
164 }
165 }
166 return descString;
167#pragma clang diagnostic pop
168}
169
173const char* wb_memory_image_control_status_to_string(const struct wb_memory_image_control_status* self, char* toString, size_t bufferSize)
174{
175#pragma clang diagnostic push
176#pragma clang diagnostic ignored "-Wunused-variable"
177 size_t len = 0;
178 if (len >= bufferSize) {
179 return toString;
180 }
181 len += snprintf(toString + len, bufferSize - len, "%u", self->res_width);
182 if (len >= bufferSize) {
183 return toString;
184 }
185 len = gu_strlcat(toString, ", ", bufferSize);
186 if (len >= bufferSize) {
187 return toString;
188 }
189 len += snprintf(toString + len, bufferSize - len, "%u", self->res_height);
190 if (len >= bufferSize) {
191 return toString;
192 }
193 len = gu_strlcat(toString, ", ", bufferSize);
194 if (len >= bufferSize) {
195 return toString;
196 }
197 switch (self->pixelFormat) {
198 case MI_BGRA:
199 {
200 len += snprintf(toString + len, bufferSize - len, "MI_BGRA");
201 break;
202 }
203 case MI_RGBA:
204 {
205 len += snprintf(toString + len, bufferSize - len, "MI_RGBA");
206 break;
207 }
208 case MI_UYV422:
209 {
210 len += snprintf(toString + len, bufferSize - len, "MI_UYV422");
211 break;
212 }
213 }
214 return toString;
215#pragma clang diagnostic pop
216}
217
222{
223 size_t temp_length = strlen(str);
224 int length = (temp_length <= INT_MAX) ? ((int)((ssize_t)temp_length)) : -1;
225 if (length < 1 || length > MEMORY_IMAGE_CONTROL_STATUS_DESC_BUFFER_SIZE) {
226 return self;
227 }
228 char var_str_buffer[MEMORY_IMAGE_CONTROL_STATUS_DESC_BUFFER_SIZE + 1];
229 char* var_str = &var_str_buffer[0];
230 char key_buffer[12];
231 char* key = &key_buffer[0];
232 int bracecount = 0;
233 int startVar = 0;
234 int index = 0;
235 int startKey = 0;
236 int endKey = -1;
237 int varIndex = 0;
238 if (index == 0 && str[0] == '{') {
239 index = 1;
240 }
241 startVar = index;
242 startKey = startVar;
243 do {
244 for (int i = index; i < length; i++) {
245 index = i + 1;
246 if (bracecount == 0 && str[i] == '=') {
247 endKey = i - 1;
248 startVar = index;
249 continue;
250 }
251 if (bracecount == 0 && isspace(str[i])) {
252 startVar = index;
253 if (endKey == -1) {
254 startKey = index;
255 }
256 continue;
257 }
258 if (bracecount == 0 && str[i] == ',') {
259 index = i - 1;
260 break;
261 }
262 if (str[i] == '{') {
263 bracecount++;
264 continue;
265 }
266 if (str[i] == '}') {
267 bracecount--;
268 if (bracecount < 0) {
269 index = i - 1;
270 break;
271 }
272 }
273 if (i == length - 1) {
274 index = i;
275 }
276 }
277 if (endKey >= startKey && endKey - startKey < length) {
278 strncpy(key, str + startKey, ((size_t)(endKey - startKey) + 1));
279 key[(endKey - startKey) + 1] = 0;
280 } else {
281 key[0] = 0;
282 }
283 strncpy(var_str, str + startVar, ((size_t)(index - startVar) + 1));
284 var_str[(index - startVar) + 1] = 0;
285 bracecount = 0;
286 index += 2;
287 startVar = index;
288 startKey = startVar;
289 endKey = -1;
290 if (strlen(key) > 0) {
291 if (0 == strcmp("res_width", key)) {
292 varIndex = 0;
293 } else if (0 == strcmp("res_height", key)) {
294 varIndex = 1;
295 } else if (0 == strcmp("pixelFormat", key)) {
296 varIndex = 2;
297 } else {
298 varIndex = -1;
299 }
300 }
301 switch (varIndex) {
302 case -1: { break; }
303 case 0:
304 {
305 self->res_width = ((uint16_t)atoi(var_str));
306 break;
307 }
308 case 1:
309 {
310 self->res_height = ((uint16_t)atoi(var_str));
311 break;
312 }
313 case 2:
314 {
315 if (strcmp("MI_BGRA", var_str) == 0) {
316#pragma clang diagnostic push
317#pragma clang diagnostic ignored "-Wbad-function-cast"
318 self->pixelFormat = MI_BGRA;
319#pragma clang diagnostic pop
320 } else if (strcmp("MI_RGBA", var_str) == 0) {
321#pragma clang diagnostic push
322#pragma clang diagnostic ignored "-Wbad-function-cast"
323 self->pixelFormat = MI_RGBA;
324#pragma clang diagnostic pop
325 } else if (strcmp("MI_UYV422", var_str) == 0) {
326#pragma clang diagnostic push
327#pragma clang diagnostic ignored "-Wbad-function-cast"
328 self->pixelFormat = MI_UYV422;
329#pragma clang diagnostic pop
330 } else {
331#pragma clang diagnostic push
332#pragma clang diagnostic ignored "-Wbad-function-cast"
333 self->pixelFormat = ((enum MemoryImagePixelFormat)atoi(var_str));
334#pragma clang diagnostic pop
335 }
336 break;
337 }
338 }
339 if (varIndex >= 0) {
340 varIndex++;
341 }
342 } while(index < length);
343 return self;
344}
345
346/*#ifdef WHITEBOARD_SERIALISATION*/
347
352{
353 uint16_t bit_offset = 0;
354 uint16_t res_width_nbo = htons(self->res_width);
355 do {
356 int8_t b;
357 for (b = (16 - 1); b >= 0; b--) {
358 do {
359 uint16_t byte = bit_offset / 8;
360 uint16_t bit = 7 - (bit_offset % 8);
361 unsigned long newbit = !!((res_width_nbo >> b) & 1U);
362 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
363 bit_offset = bit_offset + 1;
364 } while(false);
365 }
366 } while(false);
367
368 uint16_t res_height_nbo = htons(self->res_height);
369 do {
370 int8_t b;
371 for (b = (16 - 1); b >= 0; b--) {
372 do {
373 uint16_t byte = bit_offset / 8;
374 uint16_t bit = 7 - (bit_offset % 8);
375 unsigned long newbit = !!((res_height_nbo >> b) & 1U);
376 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
377 bit_offset = bit_offset + 1;
378 } while(false);
379 }
380 } while(false);
381
382 enum MemoryImagePixelFormat pixelFormat_nbo = htonl(self->pixelFormat);
383 do {
384 int8_t b;
385 for (b = (32 - 1); b >= 0; b--) {
386 do {
387 uint16_t byte = bit_offset / 8;
388 uint16_t bit = 7 - (bit_offset % 8);
389 unsigned long newbit = !!((pixelFormat_nbo >> b) & 1U);
390 dst[byte] ^= (-newbit ^ dst[byte]) & (1UL << bit);
391 bit_offset = bit_offset + 1;
392 } while(false);
393 }
394 } while(false);
395 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
396 (void)self;
397 (void)dst;
398 return bit_offset;
399}
400
405{
406 uint16_t bit_offset = 0;
407 do {
408 int8_t b;
409 for (b = (16 - 1); b >= 0; b--) {
410 do {
411 uint16_t byte = bit_offset / 8;
412 uint16_t bit = 7 - (bit_offset % 8);
413 char dataByte = src[byte];
414 unsigned char bitValue = (dataByte >> bit) & 1U;
415 dst->res_width ^= (-bitValue ^ dst->res_width) & (1UL << b);
416 bit_offset = bit_offset + 1;
417 } while(false);
418 }
419 } while(false);
420 dst->res_width = ntohs(dst->res_width);
421
422 do {
423 int8_t b;
424 for (b = (16 - 1); b >= 0; b--) {
425 do {
426 uint16_t byte = bit_offset / 8;
427 uint16_t bit = 7 - (bit_offset % 8);
428 char dataByte = src[byte];
429 unsigned char bitValue = (dataByte >> bit) & 1U;
430 dst->res_height ^= (-bitValue ^ dst->res_height) & (1UL << b);
431 bit_offset = bit_offset + 1;
432 } while(false);
433 }
434 } while(false);
435 dst->res_height = ntohs(dst->res_height);
436
437 do {
438 int8_t b;
439 for (b = (32 - 1); b >= 0; b--) {
440 do {
441 uint16_t byte = bit_offset / 8;
442 uint16_t bit = 7 - (bit_offset % 8);
443 char dataByte = src[byte];
444 unsigned char bitValue = (dataByte >> bit) & 1U;
445 dst->pixelFormat ^= (-bitValue ^ dst->pixelFormat) & (1UL << b);
446 bit_offset = bit_offset + 1;
447 } while(false);
448 }
449 } while(false);
450 dst->pixelFormat = ntohl(dst->pixelFormat);
451 //avoid unused variable warnings when you try to use an empty gen file or a gen file with no supported serialisation types.
452 (void)src;
453 (void)dst;
454 return bit_offset;
455}
456
457/*#endif // WHITEBOARD_SERIALISATION*/
WHITEBOARD_POSTER_STRING_CONVERSION.
uint16_t res_height
The resolution height.
enum MemoryImagePixelFormat pixelFormat
The pixel format of the images.
const char * wb_memory_image_control_status_to_string(const struct wb_memory_image_control_status *self, char *toString, size_t bufferSize)
Convert to a string.
size_t wb_memory_image_control_status_from_network_serialised(const char *src, struct wb_memory_image_control_status *dst)
Convert from a compressed, serialised, network byte order byte stream.
const char * wb_memory_image_control_status_description(const struct wb_memory_image_control_status *self, char *descString, size_t bufferSize)
Convert to a description string.
#define htons(x)
size_t wb_memory_image_control_status_to_network_serialised(const struct wb_memory_image_control_status *self, char *dst)
Convert to a compressed, serialised, network byte order byte stream.
#define ntohl(x)
#define ntohs(x)
#define htonl(x)
struct wb_memory_image_control_status * wb_memory_image_control_status_from_string(struct wb_memory_image_control_status *self, const char *str)
Convert from a string.
#define MEMORY_IMAGE_CONTROL_STATUS_DESC_BUFFER_SIZE