Giter Club home page Giter Club logo

png-parser's People

Contributors

hedroed avatar voidtwo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

png-parser's Issues

Not working in Python 3.10

PS C:\Windows\System32> png-parser
Traceback (most recent call last):
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\Scripts\png-parser-script.py", line 33, in <module>
    sys.exit(load_entry_point('png-parser==2.0.0', 'console_scripts', 'png-parser')())
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\Scripts\png-parser-script.py", line 25, in importlib_load_entry_point
    return next(matches).load()
  File "C:\Program Files\Python310\lib\importlib\metadata\__init__.py", line 162, in load
    module = import_module(match.group('module'))
  File "C:\Program Files\Python310\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 992, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\__init__.py", line 1, in <module>
    from .png import PngParser, PNG_MAGIC_NUMBER
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\png.py", line 9, in <module>
    from .chunks import create_chunk, ChunkRaw
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\chunks\__init__.py", line 6, in <module>
    from .ihdr import ChunkIHDR
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\chunks\ihdr.py", line 3, in <module>
    from ..utils import pixel_type_to_length
  File "C:\Users\Anton\AppData\Roaming\Python\Python310\site-packages\pngparser\utils.py", line 30, in <module>
    class BitArray(collections.Iterator):
AttributeError: module 'collections' has no attribute 'Iterator'

Fail with pal2/pal4/rgb48 images

I tried png-parser with pal2/pal4/rgb48 images:

pngparser -v -s test.png

... and they all fail. There are mainly 3 problems.


For all images, scanline_width is incorrect, so each scanline read is either too short or too long.

# line_width = pixel_count_in_line * bytes_count_by_pixel + the_filter_byte
line_width = self.header.width * self.header.pixel_len
logging.debug('%d bytes per scanline', line_width)

Guess it should be like:

# line_width_bit = pixel_count_per_line * components_per_pixel * bit_per_component
line_width_bit = self.header.width * self.header.pixel_len * self.header.bit_depth
# line_width = round_up(line_width_bit / 8) + the_filter_byte
line_width = (line_width_bit + 7) // 8 + 1

i.e. include bit_per_component(actually self.header.bit_depth) in calculation.

(I suggest renaming pixel_len to component_count, but it's also a little weird: paletted images can have more than 1 component, so maybe a better name?)


For pal2/pal4 images, it failed to convert index to pixel.

if self.palette:
pixels = [self.palette[i] for i in row]

The correct way is:

if self.palette:
    bit_depth = self.header.bit_depth  # bit count per sample
    pixels = [self.palette[i] for i in BitArray(row, bit_depth)]

For rgb48 images, it failed to scale pixel value to 0~255 range when displaying.

for val in BitArray(row, bit_depth):
if bit_depth != 8:
# shrink value between 0 and 255
val = val * (2**bit_depth - 1)
px.append(val)

With rgb48, bit_depth is 16, i.e. val in range(0, 65536).
So val should be divided by 256, or be shifted 8 bits to the right:

if bit_depth > 8:
    # shrink value between 0 and 255
    val = val >> (bit_depth - 8)

I can craft a PR for these issues, but I'm not sure about the wording problem. Anyone has an idea?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.