~registry/libfprint/master

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
/* GStreamer
 * Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
 *                    2000 Wim Taymans <wtay@chello.be>
 *                    2002 Thomas Vander Stichele <thomas@apestaart.org>
 *
 * gstutils.h: Header for various utility functions
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#pragma once

#include <glib.h>

G_BEGIN_DECLS

/* Define PUT and GET functions for unaligned memory */
#define _FP_GET(__data, __idx, __size, __shift) \
    (((guint##__size) (((const guint8 *) (__data))[__idx])) << (__shift))

#define _FP_PUT(__data, __idx, __size, __shift, __num) \
    (((guint8 *) (__data))[__idx] = (((guint##__size) (__num)) >> (__shift)) & 0xff)

#ifndef __GTK_DOC_IGNORE__

/**
 * FP_READ_UINT64_BE:
 * @data: memory location
 *
 * Read a 64 bit unsigned integer value in big endian format from the memory buffer.
 */

/**
 * FP_READ_UINT64_LE:
 * @data: memory location
 *
 * Read a 64 bit unsigned integer value in little endian format from the memory buffer.
 */
#define _FP_READ_UINT64_BE(data)	(_FP_GET (data, 0, 64, 56) | \
					 _FP_GET (data, 1, 64, 48) | \
					 _FP_GET (data, 2, 64, 40) | \
					 _FP_GET (data, 3, 64, 32) | \
					 _FP_GET (data, 4, 64, 24) | \
					 _FP_GET (data, 5, 64, 16) | \
					 _FP_GET (data, 6, 64,  8) | \
					 _FP_GET (data, 7, 64,  0))

#define _FP_READ_UINT64_LE(data)	(_FP_GET (data, 7, 64, 56) | \
					 _FP_GET (data, 6, 64, 48) | \
					 _FP_GET (data, 5, 64, 40) | \
					 _FP_GET (data, 4, 64, 32) | \
					 _FP_GET (data, 3, 64, 24) | \
					 _FP_GET (data, 2, 64, 16) | \
					 _FP_GET (data, 1, 64,  8) | \
					 _FP_GET (data, 0, 64,  0))

#define FP_READ_UINT64_BE(data) _fpi_slow_read64_be((const guint8 *)(data))
static inline guint64 _fpi_slow_read64_be (const guint8 * data) {
  return _FP_READ_UINT64_BE (data);
}
#define FP_READ_UINT64_LE(data) _fpi_slow_read64_le((const guint8 *)(data))
static inline guint64 _fpi_slow_read64_le (const guint8 * data) {
  return _FP_READ_UINT64_LE (data);
}

/**
 * FP_READ_UINT32_BE:
 * @data: memory location
 *
 * Read a 32 bit unsigned integer value in big endian format from the memory buffer.
 */

/**
 * FP_READ_UINT32_LE:
 * @data: memory location
 *
 * Read a 32 bit unsigned integer value in little endian format from the memory buffer.
 */
#define _FP_READ_UINT32_BE(data)	(_FP_GET (data, 0, 32, 24) | \
					 _FP_GET (data, 1, 32, 16) | \
					 _FP_GET (data, 2, 32,  8) | \
					 _FP_GET (data, 3, 32,  0))

#define _FP_READ_UINT32_LE(data)	(_FP_GET (data, 3, 32, 24) | \
					 _FP_GET (data, 2, 32, 16) | \
					 _FP_GET (data, 1, 32,  8) | \
					 _FP_GET (data, 0, 32,  0))

#define FP_READ_UINT32_BE(data) _fpi_slow_read32_be((const guint8 *)(data))
static inline guint32 _fpi_slow_read32_be (const guint8 * data) {
  return _FP_READ_UINT32_BE (data);
}
#define FP_READ_UINT32_LE(data) _fpi_slow_read32_le((const guint8 *)(data))
static inline guint32 _fpi_slow_read32_le (const guint8 * data) {
  return _FP_READ_UINT32_LE (data);
}

/**
 * FP_READ_UINT24_BE:
 * @data: memory location
 *
 * Read a 24 bit unsigned integer value in big endian format from the memory buffer.
 */
#define _FP_READ_UINT24_BE(data)       (_FP_GET (data, 0, 32, 16) | \
                                         _FP_GET (data, 1, 32,  8) | \
                                         _FP_GET (data, 2, 32,  0))

#define FP_READ_UINT24_BE(data) _fpi_slow_read24_be((const guint8 *)(data))
static inline guint32 _fpi_slow_read24_be (const guint8 * data) {
  return _FP_READ_UINT24_BE (data);
}

/**
 * FP_READ_UINT24_LE:
 * @data: memory location
 *
 * Read a 24 bit unsigned integer value in little endian format from the memory buffer.
 */
#define _FP_READ_UINT24_LE(data)       (_FP_GET (data, 2, 32, 16) | \
                                         _FP_GET (data, 1, 32,  8) | \
                                         _FP_GET (data, 0, 32,  0))

#define FP_READ_UINT24_LE(data) _fpi_slow_read24_le((const guint8 *)(data))
static inline guint32 _fpi_slow_read24_le (const guint8 * data) {
  return _FP_READ_UINT24_LE (data);
}

/**
 * FP_READ_UINT16_BE:
 * @data: memory location
 *
 * Read a 16 bit unsigned integer value in big endian format from the memory buffer.
 */
/**
 * FP_READ_UINT16_LE:
 * @data: memory location
 *
 * Read a 16 bit unsigned integer value in little endian format from the memory buffer.
 */
#define _FP_READ_UINT16_BE(data)	(_FP_GET (data, 0, 16,  8) | \
					 _FP_GET (data, 1, 16,  0))

