|
26 | 26 | - remove 'ext' argument, using only PNG |
27 | 27 | - do not overwrite existing image files |
28 | 28 | - few optimizations into MSSLinux::get_pixels() |
| 29 | + - few optimizations into MSSImage::png() |
29 | 30 |
|
30 | 31 | You can always get the latest version of this module at: |
31 | 32 |
|
@@ -749,27 +750,22 @@ def png(self): |
749 | 750 | http://inaps.org/journal/comment-fonctionne-le-png |
750 | 751 | ''' |
751 | 752 |
|
752 | | - width, height, data = self.width, self.height, self.data |
753 | | - to_take = (width * 3 + 3) & -4 |
| 753 | + to_take = (self.width * 3 + 3) & -4 |
754 | 754 | padding = 0 if to_take % 8 == 0 else (to_take % 8) // 2 |
755 | | - offset = 0 |
756 | | - scanlines = b'' |
757 | | - |
758 | | - for y in range(height): |
759 | | - scanlines += b'0' + data[offset:offset+to_take-padding] |
760 | | - offset += to_take |
| 755 | + height, data = self.height, self.data |
| 756 | + scanlines = [b''.join([b'0', data[to_take*y:to_take*y+to_take-padding]]) for y in range(height)] |
761 | 757 |
|
762 | 758 | magic = pack(b'>8B', 137, 80, 78, 71, 13, 10, 26, 10) |
763 | 759 |
|
764 | 760 | # Header: size, marker, data, CRC32 |
765 | 761 | ihdr = [b'', b'IHDR', b'', b''] |
766 | | - ihdr[2] = pack(b'>2I5B', width, height, 8, 2, 0, 0, 0) |
| 762 | + ihdr[2] = pack(b'>2I5B', self.width, self.height, 8, 2, 0, 0, 0) |
767 | 763 | ihdr[3] = pack(b'>I', zlib.crc32(b''.join(ihdr[1:3])) & 0xffffffff) |
768 | 764 | ihdr[0] = pack(b'>I', len(ihdr[2])) |
769 | 765 |
|
770 | 766 | # Data: size, marker, data, CRC32 |
771 | 767 | idat = [b'', b'IDAT', b'', b''] |
772 | | - idat[2] = zlib.compress(scanlines, 9) |
| 768 | + idat[2] = zlib.compress(b''.join(scanlines), 9) |
773 | 769 | idat[3] = pack(b'>I', zlib.crc32(b''.join(idat[1:3])) & 0xffffffff) |
774 | 770 | idat[0] = pack(b'>I', len(idat[2])) |
775 | 771 |
|
|
0 commit comments