From f33b92a9612a7ccbeaec72b43eecc24bf1cb51c3 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Mon, 7 Oct 2024 19:30:54 -0400 Subject: [PATCH 01/23] fix PNG images wider than 128 bits --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 84867b9..a78936c 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -110,7 +110,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements for y in range(height): dst = y * scanline src = y * (scanline + 1) + 1 - if depth < 8: + if depth < 8 or width > 128: # Work around the bug in displayio.Bitmap # https://github.com/adafruit/circuitpython/issues/6675 pixels_per_byte = 8 // depth From 3938d4ca91679eb3f5bd427fef5fba9314566785 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Wed, 9 Oct 2024 22:17:01 -0400 Subject: [PATCH 02/23] apply #74 workaround to all 8 bit mode 3 images --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index a78936c..d110938 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -110,7 +110,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements for y in range(height): dst = y * scanline src = y * (scanline + 1) + 1 - if depth < 8 or width > 128: + if depth <= 8: # Work around the bug in displayio.Bitmap # https://github.com/adafruit/circuitpython/issues/6675 pixels_per_byte = 8 // depth From 204d8b09759059ff5a8bac65f85e5747f739a8fd Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 01:16:27 -0400 Subject: [PATCH 03/23] Use memoryview for bitmap widths that it works for --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index d110938..e911287 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -110,7 +110,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements for y in range(height): dst = y * scanline src = y * (scanline + 1) + 1 - if depth <= 8: + if depth < 8 or (depth == 8 and width % 4 != 0): # Work around the bug in displayio.Bitmap # https://github.com/adafruit/circuitpython/issues/6675 pixels_per_byte = 8 // depth From 949ff2dbc081aab509f6137e6ab7925ae939642c Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 01:44:46 -0400 Subject: [PATCH 04/23] remove portion of workaround for resolved bug --- adafruit_imageload/png.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index e911287..1c5f323 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -110,9 +110,11 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements for y in range(height): dst = y * scanline src = y * (scanline + 1) + 1 - if depth < 8 or (depth == 8 and width % 4 != 0): - # Work around the bug in displayio.Bitmap + if width % 4 != 0: + # Work around the bugs in displayio.Bitmap + # The first should have been resolved by #9479 # https://github.com/adafruit/circuitpython/issues/6675 + # https://github.com/adafruit/circuitpython/issues/9707 pixels_per_byte = 8 // depth for x in range(0, width, pixels_per_byte): byte = data_bytes[src] From 77136895d68d0cac7f97550c0a93d18824b3e50a Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 02:40:05 -0400 Subject: [PATCH 05/23] workaround still needed for all 4 bit or less images --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 1c5f323..68a8d8e 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -110,7 +110,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements for y in range(height): dst = y * scanline src = y * (scanline + 1) + 1 - if width % 4 != 0: + if depth < 5 or width % 4 != 0: # Work around the bugs in displayio.Bitmap # The first should have been resolved by #9479 # https://github.com/adafruit/circuitpython/issues/6675 From 42cfb2b693d7951216914628706a36a295e4902e Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 03:15:28 -0400 Subject: [PATCH 06/23] Identified issue with memoryview copy, only 4bit and less need workaround now --- adafruit_imageload/png.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 68a8d8e..094b962 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -108,9 +108,11 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements bmp = bitmap(width, height, colors) mem = memoryview(bmp) for y in range(height): - dst = y * scanline + # Adjust for Displayio.Bitmap filler to scanline at byte boundry + filladj = (y * ((4 - (width % 4)) % 4)) + dst = y * scanline + filladj src = y * (scanline + 1) + 1 - if depth < 5 or width % 4 != 0: + if depth < 5: # Work around the bugs in displayio.Bitmap # The first should have been resolved by #9479 # https://github.com/adafruit/circuitpython/issues/6675 From dde5d395276ff935d7b65860bcb7ab4432024627 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 03:27:03 -0400 Subject: [PATCH 07/23] pre-commit formatting --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 094b962..d4e8c2d 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -109,7 +109,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements mem = memoryview(bmp) for y in range(height): # Adjust for Displayio.Bitmap filler to scanline at byte boundry - filladj = (y * ((4 - (width % 4)) % 4)) + filladj = y * ((4 - (width % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 if depth < 5: From 296bacd6771849dae5f6c428b72d0597f965fc40 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 03:58:40 -0400 Subject: [PATCH 08/23] Use work around for <8 depth for now --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index d4e8c2d..83e2d36 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -112,7 +112,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements filladj = y * ((4 - (width % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 - if depth < 5: + if depth < 8: # Work around the bugs in displayio.Bitmap # The first should have been resolved by #9479 # https://github.com/adafruit/circuitpython/issues/6675 From f931aeefe2fec715dc55e25d8f2afd60d611084f Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 04:00:11 -0400 Subject: [PATCH 09/23] comment fix --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 83e2d36..0156ee3 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -108,7 +108,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements bmp = bitmap(width, height, colors) mem = memoryview(bmp) for y in range(height): - # Adjust for Displayio.Bitmap filler to scanline at byte boundry + # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry filladj = y * ((4 - (width % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 From 9637b47b847e28436277733f336efd964dd3841b Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 04:20:07 -0400 Subject: [PATCH 10/23] finally, remove workaround code --- adafruit_imageload/png.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 0156ee3..b4d73cd 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -109,24 +109,10 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements mem = memoryview(bmp) for y in range(height): # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry - filladj = y * ((4 - (width % 4)) % 4) + filladj = y * ((4 - (scanline % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 - if depth < 8: - # Work around the bugs in displayio.Bitmap - # The first should have been resolved by #9479 - # https://github.com/adafruit/circuitpython/issues/6675 - # https://github.com/adafruit/circuitpython/issues/9707 - pixels_per_byte = 8 // depth - for x in range(0, width, pixels_per_byte): - byte = data_bytes[src] - for pixel in range(pixels_per_byte): - bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & ( - (1 << depth) - 1 - ) - src += 1 - else: - mem[dst : dst + scanline] = data_bytes[src : src + scanline] + mem[dst : dst + scanline] = data_bytes[src : src + scanline] return bmp, pal # RGB, RGBA or Grayscale import displayio From 82c08417986b0c20771a44399a5ad894020c1552 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 12:24:14 -0400 Subject: [PATCH 11/23] workaound left in as comments for documentation --- adafruit_imageload/png.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index b4d73cd..5cf9d54 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -112,6 +112,21 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements filladj = y * ((4 - (scanline % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 + # Work around the bug in displayio.Bitmap - removed afer resolution + # however left here as comments because it's helpful in + # understanding the memoryview scanline and adjustment calculations + # https://github.com/adafruit/circuitpython/issues/6675 + # https://github.com/adafruit/circuitpython/issues/9707 + # + # pixels_per_byte = 8 // depth + # for x in range(0, width, pixels_per_byte): + # byte = data_bytes[src] + # for pixel in range(pixels_per_byte): + # bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & ( + # (1 << depth) - 1 + # ) + # src += 1 + # mem[dst : dst + scanline] = data_bytes[src : src + scanline] return bmp, pal # RGB, RGBA or Grayscale From c23d7364eddb666b69193bd94c0993543aa1e5b5 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 22:25:23 -0400 Subject: [PATCH 12/23] Use workaround for older versions of CircuitPython --- adafruit_imageload/png.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 5cf9d54..8d36fbc 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -25,6 +25,7 @@ except ImportError: pass +from sys import implementation import struct import zlib @@ -112,22 +113,23 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements filladj = y * ((4 - (scanline % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 - # Work around the bug in displayio.Bitmap - removed afer resolution - # however left here as comments because it's helpful in - # understanding the memoryview scanline and adjustment calculations + # Work around the bug in displayio.Bitmap + # remove once CircuitPython 9.1 is no longer supported # https://github.com/adafruit/circuitpython/issues/6675 # https://github.com/adafruit/circuitpython/issues/9707 - # - # pixels_per_byte = 8 // depth - # for x in range(0, width, pixels_per_byte): - # byte = data_bytes[src] - # for pixel in range(pixels_per_byte): - # bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & ( - # (1 << depth) - 1 - # ) - # src += 1 - # - mem[dst : dst + scanline] = data_bytes[src : src + scanline] + if ((implementation[1][0] == 9 and implementation[1][1] < 2) or + implementation[1][0] < 9) and (depth < 8 or width % 4 != 0): + + pixels_per_byte = 8 // depth + for x in range(0, width, pixels_per_byte): + byte = data_bytes[src] + for pixel in range(pixels_per_byte): + bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & ( + (1 << depth) - 1 + ) + src += 1 + else: + mem[dst : dst + scanline] = data_bytes[src : src + scanline] return bmp, pal # RGB, RGBA or Grayscale import displayio From 20d7a15655eb4f563edda7c2e67e47680e60a6fb Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 22:28:43 -0400 Subject: [PATCH 13/23] pre-commit formatting --- adafruit_imageload/png.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 8d36fbc..1854e04 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -117,9 +117,9 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements # remove once CircuitPython 9.1 is no longer supported # https://github.com/adafruit/circuitpython/issues/6675 # https://github.com/adafruit/circuitpython/issues/9707 - if ((implementation[1][0] == 9 and implementation[1][1] < 2) or - implementation[1][0] < 9) and (depth < 8 or width % 4 != 0): - + if ( + (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 + ) and (depth < 8 or width % 4 != 0): pixels_per_byte = 8 // depth for x in range(0, width, pixels_per_byte): byte = data_bytes[src] From 1b6ebf7e0928f3f0ec0fd2c2abc20646029adbf9 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Thu, 10 Oct 2024 22:32:59 -0400 Subject: [PATCH 14/23] move import for pre-commmit --- adafruit_imageload/png.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 1854e04..7374f92 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -25,9 +25,9 @@ except ImportError: pass -from sys import implementation import struct import zlib +from sys import implementation __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git" @@ -113,13 +113,13 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements filladj = y * ((4 - (scanline % 4)) % 4) dst = y * scanline + filladj src = y * (scanline + 1) + 1 - # Work around the bug in displayio.Bitmap - # remove once CircuitPython 9.1 is no longer supported - # https://github.com/adafruit/circuitpython/issues/6675 - # https://github.com/adafruit/circuitpython/issues/9707 if ( (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 ) and (depth < 8 or width % 4 != 0): + # Work around the bug in displayio.Bitmap + # remove once CircuitPython 9.1 is no longer supported + # https://github.com/adafruit/circuitpython/issues/6675 + # https://github.com/adafruit/circuitpython/issues/9707 pixels_per_byte = 8 // depth for x in range(0, width, pixels_per_byte): byte = data_bytes[src] From 12f4cdccf9f13c9647e1e06acb77c55f95ebb132 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Fri, 11 Oct 2024 00:19:26 -0400 Subject: [PATCH 15/23] minor speed up when using workaround code --- adafruit_imageload/png.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 7374f92..6be3650 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -109,9 +109,6 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements bmp = bitmap(width, height, colors) mem = memoryview(bmp) for y in range(height): - # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry - filladj = y * ((4 - (scanline % 4)) % 4) - dst = y * scanline + filladj src = y * (scanline + 1) + 1 if ( (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 @@ -129,6 +126,9 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements ) src += 1 else: + # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry + filladj = y * ((4 - (scanline % 4)) % 4) + dst = y * scanline + filladj mem[dst : dst + scanline] = data_bytes[src : src + scanline] return bmp, pal # RGB, RGBA or Grayscale From 392007ca6b6921eb351a3e478d4dbe3b07dc01fa Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Fri, 11 Oct 2024 02:21:37 -0400 Subject: [PATCH 16/23] speed optimizations --- adafruit_imageload/png.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 6be3650..2c2f387 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -108,8 +108,13 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements if mode == 3: # indexed bmp = bitmap(width, height, colors) mem = memoryview(bmp) + pixels_per_byte = 8 // depth + # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry + filladj = (4 - (scanline % 4)) % 4 + dst = 0 + src = 1 + src_b = 1 for y in range(height): - src = y * (scanline + 1) + 1 if ( (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 ) and (depth < 8 or width % 4 != 0): @@ -117,19 +122,18 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements # remove once CircuitPython 9.1 is no longer supported # https://github.com/adafruit/circuitpython/issues/6675 # https://github.com/adafruit/circuitpython/issues/9707 - pixels_per_byte = 8 // depth for x in range(0, width, pixels_per_byte): - byte = data_bytes[src] + byte = data_bytes[src_b] for pixel in range(pixels_per_byte): bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & ( (1 << depth) - 1 ) - src += 1 + src_b += 1 else: - # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry - filladj = y * ((4 - (scanline % 4)) % 4) - dst = y * scanline + filladj mem[dst : dst + scanline] = data_bytes[src : src + scanline] + dst += scanline + filladj + src += scanline + 1 + src_b = src return bmp, pal # RGB, RGBA or Grayscale import displayio From c491b815814c2885311150aff9edac0b564d20a5 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Fri, 11 Oct 2024 02:26:10 -0400 Subject: [PATCH 17/23] one more minor optimization --- adafruit_imageload/png.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 2c2f387..b31a88f 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -114,10 +114,15 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements dst = 0 src = 1 src_b = 1 + if ( + (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 + ) and (depth < 8 or width % 4 != 0): + workaround = True + else: + workaround = False + for y in range(height): - if ( - (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 - ) and (depth < 8 or width % 4 != 0): + if (workaround): # Work around the bug in displayio.Bitmap # remove once CircuitPython 9.1 is no longer supported # https://github.com/adafruit/circuitpython/issues/6675 From 3dbc21df315be6ceb7c15d3f3efe43dd945cce2f Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Fri, 11 Oct 2024 02:32:51 -0400 Subject: [PATCH 18/23] I even ran pre-commit this time.... --- adafruit_imageload/png.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index b31a88f..d4f9c70 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -122,7 +122,7 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements workaround = False for y in range(height): - if (workaround): + if workaround: # Work around the bug in displayio.Bitmap # remove once CircuitPython 9.1 is no longer supported # https://github.com/adafruit/circuitpython/issues/6675 From d22ccf5431ed29762347b77d6b29c7ab9589a0ee Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Mon, 14 Oct 2024 22:47:21 -0400 Subject: [PATCH 19/23] deshipus optimization --- adafruit_imageload/png.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index d4f9c70..0f85bd6 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -111,18 +111,12 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements pixels_per_byte = 8 // depth # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry filladj = (4 - (scanline % 4)) % 4 - dst = 0 src = 1 - src_b = 1 if ( (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 ) and (depth < 8 or width % 4 != 0): - workaround = True - else: - workaround = False - - for y in range(height): - if workaround: + src_b = 1 + for y in range(height): # Work around the bug in displayio.Bitmap # remove once CircuitPython 9.1 is no longer supported # https://github.com/adafruit/circuitpython/issues/6675 @@ -134,11 +128,14 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements (1 << depth) - 1 ) src_b += 1 - else: + src += scanline + 1 + src_b = src + else: + dst = 0 + for y in range(height): mem[dst : dst + scanline] = data_bytes[src : src + scanline] dst += scanline + filladj - src += scanline + 1 - src_b = src + src += scanline + 1 return bmp, pal # RGB, RGBA or Grayscale import displayio From 66fa04d45b0c3b2f7657d48bfbaef6a8ef006026 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Mon, 14 Oct 2024 22:54:12 -0400 Subject: [PATCH 20/23] Move workaround comment to top of workaround --- adafruit_imageload/png.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 0f85bd6..72a6e0a 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -115,12 +115,12 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements if ( (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 ) and (depth < 8 or width % 4 != 0): + # Work around the bug in displayio.Bitmap + # remove once CircuitPython 9.1 is no longer supported + # https://github.com/adafruit/circuitpython/issues/6675 + # https://github.com/adafruit/circuitpython/issues/9707 src_b = 1 for y in range(height): - # Work around the bug in displayio.Bitmap - # remove once CircuitPython 9.1 is no longer supported - # https://github.com/adafruit/circuitpython/issues/6675 - # https://github.com/adafruit/circuitpython/issues/9707 for x in range(0, width, pixels_per_byte): byte = data_bytes[src_b] for pixel in range(pixels_per_byte): From 872e1819bdd2cbb7d12f2ad0f388a2f4420eeda0 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 15 Oct 2024 01:46:18 -0400 Subject: [PATCH 21/23] Remove memoryview copy method --- adafruit_imageload/png.py | 38 +++++++++++--------------------------- 1 file changed, 11 insertions(+), 27 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 72a6e0a..31fda8a 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -104,38 +104,22 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements data_bytes = zlib.decompress(data) unit = (1, 0, 3, 1, 2, 0, 4)[mode] scanline = (width * depth * unit + 7) // 8 - colors = 1 << (depth * unit) if mode == 3: # indexed - bmp = bitmap(width, height, colors) - mem = memoryview(bmp) + bmp = bitmap(width, height, 1 << depth) pixels_per_byte = 8 // depth # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry filladj = (4 - (scanline % 4)) % 4 src = 1 - if ( - (implementation[1][0] == 9 and implementation[1][1] < 2) or implementation[1][0] < 9 - ) and (depth < 8 or width % 4 != 0): - # Work around the bug in displayio.Bitmap - # remove once CircuitPython 9.1 is no longer supported - # https://github.com/adafruit/circuitpython/issues/6675 - # https://github.com/adafruit/circuitpython/issues/9707 - src_b = 1 - for y in range(height): - for x in range(0, width, pixels_per_byte): - byte = data_bytes[src_b] - for pixel in range(pixels_per_byte): - bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & ( - (1 << depth) - 1 - ) - src_b += 1 - src += scanline + 1 - src_b = src - else: - dst = 0 - for y in range(height): - mem[dst : dst + scanline] = data_bytes[src : src + scanline] - dst += scanline + filladj - src += scanline + 1 + src_b = 1 + pixmask = (1 << depth) - 1 + for y in range(height): + for x in range(0, width, pixels_per_byte): + byte = data_bytes[src_b] + for pixel in range(pixels_per_byte): + bmp[x + pixel, y] = (byte >> ((pixels_per_byte - pixel - 1) * depth)) & pixmask + src_b += 1 + src += scanline + 1 + src_b = src return bmp, pal # RGB, RGBA or Grayscale import displayio From 0132c78b7af36f20aad60b44b0c2925c9f7e6b83 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 15 Oct 2024 01:51:57 -0400 Subject: [PATCH 22/23] remove memoryview adjust variable --- adafruit_imageload/png.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index 31fda8a..d08956e 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -107,8 +107,6 @@ def load( # noqa: PLR0912, PLR0915, Too many branches, Too many statements if mode == 3: # indexed bmp = bitmap(width, height, 1 << depth) pixels_per_byte = 8 // depth - # Adjust for Displayio.Bitmap filler to scanline at 4-byte boundry - filladj = (4 - (scanline % 4)) % 4 src = 1 src_b = 1 pixmask = (1 << depth) - 1 From bd38609c670fe8aca5e8a7e009c6a79365c0beb6 Mon Sep 17 00:00:00 2001 From: RetiredWizard Date: Tue, 15 Oct 2024 15:42:39 -0400 Subject: [PATCH 23/23] remove sys.implementation import --- adafruit_imageload/png.py | 1 - 1 file changed, 1 deletion(-) diff --git a/adafruit_imageload/png.py b/adafruit_imageload/png.py index d08956e..89a9ded 100644 --- a/adafruit_imageload/png.py +++ b/adafruit_imageload/png.py @@ -27,7 +27,6 @@ import struct import zlib -from sys import implementation __version__ = "0.0.0-auto.0" __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git"