@@ -709,7 +709,7 @@ class MSSImage(object):
709709 '''
710710
711711 def __init__ (self , data = None , width = 1 , height = 1 ):
712- if self . data is None :
712+ if data is None :
713713 raise ValueError ('MSSImage: no data to process.' )
714714 elif width < 1 or height < 1 :
715715 raise ValueError ('MSSImage: width or height must be positive.' )
@@ -725,31 +725,31 @@ def dump(self, output):
725725 http://inaps.org/journal/comment-fonctionne-le-png
726726 '''
727727
728- to_take = (self .width * 3 + 3 ) & - 4
729- padding = 0 if to_take % 8 == 0 else (to_take % 8 ) // 2
730- height , data = self .height , self .data
731- scanlines = [b'' .join ([b'0' , data [to_take * y :to_take * y + to_take - padding ]]) for y in range (height )]
732-
733- magic = pack (b'>8B' , 137 , 80 , 78 , 71 , 13 , 10 , 26 , 10 )
734-
735- # Header: size, marker, data, CRC32
736- ihdr = [b'' , b'IHDR' , b'' , b'' ]
737- ihdr [2 ] = pack (b'>2I5B' , self .width , self .height , 8 , 2 , 0 , 0 , 0 )
738- ihdr [3 ] = pack (b'>I' , zlib .crc32 (b'' .join (ihdr [1 :3 ])) & 0xffffffff )
739- ihdr [0 ] = pack (b'>I' , len (ihdr [2 ]))
740-
741- # Data: size, marker, data, CRC32
742- idat = [b'' , b'IDAT' , b'' , b'' ]
743- idat [2 ] = zlib .compress (b'' .join (scanlines ), 9 )
744- idat [3 ] = pack (b'>I' , zlib .crc32 (b'' .join (idat [1 :3 ])) & 0xffffffff )
745- idat [0 ] = pack (b'>I' , len (idat [2 ]))
746-
747- # Footer: size, marker, None, CRC32
748- iend = [b'' , b'IEND' , b'' , b'' ]
749- iend [3 ] = pack (b'>I' , zlib .crc32 (iend [1 ]) & 0xffffffff )
750- iend [0 ] = pack (b'>I' , len (iend [2 ]))
751-
752728 with open (output , 'wb' ) as fileh :
729+ to_take = (self .width * 3 + 3 ) & - 4
730+ padding = 0 if to_take % 8 == 0 else (to_take % 8 ) // 2
731+ height , data = self .height , self .data
732+ scanlines = [b'' .join ([b'0' , data [to_take * y :to_take * y + to_take - padding ]]) for y in range (height )]
733+
734+ magic = pack (b'>8B' , 137 , 80 , 78 , 71 , 13 , 10 , 26 , 10 )
735+
736+ # Header: size, marker, data, CRC32
737+ ihdr = [b'' , b'IHDR' , b'' , b'' ]
738+ ihdr [2 ] = pack (b'>2I5B' , self .width , self .height , 8 , 2 , 0 , 0 , 0 )
739+ ihdr [3 ] = pack (b'>I' , zlib .crc32 (b'' .join (ihdr [1 :3 ])) & 0xffffffff )
740+ ihdr [0 ] = pack (b'>I' , len (ihdr [2 ]))
741+
742+ # Data: size, marker, data, CRC32
743+ idat = [b'' , b'IDAT' , b'' , b'' ]
744+ idat [2 ] = zlib .compress (b'' .join (scanlines ), 9 )
745+ idat [3 ] = pack (b'>I' , zlib .crc32 (b'' .join (idat [1 :3 ])) & 0xffffffff )
746+ idat [0 ] = pack (b'>I' , len (idat [2 ]))
747+
748+ # Footer: size, marker, None, CRC32
749+ iend = [b'' , b'IEND' , b'' , b'' ]
750+ iend [3 ] = pack (b'>I' , zlib .crc32 (iend [1 ]) & 0xffffffff )
751+ iend [0 ] = pack (b'>I' , len (iend [2 ]))
752+
753753 fileh .write (magic + b'' .join (ihdr ) + b'' .join (idat ) + b'' .join (iend ))
754754 return output
755755 return None
0 commit comments