예제 #1
0
	def __init__(self, name, mp4Bool, secondsRange):
		self.name = name
		self.framesDir = name + 'frames/'
		movieMaker.wipeDir(self.framesDir)
		if mp4Bool == False:
			self.totFrames = remoji.convertGif(name, self.framesDir, auto = True)
		else:
			print 'totFrames getting created here'
			self.totFrames = remoji.convertMp4(name, self.framesDir, secondsRange, auto = False)
	def copyImgsToDir(self, directory):
		movieMaker.wipeDir(directory)
		#print len(self.imgs)
		if self.whiteSquare == True:
			img = Image.new('RGB', (64, 64),'white')
			img.save(directory + 'white.png')
		for img in self.imgs:
			#print 'cp ' + self.lilImgDir + img + ' ' + directory + img
			os.system('cp ' + self.lilImgDir + img + ' ' + directory + img)
예제 #3
0
 def copyImgsToDir(self, directory):
     movieMaker.wipeDir(directory)
     #print len(self.imgs)
     if self.whiteSquare == True:
         img = Image.new('RGB', (64, 64), 'white')
         img.save(directory + 'white.png')
     for img in self.imgs:
         #print 'cp ' + self.lilImgDir + img + ' ' + directory + img
         os.system('cp ' + self.lilImgDir + img + ' ' + directory + img)
예제 #4
0
 def __init__(self, name, mp4Bool, secondsRange):
     self.name = name
     self.framesDir = name + 'frames/'
     movieMaker.wipeDir(self.framesDir)
     if mp4Bool == False:
         self.totFrames = remoji.convertGif(name, self.framesDir, auto=True)
     else:
         print 'totFrames getting created here'
         self.totFrames = remoji.convertMp4(name,
                                            self.framesDir,
                                            secondsRange,
                                            auto=False)
예제 #5
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')
예제 #6
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')
예제 #7
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
예제 #8
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
	def __init__(self, name, mp4Bool, secondsRange):
		self.name = name
		self.framesDir = name + 'frames/'
		#print os.listdir('.')
		if mp4Bool == False:
			self.totFrames = remoji.convertGif(name, self.framesDir, auto = True)
		else:
			if self.framesDir[:-1] in os.listdir('.'):
				print 'found ' + self.framesDir + ', not wiping'
				self.totFrames = remoji.convertMp4(name, self.framesDir, secondsRange, auto = True)
			else:
				movieMaker.wipeDir(self.framesDir)
				print 'wiping ' + self.framesDir
				self.totFrames = remoji.convertMp4(name, self.framesDir, secondsRange, auto = False)
			print 'totFrames getting created here'
			print 'secondsRange = ' + str(secondsRange)
			print 'totFrames = '  + str(self.totFrames)
def makeRandomLilImgDirs(lilImgDir, totDirs, leastTotImgs, mostTotImgs = None):
	movieMaker.wipeDir('randomdirs/')
	littleImgNames = os.listdir(lilImgDir)
	if mostTotImgs == None:
		mostTotImgs = leastTotImgs
	for i in range(totDirs):
		newDirName = 'r' + str(i) + '/'
		os.system('mkdir randomdirs/' + newDirName)
		totRanImgs = random.choice(range(leastTotImgs, mostTotImgs + 1))
		totImgsSoFar = 0
		usedImgs = {} # { <IMGNAME> : TRUE ... }
		while totImgsSoFar < totRanImgs:
			newRanImg = random.choice(littleImgNames)
			if newRanImg == 'white.png':
				continue
			if newRanImg in usedImgs:
				continue
			else:
				usedImgs[newRanImg] = True
				os.system('cp ' + lilImgDir + newRanImg + ' randomdirs/' + newDirName + newRanImg)
				totImgsSoFar += 1
	return [ 'randomdirs/' + name for name in os.listdir('randomdirs/') ]
