Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
FFmpeg
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
libremedia
Tethys
FFmpeg
Commits
07f272bd
Commit
07f272bd
authored
13 years ago
by
Michael Niedermayer
Browse files
Options
Downloads
Patches
Plain Diff
mandelbrot: use cache to avoid recalculating points.
Signed-off-by:
Michael Niedermayer
<
michaelni@gmx.at
>
parent
8ca891fc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
libavfilter/vsrc_mandelbrot.c
+52
-3
52 additions, 3 deletions
libavfilter/vsrc_mandelbrot.c
with
52 additions
and
3 deletions
libavfilter/vsrc_mandelbrot.c
+
52
−
3
View file @
07f272bd
...
@@ -35,6 +35,11 @@ enum Outer{
...
@@ -35,6 +35,11 @@ enum Outer{
NORMALIZED_ITERATION_COUNT
,
NORMALIZED_ITERATION_COUNT
,
};
};
typedef
struct
Point
{
double
p
[
2
];
uint32_t
val
;
}
Point
;
typedef
struct
{
typedef
struct
{
int
w
,
h
;
int
w
,
h
;
AVRational
time_base
;
AVRational
time_base
;
...
@@ -47,6 +52,10 @@ typedef struct {
...
@@ -47,6 +52,10 @@ typedef struct {
double
end_pts
;
double
end_pts
;
double
bailout
;
double
bailout
;
enum
Outer
outer
;
enum
Outer
outer
;
int
cache_allocated
;
int
cache_used
;
Point
*
point_cache
;
Point
*
next_cache
;
}
MBContext
;
}
MBContext
;
static
av_cold
int
init
(
AVFilterContext
*
ctx
,
const
char
*
args
,
void
*
opaque
)
static
av_cold
int
init
(
AVFilterContext
*
ctx
,
const
char
*
args
,
void
*
opaque
)
...
@@ -83,6 +92,11 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
...
@@ -83,6 +92,11 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
mb
->
time_base
.
num
=
frame_rate_q
.
den
;
mb
->
time_base
.
num
=
frame_rate_q
.
den
;
mb
->
time_base
.
den
=
frame_rate_q
.
num
;
mb
->
time_base
.
den
=
frame_rate_q
.
num
;
mb
->
cache_allocated
=
mb
->
w
*
mb
->
h
*
2
;
mb
->
cache_used
=
0
;
mb
->
point_cache
=
av_malloc
(
sizeof
(
*
mb
->
point_cache
)
*
mb
->
cache_allocated
);
mb
->
next_cache
=
av_malloc
(
sizeof
(
*
mb
->
next_cache
)
*
mb
->
cache_allocated
);
return
0
;
return
0
;
}
}
...
@@ -91,6 +105,8 @@ static av_cold void uninit(AVFilterContext *ctx)
...
@@ -91,6 +105,8 @@ static av_cold void uninit(AVFilterContext *ctx)
MBContext
*
mb
=
ctx
->
priv
;
MBContext
*
mb
=
ctx
->
priv
;
int
i
;
int
i
;
av_freep
(
&
mb
->
point_cache
);
av_freep
(
&
mb
->
next_cache
);
}
}
static
int
query_formats
(
AVFilterContext
*
ctx
)
static
int
query_formats
(
AVFilterContext
*
ctx
)
...
@@ -119,21 +135,45 @@ static int config_props(AVFilterLink *inlink)
...
@@ -119,21 +135,45 @@ static int config_props(AVFilterLink *inlink)
return
0
;
return
0
;
}
}
static
void
fill_from_cache
(
AVFilterContext
*
ctx
,
uint32_t
*
color
,
int
*
in_cidx
,
int
*
out_cidx
,
double
py
,
double
scale
){
MBContext
*
mb
=
ctx
->
priv
;
for
(;
*
in_cidx
<
mb
->
cache_used
;
(
*
in_cidx
)
++
){
Point
*
p
=
&
mb
->
point_cache
[
*
in_cidx
];
int
x
;
if
(
*
in_cidx
>=
mb
->
cache_used
||
p
->
p
[
1
]
>
py
)
break
;
x
=
round
((
p
->
p
[
0
]
-
mb
->
start_x
)
/
scale
+
mb
->
w
/
2
);
if
(
x
<
0
||
x
>=
mb
->
w
)
continue
;
if
(
color
)
color
[
x
]
=
p
->
val
;
if
(
out_cidx
&&
*
out_cidx
<
mb
->
cache_allocated
)
mb
->
next_cache
[(
*
out_cidx
)
++
]
=
*
p
;
}
}
static
void
draw_mandelbrot
(
AVFilterContext
*
ctx
,
uint32_t
*
color
,
int
linesize
,
int64_t
pts
)
static
void
draw_mandelbrot
(
AVFilterContext
*
ctx
,
uint32_t
*
color
,
int
linesize
,
int64_t
pts
)
{
{
MBContext
*
mb
=
ctx
->
priv
;
MBContext
*
mb
=
ctx
->
priv
;
int
x
,
y
,
i
;
int
x
,
y
,
i
,
in_cidx
=
0
,
next_cidx
=
0
,
tmp_cidx
;
double
scale
=
mb
->
start_scale
*
pow
(
mb
->
end_scale
/
mb
->
start_scale
,
pts
/
mb
->
end_pts
);
double
scale
=
mb
->
start_scale
*
pow
(
mb
->
end_scale
/
mb
->
start_scale
,
pts
/
mb
->
end_pts
);
fill_from_cache
(
ctx
,
NULL
,
&
in_cidx
,
NULL
,
mb
->
start_y
+
scale
*
(
-
mb
->
h
/
2
-
0
.
5
),
scale
);
for
(
y
=
0
;
y
<
mb
->
h
;
y
++
){
for
(
y
=
0
;
y
<
mb
->
h
;
y
++
){
const
double
ci
=
mb
->
start_y
+
scale
*
(
y
-
mb
->
h
/
2
);
memset
(
color
+
linesize
*
y
,
0
,
sizeof
(
*
color
)
*
mb
->
w
);
fill_from_cache
(
ctx
,
color
+
linesize
*
y
,
&
in_cidx
,
&
next_cidx
,
ci
,
scale
);
tmp_cidx
=
in_cidx
;
fill_from_cache
(
ctx
,
color
+
linesize
*
y
,
&
tmp_cidx
,
NULL
,
ci
+
scale
/
2
,
scale
);
for
(
x
=
0
;
x
<
mb
->
w
;
x
++
){
for
(
x
=
0
;
x
<
mb
->
w
;
x
++
){
const
double
cr
=
mb
->
start_x
+
scale
*
(
x
-
mb
->
w
/
2
);
const
double
cr
=
mb
->
start_x
+
scale
*
(
x
-
mb
->
w
/
2
);
const
double
ci
=
mb
->
start_y
+
scale
*
(
y
-
mb
->
h
/
2
);
double
zr
=
cr
;
double
zr
=
cr
;
double
zi
=
ci
;
double
zi
=
ci
;
uint32_t
c
=
0
;
uint32_t
c
=
0
;
if
(
color
[
x
+
y
*
linesize
]
&
0xFF000000
)
continue
;
for
(
i
=
0
;
i
<
mb
->
maxiter
;
i
++
){
for
(
i
=
0
;
i
<
mb
->
maxiter
;
i
++
){
double
t
;
double
t
;
if
(
zr
*
zr
+
zi
*
zi
>
mb
->
bailout
){
if
(
zr
*
zr
+
zi
*
zi
>
mb
->
bailout
){
...
@@ -148,9 +188,18 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize,
...
@@ -148,9 +188,18 @@ static void draw_mandelbrot(AVFilterContext *ctx, uint32_t *color, int linesize,
zi
=
2
*
zr
*
zi
+
ci
;
zi
=
2
*
zr
*
zi
+
ci
;
zr
=
t
+
cr
;
zr
=
t
+
cr
;
}
}
c
|=
0xFF000000
;
color
[
x
+
y
*
linesize
]
=
c
;
color
[
x
+
y
*
linesize
]
=
c
;
if
(
next_cidx
<
mb
->
cache_allocated
){
mb
->
next_cache
[
next_cidx
].
p
[
0
]
=
cr
;
mb
->
next_cache
[
next_cidx
].
p
[
1
]
=
ci
;
mb
->
next_cache
[
next_cidx
++
].
val
=
c
;
}
}
}
fill_from_cache
(
ctx
,
NULL
,
&
in_cidx
,
&
next_cidx
,
ci
+
scale
/
2
,
scale
);
}
}
FFSWAP
(
void
*
,
mb
->
next_cache
,
mb
->
point_cache
);
mb
->
cache_used
=
next_cidx
;
}
}
static
int
request_frame
(
AVFilterLink
*
link
)
static
int
request_frame
(
AVFilterLink
*
link
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment