1.1 released, comes with damaged flag

This commit is contained in:
Niles Rogoff 2017-02-04 19:57:56 -05:00
parent 5f77ef9d94
commit 3e8fc078db
No known key found for this signature in database
GPG Key ID: B78B908F23430F80
5 changed files with 20 additions and 10 deletions

0
.gitignore vendored Normal file → Executable file
View File

23
libpme.py Normal file → Executable file
View File

@ -3,34 +3,39 @@
# Niles Rogoff 2016
import zlib, copy
class color_types(object):
GREYSCALE = 0
RGB = 2
PALETTE = 3
GREYSCALE_WITH_ALPHA = 4
RGB_WITH_ALPHA = 6
GREYSCALE = 0
RGB = 2
PALETTE = 3
GREYSCALE_WITH_ALPHA = 4
RGB_WITH_ALPHA = 6
class PME(object):
def _assert(self, statement):
if not self._damaged:
assert(statement)
def _int(self, binary):
return int.from_bytes(binary, byteorder="big")
def _bytes(self, integer, length):
return integer.to_bytes(length, "big")
def __init__(self, filename=False):
def __init__(self, filename=False, damaged=False):
self._damaged = damaged
self._init = False
self._magic_number = b'\x89PNG\r\n\x1a\n'
self.filename = filename
self.chunks = []
if filename:
f = open(self.filename, "rb")
assert(f.read(8) == self._magic_number)
self._assert(f.read(8) == self._magic_number)
while True:
length = f.read(4)
label = f.read(4)
data = f.read(self._int(length))
crc = f.read(4)
self._verify_crc(label, data, crc)
if not self._damaged:
self._verify_crc(label, data, crc)
self.chunks.append([length, label, data, crc])
if label == b"IEND":
break
assert(self.chunks[0][1] == b"IHDR")
self._assert(self.chunks[0][1] == b"IHDR")
self.recalculate_properties()
else:
self.chunks = [

5
readme.md Normal file → Executable file
View File

@ -128,3 +128,8 @@ In this example, we will draw a red sine wave on a new 100x100 file
The output should look something like this:
![](http://i.imgur.com/vfa6lOR.png)
## Changelog
### 1.1
Added the damaged argument to the constructor. If damaged is set to true, it will allow you to open potentially damaged png files, which maybe don't have IDAT as the first chunk, or have invalid CRCs

0
setup.cfg Normal file → Executable file
View File

View File

@ -1,7 +1,7 @@
#from distutils.core import setup
from setuptools import setup
setup(name='libpme',
version='1.0',
version='1.1',
description="PNG metadata editor library",
author="Niles Rogoff",
author_email="me@niles.xyz",