FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavfilter/vf_super2xsai.c
Date: 2022-12-05 03:11:11
Exec Total Coverage
Lines: 181 185 97.8%
Functions: 4 4 100.0%
Branches: 151 177 85.3%

Line Branch Exec Source
1 /*
2 * Copyright (c) 2010 Niel van der Westhuizen <nielkie@gmail.com>
3 * Copyright (c) 2002 A'rpi
4 * Copyright (c) 1997-2001 ZSNES Team ( zsknight@zsnes.com / _demo_@zsnes.com )
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with FFmpeg; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 /**
24 * @file
25 * Super 2xSaI video filter
26 * Ported from MPlayer libmpcodecs/vf_2xsai.c.
27 */
28
29 #include "libavutil/pixdesc.h"
30 #include "libavutil/intreadwrite.h"
31 #include "avfilter.h"
32 #include "formats.h"
33 #include "internal.h"
34 #include "video.h"
35
36 typedef struct Super2xSaIContext {
37 /* masks used for two pixels interpolation */
38 uint32_t hi_pixel_mask;
39 uint32_t lo_pixel_mask;
40
41 /* masks used for four pixels interpolation */
42 uint32_t q_hi_pixel_mask;
43 uint32_t q_lo_pixel_mask;
44
45 int bpp; ///< bytes per pixel, pixel stride for each (packed) pixel
46 int is_be;
47 } Super2xSaIContext;
48
49 typedef struct ThreadData {
50 AVFrame *in, *out;
51 } ThreadData;
52
53 #define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
54
55 #define INTERPOLATE(A, B) (((A & hi_pixel_mask) >> 1) + ((B & hi_pixel_mask) >> 1) + (A & B & lo_pixel_mask))
56
57 #define Q_INTERPOLATE(A, B, C, D) ((A & q_hi_pixel_mask) >> 2) + ((B & q_hi_pixel_mask) >> 2) + ((C & q_hi_pixel_mask) >> 2) + ((D & q_hi_pixel_mask) >> 2) \
58 + ((((A & q_lo_pixel_mask) + (B & q_lo_pixel_mask) + (C & q_lo_pixel_mask) + (D & q_lo_pixel_mask)) >> 2) & q_lo_pixel_mask)
59
60 14 static int super2xsai(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
61 {
62 14 Super2xSaIContext *s = ctx->priv;
63 14 ThreadData *td = arg;
64 14 AVFrame *in = td->in;
65 14 AVFrame *out = td->out;
66 14 const uint8_t *src = in->data[0];
67 14 uint8_t *dst = out->data[0];
68 14 const int src_linesize = in->linesize[0];
69 14 const int dst_linesize = out->linesize[0];
70 14 const int width = in->width;
71 14 const int height = in->height;
72 unsigned int x, y;
73 uint32_t color[4][4];
74 const uint8_t *src_line[4];
75 14 const int bpp = s->bpp;
76 14 const uint32_t hi_pixel_mask = s->hi_pixel_mask;
77 14 const uint32_t lo_pixel_mask = s->lo_pixel_mask;
78 14 const uint32_t q_hi_pixel_mask = s->q_hi_pixel_mask;
79 14 const uint32_t q_lo_pixel_mask = s->q_lo_pixel_mask;
80 14 const int slice_start = (height * jobnr) / nb_jobs;
81 14 const int slice_end = (height * (jobnr+1)) / nb_jobs;
82
83 /* Point to the first 4 lines, first line is duplicated */
84 14 src_line[0] = src + src_linesize*FFMAX(slice_start - 1, 0);
85 14 src_line[1] = src + src_linesize*slice_start;
86
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 src_line[2] = src + src_linesize*FFMIN(slice_start + 1, height-1);
87
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 src_line[3] = src + src_linesize*FFMIN(slice_start + 2, height-1);
88
89 #define READ_COLOR4(dst, src_line, off) dst = *((const uint32_t *)src_line + off)
90 #define READ_COLOR3(dst, src_line, off) dst = AV_RL24 (src_line + 3*off)
91 #define READ_COLOR2(dst, src_line, off) dst = s->is_be ? AV_RB16(src_line + 2 * off) : AV_RL16(src_line + 2 * off)
92
93
2/2
✓ Branch 0 taken 4032 times.
✓ Branch 1 taken 14 times.
4046 for (y = slice_start; y < slice_end; y++) {
94 uint8_t *dst_line[2];
95
96 4032 dst_line[0] = dst + dst_linesize*2*y;
97 4032 dst_line[1] = dst + dst_linesize*(2*y+1);
98
99
3/3
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 576 times.
✓ Branch 2 taken 2304 times.
4032 switch (bpp) {
100 1152 case 4:
101 1152 READ_COLOR4(color[0][0], src_line[0], 0); color[0][1] = color[0][0]; READ_COLOR4(color[0][2], src_line[0], 1); READ_COLOR4(color[0][3], src_line[0], 2);
102 1152 READ_COLOR4(color[1][0], src_line[1], 0); color[1][1] = color[1][0]; READ_COLOR4(color[1][2], src_line[1], 1); READ_COLOR4(color[1][3], src_line[1], 2);
103 1152 READ_COLOR4(color[2][0], src_line[2], 0); color[2][1] = color[2][0]; READ_COLOR4(color[2][2], src_line[2], 1); READ_COLOR4(color[2][3], src_line[2], 2);
104 1152 READ_COLOR4(color[3][0], src_line[3], 0); color[3][1] = color[3][0]; READ_COLOR4(color[3][2], src_line[3], 1); READ_COLOR4(color[3][3], src_line[3], 2);
105 1152 break;
106 576 case 3:
107 576 READ_COLOR3(color[0][0], src_line[0], 0); color[0][1] = color[0][0]; READ_COLOR3(color[0][2], src_line[0], 1); READ_COLOR3(color[0][3], src_line[0], 2);
108 576 READ_COLOR3(color[1][0], src_line[1], 0); color[1][1] = color[1][0]; READ_COLOR3(color[1][2], src_line[1], 1); READ_COLOR3(color[1][3], src_line[1], 2);
109 576 READ_COLOR3(color[2][0], src_line[2], 0); color[2][1] = color[2][0]; READ_COLOR3(color[2][2], src_line[2], 1); READ_COLOR3(color[2][3], src_line[2], 2);
110 576 READ_COLOR3(color[3][0], src_line[3], 0); color[3][1] = color[3][0]; READ_COLOR3(color[3][2], src_line[3], 1); READ_COLOR3(color[3][3], src_line[3], 2);
111 576 break;
112 2304 default:
113
6/6
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 1152 times.
✓ Branch 3 taken 1152 times.
✓ Branch 4 taken 1152 times.
✓ Branch 5 taken 1152 times.
2304 READ_COLOR2(color[0][0], src_line[0], 0); color[0][1] = color[0][0]; READ_COLOR2(color[0][2], src_line[0], 1); READ_COLOR2(color[0][3], src_line[0], 2);
114
6/6
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 1152 times.
✓ Branch 3 taken 1152 times.
✓ Branch 4 taken 1152 times.
✓ Branch 5 taken 1152 times.
2304 READ_COLOR2(color[1][0], src_line[1], 0); color[1][1] = color[1][0]; READ_COLOR2(color[1][2], src_line[1], 1); READ_COLOR2(color[1][3], src_line[1], 2);
115
6/6
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 1152 times.
✓ Branch 3 taken 1152 times.
✓ Branch 4 taken 1152 times.
✓ Branch 5 taken 1152 times.
2304 READ_COLOR2(color[2][0], src_line[2], 0); color[2][1] = color[2][0]; READ_COLOR2(color[2][2], src_line[2], 1); READ_COLOR2(color[2][3], src_line[2], 2);
116
6/6
✓ Branch 0 taken 1152 times.
✓ Branch 1 taken 1152 times.
✓ Branch 2 taken 1152 times.
✓ Branch 3 taken 1152 times.
✓ Branch 4 taken 1152 times.
✓ Branch 5 taken 1152 times.
2304 READ_COLOR2(color[3][0], src_line[3], 0); color[3][1] = color[3][0]; READ_COLOR2(color[3][2], src_line[3], 1); READ_COLOR2(color[3][3], src_line[3], 2);
117 }
118
119
2/2
✓ Branch 0 taken 1419264 times.
✓ Branch 1 taken 4032 times.
1423296 for (x = 0; x < width; x++) {
120 uint32_t product1a, product1b, product2a, product2b;
121
122 //--------------------------------------- B0 B1 B2 B3 0 1 2 3
123 // 4 5* 6 S2 -> 4 5* 6 7
124 // 1 2 3 S1 8 9 10 11
125 // A0 A1 A2 A3 12 13 14 15
126 //--------------------------------------
127
4/4
✓ Branch 0 taken 33902 times.
✓ Branch 1 taken 1385362 times.
✓ Branch 2 taken 33756 times.
✓ Branch 3 taken 146 times.
1419264 if (color[2][1] == color[1][2] && color[1][1] != color[2][2]) {
128 33756 product2b = color[2][1];
129 33756 product1b = product2b;
130
4/4
✓ Branch 0 taken 1900 times.
✓ Branch 1 taken 1383608 times.
✓ Branch 2 taken 1754 times.
✓ Branch 3 taken 146 times.
1385508 } else if (color[1][1] == color[2][2] && color[2][1] != color[1][2]) {
131 1754 product2b = color[1][1];
132 1754 product1b = product2b;
133
3/4
✓ Branch 0 taken 146 times.
✓ Branch 1 taken 1383608 times.
✓ Branch 2 taken 146 times.
✗ Branch 3 not taken.
1383754 } else if (color[1][1] == color[2][2] && color[2][1] == color[1][2]) {
134 146 int r = 0;
135
136
2/8
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 146 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
146 r += GET_RESULT(color[1][2], color[1][1], color[1][0], color[3][1]);
137
6/8
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 134 times.
✓ Branch 2 taken 12 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 134 times.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
146 r += GET_RESULT(color[1][2], color[1][1], color[2][0], color[0][1]);
138
8/8
✓ Branch 0 taken 34 times.
✓ Branch 1 taken 112 times.
✓ Branch 2 taken 20 times.
✓ Branch 3 taken 14 times.
✓ Branch 4 taken 34 times.
✓ Branch 5 taken 112 times.
✓ Branch 6 taken 20 times.
✓ Branch 7 taken 14 times.
146 r += GET_RESULT(color[1][2], color[1][1], color[3][2], color[2][3]);
139
6/8
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 114 times.
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 28 times.
✓ Branch 5 taken 118 times.
✓ Branch 6 taken 28 times.
✗ Branch 7 not taken.
146 r += GET_RESULT(color[1][2], color[1][1], color[0][2], color[1][3]);
140
141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 if (r > 0)
142 product1b = color[1][2];
143
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 146 times.
146 else if (r < 0)
144 product1b = color[1][1];
145 else
146 146 product1b = INTERPOLATE(color[1][1], color[1][2]);
147
148 146 product2b = product1b;
149 } else {
150
6/8
✓ Branch 0 taken 8330 times.
✓ Branch 1 taken 1375278 times.
✓ Branch 2 taken 104 times.
✓ Branch 3 taken 8226 times.
✓ Branch 4 taken 104 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 104 times.
✗ Branch 7 not taken.
1383608 if (color[1][2] == color[2][2] && color[2][2] == color[3][1] && color[2][1] != color[3][2] && color[2][2] != color[3][0])
151 104 product2b = Q_INTERPOLATE(color[2][2], color[2][2], color[2][2], color[2][1]);
152
7/8
✓ Branch 0 taken 8652 times.
✓ Branch 1 taken 1374852 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 8624 times.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 24 times.
✓ Branch 7 taken 4 times.
1383504 else if (color[1][1] == color[2][1] && color[2][1] == color[3][2] && color[3][1] != color[2][2] && color[2][1] != color[3][3])
153 24 product2b = Q_INTERPOLATE(color[2][1], color[2][1], color[2][1], color[2][2]);
154 else
155 1383480 product2b = INTERPOLATE(color[2][1], color[2][2]);
156
157
6/8
✓ Branch 0 taken 8330 times.
✓ Branch 1 taken 1375278 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 8302 times.
✓ Branch 4 taken 28 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 28 times.
✗ Branch 7 not taken.
1383608 if (color[1][2] == color[2][2] && color[1][2] == color[0][1] && color[1][1] != color[0][2] && color[1][2] != color[0][0])
158 28 product1b = Q_INTERPOLATE(color[1][2], color[1][2], color[1][2], color[1][1]);
159
7/8
✓ Branch 0 taken 8644 times.
✓ Branch 1 taken 1374936 times.
✓ Branch 2 taken 662 times.
✓ Branch 3 taken 7982 times.
✓ Branch 4 taken 662 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 618 times.
✓ Branch 7 taken 44 times.
1383580 else if (color[1][1] == color[2][1] && color[1][1] == color[0][2] && color[0][1] != color[1][2] && color[1][1] != color[0][3])
160 618 product1b = Q_INTERPOLATE(color[1][2], color[1][1], color[1][1], color[1][1]);
161 else
162 1382962 product1b = INTERPOLATE(color[1][1], color[1][2]);
163 }
164
165
7/8
✓ Branch 0 taken 1900 times.
✓ Branch 1 taken 1417364 times.
✓ Branch 2 taken 1754 times.
✓ Branch 3 taken 146 times.
✓ Branch 4 taken 12 times.
✓ Branch 5 taken 1742 times.
✓ Branch 6 taken 12 times.
✗ Branch 7 not taken.
1419264 if (color[1][1] == color[2][2] && color[2][1] != color[1][2] && color[1][0] == color[1][1] && color[1][1] != color[3][2])
166 12 product2a = INTERPOLATE(color[2][1], color[1][1]);
167
7/8
✓ Branch 0 taken 33890 times.
✓ Branch 1 taken 1385362 times.
✓ Branch 2 taken 260 times.
✓ Branch 3 taken 33630 times.
✓ Branch 4 taken 260 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 216 times.
✓ Branch 7 taken 44 times.
1419252 else if (color[1][1] == color[2][0] && color[1][2] == color[1][1] && color[1][0] != color[2][1] && color[1][1] != color[3][0])
168 216 product2a = INTERPOLATE(color[2][1], color[1][1]);
169 else
170 1419036 product2a = color[2][1];
171
172
8/8
✓ Branch 0 taken 33902 times.
✓ Branch 1 taken 1385362 times.
✓ Branch 2 taken 33756 times.
✓ Branch 3 taken 146 times.
✓ Branch 4 taken 136 times.
✓ Branch 5 taken 33620 times.
✓ Branch 6 taken 128 times.
✓ Branch 7 taken 8 times.
1419264 if (color[2][1] == color[1][2] && color[1][1] != color[2][2] && color[2][0] == color[2][1] && color[2][1] != color[0][2])
173 128 product1a = INTERPOLATE(color[2][1], color[1][1]);
174
7/8
✓ Branch 0 taken 1884 times.
✓ Branch 1 taken 1417252 times.
✓ Branch 2 taken 44 times.
✓ Branch 3 taken 1840 times.
✓ Branch 4 taken 44 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 40 times.
✓ Branch 7 taken 4 times.
1419136 else if (color[1][0] == color[2][1] && color[2][2] == color[2][1] && color[2][0] != color[1][1] && color[2][1] != color[0][0])
175 40 product1a = INTERPOLATE(color[2][1], color[1][1]);
176 else
177 1419096 product1a = color[1][1];
178
179 /* Set the calculated pixels */
180
3/3
✓ Branch 0 taken 405504 times.
✓ Branch 1 taken 202752 times.
✓ Branch 2 taken 811008 times.
1419264 switch (bpp) {
181 405504 case 4:
182 405504 AV_WN32A(dst_line[0] + x * 8, product1a);
183 405504 AV_WN32A(dst_line[0] + x * 8 + 4, product1b);
184 405504 AV_WN32A(dst_line[1] + x * 8, product2a);
185 405504 AV_WN32A(dst_line[1] + x * 8 + 4, product2b);
186 405504 break;
187 202752 case 3:
188 202752 AV_WL24(dst_line[0] + x * 6, product1a);
189 202752 AV_WL24(dst_line[0] + x * 6 + 3, product1b);
190 202752 AV_WL24(dst_line[1] + x * 6, product2a);
191 202752 AV_WL24(dst_line[1] + x * 6 + 3, product2b);
192 202752 break;
193 811008 default: // bpp = 2
194
2/2
✓ Branch 0 taken 405504 times.
✓ Branch 1 taken 405504 times.
811008 if (s->is_be) {
195 405504 AV_WB32(dst_line[0] + x * 4, product1a | (product1b << 16));
196 405504 AV_WB32(dst_line[1] + x * 4, product2a | (product2b << 16));
197 } else {
198 405504 AV_WL32(dst_line[0] + x * 4, product1a | (product1b << 16));
199 405504 AV_WL32(dst_line[1] + x * 4, product2a | (product2b << 16));
200 }
201 }
202
203 /* Move color matrix forward */
204 1419264 color[0][0] = color[0][1]; color[0][1] = color[0][2]; color[0][2] = color[0][3];
205 1419264 color[1][0] = color[1][1]; color[1][1] = color[1][2]; color[1][2] = color[1][3];
206 1419264 color[2][0] = color[2][1]; color[2][1] = color[2][2]; color[2][2] = color[2][3];
207 1419264 color[3][0] = color[3][1]; color[3][1] = color[3][2]; color[3][2] = color[3][3];
208
209
2/2
✓ Branch 0 taken 1407168 times.
✓ Branch 1 taken 12096 times.
1419264 if (x < width - 3) {
210 1407168 x += 3;
211
3/3
✓ Branch 0 taken 402048 times.
✓ Branch 1 taken 201024 times.
✓ Branch 2 taken 804096 times.
1407168 switch (bpp) {
212 402048 case 4:
213 402048 READ_COLOR4(color[0][3], src_line[0], x);
214 402048 READ_COLOR4(color[1][3], src_line[1], x);
215 402048 READ_COLOR4(color[2][3], src_line[2], x);
216 402048 READ_COLOR4(color[3][3], src_line[3], x);
217 402048 break;
218 201024 case 3:
219 201024 READ_COLOR3(color[0][3], src_line[0], x);
220 201024 READ_COLOR3(color[1][3], src_line[1], x);
221 201024 READ_COLOR3(color[2][3], src_line[2], x);
222 201024 READ_COLOR3(color[3][3], src_line[3], x);
223 201024 break;
224 804096 default: /* case 2 */
225
2/2
✓ Branch 0 taken 402048 times.
✓ Branch 1 taken 402048 times.
804096 READ_COLOR2(color[0][3], src_line[0], x);
226
2/2
✓ Branch 0 taken 402048 times.
✓ Branch 1 taken 402048 times.
804096 READ_COLOR2(color[1][3], src_line[1], x);
227
2/2
✓ Branch 0 taken 402048 times.
✓ Branch 1 taken 402048 times.
804096 READ_COLOR2(color[2][3], src_line[2], x);
228
2/2
✓ Branch 0 taken 402048 times.
✓ Branch 1 taken 402048 times.
804096 READ_COLOR2(color[3][3], src_line[3], x);
229 }
230 1407168 x -= 3;
231 }
232 }
233
234 /* We're done with one line, so we shift the source lines up */
235 4032 src_line[0] = src_line[1];
236 4032 src_line[1] = src_line[2];
237 4032 src_line[2] = src_line[3];
238
239 /* Read next line */
240 4032 src_line[3] = src_line[2];
241
2/2
✓ Branch 0 taken 3990 times.
✓ Branch 1 taken 42 times.
4032 if (y < height - 3)
242 3990 src_line[3] += src_linesize;
243 } // y loop
244
245 14 return 0;
246 }
247
248 static const enum AVPixelFormat pix_fmts[] = {
249 AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR,
250 AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24,
251 AV_PIX_FMT_RGB565BE, AV_PIX_FMT_BGR565BE, AV_PIX_FMT_RGB555BE, AV_PIX_FMT_BGR555BE,
252 AV_PIX_FMT_RGB565LE, AV_PIX_FMT_BGR565LE, AV_PIX_FMT_RGB555LE, AV_PIX_FMT_BGR555LE,
253 AV_PIX_FMT_NONE
254 };
255
256 14 static int config_input(AVFilterLink *inlink)
257 {
258 14 Super2xSaIContext *s = inlink->dst->priv;
259
260 14 s->hi_pixel_mask = 0xFEFEFEFE;
261 14 s->lo_pixel_mask = 0x01010101;
262 14 s->q_hi_pixel_mask = 0xFCFCFCFC;
263 14 s->q_lo_pixel_mask = 0x03030303;
264 14 s->bpp = 4;
265
266
6/6
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 2 times.
✓ Branch 4 taken 2 times.
✓ Branch 5 taken 4 times.
14 switch (inlink->format) {
267 2 case AV_PIX_FMT_RGB24:
268 case AV_PIX_FMT_BGR24:
269 2 s->bpp = 3;
270 2 break;
271
272 2 case AV_PIX_FMT_RGB565BE:
273 case AV_PIX_FMT_BGR565BE:
274 2 s->is_be = 1;
275 4 case AV_PIX_FMT_RGB565LE:
276 case AV_PIX_FMT_BGR565LE:
277 4 s->hi_pixel_mask = 0xF7DEF7DE;
278 4 s->lo_pixel_mask = 0x08210821;
279 4 s->q_hi_pixel_mask = 0xE79CE79C;
280 4 s->q_lo_pixel_mask = 0x18631863;
281 4 s->bpp = 2;
282 4 break;
283
284 2 case AV_PIX_FMT_BGR555BE:
285 case AV_PIX_FMT_RGB555BE:
286 2 s->is_be = 1;
287 4 case AV_PIX_FMT_BGR555LE:
288 case AV_PIX_FMT_RGB555LE:
289 4 s->hi_pixel_mask = 0x7BDE7BDE;
290 4 s->lo_pixel_mask = 0x04210421;
291 4 s->q_hi_pixel_mask = 0x739C739C;
292 4 s->q_lo_pixel_mask = 0x0C630C63;
293 4 s->bpp = 2;
294 4 break;
295 }
296
297 14 return 0;
298 }
299
300 14 static int config_output(AVFilterLink *outlink)
301 {
302 14 AVFilterLink *inlink = outlink->src->inputs[0];
303
304 14 outlink->w = inlink->w*2;
305 14 outlink->h = inlink->h*2;
306
307 14 av_log(inlink->dst, AV_LOG_VERBOSE, "fmt:%s size:%dx%d -> size:%dx%d\n",
308 14 av_get_pix_fmt_name(inlink->format),
309 inlink->w, inlink->h, outlink->w, outlink->h);
310
311 14 return 0;
312 }
313
314 14 static int filter_frame(AVFilterLink *inlink, AVFrame *in)
315 {
316 14 AVFilterContext *ctx = inlink->dst;
317 14 AVFilterLink *outlink = ctx->outputs[0];
318 ThreadData td;
319 14 AVFrame *out = ff_get_video_buffer(outlink, outlink->w, outlink->h);
320
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
14 if (!out) {
321 av_frame_free(&in);
322 return AVERROR(ENOMEM);
323 }
324 14 av_frame_copy_props(out, in);
325 14 out->width = outlink->w;
326 14 out->height = outlink->h;
327
328 14 td.in = in, td.out = out;
329 14 ff_filter_execute(ctx, super2xsai, &td, NULL,
330
1/2
✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
14 FFMIN(in->height, ff_filter_get_nb_threads(ctx)));
331
332 14 av_frame_free(&in);
333 14 return ff_filter_frame(outlink, out);
334 }
335
336 static const AVFilterPad super2xsai_inputs[] = {
337 {
338 .name = "default",
339 .type = AVMEDIA_TYPE_VIDEO,
340 .config_props = config_input,
341 .filter_frame = filter_frame,
342 },
343 };
344
345 static const AVFilterPad super2xsai_outputs[] = {
346 {
347 .name = "default",
348 .type = AVMEDIA_TYPE_VIDEO,
349 .config_props = config_output,
350 },
351 };
352
353 const AVFilter ff_vf_super2xsai = {
354 .name = "super2xsai",
355 .description = NULL_IF_CONFIG_SMALL("Scale the input by 2x using the Super2xSaI pixel art algorithm."),
356 .priv_size = sizeof(Super2xSaIContext),
357 FILTER_INPUTS(super2xsai_inputs),
358 FILTER_OUTPUTS(super2xsai_outputs),
359 FILTER_PIXFMTS_ARRAY(pix_fmts),
360 .flags = AVFILTER_FLAG_SLICE_THREADS,
361 };
362