Skip to content

encode_raw_image crashes with simple 32 x 32 image of single color #8

Description

@gpk-code

When generating a 32 x 32 image of a single color and using it with encode_raw_image like in the following code:

from PIL import Image
from pixoo import PixooMax
#-----------------------------------------------------------------------------------------------------------------------
img = Image.new( "RGB", ( 32, 32 ), ( 255, 0, 0 ) )
img.show()

p = PixooMax( "11:75:58:FA:E5:3C" )
p.encode_raw_image( img )

The method crashes with the following error:

Traceback (most recent call last):
  File "Test.py", line 8, in <module>
    p.encode_raw_image( img )
  File "pixoo.py", line 294, in encode_raw_image
    encoded_data = [int(c, 2) for c in encoded_pixels]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "pixoo.py", line 294, in <listcomp>
    encoded_data = [int(c, 2) for c in encoded_pixels]
                    ^^^^^^^^^
ValueError: invalid literal for int() with base 2: ''

I have pinpointed the cause of the error to be due to the wrong operator used in line 290 of pixoo.py:

      # Encode pixel data
      while len(encoded_byte) >= 8:
        encoded_pixels.append(encoded_byte[-8:])
        encoded_byte = encoded_byte[:-8]

The following code should instead be:

      # Encode pixel data
      while len(encoded_byte) > 8:
        encoded_pixels.append(encoded_byte[-8:])
        encoded_byte = encoded_byte[:-8]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions