コード例 #1
0
ファイル: remoji.py プロジェクト: andrewhannebrink/Remoji-2.0
def secondsToMinuteStr(seconds):
	minutes = seconds / 60
	extraSeconds = seconds % 60
	minuteStr = movieMaker.getFrameStr(minutes, 2)
	secondStr = movieMaker.getFrameStr(extraSeconds, 2)
	outStr = '00:' + minuteStr + ':' + secondStr + '.00'
	return outStr
コード例 #2
0
def secondsToMinuteStr(seconds):
    minutes = seconds / 60
    extraSeconds = seconds % 60
    minuteStr = movieMaker.getFrameStr(minutes, 2)
    secondStr = movieMaker.getFrameStr(extraSeconds, 2)
    outStr = "00:" + minuteStr + ":" + secondStr + ".00"
    return outStr
コード例 #3
0
ファイル: remoji.py プロジェクト: andrewhannebrink/Remoji-2.0
def secondsToMinuteStr(seconds):
    minutes = seconds / 60
    extraSeconds = seconds % 60
    minuteStr = movieMaker.getFrameStr(minutes, 2)
    secondStr = movieMaker.getFrameStr(extraSeconds, 2)
    outStr = '00:' + minuteStr + ':' + secondStr + '.00'
    return outStr
コード例 #4
0
ファイル: grid.py プロジェクト: andrewhannebrink/Remoji-2.0
 def makeAnim(self, movDir, outputName, frame):
     for i in range(-20, 20):
         self.getImgCells(0.05 * i)
         self.makeImg(movDir + outputName +
                      movieMaker.getFrameStr(frame, 4))
         frame += 1
     return frame
コード例 #5
0
ファイル: remoji.py プロジェクト: andrewhannebrink/Remoji-2.0
def makeLoopsFromFrames(inputDirectory, scale, littleImgs, outputNameStr):
    inputFrameNames = os.listdir(inputDirectory)
    inputFrameNames.sort()
    pool = Pool(processes=4)
    for i in range(0, len(inputFrameNames)):
        d = 0
        for depthPix in range(6, 46, 2):
            dStr = movieMaker.getFrameStr(d, 2) + '_'
            if scale is 'autoScale':
                pool.apply_async(makeMosaic, [
                    inputDirectory + '/' + inputFrameNames[i], scale, depthPix,
                    littleImgs, outputNameStr + dStr +
                    movieMaker.getFrameStr(i, 3) + '.png', 'arbitraryDir/'
                ])
            d += 1
    pool.close()
    pool.join()
コード例 #6
0
def getMosFrames(anims, colorMap, gifMap, frameMap, movDir, outputName, seq, dbFrame, loopFrame, specDirOrder = None, secondsRange = (0, 60)):
	j = loopFrame
	for anim in anims:
		if len(anim) is 6:
			[gifName, lilImgDir, frames, speed, sRes, eRes] = anim
		if len(anim) is 5:
			[gifName, lilImgDir, frames, speed, sRes] = anim
			eRes = sRes
		frames = int(frames)
		speed = int(speed)
		sRes = int(sRes)
		eRes = int(eRes)
		framesPerGif = None
		if gifName in gifMap:
			if mp4Bool == False:
				framesPerGif = gifMap[gifName].totFrames
			else:
				framesPerGif = (secondsRange[1] - secondsRange[0]) * 30
			print 'framesPerGif:i',framesPerGif
		else:
			gifInfo = GifInfo(gifName, mp4Bool, secondsRange)
			gifMap[gifName] = gifInfo
			print 'mp4Bool: ' + str(mp4Bool)
			if mp4Bool == False:
				framesPerGif = gifInfo.totFrames
			else:
				framesPerGif = (secondsRange[1] - secondsRange[0]) * 30
		approxRes = sRes
		approxStep = (eRes - sRes) / (float(frames * speed))
		if specDirOrder != None:
			newAnims = []
			curAnimCounter = 0
			for i in range(0, int(frames)):
				curRes = int(round(approxRes))
				curAnim = anims[curAnimCounter]
				curSpecDir = specDirOrder.pop(0)
				newAnims.append([gifName, curSpecDir, 1, speed, approxRes])
				approxRes += approxStep
					
			# Recursive call to getMosFrames with each anim from newAnims
			[dbFrame, loopFrame] = getMosFrames(newAnims, colorMap, gifMap, frameMap, movDir, outputName, seq, dbFrame, loopFrame, secondsRange = secondsRange)
