1 /* Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Library General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) any later version.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Library General Public License for more details.
13 * You should have received a copy of the GNU Library General Public
14 * License along with this library; if not, write to the
15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
16 * Boston, MA 02111-1307, USA.
18 #ifndef __SPARROW_SPARROW_H__
19 #define __SPARROW_SPARROW_H__
22 #include "gstsparrow.h"
23 #include "sparrow_false_colour_lut.h"
24 #include "sparrow_gamma_lut.h"
27 void INVISIBLE
sparrow_rotate_history(GstSparrow
*sparrow
, GstBuffer
*inbuf
);
28 void INVISIBLE
sparrow_pre_init(GstSparrow
*sparrow
);
29 gboolean INVISIBLE
sparrow_init(GstSparrow
*sparrow
, GstCaps
*incaps
, GstCaps
*outcaps
);
30 void INVISIBLE
sparrow_transform(GstSparrow
*sparrow
, guint8
*in
, guint8
*out
);
31 void INVISIBLE
sparrow_finalise(GstSparrow
*sparrow
);
34 #define SPARROW_CALIBRATE_ON 1
37 #define CALIBRATE_WAIT_SIGNAL_THRESHOLD 32
41 /*memory allocation */
43 static inline __attribute__((malloc
)) UNUSED
void *
44 malloc_or_die(size_t size
){
45 void *p
= malloc(size
);
47 GST_ERROR("malloc would not allocate %u bytes! seriously!\n", size
);
53 static inline __attribute__((malloc
)) UNUSED
void *
54 malloc_aligned_or_die(size_t size
){
56 int err
= posix_memalign(&mem
, ALIGNMENT
, size
);
58 GST_ERROR("posix_memalign returned %d trying to allocate %u bytes aligned on %u byte boundaries\n",
59 err
, size
, ALIGNMENT
);
65 static inline __attribute__((malloc
)) UNUSED
void *
66 zalloc_aligned_or_die(size_t size
){
67 void *mem
= malloc_aligned_or_die(size
);
74 static inline UNUSED guint32
75 rng_uniform_int(GstSparrow
*sparrow
, guint32 limit
){
76 double d
= dsfmt_genrand_close_open(sparrow
->dsfmt
);
77 double d2
= d
* limit
;
78 guint32 i
= (guint32
)d2
;
82 static inline UNUSED
double
83 rng_uniform_double(GstSparrow
*sparrow
, double limit
){
84 return dsfmt_genrand_close_open(sparrow
->dsfmt
) * limit
;
87 #define rng_uniform(sparrow) dsfmt_genrand_close_open((sparrow)->dsfmt)
89 #define RANDINT(sparrow, start, end)((start) + rng_uniform_int(sparrow, (end) - (start)))
92 #define DISASTEROUS_CRASH(msg) GST_ERROR("DISASTER: %s\n%-25s line %4d \n", (msg), __func__, __LINE__);
97 popcount64(guint64 x64
)
99 guint32 x
= x64
& (guint32
)-1;
100 guint32 y
= x64
>> 32;
101 x
= x
- ((x
>> 1) & 0x55555555);
102 y
= y
- ((y
>> 1) & 0x55555555);
103 x
= (x
& 0x33333333) + ((x
>> 2) & 0x33333333);
104 y
= (y
& 0x33333333) + ((y
>> 2) & 0x33333333);
105 x
= (x
+ (x
>> 4)) & 0x0F0F0F0F;
106 y
= (y
+ (y
>> 4)) & 0x0F0F0F0F;
111 return (x
+ y
) & 0x000000FF;
114 static inline guint32
115 hamming_distance64(guint64 a
, guint64 b
, guint64 mask
){
118 /* count where the two differ */
119 return popcount64(a
^ b
);
122 #endif /* __SPARROW_SPARROW_H__ */