Skip to content

fix skewed PNG images caused by 'memoryview' bitmap filling #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Oct 20, 2024
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f33b92a
fix PNG images wider than 128 bits
RetiredWizard Oct 7, 2024
3938d4c
apply #74 workaround to all 8 bit mode 3 images
RetiredWizard Oct 10, 2024
204d8b0
Use memoryview for bitmap widths that it works for
RetiredWizard Oct 10, 2024
949ff2d
remove portion of workaround for resolved bug
RetiredWizard Oct 10, 2024
7713689
workaround still needed for all 4 bit or less images
RetiredWizard Oct 10, 2024
42cfb2b
Identified issue with memoryview copy, only 4bit and less need workar…
RetiredWizard Oct 10, 2024
dde5d39
pre-commit formatting
RetiredWizard Oct 10, 2024
296bacd
Use work around for <8 depth for now
RetiredWizard Oct 10, 2024
f931aee
comment fix
RetiredWizard Oct 10, 2024
9637b47
finally, remove workaround code
RetiredWizard Oct 10, 2024
82c0841
workaound left in as comments for documentation
RetiredWizard Oct 10, 2024
c23d736
Use workaround for older versions of CircuitPython
RetiredWizard Oct 11, 2024
20d7a15
pre-commit formatting
RetiredWizard Oct 11, 2024
1b6ebf7
move import for pre-commmit
RetiredWizard Oct 11, 2024
12f4cdc
minor speed up when using workaround code
RetiredWizard Oct 11, 2024
392007c
speed optimizations
RetiredWizard Oct 11, 2024
c491b81
one more minor optimization
RetiredWizard Oct 11, 2024
3dbc21d
I even ran pre-commit this time....
RetiredWizard Oct 11, 2024
d22ccf5
deshipus optimization
RetiredWizard Oct 15, 2024
66fa04d
Move workaround comment to top of workaround
RetiredWizard Oct 15, 2024
872e181
Remove memoryview copy method
RetiredWizard Oct 15, 2024
0132c78
remove memoryview adjust variable
RetiredWizard Oct 15, 2024
bd38609
remove sys.implementation import
RetiredWizard Oct 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions adafruit_imageload/png.py
Original file line number Diff line number Diff line change
@@ -103,26 +103,20 @@ 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
src = 1
src_b = 1
pixmask = (1 << depth) - 1
for y in range(height):
dst = y * scanline
src = y * (scanline + 1) + 1
if depth < 8:
# Work around the bug in displayio.Bitmap
# https://github.com/adafruit/circuitpython/issues/6675
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]
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