def modifySpecAnims(anims, colorMap, whiteSquare, lilImgDBDir = 'emoji/'):
	littleImgs = remoji.getLittleImgs(lilImgDBDir)
	newAnims = []
	i = 0
	j = 0 #Runner
	curSpec = None
	specDirOrder = [] #DIRECTORY NAMES IN ORDER CORRESPONDING 1:1 TO FRAMES IN THE ANIMATION
	while i < len(anims):
		if curSpec == None:
			pivotColors = []
			steps = anims[i].pop()
			for p in range(0, len(anims[i]) / 3):
				r = int(anims[i].pop(0))
				g = int(anims[i].pop(0))
				b = int(anims[i].pop(0))
				tempPivotColor = []
				tempPivotColor.append(r)
				tempPivotColor.append(g)
				tempPivotColor.append(b)
				pivotColors.append(tempPivotColor)
			curSpec = spectrum.Spectrum(steps, pivotColors, lilImgDBDir, littleImgs, colorMap, whiteSquare)
		j = i + 1
			#JUMP TO NEXT SPECTRUM
		while type(anims[j][0]) != int:
			j += 1
		steps = int(anims[j].pop())
		pivotColors = []
		for p in range(0, len(anims[j]) / 3):
			r = int(anims[j].pop(0))
			g = int(anims[j].pop(0))
			b = int(anims[j].pop(0))
			tempPivotColor = []
			tempPivotColor.append(r)
			tempPivotColor.append(g)
			tempPivotColor.append(b)
			pivotColors.append(tempPivotColor)
		nextSpec = spectrum.Spectrum(steps, pivotColors, lilImgDBDir, littleImgs, colorMap, whiteSquare)
		spec2d = spectrum.make2dSpectrum(20, curSpec, nextSpec, lilImgDBDir, littleImgs, colorMap)
		transitionFrames = 0
		tempNonSpecAnims = []
		#COUNT TOTAL TRANSITION FRAMES IN THIS LOOP
		while i < (j - 1):
			i += 1
			newAnims.append(anims[i])
			tempNonSpecAnims.append(anims[i])
			moreFrames = int(anims[i][2])
			transitionFrames += moreFrames
		i = j
		totSpectrums = len(spec2d) - 1 # -1 so that last spectrum doesnt get re-used in next anim 
		floatStep = totSpectrums / float(transitionFrames)
		specDirShortOrder = []
		for frame in range(0, transitionFrames):
			approxStep = floatStep * frame
			roundStep = int(round(approxStep))
			spec = spec2d[roundStep]
			dirName = spec.namify()
			specDirShortOrder.append(dirName)
			#IF THERES A PATH TO SPEC/DIRNAME, DONT BOTHER, ELSE, MAKE IT
			movieMaker.wipeDir('spec/' + dirName)
			spec.copyImgsToDir('spec/' + dirName)
			specDirOrder.append('spec/' + dirName)
		if j == (len(anims) - 1):
			break
		curSpec = nextSpec
	return [newAnims, specDirOrder]
예제 #12
0
def modifySpecAnims(anims, colorMap, whiteSquare, lilImgDBDir = 'emoji/'):
	littleImgs = remoji.getLittleImgs(lilImgDBDir)
	newAnims = []
	i = 0
	j = 0 #Runner
	curSpec = None
	specDirOrder = [] #DIRECTORY NAMES IN ORDER CORRESPONDING 1:1 TO FRAMES IN THE ANIMATION
	#if 'spec' not os.path.isdir('../spec'):
#	if not os.path.isdir('../spec'):
#		movieMaker.wipeDir('spec/')
	while i < len(anims):
