History

avfilter/vf_geq: add float formats support

Paul B Mahol committed 4 years ago

Commit d607af51 parent 352a01c1 file · +48 −9Browse files

Unified · Split

libavfilter/vf_geq.c+48−9
@@ -52,6 +52,7 @@ typedef struct GEQContext { · 51 unmodified lines
5252 AVFrame *picref; ///< current input buffer
5353 uint8_t *dst; ///< reference pointer to the 8bits output
5454 uint16_t *dst16; ///< reference pointer to the 16bits output
55+ float *dst32; ///< reference pointer to the 32bits output
5556 double values[VAR_VARS_NB]; ///< expression values
5657 int hsub, vsub; ///< chroma subsampling
5758 int planes; ///< number of planes
@@ -114,13 +115,19 @@ static inline double getpix(void *priv, double x, double y, int plane) · 56 unmodified lines
114115 x -= xi;
115116 y -= yi;
116117
117− if (geq->bps > 8) {
118+ if (geq->bps > 8 && geq->bps <= 16) {
118119 const uint16_t *src16 = (const uint16_t*)src;
119120 linesize /= 2;
120121
121122 return (1-y)*((1-x)*src16[xi + yi * linesize] + x*src16[xi + 1 + yi * linesize])
122123 + y *((1-x)*src16[xi + (yi+1) * linesize] + x*src16[xi + 1 + (yi+1) * linesize]);
123− } else {
124+ } else if (geq->bps == 32) {
125+ const float *src32 = (const float*)src;
126+ linesize /= 4;
127+
128+ return (1-y)*((1-x)*src32[xi + yi * linesize] + x*src32[xi + 1 + yi * linesize])
129+ + y *((1-x)*src32[xi + (yi+1) * linesize] + x*src32[xi + 1 + (yi+1) * linesize]);
130+ } else if (geq->bps == 8) {
124131 return (1-y)*((1-x)*src[xi + yi * linesize] + x*src[xi + 1 + yi * linesize])
125132 + y *((1-x)*src[xi + (yi+1) * linesize] + x*src[xi + 1 + (yi+1) * linesize]);
126133 }
@@ -128,15 +135,22 @@ static inline double getpix(void *priv, double x, double y, int plane) · 1 unmodified line
128135 xi = av_clipd(x, 0, w - 1);
129136 yi = av_clipd(y, 0, h - 1);
130137
131− if (geq->bps > 8) {
138+ if (geq->bps > 8 && geq->bps <= 16) {
132139 const uint16_t *src16 = (const uint16_t*)src;
133140 linesize /= 2;
134141
135142 return src16[xi + yi * linesize];
136− } else {
143+ } else if (geq->bps == 32) {
144+ const float *src32 = (const float*)src;
145+ linesize /= 4;
146+
147+ return src32[xi + yi * linesize];
148+ } else if (geq->bps == 8) {
137149 return src[xi + yi * linesize];
138150 }
139151 }
152+
153+ return 0;
140154 }
141155
142156 static int calculate_sums(GEQContext *geq, int plane, int w, int h)
@@ -150,10 +164,12 @@ static int calculate_sums(GEQContext *geq, int plane, int w, int h) · 7 unmodified lines
150164 geq->pixel_sums[plane] = av_malloc_array(w, h * sizeof (*geq->pixel_sums[plane]));
151165 if (!geq->pixel_sums[plane])
152166 return AVERROR(ENOMEM);
153− if (geq->bps > 8)
167+ if (geq->bps == 32)
168+ linesize /= 4;
169+ else if (geq->bps > 8 && geq->bps <= 16)
154170 linesize /= 2;
155171 for (yi = 0; yi < h; yi ++) {
156− if (geq->bps > 8) {
172+ if (geq->bps > 8 && geq->bps <= 16) {
157173 const uint16_t *src16 = (const uint16_t*)src;
158174 double linesum = 0;
159175
@@ -161,13 +177,21 @@ static int calculate_sums(GEQContext *geq, int plane, int w, int h) · 1 unmodified line
161177 linesum += src16[xi + yi * linesize];
162178 geq->pixel_sums[plane][xi + yi * w] = linesum;
163179 }
164− } else {
180+ } else if (geq->bps == 8) {
165181 double linesum = 0;
166182
167183 for (xi = 0; xi < w; xi ++) {
168184 linesum += src[xi + yi * linesize];
169185 geq->pixel_sums[plane][xi + yi * w] = linesum;
170186 }
187+ } else if (geq->bps == 32) {
188+ const float *src32 = (const float*)src;
189+ double linesum = 0;
190+
191+ for (xi = 0; xi < w; xi ++) {
192+ linesum += src32[xi + yi * linesize];
193+ geq->pixel_sums[plane][xi + yi * w] = linesum;
194+ }
171195 }
172196 if (yi)
173197 for (xi = 0; xi < w; xi ++) {
@@ -249,8 +273,10 @@ static av_cold int geq_init(AVFilterContext *ctx) · 75 unmodified lines
249273 if (!geq->expr_str[V]) geq->expr_str[V] = av_strdup(geq->expr_str[U]);
250274 }
251275
252− if (!geq->expr_str[A]) {
276+ if (!geq->expr_str[A] && geq->bps != 32) {
253277 geq->expr_str[A] = av_asprintf("%d", (1<<geq->bps) - 1);
278+ } else {
279+ geq->expr_str[A] = av_asprintf("%f", 1.f);
254280 }
255281 if (!geq->expr_str[G])
256282 geq->expr_str[G] = av_strdup("g(X,Y)");
@@ -322,6 +348,7 @@ static int geq_query_formats(AVFilterContext *ctx) · 65 unmodified lines
322348 AV_PIX_FMT_YUV444P16, AV_PIX_FMT_YUV422P16, AV_PIX_FMT_YUV420P16,
323349 AV_PIX_FMT_YUVA444P16, AV_PIX_FMT_YUVA422P16, AV_PIX_FMT_YUVA420P16,
324350 AV_PIX_FMT_GRAY16,
351+ AV_PIX_FMT_GRAYF32,
325352 AV_PIX_FMT_NONE
326353 };
327354 static const enum AVPixelFormat rgb_pix_fmts[] = {
@@ -331,6 +358,7 @@ static int geq_query_formats(AVFilterContext *ctx) · 3 unmodified lines
331358 AV_PIX_FMT_GBRP12, AV_PIX_FMT_GBRAP12,
332359 AV_PIX_FMT_GBRP14,
333360 AV_PIX_FMT_GBRP16, AV_PIX_FMT_GBRAP16,
361+ AV_PIX_FMT_GBRPF32, AV_PIX_FMT_GBRAPF32,
334362 AV_PIX_FMT_NONE
335363 };
336364 const enum AVPixelFormat *pix_fmts = geq->is_rgb ? rgb_pix_fmts : yuv_pix_fmts;
@@ -390,7 +418,7 @@ static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_j · 53 unmodified lines
390418 }
391419 ptr += linesize;
392420 }
393− } else {
421+ } else if (geq->bps <= 16) {
394422 uint16_t *ptr16 = geq->dst16 + (linesize/2) * slice_start;
395423 for (y = slice_start; y < slice_end; y++) {
396424 values[VAR_Y] = y;
@@ -400,6 +428,16 @@ static int slice_geq_filter(AVFilterContext *ctx, void *arg, int jobnr, int nb_j · 3 unmodified lines
400428 }
401429 ptr16 += linesize/2;
402430 }
431+ } else {
432+ float *ptr32 = geq->dst32 + (linesize/4) * slice_start;
433+ for (y = slice_start; y < slice_end; y++) {
434+ values[VAR_Y] = y;
435+ for (x = 0; x < width; x++) {
436+ values[VAR_X] = x;
437+ ptr32[x] = av_expr_eval(geq->e[plane][jobnr], values, geq);
438+ }
439+ ptr32 += linesize/4;
440+ }
403441 }
404442
405443 return 0;
@@ -433,6 +471,7 @@ static int geq_filter_frame(AVFilterLink *inlink, AVFrame *in) · 27 unmodified lines
433471
434472 geq->dst = out->data[plane];
435473 geq->dst16 = (uint16_t*)out->data[plane];
474+ geq->dst32 = (float*)out->data[plane];
436475
437476 geq->values[VAR_W] = width;
438477 geq->values[VAR_H] = height;

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