Skip to content

Commit

Permalink
Merge pull request #31 from FoamyGuy/overlay_pos
Browse files Browse the repository at this point in the history
Overlay position
  • Loading branch information
FoamyGuy authored Mar 1, 2024
2 parents b06ccf5 + c6b2502 commit ac7d37f
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 4 deletions.
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

0 comments on commit ac7d37f

Please sign in to comment.