1 /***************************************************************************
2                           ADM_vidAddBorder.cpp  -  description
3                              -------------------
4     begin                : Sun Aug 11 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_coreVideoFilter.h"
20 #include "DIA_coreToolkit.h"
21 #include "ADM_vidAddBorder.h"
22 #include "DIA_factory.h"
23 #include "addBorder_desc.cpp"
24 
25 /**
26     \fn getConfiguration
27     \brief Return current setting as a string
28 */
getConfiguration(void)29 const char *addBorders::getConfiguration(void)
30 {
31     static char conf[250];
32     conf[0]=0;
33     snprintf(conf,80,"Add Border : Left:%" PRIu32" Right:%" PRIu32" Top:%" PRIu32" Bottom:%" PRIu32" => %" PRIu32"x%" PRIu32"\n",
34                 param.left,param.right,param.top,param.bottom,
35                 info.width,info.height);
36     return conf;
37 }
38 /**
39     \fn ctor
40 */
addBorders(ADM_coreVideoFilter * in,CONFcouple * setup)41 addBorders::addBorders( ADM_coreVideoFilter *in,CONFcouple *setup) : ADM_coreVideoFilter(in,setup)
42 {
43     if(!setup || !ADM_paramLoad(setup,addBorder_param,&param))
44     {
45         // Default value
46         param.left=0;
47         param.right=0;
48         param.top=0;
49         param.bottom=0;
50 
51     }
52     info.width=in->getInfo()->width+param.left+param.right;
53     info.height=in->getInfo()->height+param.top+param.bottom;
54 
55 }
56 /**
57     \fn dtor
58 */
~addBorders()59 addBorders::~addBorders()
60 {
61 
62 }
63 
64 /**
65     \fn getCoupledConf
66     \brief Return our current configuration as couple name=value
67 */
getCoupledConf(CONFcouple ** couples)68 bool         addBorders::getCoupledConf(CONFcouple **couples)
69 {
70     return ADM_paramSave(couples, addBorder_param,&param);
71 }
72 
setCoupledConf(CONFcouple * couples)73 void addBorders::setCoupledConf(CONFcouple *couples)
74 {
75     ADM_paramLoad(couples, addBorder_param, &param);
76 }
77 #define Y_BLACK 16
78 #define UV_BLACK 128
blackenHz(int w,int nbLine,uint8_t * ptr[3],int strides[3])79 static bool blackenHz(int w,int nbLine,uint8_t *ptr[3],int strides[3])
80 {
81     // y
82     uint8_t *p=ptr[0];
83     uint32_t s=strides[0];
84     for(int y=0;y<nbLine;y++)
85     {
86         memset(p,Y_BLACK,w);
87         p+=s;
88     }
89     p=ptr[1];
90     s=strides[1];
91     nbLine/=2;
92     w/=2;
93     for(int y=0;y<nbLine;y++)
94     {
95         memset(p,UV_BLACK,w);
96         p+=s;
97     }
98     p=ptr[2];
99     s=strides[2];
100     for(int y=0;y<nbLine;y++)
101     {
102         memset(p,UV_BLACK,w);
103         p+=s;
104     }
105     return true;
106 }
107 
108 /**
109     \fn getNextFrame
110 */
getNextFrame(uint32_t * fn,ADMImage * image)111 bool addBorders::getNextFrame(uint32_t *fn,ADMImage *image)
112 {
113     uint32_t smallWidth=previousFilter->getInfo()->width;
114     uint32_t smallHeight=previousFilter->getInfo()->height;
115 
116     ADMImageRefWrittable ref(smallWidth,smallHeight);
117 
118     image->GetWritePlanes(ref._planes);
119     image->GetPitches(ref._planeStride);
120 
121     uint32_t offset=param.top*image->GetPitch(PLANAR_Y);
122     ref._planes[0]+=param.left+offset;
123 
124     offset=(param.top>>1)*image->GetPitch(PLANAR_U);
125     ref._planes[1]+=(param.left>>1)+offset;
126 
127     offset=(param.top>>1)*image->GetPitch(PLANAR_V);
128     ref._planes[2]+=(param.left>>1)+offset;
129 
130 
131     if(false==previousFilter->getNextFrame(fn,&ref))
132     {
133         ADM_warning("FlipFilter : Cannot get frame\n");
134         return false;
135     }
136     // Now do fill
137 
138     // Top...
139     uint8_t *ptr[3];
140     int     stride[3];
141     image->GetPitches(stride);
142     image->GetWritePlanes(ptr);
143     blackenHz(image->_width,param.top,ptr,stride);
144     // Left
145     blackenHz(param.left,image->_height,ptr,stride);
146     // Right
147     ptr[0]+=param.left+smallWidth;
148     ptr[1]+=(param.left+smallWidth)/2;
149     ptr[2]+=(param.left+smallWidth)/2;
150     blackenHz(param.right,image->_height,ptr,stride);
151     // Bottom
152     image->GetPitches(stride);
153     image->GetWritePlanes(ptr);
154     uint32_t offsetLine=smallHeight+param.top;
155     ptr[0]+=offsetLine*stride[0];
156     ptr[1]+=(offsetLine/2)*stride[1];
157     ptr[2]+=(offsetLine/2)*stride[2];
158     blackenHz(image->_width,param.bottom,ptr,stride);
159     // Copy info
160     image->copyInfo(&ref);
161     return true;
162 }
163 
164 /**
165     \fn configure
166 */
configure(void)167 bool addBorders::configure(void)
168 {
169         uint32_t width,height;
170 #define MAKEME(x) uint32_t x=param.x;
171         while(1)
172         {
173           MAKEME(left);
174           MAKEME(right);
175           MAKEME(top);
176           MAKEME(bottom);
177 
178           width=previousFilter->getInfo()->width;
179           height=previousFilter->getInfo()->height;
180 
181 #define BORDER_MAX_WIDTH 2160
182 
183           diaElemUInteger dleft(&left,QT_TRANSLATE_NOOP("addBorder", "_Left border:"),        0,BORDER_MAX_WIDTH);
184           diaElemUInteger dright(&right,QT_TRANSLATE_NOOP("addBorder", "_Right border:"),     0,BORDER_MAX_WIDTH);
185           diaElemUInteger dtop(&(top),QT_TRANSLATE_NOOP("addBorder", "_Top border:"),         0,BORDER_MAX_WIDTH);
186           diaElemUInteger dbottom(&(bottom),QT_TRANSLATE_NOOP("addBorder", "_Bottom border:"),0,BORDER_MAX_WIDTH);
187 
188           diaElem *elems[4]={&dleft,&dright,&dtop,&dbottom};
189           if(diaFactoryRun(QT_TRANSLATE_NOOP("addBorder", "Add Borders"),4,elems))
190           {
191             if((left&1) || (right&1)|| (top&1) || (bottom&1))
192             {
193               GUI_Error_HIG(QT_TRANSLATE_NOOP("addBorder", "Incorrect parameters"),QT_TRANSLATE_NOOP("addBorder", "All parameters must be even and within range."));
194               continue;
195             }
196             else
197             {
198   #undef MAKEME
199   #define MAKEME(x) param.x=x;
200                 MAKEME(left);
201                 MAKEME(right);
202                 MAKEME(top);
203                 MAKEME(bottom);
204                 info.width=width+left+right;
205                 info.height=height+top+bottom;
206                 return 1;
207             }
208           }
209           return 0;
210       }
211 }
212 
213 
214 
215 
216