#define _FP_READ_UINT16_LE(data)	(_FP_GET (data, 1, 16,  8) | \
					 _FP_GET (data, 0, 16,  0))

#define FP_READ_UINT16_BE(data) _fpi_slow_read16_be((const guint8 *)(data))
static inline guint16 _fpi_slow_read16_be (const guint8 * data) {
  return _FP_READ_UINT16_BE (data);
}
#define FP_READ_UINT16_LE(data) _fpi_slow_read16_le((const guint8 *)(data))
static inline guint16 _fpi_slow_read16_le (const guint8 * data) {
  return _FP_READ_UINT16_LE (data);
}

/**
 * FP_READ_UINT8:
 * @data: memory location
 *
 * Read an 8 bit unsigned integer value from the memory buffer.
 */
#define FP_READ_UINT8(data)            (_FP_GET (data, 0,  8,  0))

/**
 * FP_WRITE_UINT64_BE:
 * @data: memory location
 * @val: value to store
 *
 * Store a 64 bit unsigned integer value in big endian format into the memory buffer.
 */
/**
 * FP_WRITE_UINT64_LE:
 * @data: memory location
 * @val: value to store
 *
 * Store a 64 bit unsigned integer value in little endian format into the memory buffer.
 */
#define FP_WRITE_UINT64_BE(data,val)   do { \
                                          gpointer __put_data = data; \
                                          guint64 __put_val = val; \
                                          _FP_PUT (__put_data, 0, 64, 56, __put_val); \
                                          _FP_PUT (__put_data, 1, 64, 48, __put_val); \
                                          _FP_PUT (__put_data, 2, 64, 40, __put_val); \
                                          _FP_PUT (__put_data, 3, 64, 32, __put_val); \
                                          _FP_PUT (__put_data, 4, 64, 24, __put_val); \
                                          _FP_PUT (__put_data, 5, 64, 16, __put_val); \
                                          _FP_PUT (__put_data, 6, 64,  8, __put_val); \
                                          _FP_PUT (__put_data, 7, 64,  0, __put_val); \
                                        } while (0)

