import re
import sys
import os
rootdir = './'
for parent,dirnames,filenames in os.walk(rootdir):
for fileName in filenames:
if '.java' in fileName and 'GPUImage' in fileName:
print(fileName)
file = open(fileName, 'r', encoding='utf-8')
filterCode = file.read()
file.close()
index = filterCode.find("class")
print(index)
filterCode = filterCode[index:-1]
pattern = re.compile(r'".*?"')
filterObject = pattern.findall(filterCode)
# print(filterObject.group(1))
# //print(filterObject)
newFileName = fileName.replace(".java", ".glsl")
newFile = open(newFileName, "w")
for str in filterObject:
str = str[1:-1].replace("\\n", "\n")
print(str)
newFile.write(str)
if str == '}':
break
newFile.close()
把这个脚本放在GPUImage的着色器文件夹下面运行,
就可以把里面的glsl代码拿出来用,当然有一些小BUG,比如后面多出几个字符串啥的,这个脚本主要就是方便咱们快速学习这些滤镜,使用这个脚本需要有py3环境, 着色器的路径是