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 | |||
44 | /** | ||
45 | * Special version of ff_simple_idct_int16_10bit() which does dequantization | ||
46 | * and scales by a factor of 2 more between the two IDCTs to account | ||
47 | * for larger scale of input coefficients. | ||
48 | */ | ||
49 | 2759952 | static void prores_idct_10(int16_t *restrict block, const int16_t *restrict qmat) | |
50 | { | ||
51 |
2/2✓ Branch 0 taken 176636928 times.
✓ Branch 1 taken 2759952 times.
|
179396880 | for (int i = 0; i < 64; i++) |
52 | 176636928 | block[i] *= qmat[i]; | |
53 | |||
54 |
2/2✓ Branch 0 taken 22079616 times.
✓ Branch 1 taken 2759952 times.
|
24839568 | for (int i = 0; i < 8; i++) |
55 | 22079616 | idctRowCondDC_extrashift_10(block + i*8, 2); | |
56 | |||
57 |
2/2✓ Branch 0 taken 22079616 times.
✓ Branch 1 taken 2759952 times.
|
24839568 | for (int i = 0; i < 8; i++) { |
58 | 22079616 | block[i] += 8192; | |
59 | 22079616 | idctSparseCol_extrashift_10(block + i); | |
60 | } | ||
61 | 2759952 | } | |
62 | |||
63 | 2446164 | static void prores_idct_12(int16_t *restrict block, const int16_t *restrict qmat) | |
64 | { | ||
65 |
2/2✓ Branch 0 taken 156554496 times.
✓ Branch 1 taken 2446164 times.
|
159000660 | for (int i = 0; i < 64; i++) |
66 | 156554496 | block[i] *= qmat[i]; | |
67 | |||
68 |
2/2✓ Branch 0 taken 19569312 times.
✓ Branch 1 taken 2446164 times.
|
22015476 | for (int i = 0; i < 8; i++) |
69 | 19569312 | idctRowCondDC_int16_12bit(block + i*8, 0); | |
70 | |||
71 |
2/2✓ Branch 0 taken 19569312 times.
✓ Branch 1 taken 2446164 times.
|
22015476 | for (int i = 0; i < 8; i++) { |
72 | 19569312 | block[i] += 8192; | |
73 | 19569312 | idctSparseCol_int16_12bit(block + i); | |
74 | } | ||
75 | 2446164 | } | |
76 | |||
77 | #define CLIP_MIN (1 << 2) ///< minimum value for clipping resulting pixels | ||
78 | #define CLIP_MAX_10 (1 << 10) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels | ||
79 | #define CLIP_MAX_12 (1 << 12) - CLIP_MIN - 1 ///< maximum value for clipping resulting pixels | ||
80 | |||
81 | #define CLIP_10(x) (av_clip((x), CLIP_MIN, CLIP_MAX_10)) | ||
82 | #define CLIP_12(x) (av_clip((x), CLIP_MIN, CLIP_MAX_12)) | ||
83 | |||
84 | /** | ||
85 | * Add bias value, clamp and output pixels of a slice | ||
86 | */ | ||
87 | |||
88 | 5146116 | static inline void put_pixel(uint16_t *dst, ptrdiff_t linesize, const int16_t *in, int bits_per_raw_sample) { | |
89 |
2/2✓ Branch 0 taken 41168928 times.
✓ Branch 1 taken 5146116 times.
|
46315044 | for (int y = 0; y < 8; y++, dst += linesize) { |
90 |
2/2✓ Branch 0 taken 329351424 times.
✓ Branch 1 taken 41168928 times.
|
370520352 | for (int x = 0; x < 8; x++) { |
91 | 329351424 | int src_offset = (y << 3) + x; | |
92 | |||
93 |
2/2✓ Branch 0 taken 172796928 times.
✓ Branch 1 taken 156554496 times.
|
329351424 | if (bits_per_raw_sample == 10) { |
94 | 172796928 | dst[x] = CLIP_10(in[src_offset]); | |
95 | } else {//12b | ||
96 | 156554496 | dst[x] = CLIP_12(in[src_offset]); | |
97 | } | ||
98 | } | ||
99 | } | ||
100 | 5146116 | } | |
101 | |||
102 | ✗ | static inline void put_pixel_bayer_12(uint16_t *dst, ptrdiff_t linesize, | |
103 | const int16_t *in) | ||
104 | { | ||
105 | ✗ | for (int y = 0; y < 8; y++, dst += linesize) { | |
106 | ✗ | for (int x = 0; x < 8; x++) | |
107 | ✗ | dst[x*2] = CLIP_12(in[(y << 3) + x]) << 4; | |
108 | } | ||
109 | ✗ | } | |
110 | |||
111 | 2699952 | static void put_pixels_10(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) | |
112 | { | ||
113 | 2699952 | put_pixel(dst, linesize, in, 10); | |
114 | 2699952 | } | |
115 | |||
116 | 2446164 | static void put_pixels_12(uint16_t *dst, ptrdiff_t linesize, const int16_t *in) | |
117 | { | ||
118 | 2446164 | put_pixel(dst, linesize, in, 12); | |
119 | 2446164 | } | |
120 | |||
121 | 2699952 | static void prores_idct_put_10_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat) | |
122 | { | ||
123 | 2699952 | prores_idct_10(block, qmat); | |
124 | 2699952 | put_pixels_10(out, linesize >> 1, block); | |
125 | 2699952 | } | |
126 | |||
127 | 2446164 | static void prores_idct_put_12_c(uint16_t *out, ptrdiff_t linesize, int16_t *block, const int16_t *qmat) | |
128 | { | ||
129 | 2446164 | prores_idct_12(block, qmat); | |
130 | 2446164 | put_pixels_12(out, linesize >> 1, block); | |
131 | 2446164 | } | |
132 | |||
133 | ✗ | static void prores_idct_put_bayer_12_c(uint16_t *out, ptrdiff_t linesize, | |
134 | int16_t *block, const int16_t *qmat) | ||
135 | { | ||
136 | ✗ | prores_idct_12(block, qmat); | |
137 | ✗ | put_pixel_bayer_12(out, linesize << 1, block); | |
138 | ✗ | } | |
139 | |||
140 | 73 | av_cold void ff_proresdsp_init(ProresDSPContext *dsp, int bits_per_raw_sample) | |
141 | { | ||
142 |
2/2✓ Branch 0 taken 49 times.
✓ Branch 1 taken 24 times.
|
73 | if (bits_per_raw_sample == 10) { |
143 | 49 | dsp->idct_put = prores_idct_put_10_c; | |
144 | 49 | dsp->idct_permutation_type = FF_IDCT_PERM_NONE; | |
145 | } else { | ||
146 | av_assert1(bits_per_raw_sample == 12); | ||
147 | 24 | dsp->idct_put = prores_idct_put_12_c; | |
148 | 24 | dsp->idct_put_bayer = prores_idct_put_bayer_12_c; | |
149 | 24 | dsp->idct_permutation_type = FF_IDCT_PERM_NONE; | |
150 | } | ||
151 | |||
152 | #if ARCH_X86 | ||
153 | 73 | ff_proresdsp_init_x86(dsp, bits_per_raw_sample); | |
154 | #endif | ||
155 | |||
156 | 73 | ff_init_scantable_permutation(dsp->idct_permutation, | |
157 | 73 | dsp->idct_permutation_type); | |
158 | 73 | } | |
159 |