From 4e490db1841230ca3aae759450c249797a453f54 Mon Sep 17 00:00:00 2001 From: wyntrr-end <66278138+wyntrr-end@users.noreply.github.com> Date: Sat, 31 Oct 2020 20:33:18 -0500 Subject: [PATCH] add option to upscale frames during export includes optional command line flag and modified help text --- PPM.py | 55 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/PPM.py b/PPM.py index 07db982..d405dd3 100755 --- a/PPM.py +++ b/PPM.py @@ -589,25 +589,26 @@ class TMB: # Designed to work with PPM().Thumbnail or PPM().GetFrame(n) # # This function requires the PIl imaging module -def WriteImage(image, outputPath): +def WriteImage(image, outputPath, scale=1): if not hasPIL: print "Error: PIL not found!" return False #if not image: return False - - out = image.tostring("F") - - # out = [] - # for y in xrange(len(image[0])): - # for x in xrange(len(image)): - # out.append(DecAsc(image[x][y], 4)) - - out = Image.frombytes("RGBA", (len(image), len(image[0])), out) + + # Upscale the image by the scale factor so each original pixel is + # represented by a n-by-n-pixel square in the larger version. + # Any number 1 or smaller is just treated as a scale factor of 1. + if scale > 1: + newImg = np.repeat(np.repeat(image, scale, axis = 0), scale, axis = 1) + else: + newImg = image + + out = newImg.tostring("F") + out = Image.frombytes("RGBA", (len(newImg), len(newImg[0])), out) filetype = outputPath[outputPath.rfind(".")+1:] out.save(outputPath, filetype) - return True def get_metadata(flipnote): @@ -634,10 +635,10 @@ def get_metadata(flipnote): return meta -def DumpFrames(flipnote,directory): +def DumpFrames(flipnote,directory,scale=1): for i in xrange(flipnote.FrameCount): - print "Dumping frame #%i..." % (i+1), - WriteImage(flipnote.GetFrame(i), os.path.join(directory, "frame %s.png" % str(i+1).zfill(3))) + print "Dumping frame #%i of %i..." % (i+1, flipnote.FrameCount) + WriteImage(flipnote.GetFrame(i), os.path.join(directory, "frame %s.png" % str(i+1).zfill(3)), scale) def DumpSoundFiles(flipnote,directory,raw=False): for i, data in enumerate(flipnote.SoundData): @@ -663,7 +664,7 @@ if __name__ == '__main__': if len(sys.argv) < 3: print "Usage:" - print " PPM.py [] []" + print " PPM.py [] [] [