Skip to content

Commit

Permalink
Merge pull request #33 from FoamyGuy/overlay_scale
Browse files Browse the repository at this point in the history
Overlay scale
  • Loading branch information
FoamyGuy committed Mar 11, 2024
2 parents ac7d37f + 1920616 commit 97dd7bf
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
15 changes: 9 additions & 6 deletions adafruit_pycamera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def __init__(self) -> None: # pylint: disable=too-many-statements
self.combined_bmp = None
self.preview_scale = None
self.overlay_position = [None, None]
self.overlay_scale = 1.0
self.splash = displayio.Group()

# Reset display and I/O expander
Expand Down Expand Up @@ -929,13 +930,15 @@ def blit_overlay_into_last_capture(self):

self.decoder.decode(photo_bitmap, scale=0, x=0, y=0)

bitmaptools.blit(
bitmaptools.rotozoom(
photo_bitmap,
self.overlay_bmp,
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,
ox=self.overlay_position[0] if self.overlay_position[0] is not None else 0,
oy=self.overlay_position[1] if self.overlay_position[1] is not None else 0,
px=0 if self.overlay_position[0] is not None else None,
py=0 if self.overlay_position[1] is not None else None,
skip_index=self.overlay_transparency_color,
scale=self.overlay_scale,
)

cc565_swapped = ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED)
Expand Down Expand Up @@ -1007,7 +1010,7 @@ def blit(self, bitmap, x_offset=0, y_offset=32):
bitmaptools.rotozoom(
self.combined_bmp,
self.overlay_bmp,
scale=self.preview_scale,
scale=self.preview_scale * self.overlay_scale,
skip_index=self.overlay_transparency_color,
ox=int(self.overlay_position[0] * self.preview_scale)
if self.overlay_position[0] is not None
Expand Down
42 changes: 33 additions & 9 deletions examples/overlay/code_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
import traceback
import adafruit_pycamera # pylint: disable=import-error

MODE_POSITION = 0
MODE_SCALE = 1
CURRENT_MODE = 0

int_scale = 100

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

Expand Down Expand Up @@ -49,16 +55,34 @@
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 CURRENT_MODE == MODE_POSITION:
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 CURRENT_MODE == MODE_SCALE:
if pycam.down.fell:
int_scale -= 10
pycam.overlay_scale = int_scale / 100
print(pycam.overlay_scale)
if pycam.up.fell:
int_scale += 10
pycam.overlay_scale = int_scale / 100
print(pycam.overlay_scale)

if pycam.ok.fell:
CURRENT_MODE = MODE_POSITION if CURRENT_MODE == MODE_SCALE else MODE_SCALE
print(f"Changing mode to: {CURRENT_MODE}")
if pycam.shutter.short_count:
print("Shutter released")
pycam.tone(1200, 0.05)
Expand Down

0 comments on commit 97dd7bf

Please sign in to comment.