Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
F
ffmpeg.wasm-core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Linshizhi
ffmpeg.wasm-core
Commits
45456996
Commit
45456996
authored
Jan 12, 2020
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/vf_normalize: factor code dealing with AVFrame pixels out
parent
1908818e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
43 additions
and
26 deletions
+43
-26
vf_normalize.c
libavfilter/vf_normalize.c
+43
-26
No files found.
libavfilter/vf_normalize.c
View file @
45456996
...
@@ -113,6 +113,9 @@ typedef struct NormalizeContext {
...
@@ -113,6 +113,9 @@ typedef struct NormalizeContext {
uint8_t
*
history_mem
;
// Single allocation for above history entries
uint8_t
*
history_mem
;
// Single allocation for above history entries
uint8_t
lut
[
3
][
256
];
// Lookup table
uint8_t
lut
[
3
][
256
];
// Lookup table
void
(
*
find_min_max
)(
struct
NormalizeContext
*
s
,
AVFrame
*
in
,
NormalizeLocal
min
[
3
],
NormalizeLocal
max
[
3
]);
void
(
*
process
)(
struct
NormalizeContext
*
s
,
AVFrame
*
in
,
AVFrame
*
out
);
}
NormalizeContext
;
}
NormalizeContext
;
#define OFFSET(x) offsetof(NormalizeContext, x)
#define OFFSET(x) offsetof(NormalizeContext, x)
...
@@ -130,6 +133,39 @@ static const AVOption normalize_options[] = {
...
@@ -130,6 +133,39 @@ static const AVOption normalize_options[] = {
AVFILTER_DEFINE_CLASS
(
normalize
);
AVFILTER_DEFINE_CLASS
(
normalize
);
static
void
find_min_max
(
NormalizeContext
*
s
,
AVFrame
*
in
,
NormalizeLocal
min
[
3
],
NormalizeLocal
max
[
3
])
{
for
(
int
c
=
0
;
c
<
3
;
c
++
)
min
[
c
].
in
=
max
[
c
].
in
=
in
->
data
[
0
][
s
->
co
[
c
]];
for
(
int
y
=
0
;
y
<
in
->
height
;
y
++
)
{
uint8_t
*
inp
=
in
->
data
[
0
]
+
y
*
in
->
linesize
[
0
];
for
(
int
x
=
0
;
x
<
in
->
width
;
x
++
)
{
for
(
int
c
=
0
;
c
<
3
;
c
++
)
{
min
[
c
].
in
=
FFMIN
(
min
[
c
].
in
,
inp
[
s
->
co
[
c
]]);
max
[
c
].
in
=
FFMAX
(
max
[
c
].
in
,
inp
[
s
->
co
[
c
]]);
}
inp
+=
s
->
step
;
}
}
}
static
void
process
(
NormalizeContext
*
s
,
AVFrame
*
in
,
AVFrame
*
out
)
{
for
(
int
y
=
0
;
y
<
in
->
height
;
y
++
)
{
uint8_t
*
inp
=
in
->
data
[
0
]
+
y
*
in
->
linesize
[
0
];
uint8_t
*
outp
=
out
->
data
[
0
]
+
y
*
out
->
linesize
[
0
];
for
(
int
x
=
0
;
x
<
in
->
width
;
x
++
)
{
for
(
int
c
=
0
;
c
<
3
;
c
++
)
outp
[
s
->
co
[
c
]]
=
s
->
lut
[
c
][
inp
[
s
->
co
[
c
]]];
if
(
s
->
num_components
==
4
)
// Copy alpha as-is.
outp
[
s
->
co
[
3
]]
=
inp
[
s
->
co
[
3
]];
inp
+=
s
->
step
;
outp
+=
s
->
step
;
}
}
}
// This function is the main guts of the filter. Normalizes the input frame
// This function is the main guts of the filter. Normalizes the input frame
// into the output frame. The frames are known to have the same dimensions
// into the output frame. The frames are known to have the same dimensions
// and pixel format.
// and pixel format.
...
@@ -140,22 +176,11 @@ static void normalize(NormalizeContext *s, AVFrame *in, AVFrame *out)
...
@@ -140,22 +176,11 @@ static void normalize(NormalizeContext *s, AVFrame *in, AVFrame *out)
float
rgb_min_smoothed
;
// Min input range for linked normalization
float
rgb_min_smoothed
;
// Min input range for linked normalization
float
rgb_max_smoothed
;
// Max input range for linked normalization
float
rgb_max_smoothed
;
// Max input range for linked normalization
int
x
,
y
,
c
;
int
c
;
// First, scan the input frame to find, for each channel, the minimum
// First, scan the input frame to find, for each channel, the minimum
// (min.in) and maximum (max.in) values present in the channel.
// (min.in) and maximum (max.in) values present in the channel.
for
(
c
=
0
;
c
<
3
;
c
++
)
s
->
find_min_max
(
s
,
in
,
min
,
max
);
min
[
c
].
in
=
max
[
c
].
in
=
in
->
data
[
0
][
s
->
co
[
c
]];
for
(
y
=
0
;
y
<
in
->
height
;
y
++
)
{
uint8_t
*
inp
=
in
->
data
[
0
]
+
y
*
in
->
linesize
[
0
];
for
(
x
=
0
;
x
<
in
->
width
;
x
++
)
{
for
(
c
=
0
;
c
<
3
;
c
++
)
{
min
[
c
].
in
=
FFMIN
(
min
[
c
].
in
,
inp
[
s
->
co
[
c
]]);
max
[
c
].
in
=
FFMAX
(
max
[
c
].
in
,
inp
[
s
->
co
[
c
]]);
}
inp
+=
s
->
step
;
}
}
// Next, for each channel, push min.in and max.in into their respective
// Next, for each channel, push min.in and max.in into their respective
// histories, to determine the min.smoothed and max.smoothed for this frame.
// histories, to determine the min.smoothed and max.smoothed for this frame.
...
@@ -233,19 +258,7 @@ static void normalize(NormalizeContext *s, AVFrame *in, AVFrame *out)
...
@@ -233,19 +258,7 @@ static void normalize(NormalizeContext *s, AVFrame *in, AVFrame *out)
}
}
// Finally, process the pixels of the input frame using the lookup tables.
// Finally, process the pixels of the input frame using the lookup tables.
for
(
y
=
0
;
y
<
in
->
height
;
y
++
)
{
s
->
process
(
s
,
in
,
out
);
uint8_t
*
inp
=
in
->
data
[
0
]
+
y
*
in
->
linesize
[
0
];
uint8_t
*
outp
=
out
->
data
[
0
]
+
y
*
out
->
linesize
[
0
];
for
(
x
=
0
;
x
<
in
->
width
;
x
++
)
{
for
(
c
=
0
;
c
<
3
;
c
++
)
outp
[
s
->
co
[
c
]]
=
s
->
lut
[
c
][
inp
[
s
->
co
[
c
]]];
if
(
s
->
num_components
==
4
)
// Copy alpha as-is.
outp
[
s
->
co
[
3
]]
=
inp
[
s
->
co
[
3
]];
inp
+=
s
->
step
;
outp
+=
s
->
step
;
}
}
s
->
frame_num
++
;
s
->
frame_num
++
;
}
}
...
@@ -311,6 +324,10 @@ static int config_input(AVFilterLink *inlink)
...
@@ -311,6 +324,10 @@ static int config_input(AVFilterLink *inlink)
s
->
min
[
c
].
history
=
s
->
history_mem
+
(
c
*
2
)
*
s
->
history_len
;
s
->
min
[
c
].
history
=
s
->
history_mem
+
(
c
*
2
)
*
s
->
history_len
;
s
->
max
[
c
].
history
=
s
->
history_mem
+
(
c
*
2
+
1
)
*
s
->
history_len
;
s
->
max
[
c
].
history
=
s
->
history_mem
+
(
c
*
2
+
1
)
*
s
->
history_len
;
}
}
s
->
find_min_max
=
find_min_max
;
s
->
process
=
process
;
return
0
;
return
0
;
}
}
...
...
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