~ubuntu-branches/ubuntu/karmic/recordmydesktop/karmic

« back to all changes in this revision

Viewing changes to include/rmdmacro.h

  • Committer: Bazaar Package Importer
  • Author(s): Alan Pope
  • Date: 2009-04-21 10:57:22 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090421105722-w6l4gz958gva15wn
Tags: 0.3.8.1-0ubuntu1
* New upstream release (LP: #364674)
* debian/control: Fixed libjack0.100.0-dev dependancy
* debian/control: Fixed project home page

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/******************************************************************************
2
 
*                            recordMyDesktop                                  *
3
 
*******************************************************************************
4
 
*                                                                             *
5
 
*            Copyright (C) 2006,2007,2008 John Varouhakis                     *
6
 
*                                                                             *
7
 
*                                                                             *
8
 
*   This program is free software; you can redistribute it and/or modify      *
9
 
*   it under the terms of the GNU General Public License as published by      *
10
 
*   the Free Software Foundation; either version 2 of the License, or         *
11
 
*   (at your option) any later version.                                       *
12
 
*                                                                             *
13
 
*   This program 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             *
16
 
*   GNU General Public License for more details.                              *
17
 
*                                                                             *
18
 
*   You should have received a copy of the GNU General Public License         *
19
 
*   along with this program; if not, write to the Free Software               *
20
 
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA  *
21
 
*                                                                             *
22
 
*                                                                             *
23
 
*                                                                             *
24
 
*   For further information contact me at johnvarouhakis@gmail.com            *
25
 
******************************************************************************/
26
 
 
27
 
#ifndef RMDMACRO_H
28
 
#define RMDMACRO_H 1
29
 
 
30
 
#ifdef HAVE_CONFIG_H
31
 
    #include <config.h>
32
 
#endif
33
 
 
34
 
#include "rmdtypes.h"
35
 
 
36
 
//define which way we are reading a pixmap
37
 
#if __BYTE_ORDER == __LITTLE_ENDIAN
38
 
#define __ABYTE 3
39
 
#define __RBYTE 2
40
 
#define __GBYTE 1
41
 
#define __BBYTE 0
42
 
 
43
 
#elif __BYTE_ORDER == __BIG_ENDIAN
44
 
 
45
 
#define __ABYTE 0
46
 
#define __RBYTE 1
47
 
#define __GBYTE 2
48
 
#define __BBYTE 3
49
 
 
50
 
#else
51
 
#error Only little-endian and big-endian systems are supported
52
 
#endif
53
 
 
54
 
#define __RVALUE_32(tmp_val) (((tmp_val)&0x00ff0000)>>16)
55
 
#define __GVALUE_32(tmp_val) (((tmp_val)&0x0000ff00)>>8)
56
 
#define __BVALUE_32(tmp_val) (((tmp_val)&0x000000ff))
57
 
 
58
 
#define __R16_MASK  0xf800
59
 
#define __G16_MASK  0x7e0
60
 
#define __B16_MASK  0x1f
61
 
 
62
 
#define __RVALUE_16(tmp_val) ((((tmp_val)&__R16_MASK)>>11)*8)
63
 
#define __GVALUE_16(tmp_val) ((((tmp_val)&__G16_MASK)>>5)*4)
64
 
#define __BVALUE_16(tmp_val) ((((tmp_val)&__B16_MASK))*8)
65
 
 
66
 
//xfixes pointer data are written as unsigned long
67
 
//(even though the server returns CARD32)
68
 
//so we need to set the step accordingly to
69
 
//avoid problems (amd64 has 8byte ulong)
70
 
#define RMD_ULONG_SIZE_T (sizeof(unsigned long))
71
 
 
72
 
//size of stride when comparing planes(depending on type)
73
 
//this is just to avoid thousands of sizeof's
74
 
#ifdef HAVE_U_INT64_T
75
 
    #define COMPARE_STRIDE  8
76
 
#else
77
 
    #define COMPARE_STRIDE  4
78
 
#endif
79
 
 
80
 
//500 mb file size
81
 
#define CACHE_FILE_SIZE_LIMIT (500*1<<20)
82
 
//minimize hard disk access
83
 
#define CACHE_OUT_BUFFER_SIZE 4096
84
 
 
85
 
 
86
 
//The width, in bytes, of the blocks
87
 
//on which the y,u and v planes are broken.
88
 
//These blocks are square.
89
 
#define Y_UNIT_WIDTH    0x0010
90
 
#define UV_UNIT_WIDTH   0x0008
91
 
 
92
 
//The number of bytes for every
93
 
//sub-block of the y,u and v planes.
94
 
//Since the blocks are square
95
 
//these are obviously the squares
96
 
//of the widths(specified above),
97
 
//but the definitions bellow are only
98
 
//for convenience anyway.
99
 
#define Y_UNIT_BYTES    0x0100
100
 
#define UV_UNIT_BYTES   0x0040
101
 
 
102
 
#ifdef HAVE_LIBASOUND
103
 
    #define DEFAULT_AUDIO_DEVICE "hw:0,0"
104
 
#else
105
 
    #define DEFAULT_AUDIO_DEVICE "/dev/dsp"
106
 
#endif
107
 
 
108
 
 
109
 
 
110
 
#define CLIP_EVENT_AREA(e,brwin,wgeom){\
111
 
    if(((e)->area.x<=(brwin)->rgeom.x)&&((e)->area.y<=(brwin)->rgeom.y)&&\
112
 
        ((e)->area.width>=(brwin)->rgeom.width)&&\
113
 
        ((e)->area.height<(brwin)->rgeom.height)){\
114
 
        (wgeom)->x=(brwin)->rgeom.x;\
115
 
        (wgeom)->y=(brwin)->rgeom.y;\
116
 
        (wgeom)->width=(brwin)->rgeom.width;\
117
 
        (wgeom)->height=(brwin)->rgeom.height;\
118
 
    }\
119
 
    else{\
120
 
        (wgeom)->x=((((e)->area.x+(e)->area.width>=(brwin)->rgeom.x)&&\
121
 
        ((e)->area.x<=(brwin)->rgeom.x+(brwin)->rgeom.width))?\
122
 
        (((e)->area.x<=(brwin)->rgeom.x)?(brwin)->rgeom.x:(e)->area.x):-1);\
123
 
    \
124
 
        (wgeom)->y=((((e)->area.y+(e)->area.height>=(brwin)->rgeom.y)&&\
125
 
        ((e)->area.y<=(brwin)->rgeom.y+(brwin)->rgeom.height))?\
126
 
        (((e)->area.y<=(brwin)->rgeom.y)?(brwin)->rgeom.y:(e)->area.y):-1);\
127
 
    \
128
 
        (wgeom)->width=((e)->area.x<=(brwin)->rgeom.x)?\
129
 
        (e)->area.width-((brwin)->rgeom.x-(e)->area.x):\
130
 
        ((e)->area.x<=(brwin)->rgeom.x+(brwin)->rgeom.width)?\
131
 
        (((brwin)->rgeom.width-(e)->area.x+(brwin)->rgeom.x<(e)->area.width)?\
132
 
        (brwin)->rgeom.width-(e)->area.x+(brwin)->rgeom.x:e->area.width):-1;\
133
 
    \
134
 
        (wgeom)->height=((e)->area.y<=(brwin)->rgeom.y)?\
135
 
        (e)->area.height-((brwin)->rgeom.y-(e)->area.y):\
136
 
        ((e)->area.y<=(brwin)->rgeom.y+(brwin)->rgeom.height)?\
137
 
        (((brwin)->rgeom.height-(e)->area.y+\
138
 
         (brwin)->rgeom.y<(e)->area.height)?\
139
 
         (brwin)->rgeom.height-(e)->area.y+\
140
 
         (brwin)->rgeom.y:(e)->area.height):-1;\
141
 
    \
142
 
        if((wgeom)->width>(brwin)->rgeom.width)\
143
 
            (wgeom)->width=(brwin)->rgeom.width;\
144
 
        if((wgeom)->height>(brwin)->rgeom.height)\
145
 
            (wgeom)->height=(brwin)->rgeom.height;\
146
 
    }\
147
 
}
148
 
 
149
 
