1 /***************************************************************************
2 Swap Fields.cpp - description
3 -------------------
4 Swap each line (shift up for odd, down for even)
5
6
7 begin : Thu Mar 21 2002
8 copyright : (C) 2002 by mean
9 email : fixounet@free.fr
10 ***************************************************************************/
11
12 /***************************************************************************
13 * *
14 * This program is free software; you can redistribute it and/or modify *
15 * it under the terms of the GNU General Public License as published by *
16 * the Free Software Foundation; either version 2 of the License, or *
17 * (at your option) any later version. *
18 * *
19 ***************************************************************************/
20
21 #include "ADM_default.h"
22
23
24 #include "ADM_videoFilterDynamic.h"
25 #include "ADM_vidFieldUtil.h"
26 #include "ADM_vidSwapFields.h"
27
28
29 static FILTER_PARAM swapParam={0,{""}};
30
31 VF_DEFINE_FILTER(AVDMVideoSwapField,swapParam,
32 swapfields,
33 QT_TR_NOOP("Swap fields"),
34 1,
35 VF_INTERLACING,
36 QT_TR_NOOP("Swap top and bottom fields."));
37 //********** Register chunk ************
38
printConf(void)39 char *AVDMVideoSwapField::printConf( void )
40 {
41 ADM_FILTER_DECLARE_CONF(" Swap fields");
42
43 }
44 //_______________________________________________________________
AVDMVideoSwapField(AVDMGenericVideoStream * in,CONFcouple * setup)45 AVDMVideoSwapField::AVDMVideoSwapField(
46 AVDMGenericVideoStream *in,CONFcouple *setup)
47 {
48 UNUSED_ARG(setup);
49 _in=in;
50 memcpy(&_info,_in->getInfo(),sizeof(_info));
51 _uncompressed=new ADMImage(_info.width,_info.height);
52
53
54 }
55 // ___ destructor_____________
~AVDMVideoSwapField()56 AVDMVideoSwapField::~AVDMVideoSwapField()
57 {
58 delete _uncompressed;
59 _uncompressed=NULL;
60
61 }
62 // ___ destructor_____________
63
64 //
65 // Basically ask a uncompressed frame from editor and ask
66 // GUI to decompress it .
67 //
68
getFrameNumberNoAlloc(uint32_t frame,uint32_t * len,ADMImage * data,uint32_t * flags)69 uint8_t AVDMVideoSwapField::getFrameNumberNoAlloc(uint32_t frame,
70 uint32_t *len,
71 ADMImage *data,
72 uint32_t *flags)
73 {
74 //static Image in,out;
75 if(frame>=_info.nb_frames) return 0;
76
77
78 // read uncompressed frame
79 if(!_in->getFrameNumberNoAlloc(frame, len,_uncompressed,flags)) return 0;
80
81 uint32_t w=_info.width;
82 uint32_t h=_info.height;
83 uint32_t page=w*h;
84 uint32_t stride;
85
86 // copy u & v
87 memcpy(UPLANE(data),UPLANE(_uncompressed),page>>2);
88 memcpy(VPLANE(data),VPLANE(_uncompressed),page>>2);
89
90 uint8_t *odd,*even,*target,*target2;
91
92 even=YPLANE(_uncompressed);
93 odd=even+w;
94 target=YPLANE(data);
95 target2=YPLANE(data)+w;
96 stride=2*w;
97
98 h>>=1;
99 for(;h--;h>0)
100 {
101 memcpy(target,odd,w);
102 memcpy(target2,even,w);
103 target+=stride;
104 target2+=stride;
105 odd+=stride;
106 even+=stride;
107 }
108 data->copyInfo(_uncompressed);
109
110 return 1;
111 }
112
113