found a helper function for dataless ipl images; use it
[sparrow.git] / gstsparrow.h
blob04986a1861b21cbfdf8e482aeb01aba1b93c791d
1 /* GStreamer
2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3 * Copyright (C) <2003> David Schleef <ds@schleef.org>
4 * Copyright (C) <2003> Arwed v. Merkatz <v.merkatz@gmx.net>
5 * Copyright (C) <2006> Mark Nauwelaerts <manauw@skynet.be>
6 * Copyright (C) <2010> Douglas Bagnall <douglas@halo.gen.nz>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
25 #ifndef __GST_VIDEO_SPARROW_H__
26 #define __GST_VIDEO_SPARROW_H__
28 #include <gst/video/gstvideofilter.h>
29 #include <sys/time.h>
31 G_BEGIN_DECLS
32 #define GST_TYPE_SPARROW \
33 (gst_sparrow_get_type())
34 #define GST_SPARROW(obj) \
35 (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPARROW,GstSparrow))
36 #define GST_SPARROW_CLASS(klass) \
37 (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPARROW,GstSparrowClass))
38 #define GST_IS_SPARROW(obj) \
39 (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPARROW))
40 #define GST_IS_SPARROW_CLASS(klass) \
41 (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPARROW))
46 #define SPARROW_PPM_DEBUG 1
47 #define USE_SPARSE_MAP 1
49 #define TIMER_LOG_FILE "/tmp/timer.log"
51 #include "sparrowconfig.h"
52 #include "dSFMT/dSFMT.h"
53 #include "cv.h"
55 #ifndef UNUSED
56 #define UNUSED __attribute__ ((unused))
57 #else
58 #warning UNUSED is set
59 #endif
61 /* the common recommendation for function visibility is to default to 'hidden'
62 and specifically mark the unhidden ('default') ones, but this might muck
63 with gstreamer macros, some of which declare functions, and most sparrow
64 functions are static anyway, so it is simpler to whitelist visibility.
66 http://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html#index-fvisibility-2135
68 (actually, it seems like all functions are invisible or static, except the
69 ones that gstreamer makes in macros).
71 #ifndef INVISIBLE
72 #define INVISIBLE __attribute__ ((visibility("hidden")))
73 #else
74 #warning INVISIBLE is set
75 #endif
78 typedef guint32 pix_t;
79 #define PIXSIZE (sizeof(pix_t))
81 #define SPARROW_N_IPL_IN 3
83 #define FAKE_OTHER_PROJECTION 1
86 #define LINE_PERIOD 16
91 typedef enum {
92 SPARROW_STATUS_QUO = 0,
93 SPARROW_INIT,
94 SPARROW_FIND_SELF,
95 SPARROW_FIND_SCREEN,
96 SPARROW_FIND_EDGES,
97 SPARROW_PLAY,
100 SPARROW_NEXT_STATE /*magical last state: alias for next in sequence */
101 } sparrow_state;
103 typedef enum {
104 SPARROW_WHITE = 0,
105 SPARROW_GREEN,
106 SPARROW_MAGENTA,
108 SPARROW_LAST_COLOUR
109 } sparrow_colour;
112 typedef struct sparrow_format_s {
113 gint32 width;
114 gint32 height;
115 guint32 pixcount;
116 guint32 size;
118 guint32 rshift;
119 guint32 gshift;
120 guint32 bshift;
121 guint32 rmask;
122 guint32 gmask;
123 guint32 bmask;
124 guint32 colours[3];
125 } sparrow_format;
128 typedef enum sparrow_axis_s {
129 SPARROW_HORIZONTAL,
130 SPARROW_VERTICAL,
131 } sparrow_axis_t;
134 /* a mesh of these contains the mapping from input to output.
135 stored in a fixed point notation.
137 #define SPARROW_FIXED_POINT 8
139 typedef struct sparrow_map_point_s {
140 int x;
141 int y;
142 int dx;
143 int dy;
144 }sparrow_map_point_t;
146 typedef struct sparrow_map_row_s {
147 int start;
148 int end;
149 sparrow_map_point_t *points;
150 }sparrow_map_row_t;
152 typedef struct sparrow_map_s {
153 sparrow_map_row_t *rows;
154 void *point_mem;
155 }sparrow_map_t;
157 typedef struct sparrow_map_lut_s{
158 guint16 x;
159 guint16 y;
160 } sparrow_map_lut_t;
163 typedef struct _GstSparrow GstSparrow;
164 typedef struct _GstSparrowClass GstSparrowClass;
167 * GstSparrow:
169 * Opaque data structure.
171 struct _GstSparrow
173 GstVideoFilter videofilter;
175 sparrow_format in;
176 sparrow_format out;
178 /*some calibration modes have big unwieldy structs that attach here */
179 void *helper_struct;
181 /* properties / command line options */
182 gboolean debug;
183 gboolean use_timer;
184 gint calibrate_flag; /*whether to calibrate */
185 guint32 rng_seed;
187 /* misc */
188 dsfmt_t *dsfmt; /*rng*/
190 /*state */
191 sparrow_state state;
192 gint32 countdown; /*intra-state timing*/
194 /*buffer pointers for previous frames */
195 guint8 *in_frame;
196 guint8 *prev_frame;
197 guint8 *work_frame;
198 guint8 *debug_frame;
200 GstBuffer *in_buffer;
201 GstBuffer *prev_buffer;
202 /*don't need work_buffer */
204 guint32 colour;
205 guint32 frame_count;
207 const char *reload;
208 const char *save;
210 /*debug timer */
211 struct timeval timer_start;
212 struct timeval timer_stop;
213 FILE * timer_log;
215 /*calibration results */
216 guint32 lag;
217 guint8 *screenmask;
218 sparrow_map_t map;
219 /*full sized LUT */
220 sparrow_map_lut_t *map_lut;
224 struct _GstSparrowClass
226 GstVideoFilterClass parent_class;
229 GType gst_sparrow_get_type(void);
232 GST_DEBUG_CATEGORY_EXTERN (sparrow_debug);
233 #define GST_CAT_DEFAULT sparrow_debug
235 /* GstSparrow signals and args */
236 enum
238 /* FILL ME */
239 LAST_SIGNAL
242 enum
244 PROP_0,
245 PROP_CALIBRATE,
246 PROP_DEBUG,
247 PROP_TIMER,
248 PROP_RNG_SEED,
249 PROP_COLOUR,
250 PROP_RELOAD,
251 PROP_SAVE
254 #define DEFAULT_PROP_CALIBRATE TRUE
255 #define DEFAULT_PROP_DEBUG FALSE
256 #define DEFAULT_PROP_TIMER FALSE
257 #define DEFAULT_PROP_RNG_SEED -1
258 #define DEFAULT_PROP_COLOUR SPARROW_GREEN
259 #define DEFAULT_PROP_RELOAD ""
260 #define DEFAULT_PROP_SAVE ""
262 #define QUOTE_(x) #x
263 #define QUOTE(x) QUOTE_(x)
265 /*timing utility code */
266 #define TIME_TRANSFORM 1
268 #define TIMER_START(sparrow) do{ \
269 if (sparrow->timer_log){ \
270 if ((sparrow)->timer_start.tv_sec){ \
271 GST_DEBUG("timer already running!\n"); \
273 else { \
274 gettimeofday(&((sparrow)->timer_start), NULL); \
277 } while (0)
279 static inline void
280 TIMER_STOP(GstSparrow *sparrow)
282 if (sparrow->timer_log){
283 struct timeval *start = &(sparrow->timer_start);
284 struct timeval *stop = &(sparrow->timer_stop);
285 if (start->tv_sec == 0){
286 GST_DEBUG("the timer isn't running!\n");
287 return;
289 gettimeofday(stop, NULL);
290 guint32 t = ((stop->tv_sec - start->tv_sec) * 1000000 +
291 stop->tv_usec - start->tv_usec);
293 #if SPARROW_NOISY_DEBUG
294 GST_DEBUG("took %u microseconds (%0.5f of a frame)\n",
295 t, (double)t * (25.0 / 1000000.0));
296 #endif
298 fprintf(sparrow->timer_log, "%d %6d\n", sparrow->state, t);
299 fflush(sparrow->timer_log);
300 start->tv_sec = 0; /* mark it as unused */
304 /* GST_DISABLE_GST_DEBUG is set in gstreamer compilation. If it is set, we
305 need our own debug channel. */
306 #ifdef GST_DISABLE_GST_DEBUG
308 #undef GST_DEBUG
310 static FILE *_sparrow_bloody_debug_flags = NULL;
311 static void
312 GST_DEBUG(const char *msg, ...){
313 if (! _sparrow_bloody_debug_flags){
314 _sparrow_bloody_debug_flags = fopen("/tmp/sparrow.log", "wb");
315 if (! _sparrow_bloody_debug_flags){
316 exit(1);
319 va_list argp;
320 va_start(argp, msg);
321 vfprintf(_sparrow_bloody_debug_flags, msg, argp);
322 va_end(argp);
323 fflush(_sparrow_bloody_debug_flags);
326 #define GST_ERROR GST_DEBUG
327 #define GST_WARNING GST_DEBUG
328 #define GST_INFO GST_DEBUG
329 #define GST_LOG GST_DEBUG
330 #define GST_FIXME GST_DEBUG
332 #endif
333 #define LOG_LINENO() GST_DEBUG("%-25s line %4d \n", __func__, __LINE__ );
336 G_END_DECLS
337 #endif /* __GST_VIDEO_SPARROW_H__ */