床上为什么会有跳蚤| 头一直摇晃是什么病| 肺有小结节要注意什么| 脂肪肝吃什么好| 姿态万千的意思是什么| 凤五行属性是什么| 什么地唱| 肝是干什么用的| 中将是什么级别| 红斑狼疮是什么症状能治好吗| 羊宝是什么东西| 暑湿是什么意思| 狗狗打疫苗前后要注意什么| 孙悟空的原名叫什么| a4腰什么意思| 非无菌是什么意思| 男戴观音女戴佛是什么意思| 7月15号是什么星座| 为什么会有高血压| 为老不尊是什么意思| 金玉满堂是什么菜| 阳痿早泄吃什么药最好| sneakers是什么意思| 孕妇吃什么水果| 荷字五行属什么| 黄瓜片贴脸上有什么效果| 登对是什么意思| 初心是什么| 一个巾一个占念什么| 什么是双相情感障碍| 瑶五行属什么| 失声是什么意思| 口爆什么意思| 头总是昏昏沉沉的是什么原因| 上嘴唇上有痣代表什么| 大红袍是什么茶| 梦见和老公吵架是什么预兆| 偏头痛什么症状| 裹粉是什么粉| 6月15日是什么星座| 羊奶不能和什么一起吃| 南非叶有什么功效| 力挽狂澜是什么意思| 今年26岁属什么生肖| s和m是什么| 什么是附件炎| 歪果仁是什么意思| 冬天种什么蔬菜合适| 祈是什么意思| 手指脱皮是缺什么维生素| wc的完整形式是什么| 丙辰日是什么意思| 阴唇内侧长疙瘩是什么原因| 脑胀是什么原因| 手关节痛是什么原因| 7777什么意思| 耳垂长痘痘是什么原因| 水粉是什么| 感冒了吃什么食物最好| 尺码m是什么意思| 舌吻是什么意思| 5月26号是什么日子| 杨桃是什么季节的水果| 吃什么药可以提高性功能| 航班预警是什么意思| 冰种翡翠属于什么档次| 西洋参有什么作用| 人口基数是什么意思| 先敬罗衣后敬人是什么意思| 子宫切除后对身体有什么影响| 全血低切相对指数偏高什么意思| 酸化是什么意思| 舌头麻木是什么征兆| 什么叫多巴胺| 海马萎缩是什么情况| 什么是正月| 犬字旁的字和什么有关| 右小腿抽筋是什么原因| 海兔是什么| 甲骨文是什么朝代的| 贝珠是什么| 生理期为什么会肚子疼| classic什么意思| 抹茶是什么意思| 嗓子痛挂什么科| 地中海贫血是什么意思| 群众路线是什么| 12月2号什么星座| 肝炎是什么| 肝气不舒有什么症状| 嘴唇一圈发黑是什么原因造成的| 有个性是什么意思| 脑膜炎有什么症状| 梦见掉粪坑里了是什么意思| 爆栗什么意思| 狮子座和什么星座最配| 榴莲补什么| 大小便失禁是什么意思| 心律不齐用什么药| 三维彩超和四维彩超有什么区别| 右大腿上部疼痛是什么原因| movefree是什么药| 意淫是什么意思| 女人吃什么养颜又美白| 五个月的宝宝能吃什么辅食| 火锅油碟是什么油| 李子吃了有什么好处| 电饭煲什么内胆最好| 中气下陷吃什么药| 流产后吃什么水果好| 烂好人什么意思| 梦见大水是什么意思| 什么风大雨| 2017属什么生肖| 2月19是什么星座| 增加骨密度吃什么药| 什么像什么比喻句| 龟头敏感用什么药| vt什么意思| 荷叶搭配什么一起喝减肥效果好| 吃什么排出全身毒素| 宫颈ecc是什么意思| 月经期适合做什么运动| 夏天适合吃什么水果| 1934年属什么| 瓷娃娃什么意思| 什么是精神分裂症| 小腿发麻是什么原因| 夜游神是什么意思| 现在钱为什么这么难挣| 心什么如什么的成语| 6月25日是什么日子| 7月7号是什么节日| 莲花和荷花有什么区别| 倾注是什么意思| 老师结婚学生送什么礼物好| 2月30日是什么星座| 重本是什么意思| ru是什么意思| 性疾病都有什么症状| 犯法是什么意思| vogue是什么牌子| 鹿加几念什么| 扁尖是什么| 7月8号是什么星座| 海马是什么类动物| 完全性右束支阻滞是什么意思| 什么食物增加血管弹性| 乙肝挂什么科| 柱状上皮外移什么意思| 盐水是什么| sub是什么意思| 中暑是什么症状表现| 担担面是什么面| 发物都有什么| 心肌炎有什么症状| 本色出演是什么意思| 牙疼吃什么药效果最好| 腋毛什么时候开始生长| soe咖啡是什么意思| 9月出生的是什么星座| 花木兰姓什么| 吃什么子宫肌瘤会消除| 50公斤发什么物流便宜| 什么病可以请长假| 吃什么东西会长胖| 建档需要准备什么资料| 红萝卜和胡萝卜有什么区别| 手指缝脱皮是什么原因| 赫拉是什么神| 1月29日什么星座| 孕检挂什么科| 纳米是什么东西| 老花眼是什么原因引起的| 狗哭了代表什么预兆| 裹腹是什么意思| 酪氨酸酶是什么东西| 什么是类风湿性关节炎| 女累读什么| 吃什么对胰腺有好处| 为什么会有血管瘤| ctm是什么意思| 小孩说话不清楚挂什么科| 身上发热是什么原因| 候场是什么意思| 齐白石擅长画什么| 清热去火吃什么药| 橘白猫是什么品种| 1月21号是什么星座| 手心红是什么原因| 广谱是什么意思| 过刚易折什么意思| 黄牌是什么意思| 198什么意思| 宫腔镜检查后需要注意什么| 核桃和什么一起打豆浆| 肺癌吃什么水果| 牛腩炖什么好吃| 前胸后背疼是什么原因| 南音是什么意思| 痛经吃什么| 副省长什么级别| 总是掉头发是什么原因| 驾照c2能开什么车| 长期喝咖啡有什么好处和坏处| 三月十二是什么星座| 兔子五行属什么| 嘴贱什么意思| 怀孕吃什么必定流产| 名什么中外| 任达华是什么生肖| 为什么时间越来越快| 乘风破浪是什么意思| 做腋臭手术挂什么科室| 蝴蝶的翅膀像什么| 眩晕是怎么回事是什么原因引起| pcm是什么意思| 硫酸钠是什么| 持之以恒的恒是什么意思| 早上6点到7点是什么时辰| 什么的北京城| 什么是登革热病| 什么叫做亚健康| 河粉是什么| 急性咽炎吃什么药| 绿豆可以和什么一起煮| gi什么意思| 站久了脚后跟疼是什么原因| 脚冰冰凉是什么原因| 净化心灵是什么意思| 黑豚肉是什么肉| 做梦被杀了是什么征兆| 2010属什么生肖| 6月13日是什么星座| 肾虚型脱发是什么样子| 胃食管反流用什么药| 闭合性骨折是什么意思| 洗衣机什么牌子好| 邹去掉耳朵旁读什么| 四月二十一是什么星座| 鸡打瞌睡吃什么药| 人工流产后可以吃什么| 心肌炎是什么病| 日加军念什么| 男属蛇和什么属相最配| 放生鱼有什么好处| 鉴黄师是什么职业| 非萎缩性胃炎是什么意思| 颈椎病有什么特效药| 痉挛吃什么药效果好| 1960年是什么年| 希腊人是什么人种| 12月23日是什么星座| 高笋和茭白有什么区别| 心包填塞三联征是什么| 什么地生长| 拉肚子出血是什么原因| 吃什么减肥| mac版本是什么意思| 台湾高山茶属于什么茶| 12月26是什么星座| 左腿疼是什么原因| 为什么心会痛| 鸡蛋不能和什么食物一起吃| 百度

