From 4da329385f27a0fc6eb587f1beef629c93124388 Mon Sep 17 00:00:00 2001 From: Duncan Mundell Date: Fri, 8 Nov 2024 07:28:17 -0700 Subject: [PATCH] fix: Addressing depreceation of PIL.PyAccess in ImageToLPBM --- g13gui.geany | 45 +++++++++++++++++++++++++++++++++++++ g13gui/g13/displaydevice.py | 33 +++++++++++++++------------ 2 files changed, 64 insertions(+), 14 deletions(-) create mode 100644 g13gui.geany diff --git a/g13gui.geany b/g13gui.geany new file mode 100644 index 0000000..e2c63a4 --- /dev/null +++ b/g13gui.geany @@ -0,0 +1,45 @@ +[editor] +line_wrapping=false +line_break_column=72 +auto_continue_multiline=true + +[file_prefs] +final_new_line=true +ensure_convert_new_lines=false +strip_trailing_spaces=false +replace_tabs=false + +[indentation] +indent_width=4 +indent_type=0 +indent_hard_tab_width=8 +detect_indent=false +detect_indent_width=true +indent_mode=2 + +[project] +name=g13gui +base_path=/home/duncan/projects/g13gui +description= +file_patterns= + +[long line marker] +long_line_behaviour=1 +long_line_column=72 + +[files] +current_page=0 +FILE_NAME_0=1386;Python;0;EUTF-8;1;1;0;%2Fhome%2Fduncan%2Fprojects%2Fg13gui%2Fg13gui%2Fg13%2Fdisplaydevice.py;0;4 + +[VTE] +last_dir=/home/duncan + +[prjorg] +expanded_paths=/home/duncan/projects/g13gui/g13gui/g13; +source_patterns=*.c;*.C;*.cpp;*.cxx;*.c++;*.cc;*.m; +header_patterns=*.h;*.H;*.hpp;*.hxx;*.h++;*.hh; +ignored_dirs_patterns=.*;CVS; +ignored_file_patterns=*.o;*.obj;*.a;*.lib;*.so;*.dll;*.lo;*.la;*.class;*.jar;*.pyc;*.mo;*.gmo; +generate_tag_prefs=0 +show_empty_dirs=true +external_dirs= diff --git a/g13gui/g13/displaydevice.py b/g13gui/g13/displaydevice.py index 69e8564..496cee9 100644 --- a/g13gui/g13/displaydevice.py +++ b/g13gui/g13/displaydevice.py @@ -11,31 +11,36 @@ class DisplayMetrics(object): def ImageToLPBM(image): - """Simple function to convert a PIL Image into LPBM format.""" - - i = PIL.PyAccess.new(image, readonly=True) + #Simple function to convert a PIL Image into LPBM format. + + # Ensure the image is in grayscale ('L') or monochrome ('1') mode + image = image.convert('1') # Convert to monochrome (1-bit) if not already + pixels = image.load() # Access the pixel data directly bio = BytesIO() - - maxBytes = (DisplayMetrics.WIDTH_PIXELS * - DisplayMetrics.HEIGHT_PIXELS // 8) + + # Assuming DisplayMetrics with fixed width and height + maxBytes = (DisplayMetrics.WIDTH_PIXELS * DisplayMetrics.HEIGHT_PIXELS) // 8 + row = 0 col = 0 for byteNum in range(0, maxBytes): - b = int() + b = 0 - if row == 40: - maxSubrow = 3 - else: - maxSubrow = 8 + # Adjust the number of rows processed in a byte based on row position + maxSubrow = 3 if row == 40 else 8 - for subrow in range(0, maxSubrow): - b |= i[col, row + subrow] << subrow + for subrow in range(maxSubrow): + # Get pixel value at (col, row + subrow) and shift into position + pixel_value = pixels[col, row + subrow] + b |= (1 if pixel_value == 0 else 0) << subrow # 0 = black, 1 = white in '1' mode + # Write the byte to the output buffer bio.write(struct.pack('