#		if type(anims[i][0]) == int:
		if curSpec == None:
			pivotColors = []
			steps = anims[i].pop()
			#print 'anims[' + str(i) + ']: ', anims[i]
			for p in range(0, len(anims[i]) / 3):
				r = int(anims[i].pop(0))
				g = int(anims[i].pop(0))
				b = int(anims[i].pop(0))
				tempPivotColor = []
				tempPivotColor.append(r)
				tempPivotColor.append(g)
				tempPivotColor.append(b)
				pivotColors.append(tempPivotColor)
			curSpec = spectrum.Spectrum(steps, pivotColors, lilImgDBDir, littleImgs, colorMap, whiteSquare)
		#print curSpec.levelsPerColor, curSpec.pivotColors
		j = i + 1
			#JUMP TO NEXT SPECTRUM
		while type(anims[j][0]) != int:
			j += 1
		steps = int(anims[j].pop())
		pivotColors = []
		for p in range(0, len(anims[j]) / 3):
			#print 'p:',p
			#print len(anims[j])
			r = int(anims[j].pop(0))
			g = int(anims[j].pop(0))
			b = int(anims[j].pop(0))
			tempPivotColor = []
			tempPivotColor.append(r)
			tempPivotColor.append(g)
			tempPivotColor.append(b)
			pivotColors.append(tempPivotColor)
		#print 'pivotColors: ', pivotColors
		nextSpec = spectrum.Spectrum(steps, pivotColors, lilImgDBDir, littleImgs, colorMap, whiteSquare)
		#print type(nextSpec), type(curSpec)
		spec2d = spectrum.make2dSpectrum(20, curSpec, nextSpec, lilImgDBDir, littleImgs, colorMap)
		transitionFrames = 0
		tempNonSpecAnims = []
		#COUNT TOTAL TRANSITION FRAMES IN THIS LOOP
		while i < (j - 1):
			i += 1
			#print i, anims[i]
			newAnims.append(anims[i])
			tempNonSpecAnims.append(anims[i])
			moreFrames = int(anims[i][2])
			transitionFrames += moreFrames
		i = j
		totSpectrums = len(spec2d) - 1 # -1 so that last spectrum doesnt get re-used in next anim 
		floatStep = totSpectrums / float(transitionFrames)
		specDirShortOrder = []
		for frame in range(0, transitionFrames):
			approxStep = floatStep * frame
			roundStep = int(round(approxStep))
			spec = spec2d[roundStep]
			dirName = spec.namify()
			specDirShortOrder.append(dirName)
			#IF THERES A PATH TO SPEC/DIRNAME, DONT BOTHER, ELSE, MAKE IT
			#specDirs = os.listdir('spec/')
			#if dirName[:-1] not in specDirs:
			#	os.system('mkdir spec/' + dirName[:-1])
			#	#print 'copyingImgsToDir ..'
			#	spec.copyImgsToDir('spec/' + dirName)
			movieMaker.wipeDir('spec/' + dirName)
			spec.copyImgsToDir('spec/' + dirName)
			specDirOrder.append('spec/' + dirName)
		#print specDirs
		#print dirName
#		print 'specDirOrder:', specDirOrder
		if j == (len(anims) - 1):
			break
		curSpec = nextSpec
	return [newAnims, specDirOrder]
예제 #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]
                #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
