Skip to content

Commit ac7d37f

Browse files
authored
Merge pull request adafruit#31 from FoamyGuy/overlay_pos
Overlay position
2 parents b06ccf5 + c6b2502 commit ac7d37f

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

adafruit_pycamera/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ def __init__(self) -> None: # pylint: disable=too-many-statements
238238
self.overlay_transparency_color = None
239239
self.overlay_bmp = None
240240
self.combined_bmp = None
241+
self.preview_scale = None
242+
self.overlay_position = [None, None]
241243
self.splash = displayio.Group()
242244

243245
# Reset display and I/O expander
@@ -645,6 +647,8 @@ def resolution(self, res):
645647
microcontroller.nvm[_NVM_RESOLUTION] = res
646648
self._resolution = res
647649
self._res_label.text = self.resolutions[res]
650+
_width = int(self.resolutions[self.resolution].split("x")[0])
651+
self.preview_scale = 240 / _width
648652
self.display.refresh()
649653

650654
@property
@@ -928,8 +932,8 @@ def blit_overlay_into_last_capture(self):
928932
bitmaptools.blit(
929933
photo_bitmap,
930934
self.overlay_bmp,
931-
0,
932-
0,
935+
self.overlay_position[0] if self.overlay_position[0] is not None else 0,
936+
self.overlay_position[1] if self.overlay_position[1] is not None else 0,
933937
skip_source_index=self.overlay_transparency_color,
934938
skip_dest_index=None,
935939
)
@@ -1003,8 +1007,16 @@ def blit(self, bitmap, x_offset=0, y_offset=32):
10031007
bitmaptools.rotozoom(
10041008
self.combined_bmp,
10051009
self.overlay_bmp,
1006-
scale=0.75,
1010+
scale=self.preview_scale,
10071011
skip_index=self.overlay_transparency_color,
1012+
ox=int(self.overlay_position[0] * self.preview_scale)
1013+
if self.overlay_position[0] is not None
1014+
else None,
1015+
oy=int(self.overlay_position[1] * self.preview_scale)
1016+
if self.overlay_position[1] is not None
1017+
else None,
1018+
px=0 if self.overlay_position[0] is not None else None,
1019+
py=0 if self.overlay_position[1] is not None else None,
10081020
)
10091021
bitmap = self.combined_bmp
10101022

48.1 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# SPDX-FileCopyrightText: 2024 Tim Cocks for Adafruit Industries
2+
# SPDX-License-Identifier: MIT

examples/overlay/code_select.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import traceback
1212
import adafruit_pycamera # pylint: disable=import-error
1313

14-
1514
pycam = adafruit_pycamera.PyCamera()
1615
pycam.mode = 0 # only mode 0 (JPEG) will work in this example
1716

@@ -34,6 +33,7 @@
3433

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

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

52+
if not pycam.down.value:
53+
pycam.overlay_position[1] += 1 * (int(pycam.down.current_duration / 0.3) + 1)
54+
if not pycam.up.value:
55+
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)
56+
57+
if not pycam.left.value:
58+
pycam.overlay_position[0] -= 1 * (int(pycam.left.current_duration / 0.3) + 1)
59+
if not pycam.right.value:
60+
pycam.overlay_position[0] += 1 * (int(pycam.right.current_duration / 0.3) + 1)
61+
5262
if pycam.shutter.short_count:
5363
print("Shutter released")
5464
pycam.tone(1200, 0.05)

0 commit comments

Comments
 (0)