Code de-clutter

This commit is contained in:
MassiveBox 2025-11-17 22:11:23 +01:00
parent e82ecadbb3
commit 1e267dbdb6
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
4 changed files with 6 additions and 21 deletions

View file

@ -66,27 +66,21 @@ def convert_to_gicisky_bytes(img: Image.Image, model: ModelId, lum_threshold: in
Returns:
bytes: Processed image data in Gicisky format
"""
# Get device specifications
specs = DEVICE_SPECS.get(model)
if not specs:
raise ValueError("Unknown model")
width, height = specs.size
# Resize image to device dimensions
img = img.convert("RGB").resize((width, height), Image.Resampling.LANCZOS)
# Apply TFT transformation if enabled
if specs.tft:
# Resize to half width and double height
img = img.resize((width // 2, height * 2), Image.Resampling.LANCZOS)
width, height = img.size
# Apply mirroring if enabled
if specs.mirror:
img = img.transpose(Image.FLIP_TOP_BOTTOM)
# Convert to numpy array
arr = np.array(img)
# Process pixels - column-major order
@ -99,7 +93,6 @@ def convert_to_gicisky_bytes(img: Image.Image, model: ModelId, lum_threshold: in
r, g, b = arr[y, x] # Note: numpy uses [y, x] indexing
luminance = 0.2126 * r + 0.7152 * g + 0.0722 * b
# Apply thresholding based on compression setting
if specs.compression:
# When compression is enabled, dark pixels set bits
if luminance < lum_threshold:
@ -125,7 +118,6 @@ def convert_to_gicisky_bytes(img: Image.Image, model: ModelId, lum_threshold: in
byte_data.append(current_byte)
red_byte_data.append(current_red_byte)
# Apply compression if enabled
if specs.compression:
byte_data_compressed = _apply_compression(byte_data, red_byte_data, width, height, specs.second_color)
else:
@ -156,7 +148,6 @@ def _apply_compression(byte_data: List[int], red_byte_data: List[int],
byte_per_line = height // 8
current_pos = 0
# Process black/white data
for i in range(width):
# Add line header
byte_data_compressed.extend([