Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
BC
public
external
ffmpeg
Commits
8d2565c2
Commit
8d2565c2
authored
Mar 18, 2013
by
Anton Khirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vf_lut: use the name 's' for the pointer to the private context
This is shorter and consistent across filters.
parent
4753f802
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
60 deletions
+60
-60
libavfilter/vf_lut.c
libavfilter/vf_lut.c
+60
-60
No files found.
libavfilter/vf_lut.c
View file @
8d2565c2
...
...
@@ -104,27 +104,27 @@ static const AVOption lut_options[] = {
static
av_cold
int
init
(
AVFilterContext
*
ctx
)
{
LutContext
*
lut
=
ctx
->
priv
;
LutContext
*
s
=
ctx
->
priv
;
lut
->
var_values
[
VAR_PHI
]
=
M_PHI
;
lut
->
var_values
[
VAR_PI
]
=
M_PI
;
lut
->
var_values
[
VAR_E
]
=
M_E
;
s
->
var_values
[
VAR_PHI
]
=
M_PHI
;
s
->
var_values
[
VAR_PI
]
=
M_PI
;
s
->
var_values
[
VAR_E
]
=
M_E
;
lut
->
is_rgb
=
!
strcmp
(
ctx
->
filter
->
name
,
"lutrgb"
);
lut
->
is_yuv
=
!
strcmp
(
ctx
->
filter
->
name
,
"lutyuv"
);
s
->
is_rgb
=
!
strcmp
(
ctx
->
filter
->
name
,
"lutrgb"
);
s
->
is_yuv
=
!
strcmp
(
ctx
->
filter
->
name
,
"lutyuv"
);
return
0
;
}
static
av_cold
void
uninit
(
AVFilterContext
*
ctx
)
{
LutContext
*
lut
=
ctx
->
priv
;
LutContext
*
s
=
ctx
->
priv
;
int
i
;
for
(
i
=
0
;
i
<
4
;
i
++
)
{
av_expr_free
(
lut
->
comp_expr
[
i
]);
lut
->
comp_expr
[
i
]
=
NULL
;
av_freep
(
&
lut
->
comp_expr_str
[
i
]);
av_expr_free
(
s
->
comp_expr
[
i
]);
s
->
comp_expr
[
i
]
=
NULL
;
av_freep
(
&
s
->
comp_expr_str
[
i
]);
}
}
...
...
@@ -146,10 +146,10 @@ static enum AVPixelFormat all_pix_fmts[] = { RGB_FORMATS, YUV_FORMATS, AV_PIX_FM
static
int
query_formats
(
AVFilterContext
*
ctx
)
{
LutContext
*
lut
=
ctx
->
priv
;
LutContext
*
s
=
ctx
->
priv
;
enum
AVPixelFormat
*
pix_fmts
=
lut
->
is_rgb
?
rgb_pix_fmts
:
lut
->
is_yuv
?
yuv_pix_fmts
:
all_pix_fmts
;
enum
AVPixelFormat
*
pix_fmts
=
s
->
is_rgb
?
rgb_pix_fmts
:
s
->
is_yuv
?
yuv_pix_fmts
:
all_pix_fmts
;
ff_set_common_formats
(
ctx
,
ff_make_format_list
(
pix_fmts
));
return
0
;
...
...
@@ -160,9 +160,9 @@ static int query_formats(AVFilterContext *ctx)
*/
static
double
clip
(
void
*
opaque
,
double
val
)
{
LutContext
*
lut
=
opaque
;
double
minval
=
lut
->
var_values
[
VAR_MINVAL
];
double
maxval
=
lut
->
var_values
[
VAR_MAXVAL
];
LutContext
*
s
=
opaque
;
double
minval
=
s
->
var_values
[
VAR_MINVAL
];
double
maxval
=
s
->
var_values
[
VAR_MAXVAL
];
return
av_clip
(
val
,
minval
,
maxval
);
}
...
...
@@ -173,10 +173,10 @@ static double clip(void *opaque, double val)
*/
static
double
compute_gammaval
(
void
*
opaque
,
double
gamma
)
{
LutContext
*
lut
=
opaque
;
double
val
=
lut
->
var_values
[
VAR_CLIPVAL
];
double
minval
=
lut
->
var_values
[
VAR_MINVAL
];
double
maxval
=
lut
->
var_values
[
VAR_MAXVAL
];
LutContext
*
s
=
opaque
;
double
val
=
s
->
var_values
[
VAR_CLIPVAL
];
double
minval
=
s
->
var_values
[
VAR_MINVAL
];
double
maxval
=
s
->
var_values
[
VAR_MAXVAL
];
return
pow
((
val
-
minval
)
/
(
maxval
-
minval
),
gamma
)
*
(
maxval
-
minval
)
+
minval
;
}
...
...
@@ -196,16 +196,16 @@ static const char * const funcs1_names[] = {
static
int
config_props
(
AVFilterLink
*
inlink
)
{
AVFilterContext
*
ctx
=
inlink
->
dst
;
LutContext
*
lut
=
ctx
->
priv
;
LutContext
*
s
=
ctx
->
priv
;
const
AVPixFmtDescriptor
*
desc
=
av_pix_fmt_desc_get
(
inlink
->
format
);
int
min
[
4
],
max
[
4
];
int
val
,
comp
,
ret
;
lut
->
hsub
=
desc
->
log2_chroma_w
;
lut
->
vsub
=
desc
->
log2_chroma_h
;
s
->
hsub
=
desc
->
log2_chroma_w
;
s
->
vsub
=
desc
->
log2_chroma_h
;
lut
->
var_values
[
VAR_W
]
=
inlink
->
w
;
lut
->
var_values
[
VAR_H
]
=
inlink
->
h
;
s
->
var_values
[
VAR_W
]
=
inlink
->
w
;
s
->
var_values
[
VAR_H
]
=
inlink
->
h
;
switch
(
inlink
->
format
)
{
case
AV_PIX_FMT_YUV410P
:
...
...
@@ -225,55 +225,55 @@ static int config_props(AVFilterLink *inlink)
max
[
0
]
=
max
[
1
]
=
max
[
2
]
=
max
[
3
]
=
255
;
}
lut
->
is_yuv
=
lut
->
is_rgb
=
0
;
if
(
ff_fmt_is_in
(
inlink
->
format
,
yuv_pix_fmts
))
lut
->
is_yuv
=
1
;
else
if
(
ff_fmt_is_in
(
inlink
->
format
,
rgb_pix_fmts
))
lut
->
is_rgb
=
1
;
s
->
is_yuv
=
s
->
is_rgb
=
0
;
if
(
ff_fmt_is_in
(
inlink
->
format
,
yuv_pix_fmts
))
s
->
is_yuv
=
1
;
else
if
(
ff_fmt_is_in
(
inlink
->
format
,
rgb_pix_fmts
))
s
->
is_rgb
=
1
;
if
(
lut
->
is_rgb
)
{
if
(
s
->
is_rgb
)
{
switch
(
inlink
->
format
)
{
case
AV_PIX_FMT_ARGB
:
lut
->
rgba_map
[
A
]
=
0
;
lut
->
rgba_map
[
R
]
=
1
;
lut
->
rgba_map
[
G
]
=
2
;
lut
->
rgba_map
[
B
]
=
3
;
break
;
case
AV_PIX_FMT_ABGR
:
lut
->
rgba_map
[
A
]
=
0
;
lut
->
rgba_map
[
B
]
=
1
;
lut
->
rgba_map
[
G
]
=
2
;
lut
->
rgba_map
[
R
]
=
3
;
break
;
case
AV_PIX_FMT_ARGB
:
s
->
rgba_map
[
A
]
=
0
;
s
->
rgba_map
[
R
]
=
1
;
s
->
rgba_map
[
G
]
=
2
;
s
->
rgba_map
[
B
]
=
3
;
break
;
case
AV_PIX_FMT_ABGR
:
s
->
rgba_map
[
A
]
=
0
;
s
->
rgba_map
[
B
]
=
1
;
s
->
rgba_map
[
G
]
=
2
;
s
->
rgba_map
[
R
]
=
3
;
break
;
case
AV_PIX_FMT_RGBA
:
case
AV_PIX_FMT_RGB24
:
lut
->
rgba_map
[
R
]
=
0
;
lut
->
rgba_map
[
G
]
=
1
;
lut
->
rgba_map
[
B
]
=
2
;
lut
->
rgba_map
[
A
]
=
3
;
break
;
case
AV_PIX_FMT_RGB24
:
s
->
rgba_map
[
R
]
=
0
;
s
->
rgba_map
[
G
]
=
1
;
s
->
rgba_map
[
B
]
=
2
;
s
->
rgba_map
[
A
]
=
3
;
break
;
case
AV_PIX_FMT_BGRA
:
case
AV_PIX_FMT_BGR24
:
lut
->
rgba_map
[
B
]
=
0
;
lut
->
rgba_map
[
G
]
=
1
;
lut
->
rgba_map
[
R
]
=
2
;
lut
->
rgba_map
[
A
]
=
3
;
break
;
case
AV_PIX_FMT_BGR24
:
s
->
rgba_map
[
B
]
=
0
;
s
->
rgba_map
[
G
]
=
1
;
s
->
rgba_map
[
R
]
=
2
;
s
->
rgba_map
[
A
]
=
3
;
break
;
}
lut
->
step
=
av_get_bits_per_pixel
(
desc
)
>>
3
;
s
->
step
=
av_get_bits_per_pixel
(
desc
)
>>
3
;
}
for
(
comp
=
0
;
comp
<
desc
->
nb_components
;
comp
++
)
{
double
res
;
/* create the parsed expression */
ret
=
av_expr_parse
(
&
lut
->
comp_expr
[
comp
],
lut
->
comp_expr_str
[
comp
],
ret
=
av_expr_parse
(
&
s
->
comp_expr
[
comp
],
s
->
comp_expr_str
[
comp
],
var_names
,
funcs1_names
,
funcs1
,
NULL
,
NULL
,
0
,
ctx
);
if
(
ret
<
0
)
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Error when parsing the expression '%s' for the component %d.
\n
"
,
lut
->
comp_expr_str
[
comp
],
comp
);
s
->
comp_expr_str
[
comp
],
comp
);
return
AVERROR
(
EINVAL
);
}
/* compute the
lut
*/
lut
->
var_values
[
VAR_MAXVAL
]
=
max
[
comp
];
lut
->
var_values
[
VAR_MINVAL
]
=
min
[
comp
];
/* compute the
s
*/
s
->
var_values
[
VAR_MAXVAL
]
=
max
[
comp
];
s
->
var_values
[
VAR_MINVAL
]
=
min
[
comp
];
for
(
val
=
0
;
val
<
256
;
val
++
)
{
lut
->
var_values
[
VAR_VAL
]
=
val
;
lut
->
var_values
[
VAR_CLIPVAL
]
=
av_clip
(
val
,
min
[
comp
],
max
[
comp
]);
lut
->
var_values
[
VAR_NEGVAL
]
=
av_clip
(
min
[
comp
]
+
max
[
comp
]
-
lut
->
var_values
[
VAR_VAL
],
s
->
var_values
[
VAR_VAL
]
=
val
;
s
->
var_values
[
VAR_CLIPVAL
]
=
av_clip
(
val
,
min
[
comp
],
max
[
comp
]);
s
->
var_values
[
VAR_NEGVAL
]
=
av_clip
(
min
[
comp
]
+
max
[
comp
]
-
s
->
var_values
[
VAR_VAL
],
min
[
comp
],
max
[
comp
]);
res
=
av_expr_eval
(
lut
->
comp_expr
[
comp
],
lut
->
var_values
,
lut
);
res
=
av_expr_eval
(
s
->
comp_expr
[
comp
],
s
->
var_values
,
s
);
if
(
isnan
(
res
))
{
av_log
(
ctx
,
AV_LOG_ERROR
,
"Error when evaluating the expression '%s' for the value %d for the component #%d.
\n
"
,
lut
->
comp_expr_str
[
comp
],
val
,
comp
);
s
->
comp_expr_str
[
comp
],
val
,
comp
);
return
AVERROR
(
EINVAL
);
}
lut
->
lut
[
comp
][
val
]
=
av_clip
((
int
)
res
,
min
[
comp
],
max
[
comp
]);
av_log
(
ctx
,
AV_LOG_DEBUG
,
"val[%d][%d] = %d
\n
"
,
comp
,
val
,
lut
->
lut
[
comp
][
val
]);
s
->
lut
[
comp
][
val
]
=
av_clip
((
int
)
res
,
min
[
comp
],
max
[
comp
]);
av_log
(
ctx
,
AV_LOG_DEBUG
,
"val[%d][%d] = %d
\n
"
,
comp
,
val
,
s
->
lut
[
comp
][
val
]);
}
}
...
...
@@ -283,7 +283,7 @@ static int config_props(AVFilterLink *inlink)
static
int
filter_frame
(
AVFilterLink
*
inlink
,
AVFrame
*
in
)
{
AVFilterContext
*
ctx
=
inlink
->
dst
;
LutContext
*
lut
=
ctx
->
priv
;
LutContext
*
s
=
ctx
->
priv
;
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
AVFrame
*
out
;
uint8_t
*
inrow
,
*
outrow
,
*
inrow0
,
*
outrow0
;
...
...
@@ -296,7 +296,7 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
av_frame_copy_props
(
out
,
in
);
if
(
lut
->
is_rgb
)
{
if
(
s
->
is_rgb
)
{
/* packed */
inrow0
=
in
->
data
[
0
];
outrow0
=
out
->
data
[
0
];
...
...
@@ -305,10 +305,10 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
inrow
=
inrow0
;
outrow
=
outrow0
;
for
(
j
=
0
;
j
<
inlink
->
w
;
j
++
)
{
for
(
k
=
0
;
k
<
lut
->
step
;
k
++
)
outrow
[
k
]
=
lut
->
lut
[
lut
->
rgba_map
[
k
]][
inrow
[
k
]];
outrow
+=
lut
->
step
;
inrow
+=
lut
->
step
;
for
(
k
=
0
;
k
<
s
->
step
;
k
++
)
outrow
[
k
]
=
s
->
lut
[
s
->
rgba_map
[
k
]][
inrow
[
k
]];
outrow
+=
s
->
step
;
inrow
+=
s
->
step
;
}
inrow0
+=
in
->
linesize
[
0
];
outrow0
+=
out
->
linesize
[
0
];
...
...
@@ -316,15 +316,15 @@ static int filter_frame(AVFilterLink *inlink, AVFrame *in)
}
else
{
/* planar */
for
(
plane
=
0
;
plane
<
4
&&
in
->
data
[
plane
];
plane
++
)
{
int
vsub
=
plane
==
1
||
plane
==
2
?
lut
->
vsub
:
0
;
int
hsub
=
plane
==
1
||
plane
==
2
?
lut
->
hsub
:
0
;
int
vsub
=
plane
==
1
||
plane
==
2
?
s
->
vsub
:
0
;
int
hsub
=
plane
==
1
||
plane
==
2
?
s
->
hsub
:
0
;
inrow
=
in
->
data
[
plane
];
outrow
=
out
->
data
[
plane
];
for
(
i
=
0
;
i
<
in
->
height
>>
vsub
;
i
++
)
{
for
(
j
=
0
;
j
<
inlink
->
w
>>
hsub
;
j
++
)
outrow
[
j
]
=
lut
->
lut
[
plane
][
inrow
[
j
]];
outrow
[
j
]
=
s
->
lut
[
plane
][
inrow
[
j
]];
inrow
+=
in
->
linesize
[
plane
];
outrow
+=
out
->
linesize
[
plane
];
}
...
...
@@ -388,15 +388,15 @@ static const AVOption negate_options[] = {
static
av_cold
int
negate_init
(
AVFilterContext
*
ctx
)
{
LutContext
*
lut
=
ctx
->
priv
;
LutContext
*
s
=
ctx
->
priv
;
int
i
;
av_log
(
ctx
,
AV_LOG_DEBUG
,
"negate_alpha:%d
\n
"
,
lut
->
negate_alpha
);
av_log
(
ctx
,
AV_LOG_DEBUG
,
"negate_alpha:%d
\n
"
,
s
->
negate_alpha
);
for
(
i
=
0
;
i
<
4
;
i
++
)
{
lut
->
comp_expr_str
[
i
]
=
av_strdup
((
i
==
3
&&
lut
->
negate_alpha
)
?
s
->
comp_expr_str
[
i
]
=
av_strdup
((
i
==
3
&&
s
->
negate_alpha
)
?
"val"
:
"negval"
);
if
(
!
lut
->
comp_expr_str
[
i
])
{
if
(
!
s
->
comp_expr_str
[
i
])
{
uninit
(
ctx
);
return
AVERROR
(
ENOMEM
);
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment