deinterlace.c 67.4 KB
Newer Older
1
2
3
/*****************************************************************************
 * deinterlace.c : deinterlacer plugin for vlc
 *****************************************************************************
4
 * Copyright (C) 2000, 2001, 2002, 2003 the VideoLAN team
5
 * $Id$
6
 *
7
 * Author: Sam Hocevar <sam@zoy.org>
8
9
10
11
12
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
13
 *
14
15
16
17
18
19
20
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
dionoea's avatar
dionoea committed
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22
23
24
25
26
27
28
29
30
31
32
 *****************************************************************************/

/*****************************************************************************
 * Preamble
 *****************************************************************************/
#include <errno.h>
#include <stdlib.h>                                      /* malloc(), free() */
#include <string.h>

#include <vlc/vlc.h>
#include <vlc/vout.h>
33
34
#include <vlc/sout.h>
#include "vlc_filter.h"
35

36
37
38
39
#ifdef HAVE_ALTIVEC_H
#   include <altivec.h>
#endif

40
41
42
43
#ifdef CAN_COMPILE_MMXEXT
#   include "mmx.h"
#endif

zorglub's avatar
zorglub committed
44
#include "filter_common.h"
45
46
47
48
49
50

#define DEINTERLACE_DISCARD 1
#define DEINTERLACE_MEAN    2
#define DEINTERLACE_BLEND   3
#define DEINTERLACE_BOB     4
#define DEINTERLACE_LINEAR  5
51
#define DEINTERLACE_X       6
52
53
54
55
56
57
58
59
60
61
62

/*****************************************************************************
 * Local protypes
 *****************************************************************************/
static int  Create    ( vlc_object_t * );
static void Destroy   ( vlc_object_t * );

static int  Init      ( vout_thread_t * );
static void End       ( vout_thread_t * );
static void Render    ( vout_thread_t *, picture_t * );

63
static void RenderDiscard( vout_thread_t *, picture_t *, picture_t *, int );
64
65
66
67
static void RenderBob    ( vout_thread_t *, picture_t *, picture_t *, int );
static void RenderMean   ( vout_thread_t *, picture_t *, picture_t * );
static void RenderBlend  ( vout_thread_t *, picture_t *, picture_t * );
static void RenderLinear ( vout_thread_t *, picture_t *, picture_t *, int );
68
static void RenderX      ( vout_thread_t *, picture_t *, picture_t * );
69

70
static void MergeGeneric ( void *, const void *, const void *, size_t );
sigmunau's avatar
sigmunau committed
71
#if defined(CAN_COMPILE_C_ALTIVEC)
72
static void MergeAltivec ( void *, const void *, const void *, size_t );
sigmunau's avatar
sigmunau committed
73
#endif
74
#if defined(CAN_COMPILE_MMXEXT)
75
76
77
78
static void MergeMMXEXT  ( void *, const void *, const void *, size_t );
#endif
#if defined(CAN_COMPILE_3DNOW)
static void Merge3DNow   ( void *, const void *, const void *, size_t );
sigmunau's avatar
sigmunau committed
79
#endif
Eric Petit's avatar
Eric Petit committed
80
#if defined(CAN_COMPILE_SSE)
sigmunau's avatar
sigmunau committed
81
static void MergeSSE2    ( void *, const void *, const void *, size_t );
sigmunau's avatar
sigmunau committed
82
#endif
83
#if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)
sigmunau's avatar
sigmunau committed
84
static void EndMMX       ( void );
sigmunau's avatar
sigmunau committed
85
#endif
86
87
88
#if defined(CAN_COMPILE_3DNOW)
static void End3DNow     ( void );
#endif
89

90
91
92
static int  SendEvents   ( vlc_object_t *, char const *,
                           vlc_value_t, vlc_value_t, void * );

gbazin's avatar
   
gbazin committed
93
94
95
static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method );
static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout );

96
97
98
static int OpenFilter( vlc_object_t *p_this );
static void CloseFilter( vlc_object_t *p_this );

gbazin's avatar
   
gbazin committed
99
100
101
102
103
104
/*****************************************************************************
 * Callback prototypes
 *****************************************************************************/
static int FilterCallback ( vlc_object_t *, char const *,
                            vlc_value_t, vlc_value_t, void * );

105
106
107
/*****************************************************************************
 * Module descriptor
 *****************************************************************************/
Christophe Massiot's avatar
Christophe Massiot committed
108
#define MODE_TEXT N_("Deinterlace mode")
109
#define MODE_LONGTEXT N_("Deinterlace method to use for local playback.")
zorglub's avatar
zorglub committed
110

111
112
#define SOUT_MODE_TEXT N_("Streaming deinterlace mode")
#define SOUT_MODE_LONGTEXT N_("Deinterlace method to use for streaming.")
113

114
115
#define FILTER_CFG_PREFIX "sout-deinterlace-"

116
static char *mode_list[] = { "discard", "blend", "mean", "bob", "linear", "x" };
hartman's avatar
hartman committed
117
static char *mode_list_text[] = { N_("Discard"), N_("Blend"), N_("Mean"),
118
                                  N_("Bob"), N_("Linear"), "X" };
119
120

vlc_module_begin();
hartman's avatar
hartman committed
121
    set_description( _("Deinterlacing video filter") );
122
    set_shortname( N_("Deinterlace" ));
hartman's avatar
hartman committed
123
    set_capability( "video filter", 0 );
zorglub's avatar
zorglub committed
124
125
    set_category( CAT_VIDEO );
    set_subcategory( SUBCAT_VIDEO_VFILTER );