#define CLIP_DUMMY_POINTER_AREA(dummy_p_area,brwin,wgeom){\
150
 
    (wgeom)->x=((((dummy_p_area).x+\
151
 
                (dummy_p_area).width>=(brwin)->rgeom.x)&&\
152
 
                ((dummy_p_area).x<=(brwin)->rgeom.x+\
153
 
                (brwin)->rgeom.width))?\
154
 
                (((dummy_p_area).x<=(brwin)->rgeom.x)?\
155
 
                (brwin)->rgeom.x:(dummy_p_area).x):-1);\
156
 
    (wgeom)->y=((((dummy_p_area).y+\
157
 
                (dummy_p_area).height>=(brwin)->rgeom.y)&&\
158
 
                ((dummy_p_area).y<=(brwin)->rgeom.y+\
159
 
                (brwin)->rgeom.height))?\
160
 
                (((dummy_p_area).y<=(brwin)->rgeom.y)?\
161
 
                (brwin)->rgeom.y:(dummy_p_area).y):-1);\
162
 
    (wgeom)->width=((dummy_p_area).x<=(brwin)->rgeom.x)?\
163
 
                (dummy_p_area).width-\
164
 
                ((brwin)->rgeom.x-(dummy_p_area).x):\
165
 
                ((dummy_p_area).x<=(brwin)->rgeom.x+\
166
 
                (brwin)->rgeom.width)?\
167
 
                ((brwin)->rgeom.width-(dummy_p_area).x+\
168
 
                (brwin)->rgeom.x<(dummy_p_area).width)?\
169
 
                (brwin)->rgeom.width-(dummy_p_area).x+\
170
 
                (brwin)->rgeom.x:(dummy_p_area).width:-1;\
171
 
    (wgeom)->height=((dummy_p_area).y<=(brwin)->rgeom.y)?\
172
 
                (dummy_p_area).height-\
173
 
                ((brwin)->rgeom.y-(dummy_p_area).y):\
