/work/dav1d/src/fg_apply_tmpl.c
Line | Count | Source |
1 | | /* |
2 | | * Copyright © 2018, Niklas Haas |
3 | | * Copyright © 2018, VideoLAN and dav1d authors |
4 | | * Copyright © 2018, Two Orioles, LLC |
5 | | * All rights reserved. |
6 | | * |
7 | | * Redistribution and use in source and binary forms, with or without |
8 | | * modification, are permitted provided that the following conditions are met: |
9 | | * |
10 | | * 1. Redistributions of source code must retain the above copyright notice, this |
11 | | * list of conditions and the following disclaimer. |
12 | | * |
13 | | * 2. Redistributions in binary form must reproduce the above copyright notice, |
14 | | * this list of conditions and the following disclaimer in the documentation |
15 | | * and/or other materials provided with the distribution. |
16 | | * |
17 | | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
18 | | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
19 | | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
20 | | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
21 | | * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
22 | | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
23 | | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
24 | | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
26 | | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | | */ |
28 | | |
29 | | #include "config.h" |
30 | | |
31 | | #include <stdint.h> |
32 | | |
33 | | #include "dav1d/common.h" |
34 | | #include "dav1d/picture.h" |
35 | | |
36 | | #include "common/intops.h" |
37 | | #include "common/bitdepth.h" |
38 | | |
39 | | #include "src/fg_apply.h" |
40 | | |
41 | | static void generate_scaling(const int bitdepth, |
42 | | const uint8_t points[][2], const int num, |
43 | | uint8_t scaling[SCALING_SIZE]) |
44 | 2.04k | { |
45 | 2.04k | #if BITDEPTH == 8 |
46 | 2.04k | const int shift_x = 0; |
47 | 2.04k | const int scaling_size = SCALING_SIZE; |
48 | | #else |
49 | | assert(bitdepth > 8); |
50 | | const int shift_x = bitdepth - 8; |
51 | | const int scaling_size = 1 << bitdepth; |
52 | | #endif |
53 | | |
54 | 2.04k | if (num == 0) { |
55 | 173 | memset(scaling, 0, scaling_size); |
56 | 173 | return; |
57 | 173 | } |
58 | | |
59 | | // Fill up the preceding entries with the initial value |
60 | 1.87k | memset(scaling, points[0][1], points[0][0] << shift_x); |
61 | | |
62 | | // Linearly interpolate the values in the middle |
63 | 2.76k | for (int i = 0; i < num - 1; i++) { |
64 | 895 | const int bx = points[i][0]; |
65 | 895 | const int by = points[i][1]; |
66 | 895 | const int ex = points[i+1][0]; |
67 | 895 | const int ey = points[i+1][1]; |
68 | 895 | const int dx = ex - bx; |
69 | 895 | const int dy = ey - by; |
70 | 895 | assert(dx > 0); |
71 | 895 | const int delta = dy * ((0x10000 + (dx >> 1)) / dx); |
72 | 73.0k | for (int x = 0, d = 0x8000; x < dx; x++) { |
73 | 72.1k | scaling[(bx + x) << shift_x] = by + (d >> 16); |
74 | 72.1k | d += delta; |
75 | 72.1k | } |
76 | 895 | } |
77 | | |
78 | | // Fill up the remaining entries with the final value |
79 | 1.87k | const int n = points[num - 1][0] << shift_x; |
80 | 1.87k | memset(&scaling[n], points[num - 1][1], scaling_size - n); |
81 | | |
82 | | #if BITDEPTH != 8 |
83 | | const int pad = 1 << shift_x, rnd = pad >> 1; |
84 | | for (int i = 0; i < num - 1; i++) { |
85 | | const int bx = points[i][0] << shift_x; |
86 | | const int ex = points[i+1][0] << shift_x; |
87 | | const int dx = ex - bx; |
88 | | for (int x = 0; x < dx; x += pad) { |
89 | | const int range = scaling[bx + x + pad] - scaling[bx + x]; |
90 | | for (int n = 1, r = rnd; n < pad; n++) { |
91 | | r += range; |
92 | | scaling[bx + x + n] = scaling[bx + x] + (r >> shift_x); |
93 | | } |
94 | | } |
95 | | } |
96 | | #endif |
97 | 1.87k | } |
98 | | |
99 | | #ifndef UNIT_TEST |
100 | | void bitfn(dav1d_prep_grain)(const Dav1dFilmGrainDSPContext *const dsp, |
101 | | Dav1dPicture *const out, |
102 | | const Dav1dPicture *const in, |
103 | | uint8_t scaling[3][SCALING_SIZE], |
104 | | entry grain_lut[3][GRAIN_HEIGHT+1][GRAIN_WIDTH]) |
105 | 3.66k | { |
106 | 3.66k | const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data; |
107 | | #if BITDEPTH != 8 |
108 | | const int bitdepth_max = (1 << out->p.bpc) - 1; |
109 | | #endif |
110 | | |
111 | | // Generate grain LUTs as needed |
112 | 3.66k | dsp->generate_grain_y(grain_lut[0], data HIGHBD_TAIL_SUFFIX); // always needed |
113 | 3.66k | if (data->num_uv_points[0] || data->chroma_scaling_from_luma) |
114 | 2.54k | dsp->generate_grain_uv[in->p.layout - 1](grain_lut[1], grain_lut[0], |
115 | 2.54k | data, 0 HIGHBD_TAIL_SUFFIX); |
116 | 3.66k | if (data->num_uv_points[1] || data->chroma_scaling_from_luma) |
117 | 2.53k | dsp->generate_grain_uv[in->p.layout - 1](grain_lut[2], grain_lut[0], |
118 | 2.53k | data, 1 HIGHBD_TAIL_SUFFIX); |
119 | | |
120 | | // Generate scaling LUTs as needed |
121 | 3.66k | if (data->num_y_points || data->chroma_scaling_from_luma) |
122 | 3.05k | generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]); |
123 | 3.66k | if (data->num_uv_points[0]) |
124 | 748 | generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]); |
125 | 3.66k | if (data->num_uv_points[1]) |
126 | 741 | generate_scaling(in->p.bpc, data->uv_points[1], data->num_uv_points[1], scaling[2]); |
127 | | |
128 | | // Copy over the non-modified planes |
129 | 3.66k | assert(out->stride[0] == in->stride[0]); |
130 | 3.66k | if (!data->num_y_points) { |
131 | 1.09k | const ptrdiff_t stride = out->stride[0]; |
132 | 1.09k | const ptrdiff_t sz = out->p.h * stride; |
133 | 1.09k | if (sz < 0) |
134 | 0 | memcpy((uint8_t*) out->data[0] + sz - stride, |
135 | 0 | (uint8_t*) in->data[0] + sz - stride, -sz); |
136 | 1.09k | else |
137 | 1.09k | memcpy(out->data[0], in->data[0], sz); |
138 | 1.09k | } |
139 | | |
140 | 3.66k | if (in->p.layout != DAV1D_PIXEL_LAYOUT_I400 && !data->chroma_scaling_from_luma) { |
141 | 1.63k | assert(out->stride[1] == in->stride[1]); |
142 | 1.63k | const int ss_ver = in->p.layout == DAV1D_PIXEL_LAYOUT_I420; |
143 | 1.63k | const ptrdiff_t stride = out->stride[1]; |
144 | 1.63k | const ptrdiff_t sz = ((out->p.h + ss_ver) >> ss_ver) * stride; |
145 | 1.63k | if (sz < 0) { |
146 | 0 | if (!data->num_uv_points[0]) |
147 | 0 | memcpy((uint8_t*) out->data[1] + sz - stride, |
148 | 0 | (uint8_t*) in->data[1] + sz - stride, -sz); |
149 | 0 | if (!data->num_uv_points[1]) |
150 | 0 | memcpy((uint8_t*) out->data[2] + sz - stride, |
151 | 0 | (uint8_t*) in->data[2] + sz - stride, -sz); |
152 | 1.63k | } else { |
153 | 1.63k | if (!data->num_uv_points[0]) |
154 | 882 | memcpy(out->data[1], in->data[1], sz); |
155 | 1.63k | if (!data->num_uv_points[1]) |
156 | 889 | memcpy(out->data[2], in->data[2], sz); |
157 | 1.63k | } |
158 | 1.63k | } |
159 | 3.66k | } Line | Count | Source | 105 | 1.70k | { | 106 | 1.70k | const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data; | 107 | | #if BITDEPTH != 8 | 108 | | const int bitdepth_max = (1 << out->p.bpc) - 1; | 109 | | #endif | 110 | | | 111 | | // Generate grain LUTs as needed | 112 | 1.70k | dsp->generate_grain_y(grain_lut[0], data HIGHBD_TAIL_SUFFIX); // always needed | 113 | 1.70k | if (data->num_uv_points[0] || data->chroma_scaling_from_luma) | 114 | 1.11k | dsp->generate_grain_uv[in->p.layout - 1](grain_lut[1], grain_lut[0], | 115 | 1.11k | data, 0 HIGHBD_TAIL_SUFFIX); | 116 | 1.70k | if (data->num_uv_points[1] || data->chroma_scaling_from_luma) | 117 | 1.29k | dsp->generate_grain_uv[in->p.layout - 1](grain_lut[2], grain_lut[0], | 118 | 1.29k | data, 1 HIGHBD_TAIL_SUFFIX); | 119 | | | 120 | | // Generate scaling LUTs as needed | 121 | 1.70k | if (data->num_y_points || data->chroma_scaling_from_luma) | 122 | 1.28k | generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]); | 123 | 1.70k | if (data->num_uv_points[0]) | 124 | 289 | generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]); | 125 | 1.70k | if (data->num_uv_points[1]) | 126 | 466 | generate_scaling(in->p.bpc, data->uv_points[1], data->num_uv_points[1], scaling[2]); | 127 | | | 128 | | // Copy over the non-modified planes | 129 | 1.70k | assert(out->stride[0] == in->stride[0]); | 130 | 1.70k | if (!data->num_y_points) { | 131 | 592 | const ptrdiff_t stride = out->stride[0]; | 132 | 592 | const ptrdiff_t sz = out->p.h * stride; | 133 | 592 | if (sz < 0) | 134 | 0 | memcpy((uint8_t*) out->data[0] + sz - stride, | 135 | 0 | (uint8_t*) in->data[0] + sz - stride, -sz); | 136 | 592 | else | 137 | 592 | memcpy(out->data[0], in->data[0], sz); | 138 | 592 | } | 139 | | | 140 | 1.70k | if (in->p.layout != DAV1D_PIXEL_LAYOUT_I400 && !data->chroma_scaling_from_luma) { | 141 | 784 | assert(out->stride[1] == in->stride[1]); | 142 | 784 | const int ss_ver = in->p.layout == DAV1D_PIXEL_LAYOUT_I420; | 143 | 784 | const ptrdiff_t stride = out->stride[1]; | 144 | 784 | const ptrdiff_t sz = ((out->p.h + ss_ver) >> ss_ver) * stride; | 145 | 784 | if (sz < 0) { | 146 | 0 | if (!data->num_uv_points[0]) | 147 | 0 | memcpy((uint8_t*) out->data[1] + sz - stride, | 148 | 0 | (uint8_t*) in->data[1] + sz - stride, -sz); | 149 | 0 | if (!data->num_uv_points[1]) | 150 | 0 | memcpy((uint8_t*) out->data[2] + sz - stride, | 151 | 0 | (uint8_t*) in->data[2] + sz - stride, -sz); | 152 | 784 | } else { | 153 | 784 | if (!data->num_uv_points[0]) | 154 | 495 | memcpy(out->data[1], in->data[1], sz); | 155 | 784 | if (!data->num_uv_points[1]) | 156 | 318 | memcpy(out->data[2], in->data[2], sz); | 157 | 784 | } | 158 | 784 | } | 159 | 1.70k | } |
Line | Count | Source | 105 | 1.95k | { | 106 | 1.95k | const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data; | 107 | 1.95k | #if BITDEPTH != 8 | 108 | 1.95k | const int bitdepth_max = (1 << out->p.bpc) - 1; | 109 | 1.95k | #endif | 110 | | | 111 | | // Generate grain LUTs as needed | 112 | 1.95k | dsp->generate_grain_y(grain_lut[0], data HIGHBD_TAIL_SUFFIX); // always needed | 113 | 1.95k | if (data->num_uv_points[0] || data->chroma_scaling_from_luma) | 114 | 1.42k | dsp->generate_grain_uv[in->p.layout - 1](grain_lut[1], grain_lut[0], | 115 | 1.42k | data, 0 HIGHBD_TAIL_SUFFIX); | 116 | 1.95k | if (data->num_uv_points[1] || data->chroma_scaling_from_luma) | 117 | 1.24k | dsp->generate_grain_uv[in->p.layout - 1](grain_lut[2], grain_lut[0], | 118 | 1.24k | data, 1 HIGHBD_TAIL_SUFFIX); | 119 | | | 120 | | // Generate scaling LUTs as needed | 121 | 1.95k | if (data->num_y_points || data->chroma_scaling_from_luma) | 122 | 1.76k | generate_scaling(in->p.bpc, data->y_points, data->num_y_points, scaling[0]); | 123 | 1.95k | if (data->num_uv_points[0]) | 124 | 459 | generate_scaling(in->p.bpc, data->uv_points[0], data->num_uv_points[0], scaling[1]); | 125 | 1.95k | if (data->num_uv_points[1]) | 126 | 275 | generate_scaling(in->p.bpc, data->uv_points[1], data->num_uv_points[1], scaling[2]); | 127 | | | 128 | | // Copy over the non-modified planes | 129 | 1.95k | assert(out->stride[0] == in->stride[0]); | 130 | 1.95k | if (!data->num_y_points) { | 131 | 506 | const ptrdiff_t stride = out->stride[0]; | 132 | 506 | const ptrdiff_t sz = out->p.h * stride; | 133 | 506 | if (sz < 0) | 134 | 0 | memcpy((uint8_t*) out->data[0] + sz - stride, | 135 | 0 | (uint8_t*) in->data[0] + sz - stride, -sz); | 136 | 506 | else | 137 | 506 | memcpy(out->data[0], in->data[0], sz); | 138 | 506 | } | 139 | | | 140 | 1.95k | if (in->p.layout != DAV1D_PIXEL_LAYOUT_I400 && !data->chroma_scaling_from_luma) { | 141 | 846 | assert(out->stride[1] == in->stride[1]); | 142 | 846 | const int ss_ver = in->p.layout == DAV1D_PIXEL_LAYOUT_I420; | 143 | 846 | const ptrdiff_t stride = out->stride[1]; | 144 | 846 | const ptrdiff_t sz = ((out->p.h + ss_ver) >> ss_ver) * stride; | 145 | 846 | if (sz < 0) { | 146 | 0 | if (!data->num_uv_points[0]) | 147 | 0 | memcpy((uint8_t*) out->data[1] + sz - stride, | 148 | 0 | (uint8_t*) in->data[1] + sz - stride, -sz); | 149 | 0 | if (!data->num_uv_points[1]) | 150 | 0 | memcpy((uint8_t*) out->data[2] + sz - stride, | 151 | 0 | (uint8_t*) in->data[2] + sz - stride, -sz); | 152 | 846 | } else { | 153 | 846 | if (!data->num_uv_points[0]) | 154 | 387 | memcpy(out->data[1], in->data[1], sz); | 155 | 846 | if (!data->num_uv_points[1]) | 156 | 571 | memcpy(out->data[2], in->data[2], sz); | 157 | 846 | } | 158 | 846 | } | 159 | 1.95k | } |
|
160 | | |
161 | | void bitfn(dav1d_apply_grain_row)(const Dav1dFilmGrainDSPContext *const dsp, |
162 | | Dav1dPicture *const out, |
163 | | const Dav1dPicture *const in, |
164 | | const uint8_t scaling[3][SCALING_SIZE], |
165 | | const entry grain_lut[3][GRAIN_HEIGHT+1][GRAIN_WIDTH], |
166 | | const int row) |
167 | 36.1k | { |
168 | | // Synthesize grain for the affected planes |
169 | 36.1k | const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data; |
170 | 36.1k | const int ss_y = in->p.layout == DAV1D_PIXEL_LAYOUT_I420; |
171 | 36.1k | const int ss_x = in->p.layout != DAV1D_PIXEL_LAYOUT_I444; |
172 | 36.1k | const int cpw = (out->p.w + ss_x) >> ss_x; |
173 | 36.1k | const int is_id = out->seq_hdr->mtrx == DAV1D_MC_IDENTITY; |
174 | 36.1k | pixel *const luma_src = |
175 | 36.1k | ((pixel *) in->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(in->stride[0]); |
176 | | #if BITDEPTH != 8 |
177 | | const int bitdepth_max = (1 << out->p.bpc) - 1; |
178 | | #endif |
179 | | |
180 | 36.1k | if (data->num_y_points) { |
181 | 21.2k | const int bh = imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE); |
182 | 21.2k | dsp->fgy_32x32xn(((pixel *) out->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[0]), |
183 | 21.2k | luma_src, out->stride[0], data, |
184 | 21.2k | out->p.w, scaling[0], grain_lut[0], bh, row HIGHBD_TAIL_SUFFIX); |
185 | 21.2k | } |
186 | | |
187 | 36.1k | if (!data->num_uv_points[0] && !data->num_uv_points[1] && |
188 | 28.0k | !data->chroma_scaling_from_luma) |
189 | 6.11k | { |
190 | 6.11k | return; |
191 | 6.11k | } |
192 | | |
193 | 30.0k | const int bh = (imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE) + ss_y) >> ss_y; |
194 | | |
195 | | // extend padding pixels |
196 | 30.0k | if (out->p.w & ss_x) { |
197 | 1.88k | pixel *ptr = luma_src; |
198 | 26.1k | for (int y = 0; y < bh; y++) { |
199 | 24.2k | ptr[out->p.w] = ptr[out->p.w - 1]; |
200 | 24.2k | ptr += PXSTRIDE(in->stride[0]) << ss_y; |
201 | 24.2k | } |
202 | 1.88k | } |
203 | | |
204 | 30.0k | const ptrdiff_t uv_off = row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[1]) >> ss_y; |
205 | 30.0k | if (data->chroma_scaling_from_luma) { |
206 | 65.3k | for (int pl = 0; pl < 2; pl++) |
207 | 43.4k | dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off, |
208 | 43.4k | ((const pixel *) in->data[1 + pl]) + uv_off, |
209 | 43.4k | in->stride[1], data, cpw, |
210 | 43.4k | scaling[0], grain_lut[1 + pl], |
211 | 43.4k | bh, row, luma_src, in->stride[0], |
212 | 43.4k | pl, is_id HIGHBD_TAIL_SUFFIX); |
213 | 21.9k | } else { |
214 | 23.4k | for (int pl = 0; pl < 2; pl++) |
215 | 15.2k | if (data->num_uv_points[pl]) |
216 | 8.51k | dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off, |
217 | 8.51k | ((const pixel *) in->data[1 + pl]) + uv_off, |
218 | 8.51k | in->stride[1], data, cpw, |
219 | 8.51k | scaling[1 + pl], grain_lut[1 + pl], |
220 | 8.51k | bh, row, luma_src, in->stride[0], |
221 | 8.51k | pl, is_id HIGHBD_TAIL_SUFFIX); |
222 | 8.11k | } |
223 | 30.0k | } dav1d_apply_grain_row_8bpc Line | Count | Source | 167 | 18.7k | { | 168 | | // Synthesize grain for the affected planes | 169 | 18.7k | const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data; | 170 | 18.7k | const int ss_y = in->p.layout == DAV1D_PIXEL_LAYOUT_I420; | 171 | 18.7k | const int ss_x = in->p.layout != DAV1D_PIXEL_LAYOUT_I444; | 172 | 18.7k | const int cpw = (out->p.w + ss_x) >> ss_x; | 173 | 18.7k | const int is_id = out->seq_hdr->mtrx == DAV1D_MC_IDENTITY; | 174 | 18.7k | pixel *const luma_src = | 175 | 18.7k | ((pixel *) in->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(in->stride[0]); | 176 | | #if BITDEPTH != 8 | 177 | | const int bitdepth_max = (1 << out->p.bpc) - 1; | 178 | | #endif | 179 | | | 180 | 18.7k | if (data->num_y_points) { | 181 | 8.20k | const int bh = imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE); | 182 | 8.20k | dsp->fgy_32x32xn(((pixel *) out->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[0]), | 183 | 8.20k | luma_src, out->stride[0], data, | 184 | 8.20k | out->p.w, scaling[0], grain_lut[0], bh, row HIGHBD_TAIL_SUFFIX); | 185 | 8.20k | } | 186 | | | 187 | 18.7k | if (!data->num_uv_points[0] && !data->num_uv_points[1] && | 188 | 14.6k | !data->chroma_scaling_from_luma) | 189 | 1.43k | { | 190 | 1.43k | return; | 191 | 1.43k | } | 192 | | | 193 | 17.3k | const int bh = (imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE) + ss_y) >> ss_y; | 194 | | | 195 | | // extend padding pixels | 196 | 17.3k | if (out->p.w & ss_x) { | 197 | 1.14k | pixel *ptr = luma_src; | 198 | 16.2k | for (int y = 0; y < bh; y++) { | 199 | 15.0k | ptr[out->p.w] = ptr[out->p.w - 1]; | 200 | 15.0k | ptr += PXSTRIDE(in->stride[0]) << ss_y; | 201 | 15.0k | } | 202 | 1.14k | } | 203 | | | 204 | 17.3k | const ptrdiff_t uv_off = row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[1]) >> ss_y; | 205 | 17.3k | if (data->chroma_scaling_from_luma) { | 206 | 39.6k | for (int pl = 0; pl < 2; pl++) | 207 | 26.3k | dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off, | 208 | 26.3k | ((const pixel *) in->data[1 + pl]) + uv_off, | 209 | 26.3k | in->stride[1], data, cpw, | 210 | 26.3k | scaling[0], grain_lut[1 + pl], | 211 | 26.3k | bh, row, luma_src, in->stride[0], | 212 | 26.3k | pl, is_id HIGHBD_TAIL_SUFFIX); | 213 | 13.2k | } else { | 214 | 12.0k | for (int pl = 0; pl < 2; pl++) | 215 | 8.01k | if (data->num_uv_points[pl]) | 216 | 4.34k | dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off, | 217 | 4.34k | ((const pixel *) in->data[1 + pl]) + uv_off, | 218 | 4.34k | in->stride[1], data, cpw, | 219 | 4.34k | scaling[1 + pl], grain_lut[1 + pl], | 220 | 4.34k | bh, row, luma_src, in->stride[0], | 221 | 4.34k | pl, is_id HIGHBD_TAIL_SUFFIX); | 222 | 4.08k | } | 223 | 17.3k | } |
dav1d_apply_grain_row_16bpc Line | Count | Source | 167 | 17.3k | { | 168 | | // Synthesize grain for the affected planes | 169 | 17.3k | const Dav1dFilmGrainData *const data = &out->frame_hdr->film_grain.data; | 170 | 17.3k | const int ss_y = in->p.layout == DAV1D_PIXEL_LAYOUT_I420; | 171 | 17.3k | const int ss_x = in->p.layout != DAV1D_PIXEL_LAYOUT_I444; | 172 | 17.3k | const int cpw = (out->p.w + ss_x) >> ss_x; | 173 | 17.3k | const int is_id = out->seq_hdr->mtrx == DAV1D_MC_IDENTITY; | 174 | 17.3k | pixel *const luma_src = | 175 | 17.3k | ((pixel *) in->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(in->stride[0]); | 176 | 17.3k | #if BITDEPTH != 8 | 177 | 17.3k | const int bitdepth_max = (1 << out->p.bpc) - 1; | 178 | 17.3k | #endif | 179 | | | 180 | 17.3k | if (data->num_y_points) { | 181 | 13.0k | const int bh = imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE); | 182 | 13.0k | dsp->fgy_32x32xn(((pixel *) out->data[0]) + row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[0]), | 183 | 13.0k | luma_src, out->stride[0], data, | 184 | 13.0k | out->p.w, scaling[0], grain_lut[0], bh, row HIGHBD_TAIL_SUFFIX); | 185 | 13.0k | } | 186 | | | 187 | 17.3k | if (!data->num_uv_points[0] && !data->num_uv_points[1] && | 188 | 13.3k | !data->chroma_scaling_from_luma) | 189 | 4.68k | { | 190 | 4.68k | return; | 191 | 4.68k | } | 192 | | | 193 | 12.6k | const int bh = (imin(out->p.h - row * FG_BLOCK_SIZE, FG_BLOCK_SIZE) + ss_y) >> ss_y; | 194 | | | 195 | | // extend padding pixels | 196 | 12.6k | if (out->p.w & ss_x) { | 197 | 743 | pixel *ptr = luma_src; | 198 | 9.91k | for (int y = 0; y < bh; y++) { | 199 | 9.17k | ptr[out->p.w] = ptr[out->p.w - 1]; | 200 | 9.17k | ptr += PXSTRIDE(in->stride[0]) << ss_y; | 201 | 9.17k | } | 202 | 743 | } | 203 | | | 204 | 12.6k | const ptrdiff_t uv_off = row * FG_BLOCK_SIZE * PXSTRIDE(out->stride[1]) >> ss_y; | 205 | 12.6k | if (data->chroma_scaling_from_luma) { | 206 | 25.7k | for (int pl = 0; pl < 2; pl++) | 207 | 17.0k | dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off, | 208 | 17.0k | ((const pixel *) in->data[1 + pl]) + uv_off, | 209 | 17.0k | in->stride[1], data, cpw, | 210 | 17.0k | scaling[0], grain_lut[1 + pl], | 211 | 17.0k | bh, row, luma_src, in->stride[0], | 212 | 17.0k | pl, is_id HIGHBD_TAIL_SUFFIX); | 213 | 8.66k | } else { | 214 | 11.3k | for (int pl = 0; pl < 2; pl++) | 215 | 7.26k | if (data->num_uv_points[pl]) | 216 | 4.17k | dsp->fguv_32x32xn[in->p.layout - 1](((pixel *) out->data[1 + pl]) + uv_off, | 217 | 4.17k | ((const pixel *) in->data[1 + pl]) + uv_off, | 218 | 4.17k | in->stride[1], data, cpw, | 219 | 4.17k | scaling[1 + pl], grain_lut[1 + pl], | 220 | 4.17k | bh, row, luma_src, in->stride[0], | 221 | 4.17k | pl, is_id HIGHBD_TAIL_SUFFIX); | 222 | 4.03k | } | 223 | 12.6k | } |
|
224 | | |
225 | | void bitfn(dav1d_apply_grain)(const Dav1dFilmGrainDSPContext *const dsp, |
226 | | Dav1dPicture *const out, |
227 | | const Dav1dPicture *const in) |
228 | 0 | { |
229 | 0 | ALIGN_STK_16(entry, grain_lut, 3,[GRAIN_HEIGHT + 1][GRAIN_WIDTH]); |
230 | | #if ARCH_X86_64 && BITDEPTH == 8 |
231 | 0 | ALIGN_STK_64(uint8_t, scaling, 3,[SCALING_SIZE]); |
232 | | #else |
233 | | uint8_t scaling[3][SCALING_SIZE]; |
234 | | #endif |
235 | 0 | const int rows = (out->p.h + FG_BLOCK_SIZE - 1) / FG_BLOCK_SIZE; |
236 | |
|
237 | 0 | bitfn(dav1d_prep_grain)(dsp, out, in, scaling, grain_lut); |
238 | 0 | for (int row = 0; row < rows; row++) |
239 | 0 | bitfn(dav1d_apply_grain_row)(dsp, out, in, scaling, grain_lut, row); |
240 | 0 | } Unexecuted instantiation: dav1d_apply_grain_8bpc Unexecuted instantiation: dav1d_apply_grain_16bpc |
241 | | #endif |