hartman's avatar
hartman committed
126

Christophe Mutricy's avatar
Christophe Mutricy committed
127
    set_section( N_("Display"),NULL);
128
129
130
    add_string( "deinterlace-mode", "discard", NULL, MODE_TEXT,
                MODE_LONGTEXT, VLC_FALSE );
        change_string_list( mode_list, mode_list_text, 0 );
hartman's avatar
hartman committed
131

132
133
    add_shortcut( "deinterlace" );
    set_callbacks( Create, Destroy );
134
135
136

    add_submodule();
    set_capability( "video filter2", 0 );
hartman's avatar
hartman committed
137
    set_section( N_("Streaming"),NULL);
zorglub's avatar
zorglub committed
138
139
    add_string( FILTER_CFG_PREFIX "mode", "blend", NULL, SOUT_MODE_TEXT,
                SOUT_MODE_LONGTEXT, VLC_FALSE );
140
141
        change_string_list( mode_list, mode_list_text, 0 );
    set_callbacks( OpenFilter, CloseFilter );
142
143
vlc_module_end();

144
145
146
147
static const char *ppsz_filter_options[] = {
    "mode", NULL
};

148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*****************************************************************************
 * vout_sys_t: Deinterlace video output method descriptor
 *****************************************************************************
 * This structure is part of the video output thread descriptor.
 * It describes the Deinterlace specific properties of an output thread.
 *****************************************************************************/
struct vout_sys_t
{
    int        i_mode;        /* Deinterlace mode */
    vlc_bool_t b_double_rate; /* Shall we double the framerate? */

    mtime_t    last_date;
    mtime_t    next_date;

    vout_thread_t *p_vout;
gbazin's avatar
   
gbazin committed
163
164

    vlc_mutex_t filter_lock;
165
166

    void (*pf_merge) ( void *, const void *, const void *, size_t );
sigmunau's avatar
sigmunau committed
167
    void (*pf_end_merge) ( void );
168
169
};

170
171
172
173
174
175
176
177
/*****************************************************************************
 * Control: control facility for the vout (forwards to child vout)
 *****************************************************************************/
static int Control( vout_thread_t *p_vout, int i_query, va_list args )
{
    return vout_vaControl( p_vout->p_sys->p_vout, i_query, args );
}

178
179
180
181
182
183
/*****************************************************************************
 * Create: allocates Deinterlace video thread output method
 *****************************************************************************
 * This function allocates and initializes a Deinterlace vout method.
 *****************************************************************************/
static int Create( vlc_object_t *p_this )
184
{
185
    vout_thread_t *p_vout = (vout_thread_t *)p_this;
gbazin's avatar
   
gbazin committed
186
    vlc_value_t val;
187
188
189
190
191
192

    /* Allocate structure */
    p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
    if( p_vout->p_sys == NULL )
    {
        msg_Err( p_vout, "out of memory" );
193
        return VLC_ENOMEM;
194
195
196
197
198
199
200
    }

    p_vout->pf_init = Init;
    p_vout->pf_end = End;
    p_vout->pf_manage = NULL;
    p_vout->pf_render = Render;
    p_vout->pf_display = NULL;
201
    p_vout->pf_control = Control;
202
203

    p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
204
    p_vout->p_sys->b_double_rate = VLC_FALSE;
205
    p_vout->p_sys->last_date = 0;
206
    p_vout->p_sys->p_vout = 0;
gbazin's avatar
   
gbazin committed
207
    vlc_mutex_init( p_vout, &p_vout->p_sys->filter_lock );
208

sigmunau's avatar
sigmunau committed
209
#if defined(CAN_COMPILE_C_ALTIVEC)
210
211
212
    if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC )
    {
        p_vout->p_sys->pf_merge = MergeAltivec;
sigmunau's avatar
sigmunau committed
213
214
        p_vout->p_sys->pf_end_merge = NULL;
    }
215
    else
sigmunau's avatar
sigmunau committed
216
#endif
Eric Petit's avatar
Eric Petit committed
217
#if defined(CAN_COMPILE_SSE)
sigmunau's avatar
sigmunau committed
218
    if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_SSE2 )
sigmunau's avatar
sigmunau committed
219
    {
sigmunau's avatar
sigmunau committed
220
        p_vout->p_sys->pf_merge = MergeSSE2;
sigmunau's avatar
sigmunau committed
221
222
        p_vout->p_sys->pf_end_merge = EndMMX;
    }
sigmunau's avatar
sigmunau committed
223
224
    else
#endif
225
#if defined(CAN_COMPILE_MMXEXT)
226
    if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_MMXEXT )
sigmunau's avatar
sigmunau committed
227
    {
228
        p_vout->p_sys->pf_merge = MergeMMXEXT;
sigmunau's avatar
sigmunau committed
229
        p_vout->p_sys->pf_end_merge = EndMMX;
230
231
    }
    else
232
233
234
235
236
237
238
239
#endif
#if defined(CAN_COMPILE_3DNOW)
    if( p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_3DNOW )
    {
        p_vout->p_sys->pf_merge = Merge3DNow;
        p_vout->p_sys->pf_end_merge = End3DNow;
    }
    else
240
#endif
241
242
    {
        p_vout->p_sys->pf_merge = MergeGeneric;
sigmunau's avatar
sigmunau committed
243
        p_vout->p_sys->pf_end_merge = NULL;
244
245
    }

246
    /* Look what method was requested */
