History

avfilter/vf_colortemperature: add packed formats support

Paul B Mahol committed 5 years ago

Commit 98b0c0e1 parent aa8cf8f1 file · +106 −1Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/vf_colortemperature.c+106−1
@@ -23,10 +23,15 @@ · 22 unmodified lines
2323 #include "libavutil/opt.h"
2424 #include "libavutil/imgutils.h"
2525 #include "avfilter.h"
26+#include "drawutils.h"
2627 #include "formats.h"
2728 #include "internal.h"
2829 #include "video.h"
2930
31+#define R 0
32+#define G 1
33+#define B 2
34+
3035 typedef struct ColorTemperatureContext {
3136 const AVClass *class;
3237
@@ -36,7 +41,9 @@ typedef struct ColorTemperatureContext { · 3 unmodified lines
3641
3742 float color[3];
3843
44+ int step;
3945 int depth;
46+ uint8_t rgba_map[4];
4047
4148 int (*do_slice)(AVFilterContext *s, void *arg,
4249 int jobnr, int nb_jobs);
@@ -177,6 +184,85 @@ static int temperature_slice16(AVFilterContext *ctx, void *arg, int jobnr, int n · 134 unmodified lines
177184 return 0;
178185 }
179186
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+
180266 static int filter_frame(AVFilterLink *inlink, AVFrame *frame)
181267 {
182268 AVFilterContext *ctx = inlink->dst;
@@ -193,10 +279,17 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *frame) · 10 unmodified lines
193279 static av_cold int query_formats(AVFilterContext *ctx)
194280 {
195281 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,
196287 AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP,
197288 AV_PIX_FMT_GBRP9, AV_PIX_FMT_GBRP10, AV_PIX_FMT_GBRP12,
198289 AV_PIX_FMT_GBRP14, AV_PIX_FMT_GBRP16,
199290 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,
200293 AV_PIX_FMT_NONE
201294 };
202295
@@ -214,9 +307,21 @@ static av_cold int config_input(AVFilterLink *inlink) · 11 unmodified lines
214307 AVFilterContext *ctx = inlink->dst;
215308 ColorTemperatureContext *s = ctx->priv;
216309 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;
217318
218319 s->depth = desc->comp[0].depth;
219320 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);
220325
221326 return 0;
222327 }
@@ -244,7 +349,7 @@ static const AVFilterPad outputs[] = { · 21 unmodified lines
244349 #define VF AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
245350
246351 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 },
248353 { "mix", "set the mix with filtered output", OFFSET(mix), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 1, VF },
249354 { "pl", "set the amount of preserving lightness", OFFSET(preserve), AV_OPT_TYPE_FLOAT, {.dbl=0}, 0, 1, VF },
250355 { NULL }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t