~ubuntu-branches/ubuntu/hardy/avidemux/hardy

« back to all changes in this revision

Viewing changes to avidemux/ADM_video/ADM_vidTelecide.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Matvey Kozhev
  • Date: 2007-12-18 13:53:04 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20071218135304-cdqec2lg2bglyz15
Tags: 1:2.4~preview3-0.0ubuntu1
* Upload to Ubuntu. (LP: #163287, LP: #126572)
* debian/changelog: re-added Ubuntu releases.
* debian/control:
  - Require debhelper >= 5.0.51 (for dh_icons) and imagemagick.
  - Build-depend on libsdl1.2-dev instead of libsdl-dev.
  - Build against newer libx264-dev. (LP: #138854)
  - Removed libamrnb-dev, not in Ubuntu yet.
* debian/rules:
  - Install all icon sizes, using convert (upstream installs none).
  - Added missing calls to dh_installmenu, dh_installman, dh_icons and
    dh_desktop.
* debian/menu, debian/avidemux-qt.menu:
  - Corrected package and executable names.
* debian/avidemux-common.install: Install icons.
* debian/avidemux.common.manpages: Install man/avidemux.1.
* debian/links, debian/avidemux-cli.links, debian/avidemux-gtk.links:
  - Link manpages to avidemux.1.gz.
* debian/install, debian/avidemux-qt.install, debian/avidemux-gtk.desktop,
  debian/avidemux-qt.desktop: Install desktop files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
/***************************************************************************
3
 
                          ADM_vidTelecide.cpp  -  description
4
 
                             -------------------
5
 
        Strongly inspired by Donal Graft deinterlacer (decomb)
6
 
 
7
 
***************************************************************************
8
 
 *                                                                         *
9
 
 *   This program is free software; you can redistribute it and/or modify  *
10
 
 *   it under the terms of the GNU General Public License as published by  *
11
 
 *   the Free Software Foundation; either version 2 of the License, or     *
12
 
 *   (at your option) any later version.                                   *
13
 
 *                                                                         *
14
 
 ***************************************************************************/
15
 
 
16
 
 
17
 
#include <stdio.h>
18
 
#include <stdlib.h>
19
 
#include <string.h>
20
 
#include <ADM_assert.h>
21
 
 
22
 
#include "config.h"
23
 
#include "fourcc.h"
24
 
#include "avio.hxx"
25
 
#include "config.h"
26
 
#include "avi_vars.h"
27
 
#ifdef HAVE_ENCODER
28
 
//#define EVEN_INTERLEAVE       
29
 
 
30
 
#include "ADM_toolkit/toolkit.hxx"
31
 
#include "ADM_editor/ADM_edit.hxx"
32
 
#include "ADM_video/ADM_genvideo.hxx"
33
 
 
34
 
#include"ADM_video/ADM_vidDeinterlace.h"
35
 
#include"ADM_video/ADM_vidTelecide.h"
36
 
#include "ADM_filter/video_filters.h"
37
 
 
38
 
#define MATCH_THRESH 100
39
 
#define ASM_DEINT
40
 
#define ASM_BLEND
41
 
static FILTER_PARAM nullParam={0,{""}};
42
 
 
43
 
 
44
 
SCRIPT_CREATE(telecide_script,ADMVideoTelecide,nullParam);
45
 
extern  int32_t _l_w,_l_h;
46
 
extern uint8_t *_l_p,*_l_c,*_l_n;
47
 
extern uint8_t *_l_e,*_l_e2;
48
 
 
49
 
BUILD_CREATE(telecide_create,ADMVideoTelecide);
50
 
 
51
 
 
52
 
char *ADMVideoTelecide::printConf(void)
53
 
{
54
 
                return (char *)"Pal Smart";;
55
 
}
56
 
 
57
 
//_______________________________________________________________
58
 
 
59
 
 
60
 
ADMVideoTelecide::ADMVideoTelecide(     AVDMGenericVideoStream *in,CONFcouple *setup)
61
 
                                                                                : ADMVideoFields(in,setup)
62
 
{
63
 
        vidCache=new VideoCache(4,in);
64
 
        _uncompressed=new ADMImage(_info.width,_info.height);
65
 
        
66
 
}
67
 
ADMVideoTelecide::~ADMVideoTelecide()
68
 
{
69
 
        
70
 
        delete vidCache;
71
 
        vidCache=NULL;
72
 
        delete _uncompressed;
73
 
        
74
 
}
75
 
/*
76
 
        Interleave _uncompressed with in2
77
 
                even line from in2 odd=0
78
 
      odd  line          odd=1
79
 
*/
80
 
uint8_t ADMVideoTelecide::interleave(   ADMImage *imgsrc, ADMImage *imgdst,uint8_t odd)
81
 
{
82
 
        uint32_t w=_info.width;
83
 
        uint8_t  *src1,*dst;
84
 
        
85
 
        src1=YPLANE(imgsrc);
86
 
        dst=YPLANE(imgdst);
87
 
        if(odd)
88
 
        {
89
 
                src1+=w;
90
 
                dst+=w;
91
 
        }
92
 
        for(uint32_t y=(_info.height>>1);y>0;y--)
93
 
                {
94
 
                        memcpy(dst,src1,w);
95
 
                        src1+=w<<1;
96
 
                        dst+=w<<1;
97
 
                }
98
 
        return 1;
99
 
}
100
 
 
101
 
//
102
 
//              Try to march fields of a frame with previous  / next until it is not interlaced 
103
 
//
104
 
//
105
 
 
106
 
uint8_t ADMVideoTelecide::getFrameNumberNoAlloc(uint32_t frame,
107
 
                        uint32_t *len,
108
 
                        ADMImage *data,
109
 
                        uint32_t *flags)
110
 
{
111
 
uint32_t uvlen;
112
 
uint32_t dummylen;
113
 
uint8_t motion;
114
 
 
115
 
uint32_t        cmatch,nmatch,n2match;
116
 
ADMImage        *cur,*next;
117
 
 
118
 
                        
119
 
                if(frame>=_info.nb_frames) return 0;                    
120
 
                uvlen=    _info.width*_info.height;
121
 
                *len=uvlen+(uvlen>>1);
122
 
                
123
 
                cur=vidCache->getImage(frame);
124
 
                if(!cur) return 0;
125
 
                data->copyInfo(cur);
126
 
                if(!frame || frame==_info.nb_frames-1)
127
 
                {
128
 
 
129
 
                        data->duplicate(cur);
130
 
                        vidCache->unlockAll();
131
 
                        return 1;
132
 
                
133
 
                }
134
 
                
135
 
                next=vidCache->getImage(frame-1);
136
 
                if(!next) 
137
 
                {
138
 
                        vidCache->unlockAll();
139
 
                        return 0;
140
 
                }               
141
 
                
142
 
 
143
 
                // for u & v , no action -> copy it as is
144
 
                memcpy(UPLANE(data),UPLANE(cur),uvlen>>2);
145
 
                memcpy(VPLANE(data),VPLANE(cur),uvlen>>2);
146
 
                data->copyInfo(cur);
147
 
 
148
 
                // No interleaving detected
149
 
                if(!(motion=hasMotion(data)) )
150
 
                {
151
 
                        printf("\n Not interlaced !\n");
152
 
                        memcpy(YPLANE(data),YPLANE(cur),uvlen);
153
 
                        vidCache->unlockAll();
154
 
                        return 1; // over !
155
 
                }
156
 
                // else cmatch is the current match
157
 
                cmatch=getMatch(cur);
158
 
 
159
 
/*      ------------------------------------------------------------------------------------
160
 
                        Try to complete with next frame  fields
161
 
-----------------------------------------------------------------------------------
162
 
*/
163
 
                // Interleav next in even field
164
 
                
165
 
                interleave(cur,_uncompressed,1);
166
 
                interleave(next,_uncompressed,0);
167
 
                nmatch=getMatch(_uncompressed);
168
 
                
169
 
                interleave(cur,_uncompressed,0);
170
 
                interleave(next,_uncompressed,1);
171
 
                n2match=getMatch(_uncompressed);
172
 
 
173
 
                printf(" Cur  : %lu \n",cmatch);
174
 
                printf(" Next : %lu \n",nmatch);
175
 
                printf(" NextP: %lu \n",n2match);
176
 
 
177
 
                if((cmatch<nmatch)&&(cmatch<n2match))
178
 
                {
179
 
                        printf("\n __ pure interlaced __\n");
180
 
                        interleave(cur,_uncompressed,0);
181
 
                        interleave(cur,_uncompressed,1);
182
 
                        hasMotion(_uncompressed);
183
 
                        doBlend(_uncompressed,data);                    
184
 
                        vidCache->unlockAll();
185
 
                        return 1;
186
 
                }
187
 
                if( nmatch > n2match)
188
 
                {
189
 
                        printf("\n -------Shifted-P is better \n");     
190
 
                        if(hasMotion(_uncompressed))
191
 
                        {
192
 
                                 doBlend(_uncompressed,data);
193
 
                                 printf(" but there is still motion \n");
194
 
                        }
195
 
                        else
196
 
                                data->duplicate(_uncompressed);
197
 
 
198
 
                }
199
 
                else
200
 
                {
201
 
                        printf("\n -------Shifted-O is better \n");
202
 
                        interleave(cur,_uncompressed,1);
203
 
                        interleave(next,_uncompressed,0);
204
 
                        if(hasMotion(_uncompressed))
205
 
                        {
206
 
                                 doBlend(_uncompressed,data);
207
 
                                 printf(" but there is still motion \n");
208
 
                        }
209
 
                        else
210
 
                                data->duplicate(_uncompressed);
211
 
                }
212
 
                // which chroma is better ? from current or from next ?
213
 
                // search for a transition and see if there is also one ?
214
 
                vidCache->unlockAll();                          
215
 
                return 1;                                               
216
 
}
217
 
 
218
 
/*
219
 
        Returns the number of difference (interlacing) found
220
 
 
221
 
 
222
 
*/
223
 
uint32_t      ADMVideoTelecide::getMatch( ADMImage *image )
224
 
{
225
 
 
226
 
                        uint32_t m=0,x,y;
227
 
 
228
 
                        uint8_t *p,*n,*c;
229
 
 
230
 
                        p=YPLANE(image) ;
231
 
                        c=p+ _info.width;
232
 
                        n=c+ _info.width;
233
 
                        
234
 
                        for(y=_info.height>>2;  y >2 ; y--)
235
 
                        {
236
 
                                for(x=_info.width;x>0;x--)
237
 
                                {
238
 
                                        if(  (*c-*p)*(*c-*n) >MATCH_THRESH) 
239
 
                                                m++;
240
 
                                        p++;c++;n++;
241
 
                                }
242
 
                                p+=3*_info.width;
243
 
                                c+=3*_info.width;
244
 
                                n+=3*_info.width;
245
 
 
246
 
                        }
247
 
 
248
 
                 return m;
249
 
}
250
 
 
251
 
 
252
 
 
253
 
#endif
254
 
 
255
 
 
256
 
 
257
 
 
258
 
 
259