Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc5088b7

Browse files
Image viewer: support .raw camera captures
1 parent4489f10 commitc5088b7

File tree

2 files changed

+25
-10
lines changed
  • internal_filesystem/apps

2 files changed

+25
-10
lines changed

‎internal_filesystem/apps/com.micropythonos.camera/assets/camera.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ def snap_button_click(self, e):
177177
exceptOSError:
178178
pass
179179
ifself.current_cam_bufferisnotNone:
180-
filename=f"data/images/camera_capture_{mpos.time.epoch_seconds()}.raw"
180+
filename=f"data/images/camera_capture_{mpos.time.epoch_seconds()}_{self.width}x{self.height}_RGB565.raw"
181181
try:
182182
withopen(filename,'wb')asf:
183183
f.write(self.current_cam_buffer)

‎internal_filesystem/apps/com.micropythonos.imageview/assets/imageview.py‎

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -175,32 +175,47 @@ def show_next_image(self, event=None):
175175
print(f"show_next_image showing{name}")
176176
self.show_image(name)
177177

178+
defextract_dimensions_and_format(self,filename):
179+
# Split the filename by '_'
180+
parts=filename.split('_')
181+
# Get the color format (last part before '.raw')
182+
color_format=parts[-1].split('.')[0]# e.g., "RGB565"
183+
# Get the resolution (second-to-last part)
184+
resolution=parts[-2]# e.g., "240x240"
185+
# Split resolution by 'x' to get width and height
186+
width,height=map(int,resolution.split('x'))
187+
returnwidth,height,color_format.upper()
188+
178189
defshow_image(self,name):
179190
try:
180191
self.label.set_text(name)
181192
ifname.endswith(".raw"):
182193
f=open(name,'rb')
183194
image_data=f.read()
184-
print(f"loaded{len(image_data)} bytes")
195+
print(f"loaded{len(image_data)} bytes from .raw file")
185196
f.close()
186-
w=240
187-
h=240
197+
width,height,color_format=self.extract_dimensions_and_format(name)
198+
print(f"Raw image has width:{width}, Height:{height}, Color Format:{color_format}")
199+
stride=width*2
200+
cf=lv.COLOR_FORMAT.RGB565
201+
ifcolor_format!="RGB565":
202+
print(f"WARNING: unknown color format{color_format}, assuming RGB565...")
188203
image_dsc=lv.image_dsc_t({
189204
"header": {
190205
"magic":lv.IMAGE_HEADER_MAGIC,
191-
"w":w,
192-
"h":h,
193-
"stride":w*2,
194-
"cf":lv.COLOR_FORMAT.RGB565
206+
"w":width,
207+
"h":height,
208+
"stride":stride,
209+
"cf":cf
195210
},
196-
'data_size':w*h*2,
211+
'data_size':len(image_data),
197212
'data':image_data
198213
})
199214
self.image.set_src(image_dsc)
200215
else:
201216
self.image.set_src(f"M:{name}")
202217
self.scale_image()
203-
exceptExceptionase:
218+
exceptOSErrorase:
204219
print(f"show_image got exception:{e}")
205220

206221
defscale_image(self):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp