Skip to content
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

some Indexed BMP Images look corrupted #8734

Closed
carson-coder opened this issue Dec 20, 2023 · 12 comments
Closed

some Indexed BMP Images look corrupted #8734

carson-coder opened this issue Dec 20, 2023 · 12 comments
Labels

Comments

@carson-coder
Copy link

carson-coder commented Dec 20, 2023

CircuitPython version

Adafruit CircuitPython 9.0.0-alpha.6 on 2023-12-12; Adafruit Matrix Portal M4 with samd51j19

Code/REPL

import board
import displayio
import framebufferio
import rgbmatrix

displayio.release_displays() # Release current display, we'll create our own

# Create RGB matrix object for a chain of four 64x32 matrices tiled into
# a single 128x64 pixel display -- two matrices across, two down, with the
# second row being flipped. width and height args are the combined size of
# all the tiled sub-matrices. tile arg is the number of rows of matrices in
# the chain (horizontal tiling is implicit from the width argument, doesn't
# need to be specified, but vertical tiling must be explicitly stated).
# The serpentine argument indicates whether alternate rows are flipped --
# cabling is easier this way, downside is colors may be slightly different
# when viewed off-angle. bit_depth and pins are same as other examples.
MATRIX = rgbmatrix.RGBMatrix(
    width=128, height=64, bit_depth=6, tile=2, serpentine=True,
    rgb_pins=[board.MTX_R1,
              board.MTX_G1,
              board.MTX_B1,
              board.MTX_R2,
              board.MTX_G2,
              board.MTX_B2],
    addr_pins=[board.MTX_ADDRA,
               board.MTX_ADDRB,
               board.MTX_ADDRC,
               board.MTX_ADDRD],
    clock_pin=board.MTX_CLK, latch_pin=board.MTX_LAT,
    output_enable_pin=board.MTX_OE)

# Associate matrix with a Display to use displayio features
DISPLAY = framebufferio.FramebufferDisplay(MATRIX, auto_refresh=False,
                                           rotation=0)

# Load BMP image, create Group and TileGrid to hold it
FILENAME = "/code/team0_logos/NYJ.bmp"

# CircuitPython 6 & 7 compatible
BITMAP = displayio.OnDiskBitmap(open(FILENAME, "rb"))
TILEGRID = displayio.TileGrid(
    BITMAP,
    pixel_shader=getattr(BITMAP, 'pixel_shader', displayio.ColorConverter()),
    tile_width=BITMAP.width,
    tile_height=BITMAP.height
)

# # CircuitPython 7+ compatible
# BITMAP = displayio.OnDiskBitmap(FILENAME)
# TILEGRID = displayio.TileGrid(
#     BITMAP,
#     pixel_shader=BITMAP.pixel_shader,
#     tile_width=BITMAP.width,
#     tile_height=BITMAP.height
# )

GROUP = displayio.Group()
GROUP.append(TILEGRID)
DISPLAY.root_group = GROUP
DISPLAY.refresh()

# Nothing interactive, just hold the image there
while True:
    pass

Behavior

Images look corrupted / weird (look at uploaded file)
img

Description

Only happens with some bitmap files. Maybe because the bitmaps palette index 0 is while and 255 is black?

Additional information

I was messing around with my own build of circuit python and discovered that it looks like `displayio_convert_color' treats the color as a rgb332 color because colorspace.depth is 8 right. Or would it be 24.
I have 4 displays running and the code is running as a .mpy file from a sd card

Here is the bmp I used.
NYJ.bmp.zip

Here is all the bmp files that don't work
Bitmaps.zip

And this bitmap works
wales.bmp.zip

@dhalbert
Copy link
Collaborator

dhalbert commented Dec 20, 2023

Could you please include the .bmp in your report, not using file.io, which is only temporary? If you can't upload a .bmp, zip it up and upload it and add that as a file. See "Paste, drop, or click to add files" below the post editing box.

Also maybe include a file that is working. If you have more than one which looks wrong, include that too.

@carson-coder
Copy link
Author

Ok I will edit the post

@dhalbert
Copy link
Collaborator

BTW, identify -verbose NYJ.bmp and similar gives you all kind of info about the file, including its indexed colormap. identify is from ImageMagick.

@carson-coder
Copy link
Author

I made a python script to take a indexed bmp image and output a picture as if that bmp was rgb332 and this is what it got
picture
so its not just thinking the image is rgb332

@carson-coder
Copy link
Author

carson-coder commented Dec 20, 2023

BTW, identify -verbose NYJ.bmp and similar gives you all kind of info about the file, including its indexed colormap. identify is from ImageMagick.

[removed by @dhalbert due to size]

@dhalbert
Copy link
Collaborator

I reproduced your problem on a single panel with the Matrix Portal S3 (I can't find my Matrix Portal M4 at the moment).

I saw a similarly corrupted image. However, when I read the file into GIMP and then export it as .bmp again, with no changes, it displays properly:
NYJ1.bmp.zip
Try that.
The indexed palette as described by identify -verbose is exactly the same. However, there are these differences. The Compression difference might be the significant one. The new file is just slightly larger.

image

@dhalbert
Copy link
Collaborator

I tested with 8.2.9 and 9.0.0-alpha.6: no difference. BTW, you can also use the # # CircuitPython 7+ compatible code in the example instead of the older code, but both work.

@dhalbert
Copy link
Collaborator

This is also helpful: https://www.metadata2go.com/. Note that the size is 946 for NYJ.bmp, and it's RLE, and NYJ1.bmp is None, and the size is 1024. It seems like there's a misinterpretation of RLE for some reason for these files. Did you make them exactly according to the recipe in the scoreboard guide?

@dhalbert
Copy link
Collaborator

OK, this looks like #7450, which reports the same thing. We should complain about compressed files but we're not checking carefully enough.

@carson-coder
Copy link
Author

Thank you. Is there a way to decompress the images in python/bash. I have a lot of image that need to be decompressed.

@dhalbert
Copy link
Collaborator

On the command line:
convert NYJ.bmp -compress None NYJ-uncompressed.bmp

@carson-coder
Copy link
Author

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants