Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -23,10 +23,15 @@ · 22 unmodified lines | |||
| 23 | #include "libavutil/opt.h" | 23 | #include "libavutil/opt.h" |
| 24 | #include "libavutil/imgutils.h" | 24 | #include "libavutil/imgutils.h" |
| 25 | #include "avfilter.h" | 25 | #include "avfilter.h" |
| 26 | #include "drawutils.h" | ||
| 26 | #include "formats.h" | 27 | #include "formats.h" |
| 27 | #include "internal.h" | 28 | #include "internal.h" |
| 28 | #include "video.h" | 29 | #include "video.h" |
| 29 | 30 | ||
| 31 | #define R 0 | ||
| 32 | #define G 1 | ||
| 33 | #define B 2 | ||
| 34 | |||
| 30 | typedef struct ColorTemperatureContext { | 35 | typedef struct ColorTemperatureContext { |
| 31 | const AVClass *class; | 36 | const AVClass *class; |
| 32 | 37 | ||
| @@ -36,7 +41,9 @@ typedef struct ColorTemperatureContext { · 3 unmodified lines | |||
| 36 | 41 | ||
| 37 | float color[3]; | 42 | float color[3]; |
| 38 | 43 | ||
| 44 | int step; | ||
| 39 | int depth; | 45 | int depth; |
| 46 | uint8_t rgba_map[4]; | ||
| 40 | 47 | ||
| 41 | int (*do_slice)(AVFilterContext *s, void *arg, | 48 | int (*do_slice)(AVFilterContext *s, void *arg, |
| 42 | int jobnr, int nb_jobs); | 49 | int jobnr, int nb_jobs); |
| @@ -177,6 +184,85 @@ static int temperature_slice16(AVFilterContext *ctx, void *arg, int jobnr, int n · 134 unmodified lines | |||
| 177 | return 0; | 184 | return 0; |
| 178 | } | 185 | } |
| 179 | 186 | ||
| 187 | static int temperature_slice8p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | ||
| 188 | { | ||
| 189 | ColorTemperatureContext *s = ctx->priv; | ||
| 190 | AVFrame *frame = arg; | ||
| 191 | const int step = s->step; | ||
| 192 | const int width = frame->width; | ||
| 193 | const int height = frame->height; | ||
| 194 | const float mix = s->mix; | ||
| 195 | const float preserve = s->preserve; | ||
| 196 | const float *color = s->color; | ||
| 197 | const uint8_t roffset = s->rgba_map[R]; | ||
| 198 | const uint8_t goffset = s->rgba_map[G]; | ||
| 199 | const uint8_t boffset = s->rgba_map[B]; | ||
| 200 | const int slice_start = (height * jobnr) / nb_jobs; | ||
| 201 | const int slice_end = (height * (jobnr + 1)) / nb_jobs; | ||
| 202 | const int linesize = frame->linesize[0]; | ||
| 203 | uint8_t *ptr = frame->data[0] + slice_start * linesize; | ||
| 204 | |||
| 205 | for (int y = slice_start; y < slice_end; y++) { | ||
| 206 | for (int x = 0; x < width; x++) { | ||
| 207 | float g = ptr[x * step + goffset]; | ||
| 208 | float b = ptr[x * step + boffset]; | ||
| 209 | float r = ptr[x * step + roffset]; | ||
| 210 | float nr, ng, nb; | ||
| 211 | float l0, l1, l; | ||
| 212 | |||
| 213 | PROCESS() | ||
| 214 | |||
| 215 | ptr[x * step + goffset] = av_clip_uint8(ng); | ||
| 216 | ptr[x * step + boffset] = av_clip_uint8(nb); | ||
| 217 | ptr[x * step + roffset] = av_clip_uint8(nr); | ||
| 218 | } | ||
| 219 | |||
| 220 | ptr += linesize; | ||
| 221 | } | ||
| 222 | |||
| 223 | return 0; | ||
| 224 | } | ||
| 225 | |||
| 226 | static int temperature_slice16p(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) | ||
| 227 | { | ||
| 228 | ColorTemperatureContext *s = ctx->priv; | ||
| 229 | AVFrame *frame = arg; | ||
| 230 | const int step = s->step; | ||
| 231 | const int depth = s->depth; | ||
| 232 | const int width = frame->width; | ||
| 233 | const int height = frame->height; | ||
| 234 | const float preserve = s->preserve; | ||
| 235 | const float mix = s->mix; | ||
| 236 | const float *color = s->color; | ||
| 237 | const uint8_t roffset = s->rgba_map[R]; | ||
| 238 | const uint8_t goffset = s->rgba_map[G]; | ||
| 239 | const uint8_t boffset = s->rgba_map[B]; | ||
| 240 | const int slice_start = (height * jobnr) / nb_jobs; | ||
| 241 | const int slice_end = (height * (jobnr + 1)) / nb_jobs; | ||
| 242 | const int linesize = frame->linesize[0] / sizeof(uint16_t); | ||
| 243 | uint16_t *ptr = (uint16_t *)frame->data[0] + slice_start * linesize; | ||
| 244 | |||
| 245 | for (int y = slice_start; y < slice_end; y++) { | ||
| 246 | for (int x = 0; x < width; x++) { | ||
| 247 | float g = ptr[x * step + goffset]; | ||
| 248 | float b = ptr[x * step + boffset]; | ||
| 249 | float r = ptr[x * step + roffset]; | ||
| 250 | float nr, ng, nb; | ||
| 251 | float l0, l1, l; | ||
| 252 | |||
| 253 | PROCESS() | ||
| 254 | |||
| 255 | ptr[x * step + goffset] = av_clip_uintp2_c(ng, depth); | ||
| 256 | ptr[x * step + boffset] = av_clip_uintp2_c(nb, depth); | ||
| 257 | ptr[x * step + roffset] = av_clip_uintp2_c(nr, depth); | ||
| 258 | } | ||
| 259 | |||
| 260 | ptr += linesize; | ||
| 261 | } | ||
| 262 | |||
| 263 | return 0; | ||
| 264 | } | ||
| 265 | |||
| 180 | static int filter_frame(AVFilterLink *inlink, AVFrame *frame) | 266 | static int filter_frame(AVFilterLink *inlink, AVFrame *frame) |
| 181 | { | 267 | { |
| 182 | AVFilterContext *ctx = inlink->dst; | 268 | AVFilterContext *ctx = inlink->dst; |
| @@ -193,10 +279,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 10 unmodified lines | |||
| 193 | static av_cold int query_formats(AVFilterContext *ctx) | 279 | static av_cold int query_formats(AVFilterContext *ctx) |
| 194 | { | 280 | { |
| 195 | static const enum AVPixelFormat pixel_fmts[] = { | 281 | static const enum AVPixelFormat pixel_fmts[] = { |
| 282 | AV_PIX_FMT_RGB24, AV_PIX_FMT_BGR24, | ||
| 283 | AV_PIX_FMT_RGBA, AV_PIX_FMT_BGRA, | ||
| 284 | AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, | ||
| 285 | AV_PIX_FMT_0RGB, AV_PIX_FMT_0BGR, | ||
| 286 | AV_PIX_FMT_RGB0, AV_PIX_FMT_BGR0, | ||
| 196 | AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, | 287 | AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, |
| 197 | AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, | 288 | AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12, |
| 198 | AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, | 289 | AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16, |
| 199 | AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16, | 290 | AV_PIX_FMT_GBRAP10, AV_PIX_FMT_GBRAP12, AV_PIX_FMT_GBRAP16, |
| 291 | AV_PIX_FMT_RGB48, AV_PIX_FMT_BGR48, | ||
| 292 | AV_PIX_FMT_RGBA64, AV_PIX_FMT_BGRA64, | ||
| 200 | AV_PIX_FMT_NONE | 293 | AV_PIX_FMT_NONE |
| 201 | }; | 294 | }; |
| 202 | 295 | ||
| @@ -214,9 +307,21 @@ static av_cold int config_input(AVFilterLink *inlink) · 11 unmodified lines | |||
| 214 | AVFilterContext *ctx = inlink->dst; | 307 | AVFilterContext *ctx = inlink->dst; |
| 215 | ColorTemperatureContext *s = ctx->priv; | 308 | ColorTemperatureContext *s = ctx->priv; |
| 216 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); | 309 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(inlink->format); |
| 310 | int planar = desc->flags & AV_PIX_FMT_FLAG_PLANAR; | ||
| 311 | |||
| 312 | s->step = desc->nb_components; | ||
| 313 | if (inlink->format == AV_PIX_FMT_RGB0 || | ||
| 314 | inlink->format == AV_PIX_FMT_0RGB || | ||
| 315 | inlink->format == AV_PIX_FMT_BGR0 || | ||
| 316 | inlink->format == AV_PIX_FMT_0BGR) | ||
| 317 | s->step = 4; | ||
| 217 | 318 | ||
| 218 | s->depth = desc->comp[0].depth; | 319 | s->depth = desc->comp[0].depth; |
| 219 | s->do_slice = s->depth <= 8 ? temperature_slice8 : temperature_slice16; | 320 | s->do_slice = s->depth <= 8 ? temperature_slice8 : temperature_slice16; |
| 321 | if (!planar) | ||
| 322 | s->do_slice = s->depth <= 8 ? temperature_slice8p : temperature_slice16p; | ||
| 323 | |||
| 324 | ff_fill_rgba_map(s->rgba_map, inlink->format); | ||
| 220 | 325 | ||
| 221 | return 0; | 326 | return 0; |
| 222 | } | 327 | } |
| @@ -244,7 +349,7 @@ static const AVFilterPad outputs[] = { · 21 unmodified lines | |||
| 244 | #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM | 349 | #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM |
| 245 | 350 | ||
| 246 | static const AVOption colortemperature_options[] = { | 351 | static const AVOption colortemperature_options[] = { |
| 247 | { "temperature", "set the temperature in Kelvins", OFFSET(temperature), AV_OPT_TYPE_FLOAT, {.dbl=6500}, 1000, 40000, VF }, | 352 | { "temperature", "set the temperature in Kelvin", OFFSET(temperature), AV_OPT_TYPE_FLOAT, {.dbl=6500}, 1000, 40000, VF }, |
| 248 | { "mix", "set the mix with filtered output", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, | 353 | { "mix", "set the mix with filtered output", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF }, |
| 249 | { "pl", "set the amount of preserving lightness", OFFSET(preserve), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, VF }, | 354 | { "pl", "set the amount of preserving lightness", OFFSET(preserve), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, VF }, |
| 250 | { NULL } | 355 | { NULL } |