Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
boytacean
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
Container 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
João Magalhães
boytacean
Commits
6127023c
Verified
Commit
6127023c
authored
1 year ago
by
João Magalhães
Browse files
Options
Downloads
Patches
Plain Diff
chore: tentative video support
parent
aff0da24
No related branches found
No related tags found
1 merge request
!36
Support for Python
Pipeline
#3615
passed
1 year ago
Stage: build
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/python/boytacean/gb.py
+56
-1
56 additions, 1 deletion
src/python/boytacean/gb.py
with
56 additions
and
1 deletion
src/python/boytacean/gb.py
+
56
−
1
View file @
6127023c
from
enum
import
Enum
from
os
import
remove
from
glob
import
glob
from
contextlib
import
contextmanager
from
PIL.Image
import
Image
,
frombytes
...
...
@@ -14,6 +17,10 @@ class GameBoyMode(Enum):
class
GameBoy
:
_frame_index
:
int
=
0
_start_frame
:
int
|
None
_frame_gap
:
int
def
__init__
(
self
,
mode
=
GameBoyMode
.
DMG
,
...
...
@@ -25,6 +32,9 @@ class GameBoy:
load
=
True
,
):
super
().
__init__
()
self
.
_frame_index
=
0
self
.
_next_frame
=
None
self
.
_frame_gap
=
60
self
.
_system
=
GameBoyRust
(
mode
.
value
)
self
.
_system
.
set_ppu_enabled
(
ppu_enabled
)
self
.
_system
.
set_apu_enabled
(
apu_enabled
)
...
...
@@ -64,7 +74,12 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
return
self
.
_system
.
clocks
(
count
)
def
next_frame
(
self
)
->
int
:
return
self
.
_system
.
next_frame
()
cycles
=
self
.
_system
.
next_frame
()
self
.
_frame_index
+=
1
if
self
.
_next_frame
!=
None
and
self
.
_frame_index
>=
self
.
_next_frame
:
self
.
_next_frame
=
self
.
_next_frame
+
self
.
_frame_gap
self
.
save_image
(
f
"
frame_
{
self
.
_frame_index
}
.png
"
)
return
cycles
def
frame_buffer
(
self
):
return
self
.
_system
.
frame_buffer
()
...
...
@@ -87,6 +102,37 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
def
set_palette_colors
(
self
,
colors_hex
:
str
):
self
.
_system
.
set_palette_colors
(
colors_hex
)
@contextmanager
def
video_capture
(
self
,
fps
=
5
):
self
.
_start_capture
(
fps
=
fps
)
try
:
yield
finally
:
self
.
_stop_capture
()
def
video
(
self
):
import
cv2
images
=
glob
(
"
*.png
"
)
fourcc
=
cv2
.
VideoWriter_fourcc
(
*
"
H264
"
)
encoder
=
cv2
.
VideoWriter
(
"
output.mp4
"
,
fourcc
,
60.0
/
self
.
_frame_gap
,
(
DISPLAY_WIDTH
,
DISPLAY_HEIGHT
),
)
for
image_file
in
sorted
(
images
):
img
=
cv2
.
imread
(
image_file
)
encoder
.
write
(
img
)
encoder
.
release
()
from
IPython.display
import
Video
return
Video
(
"
output.mp4
"
,
embed
=
True
,
html_attributes
=
"
controls loop autoplay
"
)
@property
def
ppu_enabled
(
self
)
->
bool
:
return
self
.
_system
.
ppu_enabled
()
...
...
@@ -129,3 +175,12 @@ This is a [Game Boy](https://en.wikipedia.org/wiki/Game_Boy) emulator built usin
@property
def
clock_freq_s
(
self
)
->
str
:
return
self
.
_system
.
clock_freq_s
()
def
_start_capture
(
self
,
fps
=
5
):
self
.
_next_frame
=
self
.
_frame_index
+
self
.
_frame_gap
self
.
_frame_gap
=
int
(
60.0
/
fps
)
# @TODO: This is not accurate!!!
def
_stop_capture
(
self
):
self
.
_next_frame
=
None
for
file
in
glob
(
"
*.png
"
):
remove
(
file
)
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