예제 #14
0
def modifySpecAnims(anims, colorMap, whiteSquare, lilImgDBDir='emoji/'):
    littleImgs = remoji.getLittleImgs(lilImgDBDir)
    newAnims = []
    i = 0
    j = 0  #Runner
    curSpec = None
    specDirOrder = [
    ]  #DIRECTORY NAMES IN ORDER CORRESPONDING 1:1 TO FRAMES IN THE ANIMATION
    #if 'spec' not os.path.isdir('../spec'):
    #	if not os.path.isdir('../spec'):
    #		movieMaker.wipeDir('spec/')
    while i < len(anims):
        #		if type(anims[i][0]) == int:
        if curSpec == None:
            pivotColors = []
            steps = anims[i].pop()
            #print 'anims[' + str(i) + ']: ', anims[i]
            for p in range(0, len(anims[i]) / 3):
                r = int(anims[i].pop(0))
                g = int(anims[i].pop(0))
                b = int(anims[i].pop(0))
                tempPivotColor = []
                tempPivotColor.append(r)
                tempPivotColor.append(g)
                tempPivotColor.append(b)
                pivotColors.append(tempPivotColor)
            curSpec = spectrum.Spectrum(steps, pivotColors, lilImgDBDir,
                                        littleImgs, colorMap, whiteSquare)
        #print curSpec.levelsPerColor, curSpec.pivotColors
        j = i + 1
        #JUMP TO NEXT SPECTRUM
        while type(anims[j][0]) != int:
            j += 1
        steps = int(anims[j].pop())
        pivotColors = []
        for p in range(0, len(anims[j]) / 3):
            #print 'p:',p
            #print len(anims[j])
            r = int(anims[j].pop(0))
            g = int(anims[j].pop(0))
            b = int(anims[j].pop(0))
            tempPivotColor = []
            tempPivotColor.append(r)
            tempPivotColor.append(g)
            tempPivotColor.append(b)
            pivotColors.append(tempPivotColor)
        #print 'pivotColors: ', pivotColors
        nextSpec = spectrum.Spectrum(steps, pivotColors, lilImgDBDir,
                                     littleImgs, colorMap, whiteSquare)
        #print type(nextSpec), type(curSpec)
        spec2d = spectrum.make2dSpectrum(20, curSpec, nextSpec, lilImgDBDir,
                                         littleImgs, colorMap)
        transitionFrames = 0
        tempNonSpecAnims = []
        #COUNT TOTAL TRANSITION FRAMES IN THIS LOOP
        while i < (j - 1):
            i += 1
            #print i, anims[i]
            newAnims.append(anims[i])
            tempNonSpecAnims.append(anims[i])
            moreFrames = int(anims[i][2])
            transitionFrames += moreFrames
        i = j
        totSpectrums = len(
            spec2d
        ) - 1  # -1 so that last spectrum doesnt get re-used in next anim
        floatStep = totSpectrums / float(transitionFrames)
        specDirShortOrder = []
        for frame in range(0, transitionFrames):
            approxStep = floatStep * frame
            roundStep = int(round(approxStep))
            spec = spec2d[roundStep]
            dirName = spec.namify()
            specDirShortOrder.append(dirName)
            #IF THERES A PATH TO SPEC/DIRNAME, DONT BOTHER, ELSE, MAKE IT
            #specDirs = os.listdir('spec/')
            #if dirName[:-1] not in specDirs:
            #	os.system('mkdir spec/' + dirName[:-1])
            #	#print 'copyingImgsToDir ..'
            #	spec.copyImgsToDir('spec/' + dirName)
            movieMaker.wipeDir('spec/' + dirName)
            spec.copyImgsToDir('spec/' + dirName)
            specDirOrder.append('spec/' + dirName)
        #print specDirs
        #print dirName


#		print 'specDirOrder:', specDirOrder
        if j == (len(anims) - 1):
            break
        curSpec = nextSpec
    return [newAnims, specDirOrder]
