从GPUImage里提取glsl文件的一个脚本

本文介绍了一种从GPUImage的Java源代码中提取GLSL着色器代码的方法,通过Python脚本自动化处理,便于快速学习和应用各种图像滤镜效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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环境, 着色器的路径是

android-gpuimage-1.4.1\library\src\jp\co\cyberagent\android\gpuimage

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值