########
		else:
			for i in range(0, int(frames)):
				for s in range(0, int(speed)):
					curRes = int(round(approxRes))
					dbFrameStr = movieMaker.getFrameStr(dbFrame, 4)
					frameDesc = (gifName, lilImgDir, j % framesPerGif, curRes)
					if frameDesc in frameMap:
						seq.framePaths.append(frameMap[frameDesc])
					else:
						frameMap[frameDesc] = 'unique/' + outputName + dbFrameStr + '.png'
						seq.framePaths.append(frameMap[frameDesc])
						dbFrame += 1
					approxRes += approxStep
				j += 1
	loopFrame = j
	return [dbFrame, loopFrame]
コード例 #7
0
ファイル: grid.py プロジェクト: andrewhannebrink/Remoji-2.0
def loopify(inputDir, outputDir, loops):
	movieMaker.wipeDir(outputDir)
	imgs = os.listdir(inputDir)
	frames = len(imgs)
	for img in imgs:
		for loop in range(0, loops):
			numMatch = re.search('\d+', img)
			num = int(numMatch.group())
			newNum = num + (loop * frames)
			newNumStr = movieMaker.getFrameStr(newNum, 4)
			nameStrMatch = re.search('\D+', img)
			nameStr = nameStrMatch.group()
			os.system('cp ' + inputDir + img + ' ' + outputDir + nameStr + newNumStr + '.png')
コード例 #8
0
ファイル: remoji.py プロジェクト: andrewhannebrink/Remoji-2.0
def makeLoopsFromFrames(inputDirectory, scale, littleImgs, outputNameStr):
	inputFrameNames = os.listdir(inputDirectory)
	inputFrameNames.sort()
	pool = Pool(processes = 4)
	for i in range(0, len(inputFrameNames)):
		d = 0
		for depthPix in range(6,46,2):
			dStr = movieMaker.getFrameStr(d, 2) + '_'
			if scale is 'autoScale':
				pool.apply_async(makeMosaic, [inputDirectory + '/' + inputFrameNames[i], scale, depthPix, littleImgs, outputNameStr + dStr + movieMaker.getFrameStr(i,3) + '.png', 'arbitraryDir/'])
			d += 1
	pool.close()
	pool.join()
コード例 #9
0
ファイル: grid.py プロジェクト: andrewhannebrink/Remoji-2.0
def loopify(inputDir, outputDir, loops):
    movieMaker.wipeDir(outputDir)
    imgs = os.listdir(inputDir)
    frames = len(imgs)
    for img in imgs:
        for loop in range(0, loops):
            numMatch = re.search('\d+', img)
            num = int(numMatch.group())
            newNum = num + (loop * frames)
            newNumStr = movieMaker.getFrameStr(newNum, 4)
            nameStrMatch = re.search('\D+', img)
            nameStr = nameStrMatch.group()
            os.system('cp ' + inputDir + img + ' ' + outputDir + nameStr +
                      newNumStr + '.png')
コード例 #10
0
ファイル: grid.py プロジェクト: andrewhannebrink/Remoji-2.0
def reverseLoop(inputDir, outputDir):
	movieMaker.wipeDir(outputDir)
	imgs = os.listdir(inputDir)
	imgs.sort()
	frames = (len(imgs) * 2) - 1
	for img in imgs:
		numMatch = re.search('\d+', img)
		num = int(numMatch.group())
		newNum = num + frames 
		newNumStr = movieMaker.getFrameStr(newNum, 4)
		nameStrMatch = re.search('\D+', img)
		nameStr = nameStrMatch.group()
		os.system('cp ' + inputDir + img + ' ' + outputDir + img)
		os.system('cp ' + inputDir + img + ' ' + outputDir + nameStr + newNumStr + '.png')	
	#	print 'cp ' + inputDir + img + ' ' + outputDir + nameStr + newNumStr     + '.png'
		frames -= 2
コード例 #11
0
ファイル: grid.py プロジェクト: andrewhannebrink/Remoji-2.0
def reverseLoop(inputDir, outputDir):
    movieMaker.wipeDir(outputDir)
    imgs = os.listdir(inputDir)
    imgs.sort()
    frames = (len(imgs) * 2) - 1
    for img in imgs:
        numMatch = re.search('\d+', img)
        num = int(numMatch.group())
        newNum = num + frames
        newNumStr = movieMaker.getFrameStr(newNum, 4)
        nameStrMatch = re.search('\D+', img)
        nameStr = nameStrMatch.group()
        os.system('cp ' + inputDir + img + ' ' + outputDir + img)
        os.system('cp ' + inputDir + img + ' ' + outputDir + nameStr +
                  newNumStr + '.png')
        #	print 'cp ' + inputDir + img + ' ' + outputDir + nameStr + newNumStr     + '.png'
        frames -= 2
