FFmpeg coverage


Directory: ../../../ffmpeg/
File: src/libavcodec/proresdsp.c
Date: 2026-09-26 05:01:43
Exec Total Coverage
Lines: 51 74 68.9%
Functions: 8 11 72.7%
Branches: 20 32 62.5%

Line Branch Exec Source
1 /*
2 * Apple ProRes compatible decoder
3 *
4 * Copyright (c) 2010-2011 Maxim Poliakovski
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (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 GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config.h"
24 #include "libavutil/attributes.h"
25 #include "libavutil/avassert.h"
26 #include "libavutil/common.h"
27 #include "libavutil/intreadwrite.h"
28 #include "idctdsp.h"
29 #include "proresdsp.h"
30
31 #define IN_IDCT_DEPTH 16
32 #define PRORES_ONLY
33
34 #define BIT_DEPTH 10
35 #define EXTRA_SHIFT
36 #include "simple_idct_template.c"
37 #undef BIT_DEPTH
38 #undef EXTRA_SHIFT
39
40 #define BIT_DEPTH 12
41 #include "simple_idct_template.c"
42 #undef BIT_DEPTH
43 #undef IN_IDCT_DEPTH
44
45 /* 16-bit iDCT for ProRes RAW */
46 #define IN_IDCT_DEPTH 32
47 #define BIT_DEPTH 16
48 #include "simple_idct_template.c"
49 #undef BIT_DEPTH
50 #undef IN_IDCT_DEPTH
51
52 /**
53 * Special version of ff_simple_idct_int16_10bit() which does dequantization
54 * and scales by a factor of 2 more between the two IDCTs to account
55 * for larger scale of input coefficients.
56 */
57 2189760 static void prores_idct_10(int16_t *restrict block, const int16_t *restrict qmat)
58 {
59
2/2
✓ Branch 0 taken 140144640 times.
✓ Branch 1 taken 2189760 times.
142334400 for (int i = 0; i < 64; i++)
60 140144640 block[i] *= qmat[i];
61
62
2/2
✓ Branch 0 taken 17518080 times.
✓ Branch 1 taken 2189760 times.
19707840 for (int i = 0; i < 8; i++)
63 17518080 idctRowCondDC_extrashift_10(block + i*8, 2);
64
65
2/2
✓ Branch 0 taken 17518080 times.
✓ Branch 1 taken 2189760 times.
19707840 for (int i = 0; i < 8; i++) {
66 17518080 block[i] += 8192;
67 17518080 idctSparseCol_extrashift_10(block + i);
68 }
69 2189760 }
70
71 2025722 static void prores_idct_12(int16_t *restrict block, const int16_t *restrict qmat)
72 {
73
2/2
✓ Branch 0 taken 129646208 times.
✓ Branch 1 taken 2025722 times.
131671930 for (int i = 0; i < 64; i++)
74 129646208 block[i] *= qmat[i];
75
76
2/2
✓ Branch 0 taken 16205776 times.
✓ Branch 1 taken 2025722 times.
18231498 for (int i = 0; i < 8; i++)
77 16205776 idctRowCondDC_int16_12bit(block + i*8, 0);
78
79
2/2
✓ Branch 0 taken 16205776 times.
✓ Branch 1 taken 2025722 times.
18231498 for (int i = 0; i < 8; i++) {
80 16205776 block[i] += 8192;
81 16205776 idctSparseCol_int16_12bit(block + i);
82 }
83 2025722 }
84
85 /*
86 * ProRes RAW iDCT: 16-bit coefficients to a 16-bit output centered on zero
87 */
88 ✗ static void prores_idct_bayer_16(int32_t *restrict block, const int16_t *restrict qmat)
89 {
90 ✗ for (int i = 0; i < 64; i++)
91 ✗ block[i] = av_clip_int16(block[i] * qmat[i]);
92
93 ✗ for (int i = 0; i < 8; i++)
94 ✗ idctRowCondDC_int32_16bit(block + i*8, 0);
95
96 ✗ for (int i = 0; i < 8; i++)
97 ✗ idctSparseCol_int32_16bit(block + i);
98 ✗ }
99
100 #define CLIP_MIN (1 << 2) ///< minimum value for clipping resulting pixels
101 #define CLIP_MAX_10 (1 << 10) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels
102 #define CLIP_MAX_12 (1 << 12) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels
103
104 #define CLIP_10(x) (av_clip((x), CLIP_MIN, CLIP_MAX_10))
105 #define CLIP_12(x) (av_clip((x), CLIP_MIN, CLIP_MAX_12))
106
107 /**
108 * Add bias value, clamp and output pixels of a slice
109 */
110
111 4155482 static inline void put_pixel(uint16_t *dst, ptrdiff_t linesize, const int16_t *in, int bits_per_raw_sample) {
112
2/2
✓ Branch 0 taken 33243856 times.
✓ Branch 1 taken 4155482 times.
37399338 for (int y = 0; y < 8; y++, dst += linesize) {
113
2/2
✓ Branch 0 taken 265950848 times.
✓ Branch 1 taken 33243856 times.
299194704 for (int x = 0; x < 8; x++) {
114 265950848 int src_offset = (y << 3) + x;
115
116
2/2
✓ Branch 0 taken 136304640 times.
✓ Branch 1 taken 129646208 times.
265950848 if (bits_per_raw_sample == 10) {
117 136304640 dst[x] = CLIP_10(in[src_offset]);
118 } else {//12b
119 129646208 dst[x] = CLIP_12(in[src_offset]);
120 }
121 }
122 }
123 4155482 }
124
125 /* Apply the 8-point combined linearization curve (inv. transfer fn + encoder shaping) */
126 ✗ static inline void put_pixel_bayer_lin_curve_12(uint16_t *dst, ptrdiff_t linesize,
127 const int32_t *in, const uint16_t *lin_curve)
128 {
129 ✗ for (int y = 0; y < 8; y++, dst += linesize) {
130 ✗ for (int x = 0; x < 8; x++) {
131 ✗ uint32_t u = av_clip_uint16(in[(y << 3) + x] + 32768);
132 ✗ uint32_t seg = u >> 13;
133 ✗ uint32_t frac = u & 0x1FFF;
134 ✗ uint32_t cp0 = lin_curve[seg];
135 ✗ uint32_t cp1 = seg < 7 ? lin_curve[seg + 1] : 0;
136 ✗ uint32_t o = (cp0 * 8192 + ((cp1 - cp0) & 0xFFFF) * frac + 4096) >> 13;
137 ✗ dst[x*2] = FFMIN(o, 0xFFFF);
138 }
139 }
140 ✗ }
141
142 2129760 static void put_pixels_10(uint16_t *dst, ptrdiff_t linesize, const int16_t *in)
143 {
144 2129760 put_pixel(dst, linesize, in, 10);
145 2129760 }
146
147 2025722 static void put_pixels_12(uint16_t *dst, ptrdiff_t linesize, const int16_t *in)
148 {
149 2025722 put_pixel(dst, linesize, in, 12);
150 2025722 }
151
152 2129760 static void prores_idct_put_10_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat)
153 {
154 2129760 prores_idct_10(block, qmat);
155 2129760 put_pixels_10(out, linesize >> 1, block);
156 2129760 }
157
158 2025722 static void prores_idct_put_12_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat)
159 {
160 2025722 prores_idct_12(block, qmat);
161 2025722 put_pixels_12(out, linesize >> 1, block);
162 2025722 }
163
164 ✗ static void prores_idct_put_bayer_12_c(uint16_t *out, ptrdiff_t linesize,
165 int32_t *block, const int16_t *qmat,
166 const uint16_t *lin_curve)
167 {
168 ✗ prores_idct_bayer_16(block, qmat);
169 ✗ put_pixel_bayer_lin_curve_12(out, linesize << 1, block, lin_curve);
170 ✗ }
171
172 90 av_cold void ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample)
173 {
174
2/2
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 38 times.
90 if (bits_per_raw_sample == 10) {
175 52 dsp->idct_put = prores_idct_put_10_c;
176 52 dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
177 } else {
178 av_assert1(bits_per_raw_sample == 12);
179 38 dsp->idct_put = prores_idct_put_12_c;
180 38 dsp->idct_put_bayer = prores_idct_put_bayer_12_c;
181 38 dsp->idct_permutation_type = FF_IDCT_PERM_NONE;
182 }
183
184 #if ARCH_X86 && HAVE_X86ASM
185 90 ff_proresdsp_init_x86(dsp, bits_per_raw_sample);
186 #endif
187
188 90 ff_init_scantable_permutation(dsp->idct_permutation,
189 90 dsp->idct_permutation_type);
190 90 }
191