lavfi/selectivecolor: simplify crazy mid val computations

This commit is contained in:
Clément Bœsch 2016-12-27 23:43:59 +01:00
parent 571a360157
commit afaaf8db18
1 changed files with 3 additions and 30 deletions

View File

@ -28,6 +28,7 @@
#include "libavutil/intreadwrite.h" #include "libavutil/intreadwrite.h"
#include "libavutil/opt.h" #include "libavutil/opt.h"
#include "libavutil/pixdesc.h" #include "libavutil/pixdesc.h"
#include "libavcodec/mathops.h" // for mid_pred(), which is a macro so no link dependency
#include "avfilter.h" #include "avfilter.h"
#include "drawutils.h" #include "drawutils.h"
#include "formats.h" #include "formats.h"
@ -112,42 +113,14 @@ static const AVOption selectivecolor_options[] = {
AVFILTER_DEFINE_CLASS(selectivecolor); AVFILTER_DEFINE_CLASS(selectivecolor);
static inline int get_mid_val(int r, int g, int b)
{
if ((r < g && r > b) || (r < b && r > g)) return r;
if ((g < r && g > b) || (g < b && g > r)) return g;
if ((b < r && b > g) || (b < g && b > r)) return b;
return -1;
}
static int get_rgb_adjust_range(int r, int g, int b, int min_val, int max_val) static int get_rgb_adjust_range(int r, int g, int b, int min_val, int max_val)
{ {
// max - mid return max_val - mid_pred(r, g, b);
const int mid_val = get_mid_val(r, g, b);
if (mid_val == -1) {
// XXX: can be simplified
if ((r != min_val && g == min_val && b == min_val) ||
(r == min_val && g != min_val && b == min_val) ||
(r == min_val && g == min_val && b != min_val))
return max_val - min_val;
return 0;
}
return max_val - mid_val;
} }
static int get_cmy_adjust_range(int r, int g, int b, int min_val, int max_val) static int get_cmy_adjust_range(int r, int g, int b, int min_val, int max_val)
{ {
// mid - min return mid_pred(r, g, b) - min_val;
const int mid_val = get_mid_val(r, g, b);
if (mid_val == -1) {
// XXX: refactor with rgb
if ((r != max_val && g == max_val && b == max_val) ||
(r == max_val && g != max_val && b == max_val) ||
(r == max_val && g == max_val && b != max_val))
return max_val - min_val;
return 0;
}
return mid_val - min_val;
} }
#define DECLARE_ADJUST_RANGE_FUNCS(nbits) \ #define DECLARE_ADJUST_RANGE_FUNCS(nbits) \