2
/***************************************************************************
3
ADM_vidTelecide.cpp - description
5
Strongly inspired by Donal Graft deinterlacer (decomb)
7
***************************************************************************
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. *
14
***************************************************************************/
20
#include <ADM_assert.h>
28
//#define EVEN_INTERLEAVE
30
#include "ADM_toolkit/toolkit.hxx"
31
#include "ADM_editor/ADM_edit.hxx"
32
#include "ADM_video/ADM_genvideo.hxx"
34
#include"ADM_video/ADM_vidDeinterlace.h"
35
#include"ADM_video/ADM_vidTelecide.h"
36
#include "ADM_filter/video_filters.h"
38
#define MATCH_THRESH 100
41
static FILTER_PARAM nullParam={0,{""}};
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;
49
BUILD_CREATE(telecide_create,ADMVideoTelecide);
52
char *ADMVideoTelecide::printConf(void)
54
return (char *)"Pal Smart";;
57
//_______________________________________________________________
60
ADMVideoTelecide::ADMVideoTelecide( AVDMGenericVideoStream *in,CONFcouple *setup)
61
: ADMVideoFields(in,setup)
63
vidCache=new VideoCache(4,in);
64
_uncompressed=new ADMImage(_info.width,_info.height);
67
ADMVideoTelecide::~ADMVideoTelecide()
76
Interleave _uncompressed with in2
77
even line from in2 odd=0
80
uint8_t ADMVideoTelecide::interleave( ADMImage *imgsrc, ADMImage *imgdst,uint8_t odd)
82
uint32_t w=_info.width;
92
for(uint32_t y=(_info.height>>1);y>0;y--)
102
// Try to march fields of a frame with previous / next until it is not interlaced
106
uint8_t ADMVideoTelecide::getFrameNumberNoAlloc(uint32_t frame,
115
uint32_t cmatch,nmatch,n2match;
119
if(frame>=_info.nb_frames) return 0;
120
uvlen= _info.width*_info.height;
121
*len=uvlen+(uvlen>>1);
123
cur=vidCache->getImage(frame);
126
if(!frame || frame==_info.nb_frames-1)
129
data->duplicate(cur);
130
vidCache->unlockAll();
135
next=vidCache->getImage(frame-1);
138
vidCache->unlockAll();
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);
148
// No interleaving detected
149
if(!(motion=hasMotion(data)) )
151
printf("\n Not interlaced !\n");
152
memcpy(YPLANE(data),YPLANE(cur),uvlen);
153
vidCache->unlockAll();
156
// else cmatch is the current match
157
cmatch=getMatch(cur);
159
/* ------------------------------------------------------------------------------------
160
Try to complete with next frame fields
161
-----------------------------------------------------------------------------------
163
// Interleav next in even field
165
interleave(cur,_uncompressed,1);
166
interleave(next,_uncompressed,0);
167
nmatch=getMatch(_uncompressed);
169
interleave(cur,_uncompressed,0);
170
interleave(next,_uncompressed,1);
171
n2match=getMatch(_uncompressed);
173
printf(" Cur : %lu \n",cmatch);
174
printf(" Next : %lu \n",nmatch);
175
printf(" NextP: %lu \n",n2match);
177
if((cmatch<nmatch)&&(cmatch<n2match))
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();
187
if( nmatch > n2match)
189
printf("\n -------Shifted-P is better \n");
190
if(hasMotion(_uncompressed))
192
doBlend(_uncompressed,data);
193
printf(" but there is still motion \n");
196
data->duplicate(_uncompressed);
201
printf("\n -------Shifted-O is better \n");
202
interleave(cur,_uncompressed,1);
203
interleave(next,_uncompressed,0);
204
if(hasMotion(_uncompressed))
206
doBlend(_uncompressed,data);
207
printf(" but there is still motion \n");
210
data->duplicate(_uncompressed);
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();
219
Returns the number of difference (interlacing) found
223
uint32_t ADMVideoTelecide::getMatch( ADMImage *image )
234
for(y=_info.height>>2; y >2 ; y--)
236
for(x=_info.width;x>0;x--)
238
if( (*c-*p)*(*c-*n) >MATCH_THRESH)