Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rapidriter-cat
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
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
Stephen D
rapidriter-cat
Commits
366b06ab
Commit
366b06ab
authored
1 month ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
gif exporting
parent
5e3a8b31
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
Cargo.lock
+2
-0
2 additions, 0 deletions
Cargo.lock
Cargo.toml
+2
-0
2 additions, 0 deletions
Cargo.toml
src/main.rs
+58
-11
58 additions, 11 deletions
src/main.rs
with
62 additions
and
11 deletions
Cargo.lock
+
2
−
0
View file @
366b06ab
...
...
@@ -787,10 +787,12 @@ dependencies = [
name = "rapidriter-cat"
version = "0.1.0"
dependencies = [
"anyhow",
"bitvec",
"clap",
"colored",
"console",
"gif",
"image",
]
...
...
This diff is collapsed.
Click to expand it.
Cargo.toml
+
2
−
0
View file @
366b06ab
...
...
@@ -7,10 +7,12 @@ edition = "2021"
crate-type
=
[
"cdylib"
,
"rlib"
]
[dependencies]
anyhow
=
"1.0.96"
bitvec
=
"1.0.1"
clap
=
{
version
=
"4.5.30"
,
features
=
[
"derive"
]
}
colored
=
"3.0.0"
console
=
"0.15.10"
gif
=
"0.13.1"
[build-dependencies]
image
=
"0.25.5"
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
58
−
11
View file @
366b06ab
use
std
::{
io
::{
self
,
Read
},
borrow
::
Cow
,
fs
::
File
,
path
::
PathBuf
,
thread
,
time
::{
Duration
,
Instant
},
};
...
...
@@ -9,6 +11,7 @@ use bitvec::{order::Msb0, view::AsBits};
use
clap
::
Parser
;
use
colored
::
Colorize
;
use
console
::
Term
;
use
gif
::{
Encoder
,
Frame
,
Repeat
};
use
rapidriter_cat
::
next_frame
;
const
WIDTH
:
usize
=
96
;
...
...
@@ -16,17 +19,59 @@ const HEIGHT: usize = 38;
mod
arg
;
fn
main
()
{
fn
main
()
->
anyhow
::
Result
<
()
>
{
let
args
=
Args
::
parse
();
// clear screen
print!
(
"
\x1B
[2J"
);
if
args
.interactive
{
interactive_mode
();
if
let
Some
(
path
)
=
args
.out
{
generate_gif
(
path
)
?
;
}
else
{
non_interactive_mode
();
// clear screen
print!
(
"
\x1B
[2J"
);
if
args
.interactive
{
interactive_mode
();
}
else
{
non_interactive_mode
();
}
}
Ok
(())
}
fn
generate_gif
(
path
:
PathBuf
)
->
anyhow
::
Result
<
()
>
{
let
mut
gif
=
File
::
create
(
path
)
?
;
let
mut
encoder
=
Encoder
::
new
(
&
mut
gif
,
WIDTH
.try_into
()
.unwrap
(),
HEIGHT
.try_into
()
.unwrap
(),
&
[
0
,
0
,
0
,
0xFF
,
0
,
0
],
)
?
;
encoder
.set_repeat
(
Repeat
::
Infinite
)
?
;
let
mut
frame
=
[
0
;
456
];
for
i
in
0
..
100
{
let
done
=
unsafe
{
next_frame
(
i
,
frame
.as_mut_ptr
())
}
==
1
;
let
mut
exploded_frame
=
vec!
[];
for
b
in
frame
.as_bits
::
<
Msb0
>
()
{
exploded_frame
.push
(
if
*
b
{
1
}
else
{
0
});
}
let
f
=
Frame
{
delay
:
10
,
// 100 ms, or 10 FPS
width
:
WIDTH
.try_into
()
.unwrap
(),
height
:
HEIGHT
.try_into
()
.unwrap
(),
buffer
:
Cow
::
Borrowed
(
&*
exploded_frame
),
..
Default
::
default
()
};
encoder
.write_frame
(
&
f
)
?
;
if
done
{
break
;
}
}
Ok
(())
}
fn
interactive_mode
()
{
...
...
@@ -74,12 +119,14 @@ fn non_interactive_mode() {
thread
::
sleep
(
target
-
now
);
}
if
unsafe
{
next_frame
(
i
,
frame
.as_mut_ptr
())
}
==
1
{
break
;
}
let
done
=
unsafe
{
next_frame
(
i
,
frame
.as_mut_ptr
())
}
==
1
;
draw_frame
(
&
frame
);
println!
(
"Frame: {}"
,
i
);
if
done
{
break
;
}
}
}
...
...
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