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