gbazin's avatar
   
gbazin committed
247
    var_Create( p_vout, "deinterlace-mode", VLC_VAR_STRING );
gbazin's avatar
   
gbazin committed
248
    var_Change( p_vout, "deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL );
gbazin's avatar
   
gbazin committed
249
250

    if( val.psz_string == NULL )
251
    {
gbazin's avatar
   
gbazin committed
252
        msg_Err( p_vout, "configuration variable deinterlace-mode empty" );
253
254
        msg_Err( p_vout, "no deinterlace mode provided, using \"discard\"" );

gbazin's avatar
   
gbazin committed
255
        val.psz_string = strdup( "discard" );
256
257
    }

gbazin's avatar
   
gbazin committed
258
    msg_Dbg( p_vout, "using %s deinterlace mode", val.psz_string );
gbazin's avatar
   
gbazin committed
259
260
261
262
263

    SetFilterMethod( p_vout, val.psz_string );

    free( val.psz_string );

264
    return VLC_SUCCESS;
265
266
}

gbazin's avatar
   
gbazin committed
267
268
269
270
271
272
273
274
/*****************************************************************************
 * SetFilterMethod: setup the deinterlace method to use.
 *****************************************************************************/
static void SetFilterMethod( vout_thread_t *p_vout, char *psz_method )
{
    if( !strcmp( psz_method, "discard" ) )
    {
        p_vout->p_sys->i_mode = DEINTERLACE_DISCARD;
275
        p_vout->p_sys->b_double_rate = VLC_FALSE;
gbazin's avatar
   
gbazin committed
276
277
278
279
    }
    else if( !strcmp( psz_method, "mean" ) )
    {
        p_vout->p_sys->i_mode = DEINTERLACE_MEAN;
280
        p_vout->p_sys->b_double_rate = VLC_FALSE;
gbazin's avatar
   
gbazin committed
281
282
283
284
285
286
    }
    else if( !strcmp( psz_method, "blend" )
             || !strcmp( psz_method, "average" )
             || !strcmp( psz_method, "combine-fields" ) )
    {
        p_vout->p_sys->i_mode = DEINTERLACE_BLEND;
287
        p_vout->p_sys->b_double_rate = VLC_FALSE;
gbazin's avatar
   
gbazin committed
288
289
290
291
292
    }
    else if( !strcmp( psz_method, "bob" )
             || !strcmp( psz_method, "progressive-scan" ) )
    {
        p_vout->p_sys->i_mode = DEINTERLACE_BOB;
293
        p_vout->p_sys->b_double_rate = VLC_TRUE;
gbazin's avatar
   
gbazin committed
294
295
296
297
    }
    else if( !strcmp( psz_method, "linear" ) )
    {
        p_vout->p_sys->i_mode = DEINTERLACE_LINEAR;
298
        p_vout->p_sys->b_double_rate = VLC_TRUE;
gbazin's avatar
   
gbazin committed
299
    }
300
301
302
    else if( !strcmp( psz_method, "x" ) )
    {
        p_vout->p_sys->i_mode = DEINTERLACE_X;
303
        p_vout->p_sys->b_double_rate = VLC_FALSE;
304
    }
gbazin's avatar
   
gbazin committed
305
306
307
308
309
    else
    {
        msg_Err( p_vout, "no valid deinterlace mode provided, "
                 "using \"discard\"" );
    }
gbazin's avatar
   
gbazin committed
310
311

    msg_Dbg( p_vout, "using %s deinterlace method", psz_method );
gbazin's avatar
   
gbazin committed
312
313
}

314
315
316
317
318
319
320
/*****************************************************************************
 * Init: initialize Deinterlace video thread output method
 *****************************************************************************/
static int Init( vout_thread_t *p_vout )
{
    int i_index;
    picture_t *p_pic;
321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
    I_OUTPUTPICTURES = 0;

    /* Initialize the output structure, full of directbuffers since we want
     * the decoder to output directly to our structures. */
    switch( p_vout->render.i_chroma )
    {
        case VLC_FOURCC('I','4','2','0'):
        case VLC_FOURCC('I','Y','U','V'):
        case VLC_FOURCC('Y','V','1','2'):
        case VLC_FOURCC('I','4','2','2'):
            p_vout->output.i_chroma = p_vout->render.i_chroma;
            p_vout->output.i_width  = p_vout->render.i_width;
            p_vout->output.i_height = p_vout->render.i_height;
            p_vout->output.i_aspect = p_vout->render.i_aspect;
336
            p_vout->fmt_out = p_vout->fmt_in;
337
338
339
            break;

        default:
340
            return VLC_EGENERIC; /* unknown chroma */
341
342
343
            break;
    }

gbazin's avatar
   
gbazin committed
344
345
346
347
348
349
350
351
352
353
354
    /* Try to open the real video output */
    p_vout->p_sys->p_vout = SpawnRealVout( p_vout );

    if( p_vout->p_sys->p_vout == NULL )
    {
        /* Everything failed */
        msg_Err( p_vout, "cannot open vout, aborting" );

        return VLC_EGENERIC;
    }

355
356
    var_AddCallback( p_vout, "deinterlace-mode", FilterCallback, NULL );

gbazin's avatar
   
gbazin committed
357
358
359
360
    ALLOCATE_DIRECTBUFFERS( VOUT_MAX_PICTURES );

    ADD_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );

gbazin's avatar
   
gbazin committed
361
362
    ADD_PARENT_CALLBACKS( SendEventsToChild );