def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        singleBool = False
        changeColorBool = False
        preProcBool = False
        loadBool = False
        mapBool = False
        joinBool = False
        mp4Bool = False
        writeBool = False
        opts, args = getopt.getopt(sys.argv[1:], "hcsiapmljvw")
        for opt, arg in opts:
            if opt == "-h":
                usage()
            if opt == "-c":
                print "Adjusting colors of database directory images..."
                changeColorBool = True
            if opt == "-s":
                singleBool = True
                print "Making mosaic of single image..."
            if opt == "-m":
                mapBool = True
                print "Making complete colorMap and writing it to a text file..."
            if opt == "-p":
                preProcBool = True
                print "Making directory of frames by preprocessing instructions file..."
            if opt == "-v":
                mp4Bool = True
                print "Using mp4 input"
                # if opt == '-l':
                # 	loadBool = True
                # 	print 'Making directory of frames by preprocessing instructions file (colorMap file provided)...'
            if opt == "-j":
                joinBool = True
                print "Concatenating movie directories..."
            if opt == "-w":
                writeBool = True
                print "Writing instructions file from writer file"

        # ARGS FOR INITIATING ANIMATION FRAMES
        if changeColorBool is True:
            dbDir = args[0]
            changeLittleImgs(dbDir)

        # ARGS FOR SINGLE IMAGE
        if singleBool is True:
            targetImgName = args[0]
            littleImgDir = args[1]
            outputName = args[2]
            scale = float(args[3])
            depth = int(args[4])
            colorMap = {}

            littleImgs = getLittleImgs(littleImgDir, skip=1)
            makeMosaic(targetImgName, scale, depth, littleImgs, outputName, colorMap, littleImgDir, origSkip=1)
            print outputName + " saved"

        if mapBool is True:
            startTime = time.time()
            lilImgDir = args[0]
            mapFile = args[1]
            a = ""
            while (a != "y") and (a != "n"):
                a = raw_input("Overwrite file at " + mapFile + " if it exists? [y/n]")
            if a == "y":
                print "Directory size: ", str(len(os.listdir(lilImgDir))), "images"
                preProc.buildColorMap(lilImgDir, mapFile)
            endTime = time.time()
            print time.time() - startTime, "seconds"

        if preProcBool is True:
            startTime = time.time()
            movDir = args[0]  # i.e. 'mov/'
            instructionsFile = args[1]  # i.e. 'instruct.txt'
            outputName = "anim"  # i.e. 'animation'
            startSec = int(args[2])
            endSec = int(args[3])
            secondsRange = (startSec, endSec)
            movieMaker.wipeDir(movDir)
            # if loadBool is True:
            # 	mapFile = args[3]
            # 	colorMap = preProc.loadMapFile(mapFile)
            # TODO IMPLEMENT MP4BOOL NEW ARGS
            # 	preProc.readFile(instructionsFile, movDir, outputName, colorMap, mp4Bool, secondsRange = secondsRange)
            # else:
            preProc.readFile(instructionsFile, movDir, outputName, secondsRange=secondsRange)
            print time.time() - startTime, "seconds"

        if joinBool is True:
            movDirs = args[:-1]
            opMovDir = args[-1]
            print movDirs, opMovDir
            movieMaker.joinMovDirs(movDirs, opMovDir)

        if writeBool is True:
            writerFile = args[0]
            insFile = args[1]
            instructionWriter.writeInsFile(writerFile, insFile)

    except getopt.error as err:
        print str(err)
        sys.exit(-1)
예제 #16
0
def main(argv=None):
    if argv is None:
        argv = sys.argv
    try:
        singleBool = False
        initiateFramesBool = False
        animateBool = False
        changeColorBool = False
        preProcBool = False
        loadBool = False
        mapBool = False
        joinBool = False
        mp4Bool = False
        opts, args = getopt.getopt(sys.argv[1:], 'hcsiapmljv')
        for opt, arg in opts:
            if opt == '-h':
                usage()
            if opt == '-c':
                print 'Adjusting colors of database directory images...'
                changeColorBool = True
            if opt == '-s':
                singleBool = True
                print 'Making mosaic of single image...'
            if opt == '-i':
                initiateFramesBool = True
                print 'Turning frames into mosaics of various resolutions...'
            if opt == '-a':
                animateBool = True
                print 'Making mpeg animation from instructions file...'
            if opt == '-m':
                mapBool = True
                print 'Making complete colorMap and writing it to a text file...'
            if opt == '-p':
                preProcBool = True
                print 'Making directory of frames by preprocessing instructions file...'
            if opt == '-v':
                mp4Bool = True
                print 'Using mp4 input'
            if opt == '-l':
                loadBool = True
                print 'Making directory of frames by preprocessing instructions file (colorMap file provided)...'
            if opt == '-j':
                joinBool = True
                print 'Concatenating movie directories...'

#ARGS FOR INITIATING ANIMATION FRAMES
        if changeColorBool is True:
            dbDir = args[0]
            changeLittleImgs(dbDir)

