Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
F
ffmpeg
Project
Project
Details
Activity
Releases
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
ffmpeg
Commits
acd87d41
Commit
acd87d41
authored
Jan 18, 2023
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/vf_exposure: reduce copy operations
parent
2c4dcbd6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
13 deletions
+49
-13
vf_exposure.c
libavfilter/vf_exposure.c
+49
-13
No files found.
libavfilter/vf_exposure.c
View file @
acd87d41
...
@@ -38,43 +38,80 @@ typedef struct ExposureContext {
...
@@ -38,43 +38,80 @@ typedef struct ExposureContext {
int
jobnr
,
int
nb_jobs
);
int
jobnr
,
int
nb_jobs
);
}
ExposureContext
;
}
ExposureContext
;
typedef
struct
ThreadData
{
AVFrame
*
out
,
*
in
;
}
ThreadData
;
static
int
exposure_slice
(
AVFilterContext
*
ctx
,
void
*
arg
,
int
jobnr
,
int
nb_jobs
)
static
int
exposure_slice
(
AVFilterContext
*
ctx
,
void
*
arg
,
int
jobnr
,
int
nb_jobs
)
{
{
ExposureContext
*
s
=
ctx
->
priv
;
ExposureContext
*
s
=
ctx
->
priv
;
AVFrame
*
frame
=
arg
;
ThreadData
*
td
=
arg
;
const
int
width
=
frame
->
width
;
const
int
width
=
td
->
out
->
width
;
const
int
height
=
frame
->
height
;
const
int
height
=
td
->
out
->
height
;
const
int
slice_start
=
(
height
*
jobnr
)
/
nb_jobs
;
const
int
slice_start
=
(
height
*
jobnr
)
/
nb_jobs
;
const
int
slice_end
=
(
height
*
(
jobnr
+
1
))
/
nb_jobs
;
const
int
slice_end
=
(
height
*
(
jobnr
+
1
))
/
nb_jobs
;
const
float
black
=
s
->
black
;
const
float
black
=
s
->
black
;
const
float
scale
=
s
->
scale
;
const
float
scale
=
s
->
scale
;
for
(
int
p
=
0
;
p
<
3
;
p
++
)
{
for
(
int
p
=
0
;
p
<
3
;
p
++
)
{
const
int
linesize
=
frame
->
linesize
[
p
]
/
4
;
const
int
slinesize
=
td
->
in
->
linesize
[
p
]
/
4
;
float
*
ptr
=
(
float
*
)
frame
->
data
[
p
]
+
slice_start
*
linesize
;
const
int
dlinesize
=
td
->
out
->
linesize
[
p
]
/
4
;
const
float
*
src
=
(
const
float
*
)
td
->
in
->
data
[
p
]
+
slice_start
*
slinesize
;
float
*
ptr
=
(
float
*
)
td
->
out
->
data
[
p
]
+
slice_start
*
dlinesize
;
for
(
int
y
=
slice_start
;
y
<
slice_end
;
y
++
)
{
for
(
int
y
=
slice_start
;
y
<
slice_end
;
y
++
)
{
for
(
int
x
=
0
;
x
<
width
;
x
++
)
for
(
int
x
=
0
;
x
<
width
;
x
++
)
ptr
[
x
]
=
(
ptr
[
x
]
-
black
)
*
scale
;
ptr
[
x
]
=
(
src
[
x
]
-
black
)
*
scale
;
ptr
+=
dlinesize
;
src
+=
slinesize
;
}
}
ptr
+=
linesize
;
if
(
td
->
in
->
data
[
3
]
&&
td
->
in
->
linesize
[
3
]
&&
td
->
in
!=
td
->
out
)
{
const
int
slinesize
=
td
->
in
->
linesize
[
3
]
/
4
;
const
int
dlinesize
=
td
->
out
->
linesize
[
3
]
/
4
;
const
float
*
src
=
(
const
float
*
)
td
->
in
->
data
[
3
]
+
slice_start
*
slinesize
;
float
*
ptr
=
(
float
*
)
td
->
out
->
data
[
3
]
+
slice_start
*
dlinesize
;
for
(
int
y
=
slice_start
;
y
<
slice_end
;
y
++
)
{
memcpy
(
ptr
,
src
,
width
*
sizeof
(
*
ptr
));
ptr
+=
dlinesize
;
src
+=
slinesize
;
}
}
}
}
return
0
;
return
0
;
}
}
static
int
filter_frame
(
AVFilterLink
*
inlink
,
AVFrame
*
frame
)
static
int
filter_frame
(
AVFilterLink
*
inlink
,
AVFrame
*
in
)
{
{
AVFilterContext
*
ctx
=
inlink
->
dst
;
AVFilterContext
*
ctx
=
inlink
->
dst
;
AVFilterLink
*
outlink
=
ctx
->
outputs
[
0
];
ExposureContext
*
s
=
ctx
->
priv
;
ExposureContext
*
s
=
ctx
->
priv
;
float
diff
=
fabsf
(
exp2f
(
-
s
->
exposure
)
-
s
->
black
);
float
diff
=
fabsf
(
exp2f
(
-
s
->
exposure
)
-
s
->
black
);
ThreadData
td
;
AVFrame
*
out
;
if
(
av_frame_is_writable
(
in
))
{
out
=
in
;
}
else
{
out
=
ff_get_video_buffer
(
outlink
,
outlink
->
w
,
outlink
->
h
);
if
(
!
out
)
{
av_frame_free
(
&
in
);
return
AVERROR
(
ENOMEM
);
}
av_frame_copy_props
(
out
,
in
);
}
diff
=
diff
>
0
.
f
?
diff
:
1
.
f
/
1024
.
f
;
diff
=
diff
>
0
.
f
?
diff
:
1
.
f
/
1024
.
f
;
s
->
scale
=
1
.
f
/
diff
;
s
->
scale
=
1
.
f
/
diff
;
ff_filter_execute
(
ctx
,
s
->
do_slice
,
frame
,
NULL
,
td
.
out
=
out
;
FFMIN
(
frame
->
height
,
ff_filter_get_nb_threads
(
ctx
)));
td
.
in
=
in
;
ff_filter_execute
(
ctx
,
s
->
do_slice
,
&
td
,
NULL
,
return
ff_filter_frame
(
ctx
->
outputs
[
0
],
frame
);
FFMIN
(
out
->
height
,
ff_filter_get_nb_threads
(
ctx
)));
if
(
out
!=
in
)
av_frame_free
(
&
in
);
return
ff_filter_frame
(
outlink
,
out
);
}
}
static
av_cold
int
config_input
(
AVFilterLink
*
inlink
)
static
av_cold
int
config_input
(
AVFilterLink
*
inlink
)
...
@@ -91,7 +128,6 @@ static const AVFilterPad exposure_inputs[] = {
...
@@ -91,7 +128,6 @@ static const AVFilterPad exposure_inputs[] = {
{
{
.
name
=
"default"
,
.
name
=
"default"
,
.
type
=
AVMEDIA_TYPE_VIDEO
,
.
type
=
AVMEDIA_TYPE_VIDEO
,
.
flags
=
AVFILTERPAD_FLAG_NEEDS_WRITABLE
,
.
filter_frame
=
filter_frame
,
.
filter_frame
=
filter_frame
,
.
config_props
=
config_input
,
.
config_props
=
config_input
,
},
},
...
...
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