Skip to content

Commit

Permalink
working fix for py5coding#394
Browse files Browse the repository at this point in the history
  • Loading branch information
hx2A committed Feb 5, 2024
1 parent 12b4fb3 commit 9dfaa14
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions py5_resources/py5_module/py5/mixins/pixels.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from PIL import Image
from PIL.Image import Image as PIL_Image

from .. import bridge
from ..decorators import _hex_converter

_Sketch = jpype.JClass("py5.core.Sketch")
Expand Down Expand Up @@ -246,26 +247,33 @@ def save(
if isinstance(self._instance, _Sketch)
else self._instance.parent
)
if not isinstance(filename, BytesIO):
filename = Path(str(sketch_instance.savePath(str(filename))))
self.load_np_pixels()
arr = (
self.np_pixels[:, :, 1:]
if drop_alpha
else np.roll(self.np_pixels, -1, axis=2)
)
if (
isinstance(self._instance, _Sketch)
and bridge.check_run_method_callstack()
and self._py5_bridge.current_running_method not in ["setup", "draw"]
):
self._instance.save(filename)
else:
if not isinstance(filename, BytesIO):
filename = Path(str(sketch_instance.savePath(str(filename))))
self.load_np_pixels()
arr = (
self.np_pixels[:, :, 1:]
if drop_alpha
else np.roll(self.np_pixels, -1, axis=2)
)

if use_thread:
if use_thread:

def _save(arr, filename, format, params):
Image.fromarray(arr).save(filename, format=format, **params)
def _save(arr, filename, format, params):
Image.fromarray(arr).save(filename, format=format, **params)

t = threading.Thread(
target=_save, args=(arr, filename, format, params), daemon=True
)
t.start()
else:
Image.fromarray(arr).save(filename, format=format, **params)
t = threading.Thread(
target=_save, args=(arr, filename, format, params), daemon=True
)
t.start()
else:
Image.fromarray(arr).save(filename, format=format, **params)

# *** END METHODS ***

Expand Down

0 comments on commit 9dfaa14

Please sign in to comment.