174
 
                ((dummy_p_area).y<=(brwin)->rgeom.y+\
175
 
                (brwin)->rgeom.height)?\
176
 
                ((brwin)->rgeom.height-(dummy_p_area).y+\
177
 
                (brwin)->rgeom.y<(dummy_p_area).height)?\
178
 
                (brwin)->rgeom.height-(dummy_p_area).y+\
179
 
                (brwin)->rgeom.y:(dummy_p_area).height:-1;\
180
 
    if((wgeom)->width>(brwin)->rgeom.width)\
181
 
        (wgeom)->width=(brwin)->rgeom.width;\
182
 
    if((wgeom)->height>(brwin)->rgeom.height)\
183
 
        (wgeom)->height=(brwin)->rgeom.height;\
184
 
}
185
 
 
186
 
 
187
 
 
188
 
#define DEFAULT_ARGS(args){\
189
 
    (args)->delay=0;\
190
 
    if(getenv("DISPLAY")!=NULL){\
191
 
        (args)->display=(char *)malloc(strlen(getenv("DISPLAY"))+1);\
192
 
        strcpy((args)->display,getenv("DISPLAY"));\
193
 
    }\
194
 
    else\
195
 
        (args)->display=NULL;\
196
 
    (args)->windowid=\
197
 
    (args)->x=\
198
 
    (args)->y=\
199
 
    (args)->width=\
200
 
    (args)->height=\
201
 
    (args)->nosound=\
202
 
    (args)->full_shots=\
203
 
    (args)->follow_mouse=\
204
 
    (args)->encOnTheFly=\
205
 
    (args)->nowmcheck=\
206
 
    (args)->overwrite=\
207
 
    (args)->use_jack=\
208
 
    (args)->noshared=\
209
 
    (args)->no_encode=\
210
 
    (args)->noframe=\
211
 
    (args)->jack_nports=0;\
212
 
    (args)->jack_ringbuffer_secs=3.0;\
213
 
    (args)->jack_port_names=NULL;\
214
 
    (args)->zerocompression=\
215
 
    (args)->no_quick_subsample=1;\
216
 
    (args)->filename=(char *)malloc(8);\
217
 
    strcpy((args)->filename,"out.ogv");\
218
 
    (args)->cursor_color=1;\
219
 
    (args)->have_dummy_cursor=0;\
220
 
    (args)->xfixes_cursor=1;\
221
 
    (args)->device=(char *)malloc(strlen(DEFAULT_AUDIO_DEVICE)+1);\
222
 
    strcpy((args)->device,DEFAULT_AUDIO_DEVICE);\
223
 
    (args)->fps=15;\
224
 
    (args)->channels=1;\
225
 
    (args)->frequency=22050;\
226
 
    (args)->buffsize=4096;\
227
 
    (args)->v_bitrate=45000;\
228
 
    (args)->v_quality=63;\
229
 
    (args)->s_quality=10;\
230
 
    (args)->workdir=(char *)malloc(5);\
231
 
    strcpy((args)->workdir,"/tmp");\
232
 
    (args)->pause_shortcut=(char *)malloc(15);\
233
 
    strcpy((args)->pause_shortcut,"Control+Mod1+p");\
234
 
    (args)->stop_shortcut=(char *)malloc(15);\
235
 
    strcpy((args)->stop_shortcut,"Control+Mod1+s");\
236
 
}
237
 
 
238
 
#define QUERY_DISPLAY_SPECS(display,specstruct){\
239
 
    (specstruct)->screen=DefaultScreen(display);\
240
 
    (specstruct)->width=DisplayWidth(display,(specstruct)->screen);\
241
 
    (specstruct)->height=DisplayHeight(display,(specstruct)->screen);\
242
 
    (specstruct)->root=RootWindow(display,(specstruct)->screen);\
243
 
    (specstruct)->visual=DefaultVisual(display,(specstruct)->screen);\
244
 
    (specstruct)->gc=DefaultGC(display,(specstruct)->screen);\
245
 
    (specstruct)->depth=DefaultDepth(display,(specstruct)->screen);\
246
 
    (specstruct)->bpixel=XBlackPixel(display,(specstruct)->screen);\
247
 
    (specstruct)->wpixel=XWhitePixel(display,(specstruct)->screen);\
248
 
}
249
 
 
250
 
#define AVG_4_PIXELS(data_array,width_img,k_tm,i_tm,offset)\
251
 
    ((data_array[(k_tm*width_img+i_tm)*RMD_ULONG_SIZE_T+offset]+\
252
 
    data_array[((k_tm-1)*width_img+i_tm)*RMD_ULONG_SIZE_T+offset]+\
253
 
    data_array[(k_tm*width_img+i_tm-1)*RMD_ULONG_SIZE_T+offset]+\
254
 
    data_array[((k_tm-1)*width_img+i_tm-1)*RMD_ULONG_SIZE_T+offset])/4)
255
 
 
256
 
 
257
 
//the 4 most significant bytes represent the A component which
258
 
//does not need to be added on t_val, as it is always unused
259
 
#define CALC_TVAL_AVG_32(t_val,datapi,datapi_next){\
260
 
    register unsigned int t1,t2,t3,t4;\