gbazin's avatar
   
gbazin committed
363
364
365
366
367
368
369
370
371
    return VLC_SUCCESS;
}

/*****************************************************************************
 * SpawnRealVout: spawn the real video output.
 *****************************************************************************/
static vout_thread_t *SpawnRealVout( vout_thread_t *p_vout )
{
    vout_thread_t *p_real_vout = NULL;
372
    video_format_t fmt = {0};
gbazin's avatar
   
gbazin committed
373

374
375
    msg_Dbg( p_vout, "spawning the real video output" );

376
    fmt = p_vout->fmt_out;
377

378
379
380
381
382
383
384
385
386
    switch( p_vout->render.i_chroma )
    {
    case VLC_FOURCC('I','4','2','0'):
    case VLC_FOURCC('I','Y','U','V'):
    case VLC_FOURCC('Y','V','1','2'):
        switch( p_vout->p_sys->i_mode )
        {
        case DEINTERLACE_MEAN:
        case DEINTERLACE_DISCARD:
387
            fmt.i_height /= 2; fmt.i_visible_height /= 2; fmt.i_y_offset /= 2;
388
            fmt.i_sar_den *= 2;
389
            p_real_vout = vout_Create( p_vout, &fmt );
390
391
            break;

392
        case DEINTERLACE_BOB:
393
394
        case DEINTERLACE_BLEND:
        case DEINTERLACE_LINEAR:
395
        case DEINTERLACE_X:
396
            p_real_vout = vout_Create( p_vout, &fmt );
397
398
399
400
401
            break;
        }
        break;

    case VLC_FOURCC('I','4','2','2'):
402
403
        fmt.i_chroma = VLC_FOURCC('I','4','2','0');
        p_real_vout = vout_Create( p_vout, &fmt );
404
405
406
407
408
409
        break;

    default:
        break;
    }

gbazin's avatar
   
gbazin committed
410
    return p_real_vout;
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
}

/*****************************************************************************
 * End: terminate Deinterlace video thread output method
 *****************************************************************************/
static void End( vout_thread_t *p_vout )
{
    int i_index;

    /* Free the fake output buffers we allocated */
    for( i_index = I_OUTPUTPICTURES ; i_index ; )
    {
        i_index--;
        free( PP_OUTPUTPICTURE[ i_index ]->p_data_orig );
    }

427
428
429
430
431
432
    if( p_vout->p_sys->p_vout )
    {
        DEL_CALLBACKS( p_vout->p_sys->p_vout, SendEvents );
        vlc_object_detach( p_vout->p_sys->p_vout );
        vout_Destroy( p_vout->p_sys->p_vout );
    }
433

gbazin's avatar
   
gbazin committed
434
    DEL_PARENT_CALLBACKS( SendEventsToChild );
435
}
gbazin's avatar
   
gbazin committed
436

437
438
439
440
441
442
443
444
445
/*****************************************************************************
 * Destroy: destroy Deinterlace video thread output method
 *****************************************************************************
 * Terminate an output method created by DeinterlaceCreateOutputMethod
 *****************************************************************************/
static void Destroy( vlc_object_t *p_this )
{
    vout_thread_t *p_vout = (vout_thread_t *)p_this;
    vlc_mutex_destroy( &p_vout->p_sys->filter_lock );
446
447
448
449
450
451
452
453
454
455
456
457
    free( p_vout->p_sys );
}

/*****************************************************************************
 * Render: displays previously rendered output
 *****************************************************************************
 * This function send the currently rendered image to Deinterlace image,
 * waits until it is displayed and switch the two rendering buffers, preparing
 * next frame.
 *****************************************************************************/
