Skip to content

Commit 97dd7bf

Browse files
authored
Merge pull request #33 from FoamyGuy/overlay_scale
Overlay scale
2 parents ac7d37f + 1920616 commit 97dd7bf

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

Diff for: adafruit_pycamera/__init__.py

+9-6
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def __init__(self) -> None: # pylint: disable=too-many-statements
240240
self.combined_bmp = None
241241
self.preview_scale = None
242242
self.overlay_position = [None, None]
243+
self.overlay_scale = 1.0
243244
self.splash = displayio.Group()
244245

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

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

932-
bitmaptools.blit(
933+
bitmaptools.rotozoom(
933934
photo_bitmap,
934935
self.overlay_bmp,
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,
937-
skip_source_index=self.overlay_transparency_color,
938-
skip_dest_index=None,
936+
ox=self.overlay_position[0] if self.overlay_position[0] is not None else 0,
937+
oy=self.overlay_position[1] if self.overlay_position[1] is not None else 0,
938+
px=0 if self.overlay_position[0] is not None else None,
939+
py=0 if self.overlay_position[1] is not None else None,
940+
skip_index=self.overlay_transparency_color,
941+
scale=self.overlay_scale,
939942
)
940943

941944
cc565_swapped = ColorConverter(input_colorspace=Colorspace.RGB565_SWAPPED)
@@ -1007,7 +1010,7 @@ def blit(self, bitmap, x_offset=0, y_offset=32):
10071010
bitmaptools.rotozoom(
10081011
self.combined_bmp,
10091012
self.overlay_bmp,
1010-
scale=self.preview_scale,
1013+
scale=self.preview_scale * self.overlay_scale,
10111014
skip_index=self.overlay_transparency_color,
10121015
ox=int(self.overlay_position[0] * self.preview_scale)
10131016
if self.overlay_position[0] is not None

Diff for: examples/overlay/code_select.py

+33-9
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
import traceback
1212
import adafruit_pycamera # pylint: disable=import-error
1313

14+
MODE_POSITION = 0
15+
MODE_SCALE = 1
16+
CURRENT_MODE = 0
17+
18+
int_scale = 100
19+
1420
pycam = adafruit_pycamera.PyCamera()
1521
pycam.mode = 0 # only mode 0 (JPEG) will work in this example
1622

@@ -49,16 +55,34 @@
4955
print(f"changing overlay to {overlay_files[cur_overlay_idx]}")
5056
pycam.overlay = f"/sd/overlays/{overlay_files[cur_overlay_idx]}"
5157

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)
58+
if CURRENT_MODE == MODE_POSITION:
59+
if not pycam.down.value:
60+
pycam.overlay_position[1] += 1 * (
61+
int(pycam.down.current_duration / 0.3) + 1
62+
)
63+
if not pycam.up.value:
64+
pycam.overlay_position[1] -= 1 * (int(pycam.up.current_duration / 0.3) + 1)
65+
if not pycam.left.value:
66+
pycam.overlay_position[0] -= 1 * (
67+
int(pycam.left.current_duration / 0.3) + 1
68+
)
69+
if not pycam.right.value:
70+
pycam.overlay_position[0] += 1 * (
71+
int(pycam.right.current_duration / 0.3) + 1
72+
)
73+
if CURRENT_MODE == MODE_SCALE:
74+
if pycam.down.fell:
75+
int_scale -= 10
76+
pycam.overlay_scale = int_scale / 100
77+
print(pycam.overlay_scale)
78+
if pycam.up.fell:
79+
int_scale += 10
80+
pycam.overlay_scale = int_scale / 100
81+
print(pycam.overlay_scale)
6182

83+
if pycam.ok.fell:
84+
CURRENT_MODE = MODE_POSITION if CURRENT_MODE == MODE_SCALE else MODE_SCALE
85+
print(f"Changing mode to: {CURRENT_MODE}")
6286
if pycam.shutter.short_count:
6387
print("Shutter released")
6488
pycam.tone(1200, 0.05)

0 commit comments

Comments
 (0)