FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libswscale/hscale.c
Date: 2024-11-20 23:03:26
Exec Total Coverage
Lines: 155 162 95.7%
Functions: 10 10 100.0%
Branches: 41 54 75.9%

Line Branch Exec Source
1 /*
2 * Copyright (C) 2015 Pedro Arthur <bygrandao@gmail.com>
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/mem.h"
22 #include "swscale_internal.h"
23
24 /// Scaler instance data
25 typedef struct FilterContext
26 {
27 uint16_t *filter;
28 int *filter_pos;
29 int filter_size;
30 int xInc;
31 } FilterContext;
32
33 /// Color conversion instance data
34 typedef struct ColorContext
35 {
36 uint32_t *pal;
37 } ColorContext;
38
39 4487384 static int lum_h_scale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
40 {
41 4487384 FilterContext *instance = desc->instance;
42 4487384 int srcW = desc->src->width;
43 4487384 int dstW = desc->dst->width;
44 4487384 int xInc = instance->xInc;
45
46 int i;
47
2/2
✓ Branch 0 taken 21548346 times.
✓ Branch 1 taken 4487384 times.
26035730 for (i = 0; i < sliceH; ++i) {
48 21548346 uint8_t ** src = desc->src->plane[0].line;
49 21548346 uint8_t ** dst = desc->dst->plane[0].line;
50 21548346 int src_pos = sliceY+i - desc->src->plane[0].sliceY;
51 21548346 int dst_pos = sliceY+i - desc->dst->plane[0].sliceY;
52
53
54
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21548346 times.
21548346 if (c->hyscale_fast) {
55 c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc);
56 } else {
57 21548346 c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter,
58 21548346 instance->filter_pos, instance->filter_size);
59 }
60
61
2/2
✓ Branch 0 taken 2081123 times.
✓ Branch 1 taken 19467223 times.
21548346 if (c->lumConvertRange)
62 2081123 c->lumConvertRange((int16_t*)dst[dst_pos], dstW);
63
64 21548346 desc->dst->plane[0].sliceH += 1;
65
66
2/2
✓ Branch 0 taken 112136 times.
✓ Branch 1 taken 21436210 times.
21548346 if (desc->alpha) {
67 112136 src = desc->src->plane[3].line;
68 112136 dst = desc->dst->plane[3].line;
69
70 112136 src_pos = sliceY+i - desc->src->plane[3].sliceY;
71 112136 dst_pos = sliceY+i - desc->dst->plane[3].sliceY;
72
73 112136 desc->dst->plane[3].sliceH += 1;
74
75
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 112136 times.
112136 if (c->hyscale_fast) {
76 c->hyscale_fast(c, (int16_t*)dst[dst_pos], dstW, src[src_pos], srcW, xInc);
77 } else {
78 112136 c->hyScale(c, (int16_t*)dst[dst_pos], dstW, (const uint8_t *)src[src_pos], instance->filter,
79 112136 instance->filter_pos, instance->filter_size);
80 }
81 }
82 }
83
84 4487384 return sliceH;
85 }
86
87 1907851 static int lum_convert(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
88 {
89 1907851 int srcW = desc->src->width;
90 1907851 ColorContext * instance = desc->instance;
91 1907851 uint32_t * pal = instance->pal;
92 int i;
93
94 1907851 desc->dst->plane[0].sliceY = sliceY;
95 1907851 desc->dst->plane[0].sliceH = sliceH;
96 1907851 desc->dst->plane[3].sliceY = sliceY;
97 1907851 desc->dst->plane[3].sliceH = sliceH;
98
99
2/2
✓ Branch 0 taken 9311592 times.
✓ Branch 1 taken 1907851 times.
11219443 for (i = 0; i < sliceH; ++i) {
100 9311592 int sp0 = sliceY+i - desc->src->plane[0].sliceY;
101 9311592 int sp1 = ((sliceY+i) >> desc->src->v_chr_sub_sample) - desc->src->plane[1].sliceY;
102 9311592 const uint8_t * src[4] = { desc->src->plane[0].line[sp0],
103 9311592 desc->src->plane[1].line[sp1],
104 9311592 desc->src->plane[2].line[sp1],
105 9311592 desc->src->plane[3].line[sp0]};
106 9311592 uint8_t * dst = desc->dst->plane[0].line[i];
107
108
2/2
✓ Branch 0 taken 6590900 times.
✓ Branch 1 taken 2720692 times.
9311592 if (c->lumToYV12) {
109 6590900 c->lumToYV12(dst, src[0], src[1], src[2], srcW, pal, c->input_opaque);
110
1/2
✓ Branch 0 taken 2720692 times.
✗ Branch 1 not taken.
2720692 } else if (c->readLumPlanar) {
111 2720692 c->readLumPlanar(dst, src, srcW, c->input_rgb2yuv_table, c->input_opaque);
112 }
113
114
115
2/2
✓ Branch 0 taken 108104 times.
✓ Branch 1 taken 9203488 times.
9311592 if (desc->alpha) {
116 108104 dst = desc->dst->plane[3].line[i];
117
2/2
✓ Branch 0 taken 104681 times.
✓ Branch 1 taken 3423 times.
108104 if (c->alpToYV12) {
118 104681 c->alpToYV12(dst, src[3], src[1], src[2], srcW, pal, c->input_opaque);
119
1/2
✓ Branch 0 taken 3423 times.
✗ Branch 1 not taken.
3423 } else if (c->readAlpPlanar) {
120 3423 c->readAlpPlanar(dst, src, srcW, NULL, c->input_opaque);
121 }
122 }
123 }
124
125 1907851 return sliceH;
126 }
127
128 9022 int ff_init_desc_fmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal)
129 {
130 9022 ColorContext * li = av_malloc(sizeof(ColorContext));
131
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9022 times.
9022 if (!li)
132 return AVERROR(ENOMEM);
133 9022 li->pal = pal;
134 9022 desc->instance = li;
135
136
3/4
✓ Branch 1 taken 474 times.
✓ Branch 2 taken 8548 times.
✓ Branch 4 taken 474 times.
✗ Branch 5 not taken.
9022 desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
137 9022 desc->src =src;
138 9022 desc->dst = dst;
139 9022 desc->process = &lum_convert;
140
141 9022 return 0;
142 }
143
144
145 17771 int ff_init_desc_hscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc)
146 {
147 17771 FilterContext *li = av_malloc(sizeof(FilterContext));
148
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17771 times.
17771 if (!li)
149 return AVERROR(ENOMEM);
150
151 17771 li->filter = filter;
152 17771 li->filter_pos = filter_pos;
153 17771 li->filter_size = filter_size;
154 17771 li->xInc = xInc;
155
156 17771 desc->instance = li;
157
158
3/4
✓ Branch 1 taken 495 times.
✓ Branch 2 taken 17276 times.
✓ Branch 4 taken 495 times.
✗ Branch 5 not taken.
17771 desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
159 17771 desc->src = src;
160 17771 desc->dst = dst;
161
162 17771 desc->process = &lum_h_scale;
163
164 17771 return 0;
165 }
166
167 4632806 static int chr_h_scale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
168 {
169 4632806 FilterContext *instance = desc->instance;
170 4632806 int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample);
171 4632806 int dstW = AV_CEIL_RSHIFT(desc->dst->width, desc->dst->h_chr_sub_sample);
172 4632806 int xInc = instance->xInc;
173
174 4632806 uint8_t ** src1 = desc->src->plane[1].line;
175 4632806 uint8_t ** dst1 = desc->dst->plane[1].line;
176 4632806 uint8_t ** src2 = desc->src->plane[2].line;
177 4632806 uint8_t ** dst2 = desc->dst->plane[2].line;
178
179 4632806 int src_pos1 = sliceY - desc->src->plane[1].sliceY;
180 4632806 int dst_pos1 = sliceY - desc->dst->plane[1].sliceY;
181
182 4632806 int src_pos2 = sliceY - desc->src->plane[2].sliceY;
183 4632806 int dst_pos2 = sliceY - desc->dst->plane[2].sliceY;
184
185 int i;
186
2/2
✓ Branch 0 taken 16217439 times.
✓ Branch 1 taken 4632806 times.
20850245 for (i = 0; i < sliceH; ++i) {
187
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16217439 times.
16217439 if (c->hcscale_fast) {
188 c->hcscale_fast(c, (uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW, src1[src_pos1+i], src2[src_pos2+i], srcW, xInc);
189 } else {
190 16217439 c->hcScale(c, (uint16_t*)dst1[dst_pos1+i], dstW, src1[src_pos1+i], instance->filter, instance->filter_pos, instance->filter_size);
191 16217439 c->hcScale(c, (uint16_t*)dst2[dst_pos2+i], dstW, src2[src_pos2+i], instance->filter, instance->filter_pos, instance->filter_size);
192 }
193
194
2/2
✓ Branch 0 taken 770373 times.
✓ Branch 1 taken 15447066 times.
16217439 if (c->chrConvertRange)
195 770373 c->chrConvertRange((uint16_t*)dst1[dst_pos1+i], (uint16_t*)dst2[dst_pos2+i], dstW);
196
197 16217439 desc->dst->plane[1].sliceH += 1;
198 16217439 desc->dst->plane[2].sliceH += 1;
199 }
200 4632806 return sliceH;
201 }
202
203 2483969 static int chr_convert(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
204 {
205 2483969 int srcW = AV_CEIL_RSHIFT(desc->src->width, desc->src->h_chr_sub_sample);
206 2483969 ColorContext * instance = desc->instance;
207 2483969 uint32_t * pal = instance->pal;
208
209 2483969 int sp0 = (sliceY - (desc->src->plane[0].sliceY >> desc->src->v_chr_sub_sample)) << desc->src->v_chr_sub_sample;
210 2483969 int sp1 = sliceY - desc->src->plane[1].sliceY;
211
212 int i;
213
214 2483969 desc->dst->plane[1].sliceY = sliceY;
215 2483969 desc->dst->plane[1].sliceH = sliceH;
216 2483969 desc->dst->plane[2].sliceY = sliceY;
217 2483969 desc->dst->plane[2].sliceH = sliceH;
218
219
2/2
✓ Branch 0 taken 8889080 times.
✓ Branch 1 taken 2483969 times.
11373049 for (i = 0; i < sliceH; ++i) {
220 8889080 const uint8_t * src[4] = { desc->src->plane[0].line[sp0+i],
221 8889080 desc->src->plane[1].line[sp1+i],
222 8889080 desc->src->plane[2].line[sp1+i],
223 8889080 desc->src->plane[3].line[sp0+i]};
224
225 8889080 uint8_t * dst1 = desc->dst->plane[1].line[i];
226 8889080 uint8_t * dst2 = desc->dst->plane[2].line[i];
227
2/2
✓ Branch 0 taken 6518854 times.
✓ Branch 1 taken 2370226 times.
8889080 if (c->chrToYV12) {
228 6518854 c->chrToYV12(dst1, dst2, src[0], src[1], src[2], srcW, pal, c->input_opaque);
229
1/2
✓ Branch 0 taken 2370226 times.
✗ Branch 1 not taken.
2370226 } else if (c->readChrPlanar) {
230 2370226 c->readChrPlanar(dst1, dst2, src, srcW, c->input_rgb2yuv_table, c->input_opaque);
231 }
232 }
233 2483969 return sliceH;
234 }
235
236 8978 int ff_init_desc_cfmt_convert(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst, uint32_t *pal)
237 {
238 8978 ColorContext * li = av_malloc(sizeof(ColorContext));
239
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8978 times.
8978 if (!li)
240 return AVERROR(ENOMEM);
241 8978 li->pal = pal;
242 8978 desc->instance = li;
243
244 8978 desc->src =src;
245 8978 desc->dst = dst;
246 8978 desc->process = &chr_convert;
247
248 8978 return 0;
249 }
250
251 16075 int ff_init_desc_chscale(SwsFilterDescriptor *desc, SwsSlice *src, SwsSlice *dst, uint16_t *filter, int * filter_pos, int filter_size, int xInc)
252 {
253 16075 FilterContext *li = av_malloc(sizeof(FilterContext));
254
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16075 times.
16075 if (!li)
255 return AVERROR(ENOMEM);
256
257 16075 li->filter = filter;
258 16075 li->filter_pos = filter_pos;
259 16075 li->filter_size = filter_size;
260 16075 li->xInc = xInc;
261
262 16075 desc->instance = li;
263
264
3/4
✓ Branch 1 taken 357 times.
✓ Branch 2 taken 15718 times.
✓ Branch 4 taken 357 times.
✗ Branch 5 not taken.
16075 desc->alpha = isALPHA(src->fmt) && isALPHA(dst->fmt);
265 16075 desc->src = src;
266 16075 desc->dst = dst;
267
268 16075 desc->process = &chr_h_scale;
269
270 16075 return 0;
271 }
272
273 302929 static int no_chr_scale(SwsInternal *c, SwsFilterDescriptor *desc, int sliceY, int sliceH)
274 {
275 302929 desc->dst->plane[1].sliceY = sliceY + sliceH - desc->dst->plane[1].available_lines;
276 302929 desc->dst->plane[1].sliceH = desc->dst->plane[1].available_lines;
277 302929 desc->dst->plane[2].sliceY = sliceY + sliceH - desc->dst->plane[2].available_lines;
278 302929 desc->dst->plane[2].sliceH = desc->dst->plane[2].available_lines;
279 302929 return 0;
280 }
281
282 1696 int ff_init_desc_no_chr(SwsFilterDescriptor *desc, SwsSlice * src, SwsSlice *dst)
283 {
284 1696 desc->src = src;
285 1696 desc->dst = dst;
286 1696 desc->alpha = 0;
287 1696 desc->instance = NULL;
288 1696 desc->process = &no_chr_scale;
289 1696 return 0;
290 }
291