#ARGS FOR SINGLE IMAGE
        if singleBool is True:
            targetImgName = args[0]
            littleImgDir = args[1]
            outputName = args[2]
            scale = float(args[3])
            depth = int(args[4])
            colorMap = {}

            littleImgs = getLittleImgs(littleImgDir)
            makeMosaic(targetImgName, scale, depth, littleImgs, outputName,
                       colorMap, littleImgDir)
            print outputName + ' saved'

        if initiateFramesBool is True:
            startTime = time.time()
            name = args[0]  #i.e. 'squares/'
            littleImgDir = args[1]  #i.e. 'emoji/'
            framesDB = args[2]  #i.e. 'frames/'
            dbDir = args[3]  #i.e. 'mos/'
            littleImgs = getLittleImgs(littleImgDir)
            movieMaker.wipeDir(framesDB)
            movieMaker.wipeDir(dbDir)
            if args[4] != 'autoScale':
                scale = float(args[4])
                convertGif(name, framesDB)
            else:
                scale = 'autoScale'
                convertGif(name, framesDB, auto=True)
            makeLoopsFromFrames(framesDB, scale, littleImgs, dbDir + name)
            print time.time() - startTime, 'seconds'

# WHEN THE -A OPTION IS SELECTED, OUTPUT FRAMES IN MOVDIR FOR FINAL ANIMATION
        if animateBool is True:
            movDir = args[0]  #i.e. 'mov/'
            instructionsFile = args[1]  #i.e. 'instruct.txt'
            outputName = args[2]  #i.e. 'animation'

            movieMaker.wipeDir(movDir)

            movieMaker.readFile(instructionsFile, movDir, outputName)
            movieMaker.framesToMpg(outputName, movDir)


#			movieMaker.wipeDir('mov/')
#			trans = movieMaker.boxTrans('mmos/', 'hmos/', 'trans', 'mov/', 17, 0, 1, 1, 4, 15)

        if mapBool is True:
            startTime = time.time()
            lilImgDir = args[0]
            mapFile = args[1]
            a = ''
            while ((a != 'y') and (a != 'n')):
                a = raw_input('Overwrite file at ' + mapFile +
                              ' if it exists? [y/n]')
            if a == 'y':
                print 'Directory size: ', str(len(
                    os.listdir(lilImgDir))), 'images'
                preProc.buildColorMap(lilImgDir, mapFile)
            endTime = time.time()
            print time.time() - startTime, 'seconds'

        if preProcBool is True:
            startTime = time.time()
            movDir = args[0]  #i.e. 'mov/'
            instructionsFile = args[1]  #i.e. 'instruct.txt'
            outputName = 'anim'  #i.e. 'animation'
            startSec = int(args[2])
            endSec = int(args[3])
            secondsRange = (startSec, endSec)
            if loadBool is True:
                mapFile = args[3]
                colorMap = preProc.loadMapFile(mapFile)
                #TODO IMPLEMENT MP4BOOL NEW ARGS
                preProc.readFile(instructionsFile, movDir, outputName,
                                 colorMap, mp4Bool, secondsRange)
            else:
                preProc.readFile(instructionsFile, movDir, outputName)
            print time.time() - startTime, 'seconds'

        if joinBool is True:
            movDirs = args[:-1]
            opMovDir = args[-1]
            print movDirs, opMovDir
            movieMaker.joinMovDirs(movDirs, opMovDir)

    except getopt.error as err:
        print str(err)
        sys.exit(-1)
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
예제 #18
0
def main(argv = None):
	if argv is None:
		argv = sys.argv
	try:
		singleBool = False
		initiateFramesBool = False
		animateBool = False
		changeColorBool = False
		preProcBool = False
		loadBool = False
		mapBool = False
		joinBool = False
		mp4Bool = False
		opts, args = getopt.getopt(sys.argv[1:], 'hcsiapmljv')
		for opt, arg in opts:
			if opt == '-h':
				usage()
			if opt == '-c':
				print 'Adjusting colors of database directory images...'
				changeColorBool = True
			if opt == '-s':
				singleBool = True
				print 'Making mosaic of single image...'
			if opt == '-i':
				initiateFramesBool = True
				print 'Turning frames into mosaics of various resolutions...'
			if opt == '-a':
				animateBool = True
				print 'Making mpeg animation from instructions file...'
			if opt == '-m':
				mapBool = True
				print 'Making complete colorMap and writing it to a text file...'
			if opt == '-p':
				preProcBool = True
				print 'Making directory of frames by preprocessing instructions file...'
			if opt == '-v':
				mp4Bool = True
				print 'Using mp4 input'
			if opt == '-l':
				loadBool = True
				print 'Making directory of frames by preprocessing instructions file (colorMap file provided)...'
			if opt == '-j':
				joinBool = True
				print 'Concatenating movie directories...'

