Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overlay position #31

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions adafruit_pycamera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ def __init__(self) -> None: # pylint: disable=too-many-statements
self.overlay_transparency_color = None
self.overlay_bmp = None
self.combined_bmp = None
self.preview_scale = None
self.overlay_position = [None, None]
self.splash = displayio.Group()

# Reset display and I/O expander
Expand Down Expand Up @@ -645,6 +647,8 @@ def resolution(self, res):
microcontroller.nvm[_NVM_RESOLUTION] = res
self._resolution = res
self._res_label.text = self.resolutions[res]
_width = int(self.resolutions[self.resolution].split("x")[0])
self.preview_scale = 240 / _width
self.display.refresh()

@property
Expand Down Expand Up @@ -928,8 +932,8 @@ def blit_overlay_into_last_capture(self):
bitmaptools.blit(
photo_bitmap,
self.overlay_bmp,
0,
0,
self.overlay_position[0] if self.overlay_position[0] is not None else 0,
self.overlay_position[1] if self.overlay_position[1] is not None else 0,
skip_source_index=self.overlay_transparency_color,
skip_dest_index=None,
)
Expand Down Expand Up @@ -1003,8 +1007,16 @@ def blit(self, bitmap, x_offset=0, y_offset=32):
bitmaptools.rotozoom(
self.combined_bmp,
self.overlay_bmp,
scale=0.75,
scale=self.preview_scale,
skip_index=self.overlay_transparency_color,
ox=int(self.overlay_position[0] * self.preview_scale)
if self.overlay_position[0] is not None
else None,
oy=int(self.overlay_position[1] * self.preview_scale)
if self.overlay_position[1] is not None
else None,
px=0 if self.overlay_position[0] is not None else None,
py=0 if self.overlay_position[1] is not None else None,
)
bitmap = self.combined_bmp

Expand Down
Binary file added examples/overlay/blinka_emoji_rgb888.bmp
Binary file not shown.
2 changes: 2 additions & 0 deletions examples/overlay/blinka_emoji_rgb888.bmp.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
# SPDX-License-Identifier: MIT
12 changes: 11 additions & 1 deletion examples/overlay/code_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import traceback
import adafruit_pycamera # pylint: disable=import-error


pycam = adafruit_pycamera.PyCamera()
pycam.mode = 0 # only mode 0 (JPEG) will work in this example

Expand All @@ -34,6 +33,7 @@

pycam.overlay = f"/sd/overlays/{overlay_files[cur_overlay_idx]}"
pycam.overlay_transparency_color = 0xE007
pycam.overlay_position = [0, 0]

overlay_files = os.listdir("/sd/overlays/")
cur_overlay_idx = 0
Expand All @@ -49,6 +49,16 @@
print(f"changing overlay to {overlay_files[cur_overlay_idx]}")
pycam.overlay = f"/sd/overlays/{overlay_files[cur_overlay_idx]}"

if not pycam.down.value:
pycam.overlay_position[1] += 1 * (int(pycam.down.current_duration / 0.3) + 1)
if not pycam.up.value:
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)

if not pycam.left.value:
pycam.overlay_position[0] -= 1 * (int(pycam.left.current_duration / 0.3) + 1)
if not pycam.right.value:
pycam.overlay_position[0] += 1 * (int(pycam.right.current_duration / 0.3) + 1)

if pycam.shutter.short_count:
print("Shutter released")
pycam.tone(1200, 0.05)
Expand Down
Loading