1 /***************************************************************************
2                           ADM_vidPalShift.cpp  -  description
3                              -------------------
4     begin                : Sat Aug 24 2002
5     copyright            : (C) 2002 by mean
6     email                : fixounet@free.fr
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #include "ADM_default.h"
19 #include "ADM_videoFilterDynamic.h"
20 #include "ADM_vidPalShift.h"
21 #include "DIA_factory.h"
22 
23 static FILTER_PARAM nullParam={0,{""}};
24 
25 
26 //********** Register chunk ************
27 //REGISTERX(VF_INTERLACING, "palfieldshift",QT_TR_NOOP("PAL field shift"),QT_TR_NOOP(
28     //"Shift fields by one. Useful for some PAL movies."),VF_PALSHIFT,1,addPALShift_create,addPALShift_script);
29 VF_DEFINE_FILTER(ADMVideoPalShift,nullParam,
30     palfieldshift,
31                 QT_TR_NOOP("PAL field shift"),
32                 1,
33                 VF_INTERLACING,
34                 QT_TR_NOOP("Shift fields by one. Useful for some PAL movies."));
35 //********** Register chunk ************
36 
37 
printConf(void)38 char *ADMVideoPalShift::printConf( void )
39 {
40  	ADM_FILTER_DECLARE_CONF(" PAL field shift");
41 
42 }
43 
ADMVideoPalShift(AVDMGenericVideoStream * in,CONFcouple * setup)44 ADMVideoPalShift::ADMVideoPalShift(  AVDMGenericVideoStream *in,CONFcouple *setup)
45 {
46 	UNUSED_ARG(setup);
47 
48 
49 	_reverse=NULL;
50  	_in=in;
51 	memcpy(&_info,_in->getInfo(),sizeof(_info));
52 
53 
54 	_reverse=new uint32_t;;
55 	*_reverse=1;
56 
57   	_info.encoding=1;
58 
59 	vidCache=new VideoCache(5,in);
60 
61 
62 
63 }
configure(AVDMGenericVideoStream * instream)64  uint8_t ADMVideoPalShift::configure( AVDMGenericVideoStream *instream)
65 {
66 
67   diaElemToggle chroma(_reverse,QT_TR_NOOP("_Try reverse"));
68 
69     diaElem *elems[]={&chroma};
70 
71     return diaFactoryRun(QT_TR_NOOP("Pal Field Shift"),sizeof(elems)/sizeof(diaElem *),elems);
72 
73 }
~ADMVideoPalShift()74 ADMVideoPalShift::~ADMVideoPalShift()
75 {
76 	delete vidCache;
77 	delete _reverse;
78 }
getFrameNumberNoAlloc(uint32_t frame,uint32_t * len,ADMImage * data,uint32_t * flags)79 uint8_t ADMVideoPalShift::getFrameNumberNoAlloc(uint32_t frame,
80 				uint32_t *len,
81    				ADMImage *data,
82 				uint32_t *flags)
83 {
84 
85 uint32_t full,half;
86 ADMImage *cur,*next;
87 
88 		full=_info.width*_info.height;
89 		half=full>>2;
90 
91 		if(frame>=_info.nb_frames) return 0;
92 
93 		cur=vidCache->getImage(frame);
94 		if(!cur) return 0;
95 
96 		// for first or last frame do nothing
97 		if(!frame || frame==_info.nb_frames-1)
98 		{
99 
100 			data->duplicate(cur);
101 			vidCache->unlockAll();
102 			return 1;
103 		}
104 
105 		// copy u & v as they are
106 
107 		memcpy(UPLANE(data),UPLANE(cur),half);
108 		memcpy(VPLANE(data),VPLANE(cur),half);
109 
110 		// now copy odd field from framei and even frame from frame i-1
111 		// OR the other way around
112 		uint32_t dline=_info.width;
113 
114 		next=vidCache->getImage(frame+1);
115 		if(!next) return 0;
116 
117 		//
118 		uint8_t *src,*dst,*src2;
119 		if(!*_reverse)
120 		{
121 			src2=YPLANE(cur)+dline;
122 			src=YPLANE(next);
123 			dst=YPLANE(data);
124 		}
125 		else
126 		{
127 			src2=YPLANE(next)+dline;
128 			src=YPLANE(cur);
129 			dst=YPLANE(data);
130 
131 		}
132 		for(uint32_t y=(_info.height>>1);y>0;y--)
133 		{
134                 	memcpy(dst,src, dline);
135 			dst+=dline;
136                 	memcpy(dst,src2, dline);
137 			dst+=dline;
138 			src+=dline*2;
139 			src2+=dline*2;
140 		}
141 
142 	vidCache->unlockAll();
143 			data->copyInfo(cur);
144       return 1;
145 }
146 
147