Skip to content

Commit 9c0d8f2

Browse files
Try to optimize
1 parent dffaa01 commit 9c0d8f2

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

apps/com.example.camtest/assets/camtest.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,27 +78,30 @@
7878
cam.set_vflip(True)
7979

8080

81+
buffer = bytearray(width * height * 2) # RGB565 uses 2 bytes per pixel
8182

8283
image = lv.image(cont)
8384
image.align(lv.ALIGN.LEFT_MID, 0, 0)
8485
image.set_rotation(900)
86+
image_dsc = lv.image_dsc_t({
87+
"header": { "magic": lv.IMAGE_HEADER_MAGIC, "w": width, "h": height, "stride": width * 2, "cf": lv.COLOR_FORMAT.RGB565 },
88+
'data_size': len(buffer),
89+
'data': buffer
90+
})
91+
image.set_src(image_dsc)
8592

8693
def try_capture():
8794
if cam.frame_available():
88-
img = bytes(cam.capture())
95+
buffer[:] = bytes(cam.capture())
8996
cam.free_buffer()
9097
# Swap bytes for each 16-bit pixel
9198
# This is no longer needed because the esp-camera driver does {FORMAT_CTRL00, 0x6F}, // RGB565 (RGB) instead of {FORMAT_CTRL00, 0x61}, // RGB565 (BGR) now
9299
#img_swapped = bytearray(len(img))
93100
#for i in range(0, len(img), 2):
94101
# img_swapped[i] = img[i+1] # Swap high and low bytes
95102
# img_swapped[i+1] = img[i]
96-
image_dsc = lv.image_dsc_t({
97-
"header": { "magic": lv.IMAGE_HEADER_MAGIC, "w": width, "h": height, "stride": width * 2, "cf": lv.COLOR_FORMAT.RGB565 },
98-
'data_size': len(img),
99-
'data': img
100-
})
101-
image.set_src(image_dsc)
103+
# This seems needed:
104+
#image.invalidate()
102105

103106
try_capture()
104107

0 commit comments

Comments
 (0)