static void Render ( vout_thread_t *p_vout, picture_t *p_pic )
{
458
    vout_sys_t *p_sys = p_vout->p_sys;
459
460
    picture_t *pp_outpic[2];

461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
    p_vout->fmt_out.i_x_offset = p_sys->p_vout->fmt_in.i_x_offset =
        p_vout->fmt_in.i_x_offset;
    p_vout->fmt_out.i_y_offset = p_sys->p_vout->fmt_in.i_y_offset =
        p_vout->fmt_in.i_y_offset;
    p_vout->fmt_out.i_visible_width = p_sys->p_vout->fmt_in.i_visible_width =
        p_vout->fmt_in.i_visible_width;
    p_vout->fmt_out.i_visible_height = p_sys->p_vout->fmt_in.i_visible_height =
        p_vout->fmt_in.i_visible_height;
    if( p_vout->p_sys->i_mode == DEINTERLACE_MEAN ||
        p_vout->p_sys->i_mode == DEINTERLACE_DISCARD )
    {
        p_vout->fmt_out.i_y_offset /= 2; p_sys->p_vout->fmt_in.i_y_offset /= 2;
        p_vout->fmt_out.i_visible_height /= 2;
        p_sys->p_vout->fmt_in.i_visible_height /= 2;
    }
 
477
478
    pp_outpic[0] = pp_outpic[1] = NULL;

gbazin's avatar
   
gbazin committed
479
480
    vlc_mutex_lock( &p_vout->p_sys->filter_lock );

481
482
    /* Get a new picture */
    while( ( pp_outpic[0] = vout_CreatePicture( p_vout->p_sys->p_vout,
483
                                                0, 0, 0 ) )
484
485
486
487
              == NULL )
    {
        if( p_vout->b_die || p_vout->b_error )
        {
gbazin's avatar
   
gbazin committed
488
            vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
489
490
491
            return;
        }
        msleep( VOUT_OUTMEM_SLEEP );
492
    }
493
494
495
496
497
498
499
500
501
502
503
504
505

    vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[0], p_pic->date );

    /* If we are using double rate, get an additional new picture */
    if( p_vout->p_sys->b_double_rate )
    {
        while( ( pp_outpic[1] = vout_CreatePicture( p_vout->p_sys->p_vout,
                                                 0, 0, 0 ) )
                  == NULL )
        {
            if( p_vout->b_die || p_vout->b_error )
            {
                vout_DestroyPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
gbazin's avatar
   
gbazin committed
506
                vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
507
508
                return;
            }
509
            msleep( VOUT_OUTMEM_SLEEP );
510
        }
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528

        /* 20ms is a bit arbitrary, but it's only for the first image we get */
        if( !p_vout->p_sys->last_date )
        {
            vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
                              p_pic->date + 20000 );
        }
        else
        {
            vout_DatePicture( p_vout->p_sys->p_vout, pp_outpic[1],
                      (3 * p_pic->date - p_vout->p_sys->last_date) / 2 );
        }
        p_vout->p_sys->last_date = p_pic->date;
    }

    switch( p_vout->p_sys->i_mode )
    {
        case DEINTERLACE_DISCARD:
529
            RenderDiscard( p_vout, pp_outpic[0], p_pic, 0 );
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
            break;

        case DEINTERLACE_BOB:
            RenderBob( p_vout, pp_outpic[0], p_pic, 0 );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
            RenderBob( p_vout, pp_outpic[1], p_pic, 1 );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
            break;

        case DEINTERLACE_LINEAR:
            RenderLinear( p_vout, pp_outpic[0], p_pic, 0 );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
            RenderLinear( p_vout, pp_outpic[1], p_pic, 1 );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[1] );
            break;

        case DEINTERLACE_MEAN:
            RenderMean( p_vout, pp_outpic[0], p_pic );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
            break;

        case DEINTERLACE_BLEND:
            RenderBlend( p_vout, pp_outpic[0], p_pic );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
            break;
gbazin's avatar
   
gbazin committed
556

557
558
559
560
561
        case DEINTERLACE_X:
            RenderX( p_vout, pp_outpic[0], p_pic );
            vout_DisplayPicture( p_vout->p_sys->p_vout, pp_outpic[0] );
            break;
    }
gbazin's avatar
   
gbazin committed
562
    vlc_mutex_unlock( &p_vout->p_sys->filter_lock );
563
564
565
}

/*****************************************************************************
566
 * RenderDiscard: only keep TOP or BOTTOM field, discard the other.
567
 *****************************************************************************/
568
569
static void RenderDiscard( vout_thread_t *p_vout,
                           picture_t *p_outpic, picture_t *p_pic, int i_field )
570
571
572
573
574
575
{
    int i_plane;

    /* Copy image and skip lines */
    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
    {
576
        uint8_t *p_in, *p_out_end, *p_out;
577
578
579
580
581
582
583
        int i_increment;

        p_in = p_pic->p[i_plane].p_pixels
                   + i_field * p_pic->p[i_plane].i_pitch;

        p_out = p_outpic->p[i_plane].p_pixels;
        p_out_end = p_out + p_outpic->p[i_plane].i_pitch
584
                             * p_outpic->p[i_plane].i_visible_lines;
585
586
587
588
589
590
591
592
593
594
595
596

        switch( p_vout->render.i_chroma )
        {
        case VLC_FOURCC('I','4','2','0'):
        case VLC_FOURCC('I','Y','U','V'):
        case VLC_FOURCC('Y','V','1','2'):

            for( ; p_out < p_out_end ; )
            {
                p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                          p_pic->p[i_plane].i_pitch );

597
                p_out += p_outpic->p[i_plane].i_pitch;
598
599
600
601
602
603
604
605
606
607
608
609
610
611
                p_in += 2 * p_pic->p[i_plane].i_pitch;
            }
            break;

        case VLC_FOURCC('I','4','2','2'):

            i_increment = 2 * p_pic->p[i_plane].i_pitch;

            if( i_plane == Y_PLANE )
            {
                for( ; p_out < p_out_end ; )
                {
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
612
                    p_out += p_outpic->p[i_plane].i_pitch;
613
614
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
615
                    p_out += p_outpic->p[i_plane].i_pitch;
616
617
618
619
620
621
622
623
624
                    p_in += i_increment;
                }
            }
            else
            {
                for( ; p_out < p_out_end ; )
                {
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
625
                    p_out += p_outpic->p[i_plane].i_pitch;
626
627
628
629
630
631
632
633
634
635
636
637
                    p_in += i_increment;
                }
            }
            break;

        default:
            break;
        }
    }
}

/*****************************************************************************
638
639
640
641
642
 * RenderBob: renders a BOB picture - simple copy
 *****************************************************************************/