你可能没有听说过的关于维生素D和晒太阳的1…


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_swaprect.c
Date: 2025-08-04 11:35:17
Exec Total Coverage
Lines: 83 91 91.2%
Functions: 4 4 100.0%
Branches: 23 42 54.8%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2015 Paul B. Mahol
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include "libavutil/avassert.h"
22 #include "libavutil/eval.h"
23 #include "libavutil/imgutils.h"
24 #include "libavutil/mem.h"
25 #include "libavutil/opt.h"
26
27 #include "avfilter.h"
28 #include "filters.h"
29 #include "formats.h"
30 #include "video.h"
31
32 typedef struct SwapRectContext {
33 const AVClass *class;
34 char *w, *h;
35 char *x1, *y1;
36 char *x2, *y2;
37
38 int nb_planes;
39 int pixsteps[4];
40
41 const AVPixFmtDescriptor *desc;
42 uint8_t *temp;
43 } SwapRectContext;
44
45 #define OFFSET(x) offsetof(SwapRectContext, x)
46 #define FLAGS AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
47 static const AVOption swaprect_options[] = {
48 { "w", "set rect width", OFFSET(w), AV_OPT_TYPE_STRING, {.str="w/2"}, 0, 0, .flags = FLAGS },
49 { "h", "set rect height", OFFSET(h), AV_OPT_TYPE_STRING, {.str="h/2"}, 0, 0, .flags = FLAGS },
50 { "x1", "set 1st rect x top left coordinate", OFFSET(x1), AV_OPT_TYPE_STRING, {.str="w/2"}, 0, 0, .flags = FLAGS },
51 { "y1", "set 1st rect y top left coordinate", OFFSET(y1), AV_OPT_TYPE_STRING, {.str="h/2"}, 0, 0, .flags = FLAGS },
52 { "x2", "set 2nd rect x top left coordinate", OFFSET(x2), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, .flags = FLAGS },
53 { "y2", "set 2nd rect y top left coordinate", OFFSET(y2), AV_OPT_TYPE_STRING, {.str="0"}, 0, 0, .flags = FLAGS },
54 { NULL },
55 };
56
57 AVFILTER_DEFINE_CLASS(swaprect);
58
59 1 static int query_formats(const AVFilterContext *ctx,
60 AVFilterFormatsConfig **cfg_in,
61 AVFilterFormatsConfig **cfg_out)
62 {
63 1 int reject_flags = AV_PIX_FMT_FLAG_PAL |
64 AV_PIX_FMT_FLAG_HWACCEL |
65 AV_PIX_FMT_FLAG_BITSTREAM;
66
67 1 return ff_set_common_formats2(ctx, cfg_in, cfg_out,
68 ff_formats_pixdesc_filter(0, reject_flags));
69 }
70
71 static const char *const var_names[] = { "w", "h", "a", "n", "t", "sar", "dar", NULL };
72 enum { VAR_W, VAR_H, VAR_A, VAR_N, VAR_T, VAR_SAR, VAR_DAR, VAR_VARS_NB };
73
74 50 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
75 {
76 50 FilterLink *inl = ff_filter_link(inlink);
77 50 AVFilterContext *ctx = inlink->dst;
78 50 AVFilterLink *outlink = ctx->outputs[0];
79 50 SwapRectContext *s = ctx->priv;
80 double var_values[VAR_VARS_NB];
81 int x1[4], y1[4];
82 int x2[4], y2[4];
83 int aw[4], ah[4];
84 int lw[4], lh[4];
85 int pw[4], ph[4];
86 double dw, dh;
87 double dx1, dy1;
88 double dx2, dy2;
89 int y, p, w, h, ret;
90
91 50 var_values[VAR_W] = inlink->w;
92 50 var_values[VAR_H] = inlink->h;
93 50 var_values[VAR_A] = (float) inlink->w / inlink->h;
94
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 var_values[VAR_SAR] = inlink->sample_aspect_ratio.num ? av_q2d(inlink->sample_aspect_ratio) : 1;
95 50 var_values[VAR_DAR] = var_values[VAR_A] * var_values[VAR_SAR];
96 50 var_values[VAR_N] = inl->frame_count_out;
97
1/2
✓ Branch 0 taken 50 times.
✗ Branch 1 not taken.
50 var_values[VAR_T] = in->pts == AV_NOPTS_VALUE ? NAN : in->pts * av_q2d(inlink->time_base);
98
99 50 ret = av_expr_parse_and_eval(&dw, s->w,
100 var_names, &var_values[0],
101 NULL, NULL, NULL, NULL,
102 0, 0, ctx);
103
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
104 return ret;
105
106 50 ret = av_expr_parse_and_eval(&dh, s->h,
107 var_names, &var_values[0],
108 NULL, NULL, NULL, NULL,
109 0, 0, ctx);
110
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
111 return ret;
112
113 50 ret = av_expr_parse_and_eval(&dx1, s->x1,
114 var_names, &var_values[0],
115 NULL, NULL, NULL, NULL,
116 0, 0, ctx);
117
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
118 return ret;
119
120 50 ret = av_expr_parse_and_eval(&dy1, s->y1,
121 var_names, &var_values[0],
122 NULL, NULL, NULL, NULL,
123 0, 0, ctx);
124
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
125 return ret;
126
127 50 ret = av_expr_parse_and_eval(&dx2, s->x2,
128 var_names, &var_values[0],
129 NULL, NULL, NULL, NULL,
130 0, 0, ctx);
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
132 return ret;
133
134 50 ret = av_expr_parse_and_eval(&dy2, s->y2,
135 var_names, &var_values[0],
136 NULL, NULL, NULL, NULL,
137 0, 0, ctx);
138
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 if (ret < 0)
139 return ret;
140
141 50 w = dw; h = dh; x1[0] = dx1; y1[0] = dy1; x2[0] = dx2; y2[0] = dy2;
142
143 50 x1[0] = av_clip(x1[0], 0, inlink->w - 1);
144 50 y1[0] = av_clip(y1[0], 0, inlink->h - 1);
145
146 50 x2[0] = av_clip(x2[0], 0, inlink->w - 1);
147 50 y2[0] = av_clip(y2[0], 0, inlink->h - 1);
148
149 50 ah[1] = ah[2] = AV_CEIL_RSHIFT(h, s->desc->log2_chroma_h);
150 50 ah[0] = ah[3] = h;
151 50 aw[1] = aw[2] = AV_CEIL_RSHIFT(w, s->desc->log2_chroma_w);
152 50 aw[0] = aw[3] = w;
153
154 50 w = FFMIN3(w, inlink->w - x1[0], inlink->w - x2[0]);
155 50 h = FFMIN3(h, inlink->h - y1[0], inlink->h - y2[0]);
156
157 50 ph[1] = ph[2] = AV_CEIL_RSHIFT(h, s->desc->log2_chroma_h);
158 50 ph[0] = ph[3] = h;
159 50 pw[1] = pw[2] = AV_CEIL_RSHIFT(w, s->desc->log2_chroma_w);
160 50 pw[0] = pw[3] = w;
161
162 50 lh[1] = lh[2] = AV_CEIL_RSHIFT(inlink->h, s->desc->log2_chroma_h);
163 50 lh[0] = lh[3] = inlink->h;
164 50 lw[1] = lw[2] = AV_CEIL_RSHIFT(inlink->w, s->desc->log2_chroma_w);
165 50 lw[0] = lw[3] = inlink->w;
166
167 50 x1[1] = x1[2] = (x1[0] >> s->desc->log2_chroma_w);
168 50 x1[0] = x1[3] = x1[0];
169 50 y1[1] = y1[2] = (y1[0] >> s->desc->log2_chroma_h);
170 50 y1[0] = y1[3] = y1[0];
171
172 50 x2[1] = x2[2] = (x2[0] >> s->desc->log2_chroma_w);
173 50 x2[0] = x2[3] = x2[0];
174 50 y2[1] = y2[2] = (y2[0] >> s->desc->log2_chroma_h);
175 50 y2[0] = y2[3] = y2[0];
176
177
178
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 av_assert0(FFMAX(x1[1], x2[1]) + pw[1] <= lw[1]);
179
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 50 times.
50 av_assert0(FFMAX(y1[1], y2[1]) + ph[1] <= lh[1]);
180
181
2/2
✓ Branch 0 taken 150 times.
✓ Branch 1 taken 50 times.
200 for (p = 0; p < s->nb_planes; p++) {
182
2/4
✓ Branch 0 taken 150 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 150 times.
✗ Branch 3 not taken.
150 if (ph[p] == ah[p] && pw[p] == aw[p]) {
183 150 uint8_t *src = in->data[p] + y1[p] * in->linesize[p] + x1[p] * s->pixsteps[p];
184 150 uint8_t *dst = in->data[p] + y2[p] * in->linesize[p] + x2[p] * s->pixsteps[p];
185
186
2/2
✓ Branch 0 taken 14400 times.
✓ Branch 1 taken 150 times.
14550 for (y = 0; y < ph[p]; y++) {
187 14400 memcpy(s->temp, src, pw[p] * s->pixsteps[p]);
188 14400 memmove(src, dst, pw[p] * s->pixsteps[p]);
189 14400 memcpy(dst, s->temp, pw[p] * s->pixsteps[p]);
190 14400 src += in->linesize[p];
191 14400 dst += in->linesize[p];
192 }
193 }
194 }
195
196 50 return ff_filter_frame(outlink, in);
197 }
198
199 1 static int config_input(AVFilterLink *inlink)
200 {
201 1 AVFilterContext *ctx = inlink->dst;
202 1 SwapRectContext *s = ctx->priv;
203
204
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if (!s->w || !s->h ||
205
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 !s->x1 || !s->y1 ||
206
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 !s->x2 || !s->y2)
207 return AVERROR(EINVAL);
208
209 1 s->desc = av_pix_fmt_desc_get(inlink->format);
210 1 av_image_fill_max_pixsteps(s->pixsteps, NULL, s->desc);
211 1 s->nb_planes = av_pix_fmt_count_planes(inlink->format);
212
213 1 s->temp = av_malloc_array(inlink->w, s->pixsteps[0]);
214
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (!s->temp)
215 return AVERROR(ENOMEM);
216
217 1 return 0;
218 }
219
220 2 static av_cold void uninit(AVFilterContext *ctx)
221 {
222 2 SwapRectContext *s = ctx->priv;
223 2 av_freep(&s->temp);
224 2 }
225
226 static const AVFilterPad inputs[] = {
227 {
228 .name = "default",
229 .type = AVMEDIA_TYPE_VIDEO,
230 .flags = AVFILTERPAD_FLAG_NEEDS_WRITABLE,
231 .filter_frame = filter_frame,
232 .config_props = config_input,
233 },
234 };
235
236 const FFFilter ff_vf_swaprect = {
237 .p.name = "swaprect",
238 .p.description = NULL_IF_CONFIG_SMALL("Swap 2 rectangular objects in video."),
239 .p.priv_class = &swaprect_class,
240 .p.flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC,
241 .priv_size = sizeof(SwapRectContext),
242 .uninit = uninit,
243 FILTER_INPUTS(inputs),
244 FILTER_OUTPUTS(ff_video_default_filterpad),
245 FILTER_QUERY_FUNC2(query_formats),
246 .process_command = ff_filter_process_command,
247 };
248

