Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -36,6 +36,7 @@ typedef struct BilateralContext { · 35 unmodified lines | |||
| 36 | float sigmaR; | 36 | float sigmaR; |
| 37 | int planes; | 37 | int planes; |
| 38 | 38 | ||
| 39 | int nb_threads; | ||
| 39 | int nb_planes; | 40 | int nb_planes; |
| 40 | int depth; | 41 | int depth; |
| 41 | int planewidth[4]; | 42 | int planewidth[4]; |
| @@ -44,14 +45,14 @@ typedef struct BilateralContext { · 2 unmodified lines | |||
| 44 | float alpha; | 45 | float alpha; |
| 45 | float range_table[65536]; | 46 | float range_table[65536]; |
| 46 | 47 | ||
| 47 | float *img_out_f; | 48 | float *img_out_f[4]; |
| 48 | float *img_temp; | 49 | float *img_temp[4]; |
| 49 | float *map_factor_a; | 50 | float *map_factor_a[4]; |
| 50 | float *map_factor_b; | 51 | float *map_factor_b[4]; |
| 51 | float *slice_factor_a; | 52 | float *slice_factor_a[4]; |
| 52 | float *slice_factor_b; | 53 | float *slice_factor_b[4]; |
| 53 | float *line_factor_a; | 54 | float *line_factor_a[4]; |
| 54 | float *line_factor_b; | 55 | float *line_factor_b[4]; |
| 55 | } BilateralContext; | 56 | } BilateralContext; |
| 56 | 57 | ||
| 57 | #define OFFSET(x) offsetof(BilateralContext, x) | 58 | #define OFFSET(x) offsetof(BilateralContext, x) |
| @@ -102,6 +103,10 @@ static int config_params(AVFilterContext *ctx) · 44 unmodified lines | |||
| 102 | return 0; | 103 | return 0; |
| 103 | } | 104 | } |
| 104 | 105 | ||
| 106 | typedef struct ThreadData { | ||
| 107 | AVFrame *in, *out; | ||
| 108 | } ThreadData; | ||
| 109 | |||
| 105 | static int config_input(AVFilterLink *inlink) | 110 | static int config_input(AVFilterLink *inlink) |
| 106 | { | 111 | { |
| 107 | AVFilterContext *ctx = inlink->dst; | 112 | AVFilterContext *ctx = inlink->dst; |
| @@ -109,7 +114,6 @@ static int config_input(AVFilterLink *inlink) · 1 unmodified line | |||
| 109 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | 114 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 110 | 115 | ||
| 111 | s->depth = desc->comp[0].depth; | 116 | s->depth = desc->comp[0].depth; |
| 112 | |||
| 113 | config_params(ctx); | 117 | config_params(ctx); |
| 114 | 118 | ||
| 115 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); | 119 | s->planewidth[1] = s->planewidth[2] = AV_CEIL_RSHIFT(inlink->w, desc->log2_chroma_w); |
| @@ -118,133 +122,169 @@ static int config_input(AVFilterLink *inlink) · 2 unmodified lines | |||
| 118 | s->planeheight[0] = s->planeheight[3] = inlink->h; | 122 | s->planeheight[0] = s->planeheight[3] = inlink->h; |
| 119 | 123 | ||
| 120 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); | 124 | s->nb_planes = av_pix_fmt_count_planes(inlink->format); |
| 121 | 125 | s->nb_threads = ff_filter_get_nb_threads(ctx); | |
| 122 | s->img_out_f = av_calloc(inlink->w * inlink->h, sizeof(float)); | 126 | |
| 123 | s->img_temp = av_calloc(inlink->w * inlink->h, sizeof(float)); | 127 | for (int p = 0; p < s->nb_planes; p++) { |
| 124 | s->map_factor_a = av_calloc(inlink->w * inlink->h, sizeof(float)); | 128 | const int w = s->planewidth[p]; |
| 125 | s->map_factor_b = av_calloc(inlink->w * inlink->h, sizeof(float)); | 129 | const int h = s->planeheight[p]; |
| 126 | s->slice_factor_a = av_calloc(inlink->w, sizeof(float)); | 130 | |
| 127 | s->slice_factor_b = av_calloc(inlink->w, sizeof(float)); | 131 | s->img_out_f[p] = av_calloc(w * h, sizeof(float)); |
| 128 | s->line_factor_a = av_calloc(inlink->w, sizeof(float)); | 132 | s->img_temp[p] = av_calloc(w * h, sizeof(float)); |
| 129 | s->line_factor_b = av_calloc(inlink->w, sizeof(float)); | 133 | s->map_factor_a[p] = av_calloc(w * h, sizeof(float)); |
| 130 | 134 | s->map_factor_b[p] = av_calloc(w * h, sizeof(float)); | |
| 131 | if (!s->img_out_f || | 135 | s->slice_factor_a[p] = av_calloc(w, sizeof(float)); |
| 132 | !s->img_temp || | 136 | s->slice_factor_b[p] = av_calloc(w, sizeof(float)); |
| 133 | !s->map_factor_a || | 137 | s->line_factor_a[p] = av_calloc(w, sizeof(float)); |
| 134 | !s->map_factor_b || | 138 | s->line_factor_b[p] = av_calloc(w, sizeof(float)); |
| 135 | !s->slice_factor_a || | 139 | |
| 136 | !s->slice_factor_a || | 140 | if (!s->img_out_f[p] || |
| 137 | !s->line_factor_a || | 141 | !s->img_temp[p] || |
| 138 | !s->line_factor_a) | 142 | !s->map_factor_a[p] || |
| 139 | return AVERROR(ENOMEM); | 143 | !s->map_factor_b[p] || |
| 144 | !s->slice_factor_a[p] || | ||
| 145 | !s->slice_factor_a[p] || | ||
| 146 | !s->line_factor_a[p] || | ||
| 147 | !s->line_factor_a[p]) | ||
| 148 | return AVERROR(ENOMEM); | ||
| 149 | } | ||
| 140 | 150 | ||
| 141 | return 0; | 151 | return 0; |
| 142 | } | 152 | } |
| 143 | 153 | ||
| 144 | #define BILATERAL(type, name) \ | 154 | #define BILATERAL_H(type, name) \ |
| 145 | static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t *ddst, \ | 155 | static void bilateralh_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \ |
| 146 | int width, int height, int src_linesize, int dst_linesize) \ | 156 | int jobnr, int nb_jobs, int plane) \ |
| 147 | { \ | 157 | { \ |
| 148 | type *dst = (type *)ddst; \ | 158 | const int width = s->planewidth[plane]; \ |
| 149 | const type *src = (const type *)ssrc; \ | 159 | const int height = s->planeheight[plane]; \ |
| 150 | float *img_out_f = s->img_out_f, *img_temp = s->img_temp; \ | 160 | const int slice_start = (height * jobnr) / nb_jobs; \ |
| 151 | float *map_factor_a = s->map_factor_a, *map_factor_b = s->map_factor_b; \ | 161 | const int slice_end = (height * (jobnr+1)) / nb_jobs; \ |
| 152 | float *slice_factor_a = s->slice_factor_a, *slice_factor_b = s->slice_factor_b; \ | 162 | const int src_linesize = in->linesize[plane] / sizeof(type); \ |
| 153 | float *line_factor_a = s->line_factor_a, *line_factor_b = s->line_factor_b; \ | 163 | const type *src = (const type *)in->data[plane]; \ |
| 154 | const float *range_table = s->range_table; \ | 164 | float *img_temp = s->img_temp[plane]; \ |
| 155 | const float alpha = s->alpha; \ | 165 | float *map_factor_a = s->map_factor_a[plane]; \ |
| 156 | float ypr, ycr, *ycy, *ypy, *xcy, fp, fc; \ | 166 | const float *const range_table = s->range_table; \ |
| 157 | const float inv_alpha_ = 1.f - alpha; \ | 167 | const float alpha = s->alpha; \ |
| 158 | float *ycf, *ypf, *xcf, *in_factor; \ | 168 | float ypr, ycr, fp, fc; \ |
| 159 | const type *tcy, *tpy; \ | 169 | const float inv_alpha_ = 1.f - alpha; \ |
| 160 | int h1; \ | 170 | \ |
| 161 | \ | 171 | for (int y = slice_start; y < slice_end; y++) { \ |
| 162 | for (int y = 0; y < height; y++) { \ | 172 | float *temp_factor_x, *temp_x = &img_temp[y * width]; \ |
| 163 | float *temp_factor_x, *temp_x = &img_temp[y * width]; \ | 173 | const type *in_x = &src[y * src_linesize]; \ |
| 164 | const type *in_x = &src[y * src_linesize]; \ | 174 | const type *texture_x = &src[y * src_linesize]; \ |
| 165 | const type *texture_x = &src[y * src_linesize]; \ | 175 | type tpr; \ |
| 166 | type tpr; \ | 176 | \ |
| 167 | \ | 177 | *temp_x++ = ypr = *in_x++; \ |
| 168 | *temp_x++ = ypr = *in_x++; \ | 178 | tpr = *texture_x++; \ |
| 169 | tpr = *texture_x++; \ | 179 | \ |
| 170 | \ | 180 | temp_factor_x = &map_factor_a[y * width]; \ |
| 171 | temp_factor_x = &map_factor_a[y * width]; \ | 181 | *temp_factor_x++ = fp = 1; \ |
| 172 | *temp_factor_x++ = fp = 1; \ | 182 | \ |
| 173 | \ | 183 | for (int x = 1; x < width; x++) { \ |
| 174 | for (int x = 1; x < width; x++) { \ | 184 | float alpha_; \ |
| 175 | float alpha_; \ | 185 | int range_dist; \ |
| 176 | int range_dist; \ | 186 | type tcr = *texture_x++; \ |
| 177 | type tcr = *texture_x++; \ | 187 | type dr = abs(tcr - tpr); \ |
| 178 | type dr = abs(tcr - tpr); \ | 188 | \ |
| 179 | \ | 189 | range_dist = dr; \ |
| 180 | range_dist = dr; \ | 190 | alpha_ = range_table[range_dist]; \ |
| 181 | alpha_ = range_table[range_dist]; \ | 191 | *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \ |
| 182 | *temp_x++ = ycr = inv_alpha_*(*in_x++) + alpha_*ypr; \ | 192 | tpr = tcr; \ |
| 183 | tpr = tcr; \ | 193 | ypr = ycr; \ |
| 184 | ypr = ycr; \ | 194 | *temp_factor_x++ = fc = inv_alpha_ + alpha_ * fp; \ |
| 185 | *temp_factor_x++ = fc = inv_alpha_ + alpha_ * fp; \ | 195 | fp = fc; \ |
| 186 | fp = fc; \ | 196 | } \ |
| 187 | } \ | 197 | --temp_x; *temp_x = ((*temp_x) + (*--in_x)); \ |
| 188 | --temp_x; *temp_x = ((*temp_x) + (*--in_x)); \ | 198 | tpr = *--texture_x; \ |
| 189 | tpr = *--texture_x; \ | 199 | ypr = *in_x; \ |
| 190 | ypr = *in_x; \ | 200 | \ |
| 191 | \ | 201 | --temp_factor_x; *temp_factor_x = ((*temp_factor_x) + 1); \ |
| 192 | --temp_factor_x; *temp_factor_x = ((*temp_factor_x) + 1); \ | 202 | fp = 1; \ |
| 193 | fp = 1; \ | 203 | \ |
| 194 | \ | 204 | for (int x = width - 2; x >= 0; x--) { \ |
| 195 | for (int x = width - 2; x >= 0; x--) { \ | 205 | type tcr = *--texture_x; \ |
| 196 | type tcr = *--texture_x; \ | 206 | type dr = abs(tcr - tpr); \ |
| 197 | type dr = abs(tcr - tpr); \ | 207 | int range_dist = dr; \ |
| 198 | int range_dist = dr; \ | 208 | float alpha_ = range_table[range_dist]; \ |
| 199 | float alpha_ = range_table[range_dist]; \ | 209 | \ |
| 200 | \ | 210 | ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \ |
| 201 | ycr = inv_alpha_ * (*--in_x) + alpha_ * ypr; \ | 211 | --temp_x; *temp_x = ((*temp_x) + ycr); \ |
| 202 | --temp_x; *temp_x = ((*temp_x) + ycr); \ | 212 | tpr = tcr; \ |
| 203 | tpr = tcr; \ | 213 | ypr = ycr; \ |
| 204 | ypr = ycr; \ | 214 | \ |
| 205 | \ | 215 | fc = inv_alpha_ + alpha_*fp; \ |
| 206 | fc = inv_alpha_ + alpha_*fp; \ | 216 | --temp_factor_x; \ |
| 207 | --temp_factor_x; \ | 217 | *temp_factor_x = ((*temp_factor_x) + fc); \ |
| 208 | *temp_factor_x = ((*temp_factor_x) + fc); \ | 218 | fp = fc; \ |
| 209 | fp = fc; \ | 219 | } \ |
| 210 | } \ | 220 | } \ |
| 211 | } \ | 221 | } |
| 212 | memcpy(img_out_f, img_temp, sizeof(float) * width); \ | 222 | |
| 213 | \ | 223 | BILATERAL_H(uint8_t, byte) |
| 214 | in_factor = map_factor_a; \ | 224 | BILATERAL_H(uint16_t, word) |
| 215 | memcpy(map_factor_b, in_factor, sizeof(float) * width); \ | 225 | |
| 216 | for (int y = 1; y < height; y++) { \ | 226 | #define BILATERAL_V(type, name) \ |
| 217 | tpy = &src[(y - 1) * src_linesize]; \ | 227 | static void bilateralv_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \ |
| 218 | tcy = &src[y * src_linesize]; \ | 228 | int jobnr, int nb_jobs, int plane) \ |
| 219 | xcy = &img_temp[y * width]; \ | 229 | { \ |
| 220 | ypy = &img_out_f[(y - 1) * width]; \ | 230 | const int width = s->planewidth[plane]; \ |
| 221 | ycy = &img_out_f[y * width]; \ | 231 | const int height = s->planeheight[plane]; \ |
| 222 | \ | 232 | const int slice_start = (width * jobnr) / nb_jobs; \ |
| 223 | xcf = &in_factor[y * width]; \ | 233 | const int slice_end = (width * (jobnr+1)) / nb_jobs; \ |
| 224 | ypf = &map_factor_b[(y - 1) * width]; \ | 234 | const int src_linesize = in->linesize[plane] / sizeof(type); \ |
| 225 | ycf = &map_factor_b[y * width]; \ | 235 | const type *src = (const type *)in->data[plane] + slice_start; \ |
| 226 | for (int x = 0; x < width; x++) { \ | 236 | float *img_out_f = s->img_out_f[plane] + slice_start; \ |
| 227 | type dr = abs((*tcy++) - (*tpy++)); \ | 237 | float *img_temp = s->img_temp[plane] + slice_start; \ |
| 228 | int range_dist = dr; \ | 238 | float *map_factor_a = s->map_factor_a[plane] + slice_start; \ |
| 229 | float alpha_ = range_table[range_dist]; \ | 239 | float *map_factor_b = s->map_factor_b[plane] + slice_start; \ |
| 230 | \ | 240 | float *slice_factor_a = s->slice_factor_a[plane] + slice_start; \ |
| 231 | *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \ | 241 | float *slice_factor_b = s->slice_factor_b[plane] + slice_start; \ |
| 232 | *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \ | 242 | float *line_factor_a = s->line_factor_a[plane] + slice_start; \ |
| 233 | } \ | 243 | float *line_factor_b = s->line_factor_b[plane] + slice_start; \ |
| 234 | } \ | 244 | const float *const range_table = s->range_table; \ |
| 235 | h1 = height - 1; \ | 245 | const float alpha = s->alpha; \ |
| 236 | ycf = line_factor_a; \ | 246 | float *ycy, *ypy, *xcy; \ |
| 237 | ypf = line_factor_b; \ | 247 | const float inv_alpha_ = 1.f - alpha; \ |
| 238 | memcpy(ypf, &in_factor[h1 * width], sizeof(float) * width); \ | 248 | float *ycf, *ypf, *xcf, *in_factor; \ |
| 239 | for (int x = 0; x < width; x++) \ | 249 | const type *tcy, *tpy; \ |
| 240 | map_factor_b[h1 * width + x] = (map_factor_b[h1 * width + x] + ypf[x]); \ | 250 | int h1; \ |
| 241 | \ | 251 | \ |
| 242 | ycy = slice_factor_a; \ | 252 | memcpy(img_out_f, img_temp, sizeof(float) * (slice_end - slice_start)); \ |
| 243 | ypy = slice_factor_b; \ | 253 | \ |
| 244 | memcpy(ypy, &img_temp[h1 * width], sizeof(float) * width); \ | 254 | in_factor = map_factor_a; \ |
| 245 | for (int x = 0, k = 0; x < width; x++) { \ | 255 | memcpy(map_factor_b, in_factor, sizeof(float) * (slice_end - slice_start)); \ |
| 246 | int idx = h1 * width + x; \ | 256 | for (int y = 1; y < height; y++) { \ |
| 247 | img_out_f[idx] = (img_out_f[idx] + ypy[k++]) / map_factor_b[h1 * width + x]; \ | 257 | tpy = &src[(y - 1) * src_linesize]; \ |
| 258 | tcy = &src[y * src_linesize]; \ | ||
| 259 | xcy = &img_temp[y * width]; \ | ||
| 260 | ypy = &img_out_f[(y - 1) * width]; \ | ||
| 261 | ycy = &img_out_f[y * width]; \ | ||
| 262 | \ | ||
| 263 | xcf = &in_factor[y * width]; \ | ||
| 264 | ypf = &map_factor_b[(y - 1) * width]; \ | ||
| 265 | ycf = &map_factor_b[y * width]; \ | ||
| 266 | for (int x = 0; x < slice_end - slice_start; x++) { \ | ||
| 267 | type dr = abs((*tcy++) - (*tpy++)); \ | ||
| 268 | int range_dist = dr; \ | ||
| 269 | float alpha_ = range_table[range_dist]; \ | ||
| 270 | \ | ||
| 271 | *ycy++ = inv_alpha_*(*xcy++) + alpha_*(*ypy++); \ | ||
| 272 | *ycf++ = inv_alpha_*(*xcf++) + alpha_*(*ypf++); \ | ||
| 273 | } \ | ||
| 274 | } \ | ||
| 275 | h1 = height - 1; \ | ||
| 276 | ycf = line_factor_a; \ | ||
| 277 | ypf = line_factor_b; \ | ||
| 278 | memcpy(ypf, &in_factor[h1 * width], sizeof(float) * (slice_end - slice_start)); \ | ||
| 279 | for (int x = 0, k = 0; x < slice_end - slice_start; x++) \ | ||
| 280 | map_factor_b[h1 * width + x] = (map_factor_b[h1 * width + x] + ypf[k++]); \ | ||
| 281 | \ | ||
| 282 | ycy = slice_factor_a; \ | ||
| 283 | ypy = slice_factor_b; \ | ||
| 284 | memcpy(ypy, &img_temp[h1 * width], sizeof(float) * (slice_end - slice_start)); \ | ||
| 285 | for (int x = 0, k = 0; x < slice_end - slice_start; x++) { \ | ||
| 286 | int idx = h1 * width + x; \ | ||
| 287 | img_out_f[idx] = (img_out_f[idx] + ypy[k++]) / map_factor_b[h1 * width + x]; \ | ||
| 248 | } \ | 288 | } \ |
| 249 | \ | 289 | \ |
| 250 | for (int y = h1 - 1; y >= 0; y--) { \ | 290 | for (int y = h1 - 1; y >= 0; y--) { \ |
| @@ -262,7 +302,7 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 11 unmodified lines | |||
| 262 | ycf_ = ycf; \ | 302 | ycf_ = ycf; \ |
| 263 | ypf_ = ypf; \ | 303 | ypf_ = ypf; \ |
| 264 | factor_ = &map_factor_b[y * width]; \ | 304 | factor_ = &map_factor_b[y * width]; \ |
| 265 | for (int x = 0; x < width; x++) { \ | 305 | for (int x = 0; x < slice_end - slice_start; x++) { \ |
| 266 | type dr = abs((*tcy++) - (*tpy++)); \ | 306 | type dr = abs((*tcy++) - (*tpy++)); \ |
| 267 | int range_dist = dr; \ | 307 | int range_dist = dr; \ |
| 268 | float alpha_ = range_table[range_dist]; \ | 308 | float alpha_ = range_table[range_dist]; \ |
| @@ -281,20 +321,119 @@ static void bilateral_##name(BilateralContext *s, const uint8_t *ssrc, uint8_t * · 12 unmodified lines | |||
| 281 | ypy = ycy; \ | 321 | ypy = ycy; \ |
| 282 | ypf = ycf; \ | 322 | ypf = ycf; \ |
| 283 | } \ | 323 | } \ |
| 284 | \ | ||
| 285 | for (int i = 0; i < height; i++) \ | ||
| 286 | for (int j = 0; j < width; j++) \ | ||
| 287 | dst[j + i * dst_linesize] = lrintf(img_out_f[i * width + j]); \ | ||
| 288 | } | 324 | } |
| 289 | 325 | ||
| 290 | BILATERAL(uint8_t, byte) | 326 | BILATERAL_V(uint8_t, byte) |
| 291 | BILATERAL(uint16_t, word) | 327 | BILATERAL_V(uint16_t, word) |
| 328 | |||
| 329 | #define BILATERAL_O(type, name) \ | ||
| 330 | static void bilateralo_##name(BilateralContext *s, AVFrame *out, AVFrame *in, \ | ||
| 331 | int jobnr, int nb_jobs, int plane) \ | ||
| 332 | { \ | ||
| 333 | const int width = s->planewidth[plane]; \ | ||
| 334 | const int height = s->planeheight[plane]; \ | ||
| 335 | const int slice_start = (height * jobnr) / nb_jobs; \ | ||
| 336 | const int slice_end = (height * (jobnr+1)) / nb_jobs; \ | ||
| 337 | const int dst_linesize = out->linesize[plane] / sizeof(type); \ | ||
| 338 | \ | ||
| 339 | for (int i = slice_start; i < slice_end; i++) { \ | ||
| 340 | type *dst = (type *)out->data[plane] + i * dst_linesize; \ | ||
| 341 | const float *const img_out_f = s->img_out_f[plane] + i * width; \ | ||
| 342 | for (int j = 0; j < width; j++) \ | ||
| 343 | dst[j] = lrintf(img_out_f[j]); \ | ||
| 344 | } \ | ||
| 345 | } | ||
| 346 | |||
| 347 | BILATERAL_O(uint8_t, byte) | ||
| 348 | BILATERAL_O(uint16_t, word) | ||
| 349 | |||
| 350 | static int bilateralh_planes(AVFilterContext *ctx, void *arg, | ||
| 351 | int jobnr, int nb_jobs) | ||
| 352 | { | ||
| 353 | BilateralContext *s = ctx->priv; | ||
| 354 | ThreadData *td = arg; | ||
| 355 | AVFrame *out = td->out; | ||
| 356 | AVFrame *in = td->in; | ||
| 357 | |||
| 358 | for (int plane = 0; plane < s->nb_planes; plane++) { | ||
| 359 | if (!(s->planes & (1 << plane))) | ||
| 360 | continue; | ||
| 361 | |||
| 362 | if (s->depth <= 8) | ||
| 363 | bilateralh_byte(s, out, in, jobnr, nb_jobs, plane); | ||
| 364 | else | ||
| 365 | bilateralh_word(s, out, in, jobnr, nb_jobs, plane); | ||
| 366 | } | ||
| 367 | |||
| 368 | return 0; | ||
| 369 | } | ||
| 370 | |||
| 371 | static int bilateralv_planes(AVFilterContext *ctx, void *arg, | ||
| 372 | int jobnr, int nb_jobs) | ||
| 373 | { | ||
| 374 | BilateralContext *s = ctx->priv; | ||
| 375 | ThreadData *td = arg; | ||
| 376 | AVFrame *out = td->out; | ||
| 377 | AVFrame *in = td->in; | ||
| 378 | |||
| 379 | for (int plane = 0; plane < s->nb_planes; plane++) { | ||
| 380 | if (!(s->planes & (1 << plane))) | ||
| 381 | continue; | ||
| 382 | |||
| 383 | if (s->depth <= 8) | ||
| 384 | bilateralv_byte(s, out, in, jobnr, nb_jobs, plane); | ||
| 385 | else | ||
| 386 | bilateralv_word(s, out, in, jobnr, nb_jobs, plane); | ||
| 387 | } | ||
| 388 | |||
| 389 | return 0; | ||
| 390 | } | ||
| 391 | |||
| 392 | static int bilateralo_planes(AVFilterContext *ctx, void *arg, | ||
| 393 | int jobnr, int nb_jobs) | ||
| 394 | { | ||
| 395 | BilateralContext *s = ctx->priv; | ||
| 396 | ThreadData *td = arg; | ||
| 397 | AVFrame *out = td->out; | ||
| 398 | AVFrame *in = td->in; | ||
| 399 | |||
| 400 | for (int plane = 0; plane < s->nb_planes; plane++) { | ||
| 401 | if (!(s->planes & (1 << plane))) { | ||
| 402 | if (out != in) { | ||
| 403 | const int height = s->planeheight[plane]; | ||
| 404 | const int slice_start = (height * jobnr) / nb_jobs; | ||
| 405 | const int slice_end = (height * (jobnr+1)) / nb_jobs; | ||
| 406 | const int width = s->planewidth[plane]; | ||
| 407 | const int linesize = in->linesize[plane]; | ||
| 408 | const int dst_linesize = out->linesize[plane]; | ||
| 409 | const uint8_t *src = in->data[plane]; | ||
| 410 | uint8_t *dst = out->data[plane]; | ||
| 411 | |||
| 412 | av_image_copy_plane(dst + slice_start * dst_linesize, | ||
| 413 | dst_linesize, | ||
| 414 | src + slice_start * linesize, | ||
| 415 | linesize, | ||
| 416 | width * ((s->depth + 7) / 8), | ||
| 417 | slice_end - slice_start); | ||
| 418 | } | ||
| 419 | continue; | ||
| 420 | } | ||
| 421 | |||
| 422 | if (s->depth <= 8) | ||
| 423 | bilateralo_byte(s, out, in, jobnr, nb_jobs, plane); | ||
| 424 | else | ||
| 425 | bilateralo_word(s, out, in, jobnr, nb_jobs, plane); | ||
| 426 | } | ||
| 427 | |||
| 428 | return 0; | ||
| 429 | } | ||
| 292 | 430 | ||
| 293 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) | 431 | static int filter_frame(AVFilterLink *inlink, AVFrame *in) |
| 294 | { | 432 | { |
| 295 | AVFilterContext *ctx = inlink->dst; | 433 | AVFilterContext *ctx = inlink->dst; |
| 296 | BilateralContext *s = ctx->priv; | 434 | BilateralContext *s = ctx->priv; |
| 297 | AVFilterLink *outlink = ctx->outputs[0]; | 435 | AVFilterLink *outlink = ctx->outputs[0]; |
| 436 | ThreadData td; | ||
| 298 | AVFrame *out; | 437 | AVFrame *out; |
| 299 | 438 | ||
| 300 | if (av_frame_is_writable(in)) { | 439 | if (av_frame_is_writable(in)) { |
| @@ -308,24 +447,11 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in) · 7 unmodified lines | |||
| 308 | av_frame_copy_props(out, in); | 447 | av_frame_copy_props(out, in); |
| 309 | } | 448 | } |
| 310 | 449 | ||
| 311 | for (int plane = 0; plane < s->nb_planes; plane++) { | 450 | td.in = in; |
| 312 | if (!(s->planes & (1 << plane))) { | 451 | td.out = out; |
| 313 | if (out != in) | 452 | ff_filter_execute(ctx, bilateralh_planes, &td, NULL, s->nb_threads); |
| 314 | av_image_copy_plane(out->data[plane], out->linesize[plane], | 453 | ff_filter_execute(ctx, bilateralv_planes, &td, NULL, s->nb_threads); |
| 315 | in->data[plane], in->linesize[plane], | 454 | ff_filter_execute(ctx, bilateralo_planes, &td, NULL, s->nb_threads); |
| 316 | s->planewidth[plane] * ((s->depth + 7) / 8), s->planeheight[plane]); | ||
| 317 | continue; | ||
| 318 | } | ||
| 319 | |||
| 320 | if (s->depth <= 8) | ||
| 321 | bilateral_byte(s, in->data[plane], out->data[plane], | ||
| 322 | s->planewidth[plane], s->planeheight[plane], | ||
| 323 | in->linesize[plane], out->linesize[plane]); | ||
| 324 | else | ||
| 325 | bilateral_word(s, in->data[plane], out->data[plane], | ||
| 326 | s->planewidth[plane], s->planeheight[plane], | ||
| 327 | in->linesize[plane] / 2, out->linesize[plane] / 2); | ||
| 328 | } | ||
| 329 | 455 | ||
| 330 | if (out != in) | 456 | if (out != in) |
| 331 | av_frame_free(&in); | 457 | av_frame_free(&in); |
| @@ -336,14 +462,16 @@ static av_cold void uninit(AVFilterContext *ctx) · 4 unmodified lines | |||
| 336 | { | 462 | { |
| 337 | BilateralContext *s = ctx->priv; | 463 | BilateralContext *s = ctx->priv; |
| 338 | 464 | ||
| 339 | av_freep(&s->img_out_f); | 465 | for (int p = 0; p < s->nb_planes; p++) { |
| 340 | av_freep(&s->img_temp); | 466 | av_freep(&s->img_out_f[p]); |
| 341 | av_freep(&s->map_factor_a); | 467 | av_freep(&s->img_temp[p]); |
| 342 | av_freep(&s->map_factor_b); | 468 | av_freep(&s->map_factor_a[p]); |
| 343 | av_freep(&s->slice_factor_a); | 469 | av_freep(&s->map_factor_b[p]); |
| 344 | av_freep(&s->slice_factor_b); | 470 | av_freep(&s->slice_factor_a[p]); |
| 345 | av_freep(&s->line_factor_a); | 471 | av_freep(&s->slice_factor_b[p]); |
| 346 | av_freep(&s->line_factor_b); | 472 | av_freep(&s->line_factor_a[p]); |
| 473 | av_freep(&s->line_factor_b[p]); | ||
| 474 | } | ||
| 347 | } | 475 | } |
| 348 | 476 | ||
| 349 | static int process_command(AVFilterContext *ctx, | 477 | static int process_command(AVFilterContext *ctx, |
| @@ -386,6 +514,7 @@ const AVFilter ff_vf_bilateral = { · 36 unmodified lines | |||
| 386 | FILTER_INPUTS(bilateral_inputs), | 514 | FILTER_INPUTS(bilateral_inputs), |
| 387 | FILTER_OUTPUTS(bilateral_outputs), | 515 | FILTER_OUTPUTS(bilateral_outputs), |
| 388 | FILTER_PIXFMTS_ARRAY(pix_fmts), | 516 | FILTER_PIXFMTS_ARRAY(pix_fmts), |
| 389 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC, | 517 | .flags = AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC | |
| 518 | AVFILTER_FLAG_SLICE_THREADS, | ||
| 390 | .process_command = process_command, | 519 | .process_command = process_command, |
| 391 | }; | 520 | }; |