FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Typedefs | Functions | Variables
vf_xbr.c File Reference

XBR Filter is used for depixelization of image. More...

#include "libavutil/opt.h"
#include "libavutil/avassert.h"
#include "libavutil/pixdesc.h"
#include "internal.h"

Go to the source code of this file.

Data Structures

struct  XBRContext
 
struct  ThreadData
 

Macros

#define RGB_MASK   0x00FFFFFF
 
#define LB_MASK   0x00FEFEFE
 
#define RED_BLUE_MASK   0x00FF00FF
 
#define GREEN_MASK   0x0000FF00
 
#define OFFSET(x)   offsetof(XBRContext, x)
 
#define FLAGS   AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
 
#define YMASK   0xff0000
 
#define UMASK   0x00ff00
 
#define VMASK   0x0000ff
 
#define ALPHA_BLEND_128_W(dst, src)   dst = ((src & LB_MASK) >> 1) + ((dst & LB_MASK) >> 1)
 
#define ALPHA_BLEND_32_W(dst, src)
 
#define ALPHA_BLEND_64_W(dst, src)
 
#define ALPHA_BLEND_192_W(dst, src)
 
#define ALPHA_BLEND_224_W(dst, src)
 
#define df(A, B)   pixel_diff(A, B, r2y)
 
#define eq(A, B)   (df(A, B) < 155)
 
#define FILT2(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1,N0, N1, N2, N3)
 
#define FILT3(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1,N0, N1, N2, N3, N4, N5, N6, N7, N8)
 
#define FILT4(PE, PI, PH, PF, PG, PC, PD, PB, PA, G5, C4, G0, D0, C1, B1, F4, I4, H5, I5, A0, A1,N15, N14, N11, N3, N7, N10, N13, N12, N9, N6, N2, N1, N5, N8, N4, N0)
 
#define XBR_FUNC(size)
 

Typedefs

typedef int(* xbrfunc_t )(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)
 

Functions

 AVFILTER_DEFINE_CLASS (xbr)
 
static uint32_t pixel_diff (uint32_t x, uint32_t y, const uint32_t *r2y)
 
static av_always_inline void xbr_filter (const ThreadData *td, int jobnr, int nb_jobs, int n)
 
static int config_output (AVFilterLink *outlink)
 
static int query_formats (AVFilterContext *ctx)
 
static int filter_frame (AVFilterLink *inlink, AVFrame *in)
 
static int init (AVFilterContext *ctx)
 

Variables

static const AVOption xbr_options []
 
static const AVFilterPad xbr_inputs []
 
static const AVFilterPad xbr_outputs []
 
AVFilter ff_vf_xbr
 

Detailed Description

XBR Filter is used for depixelization of image.

This is based on Hyllian's xBR shader.

See Also
http://www.libretro.com/forums/viewtopic.php?f=6&t=134
https://github.com/yoyofr/iFBA/blob/master/fba_src/src/intf/video/scalers/xbr.cpp

Definition in file vf_xbr.c.

Macro Definition Documentation

#define RGB_MASK   0x00FFFFFF

Definition at line 36 of file vf_xbr.c.

#define LB_MASK   0x00FEFEFE

Definition at line 37 of file vf_xbr.c.

#define RED_BLUE_MASK   0x00FF00FF

Definition at line 38 of file vf_xbr.c.

#define GREEN_MASK   0x0000FF00

Definition at line 39 of file vf_xbr.c.

#define OFFSET (   x)    offsetof(XBRContext, x)

Definition at line 55 of file vf_xbr.c.

Definition at line 56 of file vf_xbr.c.

#define YMASK   0xff0000
#define UMASK   0x00ff00
#define VMASK   0x0000ff
#define ALPHA_BLEND_128_W (   dst,
  src 
)    dst = ((src & LB_MASK) >> 1) + ((dst & LB_MASK) >> 1)

Definition at line 78 of file vf_xbr.c.

#define ALPHA_BLEND_32_W (   dst,
  src 
)
Value:
dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
(dst & RED_BLUE_MASK))) >> 3))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
((((src & GREEN_MASK) - (dst & GREEN_MASK))) >> 3))))

Definition at line 80 of file vf_xbr.c.

#define ALPHA_BLEND_64_W (   dst,
  src 
)
Value:
dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
(dst & RED_BLUE_MASK))) >> 2))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
((((src & GREEN_MASK) - (dst & GREEN_MASK))) >> 2))))

Definition at line 85 of file vf_xbr.c.

#define ALPHA_BLEND_192_W (   dst,
  src 
)
Value:
dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
(dst & RED_BLUE_MASK)) * 3) >> 2))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
((((src & GREEN_MASK) - (dst & GREEN_MASK)) * 3) >> 2))))

Definition at line 90 of file vf_xbr.c.

#define ALPHA_BLEND_224_W (   dst,
  src 
)
Value:
dst = ((RED_BLUE_MASK & ((dst & RED_BLUE_MASK) + ((((src & RED_BLUE_MASK) - \
(dst & RED_BLUE_MASK)) * 7) >> 3))) | (GREEN_MASK & ((dst & GREEN_MASK) + \
((((src & GREEN_MASK) - (dst & GREEN_MASK)) * 7) >> 3))))

Definition at line 95 of file vf_xbr.c.

#define df (   A,
  B 
)    pixel_diff(A, B, r2y)

Definition at line 100 of file vf_xbr.c.

Referenced by filter_slice().

#define eq (   A,
  B 
)    (df(A, B) < 155)

Definition at line 101 of file vf_xbr.c.

Referenced by control().

