You've already forked FFmpeg
mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-11-29 05:57:37 +02:00
avfilter/vf_colordetect: slightly change detect_alpha() signature
Basically cosmetic. I want to expand this to detect more than a single property about the alpha channel at the same time; so we first need a way for this function to return a more complex result. Move the enum AlphaMode to the header and formally generalize the return signature a bit to allow returning more than just one value.
This commit is contained in:
@@ -39,13 +39,6 @@
|
||||
|
||||
#include "vf_colordetect.h"
|
||||
|
||||
enum AlphaMode {
|
||||
ALPHA_NONE = -1,
|
||||
ALPHA_UNDETERMINED = 0,
|
||||
ALPHA_STRAIGHT,
|
||||
/* No way to positively identify premultiplied alpha */
|
||||
};
|
||||
|
||||
enum ColorDetectMode {
|
||||
COLOR_DETECT_COLOR_RANGE = 1 << 0,
|
||||
COLOR_DETECT_ALPHA_MODE = 1 << 1,
|
||||
@@ -64,7 +57,7 @@ typedef struct ColorDetectContext {
|
||||
int mpeg_max;
|
||||
|
||||
atomic_int detected_range; // enum AVColorRange
|
||||
atomic_int detected_alpha; // enum AlphaMode
|
||||
atomic_int detected_alpha; // enum FFAlphaDetect
|
||||
} ColorDetectContext;
|
||||
|
||||
#define OFFSET(x) offsetof(ColorDetectContext, x)
|
||||
@@ -124,9 +117,9 @@ static int config_input(AVFilterLink *inlink)
|
||||
|
||||
if (desc->flags & AV_PIX_FMT_FLAG_ALPHA) {
|
||||
s->idx_a = desc->comp[desc->nb_components - 1].plane;
|
||||
atomic_init(&s->detected_alpha, ALPHA_UNDETERMINED);
|
||||
atomic_init(&s->detected_alpha, FF_ALPHA_UNDETERMINED);
|
||||
} else {
|
||||
atomic_init(&s->detected_alpha, ALPHA_NONE);
|
||||
atomic_init(&s->detected_alpha, FF_ALPHA_NONE);
|
||||
}
|
||||
|
||||
ff_color_detect_dsp_init(&s->dsp, depth, inlink->color_range);
|
||||
@@ -182,12 +175,14 @@ static int detect_alpha(AVFilterContext *ctx, void *arg,
|
||||
const int q = s->mpeg_max - s->mpeg_min;
|
||||
const int k = p * s->mpeg_min + q + (1 << (s->depth - 1));
|
||||
|
||||
int ret = 0;
|
||||
for (int i = 0; i < nb_planes; i++) {
|
||||
const ptrdiff_t stride = in->linesize[i];
|
||||
if (s->dsp.detect_alpha(in->data[i] + y_start * stride, stride,
|
||||
alpha, alpha_stride, w, h_slice, p, q, k)) {
|
||||
atomic_store(&s->detected_alpha, ALPHA_STRAIGHT);
|
||||
return 0;
|
||||
ret = s->dsp.detect_alpha(in->data[i] + y_start * stride, stride,
|
||||
alpha, alpha_stride, w, h_slice, p, q, k);
|
||||
if (ret) {
|
||||
atomic_store(&s->detected_alpha, ret);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -202,7 +197,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
|
||||
|
||||
if (s->mode & COLOR_DETECT_COLOR_RANGE && s->detected_range == AVCOL_RANGE_UNSPECIFIED)
|
||||
ff_filter_execute(ctx, detect_range, in, NULL, nb_threads);
|
||||
if (s->mode & COLOR_DETECT_ALPHA_MODE && s->detected_alpha == ALPHA_UNDETERMINED)
|
||||
if (s->mode & COLOR_DETECT_ALPHA_MODE && s->detected_alpha == FF_ALPHA_UNDETERMINED)
|
||||
ff_filter_execute(ctx, detect_alpha, in, NULL, nb_threads);
|
||||
|
||||
return ff_filter_frame(inlink->dst->outputs[0], in);
|
||||
@@ -223,9 +218,9 @@ static av_cold void uninit(AVFilterContext *ctx)
|
||||
|
||||
if (s->mode & COLOR_DETECT_ALPHA_MODE) {
|
||||
av_log(ctx, AV_LOG_INFO, " Alpha mode: %s\n",
|
||||
s->detected_alpha == ALPHA_NONE ? "none" :
|
||||
s->detected_alpha == ALPHA_STRAIGHT ? "straight / independent"
|
||||
: "undetermined");
|
||||
s->detected_alpha == FF_ALPHA_NONE ? "none" :
|
||||
s->detected_alpha == FF_ALPHA_STRAIGHT ? "straight / independent"
|
||||
: "undertermined");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,13 +26,20 @@
|
||||
#include <libavutil/macros.h>
|
||||
#include <libavutil/pixfmt.h>
|
||||
|
||||
enum FFAlphaDetect {
|
||||
FF_ALPHA_NONE = -1,
|
||||
FF_ALPHA_UNDETERMINED = 0,
|
||||
FF_ALPHA_STRAIGHT,
|
||||
/* No way to positively identify premultiplied alpha */
|
||||
};
|
||||
|
||||
typedef struct FFColorDetectDSPContext {
|
||||
/* Returns 1 if an out-of-range value was detected, 0 otherwise */
|
||||
int (*detect_range)(const uint8_t *data, ptrdiff_t stride,
|
||||
ptrdiff_t width, ptrdiff_t height,
|
||||
int mpeg_min, int mpeg_max);
|
||||
|
||||
/* Returns 1 if the color value exceeds the alpha value, 0 otherwise */
|
||||
/* Returns an FFAlphaDetect enum value */
|
||||
int (*detect_alpha)(const uint8_t *color, ptrdiff_t color_stride,
|
||||
const uint8_t *alpha, ptrdiff_t alpha_stride,
|
||||
ptrdiff_t width, ptrdiff_t height,
|
||||
@@ -111,7 +118,7 @@ ff_detect_alpha_full_c(const uint8_t *color, ptrdiff_t color_stride,
|
||||
for (int x = 0; x < width; x++)
|
||||
cond |= color[x] > alpha[x];
|
||||
if (cond)
|
||||
return 1;
|
||||
return FF_ALPHA_STRAIGHT;
|
||||
color += color_stride;
|
||||
alpha += alpha_stride;
|
||||
}
|
||||
@@ -129,7 +136,7 @@ ff_detect_alpha_limited_c(const uint8_t *color, ptrdiff_t color_stride,
|
||||
for (int x = 0; x < width; x++)
|
||||
cond |= p * color[x] - k > q * alpha[x];
|
||||
if (cond)
|
||||
return 1;
|
||||
return FF_ALPHA_STRAIGHT;
|
||||
color += color_stride;
|
||||
alpha += alpha_stride;
|
||||
}
|
||||
@@ -149,7 +156,7 @@ ff_detect_alpha16_full_c(const uint8_t *color, ptrdiff_t color_stride,
|
||||
for (int x = 0; x < width; x++)
|
||||
cond |= color16[x] > alpha16[x];
|
||||
if (cond)
|
||||
return 1;
|
||||
return FF_ALPHA_STRAIGHT;
|
||||
color += color_stride;
|
||||
alpha += alpha_stride;
|
||||
}
|
||||
@@ -167,7 +174,7 @@ ff_detect_alpha16_limited_c(const uint8_t *color, ptrdiff_t color_stride,
|
||||
const uint16_t *alpha16 = (const uint16_t *) alpha;
|
||||
for (int x = 0; x < width; x++) {
|
||||
if ((int64_t) p * color16[x] - k > (int64_t) q * alpha16[x])
|
||||
return 1;
|
||||
return FF_ALPHA_STRAIGHT;
|
||||
}
|
||||
color += color_stride;
|
||||
alpha += alpha_stride;
|
||||
|
||||
Reference in New Issue
Block a user