基础库
This commit is contained in:
		
							parent
							
								
									e44ea96b43
								
							
						
					
					
						commit
						fbf31f0104
					
				
							
								
								
									
										28
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										28
									
								
								.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							| 
						 | 
				
			
			@ -75,7 +75,33 @@
 | 
			
		|||
        "stack": "cpp",
 | 
			
		||||
        "__mutex_base": "cpp",
 | 
			
		||||
        "shared_mutex": "cpp",
 | 
			
		||||
        "valarray": "cpp"
 | 
			
		||||
        "valarray": "cpp",
 | 
			
		||||
        "__bit_reference": "cpp",
 | 
			
		||||
        "__debug": "cpp",
 | 
			
		||||
        "__errc": "cpp",
 | 
			
		||||
        "__functional_base": "cpp",
 | 
			
		||||
        "__hash_table": "cpp",
 | 
			
		||||
        "__locale": "cpp",
 | 
			
		||||
        "__node_handle": "cpp",
 | 
			
		||||
        "__nullptr": "cpp",
 | 
			
		||||
        "__split_buffer": "cpp",
 | 
			
		||||
        "__string": "cpp",
 | 
			
		||||
        "__threading_support": "cpp",
 | 
			
		||||
        "__tree": "cpp",
 | 
			
		||||
        "__tuple": "cpp",
 | 
			
		||||
        "algorithm": "cpp",
 | 
			
		||||
        "codecvt": "cpp",
 | 
			
		||||
        "fstream": "cpp",
 | 
			
		||||
        "iomanip": "cpp",
 | 
			
		||||
        "iterator": "cpp",
 | 
			
		||||
        "locale": "cpp",
 | 
			
		||||
        "random": "cpp",
 | 
			
		||||
        "regex": "cpp",
 | 
			
		||||
        "cinttypes": "cpp",
 | 
			
		||||
        "csignal": "cpp",
 | 
			
		||||
        "memory_resource": "cpp",
 | 
			
		||||
        "future": "cpp",
 | 
			
		||||
        "cfenv": "cpp"
 | 
			
		||||
    },
 | 
			
		||||
    "C_Cpp.errorSquiggles": "Disabled"
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -58,6 +58,12 @@ cc_library(
 | 
			
		|||
    srcs = ["GPUImageUtil.cpp"],
 | 
			
		||||
    hdrs = ["GPUImageUtil.h"],
 | 
			
		||||
    visibility = ["//path/to/package:__pkg__"],
 | 
			
		||||
    linkopts = select({
 | 
			
		||||
        "//conditions:default": [],
 | 
			
		||||
        "//mediapipe:android": [
 | 
			
		||||
            "-llog",
 | 
			
		||||
        ],
 | 
			
		||||
    }),
 | 
			
		||||
    deps = select({
 | 
			
		||||
        "//mediapipe:android": [],
 | 
			
		||||
        "//mediapipe:apple": [],
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,6 +23,7 @@
 | 
			
		|||
#import <OpenGLES/ES3/glext.h>
 | 
			
		||||
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include "Filter.hpp"
 | 
			
		||||
#include "Context.hpp"
 | 
			
		||||
#include "GPUImageUtil.h"
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +35,7 @@ std::mutex Context::_mutex;
 | 
			
		|||
std::string Context::activatedContextKey = "";
 | 
			
		||||
std::map<std::string, Context*> Context::_ContextCache;
 | 
			
		||||
 | 
			
		||||
#if defined(__APPLE__)
 | 
			
		||||
Context::Context(EAGLContext *context)
 | 
			
		||||
:_curShaderProgram(0)
 | 
			
		||||
,isCapturingFrame(false)
 | 
			
		||||
| 
						 | 
				
			
			@ -44,16 +46,13 @@ Context::Context(EAGLContext *context)
 | 
			
		|||
,_eglContextIO(0)
 | 
			
		||||
,vertexArray(-1) {
 | 
			
		||||
    _framebufferCache = new FramebufferCache(this);
 | 
			
		||||
 | 
			
		||||
#if defined(__APPLE__)
 | 
			
		||||
 | 
			
		||||
    _eglContext = context;
 | 
			
		||||
    shareGroup = [_eglContext sharegroup];
 | 
			
		||||
    _eglContextIO = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 sharegroup:shareGroup];
 | 
			
		||||
    _eglOfflinerenderContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES3 sharegroup:shareGroup];
 | 
			
		||||
    
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
Context::Context()
 | 
			
		||||
:_curShaderProgram(0)
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -30,8 +30,9 @@
 | 
			
		|||
#import <OpenGLES/EAGL.h>
 | 
			
		||||
#import <OpenGLES/ES3/gl.h>
 | 
			
		||||
#import <CoreVideo/CoreVideo.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <EGL/egl.h>
 | 
			
		||||
#elif defined(__ANDROID__) 
 | 
			
		||||
#include <GLES3/gl3.h>
 | 
			
		||||
#include <GLES3/gl3ext.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -17,11 +17,14 @@
 | 
			
		|||
 */
 | 
			
		||||
#if defined(__APPLE__)
 | 
			
		||||
#import <Foundation/Foundation.h>
 | 
			
		||||
#elif defined(__ANDROID__)
 | 
			
		||||
#include <android/log.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include "GPUImageUtil.h"
 | 
			
		||||
#define openLog 1
 | 
			
		||||
 | 
			
		||||
#define ANDROID_LOG_INFO 'gpu_log_info'
 | 
			
		||||
 | 
			
		||||
namespace Opipe {
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@
 | 
			
		|||
 | 
			
		||||
#include <cmath>
 | 
			
		||||
#include "GaussianBlurFilter.hpp"
 | 
			
		||||
#include "util.h"
 | 
			
		||||
// #include "util.h"
 | 
			
		||||
 | 
			
		||||
NS_GI_BEGIN
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,6 @@
 | 
			
		|||
 | 
			
		||||
#include <cmath>
 | 
			
		||||
#include "GaussianBlurMonoFilter.hpp"
 | 
			
		||||
#include "util.h"
 | 
			
		||||
 | 
			
		||||
NS_GI_BEGIN
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,7 +13,7 @@
 | 
			
		|||
#if defined(__APPLE__)
 | 
			
		||||
#include "GPUImageMacros.h"
 | 
			
		||||
#else
 | 
			
		||||
#include "GPUImage-x/GPUImageMacros.h"
 | 
			
		||||
#include "GPUImageMacros.h"
 | 
			
		||||
#endif
 | 
			
		||||
#if defined(__APPLE__)
 | 
			
		||||
#include <pthread.h>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -44,8 +44,6 @@ cc_library(
 | 
			
		|||
    linkstatic = True,
 | 
			
		||||
    deps = [
 | 
			
		||||
        "//mediapipe/render/module/common:olamodule_common_library",
 | 
			
		||||
       
 | 
			
		||||
        
 | 
			
		||||
    ] + select({
 | 
			
		||||
        "//mediapipe:apple": [
 | 
			
		||||
            "//mediapipe/render/core:core-ios",
 | 
			
		||||
| 
						 | 
				
			
			@ -53,6 +51,12 @@ cc_library(
 | 
			
		|||
            "//mediapipe/framework/formats:landmark_cc_proto",
 | 
			
		||||
            "//mediapipe/render/module/beauty/filters:BeautyFilters",
 | 
			
		||||
        ],
 | 
			
		||||
        "//mediapipe:android": [
 | 
			
		||||
            "//mediapipe/render/core:core",
 | 
			
		||||
            "//mediapipe/graphs/face_mesh:mobile_calculators",
 | 
			
		||||
            "//mediapipe/framework/formats:landmark_cc_proto",
 | 
			
		||||
            "//mediapipe/render/module/beauty/filters:BeautyFilters",
 | 
			
		||||
        ],
 | 
			
		||||
        "//conditions:default": [
 | 
			
		||||
            "//mediapipe/render/core:core",
 | 
			
		||||
            "//mediapipe/graphs/face_mesh:mobile_calculators",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,9 +0,0 @@
 | 
			
		|||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
    package="com.ola.olamera">
 | 
			
		||||
 | 
			
		||||
    <uses-permission android:name="android.permission.CAMERA" />
 | 
			
		||||
 | 
			
		||||
    <uses-sdk tools:overrideLibrary="androidx.camera.core,androidx.camera.camera2" />
 | 
			
		||||
</manifest>
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +0,0 @@
 | 
			
		|||
//
 | 
			
		||||
// Created by  jormin on 2021/4/3.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include <jni.h>
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *jvm, void *reserved) {
 | 
			
		||||
    return JNI_VERSION_1_6;
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,63 +0,0 @@
 | 
			
		|||
precision highp float;
 | 
			
		||||
precision highp int;
 | 
			
		||||
varying vec2 textureCoordinate;
 | 
			
		||||
uniform sampler2D inputImageTexture;
 | 
			
		||||
uniform float inputImageTextureWidth;
 | 
			
		||||
uniform float inputImageTextureHeight;
 | 
			
		||||
float cY(float x,float y){
 | 
			
		||||
    vec4 c=texture2D(inputImageTexture,vec2(x,y));
 | 
			
		||||
    return 0.183 * c.r + 0.614 * c.g + 0.062 * c.b + 0.0625;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec4 cC(float x,float y,float dx,float dy){
 | 
			
		||||
    vec4 c0=texture2D(inputImageTexture,vec2(x,y));
 | 
			
		||||
    vec4 c1=texture2D(inputImageTexture,vec2(x+dx,y));
 | 
			
		||||
    vec4 c2=texture2D(inputImageTexture,vec2(x,y+dy));
 | 
			
		||||
    vec4 c3=texture2D(inputImageTexture,vec2(x+dx,y+dy));
 | 
			
		||||
    return (c0+c1+c2+c3)/4.;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float cU(float x,float y,float dx,float dy){
 | 
			
		||||
    vec4 c=cC(x,y,dx,dy);
 | 
			
		||||
    return -0.101 * c.r - 0.339 * c.g + 0.439 * c.b + 0.5000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
float cV(float x,float y,float dx,float dy){
 | 
			
		||||
    vec4 c=cC(x,y,dx,dy);
 | 
			
		||||
    return 0.439 * c.r - 0.399 * c.g - 0.040 * c.b + 0.5000;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec2 cPos(float t,float shiftx,float gy){
 | 
			
		||||
    vec2 pos=vec2(floor(inputImageTextureWidth*textureCoordinate.x),floor(inputImageTextureHeight*gy));
 | 
			
		||||
    return vec2(mod(pos.x*shiftx,inputImageTextureWidth),(pos.y*shiftx+floor(pos.x*shiftx/inputImageTextureWidth))*t);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vec4 calculateY(){
 | 
			
		||||
    vec2 pos=cPos(1.,4.,textureCoordinate.y);
 | 
			
		||||
    vec4 oColor=vec4(0);
 | 
			
		||||
    float textureYPos=pos.y/inputImageTextureHeight;
 | 
			
		||||
    oColor[0]=cY(pos.x/inputImageTextureWidth,textureYPos);
 | 
			
		||||
    oColor[1]=cY((pos.x+1.)/inputImageTextureWidth,textureYPos);
 | 
			
		||||
    oColor[2]=cY((pos.x+2.)/inputImageTextureWidth,textureYPos);
 | 
			
		||||
    oColor[3]=cY((pos.x+3.)/inputImageTextureWidth,textureYPos);
 | 
			
		||||
    return oColor;
 | 
			
		||||
}
 | 
			
		||||
vec4 calculateUV(float dx,float dy){
 | 
			
		||||
    vec2 pos=cPos(2.,4.,textureCoordinate.y-0.2500);
 | 
			
		||||
    vec4 oColor=vec4(0);
 | 
			
		||||
    float textureYPos=pos.y/inputImageTextureHeight;
 | 
			
		||||
    oColor[0]= cV(pos.x/inputImageTextureWidth,textureYPos,dx,dy);
 | 
			
		||||
    oColor[1]= cU(pos.x/inputImageTextureWidth,textureYPos,dx,dy);
 | 
			
		||||
    oColor[2]= cV((pos.x+2.)/inputImageTextureWidth,textureYPos,dx,dy);
 | 
			
		||||
    oColor[3]= cU((pos.x+2.)/inputImageTextureWidth,textureYPos,dx,dy);
 | 
			
		||||
    return oColor;
 | 
			
		||||
}
 | 
			
		||||
void main() {
 | 
			
		||||
    if(textureCoordinate.y<0.2500){
 | 
			
		||||
        gl_FragColor=calculateY();
 | 
			
		||||
    }else if(textureCoordinate.y<0.3750){
 | 
			
		||||
        gl_FragColor=calculateUV(1./inputImageTextureWidth,1./inputImageTextureHeight);
 | 
			
		||||
    }else{
 | 
			
		||||
        gl_FragColor=vec4(0,0,0,0);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,11 +0,0 @@
 | 
			
		|||
    attribute vec4 position;
 | 
			
		||||
    attribute vec4 inputTextureCoordinate;
 | 
			
		||||
    uniform mat4 mvp;
 | 
			
		||||
 | 
			
		||||
    varying vec2 textureCoordinate;
 | 
			
		||||
 | 
			
		||||
    void main()
 | 
			
		||||
    {
 | 
			
		||||
        gl_Position = mvp * position;
 | 
			
		||||
        textureCoordinate = inputTextureCoordinate.xy;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			@ -42,7 +42,6 @@ cc_library(
 | 
			
		|||
            "-Wno-shorten-64-to-32",
 | 
			
		||||
            "-fobjc-arc",  # enable reference-counting
 | 
			
		||||
        ],
 | 
			
		||||
         
 | 
			
		||||
        "//conditions:default": ["-std=c++17"],
 | 
			
		||||
    }),
 | 
			
		||||
    alwayslink = True,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user