static void RenderBob( vout_thread_t *p_vout,
                       picture_t *p_outpic, picture_t *p_pic, int i_field )
{
643
    int i_plane;
644
645
646
647

    /* Copy image and skip lines */
    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
    {
648
        uint8_t *p_in, *p_out_end, *p_out;
649
650
651
652

        p_in = p_pic->p[i_plane].p_pixels;
        p_out = p_outpic->p[i_plane].p_pixels;
        p_out_end = p_out + p_outpic->p[i_plane].i_pitch
653
                             * p_outpic->p[i_plane].i_visible_lines;
654

655
        switch( p_vout->render.i_chroma )
656
        {
657
658
659
660
661
662
663
664
665
            case VLC_FOURCC('I','4','2','0'):
            case VLC_FOURCC('I','Y','U','V'):
            case VLC_FOURCC('Y','V','1','2'):
                /* For BOTTOM field we need to add the first line */
                if( i_field == 1 )
                {
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
                    p_in += p_pic->p[i_plane].i_pitch;
666
                    p_out += p_outpic->p[i_plane].i_pitch;
667
                }
668

669
                p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
670

671
672
673
674
                for( ; p_out < p_out_end ; )
                {
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
675

676
                    p_out += p_outpic->p[i_plane].i_pitch;
677

678
679
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
680

681
                    p_in += 2 * p_pic->p[i_plane].i_pitch;
682
                    p_out += p_outpic->p[i_plane].i_pitch;
683
                }
684

685
686
                p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                          p_pic->p[i_plane].i_pitch );
687

688
689
690
691
                /* For TOP field we need to add the last line */
                if( i_field == 0 )
                {
                    p_in += p_pic->p[i_plane].i_pitch;
692
                    p_out += p_outpic->p[i_plane].i_pitch;
693
694
695
696
697
698
699
700
701
702
703
704
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
                }
                break;

            case VLC_FOURCC('I','4','2','2'):
                /* For BOTTOM field we need to add the first line */
                if( i_field == 1 )
                {
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
                    p_in += p_pic->p[i_plane].i_pitch;
705
                    p_out += p_outpic->p[i_plane].i_pitch;
706
707
708
709
710
711
712
713
714
715
716
                }

                p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;

                if( i_plane == Y_PLANE )
                {
                    for( ; p_out < p_out_end ; )
                    {
                        p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                                  p_pic->p[i_plane].i_pitch );

717
                        p_out += p_outpic->p[i_plane].i_pitch;
718
719
720
721
722

                        p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                                  p_pic->p[i_plane].i_pitch );

                        p_in += 2 * p_pic->p[i_plane].i_pitch;
723
                        p_out += p_outpic->p[i_plane].i_pitch;
724
725
726
727
728
729
730
731
732
                    }
                }
                else
                {
                    for( ; p_out < p_out_end ; )
                    {
                        p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                                  p_pic->p[i_plane].i_pitch );

733
                        p_out += p_outpic->p[i_plane].i_pitch;
734
735
736
737
738
739
740
741
742
743
744
                        p_in += 2 * p_pic->p[i_plane].i_pitch;
                    }
                }

                p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                          p_pic->p[i_plane].i_pitch );

                /* For TOP field we need to add the last line */
                if( i_field == 0 )
                {
                    p_in += p_pic->p[i_plane].i_pitch;
745
                    p_out += p_outpic->p[i_plane].i_pitch;
746
747
748
749
                    p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                              p_pic->p[i_plane].i_pitch );
                }
                break;
750
        }
751
752
753
    }
}

754
#define Merge p_vout->p_sys->pf_merge
sigmunau's avatar
sigmunau committed
755
#define EndMerge if(p_vout->p_sys->pf_end_merge) p_vout->p_sys->pf_end_merge
756

757
758
/*****************************************************************************
 * RenderLinear: BOB with linear interpolation
759
760
761
762
763
764
765
766
767
 *****************************************************************************/
static void RenderLinear( vout_thread_t *p_vout,
                          picture_t *p_outpic, picture_t *p_pic, int i_field )
{
    int i_plane;

    /* Copy image and skip lines */
    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
    {
768
        uint8_t *p_in, *p_out_end, *p_out;
769

770
        p_in = p_pic->p[i_plane].p_pixels;
771
772
        p_out = p_outpic->p[i_plane].p_pixels;
        p_out_end = p_out + p_outpic->p[i_plane].i_pitch
773
                             * p_outpic->p[i_plane].i_visible_lines;
774

775
776
        /* For BOTTOM field we need to add the first line */
        if( i_field == 1 )
777
778
779
        {
            p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                      p_pic->p[i_plane].i_pitch );
780
            p_in += p_pic->p[i_plane].i_pitch;
781
            p_out += p_outpic->p[i_plane].i_pitch;
782
783
        }

784
        p_out_end -= 2 * p_outpic->p[i_plane].i_pitch;
785
786
787
788
789
790

        for( ; p_out < p_out_end ; )
        {
            p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                      p_pic->p[i_plane].i_pitch );

791
            p_out += p_outpic->p[i_plane].i_pitch;
792
793
794
795
796

            Merge( p_out, p_in, p_in + 2 * p_pic->p[i_plane].i_pitch,
                   p_pic->p[i_plane].i_pitch );

            p_in += 2 * p_pic->p[i_plane].i_pitch;
797
            p_out += p_outpic->p[i_plane].i_pitch;
798
799
        }

800
801
802
803
        p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                  p_pic->p[i_plane].i_pitch );

        /* For TOP field we need to add the last line */
804
805
        if( i_field == 0 )
        {
806
            p_in += p_pic->p[i_plane].i_pitch;
807
            p_out += p_outpic->p[i_plane].i_pitch;
808
809
810
811
            p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                      p_pic->p[i_plane].i_pitch );
        }
    }
sigmunau's avatar
sigmunau committed
812
    EndMerge();
813
814
815
816
817
818
819
820
821
822
}