#ARGS FOR INITIATING ANIMATION FRAMES
		if changeColorBool is True:
			dbDir = args[0]
			changeLittleImgs(dbDir)
			
#ARGS FOR SINGLE IMAGE
		if singleBool is True:
			targetImgName = args[0]
			littleImgDir = args[1]
			outputName = args[2]
			scale = float(args[3])
			depth = int(args[4])
			colorMap = {}

			littleImgs = getLittleImgs(littleImgDir)
			makeMosaic(targetImgName, scale, depth, littleImgs, outputName, colorMap, littleImgDir)
			print outputName + ' saved'

		if initiateFramesBool is True:
			startTime = time.time()
			name = args[0]			#i.e. 'squares/'
			littleImgDir = args[1]		#i.e. 'emoji/'
			framesDB = args[2]		#i.e. 'frames/'
			dbDir = args[3]			#i.e. 'mos/'
			littleImgs = getLittleImgs(littleImgDir)
			movieMaker.wipeDir(framesDB)
			movieMaker.wipeDir(dbDir)
			if args[4] != 'autoScale':
				scale = float(args[4])
				convertGif(name, framesDB)
			else:
				scale = 'autoScale'
				convertGif(name, framesDB, auto = True)
			makeLoopsFromFrames(framesDB, scale, littleImgs, dbDir + name)
			print time.time() - startTime, 'seconds'
		
# WHEN THE -A OPTION IS SELECTED, OUTPUT FRAMES IN MOVDIR FOR FINAL ANIMATION
		if animateBool is True:
			movDir = args[0]		#i.e. 'mov/'
			instructionsFile = args[1]	#i.e. 'instruct.txt'
			outputName = args[2]		#i.e. 'animation'
			
			movieMaker.wipeDir(movDir)

			movieMaker.readFile(instructionsFile, movDir, outputName)
			movieMaker.framesToMpg(outputName, movDir)
#			movieMaker.wipeDir('mov/')
#			trans = movieMaker.boxTrans('mmos/', 'hmos/', 'trans', 'mov/', 17, 0, 1, 1, 4, 15)

		if mapBool is True:
			startTime = time.time()
			lilImgDir = args[0]
			mapFile = args[1]
			a = ''
			while((a != 'y') and (a != 'n')):
				a = raw_input('Overwrite file at ' + mapFile + ' if it exists? [y/n]')	
			if a == 'y':
				print 'Directory size: ', str(len(os.listdir(lilImgDir))) , 'images'
				preProc.buildColorMap(lilImgDir, mapFile)
			endTime = time.time()
			print time.time() - startTime, 'seconds'

		if preProcBool is True:
			startTime = time.time()
			movDir = args[0]		#i.e. 'mov/'
			instructionsFile = args[1]	#i.e. 'instruct.txt'
			outputName = 'anim'		#i.e. 'animation'
			startSec = int(args[2])
			endSec = int(args[3])
			secondsRange = (startSec, endSec)
			if loadBool is True:
				mapFile = args[3]
				colorMap = preProc.loadMapFile(mapFile)
#TODO IMPLEMENT MP4BOOL NEW ARGS
				preProc.readFile(instructionsFile, movDir, outputName, colorMap, mp4Bool, secondsRange)
			else:
				preProc.readFile(instructionsFile, movDir, outputName)
			print time.time() - startTime, 'seconds'

		if joinBool is True:
			movDirs = args[:-1]
			opMovDir = args[-1]
			print movDirs, opMovDir
			movieMaker.joinMovDirs(movDirs, opMovDir)
			

	except getopt.error as err:
		print str(err)
		sys.exit(-1)