Skip to content

Commit b2d8815

Browse files
author
BoboTiG
committed
MSS: fix errors from pngcheck tool
1 parent 93e2f4c commit b2d8815

3 files changed

Lines changed: 11 additions & 2 deletions

File tree

doc/CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ devel 201y/mm/dd
88
- prevent export of MSS* classes in case of "from mss import *"
99
- MSS: rename save_img() to to_png()
1010
- MSS: optimization of to_png()
11+
- MSS: to_png() generate valid PNG files
1112
- MSSLinux: prevent segfault when DISPLAY is set but no X server started
1213
- MSSLinux: get_pixels() insanely fast, use of MSS library (C code)
1314
- MSSWindows: get_pixels() insanely fast

doc/QUALITY

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ codespell doc/*
1212

1313
# Dry run
1414
python setup.py check
15+
16+
# Check generated PNG
17+
pngcheck -c *.png

mss.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,16 +204,21 @@ def to_png(self, data, width, height, output):
204204
ihdr[2] = b(b'>2I5B', width, height, 8, 2, 0, 0, 0)
205205
ihdr[3] = b(b'>I', crc32(b''.join(ihdr[1:3])) & 0xffffffff)
206206
ihdr[0] = b(b'>I', len(ihdr[2]))
207+
ihdr = b''.join(ihdr)
207208

208209
# Data: size, marker, data, CRC32
209210
idat = [b'', b'IDAT', compress(scanlines), b'']
210211
idat[3] = b(b'>I', crc32(b''.join(idat[1:3])) & 0xffffffff)
211212
idat[0] = b(b'>I', len(idat[2]))
213+
idat = b''.join(idat)
212214

213215
# Footer: size, marker, None, CRC32
214-
iend = b'4IEND'
216+
iend = [b'', b'IEND', b'', b'']
217+
iend[3] = b(b'>I', crc32(b''.join(iend[1:3])) & 0xffffffff)
218+
iend[0] = b(b'>I', len(iend[2]))
219+
iend = b''.join(iend)
215220

216-
fileh.write(magic + b''.join(ihdr) + b''.join(idat) + iend)
221+
fileh.write(magic + ihdr + idat + iend)
217222
return
218223

219224
err = 'MSS: error writing data to "{0}".'.format(output)

0 commit comments

Comments
 (0)