static void RenderMean( vout_thread_t *p_vout,
                        picture_t *p_outpic, picture_t *p_pic )
{
    int i_plane;

    /* Copy image and skip lines */
    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
    {
823
        uint8_t *p_in, *p_out_end, *p_out;
824
825
826
827
828

        p_in = p_pic->p[i_plane].p_pixels;

        p_out = p_outpic->p[i_plane].p_pixels;
        p_out_end = p_out + p_outpic->p[i_plane].i_pitch
829
                             * p_outpic->p[i_plane].i_visible_lines;
830
831
832
833
834
835
836

        /* All lines: mean value */
        for( ; p_out < p_out_end ; )
        {
            Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
                   p_pic->p[i_plane].i_pitch );

837
            p_out += p_outpic->p[i_plane].i_pitch;
838
839
840
            p_in += 2 * p_pic->p[i_plane].i_pitch;
        }
    }
sigmunau's avatar
sigmunau committed
841
    EndMerge();
842
843
844
845
846
847
}

static void RenderBlend( vout_thread_t *p_vout,
                         picture_t *p_outpic, picture_t *p_pic )
{
    int i_plane;
848

849
850
851
    /* Copy image and skip lines */
    for( i_plane = 0 ; i_plane < p_pic->i_planes ; i_plane++ )
    {
852
        uint8_t *p_in, *p_out_end, *p_out;
853
854
855
856
857

        p_in = p_pic->p[i_plane].p_pixels;

        p_out = p_outpic->p[i_plane].p_pixels;
        p_out_end = p_out + p_outpic->p[i_plane].i_pitch
858
                             * p_outpic->p[i_plane].i_visible_lines;
859

860
        switch( p_vout->render.i_chroma )
861
        {
862
863
864
865
866
867
            case VLC_FOURCC('I','4','2','0'):
            case VLC_FOURCC('I','Y','U','V'):
            case VLC_FOURCC('Y','V','1','2'):
                /* First line: simple copy */
                p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                          p_pic->p[i_plane].i_pitch );
868
                p_out += p_outpic->p[i_plane].i_pitch;
869

870
871
872
                /* Remaining lines: mean value */
                for( ; p_out < p_out_end ; )
                {
873
874
                    Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
                           p_pic->p[i_plane].i_pitch );
875

876
                    p_out += p_outpic->p[i_plane].i_pitch;
877
878
879
880
881
882
883
884
                    p_in += p_pic->p[i_plane].i_pitch;
                }
                break;

            case VLC_FOURCC('I','4','2','2'):
                /* First line: simple copy */
                p_vout->p_vlc->pf_memcpy( p_out, p_in,
                                          p_pic->p[i_plane].i_pitch );
885
                p_out += p_outpic->p[i_plane].i_pitch;
886
887
888
889
890
891
892
893
894

                /* Remaining lines: mean value */
                if( i_plane == Y_PLANE )
                {
                    for( ; p_out < p_out_end ; )
                    {
                        Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
                               p_pic->p[i_plane].i_pitch );

895
                        p_out += p_outpic->p[i_plane].i_pitch;
896
897
898
899
900
901
902
903
904
905
906
                        p_in += p_pic->p[i_plane].i_pitch;
                    }
                }

                else
                {
                    for( ; p_out < p_out_end ; )
                    {
                        Merge( p_out, p_in, p_in + p_pic->p[i_plane].i_pitch,
                               p_pic->p[i_plane].i_pitch );

907
                        p_out += p_outpic->p[i_plane].i_pitch;
908
909
910
911
                        p_in += 2*p_pic->p[i_plane].i_pitch;
                    }
                }
                break;
912
913
        }
    }
sigmunau's avatar
sigmunau committed
914
    EndMerge();
915
916
}

917
918
919
920
#undef Merge

static void MergeGeneric( void *_p_dest, const void *_p_s1,
                          const void *_p_s2, size_t i_bytes )
921
{
922
923
924
925
    uint8_t* p_dest = (uint8_t*)_p_dest;
    const uint8_t *p_s1 = (const uint8_t *)_p_s1;
    const uint8_t *p_s2 = (const uint8_t *)_p_s2;
    uint8_t* p_end = p_dest + i_bytes - 8;
926

927
    while( p_dest < p_end )
928
    {
929
930
931
932
933
934
935
936
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
937
938
939
940
    }

    p_end += 8;

941
942
943
944
945
946
    while( p_dest < p_end )
    {
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
    }
}

947
#if defined(CAN_COMPILE_MMXEXT)
948
949
static void MergeMMXEXT( void *_p_dest, const void *_p_s1, const void *_p_s2,
                         size_t i_bytes )
sigmunau's avatar
sigmunau committed
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
{
    uint8_t* p_dest = (uint8_t*)_p_dest;
    const uint8_t *p_s1 = (const uint8_t *)_p_s1;
    const uint8_t *p_s2 = (const uint8_t *)_p_s2;
    uint8_t* p_end = p_dest + i_bytes - 8;
    while( p_dest < p_end )
    {
        __asm__  __volatile__( "movq %2,%%mm1;"
                               "pavgb %1, %%mm1;"
                               "movq %%mm1, %0" :"=m" (*p_dest):
                                                 "m" (*p_s1),
                                                 "m" (*p_s2) );
        p_dest += 8;
        p_s1 += 8;
        p_s2 += 8;
    }

    p_end += 8;

    while( p_dest < p_end )
    {
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
    }
}
sigmunau's avatar
sigmunau committed
974
#endif
sigmunau's avatar
sigmunau committed
975