#define FILT2 (   PE,
  PI,
  PH,
  PF,
  PG,
  PC,
  PD,
  PB,
  PA,
  G5,
  C4,
  G0,
  D0,
  C1,
  B1,
  F4,
  I4,
  H5,
  I5,
  A0,
  A1,
  N0,
  N1,
  N2,
  N3 
)
Value:
do { \
if (PE != PH && PE != PF) { \
const unsigned e = df(PE,PC) + df(PE,PG) + df(PI,H5) + df(PI,F4) + (df(PH,PF)<<2); \
const unsigned i = df(PH,PD) + df(PH,I5) + df(PF,I4) + df(PF,PB) + (df(PE,PI)<<2); \
if (e < i && (!eq(PF,PB) && !eq(PH,PD) || eq(PE,PI) \
&& (!eq(PF,I4) && !eq(PH,I5)) \
|| eq(PE,PG) || eq(PE,PC))) { \
const unsigned ke = df(PF,PG); \
const unsigned ki = df(PH,PC); \
const int left = ke<<1 <= ki && PE != PG && PD != PG; \
const int up = ke >= ki<<1 && PE != PC && PB != PC; \
const unsigned px = df(PE,PF) <= df(PE,PH) ? PF : PH; \
if (left && up) { \
ALPHA_BLEND_224_W(E[N3], px); \
ALPHA_BLEND_64_W( E[N2], px); \
E[N1] = E[N2]; \
} else if (left) { \
ALPHA_BLEND_192_W(E[N3], px); \
ALPHA_BLEND_64_W( E[N2], px); \
} else if (up) { \
ALPHA_BLEND_192_W(E[N3], px); \
ALPHA_BLEND_64_W( E[N1], px); \
} else { /* diagonal */ \
ALPHA_BLEND_128_W(E[N3], px); \
} \
} else if (e <= i) { \
ALPHA_BLEND_128_W( E[N3], ((df(PE,PF) <= df(PE,PH)) ? PF : PH)); \
} \
} \
} while (0)

Definition at line 103 of file vf_xbr.c.

Referenced by xbr_filter().

#define FILT3 (   PE,
  PI,
  PH,
  PF,
  PG,
  PC,
  PD,
  PB,
  PA,
  G5,
  C4,
  G0,
  D0,
  C1,
  B1,
  F4,
  I4,
  H5,
  I5,
  A0,
  A1,
  N0,
  N1,
  N2,
  N3,
  N4,
  N5,
  N6,
  N7,
  N8 
)

Definition at line 135 of file vf_xbr.c.

Referenced by xbr_filter().

#define FILT4 (   PE,
  PI,
  PH,
  PF,
  PG,
  PC,
  PD,
  PB,
  PA,
  G5,
  C4,
  G0,
  D0,
  C1,
  B1,
  F4,
  I4,
  H5,
  I5,
  A0,
  A1,
  N15,
  N14,
  N11,
  N3,
  N7,
  N10,
  N13,
  N12,
  N9,
  N6,
  N2,
  N1,
  N5,
  N8,
  N4,
  N0 
)

Definition at line 175 of file vf_xbr.c.

Referenced by xbr_filter().

#define XBR_FUNC (   size)
Value:
static int xbr##size##x(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs) \
{ \
xbr_filter(arg, jobnr, nb_jobs, size); \
return 0; \
}

Definition at line 325 of file vf_xbr.c.

Typedef Documentation

typedef int(* xbrfunc_t)(AVFilterContext *ctx, void *arg, int jobnr, int nb_jobs)

Definition at line 41 of file vf_xbr.c.

Function Documentation

AVFILTER_DEFINE_CLASS ( xbr  )
static uint32_t pixel_diff ( uint32_t  x,
uint32_t  y,
const uint32_t *  r2y 
)
static

Definition at line 64 of file vf_xbr.c.

static av_always_inline void xbr_filter ( const ThreadData td,
int  jobnr,
int  nb_jobs,
int  n 
)
static

Definition at line 219 of file vf_xbr.c.

static int config_output ( AVFilterLink outlink)
static

Definition at line 337 of file vf_xbr.c.

static int query_formats ( AVFilterContext ctx)
static

Definition at line 348 of file vf_xbr.c.

static int filter_frame ( AVFilterLink inlink,
AVFrame in 
)
static

Definition at line 358 of file vf_xbr.c.

static int init ( AVFilterContext ctx)
static

Definition at line 385 of file vf_xbr.c.

Variable Documentation

const AVOption xbr_options[]
static
Initial value:
= {
{ "n", "set scale factor", OFFSET(n), AV_OPT_TYPE_INT, {.i64 = 3}, 2, 4, .flags = FLAGS },
{ NULL }
}

Definition at line 57 of file vf_xbr.c.

const AVFilterPad xbr_inputs[]
static
Initial value:
= {
{
.name = "default",
.filter_frame = filter_frame,
},
{ NULL }
}

Definition at line 412 of file vf_xbr.c.

const AVFilterPad xbr_outputs[]
static
Initial value:
= {
{
.name = "default",
.config_props = config_output,
},
{ NULL }
}

Definition at line 421 of file vf_xbr.c.

AVFilter ff_vf_xbr
Initial value:
= {
.name = "xbr",
.description = NULL_IF_CONFIG_SMALL("Scale the input using xBR algorithm."),
.inputs = xbr_inputs,
.outputs = xbr_outputs,
.query_formats = query_formats,
.priv_size = sizeof(XBRContext),
.priv_class = &xbr_class,
.init = init,
}

Definition at line 430 of file vf_xbr.c.