261
 
    t1=*datapi;\
262
 
    t2=*(datapi+1);\
263
 
    t3=*datapi_next;\
264
 
    t4=*(datapi_next+1);\
265
 
    t_val=((((t1&0x00ff0000) +(t2&0x00ff0000)+\
266
 
            (t3&0x00ff0000)+(t4&0x00ff0000))/4)&0x00ff0000)+\
267
 
          ((((t1&0x0000ff00) +(t2&0x0000ff00)+\
268
 
            (t3&0x0000ff00)+(t4&0x0000ff00))/4)&0x0000ff00)+\
269
 
          ((((t1&0x000000ff) +(t2&0x000000ff)+\
270
 
            (t3&0x000000ff)+(t4&0x000000ff))/4)&0x000000ff);\
271
 
}
272
 
 
273
 
//when adding the r values, we go beyond
274
 
//the (16 bit)range of the t_val variable, but we are performing
275
 
//32 bit arithmetics, so there's no problem.
276
 
//(This note is useless, I'm just adding because
277
 
//the addition of the A components in CALC_TVAL_AVG_32,
278
 
//now removed as uneeded, produced an overflow which would have caused
279
 
//color distrtion, where it one of the R,G or B components)
280
 
#define CALC_TVAL_AVG_16(t_val,datapi,datapi_next){\
281
 
    register u_int16_t t1,t2,t3,t4;\
282
 
    t1=*datapi;\
283
 
    t2=*(datapi+1);\
284
 
    t3=*datapi_next;\
285
 
    t4=*(datapi_next+1);\
286
 
    t_val=((((t1&__R16_MASK) +(t2&__R16_MASK)+\
287
 
             (t3&__R16_MASK)+(t4&__R16_MASK))/4)&__R16_MASK)+\
288
 
          ((((t1&__G16_MASK) +(t2&__G16_MASK)+\
289
 
             (t3&__G16_MASK)+(t4&__G16_MASK))/4)&__G16_MASK)+\
290
 
          ((((t1&__B16_MASK) +(t2&__B16_MASK)+\
291
 
             (t3&__B16_MASK)+(t4&__B16_MASK))/4)&__B16_MASK);\
292
 
}
293
 
 
294
 
#define POINT_IN_BLOCK(xv,yv,widthv,blocksize) ((yv/blocksize)*\
295
 
                                                (widthv/blocksize)+\
296
 
                                                (xv/blocksize))
297
 
 
298
 
#define UPDATE_Y_PLANE(data,\
299
 
                       x_tm,\
300
 
                       y_tm,\
301
 
                       height_tm,\
302
 
                       width_tm,\
303
 
                       yuv,\