コード例 #12
0
ファイル: remoji.py プロジェクト: andrewhannebrink/Remoji-2.0
def convertGif(inputGifName, framesDB, auto = False):
	longInputGifName = 'gifs/' + inputGifName
	totFrames = movieMaker.getTotFrames(longInputGifName)
	if auto is False:
		for i in range(0, totFrames):
			os.system('convert ' + longInputGifName + '.gif[' + str(i) + '] ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + '.png')
	else:
		for i in range(0, totFrames):
			os.system('convert ' + longInputGifName + '.gif[' + str(i) + '] ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'l.png')
			os.system('convert -flop ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'l.png ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'r.png')
			os.system('convert +append ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'l.png ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'r.png ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + '.png')
			os.system('rm ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'l.png')
			os.system('rm ' + framesDB + inputGifName + movieMaker.getFrameStr(i,3) + 'r.png')
			unCroppedImg = Image.open(framesDB + inputGifName + movieMaker.getFrameStr(i,3) + '.png').convert('RGB')
			[xi, yi] = unCroppedImg.size
			xn = int( (yi*16) / 9.0 )
			xBuf = (xi - xn) / 2
			croppedImg = unCroppedImg.crop((xBuf, 0, xi - xBuf - 1, yi))	
			croppedImg.save(framesDB + inputGifName + movieMaker.getFrameStr(i,3) + '.png')
	return totFrames	
コード例 #13
0
def readFile(instructionsFile, movDir, outputName, colorMap = {}, mp4Bool = False, secondsRange = (0, 60)):
	movieMaker.wipeDir('unique/')
	frameMap = {}
	specMap = {}	# { (PIVOTCOLORS, LEVELSPERPIVOTCOLOR, LILIMGDIR) : SPECTRUMDIR }
#	colorMap = {} 	# { (COLOR TUPLE, LILIMGDIR) : LILIMGPATH }	
	definedSequences = {}
	lilImgMap = {}
	gifMap = {}
	seqOrder = []
	dbFrame = 1
	f = open(instructionsFile)
	frame = 1
	lines = f.readlines()
	curLine = 0
	#EVENTUALLY CHANGE THIS TO ROLLING I VALUE
	while curLine < len(lines):
		lineWords = getWords(lines[curLine])
		if lineWords is None:
			curLine += 1
			continue
		if '#' in lineWords[0]:
			curLine += 1
			continue
		if lineWords[0] == 'Sequence':
			seqLines = []
			seqName = lineWords[1]
			seqType = lineWords[2][1:-1]
			seq = Sequence(seqName)
			#SPECTRUM MODE LINE PARSING
			if seqType == 'spec':
				lilImgDir = ''
				baseDir = lineWords[3]
				loopFrame = int(lineWords[4])
				whiteSquare = False
				if baseDir[-1] == 'w':
					baseDir = baseDir[:-1]
					whiteSquare = True
				anims = []
				j = curLine + 1
				while getWords(lines[j])[0] != 'endSeq':
					seqLines.append(lines[j])
					if '#' in lines[j]:
						curLine += 1
						continue
					j += 1
				seqLines.append(lines[j])
				curSeqLine = 0
				while curSeqLine < len(seqLines):
					s = re.search('^\t{1}\S', seqLines[curSeqLine])
					try:
						match = s.group(0)
					except:
						s = re.search('^\t{2}\S', seqLines[curSeqLine])
						try:
							match = s.group(0)
						except:
							s = re.search('^\t{3}\S', seqLines[curSeqLine])
							try:
								match = s.group(0)
								seqLineWords = getWords(seqLines[curSeqLine])
								if len(seqLineWords) is 4:
									anim = [gifName, lilImgDir, seqLineWords[0], seqLineWords[1], seqLineWords[2], seqLineWords[3]]
									anims.append(anim)
								if len(seqLineWords) is 3:
									anim = [gifName, lilImgDir, seqLineWords[0], seqLineWords[1], seqLineWords[2]]
									anims.append(anim)
							except:
								curSeqLine += 1
								continue
							curSeqLine += 1
							continue 
						gifName = getWords(seqLines[curSeqLine])[0]
						curSeqLine += 1
						continue
					spectrumNums = getNums(seqLines[curSeqLine])
					anims.append(spectrumNums)
					
					curSeqLine += 1
				print 'anims:', anims
				(anims, specDirOrder) = modifySpecAnims(anims, colorMap, whiteSquare, baseDir)
				[dbFrame, loopFrame] = getMosFrames(anims, colorMap, gifMap, frameMap, movDir, outputName, seq, dbFrame, loopFrame, specDirOrder, secondsRange = secondsRange)


			#MOSAIC MODE LINE PARSING
			if seqType == 'mos':
				#ANIMS DESCRIBE SEGMENTS OF THE SEQUENCE
				loopFrame = int(lineWords[3])
				anims = []
				j = curLine + 1
				while getWords(lines[j])[0] != 'endSeq':
					seqLines.append(lines[j])
					if '#' in lines[j]:
						curLine += 1
						continue
					j += 1
				seqLines.append(lines[j]) 
				curSeqLine = 0
				while curSeqLine < len(seqLines):
					#MATCH SINGLE TABBED LINE
					s = re.search('^\t{1}\S', seqLines[curSeqLine])
					try:
						match = s.group(0)
					except:
						#MATCH DOUBLE TABBED LINE
						s = re.search('^\t{2}\S', seqLines[curSeqLine])
						try:
							match = s.group(0)
							seqLineWords = getWords(seqLines[curSeqLine])
							if len(seqLineWords) is 4:
								anim = (gifName, lilImgDir, seqLineWords[0], seqLineWords[1], seqLineWords[2], seqLineWords[3])
								anims.append(anim)
							if len(seqLineWords) is 3:
								anim = (gifName, lilImgDir, seqLineWords[0], seqLineWords[1], seqLineWords[2])
								anims.append(anim)
						except:
							curSeqLine += 1
							continue
						curSeqLine += 1
						continue
					seqLineWords = getWords(seqLines[curSeqLine])
					(gifName, lilImgDir) = (seqLineWords[0], seqLineWords[1])
					print gifName, lilImgDir
					curSeqLine += 1
				[dbFrame, loopFrame] = getMosFrames(anims, colorMap, gifMap, frameMap, movDir, outputName, seq, dbFrame, loopFrame, secondsRange = secondsRange)
			definedSequences[seq.name] = seq
		if lineWords[0] == 'makeAnim':
			j = curLine + 1
			while getWords(lines[j])[0] != 'endAnim':	
				if '#' in lines[j]:
					curLine += 1
					continue
				seqOrder.append(getWords(lines[j])[0])
				j += 1
			frame = 1
			pool = Pool(processes = 4)
			inputFrameNames = []
			print 'making mosaics for ' + str(len(frameMap)) + ' unique frames...'
			for key in frameMap:
				(gifName, lilImgDir, loopFrame, curRes) = key
				if gifName not in gifMap:
					gifInfo = GifInfo(gifName, mp4Bool, secondsRange)
					print 'new gifInfo class'
					gifMap[gifName] = gifInfo
				if lilImgDir not in lilImgMap:
					littleImgs = remoji.getLittleImgs(lilImgDir)
					lilImgMap[lilImgDir] = littleImgs
				else:
					littleImgs = lilImgMap[lilImgDir]
			for key in frameMap:
				(gifName, lilImgDir, loopFrame, curRes) = key
				inputFrameNames = os.listdir(gifMap[gifName].framesDir)
				inputFrameNames.sort()
				depthPix = curRes + 6
				pool.apply_async(remoji.makeMosaic, [gifMap[gifName].framesDir + inputFrameNames[loopFrame], 'autoScale', depthPix, lilImgMap[lilImgDir], frameMap[key], colorMap, lilImgDir])
			pool.close()
			pool.join()

			movieMaker.wipeDir(movDir)
			for seqName in seqOrder:
				seq = definedSequences[seqName]
				for framePath in seq.framePaths:
					frameStr = movieMaker.getFrameStr(frame, 4)
					os.system('cp ' + framePath + ' ' + movDir + outputName + frameStr + '.png')
					frame += 1
			break
		curLine += 1
コード例 #14
0
ファイル: grid.py プロジェクト: andrewhannebrink/Remoji-2.0
	def makeAnim(self, movDir, outputName, frame):
		for i in range(-20, 20):
			self.getImgCells(0.05 * i)
			self.makeImg(movDir + outputName + movieMaker.getFrameStr(frame,4))
			frame += 1
		return frame
コード例 #15
0
ファイル: remoji.py プロジェクト: andrewhannebrink/Remoji-2.0
def convertGif(inputGifName, framesDB, auto=False):
    longInputGifName = 'gifs/' + inputGifName
    totFrames = movieMaker.getTotFrames(longInputGifName)
    if auto is False:
        for i in range(0, totFrames):
            os.system('convert ' + longInputGifName + '.gif[' + str(i) + '] ' +
                      framesDB + inputGifName + movieMaker.getFrameStr(i, 3) +
                      '.png')
    else:
        for i in range(0, totFrames):
            os.system('convert ' + longInputGifName + '.gif[' + str(i) + '] ' +
                      framesDB + inputGifName + movieMaker.getFrameStr(i, 3) +
                      'l.png')
            os.system('convert -flop ' + framesDB + inputGifName +
                      movieMaker.getFrameStr(i, 3) + 'l.png ' + framesDB +
                      inputGifName + movieMaker.getFrameStr(i, 3) + 'r.png')
            os.system('convert +append ' + framesDB + inputGifName +
                      movieMaker.getFrameStr(i, 3) + 'l.png ' + framesDB +
                      inputGifName + movieMaker.getFrameStr(i, 3) + 'r.png ' +
                      framesDB + inputGifName + movieMaker.getFrameStr(i, 3) +
                      '.png')
            os.system('rm ' + framesDB + inputGifName +
                      movieMaker.getFrameStr(i, 3) + 'l.png')
            os.system('rm ' + framesDB + inputGifName +
                      movieMaker.getFrameStr(i, 3) + 'r.png')
            unCroppedImg = Image.open(framesDB + inputGifName +
                                      movieMaker.getFrameStr(i, 3) +
                                      '.png').convert('RGB')
            [xi, yi] = unCroppedImg.size
            xn = int((yi * 16) / 9.0)
            xBuf = (xi - xn) / 2
            croppedImg = unCroppedImg.crop((xBuf, 0, xi - xBuf - 1, yi))
            croppedImg.save(framesDB + inputGifName +
                            movieMaker.getFrameStr(i, 3) + '.png')
    return totFrames
コード例 #16
0
def convertGif(inputGifName, framesDB, auto=False):
    longInputGifName = "gifs/" + inputGifName
    totFrames = movieMaker.getTotFrames(longInputGifName)
    if auto is False:
        for i in range(0, totFrames):
            os.system(
                "convert "
                + longInputGifName
                + ".gif["
                + str(i)
                + "] "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + ".png"
            )
    else:
        for i in range(0, totFrames):
            os.system(
                "convert "
                + longInputGifName
                + ".gif["
                + str(i)
                + "] "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + "l.png"
            )
            os.system(
                "convert -flop "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + "l.png "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + "r.png"
            )
            os.system(
                "convert +append "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + "l.png "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + "r.png "
                + framesDB
                + inputGifName
                + movieMaker.getFrameStr(i, 3)
                + ".png"
            )
            os.system("rm " + framesDB + inputGifName + movieMaker.getFrameStr(i, 3) + "l.png")
            os.system("rm " + framesDB + inputGifName + movieMaker.getFrameStr(i, 3) + "r.png")
            unCroppedImg = Image.open(framesDB + inputGifName + movieMaker.getFrameStr(i, 3) + ".png").convert("RGB")
            [xi, yi] = unCroppedImg.size
            xn = int((yi * 16) / 9.0)
            xBuf = (xi - xn) / 2
            croppedImg = unCroppedImg.crop((xBuf, 0, xi - xBuf - 1, yi))
            croppedImg.save(framesDB + inputGifName + movieMaker.getFrameStr(i, 3) + ".png")
    return totFrames
コード例 #17
0
def getMosFrames(anims,
                 colorMap,
                 gifMap,
                 frameMap,
                 movDir,
                 outputName,
                 seq,
                 dbFrame,
                 loopFrame,
                 specDirOrder=None,
                 secondsRange=(0, 60)):
    #	frame = 1

    #	loopFrame = 0
    j = loopFrame
    for anim in anims:
        if len(anim) is 6:
            #print 'anim: ', anim
            [gifName, lilImgDir, frames, speed, sRes, eRes] = anim
        if len(anim) is 5:
            [gifName, lilImgDir, frames, speed, sRes] = anim
            eRes = sRes
        #print 'frames: ', frames
        frames = int(frames)
        speed = int(speed)
        sRes = int(sRes)
        eRes = int(eRes)
        framesPerGif = None
        #print 'gifMap: ', gifMap
        #print 'gifMap: ', gifMap
        if gifName in gifMap:
            if mp4Bool == False:
                framesPerGif = gifMap[gifName].totFrames
            else:
                framesPerGif = (secondsRange[1] - secondsRange[0]) * 30
            print 'framesPerGif:i', framesPerGif
        else:
            gifInfo = GifInfo(gifName, mp4Bool, secondsRange)
            gifMap[gifName] = gifInfo
            print 'mp4Bool: ' + str(mp4Bool)
            if mp4Bool == False:
                framesPerGif = gifInfo.totFrames
            else:
                framesPerGif = (secondsRange[1] - secondsRange[0]) * 30
        approxRes = sRes
        approxStep = (eRes - sRes) / (float(frames * speed))
        if specDirOrder != None:
            #print 'specDirOrder:', specDirOrder
            #print 'len(specDirOrder):', len(specDirOrder)
            # newAnims is a longer version of anims to account for increased directory changes in (spec) mode
            newAnims = []
            curAnimCounter = 0
            for i in range(0, int(frames)):
                curRes = int(round(approxRes))
                curAnim = anims[curAnimCounter]
                #print 'curAnim:', curAnim
                curSpecDir = specDirOrder.pop(0)
                newAnims.append([gifName, curSpecDir, 1, speed, approxRes])
                approxRes += approxStep

            # Recursive call to getMosFrames with each anim from newAnims
            [dbFrame, loopFrame] = getMosFrames(newAnims,
                                                colorMap,
                                                gifMap,
                                                frameMap,
                                                movDir,
                                                outputName,
                                                seq,
                                                dbFrame,
                                                loopFrame,
                                                secondsRange=secondsRange)
########
        else:
            for i in range(0, int(frames)):
                for s in range(0, int(speed)):
                    curRes = int(round(approxRes))
                    dbFrameStr = movieMaker.getFrameStr(dbFrame, 4)
                    print dbFrameStr
                    frameDesc = (gifName, lilImgDir, j % framesPerGif, curRes)
                    if frameDesc in frameMap:
                        print 'appending ', frameDesc, 'to frameMap'
                        seq.framePaths.append(frameMap[frameDesc])
                        #print frameDesc, ' already in frameMap'
                    else:
                        frameMap[
                            frameDesc] = 'unique/' + outputName + dbFrameStr + '.png'
                        #print frameDesc, ':', frameMap[frameDesc]
                        seq.framePaths.append(frameMap[frameDesc])
                        dbFrame += 1
                    approxRes += approxStep
                j += 1
    loopFrame = j
    return [dbFrame, loopFrame]
コード例 #18
0
def getMosFrames(anims, colorMap, gifMap, frameMap, movDir, outputName, seq, dbFrame, loopFrame, specDirOrder = None, secondsRange = (0, 60)):
#	frame = 1	
	
#	loopFrame = 0
	j = loopFrame
	for anim in anims:
		if len(anim) is 6:
			#print 'anim: ', anim
			[gifName, lilImgDir, frames, speed, sRes, eRes] = anim
		if len(anim) is 5:
			[gifName, lilImgDir, frames, speed, sRes] = anim
			eRes = sRes
		#print 'frames: ', frames
		frames = int(frames)
		speed = int(speed)
		sRes = int(sRes)
		eRes = int(eRes)
		framesPerGif = None
		#print 'gifMap: ', gifMap
		#print 'gifMap: ', gifMap
		if gifName in gifMap:
			if mp4Bool == False:
				framesPerGif = gifMap[gifName].totFrames
			else:
				framesPerGif = (secondsRange[1] - secondsRange[0]) * 30
			print 'framesPerGif:i',framesPerGif
		else:
			gifInfo = GifInfo(gifName, mp4Bool, secondsRange)
			gifMap[gifName] = gifInfo
			print 'mp4Bool: ' + str(mp4Bool)
			if mp4Bool == False:
				framesPerGif = gifInfo.totFrames
			else:
				framesPerGif = (secondsRange[1] - secondsRange[0]) * 30
		approxRes = sRes
		approxStep = (eRes - sRes) / (float(frames * speed))
		if specDirOrder != None:
			#print 'specDirOrder:', specDirOrder
			#print 'len(specDirOrder):', len(specDirOrder)
			# newAnims is a longer version of anims to account for increased directory changes in (spec) mode
			newAnims = []
			curAnimCounter = 0
			for i in range(0, int(frames)):
				curRes = int(round(approxRes))
				curAnim = anims[curAnimCounter]
				#print 'curAnim:', curAnim
				curSpecDir = specDirOrder.pop(0)
				newAnims.append([gifName, curSpecDir, 1, speed, approxRes])
				approxRes += approxStep
					
			# Recursive call to getMosFrames with each anim from newAnims
			[dbFrame, loopFrame] = getMosFrames(newAnims, colorMap, gifMap, frameMap, movDir, outputName, seq, dbFrame, loopFrame, secondsRange = secondsRange)
########
		else:
			for i in range(0, int(frames)):
				for s in range(0, int(speed)):
					curRes = int(round(approxRes))
					dbFrameStr = movieMaker.getFrameStr(dbFrame, 4)
					print dbFrameStr
					frameDesc = (gifName, lilImgDir, j % framesPerGif, curRes)
					if frameDesc in frameMap:
						print 'appending ', frameDesc, 'to frameMap'
						seq.framePaths.append(frameMap[frameDesc])
						#print frameDesc, ' already in frameMap'
					else:
						frameMap[frameDesc] = 'unique/' + outputName + dbFrameStr + '.png'
						#print frameDesc, ':', frameMap[frameDesc]
						seq.framePaths.append(frameMap[frameDesc])
						dbFrame += 1
					approxRes += approxStep
				j += 1
	loopFrame = j
	return [dbFrame, loopFrame]
コード例 #19
0
def readFile(instructionsFile,
             movDir,
             outputName,
             colorMap={},
             mp4Bool=False,
             secondsRange=(0, 60)):
    movieMaker.wipeDir('unique/')
    frameMap = {}
    specMap = {
    }  # { (PIVOTCOLORS, LEVELSPERPIVOTCOLOR, LILIMGDIR) : SPECTRUMDIR }
    #	colorMap = {} 	# { (COLOR TUPLE, LILIMGDIR) : LILIMGPATH }
    definedSequences = {}
    lilImgMap = {}
    gifMap = {}
    seqOrder = []
    dbFrame = 1
    f = open(instructionsFile)
    frame = 1
    lines = f.readlines()
    curLine = 0
    #EVENTUALLY CHANGE THIS TO ROLLING I VALUE
    while curLine < len(lines):
        lineWords = getWords(lines[curLine])
        if lineWords is None:
            curLine += 1
            continue
        if '#' in lineWords[0]:
            curLine += 1
            continue
        if lineWords[0] == 'Sequence':
            seqLines = []
            seqName = lineWords[1]
            seqType = lineWords[2][1:-1]
            seq = Sequence(seqName)
            #SPECTRUM MODE LINE PARSING
            if seqType == 'spec':
                lilImgDir = ''
                baseDir = lineWords[3]
                #print lineWords
                loopFrame = int(lineWords[4])
                whiteSquare = False
                if baseDir[-1] == 'w':
                    baseDir = baseDir[:-1]
                    whiteSquare = True
                anims = []
                j = curLine + 1
                while getWords(lines[j])[0] != 'endSeq':
                    seqLines.append(lines[j])
                    if '#' in lines[j]:
                        curLine += 1
                        continue
                    j += 1
                seqLines.append(lines[j])
                curSeqLine = 0
                while curSeqLine < len(seqLines):
                    s = re.search('^\t{1}\S', seqLines[curSeqLine])
                    try:
                        match = s.group(0)
                    except:
                        s = re.search('^\t{2}\S', seqLines[curSeqLine])
                        try:
                            match = s.group(0)
                        except:
                            s = re.search('^\t{3}\S', seqLines[curSeqLine])
                            try:
                                match = s.group(0)
                                seqLineWords = getWords(seqLines[curSeqLine])
                                if len(seqLineWords) is 4:
                                    anim = [
                                        gifName, lilImgDir, seqLineWords[0],
                                        seqLineWords[1], seqLineWords[2],
                                        seqLineWords[3]
                                    ]
                                    #print anim
                                    anims.append(anim)
                                if len(seqLineWords) is 3:
                                    anim = [
                                        gifName, lilImgDir, seqLineWords[0],
                                        seqLineWords[1], seqLineWords[2]
                                    ]
                                    anims.append(anim)
                            except:
                                curSeqLine += 1
                                continue
                            curSeqLine += 1
                            continue
                        gifName = getWords(seqLines[curSeqLine])[0]
                        curSeqLine += 1
                        continue
                    spectrumNums = getNums(seqLines[curSeqLine])
                    anims.append(spectrumNums)

                    curSeqLine += 1
                print 'anims:', anims
                (anims,
                 specDirOrder) = modifySpecAnims(anims, colorMap, whiteSquare,
                                                 baseDir)
                #print 'anims:',anims
                #print 'len(anims):',len(anims)
                #print 'specDirOrder:',specDirOrder
                #print 'len(specDirOrder):',len(specDirOrder)
                [dbFrame, loopFrame] = getMosFrames(anims,
                                                    colorMap,
                                                    gifMap,
                                                    frameMap,
                                                    movDir,
                                                    outputName,
                                                    seq,
                                                    dbFrame,
                                                    loopFrame,
                                                    specDirOrder,
                                                    secondsRange=secondsRange)

            #MOSAIC MODE LINE PARSING
            if seqType == 'mos':
                #ANIMS DESCRIBE SEGMENTS OF THE SEQUENCE
                loopFrame = int(lineWords[3])
                anims = []
                j = curLine + 1
                while getWords(lines[j])[0] != 'endSeq':
                    seqLines.append(lines[j])
                    if '#' in lines[j]:
                        curLine += 1
                        continue
                    j += 1
#				print seqLines
                seqLines.append(lines[j])
                curSeqLine = 0
                while curSeqLine < len(seqLines):
                    #print 'seqLines[curSeqLines]:', seqLines[curSeqLine]
                    #MATCH SINGLE TABBED LINE
                    s = re.search('^\t{1}\S', seqLines[curSeqLine])
                    try:
                        match = s.group(0)
                    except:
                        #MATCH DOUBLE TABBED LINE
                        s = re.search('^\t{2}\S', seqLines[curSeqLine])
                        try:
                            match = s.group(0)
                            seqLineWords = getWords(seqLines[curSeqLine])
                            if len(seqLineWords) is 4:
                                anim = (gifName, lilImgDir, seqLineWords[0],
                                        seqLineWords[1], seqLineWords[2],
                                        seqLineWords[3])
                                anims.append(anim)
                            if len(seqLineWords) is 3:
                                anim = (gifName, lilImgDir, seqLineWords[0],
                                        seqLineWords[1], seqLineWords[2])
                                anims.append(anim)
                        except:
                            curSeqLine += 1
                            continue
                        curSeqLine += 1
                        continue
        #			print 'match: ',match
                    seqLineWords = getWords(seqLines[curSeqLine])
                    (gifName, lilImgDir) = (seqLineWords[0], seqLineWords[1])
                    #print 'gifName, lilImgDir): ', (gifName, lilImgDir)
                    curSeqLine += 1
                [dbFrame, loopFrame] = getMosFrames(anims,
                                                    colorMap,
                                                    gifMap,
                                                    frameMap,
                                                    movDir,
                                                    outputName,
                                                    seq,
                                                    dbFrame,
                                                    loopFrame,
                                                    secondsRange=secondsRange)
            definedSequences[seq.name] = seq
        if lineWords[0] == 'makeAnim':
            j = curLine + 1
            while getWords(lines[j])[0] != 'endAnim':
                if '#' in lines[j]:
                    curLine += 1
                    continue
                seqOrder.append(getWords(lines[j])[0])
                j += 1
            #print seqOrder
            frame = 1
            pool = Pool(processes=4)
            inputFrameNames = []
            #			print frameMap[('tunnel2', 'animalmini2/', 1, 17)]
            print 'making mosaics for ' + str(
                len(frameMap)) + ' unique frames...'
            for key in frameMap:
                #print 'key: ', key
                #print 'frameMap[key]: ', frameMap[key]
                (gifName, lilImgDir, loopFrame, curRes) = key
                if gifName not in gifMap:
                    gifInfo = GifInfo(gifName, mp4Bool, secondsRange)
                    print 'new gifInfo class'
                    gifMap[gifName] = gifInfo
                if lilImgDir not in lilImgMap:
                    #print lilImgDir
                    littleImgs = remoji.getLittleImgs(lilImgDir)
                    lilImgMap[lilImgDir] = littleImgs
                else:
                    littleImgs = lilImgMap[lilImgDir]
#			littleImgs = remoji.getLittleImgs(lilImgDir)
            for key in frameMap:
                (gifName, lilImgDir, loopFrame, curRes) = key
                inputFrameNames = os.listdir(gifMap[gifName].framesDir)
                inputFrameNames.sort()
                depthPix = curRes + 6
                #				print  ['unique/' + inputFrameNames[loopFrame], 'autoScale', depthPix, littleImgs, frameMap[key], 'arbitraryDir/']
                #print 'lilImgMap:,',lilImgMap
                #remoji.makeMosaic(gifMap[gifName].framesDir + inputFrameNames[loopFrame], 'autoScale', depthPix, lilImgMap[lilImgDir], frameMap[key], colorMap, lilImgDir, 'arbitraryDir/')
                #print gifMap[gifName]
                #print inputFrameNames
                #print loopFrame
                #print inputFrameNames[loopFrame]

                #print lilImgMap[lilImgDir]
                #print frameMap[key]
                pool.apply_async(remoji.makeMosaic, [
                    gifMap[gifName].framesDir + inputFrameNames[loopFrame],
                    'autoScale', depthPix, lilImgMap[lilImgDir], frameMap[key],
                    colorMap, lilImgDir
                ])
            pool.close()
            pool.join()

            movieMaker.wipeDir(movDir)
            for seqName in seqOrder:
                seq = definedSequences[seqName]
                for framePath in seq.framePaths:
                    frameStr = movieMaker.getFrameStr(frame, 4)
                    os.system('cp ' + framePath + ' ' + movDir + outputName +
                              frameStr + '.png')
                    frame += 1
            break
        curLine += 1