@@ -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+ def extract_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+ return width , height , color_format .upper ()
188+
178189 def show_image (self , name ):
179190 try :
180191 self .label .set_text (name )
181192 if name .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+ if color_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- except Exception as e :
218+ except OSError as e :
204219 print (f"show_image got exception: { e } " )
205220
206221 def scale_image (self ):
0 commit comments