304
 
                       __bit_depth__){ \
305
 
    int k,i;\
306
 
    register u_int##__bit_depth__##_t t_val;\
307
 
    register unsigned char  *yuv_y=yuv->y+x_tm+y_tm*yuv->y_width,\
308
 
                            *_yr=Yr,*_yg=Yg,*_yb=Yb;\
309
 
    register u_int##__bit_depth__##_t *datapi=(u_int##__bit_depth__##_t *)data;\
310
 
    for(k=0;k<height_tm;k++){\
311
 
        for(i=0;i<width_tm;i++){\
312
 
            t_val=*datapi;\
313
 
            *yuv_y=_yr[__RVALUE_##__bit_depth__(t_val)] +\
314
 
                   _yg[__GVALUE_##__bit_depth__(t_val)] +\
315
 
                   _yb[__BVALUE_##__bit_depth__(t_val)] ;\
316
 
            datapi++;\
317
 
            yuv_y++;\
318
 
        }\
319
 
        yuv_y+=yuv->y_width-width_tm;\
320
 
    }\
321
 
}
322
 
 
323
 
#define UPDATE_Y_PLANE_DBUF(data,\
324
 
                            data_back,\
325
 
                            x_tm,\
326
 
                            y_tm,\
327
 
                            height_tm,\
328
 
                            width_tm,\
329
 
                            yuv,\
330
 
                            __bit_depth__){ \
331
 
    int k,i;\
332
 
    register u_int##__bit_depth__##_t t_val;\
333
 
    register unsigned char  *yuv_y=yuv->y+x_tm+y_tm*yuv->y_width,\
334
 
                            *_yr=Yr,*_yg=Yg,*_yb=Yb;\
335
 
    register u_int##__bit_depth__##_t *datapi=(u_int##__bit_depth__##_t *)data,\
336
 
                            *datapi_back=(u_int##__bit_depth__##_t *)data_back;\
337
 
    for(k=0;k<height_tm;k++){\
338
 
        for(i=0;i<width_tm;i++){\
339
 
            if(*datapi!=*datapi_back){\
340
 
                t_val=*datapi;\
341
 
                *yuv_y=_yr[__RVALUE_##__bit_depth__(t_val)] +\
342
 
                    _yg[__GVALUE_##__bit_depth__(t_val)] +\
343
 
                    _yb[__BVALUE_##__bit_depth__(t_val)] ;\
344
 
                yblocks[POINT_IN_BLOCK(i,k,width_tm,Y_UNIT_WIDTH)]=1;\
345
 
            }\
346
 
            datapi++;\
347
 
            datapi_back++;\
348
 
            yuv_y++;\
349
 
        }\
350
 
        yuv_y+=yuv->y_width-width_tm;\
351
 
    }\
352
 
}
353
 
 
354
 
#define UPDATE_A_UV_PIXEL(yuv_u,\
355
 
                          yuv_v,\
356
 
                          t_val,\
357
 
                          datapi,\
358
 
                          datapi_next,\
359
 
                          _ur,_ug,_ubvr,_vg,_vb,\
360
 
                          __sampling_type,\
361
 
                          __bit_depth__)\
362
 
            if(__sampling_type==__PXL_AVERAGE){\
363
 
                CALC_TVAL_AVG_##__bit_depth__(t_val,datapi,datapi_next)\
364
 
            }\
365
 
            else\
366
 
                t_val=*datapi;\
367
 
            *yuv_u=\
368
 
            _ur[__RVALUE_##__bit_depth__(t_val)] +\
369
 
            _ug[__GVALUE_##__bit_depth__(t_val)] +\
370
 
            _ubvr[__BVALUE_##__bit_depth__(t_val)];\
371
 
            *yuv_v=\
372
 
            _ubvr[__RVALUE_##__bit_depth__(t_val)] +\
373
 
            _vg[__GVALUE_##__bit_depth__(t_val)] +\
374
 
            _vb[__BVALUE_##__bit_depth__(t_val)];\
375
 
 
376
 
 
377
 
#define UPDATE_UV_PLANES(data,\
378
 
                         x_tm,\
379
 
                         y_tm,\
380
 
                         height_tm,\
381
 
                         width_tm,\
382
 
                         yuv,\
383
 
                         __sampling_type,\
384
 
                         __bit_depth__){  \
385
 
    int k,i;\
386
 
    register u_int##__bit_depth__##_t t_val;\
387
 
    register unsigned char  *yuv_u=yuv->u+x_tm/2+(y_tm*yuv->uv_width)/2,\
388
 
                            *yuv_v=yuv->v+x_tm/2+(y_tm*yuv->uv_width)/2,\
389
 
                            *_ur=Ur,*_ug=Ug,*_ubvr=UbVr,\
390
 
                            *_vg=Vg,*_vb=Vb;\
391
 
    register u_int##__bit_depth__##_t *datapi=(u_int##__bit_depth__##_t *)data,\
392
 
                                      *datapi_next=NULL;\
393
 
    if(__sampling_type==__PXL_AVERAGE){\
394
 
        datapi_next=datapi+width_tm;\
395
 
    }\
396
 
    for(k=0;k<height_tm;k+=2){\
397
 
        for(i=0;i<width_tm;i+=2){\
398
 
            UPDATE_A_UV_PIXEL(  yuv_u,\
399
 
                                yuv_v,\
400
 
                                t_val,\
401
 
                                datapi,\
402
 
                                datapi_next,\
403
 
                                _ur,_ug,_ubvr,_vg,_vb,\
404
 
                                __sampling_type,\
405
 
                                __bit_depth__)\
406
 
            datapi+=2;\
407
 
            if(__sampling_type==__PXL_AVERAGE)\
408
 
                datapi_next+=2;\
409
 
            yuv_u++;\
410
 
            yuv_v++;\
411
 
        }\
412
 
        yuv_u+=(yuv->y_width-width_tm)/2;\
413
 
        yuv_v+=(yuv->y_width-width_tm)/2;\
414
 
        datapi+=width_tm;\
415
 
        if(__sampling_type==__PXL_AVERAGE)\
416
 
            datapi_next+=width_tm;\
417
 
    }\
418
 
}
419
 
 
420
 
#define UPDATE_UV_PLANES_DBUF(  data,\
421
 
                                data_back,\
422
 
                                x_tm,\
423
 
                                y_tm,\
424
 
                                height_tm,\
425
 
                                width_tm,\
426
 
                                yuv,\
427
 
                                __sampling_type,\
428
 
                                __bit_depth__){  \
429
 
    int k,i;\
430
 
    register u_int##__bit_depth__##_t t_val;\
431
 
    register unsigned char  *yuv_u=yuv->u+x_tm/2+(y_tm*yuv->uv_width)/2,\
432
 
                            *yuv_v=yuv->v+x_tm/2+(y_tm*yuv->uv_width)/2,\
433
 
                            *_ur=Ur,*_ug=Ug,*_ubvr=UbVr,\
434
 
                            *_vg=Vg,*_vb=Vb;\
435
 
    register u_int##__bit_depth__##_t *datapi=(u_int##__bit_depth__##_t *)data,\
436
 
                                      *datapi_next=NULL,\
437
 
                            *datapi_back=(u_int##__bit_depth__##_t *)data_back,\
438
 
                            *datapi_back_next=NULL;\
439
 
    if(__sampling_type==__PXL_AVERAGE){\
440
 
        datapi_next=datapi+width_tm;\
441
 
        datapi_back_next=datapi_back+width_tm;\
442
 
        for(k=0;k<height_tm;k+=2){\
443
 
            for(i=0;i<width_tm;i+=2){\
444
 
                if(( (*datapi!=*datapi_back) ||\
445
 
                    (*(datapi+1)!=*(datapi_back+1)) ||\
446
 
                    (*datapi_next!=*datapi_back_next) ||\
447
 
                    (*(datapi_next+1)!=*(datapi_back_next+1)))){\
448
 
                    UPDATE_A_UV_PIXEL(  yuv_u,\
449
 
                                        yuv_v,\
450
 
                                        t_val,\
451
 
                                        datapi,\
452
 
                                        datapi_next,\
453
 
                                        _ur,_ug,_ubvr,_vg,_vb,\
454
 
                                        __sampling_type,\
455
 
                                        __bit_depth__)\
456
 
                    ublocks[POINT_IN_BLOCK(i,k,width_tm,Y_UNIT_WIDTH)]=1;\
457
 
                    vblocks[POINT_IN_BLOCK(i,k,width_tm,Y_UNIT_WIDTH)]=1;\
458
 
                }\
459
 
                datapi+=2;\
460
 
                datapi_back+=2;\
461
 
                if(__sampling_type==__PXL_AVERAGE){\
462
 
                    datapi_next+=2;\
463
 
                    datapi_back_next+=2;\
464
 
                }\
465
 
                yuv_u++;\
466
 
                yuv_v++;\
467
 
            }\
468
 
            yuv_u+=(yuv->y_width-width_tm)/2;\
469
 
            yuv_v+=(yuv->y_width-width_tm)/2;\
470
 
            datapi+=width_tm;\
471
 
            datapi_back+=width_tm;\
472
 
            if(__sampling_type==__PXL_AVERAGE){\
473
 
                datapi_next+=width_tm;\
474
 
                datapi_back_next+=width_tm;\
475
 
            }\
476
 
        }\
477
 
    }\
478
 
    else{\
479
 
        for(k=0;k<height_tm;k+=2){\
480
 
            for(i=0;i<width_tm;i+=2){\
481
 
                if ((*datapi!=*datapi_back)){\
482
 
                    UPDATE_A_UV_PIXEL(  yuv_u,\
483
 
                                        yuv_v,\
484
 
                                        t_val,\
485
 
                                        datapi,\
486
 
                                        datapi_next,\
487
 
                                        _ur,_ug,_ubvr,_vg,_vb,\
488
 
                                        __sampling_type,\
489
 
                                        __bit_depth__)\
490
 
                    ublocks[POINT_IN_BLOCK(i,k,width_tm,Y_UNIT_WIDTH)]=1;\
491
 
                    vblocks[POINT_IN_BLOCK(i,k,width_tm,Y_UNIT_WIDTH)]=1;\
492
 
                }\
493
 
                datapi+=2;\
494
 
                datapi_back+=2;\
495
 
                if(__sampling_type==__PXL_AVERAGE){\
496
 
                    datapi_next+=2;\
497
 
                    datapi_back_next+=2;\
498
 
                }\
499
 
                yuv_u++;\
500
 
                yuv_v++;\
501
 
            }\
502
 
            yuv_u+=(yuv->y_width-width_tm)/2;\
503
 
            yuv_v+=(yuv->y_width-width_tm)/2;\
504
 
            datapi+=width_tm;\
505
 
            datapi_back+=width_tm;\
506
 
            if(__sampling_type==__PXL_AVERAGE){\
507
 
                datapi_next+=width_tm;\
508
 
                datapi_back_next+=width_tm;\
509
 
            }\
510
 
        }\
511
 
    }\
512
 
}
513
 
 
514
 
#define UPDATE_YUV_BUFFER(yuv,\
515
 
                          data,\
516
 
                          data_back,\
517
 
                          x_tm,\
518
 
                          y_tm,\
519
 
                          width_tm,\
520
 
                          height_tm,\
521
 
                          __sampling_type,\
522
 
                          __color_depth){\
523
 
    if(data_back==NULL){\
524
 
        if((__color_depth==24)||(__color_depth==32)){\
525
 
            UPDATE_Y_PLANE(data,x_tm,y_tm,height_tm,width_tm,yuv,32)\
526
 
            UPDATE_UV_PLANES(data,x_tm,y_tm,height_tm,width_tm,\
527
 
                             yuv,__sampling_type,32)\
528
 
        }\
529
 
        else if(__color_depth==16){\
530
 
            UPDATE_Y_PLANE(data,x_tm,y_tm,height_tm,width_tm,yuv,16)\
531
 
            UPDATE_UV_PLANES(data,x_tm,y_tm,height_tm,width_tm,\
532
 
                            yuv,__sampling_type,16)\
533
 
        }\
534
 
    }\
535
 
    else{\
536
 
        if((__color_depth==24)||(__color_depth==32)){\
537
 
            UPDATE_Y_PLANE_DBUF(data,data_back,x_tm,y_tm,\
538
 
                                height_tm,width_tm,yuv,32)\
539
 
            UPDATE_UV_PLANES_DBUF(data,data_back,x_tm,y_tm,height_tm,width_tm,\
540
 
                                  yuv,__sampling_type,32)\
541
 
        }\
542
 
        else if(__color_depth==16){\
543
 
            UPDATE_Y_PLANE_DBUF(data,data_back,x_tm,y_tm,\
544
 
                                height_tm,width_tm,yuv,16)\
545
 
            UPDATE_UV_PLANES_DBUF(data,data_back,x_tm,y_tm,height_tm,width_tm,\
546
 
                                  yuv,__sampling_type,16)\
547
 
        }\
548
 
    }\
549
 
}
550
 
 
551
 
 
552
 
 
553
 
#define XFIXES_POINTER_TO_YUV(yuv,\
554
 
                              data,\
555
 
                              x_tm,\
556
 
                              y_tm,\
557
 
                              width_tm,\
558
 
                              height_tm,\
559
 
                              x_offset,\
560
 
                              y_offset,\
561
 
                              column_discard_stride){\
562
 
    int i,k,j=0;\
563
 
    unsigned char avg0,avg1,avg2,avg3;\
564
 
    int x_2=x_tm/2,y_2=y_tm/2;\
565
 
    for(k=y_offset;k<y_offset+height_tm;k++){\
566
 
        for(i=x_offset;i<x_offset+width_tm;i++){\
567
 
                j=k*(width_tm+column_discard_stride)+i;\
568
 
                yuv->y[x_tm+(i-x_offset)+(k+y_tm-y_offset)*yuv->y_width]=\
569
 
                    (yuv->y[x_tm+(i-x_offset)+(k-y_offset+y_tm)*yuv->y_width]*\
570
 
                    (UCHAR_MAX-data[(j*RMD_ULONG_SIZE_T)+__ABYTE])+\
571
 
                    (Yr[data[(j*RMD_ULONG_SIZE_T)+__RBYTE]]+\
572
 
                    Yg[data[(j*RMD_ULONG_SIZE_T)+__GBYTE]] +\
573
 
                    Yb[data[(j*RMD_ULONG_SIZE_T)+__BBYTE]])*\
574
 
                data[(j*RMD_ULONG_SIZE_T)+__ABYTE])/UCHAR_MAX ;\
575
 
                if((k%2)&&(i%2)){\
576
 
                    avg3=AVG_4_PIXELS(data,\
577
 
                                      (width_tm+column_discard_stride),\
578
 
                                      k,i,__ABYTE);\
579
 
                    avg2=AVG_4_PIXELS(data,\
580
 
                                      (width_tm+column_discard_stride),\
581
 
                                      k,i,__RBYTE);\
582
 
                    avg1=AVG_4_PIXELS(data,\
583
 
                                      (width_tm+column_discard_stride),\
584
 
                                      k,i,__GBYTE);\
585
 
                    avg0=AVG_4_PIXELS(data,\
586
 
                                      (width_tm+column_discard_stride),\
587
 
                                      k,i,__BBYTE);\
588
 
                    yuv->u[x_2+(i-x_offset)/2+((k-y_offset)/2+y_2)*\
589
 
                           yuv->uv_width]=\
590
 
                    (yuv->u[x_2+(i-x_offset)/2+((k-y_offset)/2+y_2)*\
591
 
                            yuv->uv_width]*\
592
 
                    (UCHAR_MAX-avg3)+\
593
 
                    (Ur[avg2] + Ug[avg1] +UbVr[avg0])*avg3)/UCHAR_MAX;\
594
 
                    yuv->v[x_2+(i-x_offset)/2+((k-y_offset)/2+y_2)*\
595
 
                           yuv->uv_width]=\
596
 
                    (yuv->v[x_2+(i-x_offset)/2+((k-y_offset)/2+y_2)*\
597
 
                            yuv->uv_width]*\
598
 
                    (UCHAR_MAX-avg3)+\
599
 
                    (UbVr[avg2] + Vg[avg1] +Vb[avg0])*avg3)/UCHAR_MAX;\
600
 
                }\
601
 
        }\
602
 
    }\
603
 
}
604
 
 
605
 
#define DUMMY_POINTER_TO_YUV(yuv,\
606
 
                             data_tm,\
607
 
                             x_tm,\
608
 
                             y_tm,\
609
 
                             width_tm,\
610
 
                             height_tm,\
611
 
                             x_offset,\
612
 
                             y_offset,\
613
 
                             no_pixel){\
614
 
    int i,k,j=0;\
615
 
    int x_2=x_tm/2,y_2=y_tm/2,y_width_2=(yuv)->y_width/2;\
616
 
    for(k=y_offset;k<y_offset+height_tm;k++){\
617
 
        for(i=x_offset;i<x_offset+width_tm;i++){\
618
 
            j=k*16+i;\
619
 
            if(data_tm[(j*4)]!=(no_pixel)){\
620
 
                (yuv)->y[x_tm+(i-x_offset)+((k-y_offset)+y_tm)*(yuv)->y_width]=\
621
 
                    Yr[data_tm[(j*4)+__RBYTE]] +\
622
 
                    Yg[data_tm[(j*4)+__GBYTE]] +\
623
 
                    Yb[data_tm[(j*4)+__BBYTE]];\
624
 
                if((k%2)&&(i%2)){\
625
 
                    yuv->u[x_2+(i-x_offset)/2+((k-y_offset)/2+y_2)*y_width_2]=\
626
 
                        Ur[data_tm[(k*width_tm+i)*4+__RBYTE]] +\
627
 
                        Ug[data_tm[(k*width_tm+i)*4+__GBYTE]] +\
628
 
                        UbVr[data_tm[(k*width_tm+i)*4+__BBYTE]];\
629
 
                    yuv->v[x_2+(i-x_offset)/2+((k-y_offset)/2+y_2)*y_width_2]=\
630
 
                        UbVr[data_tm[(k*width_tm+i)*4+__RBYTE]] +\
631
 
                        Vg[data_tm[(k*width_tm+i)*4+__GBYTE]] +\
632
 
                        Vb[data_tm[(k*width_tm+i)*4+__BBYTE]] ;\
633
 
                }\
634
 
            }\
635
 
        }\
636
 
    }\
637
 
}
638
 
 
639
 
#define MARK_BACK_BUFFER(   data,\
640
 
                            x_tm,\
641
 
                            y_tm,\
642
 
                            width_tm,\
643
 
                            height_tm,\
644
 
                            buffer_width,\
645
 
                            __bit_depth__){\
646
 
    if((__bit_depth__==24)||(__bit_depth__==32)){\
647
 
        MARK_BACK_BUFFER_C( data,\
648
 
                            x_tm,\
649
 
                            y_tm,\
650
 
                            width_tm,\
651
 
                            height_tm,\
652
 
                            buffer_width,\
653
 
                            32)\
654
 
    }\
655
 
    else{\
656
 
        MARK_BACK_BUFFER_C( data,\
657
 
                            x_tm,\
658
 
                            y_tm,\
659
 
                            width_tm,\
660
 
                            height_tm,\
661
 
                            buffer_width,\
662
 
                            16)\
663
 
    }\
664
 
}\
665
 
 
666
 
 
667
 
#define MARK_BACK_BUFFER_C( data,\
668
 
                            x_tm,\
669
 
                            y_tm,\
670
 
                            width_tm,\
671
 
                            height_tm,\
672
 
                            buffer_width,\
673
 
                            __bit_depth__){\
674
 
    int k,i;\
675
 
    register u_int##__bit_depth__##_t\
676
 
        *datapi=\
677
 
            ((u_int##__bit_depth__##_t *)data)+y_tm*buffer_width+x_tm;\
678
 
    for(k=0;k<height_tm;k++){\
679
 
        for(i=0;i<width_tm;i++){\
680
 
            *datapi+=1;\
681
 
            datapi++;\
682
 
        }\
683
 
        datapi+=buffer_width-width_tm;\
684
 
    }\
685
 
}
686
 
 
687
 
#define I16TOA(number,buffer){\
688
 
    int t_num=(number),__k=0,__i=0;\
689
 
    char *t_buf=malloc(8);\
690
 
    t_num=t_num&((2<<15)-1);\
691
 
    while(t_num>0){\
692
 
        int digit=t_num%10;\
693
 
        t_buf[__k]=digit+48;\
694
 
        t_num-=digit;\
695
 
        t_num/=10;\
696
 
        __k++;\
697
 
    }\
698
 
    while(__k>0)\
699
 
        (buffer)[__i++]=t_buf[--__k];\
700
 
    (buffer)[__i]='\0';\
701
 
    free(t_buf);\
702
 
};\
703
 
 
704
 
#define INIT_FRAME(frame_t,fheader_t,yuv_t,\
705
 
                   YBlocks_t,UBlocks_t,VBlocks_t){\
706
 
    (frame_t)->header=(fheader_t);\
707
 
    (frame_t)->YBlocks=YBlocks_t;\
708
 
    (frame_t)->UBlocks=UBlocks_t;\
709
 
    (frame_t)->VBlocks=VBlocks_t;\
710
 
    (frame_t)->YData=malloc((yuv_t)->y_width*(yuv_t)->y_height);\
711
 
    (frame_t)->UData=malloc((yuv_t)->uv_width*(yuv_t)->uv_height);\
712
 
    (frame_t)->VData=malloc((yuv_t)->uv_width*(yuv_t)->uv_height);\
713
 
};
714
 
 
715
 
#define CLEAR_FRAME(frame_t){\
716
 
    free((frame_t)->YData);\
717
 
    free((frame_t)->UData);\
718
 
    free((frame_t)->VData);\
719
 
};
720
 
 
721
 
#ifdef HAVE_JACK_H
722
 
 
723
 
#define CHECK_DLERRORS_FATAL(__error_p)\
724
 
    if((__error_p=dlerror())!=NULL){\
725
 
        fprintf(stderr,"%s\n",__error_p);\
726
 
        return 1;\
727
 
    }
728
 
 
729
 
#define DLSYM_AND_CHECK(lib_handle,__call_name__,__error_p)\
730
 
    __call_name__##_p=dlsym(lib_handle,#__call_name__);\
731
 
    CHECK_DLERRORS_FATAL(__error_p)
732
 
 
733
 
#endif
734
 
 
735
 
#endif
736