1 /*
2 * Copyright (c) 2019 Paul B Mahol
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 * Redistribution and use in source and binary forms, with or without modification,
20 * are permitted provided that the following conditions are met:
21 */
22
26
27 #undef pixel
28 #if DEPTH == 8
29 #define pixel uint8_t
30 #else
31 #define pixel uint16_t
32 #endif
33
34 #undef htype
35 #define htype uint16_t
36
37 #undef fn
38 #undef fn2
39 #undef fn3
40 #define SHIFT ((DEPTH + 1) / 2)
41 #define BINS (1 << SHIFT)
42 #define MASK (BINS - 1)
43 #define fn3(a,b) a##_##b
44 #define fn2(a,b) fn3(a,b)
45 #define fn(a) fn2(a, DEPTH)
46
47 #define PICK_COARSE_BIN(x, y) (BINS * (x) + ((y) >> SHIFT))
48 #define PICK_FINE_BIN(x, y, z) (BINS * ((x) * ((y) >> SHIFT) + (z)) + ((y) & MASK))
49
51 uint8_t *ddst,
int dst_linesize,
int width,
int height,
52 int slice_h_start, int slice_h_end, int jobnr)
53 {
55 htype *ccoarse =
s->coarse[jobnr];
56 htype *cfine =
s->fine[jobnr];
57 const int radius =
s->radius;
58 const int radiusV =
s->radiusV;
64
65 src_linesize /=
sizeof(
pixel);
66 dst_linesize /=
sizeof(
pixel);
67
68 memset(cfine, 0,
s->fine_size *
sizeof(*cfine));
69 memset(ccoarse, 0,
s->coarse_size *
sizeof(*ccoarse));
70
71 srcp =
src +
FFMAX(0, slice_h_start - radiusV) * src_linesize;
72 if (jobnr == 0) {
76 }
77 }
78
79 srcp =
src +
FFMAX(0, slice_h_start - radiusV - (jobnr != 0)) * src_linesize;
80 for (
int i = 0;
i < radiusV + (jobnr != 0) * (1 + radiusV);
i++) {
81 for (
int j = 0; j <
width; j++) {
84 }
85 srcp += src_linesize;
86 }
87
89
90 for (
int i = slice_h_start;
i < slice_h_end;
i++) {
94
95 p = srcp + src_linesize *
FFMAX(0,
i - radiusV - 1);
96 for (
int j = 0; j <
width; j++) {
99 }
100
102 for (
int j = 0; j <
width; j++) {
105 }
106
107 s->hmuladd(coarse, &ccoarse[0], radius,
BINS);
108 for (int j = 0; j < radius; j++)
109 s->hadd(coarse, &ccoarse[
BINS * j],
BINS);
110 for (
int k = 0; k <
BINS; k++)
111 s->hmuladd(&fine[k][0], &cfine[
BINS *
width * k], 2 * radius + 1,
BINS);
112
113 for (
int j = 0; j <
width; j++) {
116
118
119 for (k = 0; k <
BINS; k++) {
120 sum += coarse[k];
121 if (sum > t) {
122 sum -= coarse[k];
123 break;
124 }
125 }
127
128 if (luc[k] <= j - radius) {
129 memset(&fine[k], 0,
BINS *
sizeof(
htype));
130 for (luc[k] = j - radius; luc[k] <
FFMIN(j + radius + 1,
width); luc[k]++)
132 if (luc[k] < j + radius + 1) {
134 luc[k] = j + radius + 1;
135 }
136 } else {
137 for (; luc[k] < j + radius + 1; luc[k]++) {
140 }
141 }
142
144
148 if (sum > t) {
150 break;
151 }
152 }
154 }
155
157 }
158 }