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
2b172cb6
Commit
2b172cb6
authored
Jan 02, 2016
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/avf_showspectrum: make some helper functions
Signed-off-by:
Paul B Mahol
<
onemda@gmail.com
>
parent
d35c029c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
51 deletions
+57
-51
avf_showspectrum.c
libavfilter/avf_showspectrum.c
+57
-51
No files found.
libavfilter/avf_showspectrum.c
View file @
2b172cb6
...
...
@@ -428,6 +428,61 @@ static void scale_magnitudes(ShowSpectrumContext *s, float scale)
}
}
static
void
pick_color
(
ShowSpectrumContext
*
s
,
float
yf
,
float
uf
,
float
vf
,
float
a
,
float
*
out
)
{
if
(
s
->
color_mode
>
CHANNEL
)
{
const
int
cm
=
s
->
color_mode
;
float
y
,
u
,
v
;
int
i
;
for
(
i
=
1
;
i
<
FF_ARRAY_ELEMS
(
color_table
[
cm
])
-
1
;
i
++
)
if
(
color_table
[
cm
][
i
].
a
>=
a
)
break
;
// i now is the first item >= the color
// now we know to interpolate between item i - 1 and i
if
(
a
<=
color_table
[
cm
][
i
-
1
].
a
)
{
y
=
color_table
[
cm
][
i
-
1
].
y
;
u
=
color_table
[
cm
][
i
-
1
].
u
;
v
=
color_table
[
cm
][
i
-
1
].
v
;
}
else
if
(
a
>=
color_table
[
cm
][
i
].
a
)
{
y
=
color_table
[
cm
][
i
].
y
;
u
=
color_table
[
cm
][
i
].
u
;
v
=
color_table
[
cm
][
i
].
v
;
}
else
{
float
start
=
color_table
[
cm
][
i
-
1
].
a
;
float
end
=
color_table
[
cm
][
i
].
a
;
float
lerpfrac
=
(
a
-
start
)
/
(
end
-
start
);
y
=
color_table
[
cm
][
i
-
1
].
y
*
(
1
.
0
f
-
lerpfrac
)
+
color_table
[
cm
][
i
].
y
*
lerpfrac
;
u
=
color_table
[
cm
][
i
-
1
].
u
*
(
1
.
0
f
-
lerpfrac
)
+
color_table
[
cm
][
i
].
u
*
lerpfrac
;
v
=
color_table
[
cm
][
i
-
1
].
v
*
(
1
.
0
f
-
lerpfrac
)
+
color_table
[
cm
][
i
].
v
*
lerpfrac
;
}
out
[
0
]
+=
y
*
yf
;
out
[
1
]
+=
u
*
uf
;
out
[
2
]
+=
v
*
vf
;
}
else
{
out
[
0
]
+=
a
*
yf
;
out
[
1
]
+=
a
*
uf
;
out
[
2
]
+=
a
*
vf
;
}
}
static
void
clear_combine_buffer
(
ShowSpectrumContext
*
s
,
int
size
)
{
int
y
;
for
(
y
=
0
;
y
<
size
;
y
++
)
{
s
->
combine_buffer
[
3
*
y
]
=
0
;
s
->
combine_buffer
[
3
*
y
+
1
]
=
127
.
5
;
s
->
combine_buffer
[
3
*
y
+
2
]
=
127
.
5
;
}
}
static
int
plot_spectrum_column
(
AVFilterLink
*
inlink
,
AVFrame
*
insamples
)
{
int
ret
;
...
...
@@ -442,19 +497,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
/* fill a new spectrum column */
/* initialize buffer for combining to black */
if
(
s
->
orientation
==
VERTICAL
)
{
for
(
y
=
0
;
y
<
outlink
->
h
;
y
++
)
{
s
->
combine_buffer
[
3
*
y
]
=
0
;
s
->
combine_buffer
[
3
*
y
+
1
]
=
127
.
5
;
s
->
combine_buffer
[
3
*
y
+
2
]
=
127
.
5
;
}
}
else
{
for
(
y
=
0
;
y
<
outlink
->
w
;
y
++
)
{
s
->
combine_buffer
[
3
*
y
]
=
0
;
s
->
combine_buffer
[
3
*
y
+
1
]
=
127
.
5
;
s
->
combine_buffer
[
3
*
y
+
2
]
=
127
.
5
;
}
}
clear_combine_buffer
(
s
,
s
->
orientation
==
VERTICAL
?
outlink
->
h
:
outlink
->
w
);
for
(
ch
=
0
;
ch
<
s
->
nb_display_channels
;
ch
++
)
{
float
*
magnitudes
=
s
->
magnitudes
[
ch
];
...
...
@@ -532,44 +575,7 @@ static int plot_spectrum_column(AVFilterLink *inlink, AVFrame *insamples)
av_assert0
(
0
);
}
if
(
s
->
color_mode
>
CHANNEL
)
{
const
int
cm
=
s
->
color_mode
;
float
y
,
u
,
v
;
int
i
;
for
(
i
=
1
;
i
<
FF_ARRAY_ELEMS
(
color_table
[
cm
])
-
1
;
i
++
)
if
(
color_table
[
cm
][
i
].
a
>=
a
)
break
;
// i now is the first item >= the color
// now we know to interpolate between item i - 1 and i
if
(
a
<=
color_table
[
cm
][
i
-
1
].
a
)
{
y
=
color_table
[
cm
][
i
-
1
].
y
;
u
=
color_table
[
cm
][
i
-
1
].
u
;
v
=
color_table
[
cm
][
i
-
1
].
v
;
}
else
if
(
a
>=
color_table
[
cm
][
i
].
a
)
{
y
=
color_table
[
cm
][
i
].
y
;
u
=
color_table
[
cm
][
i
].
u
;
v
=
color_table
[
cm
][
i
].
v
;
}
else
{
float
start
=
color_table
[
cm
][
i
-
1
].
a
;
float
end
=
color_table
[
cm
][
i
].
a
;
float
lerpfrac
=
(
a
-
start
)
/
(
end
-
start
);
y
=
color_table
[
cm
][
i
-
1
].
y
*
(
1
.
0
f
-
lerpfrac
)
+
color_table
[
cm
][
i
].
y
*
lerpfrac
;
u
=
color_table
[
cm
][
i
-
1
].
u
*
(
1
.
0
f
-
lerpfrac
)
+
color_table
[
cm
][
i
].
u
*
lerpfrac
;
v
=
color_table
[
cm
][
i
-
1
].
v
*
(
1
.
0
f
-
lerpfrac
)
+
color_table
[
cm
][
i
].
v
*
lerpfrac
;
}
out
[
0
]
+=
y
*
yf
;
out
[
1
]
+=
u
*
uf
;
out
[
2
]
+=
v
*
vf
;
}
else
{
out
[
0
]
+=
a
*
yf
;
out
[
1
]
+=
a
*
uf
;
out
[
2
]
+=
a
*
vf
;
}
pick_color
(
s
,
yf
,
uf
,
vf
,
a
,
out
);
}
}
...
...
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