血压高可以吃什么水果 病毒性发烧吃什么药 为什么不开朱元璋的墓 皮肤过敏忌口什么食物 奶水不足吃什么
梦见自己的头发长长了是什么意思 束缚的意思是什么 二氧化硅是什么氧化物 歆字取名什么寓意 上火了吃什么药
什么时候需要打破伤风针 前列腺肥大有什么症状 梦见烧纸钱是什么意思 帝旺是什么意思 原位杂交技术检查什么
颈动脉斑块做什么检查 上海特产是什么 得了子宫肌瘤注意什么 洗衣粉和洗衣液有什么区别 肩周炎看什么科
胃火吃什么药hcv9jop6ns4r.cn 干咳无痰吃什么药dajiketang.com 尿喝起来是什么味道hcv9jop3ns0r.cn 梦见两个小男孩是什么意思hcv8jop4ns4r.cn 互诉衷肠是什么意思hcv8jop0ns8r.cn
1935年属什么hcv8jop4ns5r.cn 8.1号是什么星座hcv8jop5ns7r.cn 继发性高血压什么意思hcv8jop4ns6r.cn 水猴子是什么动物jasonfriends.com 早起眼皮肿是什么原因引起的hcv8jop0ns0r.cn
怀孕一个月会有什么反应hcv9jop6ns4r.cn 保底和底薪有什么区别hcv7jop6ns7r.cn 精卫填海是什么意思qingzhougame.com 卤肉是什么肉hcv9jop7ns9r.cn 六味地黄丸什么牌子的好hcv8jop1ns8r.cn
早上打喷嚏是什么预兆liaochangning.com 临床医学是什么hcv9jop1ns8r.cn 女人腰疼是什么原因引起的hcv7jop9ns1r.cn 蜂蜜水喝了有什么好处hcv8jop9ns1r.cn 小土豆是什么意思0735v.com
百度