Skip to content

Commit e69c14b

Browse files
author
ryan
committed
Implement option to save last frame for opengl
1 parent 66d2638 commit e69c14b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

manim/renderer/opengl_renderer.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ def __init__(self, file_writer_class=SceneFileWriter, skip_animations=False):
224224

225225
self._original_skipping_status = skip_animations
226226
self.skip_animations = skip_animations
227+
self.animation_start_time = 0
227228
self.animations_hashes = []
228229
self.num_plays = 0
229230

@@ -416,8 +417,30 @@ def update_frame(self, scene):
416417
self.animation_elapsed_time = time.time() - self.animation_start_time
417418

418419
def scene_finished(self, scene):
420+
if config["save_last_frame"]:
421+
self.update_frame(scene)
422+
self.file_writer.save_final_image(self.get_image())
419423
self.file_writer.finish()
420424

425+
def get_image(self) -> Image.Image:
426+
"""Returns an image from the current frame.
427+
428+
Returns
429+
-------
430+
PIL.Image
431+
The PIL image of the array.
432+
"""
433+
image = Image.frombytes(
434+
"RGBA",
435+
self.get_pixel_shape(),
436+
self.context.fbo.read(self.get_pixel_shape(), components=4),
437+
"raw",
438+
"RGBA",
439+
0,
440+
-1,
441+
)
442+
return image
443+
421444
def save_static_frame_data(self, scene, static_mobjects):
422445
pass
423446

0 commit comments

Comments
 (0)