#define FP_WRITE_UINT64_LE(data,val)   do { \
                                          gpointer __put_data = data; \
                                          guint64 __put_val = val; \
                                          _FP_PUT (__put_data, 0, 64,  0, __put_val); \
                                          _FP_PUT (__put_data, 1, 64,  8, __put_val); \
                                          _FP_PUT (__put_data, 2, 64, 16, __put_val); \
                                          _FP_PUT (__put_data, 3, 64, 24, __put_val); \
                                          _FP_PUT (__put_data, 4, 64, 32, __put_val); \
                                          _FP_PUT (__put_data, 5, 64, 40, __put_val); \
                                          _FP_PUT (__put_data, 6, 64, 48, __put_val); \
                                          _FP_PUT (__put_data, 7, 64, 56, __put_val); \
                                        } while (0)

/**
 * FP_WRITE_UINT32_BE:
 * @data: memory location
 * @val: value to store
 *
 * Store a 32 bit unsigned integer value in big endian format into the memory buffer.
 */
/**
 * FP_WRITE_UINT32_LE:
 * @data: memory location
 * @val: value to store
 *
 * Store a 32 bit unsigned integer value in little endian format into the memory buffer.
 */
#define FP_WRITE_UINT32_BE(data,val)   do { \
                                          gpointer __put_data = data; \
                                          guint32 __put_val = val; \
                                          _FP_PUT (__put_data, 0, 32, 24, __put_val); \
                                          _FP_PUT (__put_data, 1, 32, 16, __put_val); \
                                          _FP_PUT (__put_data, 2, 32,  8, __put_val); \
                                          _FP_PUT (__put_data, 3, 32,  0, __put_val); \
                                        } while (0)

#define FP_WRITE_UINT32_LE(data,val)   do { \
                                          gpointer __put_data = data; \
                                          guint32 __put_val = val; \
                                          _FP_PUT (__put_data, 0, 32,  0, __put_val); \
                                          _FP_PUT (__put_data, 1, 32,  8, __put_val); \
                                          _FP_PUT (__put_data, 2, 32, 16, __put_val); \
                                          _FP_PUT (__put_data, 3, 32, 24, __put_val); \
                                        } while (0)

/**
 * FP_WRITE_UINT24_BE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 24 bit unsigned integer value in big endian format into the memory buffer.
 */
#define FP_WRITE_UINT24_BE(data, num)  do { \
                                          gpointer __put_data = data; \
                                          guint32 __put_val = num; \
                                          _FP_PUT (__put_data, 0, 32,  16, __put_val); \
                                          _FP_PUT (__put_data, 1, 32,  8, __put_val); \
                                          _FP_PUT (__put_data, 2, 32,  0, __put_val); \
                                        } while (0)

/**
 * FP_WRITE_UINT24_LE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 24 bit unsigned integer value in little endian format into the memory buffer.
 */
#define FP_WRITE_UINT24_LE(data, num)  do { \
                                          gpointer __put_data = data; \
                                          guint32 __put_val = num; \
                                          _FP_PUT (__put_data, 0, 32,  0, __put_val); \
                                          _FP_PUT (__put_data, 1, 32,  8, __put_val); \
                                          _FP_PUT (__put_data, 2, 32,  16, __put_val); \
                                        } while (0)

/**
 * FP_WRITE_UINT16_BE:
 * @data: memory location
 * @val: value to store
 *
 * Store a 16 bit unsigned integer value in big endian format into the memory buffer.
 */
/**
 * FP_WRITE_UINT16_LE:
 * @data: memory location
 * @val: value to store
 *
 * Store a 16 bit unsigned integer value in little endian format into the memory buffer.
 */
#define FP_WRITE_UINT16_BE(data,val)   do { \
                                          gpointer __put_data = data; \
                                          guint16 __put_val = val; \
                                          _FP_PUT (__put_data, 0, 16,  8, __put_val); \
                                          _FP_PUT (__put_data, 1, 16,  0, __put_val); \
                                        } while (0)