976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
#if defined(CAN_COMPILE_3DNOW)
static void Merge3DNow( void *_p_dest, const void *_p_s1, const void *_p_s2,
                        size_t i_bytes )
{
    uint8_t* p_dest = (uint8_t*)_p_dest;
    const uint8_t *p_s1 = (const uint8_t *)_p_s1;
    const uint8_t *p_s2 = (const uint8_t *)_p_s2;
    uint8_t* p_end = p_dest + i_bytes - 8;
    while( p_dest < p_end )
    {
        __asm__  __volatile__( "movq %2,%%mm1;"
                               "pavgusb %1, %%mm1;"
                               "movq %%mm1, %0" :"=m" (*p_dest):
                                                 "m" (*p_s1),
                                                 "m" (*p_s2) );
        p_dest += 8;
        p_s1 += 8;
        p_s2 += 8;
    }

    p_end += 8;

    while( p_dest < p_end )
    {
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
    }
}
#endif

Eric Petit's avatar
Eric Petit committed
1005
#if defined(CAN_COMPILE_SSE)
sigmunau's avatar
sigmunau committed
1006
1007
1008
1009
1010
1011
static void MergeSSE2( void *_p_dest, const void *_p_s1, const void *_p_s2,
                       size_t i_bytes )
{
    uint8_t* p_dest = (uint8_t*)_p_dest;
    const uint8_t *p_s1 = (const uint8_t *)_p_s1;
    const uint8_t *p_s2 = (const uint8_t *)_p_s2;
1012
    uint8_t* p_end;
1013
    while( (ptrdiff_t)p_s1 % 16 )
1014
1015
1016
    {
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
    }        
1017
    p_end = p_dest + i_bytes - 16;
sigmunau's avatar
sigmunau committed
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
    while( p_dest < p_end )
    {
        __asm__  __volatile__( "movdqu %2,%%xmm1;"
                               "pavgb %1, %%xmm1;"
                               "movdqu %%xmm1, %0" :"=m" (*p_dest):
                                                 "m" (*p_s1),
                                                 "m" (*p_s2) );
        p_dest += 16;
        p_s1 += 16;
        p_s2 += 16;
    }

    p_end += 16;

    while( p_dest < p_end )
    {
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
    }
}
sigmunau's avatar
sigmunau committed
1037
#endif
sigmunau's avatar
sigmunau committed
1038

1039
#if defined(CAN_COMPILE_MMXEXT) || defined(CAN_COMPILE_SSE)
sigmunau's avatar
sigmunau committed
1040
1041
1042
1043
static void EndMMX( void )
{
    __asm__ __volatile__( "emms" :: );
}
sigmunau's avatar
sigmunau committed
1044
#endif
sigmunau's avatar
sigmunau committed
1045

1046
1047
1048
1049
1050
1051
1052
#if defined(CAN_COMPILE_3DNOW)
static void End3DNow( void )
{
    __asm__ __volatile__( "femms" :: );
}
#endif

sigmunau's avatar
sigmunau committed
1053
#ifdef CAN_COMPILE_C_ALTIVEC
1054
1055
1056
static void MergeAltivec( void *_p_dest, const void *_p_s1,
                          const void *_p_s2, size_t i_bytes )
{
1057
1058
1059
1060
    uint8_t *p_dest = (uint8_t *)_p_dest;
    uint8_t *p_s1   = (uint8_t *)_p_s1;
    uint8_t *p_s2   = (uint8_t *)_p_s2;
    uint8_t *p_end  = p_dest + i_bytes - 15;
1061

1062
1063
    /* Use C until the first 16-bytes aligned destination pixel */
    while( (int)p_dest & 0xF )
1064
    {
1065
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
1066
1067
    }

1068
    if( ( (int)p_s1 & 0xF ) | ( (int)p_s2 & 0xF ) )
1069
    {
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
        /* Unaligned source */
        vector unsigned char s1v, s2v, destv;
        vector unsigned char s1oldv, s2oldv, s1newv, s2newv;
        vector unsigned char perm1v, perm2v;

        perm1v = vec_lvsl( 0, p_s1 );
        perm2v = vec_lvsl( 0, p_s2 );
        s1oldv = vec_ld( 0, p_s1 );
        s2oldv = vec_ld( 0, p_s2 );

        while( p_dest < p_end )
        {
            s1newv = vec_ld( 16, p_s1 );
            s2newv = vec_ld( 16, p_s2 );
            s1v    = vec_perm( s1oldv, s1newv, perm1v );
            s2v    = vec_perm( s2oldv, s2newv, perm2v );
            s1oldv = s1newv;
            s2oldv = s2newv;
            destv  = vec_avg( s1v, s2v );
            vec_st( destv, 0, p_dest );

            p_s1   += 16;
            p_s2   += 16;
            p_dest += 16;
        }
1095
    }
1096
1097
1098
1099
    else
    {
        /* Aligned source */
        vector unsigned char s1v, s2v, destv;
1100

1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
        while( p_dest < p_end )
        {
            s1v   = vec_ld( 0, p_s1 );
            s2v   = vec_ld( 0, p_s2 );
            destv = vec_avg( s1v, s2v );
            vec_st( destv, 0, p_dest );

            p_s1   += 16;
            p_s2   += 16;
            p_dest += 16;
        }
    }

    p_end += 15;
1115
1116
1117
1118
1119
1120

    while( p_dest < p_end )
    {
        *p_dest++ = ( (uint16_t)(*p_s1++) + (uint16_t)(*p_s2++) ) >> 1;
    }
}
sigmunau's avatar
sigmunau committed
1121
#endif
1122

1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374