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
6a955750
Commit
6a955750
authored
Apr 26, 2018
by
Paul B Mahol
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
avfilter/vf_maskedclamp: add slice threading
Signed-off-by:
Paul B Mahol
<
onemda@gmail.com
>
parent
356a33b2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
69 deletions
+99
-69
vf_maskedclamp.c
libavfilter/vf_maskedclamp.c
+99
-69
No files found.
libavfilter/vf_maskedclamp.c
View file @
6a955750
...
@@ -30,6 +30,10 @@
...
@@ -30,6 +30,10 @@
#define OFFSET(x) offsetof(MaskedClampContext, x)
#define OFFSET(x) offsetof(MaskedClampContext, x)
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
#define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
typedef
struct
ThreadData
{
AVFrame
*
b
,
*
o
,
*
m
,
*
d
;
}
ThreadData
;
typedef
struct
MaskedClampContext
{
typedef
struct
MaskedClampContext
{
const
AVClass
*
class
;
const
AVClass
*
class
;
...
@@ -43,11 +47,7 @@ typedef struct MaskedClampContext {
...
@@ -43,11 +47,7 @@ typedef struct MaskedClampContext {
int
depth
;
int
depth
;
FFFrameSync
fs
;
FFFrameSync
fs
;
void
(
*
maskedclamp
)(
const
uint8_t
*
bsrc
,
const
uint8_t
*
osrc
,
int
(
*
maskedclamp
)(
AVFilterContext
*
ctx
,
void
*
arg
,
int
jobnr
,
int
nb_jobs
);
const
uint8_t
*
msrc
,
uint8_t
*
dst
,
ptrdiff_t
blinesize
,
ptrdiff_t
darklinesize
,
ptrdiff_t
brightlinesize
,
ptrdiff_t
destlinesize
,
int
w
,
int
h
,
int
undershoot
,
int
overshoot
);
}
MaskedClampContext
;
}
MaskedClampContext
;
static
const
AVOption
maskedclamp_options
[]
=
{
static
const
AVOption
maskedclamp_options
[]
=
{
...
@@ -103,92 +103,122 @@ static int process_frame(FFFrameSync *fs)
...
@@ -103,92 +103,122 @@ static int process_frame(FFFrameSync *fs)
if
(
!
out
)
if
(
!
out
)
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
}
else
{
}
else
{
int
p
;
ThreadData
td
;
out
=
ff_get_video_buffer
(
outlink
,
outlink
->
w
,
outlink
->
h
);
out
=
ff_get_video_buffer
(
outlink
,
outlink
->
w
,
outlink
->
h
);
if
(
!
out
)
if
(
!
out
)
return
AVERROR
(
ENOMEM
);
return
AVERROR
(
ENOMEM
);
av_frame_copy_props
(
out
,
base
);
av_frame_copy_props
(
out
,
base
);
for
(
p
=
0
;
p
<
s
->
nb_planes
;
p
++
)
{
td
.
b
=
base
;
if
(
!
((
1
<<
p
)
&
s
->
planes
))
{
td
.
o
=
dark
;
av_image_copy_plane
(
out
->
data
[
p
],
out
->
linesize
[
p
],
base
->
data
[
p
],
base
->
linesize
[
p
],
td
.
m
=
bright
;
s
->
linesize
[
p
],
s
->
height
[
p
]);
td
.
d
=
out
;
continue
;
}
s
->
maskedclamp
(
base
->
data
[
p
],
dark
->
data
[
p
],
ctx
->
internal
->
execute
(
ctx
,
s
->
maskedclamp
,
&
td
,
NULL
,
FFMIN
(
s
->
height
[
0
],
bright
->
data
[
p
],
out
->
data
[
p
],
ff_filter_get_nb_threads
(
ctx
)));
base
->
linesize
[
p
],
dark
->
linesize
[
p
],
bright
->
linesize
[
p
],
out
->
linesize
[
p
],
s
->
width
[
p
],
s
->
height
[
p
],
s
->
undershoot
,
s
->
overshoot
);
}
}
}
out
->
pts
=
av_rescale_q
(
s
->
fs
.
pts
,
s
->
fs
.
time_base
,
outlink
->
time_base
);
out
->
pts
=
av_rescale_q
(
s
->
fs
.
pts
,
s
->
fs
.
time_base
,
outlink
->
time_base
);
return
ff_filter_frame
(
outlink
,
out
);
return
ff_filter_frame
(
outlink
,
out
);
}
}
static
void
maskedclamp8
(
const
uint8_t
*
bsrc
,
const
uint8_t
*
darksrc
,
static
int
maskedclamp8
(
AVFilterContext
*
ctx
,
void
*
arg
,
int
jobnr
,
int
nb_jobs
)
const
uint8_t
*
brightsrc
,
uint8_t
*
dst
,
ptrdiff_t
blinesize
,
ptrdiff_t
darklinesize
,
ptrdiff_t
brightlinesize
,
ptrdiff_t
dlinesize
,
int
w
,
int
h
,
int
undershoot
,
int
overshoot
)
{
{
int
x
,
y
;
MaskedClampContext
*
s
=
ctx
->
priv
;
ThreadData
*
td
=
arg
;
for
(
y
=
0
;
y
<
h
;
y
++
)
{
int
p
;
for
(
x
=
0
;
x
<
w
;
x
++
)
{
if
(
bsrc
[
x
]
<
darksrc
[
x
]
-
undershoot
)
for
(
p
=
0
;
p
<
s
->
nb_planes
;
p
++
)
{
dst
[
x
]
=
darksrc
[
x
]
-
undershoot
;
const
ptrdiff_t
blinesize
=
td
->
b
->
linesize
[
p
];
else
if
(
bsrc
[
x
]
>
brightsrc
[
x
]
+
overshoot
)
const
ptrdiff_t
brightlinesize
=
td
->
m
->
linesize
[
p
];
dst
[
x
]
=
brightsrc
[
x
]
+
overshoot
;
const
ptrdiff_t
darklinesize
=
td
->
o
->
linesize
[
p
];
else
const
ptrdiff_t
dlinesize
=
td
->
d
->
linesize
[
p
];
dst
[
x
]
=
bsrc
[
x
];
const
int
w
=
s
->
width
[
p
];
const
int
h
=
s
->
height
[
p
];
const
int
slice_start
=
(
h
*
jobnr
)
/
nb_jobs
;
const
int
slice_end
=
(
h
*
(
jobnr
+
1
))
/
nb_jobs
;
const
uint8_t
*
bsrc
=
td
->
b
->
data
[
p
]
+
slice_start
*
blinesize
;
const
uint8_t
*
darksrc
=
td
->
o
->
data
[
p
]
+
slice_start
*
darklinesize
;
const
uint8_t
*
brightsrc
=
td
->
m
->
data
[
p
]
+
slice_start
*
brightlinesize
;
uint8_t
*
dst
=
td
->
d
->
data
[
p
]
+
slice_start
*
dlinesize
;
const
int
undershoot
=
s
->
undershoot
;
const
int
overshoot
=
s
->
overshoot
;
int
x
,
y
;
if
(
!
((
1
<<
p
)
&
s
->
planes
))
{
av_image_copy_plane
(
dst
,
dlinesize
,
bsrc
,
blinesize
,
s
->
linesize
[
p
],
slice_end
-
slice_start
);
continue
;
}
}
dst
+=
dlinesize
;
for
(
y
=
slice_start
;
y
<
slice_end
;
y
++
)
{
bsrc
+=
blinesize
;
for
(
x
=
0
;
x
<
w
;
x
++
)
{
darksrc
+=
darklinesize
;
if
(
bsrc
[
x
]
<
darksrc
[
x
]
-
undershoot
)
brightsrc
+=
brightlinesize
;
dst
[
x
]
=
darksrc
[
x
]
-
undershoot
;
else
if
(
bsrc
[
x
]
>
brightsrc
[
x
]
+
overshoot
)
dst
[
x
]
=
brightsrc
[
x
]
+
overshoot
;
else
dst
[
x
]
=
bsrc
[
x
];
}
dst
+=
dlinesize
;
bsrc
+=
blinesize
;
darksrc
+=
darklinesize
;
brightsrc
+=
brightlinesize
;
}
}
}
return
0
;
}
}
static
void
maskedclamp16
(
const
uint8_t
*
bbsrc
,
const
uint8_t
*
oosrc
,
static
int
maskedclamp16
(
AVFilterContext
*
ctx
,
void
*
arg
,
int
jobnr
,
int
nb_jobs
)
const
uint8_t
*
mmsrc
,
uint8_t
*
ddst
,
ptrdiff_t
blinesize
,
ptrdiff_t
darklinesize
,
ptrdiff_t
brightlinesize
,
ptrdiff_t
dlinesize
,
int
w
,
int
h
,
int
undershoot
,
int
overshoot
)
{
{
const
uint16_t
*
bsrc
=
(
const
uint16_t
*
)
bbsrc
;
MaskedClampContext
*
s
=
ctx
->
priv
;
const
uint16_t
*
darksrc
=
(
const
uint16_t
*
)
oosrc
;
ThreadData
*
td
=
arg
;
const
uint16_t
*
brightsrc
=
(
const
uint16_t
*
)
mmsrc
;
int
p
;
uint16_t
*
dst
=
(
uint16_t
*
)
ddst
;
int
x
,
y
;
for
(
p
=
0
;
p
<
s
->
nb_planes
;
p
++
)
{
const
ptrdiff_t
blinesize
=
td
->
b
->
linesize
[
p
]
/
2
;
dlinesize
/=
2
;
const
ptrdiff_t
brightlinesize
=
td
->
m
->
linesize
[
p
]
/
2
;
blinesize
/=
2
;
const
ptrdiff_t
darklinesize
=
td
->
o
->
linesize
[
p
]
/
2
;
darklinesize
/=
2
;
const
ptrdiff_t
dlinesize
=
td
->
d
->
linesize
[
p
]
/
2
;
brightlinesize
/=
2
;
const
int
w
=
s
->
width
[
p
];
const
int
h
=
s
->
height
[
p
];
for
(
y
=
0
;
y
<
h
;
y
++
)
{
const
int
slice_start
=
(
h
*
jobnr
)
/
nb_jobs
;
for
(
x
=
0
;
x
<
w
;
x
++
)
{
const
int
slice_end
=
(
h
*
(
jobnr
+
1
))
/
nb_jobs
;
if
(
bsrc
[
x
]
<
darksrc
[
x
]
-
undershoot
)
const
uint16_t
*
bsrc
=
(
const
uint16_t
*
)
td
->
b
->
data
[
p
]
+
slice_start
*
blinesize
;
dst
[
x
]
=
darksrc
[
x
]
-
undershoot
;
const
uint16_t
*
darksrc
=
(
const
uint16_t
*
)
td
->
o
->
data
[
p
]
+
slice_start
*
darklinesize
;
else
if
(
bsrc
[
x
]
>
brightsrc
[
x
]
+
overshoot
)
const
uint16_t
*
brightsrc
=
(
const
uint16_t
*
)
td
->
m
->
data
[
p
]
+
slice_start
*
brightlinesize
;
dst
[
x
]
=
brightsrc
[
x
]
+
overshoot
;
uint16_t
*
dst
=
(
uint16_t
*
)
td
->
d
->
data
[
p
]
+
slice_start
*
dlinesize
;
else
const
int
undershoot
=
s
->
undershoot
;
dst
[
x
]
=
bsrc
[
x
];
const
int
overshoot
=
s
->
overshoot
;
int
x
,
y
;
if
(
!
((
1
<<
p
)
&
s
->
planes
))
{
av_image_copy_plane
(
dst
,
dlinesize
,
bsrc
,
blinesize
,
s
->
linesize
[
p
],
slice_end
-
slice_start
);
continue
;
}
}
dst
+=
dlinesize
;
for
(
y
=
slice_start
;
y
<
slice_end
;
y
++
)
{
bsrc
+=
blinesize
;
for
(
x
=
0
;
x
<
w
;
x
++
)
{
darksrc
+=
darklinesize
;
if
(
bsrc
[
x
]
<
darksrc
[
x
]
-
undershoot
)
brightsrc
+=
brightlinesize
;
dst
[
x
]
=
darksrc
[
x
]
-
undershoot
;
else
if
(
bsrc
[
x
]
>
brightsrc
[
x
]
+
overshoot
)
dst
[
x
]
=
brightsrc
[
x
]
+
overshoot
;
else
dst
[
x
]
=
bsrc
[
x
];
}
dst
+=
dlinesize
;
bsrc
+=
blinesize
;
darksrc
+=
darklinesize
;
brightsrc
+=
brightlinesize
;
}
}
}
return
0
;
}
}
static
int
config_input
(
AVFilterLink
*
inlink
)
static
int
config_input
(
AVFilterLink
*
inlink
)
...
@@ -324,5 +354,5 @@ AVFilter ff_vf_maskedclamp = {
...
@@ -324,5 +354,5 @@ AVFilter ff_vf_maskedclamp = {
.
inputs
=
maskedclamp_inputs
,
.
inputs
=
maskedclamp_inputs
,
.
outputs
=
maskedclamp_outputs
,
.
outputs
=
maskedclamp_outputs
,
.
priv_class
=
&
maskedclamp_class
,
.
priv_class
=
&
maskedclamp_class
,
.
flags
=
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
,
.
flags
=
AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL
|
AVFILTER_FLAG_SLICE_THREADS
,
};
};
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