#define FP_WRITE_UINT16_LE(data,val)   do { \
                                          gpointer __put_data = data; \
                                          guint16 __put_val = val; \
                                          _FP_PUT (__put_data, 0, 16,  0, __put_val); \
                                          _FP_PUT (__put_data, 1, 16,  8, __put_val); \
                                        } while (0)

/**
 * FP_WRITE_UINT8:
 * @data: memory location
 * @num: value to store
 *
 * Store an 8 bit unsigned integer value into the memory buffer.
 */
#define FP_WRITE_UINT8(data, num)      do { \
                                          _FP_PUT (data, 0,  8,  0, num); \
                                        } while (0)

/* Float endianness conversion macros */

/**
 * FP_READ_FLOAT_LE:
 * @data: memory location
 *
 * Read a 32 bit float value in little endian format from the memory buffer.
 *
 * Returns: The floating point value read from @data
 */
static inline gfloat
FP_READ_FLOAT_LE(const guint8 *data)
{
  union
  {
    guint32 i;
    gfloat f;
  } u;

  u.i = FP_READ_UINT32_LE (data);
  return u.f;
}

/**
 * FP_READ_FLOAT_BE:
 * @data: memory location
 *
 * Read a 32 bit float value in big endian format from the memory buffer.
 *
 * Returns: The floating point value read from @data
 */
static inline gfloat
FP_READ_FLOAT_BE(const guint8 *data)
{
  union
  {
    guint32 i;
    gfloat f;
  } u;

  u.i = FP_READ_UINT32_BE (data);
  return u.f;
}

/**
 * FP_READ_DOUBLE_LE:
 * @data: memory location
 *
 * Read a 64 bit double value in little endian format from the memory buffer.
 *
 * Returns: The double-precision floating point value read from @data
 */
static inline gdouble
FP_READ_DOUBLE_LE(const guint8 *data)
{
  union
  {
    guint64 i;
    gdouble d;
  } u;

  u.i = FP_READ_UINT64_LE (data);
  return u.d;
}

/**
 * FP_READ_DOUBLE_BE:
 * @data: memory location
 *
 * Read a 64 bit double value in big endian format from the memory buffer.
 *
 * Returns: The double-precision floating point value read from @data
 */
static inline gdouble
FP_READ_DOUBLE_BE(const guint8 *data)
{
  union
  {
    guint64 i;
    gdouble d;
  } u;

  u.i = FP_READ_UINT64_BE (data);
  return u.d;
}

/**
 * FP_WRITE_FLOAT_LE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 32 bit float value in little endian format into the memory buffer.
 */
static inline void
FP_WRITE_FLOAT_LE(guint8 *data, gfloat num)
{
  union
  {
    guint32 i;
    gfloat f;
  } u;

  u.f = num;
  FP_WRITE_UINT32_LE (data, u.i);
}

/**
 * FP_WRITE_FLOAT_BE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 32 bit float value in big endian format into the memory buffer.
 */
static inline void
FP_WRITE_FLOAT_BE(guint8 *data, gfloat num)
{
  union
  {
    guint32 i;
    gfloat f;
  } u;

  u.f = num;
  FP_WRITE_UINT32_BE (data, u.i);
}

/**
 * FP_WRITE_DOUBLE_LE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 64 bit double value in little endian format into the memory buffer.
 */
static inline void
FP_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
{
  union
  {
    guint64 i;
    gdouble d;
  } u;

  u.d = num;
  FP_WRITE_UINT64_LE (data, u.i);
}

/**
 * FP_WRITE_DOUBLE_BE:
 * @data: memory location
 * @num: value to store
 *
 * Store a 64 bit double value in big endian format into the memory buffer.
 */
static inline void
FP_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
{
  union
  {
    guint64 i;
    gdouble d;
  } u;

  u.d = num;
  FP_WRITE_UINT64_BE (data, u.i);
}

G_END_DECLS

#endif /* __GTK_DOC_IGNORE__ */