From 16c74281a6216846f10a3c93d20444b4b8d52f6b Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Feb 2024 20:21:22 -0600 Subject: [PATCH 1/2] overlay_scale feature --- adafruit_pycamera/__init__.py | 15 +++++++++------ examples/overlay/code_select.py | 9 ++++++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/adafruit_pycamera/__init__.py b/adafruit_pycamera/__init__.py index 1c6ad6f..45dcb3c 100644 --- a/adafruit_pycamera/__init__.py +++ b/adafruit_pycamera/__init__.py @@ -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 @@ -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) @@ -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 diff --git a/examples/overlay/code_select.py b/examples/overlay/code_select.py index 441433d..da7ca6f 100644 --- a/examples/overlay/code_select.py +++ b/examples/overlay/code_select.py @@ -2,9 +2,16 @@ # SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries # # SPDX-License-Identifier: MIT -""" simple point-and-shoot camera example, with overly selecting using select button. +""" simple point-and-shoot camera example, with overly capabilities. Place all overlay files inside /sd/overlays/ directory. + +Usage: + +Select Button - Change to the next overlay file +OK Button - Change between position and scale modes +D-Pad - Change the overlay's position or scale depending on which mode + we're currently in. """ import os import time From 1920616c0c49dbe457003d8e5459bdf86a6ca8e4 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 29 Feb 2024 20:23:08 -0600 Subject: [PATCH 2/2] overlay_scale in the example --- examples/overlay/code_select.py | 53 ++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/examples/overlay/code_select.py b/examples/overlay/code_select.py index da7ca6f..665d4e2 100644 --- a/examples/overlay/code_select.py +++ b/examples/overlay/code_select.py @@ -2,22 +2,21 @@ # SPDX-FileCopyrightText: Copyright (c) 2024 Tim Cocks for Adafruit Industries # # SPDX-License-Identifier: MIT -""" simple point-and-shoot camera example, with overly capabilities. +""" simple point-and-shoot camera example, with overly selecting using select button. Place all overlay files inside /sd/overlays/ directory. - -Usage: - -Select Button - Change to the next overlay file -OK Button - Change between position and scale modes -D-Pad - Change the overlay's position or scale depending on which mode - we're currently in. """ import os import time 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 @@ -56,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) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy