diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e47ba7d --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.DS_Store + +build/ +project.xcworkspace/ +xcuserdata/ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/.gitignore b/GPUImage-x/proj.android/GPUImage-x/library/.gitignore deleted file mode 100644 index 87e7e72..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) -### Android template -# Built application files -*.apk -*.ap_ - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# Intellij -*.iml -.idea/ - -# Keystore files -*.jks -*.DS_Store - -.externalNativeBuild diff --git a/GPUImage-x/proj.android/GPUImage-x/library/build.gradle b/GPUImage-x/proj.android/GPUImage-x/library/build.gradle deleted file mode 100755 index e4e31e3..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/build.gradle +++ /dev/null @@ -1,30 +0,0 @@ -apply plugin: 'com.android.library' -apply plugin: 'com.novoda.bintray-release' - -android { - compileSdkVersion 25 - buildToolsVersion "25.0.0" - defaultConfig { - minSdkVersion 9 - targetSdkVersion 25 - versionCode 1 - versionName "1.0" - } -// buildTypes { -// release { -// minifyEnabled false -// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' -// } -// } - externalNativeBuild { - cmake { - path "CMakeLists.txt" - } - } -} - -publish { - groupId = 'com.jin.gpuimage-x' - artifactId = 'gpuimage-x' - publishVersion = '1.0.1' -} \ No newline at end of file diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Context.hpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Context.hpp deleted file mode 100755 index 1799dcf..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Context.hpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Context_hpp -#define Context_hpp - -#include "macros.h" -#include "FramebufferCache.hpp" -#include -#include -#include "GLProgram.hpp" -#include "filter/Filter.hpp" - -#if PLATFORM == PLATFORM_IOS -#import -#import -#endif - -NS_GI_BEGIN - -class Context { -public: - Context(); - ~Context(); - - static void init(); - static void destroy(); - - static Context* getInstance(); - - FramebufferCache* getFramebufferCache() const; - void setActiveShaderProgram(GLProgram* shaderProgram); - void purge(); - -#if PLATFORM == PLATFORM_IOS - void runSync(std::function func); - void runAsync(std::function func); - void useAsCurrent(void); - dispatch_queue_t getContextQueue() const { return _contextQueue; }; - EAGLContext* getEglContext() const { return _eglContext; }; - void presentBufferForDisplay(); -#endif - - // used for capturing a processed frame data - bool isCapturingFrame; - Filter* captureUpToFilter; - unsigned char* capturedFrameData; - int captureWidth; - int captureHeight; - -private: - static Context* _instance; - static std::mutex _mutex; - FramebufferCache* _framebufferCache; - GLProgram* _curShaderProgram; - -#if PLATFORM == PLATFORM_IOS - dispatch_queue_t _contextQueue; - EAGLContext* _eglContext; -#endif -}; - - - -NS_GI_END - -#endif /* Context_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GLProgram.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GLProgram.cpp deleted file mode 100755 index 9b58df4..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GLProgram.cpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "GLProgram.hpp" -#include "Context.hpp" -#include "util.h" - -NS_GI_BEGIN - -std::vector GLProgram::_programs; - -GLProgram::GLProgram() -:_program(-1) -{ - _programs.push_back(this); -} - -GLProgram::~GLProgram() { - std::vector::iterator itr = std::find(_programs.begin(), _programs.end(), this); - if (itr != _programs.end()) { - _programs.erase(itr); - } - - bool bDeleteProgram = (_program != -1); - - for (auto const& program : _programs ) { - if (bDeleteProgram) { - if (_program == program->getID()) { - bDeleteProgram = false; - break; - } - } - } - - if (bDeleteProgram) { - glDeleteProgram(_program); - _program = -1; - } -} - -GLProgram* GLProgram::createByShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource) { - GLProgram* ret = new (std::nothrow) GLProgram(); - if (ret) { - if (!ret->_initWithShaderString(vertexShaderSource, fragmentShaderSource)) - { - delete ret; - ret = 0; - } - } - return ret; -} - - -bool GLProgram::_initWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource) { - - if (_program != -1) { - CHECK_GL(glDeleteProgram(_program)); - _program = -1; - } - CHECK_GL(_program = glCreateProgram()); - - CHECK_GL(GLuint vertShader = glCreateShader(GL_VERTEX_SHADER)); - const char* vertexShaderSourceStr = vertexShaderSource.c_str(); - CHECK_GL(glShaderSource(vertShader, 1, &vertexShaderSourceStr, NULL)); - CHECK_GL(glCompileShader(vertShader)); - - CHECK_GL(GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER)); - const char* fragmentShaderSourceStr = fragmentShaderSource.c_str(); - CHECK_GL(glShaderSource(fragShader, 1, &fragmentShaderSourceStr, NULL)); - CHECK_GL(glCompileShader(fragShader)); - - CHECK_GL(glAttachShader(_program, vertShader)); - CHECK_GL(glAttachShader(_program, fragShader)); - - CHECK_GL(glLinkProgram(_program)); - - CHECK_GL(glDeleteShader(vertShader)); - CHECK_GL(glDeleteShader(fragShader)); - - return true; -} - -void GLProgram::use() { - CHECK_GL(glUseProgram(_program)); -} - -GLuint GLProgram::getAttribLocation(const std::string& attribute) { - return glGetAttribLocation(_program, attribute.c_str()); -} - -GLuint GLProgram::getUniformLocation(const std::string& uniformName) { - return glGetUniformLocation(_program, uniformName.c_str()); -} - - -void GLProgram::setUniformValue(const std::string& uniformName, int value) { - Context::getInstance()->setActiveShaderProgram(this); - setUniformValue(getUniformLocation(uniformName), value); -} - -void GLProgram::setUniformValue(const std::string& uniformName, float value) { - Context::getInstance()->setActiveShaderProgram(this); - setUniformValue(getUniformLocation(uniformName), value); -} - -void GLProgram::setUniformValue(const std::string& uniformName, Matrix4 value) { - Context::getInstance()->setActiveShaderProgram(this); - setUniformValue(getUniformLocation(uniformName), value); -} - -void GLProgram::setUniformValue(const std::string& uniformName, Vector2 value) { - Context::getInstance()->setActiveShaderProgram(this); - setUniformValue(getUniformLocation(uniformName), value); -} - -void GLProgram::setUniformValue(const std::string& uniformName, Matrix3 value) { - Context::getInstance()->setActiveShaderProgram(this); - setUniformValue(getUniformLocation(uniformName), value); -} - -void GLProgram::setUniformValue(int uniformLocation, int value) { - Context::getInstance()->setActiveShaderProgram(this); - CHECK_GL(glUniform1i(uniformLocation, value)); -} - -void GLProgram::setUniformValue(int uniformLocation, float value) { - Context::getInstance()->setActiveShaderProgram(this); - CHECK_GL(glUniform1f(uniformLocation, value)); -} - -void GLProgram::setUniformValue(int uniformLocation, Matrix4 value) { - Context::getInstance()->setActiveShaderProgram(this); - CHECK_GL(glUniformMatrix4fv(uniformLocation, 1, GL_FALSE, (GLfloat *)&value)); -} - -void GLProgram::setUniformValue(int uniformLocation, Vector2 value) { - Context::getInstance()->setActiveShaderProgram(this); - CHECK_GL(glUniform2f(uniformLocation, value.x, value.y)); -} - -void GLProgram::setUniformValue(int uniformLocation, Matrix3 value) { - Context::getInstance()->setActiveShaderProgram(this); - CHECK_GL(glUniformMatrix3fv(uniformLocation, 1, GL_FALSE, (GLfloat *)&value)); -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BeautifyFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BeautifyFilter.cpp deleted file mode 100755 index cc90f94..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BeautifyFilter.cpp +++ /dev/null @@ -1,182 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "BeautifyFilter.hpp" - - -NS_GI_BEGIN - - -// Beautify shader code is adapted from guikz's beautify filter demo -// reference : -// http://www.csie.ntu.edu.tw/~fuh/personal/FaceBeautificationandColorEnhancement.A2-1-0040.pdf -// http://m.blog.csdn.net/article/details?id=50496969 -const std::string kBeautifyCombinationFragmentShaderString = SHADER_STRING -( - varying highp vec2 vTexCoord; - varying highp vec2 vTexCoord1; - varying highp vec2 vTexCoord2; - - uniform sampler2D colorMap; - uniform sampler2D colorMap1; - uniform sampler2D colorMap2; - uniform mediump float smoothDegree; - - void main() - { - highp vec4 bilateral = texture2D(colorMap, vTexCoord); - highp vec4 canny = texture2D(colorMap1, vTexCoord1); - - highp vec4 origin = texture2D(colorMap2,vTexCoord2); - highp vec4 smooth; - lowp float r = origin.r; - lowp float g = origin.g; - lowp float b = origin.b; - - if (canny.r < 0.2 && r > 0.3725 && g > 0.1568 && b > 0.0784 && r > b && (max(max(r, g), b) - min(min(r, g), b)) > 0.0588 && abs(r-g) > 0.0588) { - smooth = (1.0 - smoothDegree) * (origin - bilateral) + bilateral; - } - else { - smooth = origin; - } - - smooth.r = log(1.0 + 0.2 * smooth.r)/log(1.2); - smooth.g = log(1.0 + 0.2 * smooth.g)/log(1.2); - smooth.b = log(1.0 + 0.2 * smooth.b)/log(1.2); - gl_FragColor = smooth; - //gl_FragColor = origin; - } - ); - -class CombinationFilter : public Filter { -public: - static CombinationFilter* create() { - CombinationFilter* ret = new (std::nothrow) CombinationFilter(); - if (!ret || !ret->init()) { - delete ret; - ret = 0; - } - return ret; - } - - bool init() { - if (!Filter::initWithFragmentShaderString(kBeautifyCombinationFragmentShaderString, 3)) { - return false; - } - _intensity = 0.5; - - return true; - } - - virtual bool proceed(bool bUpdateTargets = true) override { - _filterProgram->setUniformValue("smoothDegree", _intensity); - return Filter::proceed(bUpdateTargets); - } - -protected: - CombinationFilter() {}; - -private: - float _intensity; -}; - -REGISTER_FILTER_CLASS(BeautifyFilter) - -BeautifyFilter::BeautifyFilter() -:_bilateralFilter(0) -,_cannyEdgeDetectionFilter(0) -,_combinationFilter(0) -,_hsbFilter(0) -{ -} - -BeautifyFilter::~BeautifyFilter() { - if (_bilateralFilter) { - _bilateralFilter->release(); - _bilateralFilter = 0; - } - if (_cannyEdgeDetectionFilter) { - _cannyEdgeDetectionFilter->release(); - _cannyEdgeDetectionFilter = 0; - } - if (_combinationFilter) { - _combinationFilter->release(); - _combinationFilter = 0; - } - if (_hsbFilter) { - _hsbFilter->release(); - _hsbFilter = 0; - } -} - -BeautifyFilter* BeautifyFilter::create() { - BeautifyFilter* ret = new (std::nothrow) BeautifyFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool BeautifyFilter::init() { - if (!FilterGroup::init()) { - return false; - } - - // 1. face smoothing - _bilateralFilter = BilateralFilter::create(); - _bilateralFilter->setDistanceNormalizationFactor(4.0); - addFilter(_bilateralFilter); - - // 2. edge detection - _cannyEdgeDetectionFilter = CannyEdgeDetectionFilter::create(); - addFilter(_cannyEdgeDetectionFilter); - - // 3.combination bilateral, edge detection and origin - _combinationFilter = CombinationFilter::create(); - addFilter(_combinationFilter); - - _bilateralFilter->addTarget(_combinationFilter); - _cannyEdgeDetectionFilter->addTarget(_combinationFilter); - - // 4. adjust hsb - _hsbFilter = HSBFilter::create(); - _hsbFilter->adjustBrightness(1.1); - _hsbFilter->adjustSaturation(1.1); - _combinationFilter->addTarget(_hsbFilter); - - setTerminalFilter(_hsbFilter); - - return true; -} - - -bool BeautifyFilter::proceed(bool bUpdateTargets/* = true*/) { - return FilterGroup::proceed(bUpdateTargets); -} - - -void BeautifyFilter::setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode/* = NoRotation*/, int texIdx/* = 0*/) { - for (auto& filter : _filters) { - if (filter == _combinationFilter) - texIdx = 2; - filter->setInputFramebuffer(framebuffer, rotationMode, texIdx); - } -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BilateralFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BilateralFilter.cpp deleted file mode 100755 index b1e990e..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BilateralFilter.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "BilateralFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(BilateralMonoFilter) - -const std::string kBilateralBlurVertexShaderString = SHADER_STRING -( - attribute vec4 position; - attribute vec4 texCoord; - - const int GAUSSIAN_SAMPLES = 9; - - uniform float texelSpacingU; - uniform float texelSpacingV; - - varying vec2 blurCoordinates[GAUSSIAN_SAMPLES]; - - void main() - { - gl_Position = position; - vec2 texelSpacing = vec2(texelSpacingU, texelSpacingV); - for (int i = 0; i < GAUSSIAN_SAMPLES; i++) - { - blurCoordinates[i] = texCoord.xy + texelSpacing * float((i - ((GAUSSIAN_SAMPLES - 1) / 2))); - } - } - ); - -const std::string kBilateralBlurFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - - const lowp int GAUSSIAN_SAMPLES = 9; - - varying highp vec2 blurCoordinates[GAUSSIAN_SAMPLES]; - - uniform mediump float distanceNormalizationFactor; - - void main() - { - lowp vec4 centralColor; - lowp float gaussianWeightTotal; - lowp vec4 sum; - lowp vec4 sampleColor; - lowp float distanceFromCentralColor; - lowp float gaussianWeight; - - centralColor = texture2D(colorMap, blurCoordinates[4]); - gaussianWeightTotal = 0.18; - sum = centralColor * 0.18; - - sampleColor = texture2D(colorMap, blurCoordinates[0]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[1]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.09 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[2]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.12 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[3]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.15 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[5]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.15 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[6]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.12 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[7]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.09 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - sampleColor = texture2D(colorMap, blurCoordinates[8]); - distanceFromCentralColor = min(distance(centralColor, sampleColor) * distanceNormalizationFactor, 1.0); - gaussianWeight = 0.05 * (1.0 - distanceFromCentralColor); - gaussianWeightTotal += gaussianWeight; - sum += sampleColor * gaussianWeight; - - gl_FragColor = sum / gaussianWeightTotal; - } - ); - - BilateralMonoFilter::BilateralMonoFilter(Type type) - :_type(type) -,_texelSpacingMultiplier(4.0) -,_distanceNormalizationFactor(8.0) - { - - } - - BilateralMonoFilter* BilateralMonoFilter::create(Type type/* = HORIZONTAL*/) { - BilateralMonoFilter* ret = new (std::nothrow) BilateralMonoFilter(type); - if (!ret || !ret->init()) { - delete ret; - ret = 0; - } - return ret; - } - -bool BilateralMonoFilter::init() { - if (Filter::initWithShaderString(kBilateralBlurVertexShaderString, kBilateralBlurFragmentShaderString)) { - return true; - } - return false; -} - -bool BilateralMonoFilter::proceed(bool bUpdateTargets/* = true*/) { - Framebuffer* inputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; - - if (rotationSwapsSize(inputRotation)) - { - if (_type == HORIZONTAL) { - _filterProgram->setUniformValue("texelSpacingU", (float)0.0); - _filterProgram->setUniformValue("texelSpacingV", (float)(_texelSpacingMultiplier / _framebuffer->getWidth())); - } else { - _filterProgram->setUniformValue("texelSpacingU", (float)(_texelSpacingMultiplier / _framebuffer->getHeight())); - _filterProgram->setUniformValue("texelSpacingV", (float)0.0); - } - } else { - if (_type == HORIZONTAL) { - _filterProgram->setUniformValue("texelSpacingU", (float)(_texelSpacingMultiplier / _framebuffer->getWidth())); - _filterProgram->setUniformValue("texelSpacingV", (float)0.0); - } else { - _filterProgram->setUniformValue("texelSpacingU", (float)0.0); - _filterProgram->setUniformValue("texelSpacingV", (float)(_texelSpacingMultiplier / _framebuffer->getHeight())); - } - } - - - _filterProgram->setUniformValue("distanceNormalizationFactor", _distanceNormalizationFactor); - return Filter::proceed(bUpdateTargets); -} - -void BilateralMonoFilter::setTexelSpacingMultiplier(float multiplier) { - _texelSpacingMultiplier = multiplier; -} - -void BilateralMonoFilter::setDistanceNormalizationFactor(float value) { - _distanceNormalizationFactor = value; -} - -REGISTER_FILTER_CLASS(BilateralFilter) - -BilateralFilter::BilateralFilter() -:_hBlurFilter(0) -,_vBlurFilter(0) -{ -} - -BilateralFilter::~BilateralFilter() { - if (_hBlurFilter) { - _hBlurFilter->release(); - _hBlurFilter = 0; - } - - if (_vBlurFilter) { - _vBlurFilter->release(); - _vBlurFilter = 0; - } - -} - -BilateralFilter* BilateralFilter::create() { - BilateralFilter* ret = new (std::nothrow) BilateralFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool BilateralFilter::init() { - if (!FilterGroup::init()) { - return false; - } - - _hBlurFilter = BilateralMonoFilter::create(BilateralMonoFilter::HORIZONTAL); - _vBlurFilter = BilateralMonoFilter::create(BilateralMonoFilter::VERTICAL); - _hBlurFilter->addTarget(_vBlurFilter); - addFilter(_hBlurFilter); - - registerProperty("texelSpacingMultiplier", 4.0, "The texel spacing multiplier.", [this](float& texelSpacingMultiplier){ - setTexelSpacingMultiplier(texelSpacingMultiplier); - }); - - registerProperty("distanceNormalizationFactor", 8.0, "The distance normalization factor.", [this](float& distanceNormalizationFactor){ - setDistanceNormalizationFactor(distanceNormalizationFactor); - }); - - return true; -} - -void BilateralFilter::setTexelSpacingMultiplier(float multiplier) { - _hBlurFilter->setTexelSpacingMultiplier(multiplier); - _vBlurFilter->setTexelSpacingMultiplier(multiplier); -} - -void BilateralFilter::setDistanceNormalizationFactor(float value) { - _hBlurFilter->setDistanceNormalizationFactor(value); - _vBlurFilter->setDistanceNormalizationFactor(value); - -} -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BilateralFilter.hpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BilateralFilter.hpp deleted file mode 100755 index f2bb7d9..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BilateralFilter.hpp +++ /dev/null @@ -1,68 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BilateralFilter_hpp -#define BilateralFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" - -NS_GI_BEGIN - - -class BilateralMonoFilter : public Filter { -public: - enum Type {HORIZONTAL, VERTICAL}; - - static BilateralMonoFilter* create(Type type = HORIZONTAL); - bool init(); - - virtual bool proceed(bool bUpdateTargets = true) override; - - void setTexelSpacingMultiplier(float multiplier); - void setDistanceNormalizationFactor(float value); -protected: - BilateralMonoFilter(Type type); - Type _type; - float _texelSpacingMultiplier; - float _distanceNormalizationFactor; -}; - -class BilateralFilter : public FilterGroup { -public: - virtual ~BilateralFilter(); - - static BilateralFilter* create(); - bool init(); - - void setTexelSpacingMultiplier(float multiplier); - void setDistanceNormalizationFactor(float value); - -protected: - BilateralFilter(); - -private: - //friend BilateralMonoFilter; - BilateralMonoFilter* _hBlurFilter; - BilateralMonoFilter* _vBlurFilter; -}; - - -NS_GI_END - -#endif /* BilateralFilter_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CannyEdgeDetectionFilter.hpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CannyEdgeDetectionFilter.hpp deleted file mode 100755 index 3fbca0a..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CannyEdgeDetectionFilter.hpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CannyEdgeDetectionFilter_hpp -#define CannyEdgeDetectionFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "GrayscaleFilter.hpp" -#include "SingleComponentGaussianBlurFilter.hpp" -#include "DirectionalSobelEdgeDetectionFilter.hpp" -#include "DirectionalNonMaximumSuppressionFilter.hpp" -#include "WeakPixelInclusionFilter.hpp" - -NS_GI_BEGIN - -class CannyEdgeDetectionFilter : public FilterGroup { -public: - static CannyEdgeDetectionFilter* create(); - bool init(); - -protected: - CannyEdgeDetectionFilter(); - ~CannyEdgeDetectionFilter(); - - GrayscaleFilter* _grayscaleFilter; - SingleComponentGaussianBlurFilter* _blurFilter; - DirectionalSobelEdgeDetectionFilter* _edgeDetectionFilter; - DirectionalNonMaximumSuppressionFilter* _nonMaximumSuppressionFilter; - WeakPixelInclusionFilter* _weakPixelInclusionFilter; - -}; - -NS_GI_END - -#endif /* CannyEdgeDetectionFilter_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorMatrixFilter.hpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorMatrixFilter.hpp deleted file mode 100755 index fe3e123..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorMatrixFilter.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ColorMatrixFilter_hpp -#define ColorMatrixFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" -#include "../math.hpp" - -NS_GI_BEGIN - - -class ColorMatrixFilter : public Filter { -public: - static ColorMatrixFilter* create(); - bool init(); - - virtual bool proceed(bool bUpdateTargets = true) override; - - void setIntensity(float intensity) { _intensity = intensity; } - void setColorMatrix(Matrix4 colorMatrix) { _colorMatrix = colorMatrix; } - -protected: - ColorMatrixFilter(); - - float _intensity; - Matrix4 _colorMatrix; -}; - - -NS_GI_END - -#endif /* ColorMatrixFilter_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ContrastFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ContrastFilter.cpp deleted file mode 100755 index 07f6668..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ContrastFilter.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ContrastFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(ContrastFilter) - -const std::string kContrastFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float contrast; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - gl_FragColor = vec4(((color.rgb - vec3(0.5)) * contrast + vec3(0.5)), color.a); - } -); - - -ContrastFilter* ContrastFilter::create() { - ContrastFilter* ret = new (std::nothrow) ContrastFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool ContrastFilter::init() { - if (!initWithFragmentShaderString(kContrastFragmentShaderString)) return false; - - _contrast = 1.0; - registerProperty("contrast", _contrast, "The contrast of the image. Contrast ranges from 0.0 to 4.0 (max contrast), with 1.0 as the normal level", [this](float& contrast){ - setContrast(contrast); - }); - - return true; -} - -void ContrastFilter::setContrast(float contrast) { - _contrast = contrast; - if (_contrast > 4.0) _contrast = 4.0; - else if (_contrast < 0.0) _contrast = 0.0; -} - -bool ContrastFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("contrast", _contrast); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalNonMaximumSuppressionFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalNonMaximumSuppressionFilter.cpp deleted file mode 100755 index 485d2c5..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalNonMaximumSuppressionFilter.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "DirectionalNonMaximumSuppressionFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(DirectionalNonMaximumSuppressionFilter) - -const std::string kDirectionalNonmaximumSuppressionFragmentShaderString = SHADER_STRING -( - precision mediump float; - - uniform sampler2D colorMap; - uniform highp float texelWidth; - uniform highp float texelHeight; - uniform mediump float upperThreshold; - uniform mediump float lowerThreshold; - - varying highp vec2 vTexCoord; - - void main() - { - vec3 currentGradientAndDirection = texture2D(colorMap, vTexCoord).rgb; - vec2 gradientDirection = ((currentGradientAndDirection.gb * 2.0) - 1.0) * vec2(texelWidth, texelHeight); - - float firstSampledGradientMagnitude = texture2D(colorMap, vTexCoord + gradientDirection).r; - float secondSampledGradientMagnitude = texture2D(colorMap, vTexCoord - gradientDirection).r; - - float multiplier = step(firstSampledGradientMagnitude, currentGradientAndDirection.r); - multiplier = multiplier * step(secondSampledGradientMagnitude, currentGradientAndDirection.r); - - float thresholdCompliance = smoothstep(lowerThreshold, upperThreshold, currentGradientAndDirection.r); - multiplier = multiplier * thresholdCompliance; - - gl_FragColor = vec4(multiplier, multiplier, multiplier, 1.0); - } - ); - - -DirectionalNonMaximumSuppressionFilter* DirectionalNonMaximumSuppressionFilter::create() { - DirectionalNonMaximumSuppressionFilter* ret = new (std::nothrow) DirectionalNonMaximumSuppressionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool DirectionalNonMaximumSuppressionFilter::init() { - if (initWithFragmentShaderString(kDirectionalNonmaximumSuppressionFragmentShaderString)) { - _texelWidthUniform = _filterProgram->getUniformLocation("texelWidth"); - _texelHeightUniform = _filterProgram->getUniformLocation("texelWidth"); - - _filterProgram->setUniformValue("upperThreshold", (float)0.5); - _filterProgram->setUniformValue("lowerThreshold", (float)0.1); - - return true; - } - return false; -} - - -bool DirectionalNonMaximumSuppressionFilter::proceed(bool bUpdateTargets/* = true*/) { - float texelWidth = 1.0 / _framebuffer->getWidth(); - float texelHeight = 1.0 / _framebuffer->getHeight(); - - Framebuffer* inputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; - - if (rotationSwapsSize(inputRotation)){ - texelWidth = 1.0 / _framebuffer->getHeight(); - texelHeight = 1.0 / _framebuffer->getWidth(); - } - - _filterProgram->setUniformValue(_texelWidthUniform, texelWidth); - _filterProgram->setUniformValue(_texelHeightUniform, texelHeight); - - return Filter::proceed(bUpdateTargets); -} - - - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalSobelEdgeDetectionFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalSobelEdgeDetectionFilter.cpp deleted file mode 100755 index c184cc4..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalSobelEdgeDetectionFilter.cpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "DirectionalSobelEdgeDetectionFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(DirectionalSobelEdgeDetectionFilter) - -const std::string kDirectionalSobelEdgeDetectionFragmentShaderString = SHADER_STRING -( - precision mediump float; - uniform sampler2D colorMap; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - - void main() - { - float bottomLeftIntensity = texture2D(colorMap, vBottomLeftTexCoord).r; - float topRightIntensity = texture2D(colorMap, vTopRightTexCoord).r; - float topLeftIntensity = texture2D(colorMap, vTopLeftTexCoord).r; - float bottomRightIntensity = texture2D(colorMap, vBottomRightTexCoord).r; - float leftIntensity = texture2D(colorMap, vLeftTexCoord).r; - float rightIntensity = texture2D(colorMap, vRightTexCoord).r; - float bottomIntensity = texture2D(colorMap, vBottomTexCoord).r; - float topIntensity = texture2D(colorMap, vTopTexCoord).r; - - vec2 gradientDirection; - gradientDirection.x = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; - gradientDirection.y = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; - - float gradientMagnitude = length(gradientDirection); - vec2 normalizedDirection = normalize(gradientDirection); - normalizedDirection = sign(normalizedDirection) * floor(abs(normalizedDirection) + 0.617316); // Offset by 1-sin(pi/8) to set to 0 if near axis, 1 if away - normalizedDirection = (normalizedDirection + 1.0) * 0.5; // Place -1.0 - 1.0 within 0 - 1.0 - - gl_FragColor = vec4(gradientMagnitude, normalizedDirection.x, normalizedDirection.y, 1.0); - } - ); - - -DirectionalSobelEdgeDetectionFilter* DirectionalSobelEdgeDetectionFilter::create() { - DirectionalSobelEdgeDetectionFilter* ret = new (std::nothrow) DirectionalSobelEdgeDetectionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool DirectionalSobelEdgeDetectionFilter::init() { - if (initWithFragmentShaderString(kDirectionalSobelEdgeDetectionFragmentShaderString)) { - return true; - } - return false; -} - - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Filter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Filter.cpp deleted file mode 100755 index ec2ef14..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Filter.cpp +++ /dev/null @@ -1,424 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Filter.hpp" -#include "../Context.hpp" - - -NS_GI_BEGIN - -std::map> Filter::_filterFactories; - -Filter::Filter() -:_filterProgram(0) -,_filterClassName("") -{ - _backgroundColor.r = 0.0; - _backgroundColor.g = 0.0; - _backgroundColor.b = 0.0; - _backgroundColor.a = 1.0; -} - -Filter::~Filter() { - if (_filterProgram) { - delete _filterProgram; - _filterProgram = 0; - } -} - -Filter* Filter::create(const std::string& filterClassName) { - std::map>::iterator it = _filterFactories.find(filterClassName); - if (it == _filterFactories.end()) - return 0; - else { - Filter* filter = it->second(); - filter->setFilterClassName(filterClassName); - return it->second(); - } -} - -Filter* Filter::createWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource) { - Filter* filter = new Filter(); - if (!filter->initWithShaderString(vertexShaderSource, fragmentShaderSource)) { - delete filter; - filter = 0; - return 0; - } - return filter; -} - -Filter* Filter::createWithFragmentShaderString(const std::string& fragmentShaderSource) { - Filter* filter = new Filter(); - if (!filter->initWithFragmentShaderString(fragmentShaderSource)) { - delete filter; - filter = 0; - return 0; - } - return filter; -} - -bool Filter::initWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource) { - - _filterProgram = GLProgram::createByShaderString(vertexShaderSource, fragmentShaderSource); - _filterPositionAttribute = _filterProgram->getAttribLocation("position"); - //_filterTexCoordAttribute = _filterProgram->getAttribLocation("texCoord"); - Context::getInstance()->setActiveShaderProgram(_filterProgram); - CHECK_GL(glEnableVertexAttribArray(_filterPositionAttribute)); - //glEnableVertexAttribArray(_filterTexCoordAttribute); - - return true; -} - -bool Filter::initWithFragmentShaderString(const std::string& fragmentShaderSource, int inputNumber/* = 1*/) { - _inputNum = inputNumber; - return initWithShaderString(_getVertexShaderString(), fragmentShaderSource); -} - -std::string Filter::_getVertexShaderString() const { - - if (_inputNum <= 1) - { - return kDefaultVertexShader; - } - - std::string shaderStr = "\ - attribute vec4 position;\n\ - attribute vec4 texCoord;\n\ - varying vec2 vTexCoord;\n\ - "; - for (int i = 1; i < _inputNum; ++i) { - shaderStr += str_format("\ - attribute vec4 texCoord%d;\n\ - varying vec2 vTexCoord%d;\n\ - ", i, i); - } - shaderStr += "\ - void main()\n\ - {\n\ - gl_Position = position;\n\ - vTexCoord = texCoord.xy;\n\ - "; - for (int i = 1; i < _inputNum; ++i) { - shaderStr += str_format("vTexCoord%d = texCoord%d.xy;\n", i, i); - } - shaderStr += "}\n"; - - return shaderStr; -} - -bool Filter::proceed(bool bUpdateTargets/* = true*/) { - static const GLfloat imageVertices[] = { - -1.0f, -1.0f, - 1.0f, -1.0f, - -1.0f, 1.0f, - 1.0f, 1.0f, - }; - - Context::getInstance()->setActiveShaderProgram(_filterProgram); - _framebuffer->active(); - CHECK_GL(glClearColor(_backgroundColor.r, _backgroundColor.g, _backgroundColor.b, _backgroundColor.a)); - CHECK_GL(glClear(GL_COLOR_BUFFER_BIT)); - for (std::map::const_iterator it = _inputFramebuffers.begin(); it != _inputFramebuffers.end(); ++it) { - int texIdx = it->first; - Framebuffer* fb = it->second.frameBuffer; - CHECK_GL(glActiveTexture(GL_TEXTURE0 + texIdx)); - CHECK_GL(glBindTexture(GL_TEXTURE_2D, fb->getTexture())); - _filterProgram->setUniformValue( - texIdx == 0 ? "colorMap" : str_format("colorMap%d", texIdx), - texIdx); - // texcoord attribute - GLuint filterTexCoordAttribute = _filterProgram->getAttribLocation(texIdx == 0 ? "texCoord" : str_format("texCoord%d", texIdx)); - CHECK_GL(glEnableVertexAttribArray(filterTexCoordAttribute)); - CHECK_GL(glVertexAttribPointer(filterTexCoordAttribute, 2, GL_FLOAT, 0, 0, _getTexureCoordinate(it->second.rotationMode))); - } - CHECK_GL(glVertexAttribPointer(_filterPositionAttribute, 2, GL_FLOAT, 0, 0, imageVertices)); - CHECK_GL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); - - _framebuffer->inactive(); - - return Source::proceed(bUpdateTargets); -} - -const GLfloat* Filter::_getTexureCoordinate(const RotationMode& rotationMode) const { - static const GLfloat noRotationTextureCoordinates[] = { - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, - }; - - static const GLfloat rotateLeftTextureCoordinates[] = { - 1.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 0.0f, 1.0f, - }; - - static const GLfloat rotateRightTextureCoordinates[] = { - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f, - }; - - static const GLfloat verticalFlipTextureCoordinates[] = { - 0.0f, 1.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 0.0f, - }; - - static const GLfloat horizontalFlipTextureCoordinates[] = { - 1.0f, 0.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 1.0f, - }; - - static const GLfloat rotateRightVerticalFlipTextureCoordinates[] = { - 0.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 1.0f, 1.0f, - }; - - static const GLfloat rotateRightHorizontalFlipTextureCoordinates[] = { - 1.0f, 1.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 0.0f, 0.0f, - }; - - static const GLfloat rotate180TextureCoordinates[] = { - 1.0f, 1.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 0.0f, 0.0f, - }; - - switch (rotationMode) { - case NoRotation: - return noRotationTextureCoordinates; - break; - case RotateLeft: - return rotateLeftTextureCoordinates; - break; - case RotateRight: - return rotateRightTextureCoordinates; - break; - case FlipVertical: - return verticalFlipTextureCoordinates; - break; - case FlipHorizontal: - return horizontalFlipTextureCoordinates; - break; - case RotateRightFlipVertical: - return rotateRightVerticalFlipTextureCoordinates; - break; - case RotateRightFlipHorizontal: - return rotateRightHorizontalFlipTextureCoordinates; - break; - case Rotate180: - return rotate180TextureCoordinates; - break; - default: - break; - } -} - -void Filter::update(float frameTime) { - if (_inputFramebuffers.empty()) return; - - if (Context::getInstance()->isCapturingFrame && this == Context::getInstance()->captureUpToFilter) { - int captureWidth = Context::getInstance()->captureWidth; - int captureHeight = Context::getInstance()->captureHeight; - - _framebuffer = Context::getInstance()->getFramebufferCache()->fetchFramebuffer(captureWidth, captureHeight); - proceed(false); - - _framebuffer->active(); - Context::getInstance()->capturedFrameData = new unsigned char[captureWidth * captureHeight * 4]; - CHECK_GL(glReadPixels(0, 0, captureWidth, captureHeight, GL_RGBA, GL_UNSIGNED_BYTE, Context::getInstance()->capturedFrameData)); - _framebuffer->inactive(); - } else { - // todo - Framebuffer* firstInputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - RotationMode firstInputRotation = _inputFramebuffers.begin()->second.rotationMode; - if (!firstInputFramebuffer) return; - - int rotatedFramebufferWidth = firstInputFramebuffer->getWidth(); - int rotatedFramebufferHeight = firstInputFramebuffer->getHeight(); - if (rotationSwapsSize(firstInputRotation)) - { - rotatedFramebufferWidth = firstInputFramebuffer->getHeight(); - rotatedFramebufferHeight = firstInputFramebuffer->getWidth(); - } - - if (_framebufferScale != 1.0) { - rotatedFramebufferWidth = int(rotatedFramebufferWidth * _framebufferScale); - rotatedFramebufferHeight = int(rotatedFramebufferHeight * _framebufferScale); - } - - _framebuffer = Context::getInstance()->getFramebufferCache()->fetchFramebuffer(rotatedFramebufferWidth, rotatedFramebufferHeight); - proceed(); - } - - _framebuffer->release(); - _framebuffer = 0; -} - -bool Filter::registerProperty(const std::string& name, int defaultValue, const std::string& comment/* = ""*/, std::function setCallback/* = 0*/) { - if (hasProperty(name)) return false; - IntProperty property; - property.type = "int"; - property.value = defaultValue; - property.comment = comment; - property.setCallback = setCallback; - _intProperties[name] = property; - return true; -} - -bool Filter::registerProperty(const std::string& name, float defaultValue, const std::string& comment/* = ""*/, std::function setCallback/* = 0*/) { - if (hasProperty(name)) return false; - FloatProperty property; - property.type = "float"; - property.value = defaultValue; - property.comment = comment; - property.setCallback = setCallback; - _floatProperties[name] = property; - return true; -} - -bool Filter::registerProperty(const std::string& name, const std::string& defaultValue, const std::string& comment/* = ""*/, std::function setCallback/* = 0*/) { - if (hasProperty(name)) return false; - StringProperty property; - property.type = "string"; - property.value = defaultValue; - property.comment = comment; - property.setCallback = setCallback; - _stringProperties[name] = property; - return true; -} - -bool Filter::setProperty(const std::string& name, int value) { - Property* rawProperty = _getProperty(name); - if (!rawProperty) { - Log("WARNING", "Filter::setProperty invalid property %s", name.c_str()); - return false; - } else if (rawProperty->type != "int") { - Log("WARNING", "Filter::setProperty The property type is expected to be %s", rawProperty->type.c_str()); - return false; - } - IntProperty* property = ((IntProperty*)rawProperty); - property->value = value; - if (property->setCallback) - property->setCallback(value); - return true; -} - -bool Filter::setProperty(const std::string& name, float value) { - Property* rawProperty = _getProperty(name); - if (!rawProperty) { - Log("WARNING", "Filter::setProperty invalid property %s", name.c_str()); - return false; - } else if (rawProperty->type != "float") { - Log("WARNING", "Filter::setProperty The property type is expected to be %s", rawProperty->type.c_str()); - return false; - } - FloatProperty* property = ((FloatProperty*)rawProperty); - if (property->setCallback) - property->setCallback(value); - property->value = value; - - return true; -} - -bool Filter::setProperty(const std::string& name, std::string value) { - Property* rawProperty = _getProperty(name); - if (!rawProperty) { - Log("WARNING", "Filter::setProperty invalid property %s", name.c_str()); - return false; - } else if (rawProperty->type != "string") { - Log("WARNING", "Filter::setProperty The property type is expected to be %s", rawProperty->type.c_str()); - return false; - } - StringProperty* property = ((StringProperty*)rawProperty); - property->value = value; - if (property->setCallback) - property->setCallback(value); - return true; -} - -bool Filter::getProperty(const std::string& name, int& retValue) { - Property* property = _getProperty(name); - if (!property) return false; - retValue = ((IntProperty*)property)->value; - return true; -} - -bool Filter::getProperty(const std::string& name, float& retValue) { - Property* property = _getProperty(name); - if (!property) return false; - retValue = ((FloatProperty*)property)->value; - return true; -} - -bool Filter::getProperty(const std::string& name, std::string& retValue) { - Property* property = _getProperty(name); - if (!property) return false; - retValue = ((StringProperty*)property)->value; - return true; -} - -Filter::Property* Filter::_getProperty(const std::string& name) { - if (_intProperties.find(name) != _intProperties.end()) { - return &_intProperties[name]; - } - if (_floatProperties.find(name) != _floatProperties.end()) { - return &_floatProperties[name]; - } - if (_stringProperties.find(name) != _stringProperties.end()) { - return &_stringProperties[name]; - } - return 0; -} - -bool Filter::hasProperty(const std::string& name, const std::string type) { - Property* property = _getProperty(name); - return property && property->type == type ? true : false; -} - -bool Filter::hasProperty(const std::string& name) { - return _getProperty(name) ? true : false; -} - -bool Filter::getPropertyComment(const std::string& name, std::string& retComment) { - Property* property = _getProperty(name); - if (!property) return false; - retComment = std::string("[") + property->type + "] " + property->comment; - return true; -} - -bool Filter::getPropertyType(const std::string& name, std::string& retType) { - Property* property = _getProperty(name); - if (!property) return false; - retType = property->type; - return true; -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Filter.hpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Filter.hpp deleted file mode 100755 index ae7acba..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Filter.hpp +++ /dev/null @@ -1,162 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Filter_hpp -#define Filter_hpp - -#include "../macros.h" -#include "string" -#include "../source/Source.hpp" -#include "../target/Target.hpp" -#include "../GLProgram.hpp" -#include "../Ref.hpp" -#include "../util.h" - -NS_GI_BEGIN - - -// Hardcode the vertex shader for standard filters, but this can be overridden -const std::string kDefaultVertexShader = SHADER_STRING -( - attribute vec4 position; - attribute vec4 texCoord; - - varying vec2 vTexCoord; - - void main() - { - gl_Position = position; - vTexCoord = texCoord.xy; - } - ); - -const std::string kDefaultFragmentShader = SHADER_STRING -( - varying highp vec2 vTexCoord; - uniform sampler2D colorMap; - - void main() - { - gl_FragColor = texture2D(colorMap, vTexCoord); - } - ); - -class Filter : public Source, public Target { -public: - virtual ~Filter(); - - static Filter* create(const std::string& filterClassName); - static Filter* createWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource); - static Filter* createWithFragmentShaderString(const std::string& fragmentShaderSource); - - bool initWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource); - virtual bool initWithFragmentShaderString(const std::string& fragmentShaderSource, int inputNumber = 1); - void setFilterClassName(const std::string filterClassName) {_filterClassName = filterClassName; } - std::string getFilterClassName() const { return _filterClassName; }; - - virtual void update(float frameTime) override; - virtual bool proceed(bool bUpdateTargets = true) override; - GLProgram* getProgram() const { return _filterProgram; }; - - // property setters & getters - bool registerProperty(const std::string& name, int defaultValue, const std::string& comment = "", std::function setCallback = 0); - bool registerProperty(const std::string& name, float defaultValue, const std::string& comment = "", std::function setCallback = 0); - bool registerProperty(const std::string& name, const std::string& defaultValue, const std::string& comment = "", std::function setCallback = 0); - bool setProperty(const std::string& name, int value); - bool setProperty(const std::string& name, float value); - bool setProperty(const std::string& name, std::string value); - bool getProperty(const std::string& name, int& retValue); - bool getProperty(const std::string& name, float& retValue); - bool getProperty(const std::string& name, std::string& retValue); - bool hasProperty(const std::string& name); - bool hasProperty(const std::string& name, const std::string type); - bool getPropertyComment(const std::string& name, std::string& retComment); - bool getPropertyType(const std::string& name, std::string& retType); - -#if PLATFORM == PLATFORM_ANDROID - class Registry { - public: - Registry(const std::string& name, std::function createFunc) { - Filter::_registerFilterClass(name, createFunc); - } - }; - static void _registerFilterClass(const std::string& filterClassName, std::function createFunc) { - //Log("jin", "Filter::registerClass : %s", filterClassName.c_str()); - _filterFactories[filterClassName] = createFunc; - } -#endif - -protected: - GLProgram* _filterProgram; - GLuint _filterPositionAttribute; - std::string _filterClassName; - struct { - float r; float g; float b; float a; - } _backgroundColor; - - Filter(); - std::string _getVertexShaderString() const; - const GLfloat* _getTexureCoordinate(const RotationMode& rotationMode) const; - - // properties - struct Property { - std::string type; - std::string comment; - }; - Property* _getProperty(const std::string& name); - - struct IntProperty : Property{ - int value; - std::function setCallback; - }; - std::map _intProperties; - - struct FloatProperty : Property { - float value; - std::function setCallback; - }; - std::map _floatProperties; - - struct StringProperty : Property { - std::string value; - std::function setCallback; - }; - std::map _stringProperties; - -private: - static std::map> _filterFactories; -}; - -#if PLATFORM == PLATFORM_ANDROID -#define REGISTER_FILTER_CLASS(className) \ -class className##Registry { \ - public: \ - static Filter* newInstance() { \ - return className::create(); \ - } \ - private: \ - static const Filter::Registry _registry; \ -}; \ -const Filter::Registry className##Registry::_registry(#className, className##Registry::newInstance); -#elif PLATFORM == PLATFORM_IOS -#define REGISTER_FILTER_CLASS(className) -#endif - -NS_GI_END - -#endif /* Filter_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/FilterGroup.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/FilterGroup.cpp deleted file mode 100755 index 3e42903..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/FilterGroup.cpp +++ /dev/null @@ -1,222 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "FilterGroup.hpp" -#include -#include "../Context.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(FilterGroup) - -FilterGroup::FilterGroup() -:_terminalFilter(0) -{ -} - -FilterGroup::~FilterGroup() { - removeAllFilters(); - _terminalFilter = 0; -} - -FilterGroup* FilterGroup::create() { - FilterGroup* ret = new (std::nothrow) FilterGroup(); - if (ret && ret->init()) { - //ret->autorelease(); - } else { - delete ret; - ret = 0; - } - return ret; -} - -FilterGroup* FilterGroup::create(std::vector filters) { - FilterGroup* ret = new (std::nothrow) FilterGroup(); - if (ret && ret->init(filters)) { - //ret->autorelease(); - } else { - delete ret; - ret = 0; - } - return ret; -} - -bool FilterGroup::init() { - return true; -} - - -bool FilterGroup::init(std::vector filters) { - if (filters.size() == 0) return true; - _filters = filters; - - for (auto const& filter : filters ) { - Ref* ref = dynamic_cast(filter); - if (ref) { - ref->retain(); - } - } - - setTerminalFilter(_predictTerminalFilter(filters[filters.size() - 1])); - return true; -} - -bool FilterGroup::hasFilter(const Filter* filter) const { - std::vector::const_iterator it = std::find(_filters.begin(), _filters.end(), filter); - if (it != _filters.end()) - return true; - else - return false; -} - -void FilterGroup::addFilter(Filter* filter) { - if (hasFilter(filter)) return; - - _filters.push_back(filter); - - Ref* ref = dynamic_cast(filter); - if (ref) { - ref->retain(); - } - - setTerminalFilter(_predictTerminalFilter(filter)); -} - -void FilterGroup::removeFilter(Filter* filter) { - std::vector::iterator itr = std::find(_filters.begin(), _filters.end(), filter); - if (itr != _filters.end()) { - Ref* ref = dynamic_cast(*itr); - if (ref) { - ref->release(); - } - _filters.erase(itr); - } -} - -void FilterGroup::removeAllFilters() { - for (auto const& filter : _filters ) { - Ref* ref = dynamic_cast(filter); - if (ref) { - ref->release(); - } - } - _filters.clear(); -} - -Filter* FilterGroup::_predictTerminalFilter(Filter* filter) { - if (filter->getTargets().size() == 0) - return filter; - else - return _predictTerminalFilter(dynamic_cast(filter->getTargets().begin()->first)); -} - -Source* FilterGroup::addTarget(Target* target) { - if (_terminalFilter) - return _terminalFilter->addTarget(target); - else - return 0; -} - -//#if GI_TARGET_PLATFORM == GI_PLATFORM_IOS -//Source* FilterGroup::addTarget(id target) { -// if (_terminalFilter) -// return _terminalFilter->addTarget(target); -// else -// return 0; -//} -//#endif - -void FilterGroup::removeTarget(Target* target) { - if (_terminalFilter) - _terminalFilter->removeTarget(target); -} - -void FilterGroup::removeAllTargets() { - if (_terminalFilter) - _terminalFilter->removeAllTargets(); -} - -bool FilterGroup::hasTarget(const Target* target) const { - if (_terminalFilter) - return _terminalFilter->hasTarget(target); - else - return false; -} - -std::map& FilterGroup::getTargets() { - assert(_terminalFilter); - return _terminalFilter->getTargets(); -} - -bool FilterGroup::proceed(bool bUpdateTargets/* = true*/) { - - return true; -} - -void FilterGroup::update(float frameTime) { - proceed(); - if (Context::getInstance()->isCapturingFrame && this == Context::getInstance()->captureUpToFilter) { - Context::getInstance()->captureUpToFilter = _terminalFilter; - } - - for(auto& filter : _filters){ - if (filter->isPrepared()) { - filter->update(frameTime); - filter->unPrepear(); - } - } -} - -void FilterGroup::updateTargets(float frameTime) { - if (_terminalFilter) - _terminalFilter->updateTargets(frameTime); -} - -void FilterGroup::setFramebuffer(Framebuffer* fb, RotationMode outputRotation/* = RotationMode::NoRotation*/) { - //if (_terminalFilter) - // _terminalFilter->setFramebuffer(fb); -} - -Framebuffer* FilterGroup::getFramebuffer() const { - //if (_terminalFilter) - // return _terminalFilter->getFramebuffer(); - return 0; -} - -void FilterGroup::setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode/* = NoRotation*/, int texIdx/* = 0*/) { - for (auto& filter : _filters) { - filter->setInputFramebuffer(framebuffer, rotationMode, texIdx); - } -} - -bool FilterGroup::isPrepared() const { -// for (auto& filter : _filters) { -// if (!filter->isPrepared()) -// return false; -// } - return true; -} - -void FilterGroup::unPrepear() { - //for (auto& filter : _filters) { - // filter->unPrepeared(); - //} -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurMonoFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurMonoFilter.cpp deleted file mode 100755 index 80e8b84..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurMonoFilter.cpp +++ /dev/null @@ -1,329 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "GaussianBlurMonoFilter.hpp" -#include "../util.h" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(GaussianBlurMonoFilter) - -GaussianBlurMonoFilter::GaussianBlurMonoFilter(Type type/* = HORIZONTAL*/) -:_type(type) -,_radius(4) -,_sigma(2.0) -{ -} - -GaussianBlurMonoFilter* GaussianBlurMonoFilter::create(Type type/* = HORIZONTAL*/, int radius/* = 4*/, float sigma/* = 2.0*/) { - GaussianBlurMonoFilter* ret = new (std::nothrow) GaussianBlurMonoFilter(type); - if (ret && !ret->init(radius, sigma)) { - delete ret; - ret = 0; - } - return ret; -} - -bool GaussianBlurMonoFilter::init(int radius, float sigma) { - if (Filter::initWithShaderString(_generateOptimizedVertexShaderString(radius, sigma), _generateOptimizedFragmentShaderString(radius, sigma))) { - return true; - } - return false; -} - -void GaussianBlurMonoFilter::setRadius(int radius) { - if (radius == _radius) return; - - _radius = radius; - - if (_filterProgram) { - delete _filterProgram; - _filterProgram = 0; - } - initWithShaderString(_generateOptimizedVertexShaderString(_radius, _sigma), _generateOptimizedFragmentShaderString(_radius, _sigma)); -} - -void GaussianBlurMonoFilter::setSigma(float sigma) { - if (sigma == _sigma) return; - - _sigma = round(sigma); - - int calculatedSampleRadius = 0; - if (_sigma >= 1) // Avoid a divide-by-zero error here - { - // Calculate the number of pixels to sample from by setting a bottom limit for the contribution of the outermost pixel - float minimumWeightToFindEdgeOfSamplingArea = 1.0/256.0; - calculatedSampleRadius = floor(sqrt(-2.0 * pow(_sigma, 2.0) * log(minimumWeightToFindEdgeOfSamplingArea * sqrt(2.0 * M_PI * pow(_sigma, 2.0))) )); - calculatedSampleRadius += calculatedSampleRadius % 2; // There's nothing to gain from handling odd radius sizes, due to the optimizations I use - } - _radius = calculatedSampleRadius; - - if (_filterProgram) { - delete _filterProgram; - _filterProgram = 0; - } - initWithShaderString(_generateOptimizedVertexShaderString(_radius, _sigma), _generateOptimizedFragmentShaderString(_radius, _sigma)); -} - -bool GaussianBlurMonoFilter::proceed(bool bUpdateTargets/* = true*/) { - - RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; - - if (rotationSwapsSize(inputRotation)) - { - if (_type == HORIZONTAL) { - _filterProgram->setUniformValue("texelWidthOffset", (float)0.0); - _filterProgram->setUniformValue("texelHeightOffset", (float)(1.0 / _framebuffer->getWidth())); - } else { - _filterProgram->setUniformValue("texelWidthOffset", (float)(1.0 / _framebuffer->getHeight())); - _filterProgram->setUniformValue("texelHeightOffset", (float)0.0); - } - } else { - if (_type == HORIZONTAL) { - _filterProgram->setUniformValue("texelWidthOffset", (float)(1.0 / _framebuffer->getWidth())); - _filterProgram->setUniformValue("texelHeightOffset", (float)0.0); - } else { - _filterProgram->setUniformValue("texelWidthOffset", (float)0.0); - _filterProgram->setUniformValue("texelHeightOffset", (float)(1.0 / _framebuffer->getHeight())); - } - } - return Filter::proceed(bUpdateTargets); -} - -std::string GaussianBlurMonoFilter::_generateVertexShaderString(int radius, float sigma) { - if (radius < 1 || sigma <= 0.0) - { - return kDefaultVertexShader; - } - - std::string shaderStr = - str_format("\ - attribute vec4 position;\n\ - attribute vec4 texCoord;\n\ - uniform float texelWidthOffset;\n\ - uniform float texelHeightOffset;\n\ - varying vec2 blurCoordinates[%d];\n\ - void main()\n\ - {\n\ - gl_Position = position;\n\ - vec2 texelSpacing = vec2(texelWidthOffset, texelHeightOffset);\n\ - ", radius * 2 + 1); - - for (int i = 0; i < radius * 2 + 1; ++i) { - int offsetFromCenter = i - radius; - if (offsetFromCenter == 0) { - shaderStr = shaderStr + str_format("blurCoordinates[%d] = texCoord.xy;\n", i); - } else { - shaderStr = shaderStr + str_format("blurCoordinates[%d] = texCoord.xy + texelSpacing * (%f);\n", i, (float)offsetFromCenter); - } - } - - shaderStr += "}\n"; - - return shaderStr; -} - -std::string GaussianBlurMonoFilter::_generateFragmentShaderString(int radius, float sigma) { - if (radius < 1 || sigma <= 0.0) - { - return kDefaultFragmentShader; - } - - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = (1.0 / sqrt(2.0 * PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); - - if (i == 0) - { - sumOfWeights += standardGaussianWeights[i]; - } else { - sumOfWeights += 2.0 * standardGaussianWeights[i]; - } - } - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; - } - - std::string shaderStr = - str_format("\ - uniform sampler2D colorMap;\n\ - varying highp vec2 blurCoordinates[%d];\n\ - void main()\n\ - {\n\ - gl_FragColor = vec4(0.0);\n", radius * 2 + 1); - for (int i = 0; i < radius * 2 + 1; ++i) { - int offsetFromCenter = i - radius; - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[%d]) * %f;\n", i, standardGaussianWeights[abs(offsetFromCenter)]); - } - shaderStr += "}"; - - delete[] standardGaussianWeights; standardGaussianWeights = 0; - - return shaderStr; -} - -std::string GaussianBlurMonoFilter::_generateOptimizedVertexShaderString(int radius, float sigma) -{ - if (radius < 1 || sigma <= 0.0) - { - return kDefaultVertexShader; - } - - // 1. generate the normal Gaussian weights for a given sigma - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); - if (i == 0) - sumOfWeights += standardGaussianWeights[i]; - else - sumOfWeights += 2.0 * standardGaussianWeights[i]; - } - - // 2. normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; - } - - // 3. From these weights we calculate the offsets to read interpolated values from - int numberOfOptimizedOffsets = fmin(radius / 2 + (radius % 2), 7); - float* optimizedGaussianOffsets = new float[numberOfOptimizedOffsets]; - - for (int i = 0; i < numberOfOptimizedOffsets; ++i) - { - GLfloat firstWeight = standardGaussianWeights[i * 2 + 1]; - GLfloat secondWeight = standardGaussianWeights[i * 2 + 2]; - - GLfloat optimizedWeight = firstWeight + secondWeight; - - optimizedGaussianOffsets[i] = (firstWeight * (i * 2 + 1) + secondWeight * (i * 2 + 2)) / optimizedWeight; - } - - std::string shaderStr = - str_format("\ - attribute vec4 position;\n\ - attribute vec4 texCoord;\n\ - uniform float texelWidthOffset;\n\ - uniform float texelHeightOffset;\n\ - varying highp vec2 blurCoordinates[%d];\n\ - void main()\n\ - {\n\ - gl_Position = position;\n\ - vec2 texelSpacing = vec2(texelWidthOffset, texelHeightOffset);\n\ - ", numberOfOptimizedOffsets * 2 + 1); - - shaderStr = shaderStr + str_format("blurCoordinates[0] = texCoord.xy;\n"); - for (int i = 0; i < numberOfOptimizedOffsets; ++i) { - shaderStr = shaderStr + str_format( - "blurCoordinates[%d] = texCoord.xy + texelSpacing * (%f);\n\ - blurCoordinates[%d] = texCoord.xy - texelSpacing * (%f);", - i * 2 + 1, - optimizedGaussianOffsets[i], - i * 2 + 2, - optimizedGaussianOffsets[i]); - } - - shaderStr += "}\n"; - - delete[] standardGaussianWeights; - delete[] optimizedGaussianOffsets; - - return shaderStr; -} - -std::string GaussianBlurMonoFilter::_generateOptimizedFragmentShaderString(int radius, float sigma) -{ - if (radius < 1 || sigma <= 0.0) - { - return kDefaultFragmentShader; - } - - // 1. generate the normal Gaussian weights for a given sigma - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); - if (i == 0) - sumOfWeights += standardGaussianWeights[i]; - else - sumOfWeights += 2.0 * standardGaussianWeights[i]; - } - - // 2. normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; - } - - // 3. From these weights we calculate the offsets to read interpolated values from - int trueNumberOfOptimizedOffsets = radius / 2 + (radius % 2); - int numberOfOptimizedOffsets = fmin(trueNumberOfOptimizedOffsets, 7); - - std::string shaderStr = - str_format("\ - uniform sampler2D colorMap;\n\ - uniform highp float texelWidthOffset;\n\ - uniform highp float texelHeightOffset;\n\ - varying highp vec2 blurCoordinates[%d];\n\ - void main()\n\ - {\n\ - gl_FragColor = vec4(0.0);\n", numberOfOptimizedOffsets * 2 + 1); - - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[0]) * %f;\n", standardGaussianWeights[0]); - for (int i = 0; i < numberOfOptimizedOffsets; ++i) { - float firstWeight = standardGaussianWeights[i * 2 + 1]; - float secondWeight = standardGaussianWeights[i * 2 + 2]; - float optimizedWeight = firstWeight + secondWeight; - - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[%d]) * %f;\n", i * 2 + 1, optimizedWeight); - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[%d]) * %f;\n", i * 2 + 2, optimizedWeight); - } - - // If the number of required samples exceeds the amount we can pass in via varyings, we have to do dependent texture reads in the fragment shader - if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) - { - shaderStr += str_format("highp vec2 texelSpacing = vec2(texelWidthOffset, texelHeightOffset);\n"); - - for (int i = numberOfOptimizedOffsets; i < trueNumberOfOptimizedOffsets; i++) - { - float firstWeight = standardGaussianWeights[i * 2 + 1]; - float secondWeight = standardGaussianWeights[i * 2 + 2]; - - float optimizedWeight = firstWeight + secondWeight; - float optimizedOffset = (firstWeight * (i * 2 + 1) + secondWeight * (i * 2 + 2)) / optimizedWeight; - - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[0] + texelSpacing * %f) * %f;\n", optimizedOffset, optimizedWeight); - - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[0] - texelSpacing * %f) * %f;\n", optimizedOffset, optimizedWeight); - } - } - - shaderStr += "}"; - - delete[] standardGaussianWeights; standardGaussianWeights = 0; - return shaderStr; -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HSBFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HSBFilter.cpp deleted file mode 100755 index e21dc63..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HSBFilter.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "HSBFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(HSBFilter) - -/* Matrix algorithms adapted from http://www.graficaobscura.com/matrix/index.html - - Note about luminance vector values below from that page: - Where rwgt is 0.3086, gwgt is 0.6094, and bwgt is 0.0820. This is the luminance vector. Notice here that we do not use the standard NTSC weights of 0.299, 0.587, and 0.114. The NTSC weights are only applicable to RGB colors in a gamma 2.2 color space. For linear RGB colors the values above are better. - */ -//#define RLUM (0.3086f) -//#define GLUM (0.6094f) -//#define BLUM (0.0820f) - -/* This is the vector value from the PDF specification, and may be closer to what Photoshop uses */ -#define RLUM (0.3f) -#define GLUM (0.59f) -#define BLUM (0.11f) - - -HSBFilter* HSBFilter::create() { - HSBFilter* ret = new (std::nothrow) HSBFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool HSBFilter::init() { - if (!ColorMatrixFilter::init()) return false; - reset(); - - return true; -} - -void HSBFilter::reset() { - setColorMatrix(Matrix4::IDENTITY); -} - -void HSBFilter::rotateHue(float h){ - // todo -} - -void HSBFilter::adjustSaturation(float sat) { - - Matrix4 sMat; - float rwgt = RLUM; - float gwgt = GLUM; - float bwgt = BLUM; - - sMat.m[0] = (1.0 - sat) * rwgt + sat; - sMat.m[1] = (1.0 - sat) * rwgt; - sMat.m[2] = (1.0 - sat) * rwgt; - sMat.m[3] = 0.0; - sMat.m[4] = (1.0 - sat) * gwgt; - sMat.m[5] = (1.0 - sat) * gwgt + sat; - sMat.m[6] = (1.0 - sat) * gwgt; - sMat.m[7] = 0.0; - sMat.m[8] = (1.0 - sat) * bwgt; - sMat.m[9] = (1.0 - sat) * bwgt; - sMat.m[10] = (1.0 - sat) * bwgt + sat; - sMat.m[11] = 0.0; - sMat.m[12] = 0.0; - sMat.m[13] = 0.0; - sMat.m[14] = 0.0; - sMat.m[15] = 1.0; - - _colorMatrix = sMat * _colorMatrix; -} - -void HSBFilter::adjustBrightness(float b) { - Matrix4 scaleMatrix = Matrix4::IDENTITY; - scaleMatrix *= b; - _colorMatrix *= scaleMatrix; - -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HalftoneFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HalftoneFilter.cpp deleted file mode 100755 index 08d28fa..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HalftoneFilter.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "HalftoneFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(HalftoneFilter) - -const std::string kHalftoneFragmentShaderString = SHADER_STRING -( - uniform highp float pixelSize; - uniform highp float aspectRatio; - - uniform sampler2D colorMap; - varying highp vec2 vTexCoord; - - const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); - - void main() - { - highp vec2 pixelSizeVec = vec2(pixelSize, pixelSize / aspectRatio); - highp vec2 samplePos = floor(vTexCoord / pixelSizeVec) * pixelSizeVec + 0.5 * pixelSizeVec; - - highp vec2 textureCoordinateToUse = vec2(vTexCoord.x, (vTexCoord.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); - highp vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); - highp float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse); - lowp vec3 sampledColor = texture2D(colorMap, samplePos ).rgb; - highp float dotScaling = 1.0 - dot(sampledColor, W); - - lowp float checkForPresenceWithinDot = 1.0 - step(distanceFromSamplePoint, (pixelSize * 0.5) * dotScaling); - - gl_FragColor = vec4(vec3(checkForPresenceWithinDot), 1.0); - } - ); - - - -HalftoneFilter* HalftoneFilter::create() { - HalftoneFilter* ret = new (std::nothrow) HalftoneFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool HalftoneFilter::init() { - if (!initWithFragmentShaderString(kHalftoneFragmentShaderString)) return false; - - setPixelSize(0.01); - registerProperty("pixelSize", _pixelSize, "The size of a pixel that you want to pixellate, ranges from 0 to 0.05.", [this](float& pixelSize){ - setPixelSize(pixelSize); - }); - - return true; -} diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HueFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HueFilter.cpp deleted file mode 100755 index 48f554a..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HueFilter.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "HueFilter.hpp" -#include - -USING_NS_GI - -REGISTER_FILTER_CLASS(HueFilter) - -// Adapted from http://stackoverflow.com/questions/9234724/how-to-change-hue-of-a-texture-with-glsl - see for code and discussion -const std::string kHueFragmentShaderString = SHADER_STRING -( - precision highp float; - uniform sampler2D colorMap; - uniform mediump float hueAdjustment; - varying highp vec2 vTexCoord; - const highp vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0); - const highp vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0); - const highp vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0); - const highp vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0); - const highp vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0); - const highp vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0); - - void main() - { - // Sample the input pixel - highp vec4 color = texture2D(colorMap, vTexCoord); - - // Convert to YIQ - highp float YPrime = dot(color, kRGBToYPrime); - highp float I = dot(color, kRGBToI); - highp float Q = dot(color, kRGBToQ); - - // Calculate the hue and chroma - highp float hue = atan(Q, I); - highp float chroma = sqrt(I * I + Q * Q); - - // Make the user's adjustments - hue += (-hueAdjustment); //why negative rotation? - - // Convert back to YIQ - Q = chroma * sin (hue); - I = chroma * cos (hue); - - // Convert back to RGB - highp vec4 yIQ = vec4 (YPrime, I, Q, 0.0); - color.r = dot(yIQ, kYIQToR); - color.g = dot(yIQ, kYIQToG); - color.b = dot(yIQ, kYIQToB); - - // Save the result - gl_FragColor = color; - } -); - - -HueFilter* HueFilter::create() { - HueFilter* ret = new (std::nothrow) HueFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool HueFilter::init() { - if (!initWithFragmentShaderString(kHueFragmentShaderString)) return false; - - _hueAdjustment = 90; - registerProperty("hueAdjustment", _hueAdjustment, "The hueAdjustment (in degree) of the image", [this](float& hueAdjustment){ - setHueAdjustment(hueAdjustment); - }); - - return true; -} - -void HueFilter::setHueAdjustment(float hueAdjustment) { - // Convert degrees to radians for hue rotation - _hueAdjustment = fmodf(hueAdjustment, 360.0) * M_PI/180; -} - -bool HueFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("hueAdjustment", _hueAdjustment); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/IOSBlurFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/IOSBlurFilter.cpp deleted file mode 100755 index 121291d..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/IOSBlurFilter.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "IOSBlurFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(IOSBlurFilter) - -IOSBlurFilter::IOSBlurFilter() -:_saturationFilter(0) -,_blurFilter(0) -,_luminanceRangeFilter(0) -{ -} - -IOSBlurFilter::~IOSBlurFilter() { - if (_saturationFilter) { - _saturationFilter->release(); - _saturationFilter = 0; - } - - if (_blurFilter) { - _blurFilter->release(); - _blurFilter = 0; - } - - if (_luminanceRangeFilter) { - _luminanceRangeFilter->release(); - _luminanceRangeFilter = 0; - } -} - -IOSBlurFilter* IOSBlurFilter::create() { - IOSBlurFilter* ret = new (std::nothrow) IOSBlurFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool IOSBlurFilter::init() { - if (!FilterGroup::init()) { - return false; - } - - _saturationFilter = SaturationFilter::create(); - _blurFilter = GaussianBlurFilter::create(); - _luminanceRangeFilter = LuminanceRangeFilter::create(); - - _saturationFilter // 1. downsample and desaturate - ->addTarget(_blurFilter) // 2. apply a strong Gaussian blur - ->addTarget(_luminanceRangeFilter); // 3. upsample and adjust luminance range - - addFilter(_saturationFilter); - - _blurSigma = 12.0; - setBlurSigma(_blurSigma); - registerProperty("blurSigma", _blurSigma, "", [this](float& blurSigma){ - setBlurSigma(blurSigma); - }); - - _saturation = 0.8; - setSaturation(_saturation); - registerProperty("saturation", _saturation, "", [this](float& saturation){ - setSaturation(saturation); - }); - - _rangeReductionFactor = 0.6; - setRangeReductionFactor(_rangeReductionFactor); - registerProperty("rangeReductionFactor", _rangeReductionFactor, "", [this](float& rangeReductionFactor){ - setRangeReductionFactor(rangeReductionFactor); - }); - - _downSampling = 4.0; - setDownSampling(_downSampling); - registerProperty("downSampling", _downSampling, "", [this](float& downSampling){ - setDownSampling(downSampling); - }); - - return true; -} - - -void IOSBlurFilter::setBlurSigma(float blurSigma) { - _blurSigma = blurSigma; - _blurFilter->setSigma(blurSigma); -} - -void IOSBlurFilter::setSaturation(float saturation) { - _saturation = saturation; - _saturationFilter->setSaturation(saturation); -} - -void IOSBlurFilter::setRangeReductionFactor(float rangeReductionFactor) { - _rangeReductionFactor = rangeReductionFactor; - _luminanceRangeFilter->setRangeReductionFactor(rangeReductionFactor); -} - -void IOSBlurFilter::setDownSampling(float downSampling) { - _downSampling = downSampling; - _saturationFilter->setFramebufferScale(1 / downSampling); - _luminanceRangeFilter->setFramebufferScale(downSampling); -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/LuminanceRangeFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/LuminanceRangeFilter.cpp deleted file mode 100755 index 7f1a046..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/LuminanceRangeFilter.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "LuminanceRangeFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(LuminanceRangeFilter) - -const std::string kLuminanceRangeFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float rangeReductionFactor; - varying highp vec2 vTexCoord; - - // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham - const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - mediump float luminance = dot(color.rgb, luminanceWeighting); - mediump float luminanceRatio = ((0.5 - luminance) * rangeReductionFactor); - gl_FragColor = vec4((color.rgb) + (luminanceRatio), color.a); - } -); - -LuminanceRangeFilter* LuminanceRangeFilter::create() { - LuminanceRangeFilter* ret = new (std::nothrow) LuminanceRangeFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool LuminanceRangeFilter::init() { - if (!initWithFragmentShaderString(kLuminanceRangeFragmentShaderString)) return false; - - _rangeReductionFactor = 0.6; - registerProperty("rangeReductionFactor", _rangeReductionFactor, "The degree to reduce the luminance range, from 0.0 to 1.0. Default is 0.6.", [this](float& rangeReductionFactor){ - setRangeReductionFactor(rangeReductionFactor); - }); - - return true; -} - -void LuminanceRangeFilter::setRangeReductionFactor(float rangeReductionFactor) { - _rangeReductionFactor = rangeReductionFactor; - if (_rangeReductionFactor > 1.0) _rangeReductionFactor = 1.0; - else if (_rangeReductionFactor < 0.0) _rangeReductionFactor = 0.0; -} - -bool LuminanceRangeFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("rangeReductionFactor", _rangeReductionFactor); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NonMaximumSuppressionFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NonMaximumSuppressionFilter.cpp deleted file mode 100755 index 2b09b0e..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NonMaximumSuppressionFilter.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "NonMaximumSuppressionFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(NonMaximumSuppressionFilter) - -const std::string kNonMaximumSuppressionShaderString = SHADER_STRING -( - precision mediump float; - uniform sampler2D colorMap; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - void main() - { - float bottomLeftIntensity = texture2D(colorMap, vBottomLeftTexCoord).r; - float topRightIntensity = texture2D(colorMap, vTopRightTexCoord).r; - float topLeftIntensity = texture2D(colorMap, vTopLeftTexCoord).r; - float bottomRightIntensity = texture2D(colorMap, vBottomRightTexCoord).r; - float leftIntensity = texture2D(colorMap, vLeftTexCoord).r; - float rightIntensity = texture2D(colorMap, vRightTexCoord).r; - float bottomIntensity = texture2D(colorMap, vBottomTexCoord).r; - float topIntensity = texture2D(colorMap, vTopTexCoord).r; - lowp vec4 centerColor = texture2D(colorMap, vTexCoord); - - // Use a tiebreaker for pixels to the left and immediately above this one - lowp float multiplier = 1.0 - step(centerColor.r, topIntensity); - multiplier = multiplier * (1.0 - step(centerColor.r, topLeftIntensity)); - multiplier = multiplier * (1.0 - step(centerColor.r, leftIntensity)); - multiplier = multiplier * (1.0 - step(centerColor.r, bottomLeftIntensity)); - - lowp float maxValue = max(centerColor.r, bottomIntensity); - maxValue = max(maxValue, bottomRightIntensity); - maxValue = max(maxValue, rightIntensity); - maxValue = max(maxValue, topRightIntensity); - - gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0); - - } - ); - - -NonMaximumSuppressionFilter* NonMaximumSuppressionFilter::create() { - NonMaximumSuppressionFilter* ret = new (std::nothrow) NonMaximumSuppressionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool NonMaximumSuppressionFilter::init() { - if (initWithFragmentShaderString(kNonMaximumSuppressionShaderString)) { - return true; - } - return false; -} - - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PosterizeFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PosterizeFilter.cpp deleted file mode 100755 index 0b2817c..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PosterizeFilter.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "PosterizeFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(PosterizeFilter) - -const std::string kPosterizeFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform highp float colorLevels; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - - gl_FragColor = floor((color * colorLevels) + vec4(0.5)) / colorLevels; - } -); - - -PosterizeFilter* PosterizeFilter::create() { - PosterizeFilter* ret = new (std::nothrow) PosterizeFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool PosterizeFilter::init() { - if (!initWithFragmentShaderString(kPosterizeFragmentShaderString)) return false; - - _colorLevels = 10; - registerProperty("colorLevels", _colorLevels, "The number of color levels to reduce the image space to. This ranges from 1 to 256, with a default of 10.", [this](int& colorLevels){ - setColorLevels(colorLevels); - }); - - return true; -} - -void PosterizeFilter::setColorLevels(int colorLevels) { - _colorLevels = colorLevels; - if (_colorLevels > 256) _colorLevels = 256; - else if (_colorLevels < 1) _colorLevels = 1; -} - -bool PosterizeFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("colorLevels", (float)_colorLevels); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SaturationFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SaturationFilter.cpp deleted file mode 100755 index f9b4b8e..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SaturationFilter.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SaturationFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(SaturationFilter) - -const std::string kSaturationFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float saturation; - varying highp vec2 vTexCoord; - - // Values from "Graphics Shaders: Theory and Practice" by Bailey and Cunningham - const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - lowp float luminance = dot(color.rgb, luminanceWeighting); - lowp vec3 greyScaleColor = vec3(luminance); - - gl_FragColor = vec4(mix(greyScaleColor, color.rgb, saturation), color.a); - } -); - - -SaturationFilter* SaturationFilter::create() { - SaturationFilter* ret = new (std::nothrow) SaturationFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool SaturationFilter::init() { - if (!initWithFragmentShaderString(kSaturationFragmentShaderString)) return false; - - _saturation = 1.0; - registerProperty("saturation", _saturation, "The saturation of an image. Saturation ranges from 0.0 (fully desaturated) to 2.0 (max saturation), with 1.0 as the normal level", [this](float& saturation){ - setSaturation(saturation); - }); - - return true; -} - -void SaturationFilter::setSaturation(float saturation) { - _saturation = saturation; - if (_saturation > 2.0) _saturation = 2.0; - else if (_saturation < 0.0) _saturation = 0.0; -} - -bool SaturationFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("saturation", _saturation); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SketchFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SketchFilter.cpp deleted file mode 100755 index 1b7f260..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SketchFilter.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SketchFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(SketchFilter) - -const std::string kSketchFilterFragmentShaderString = SHADER_STRING -( - precision mediump float; - uniform sampler2D colorMap; - uniform float edgeStrength; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - void main() - { - float bottomLeftIntensity = texture2D(colorMap, vBottomLeftTexCoord).r; - float topRightIntensity = texture2D(colorMap, vTopRightTexCoord).r; - float topLeftIntensity = texture2D(colorMap, vTopLeftTexCoord).r; - float bottomRightIntensity = texture2D(colorMap, vBottomRightTexCoord).r; - float leftIntensity = texture2D(colorMap, vLeftTexCoord).r; - float rightIntensity = texture2D(colorMap, vRightTexCoord).r; - float bottomIntensity = texture2D(colorMap, vBottomTexCoord).r; - float topIntensity = texture2D(colorMap, vTopTexCoord).r; - float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; - float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; - - float mag = 1.0 - length(vec2(h, v)) * edgeStrength; - gl_FragColor = vec4(vec3(mag), 1.0); - } - ); - -SketchFilter::SketchFilter() -:_grayscaleFilter(0) -,_sketchFilter(0) -{ - -} - -SketchFilter::~SketchFilter() -{ - if (_grayscaleFilter) { - _grayscaleFilter->release(); - _grayscaleFilter = 0; - } - if (_sketchFilter) { - _sketchFilter->release(); - _sketchFilter = 0; - } -} - -SketchFilter* SketchFilter::create() { - SketchFilter* ret = new (std::nothrow) SketchFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - -bool SketchFilter::init() { - if (!FilterGroup::init()) { - return false; - } - - _grayscaleFilter = GrayscaleFilter::create(); - _sketchFilter = _SketchFilter::create(); - _grayscaleFilter->addTarget(_sketchFilter); - addFilter(_grayscaleFilter); - - - _edgeStrength = 1.0; - registerProperty("edgeStrength", _edgeStrength, "The edge strength of sobel edge detection filter", [this](float& edgeStrength){ - _sketchFilter->setEdgeStrength(edgeStrength); - }); - - return true; -} - -_SketchFilter* _SketchFilter::create() { - _SketchFilter* ret = new (std::nothrow) _SketchFilter(); - if (!ret || !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - -bool _SketchFilter::init() { - if (!initWithFragmentShaderString(kSketchFilterFragmentShaderString)) { - return false; - } - _edgeStrength = 1.0; - return true; -} - -void _SketchFilter::setEdgeStrength(float edgeStrength) { - _edgeStrength = edgeStrength; -} - -bool _SketchFilter::proceed(bool bUpdateTargets/* = true*/) { - float texelWidth = 1.0 / _framebuffer->getWidth(); - float texelHeight = 1.0 / _framebuffer->getHeight(); - - Framebuffer* inputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; - if (rotationSwapsSize(inputRotation)){ - texelWidth = 1.0 / _framebuffer->getHeight(); - texelHeight = 1.0 / _framebuffer->getWidth(); - } - - _filterProgram->setUniformValue("texelWidth", texelWidth); - _filterProgram->setUniformValue("texelHeight", texelHeight); - _filterProgram->setUniformValue("edgeStrength", _edgeStrength); - return NearbySampling3x3Filter::proceed(bUpdateTargets); -} - - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SmoothToonFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SmoothToonFilter.cpp deleted file mode 100755 index 8f8d367..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SmoothToonFilter.cpp +++ /dev/null @@ -1,99 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SmoothToonFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(SmoothToonFilter) - -SmoothToonFilter::SmoothToonFilter() -:_gaussianBlurFilter(0) -,_toonFilter(0) -{ -} - -SmoothToonFilter::~SmoothToonFilter() { - if (_gaussianBlurFilter) { - _gaussianBlurFilter->release(); - _gaussianBlurFilter = 0; - } - - if (_toonFilter) { - _toonFilter->release(); - _toonFilter = 0; - } - -} - -SmoothToonFilter* SmoothToonFilter::create() { - SmoothToonFilter* ret = new (std::nothrow) SmoothToonFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool SmoothToonFilter::init() { - if (!FilterGroup::init()) { - return false; - } - _gaussianBlurFilter = GaussianBlurFilter::create(); - _toonFilter = ToonFilter::create(); - _gaussianBlurFilter->addTarget(_toonFilter); - addFilter(_gaussianBlurFilter); - - - _blurRadius = 2.0; - setBlurRadius(_blurRadius); - registerProperty("blurRadius", _blurRadius, "", [this](int& blurRadius){ - setBlurRadius(blurRadius); - }); - - _toonThreshold = 0.2; - registerProperty("toonThreshold", _toonThreshold, "The threshold at which to apply the edges", [this](float& toonThreshold){ - setToonThreshold(toonThreshold); - }); - - _toonQuantizationLevels = 10.0; - registerProperty("toonQuantizationLevels", _toonQuantizationLevels, "The levels of quantization for the posterization of colors within the scene", [this](float& toonQuantizationLevels){ - setToonQuantizationLevels(toonQuantizationLevels); - }); - - - return true; -} - -void SmoothToonFilter::setBlurRadius(int blurRadius) { - _blurRadius = blurRadius; - _gaussianBlurFilter->setRadius(_blurRadius); -} - -void SmoothToonFilter::setToonThreshold(float toonThreshold) { - _toonThreshold = toonThreshold; - _toonFilter->setThreshold(_toonThreshold); -} - -void SmoothToonFilter::setToonQuantizationLevels(float toonQuantizationLevels) { - _toonQuantizationLevels = toonQuantizationLevels; - _toonFilter->setQuantizatinLevels(_toonQuantizationLevels); -} - - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SobelEdgeDetectionFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SobelEdgeDetectionFilter.cpp deleted file mode 100755 index 1a4edcf..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SobelEdgeDetectionFilter.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SobelEdgeDetectionFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(SobelEdgeDetectionFilter) - -// Code from "Graphics Shaders: Theory and Practice" by M. Bailey and S. Cunningham -const std::string kSobelEdgeDetectionFragmentShaderString = SHADER_STRING -( - precision mediump float; - uniform sampler2D colorMap; - uniform float edgeStrength; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - void main() - { - float bottomLeftIntensity = texture2D(colorMap, vBottomLeftTexCoord).r; - float topRightIntensity = texture2D(colorMap, vTopRightTexCoord).r; - float topLeftIntensity = texture2D(colorMap, vTopLeftTexCoord).r; - float bottomRightIntensity = texture2D(colorMap, vBottomRightTexCoord).r; - float leftIntensity = texture2D(colorMap, vLeftTexCoord).r; - float rightIntensity = texture2D(colorMap, vRightTexCoord).r; - float bottomIntensity = texture2D(colorMap, vBottomTexCoord).r; - float topIntensity = texture2D(colorMap, vTopTexCoord).r; - float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; - float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; - - float mag = length(vec2(h, v)) * edgeStrength; - gl_FragColor = vec4(vec3(mag), 1.0); - } - ); - -SobelEdgeDetectionFilter::SobelEdgeDetectionFilter() -:_grayscaleFilter(0) -,_sobelEdgeDetectionFilter(0) -{ -} - -SobelEdgeDetectionFilter::~SobelEdgeDetectionFilter() { - if (_grayscaleFilter) { - _grayscaleFilter->release(); - _grayscaleFilter = 0; - } - if (_sobelEdgeDetectionFilter) { - _sobelEdgeDetectionFilter->release(); - _sobelEdgeDetectionFilter = 0; - } -} - -SobelEdgeDetectionFilter* SobelEdgeDetectionFilter::create() { - SobelEdgeDetectionFilter* ret = new (std::nothrow) SobelEdgeDetectionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - -bool SobelEdgeDetectionFilter::init() { - if (!FilterGroup::init()) { - return false; - } - - _grayscaleFilter = GrayscaleFilter::create(); - _sobelEdgeDetectionFilter = _SobelEdgeDetectionFilter::create(); - _grayscaleFilter->addTarget(_sobelEdgeDetectionFilter); - addFilter(_grayscaleFilter); - - - _edgeStrength = 1.0; - registerProperty("edgeStrength", _edgeStrength, "The edge strength of sobel edge detection filter", [this](float& edgeStrength){ - _sobelEdgeDetectionFilter->setEdgeStrength(edgeStrength); - }); - - return true; -} - -_SobelEdgeDetectionFilter* _SobelEdgeDetectionFilter::create() { - _SobelEdgeDetectionFilter* ret = new (std::nothrow) _SobelEdgeDetectionFilter(); - if (!ret || !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - -bool _SobelEdgeDetectionFilter::init() { - if (!initWithFragmentShaderString(kSobelEdgeDetectionFragmentShaderString)) { - return false; - } - _edgeStrength = 1.0; - return true; -} - -void _SobelEdgeDetectionFilter::setEdgeStrength(float edgeStrength) { - _edgeStrength = edgeStrength; -} - -bool _SobelEdgeDetectionFilter::proceed(bool bUpdateTargets/* = true*/) { - float texelWidth = 1.0 / _framebuffer->getWidth(); - float texelHeight = 1.0 / _framebuffer->getHeight(); - - Framebuffer* inputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; - if (rotationSwapsSize(inputRotation)){ - texelWidth = 1.0 / _framebuffer->getHeight(); - texelHeight = 1.0 / _framebuffer->getWidth(); - } - - _filterProgram->setUniformValue("texelWidth", texelWidth); - _filterProgram->setUniformValue("texelHeight", texelHeight); - _filterProgram->setUniformValue("edgeStrength", _edgeStrength); - return NearbySampling3x3Filter::proceed(bUpdateTargets); -} - - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ToonFilter.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ToonFilter.cpp deleted file mode 100755 index 8257ee8..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ToonFilter.cpp +++ /dev/null @@ -1,107 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ToonFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(ToonFilter) - -const std::string kToonFragmentShaderString = SHADER_STRING -( - precision mediump float; - uniform sampler2D colorMap; - uniform float threshold; - uniform float quantizationLevels; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - void main() - { - float bottomLeftIntensity = texture2D(colorMap, vBottomLeftTexCoord).r; - float topRightIntensity = texture2D(colorMap, vTopRightTexCoord).r; - float topLeftIntensity = texture2D(colorMap, vTopLeftTexCoord).r; - float bottomRightIntensity = texture2D(colorMap, vBottomRightTexCoord).r; - float leftIntensity = texture2D(colorMap, vLeftTexCoord).r; - float rightIntensity = texture2D(colorMap, vRightTexCoord).r; - float bottomIntensity = texture2D(colorMap, vBottomTexCoord).r; - float topIntensity = texture2D(colorMap, vTopTexCoord).r; - float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity; - float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity; - - float mag = length(vec2(h, v)); - - vec4 color = texture2D(colorMap, vTexCoord); - vec3 posterizedImageColor = (floor(color.rgb * quantizationLevels) + 0.5) / quantizationLevels; - - float thresholdTest = 1.0 - step(threshold, mag); - - gl_FragColor = vec4(posterizedImageColor * thresholdTest, color.a); - } - ); - - -ToonFilter* ToonFilter::create() { - ToonFilter* ret = new (std::nothrow) ToonFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool ToonFilter::init() { - if (!initWithFragmentShaderString(kToonFragmentShaderString)) return false; - - _threshold = 0.2; - registerProperty("threshold", _threshold, "The threshold at which to apply the edges", [this](float& threshold){ - setThreshold(threshold); - }); - - _quantizationLevels = 10.0; - registerProperty("quantizationLevels", _quantizationLevels, "The levels of quantization for the posterization of colors within the scene", [this](float& quantizationLevels){ - setQuantizatinLevels(quantizationLevels); - }); - - return true; -} - -void ToonFilter::setThreshold(float threshold) { - _threshold = threshold; -} - -void ToonFilter::setQuantizatinLevels(float quantizationLevels) { - _quantizationLevels = quantizationLevels; -} - -bool ToonFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("threshold", _threshold); - _filterProgram->setUniformValue("quantizationLevels", _quantizationLevels); - return NearbySampling3x3Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/math.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/math.cpp deleted file mode 100755 index 8096794..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/math.cpp +++ /dev/null @@ -1,818 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "math.hpp" -#include -#include - -NS_GI_BEGIN - -Vector2::Vector2() -: x(0.0f), y(0.0f) -{ -} - -Vector2::Vector2(float xx, float yy) -: x(xx), y(yy) -{ -} - -Vector2::Vector2(const float* array) -{ - set(array); -} - -Vector2::Vector2(const Vector2& p1, const Vector2& p2) -{ - set(p1, p2); -} - -Vector2::Vector2(const Vector2& copy) -{ - set(copy); -} - -Vector2::~Vector2() -{ -} - -bool Vector2::isZero() const -{ - return x == 0.0f && y == 0.0f; -} - -bool Vector2::isOne() const -{ - return x == 1.0f && y == 1.0f; -} - -void Vector2::add(const Vector2& v) -{ - x += v.x; - y += v.y; -} - -float Vector2::distanceSquared(const Vector2& v) const -{ - float dx = v.x - x; - float dy = v.y - y; - return (dx * dx + dy * dy); -} - -float Vector2::dot(const Vector2& v) const -{ - return (x * v.x + y * v.y); -} - -float Vector2::lengthSquared() const -{ - return (x * x + y * y); -} - -void Vector2::negate() -{ - x = -x; - y = -y; -} - -void Vector2::scale(float scalar) -{ - x *= scalar; - y *= scalar; -} - -void Vector2::scale(const Vector2& scale) -{ - x *= scale.x; - y *= scale.y; -} - -void Vector2::set(float xx, float yy) -{ - this->x = xx; - this->y = yy; -} - -void Vector2::set(const Vector2& v) -{ - this->x = v.x; - this->y = v.y; -} - -void Vector2::set(const Vector2& p1, const Vector2& p2) -{ - x = p2.x - p1.x; - y = p2.y - p1.y; -} - -void Vector2::setZero() -{ - x = y = 0.0f; -} - -void Vector2::subtract(const Vector2& v) -{ - x -= v.x; - y -= v.y; -} - -void Vector2::smooth(const Vector2& target, float elapsedTime, float responseTime) -{ - if (elapsedTime > 0) - { - *this += (target - *this) * (elapsedTime / (elapsedTime + responseTime)); - } -} - -const Vector2 Vector2::operator+(const Vector2& v) const -{ - Vector2 result(*this); - result.add(v); - return result; -} - -Vector2& Vector2::operator+=(const Vector2& v) -{ - add(v); - return *this; -} - -const Vector2 Vector2::operator-(const Vector2& v) const -{ - Vector2 result(*this); - result.subtract(v); - return result; -} - -Vector2& Vector2::operator-=(const Vector2& v) -{ - subtract(v); - return *this; -} - -const Vector2 Vector2::operator-() const -{ - Vector2 result(*this); - result.negate(); - return result; -} - -const Vector2 Vector2::operator*(float s) const -{ - Vector2 result(*this); - result.scale(s); - return result; -} - -Vector2& Vector2::operator*=(float s) -{ - scale(s); - return *this; -} - -const Vector2 Vector2::operator/(const float s) const -{ - return Vector2(this->x / s, this->y / s); -} - -bool Vector2::operator<(const Vector2& v) const -{ - if (x == v.x) - { - return y < v.y; - } - return x < v.x; -} - -bool Vector2::operator>(const Vector2& v) const -{ - if (x == v.x) - { - return y > v.y; - } - return x > v.x; -} - -bool Vector2::operator==(const Vector2& v) const -{ - return x==v.x && y==v.y; -} - -bool Vector2::operator!=(const Vector2& v) const -{ - return x!=v.x || y!=v.y; -} - -const Vector2 operator*(float x, const Vector2& v) -{ - Vector2 result(v); - result.scale(x); - return result; -} - - -const Matrix4 Matrix4::IDENTITY = Matrix4( - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); - -Matrix4::Matrix4() { - *this = IDENTITY; -} - -Matrix4::Matrix4(const float* mat) { - set(mat); -} - -Matrix4::Matrix4(float m11, float m12, float m13, float m14, float m21, float m22, float m23,float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { - set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); -} - -Matrix4::Matrix4(const Matrix4& copy) { - memcpy(m, copy.m, sizeof(float) * 16); -} - -Matrix4::~Matrix4() { - -} - -void Matrix4::set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { - m[0] = m11; - m[1] = m21; - m[2] = m31; - m[3] = m41; - m[4] = m12; - m[5] = m22; - m[6] = m32; - m[7] = m42; - m[8] = m13; - m[9] = m23; - m[10] = m33; - m[11] = m43; - m[12] = m14; - m[13] = m24; - m[14] = m34; - m[15] = m44; -} - -void Matrix4::set(const float* mat) { - assert(mat); - memcpy(this->m, mat, sizeof(float) * 16); -} - -void Matrix4::set(const Matrix4& mat) { - memcpy(this->m, mat.m, sizeof(float) * 16); -} - -void Matrix4::setIdentity() { - memcpy(m, &IDENTITY, sizeof(float) * 16); -} - -void Matrix4::negate() -{ - m[0] = -m[0]; - m[1] = -m[1]; - m[2] = -m[2]; - m[3] = -m[3]; - m[4] = -m[4]; - m[5] = -m[5]; - m[6] = -m[6]; - m[7] = -m[7]; - m[8] = -m[8]; - m[9] = -m[9]; - m[10] = -m[10]; - m[11] = -m[11]; - m[12] = -m[12]; - m[13] = -m[13]; - m[14] = -m[14]; - m[15] = -m[15]; -} - -Matrix4 Matrix4::getNegated() const -{ - Matrix4 mat(*this); - mat.negate(); - return mat; -} - -void Matrix4::transpose() { - float tmp; - tmp = m[1]; m[1] = m[4]; m[4] = tmp; - tmp = m[2]; m[2] = m[8]; m[8] = tmp; - tmp = m[6]; m[6] = m[9]; m[9] = tmp; - tmp = m[3]; m[3] = m[12]; m[12] = tmp; - tmp = m[7]; m[7] = m[13]; m[13] = tmp; - tmp = m[11]; m[11] = m[14]; m[14] = tmp; -} - -Matrix4 Matrix4::getTransposed() const { - Matrix4 mat(*this); - mat.transpose(); - return mat; -} - -void Matrix4::add(float scalar) -{ - add(scalar, this); -} - -void Matrix4::add(float scalar, Matrix4* dst) const -{ - assert(dst); - dst->m[0] = this->m[0] + scalar; - dst->m[1] = this->m[1] + scalar; - dst->m[2] = this->m[2] + scalar; - dst->m[3] = this->m[3] + scalar; - dst->m[4] = this->m[4] + scalar; - dst->m[5] = this->m[5] + scalar; - dst->m[6] = this->m[6] + scalar; - dst->m[7] = this->m[7] + scalar; - dst->m[8] = this->m[8] + scalar; - dst->m[9] = this->m[9] + scalar; - dst->m[10] = this->m[10] + scalar; - dst->m[11] = this->m[11] + scalar; - dst->m[12] = this->m[12] + scalar; - dst->m[13] = this->m[13] + scalar; - dst->m[14] = this->m[14] + scalar; - dst->m[15] = this->m[15] + scalar; -} - -void Matrix4::add(const Matrix4& mat) -{ - add(*this, mat, this); -} - -void Matrix4::add(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] + m2.m[0]; - dst->m[1] = m1.m[1] + m2.m[1]; - dst->m[2] = m1.m[2] + m2.m[2]; - dst->m[3] = m1.m[3] + m2.m[3]; - dst->m[4] = m1.m[4] + m2.m[4]; - dst->m[5] = m1.m[5] + m2.m[5]; - dst->m[6] = m1.m[6] + m2.m[6]; - dst->m[7] = m1.m[7] + m2.m[7]; - dst->m[8] = m1.m[8] + m2.m[8]; - dst->m[9] = m1.m[9] + m2.m[9]; - dst->m[10] = m1.m[10] + m2.m[10]; - dst->m[11] = m1.m[11] + m2.m[11]; - dst->m[12] = m1.m[12] + m2.m[12]; - dst->m[13] = m1.m[13] + m2.m[13]; - dst->m[14] = m1.m[14] + m2.m[14]; - dst->m[15] = m1.m[15] + m2.m[15]; -} - -void Matrix4::subtract(const Matrix4& mat) -{ - subtract(*this, mat, this); -} - -void Matrix4::subtract(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] - m2.m[0]; - dst->m[1] = m1.m[1] - m2.m[1]; - dst->m[2] = m1.m[2] - m2.m[2]; - dst->m[3] = m1.m[3] - m2.m[3]; - dst->m[4] = m1.m[4] - m2.m[4]; - dst->m[5] = m1.m[5] - m2.m[5]; - dst->m[6] = m1.m[6] - m2.m[6]; - dst->m[7] = m1.m[7] - m2.m[7]; - dst->m[8] = m1.m[8] - m2.m[8]; - dst->m[9] = m1.m[9] - m2.m[9]; - dst->m[10] = m1.m[10] - m2.m[10]; - dst->m[11] = m1.m[11] - m2.m[11]; - dst->m[12] = m1.m[12] - m2.m[12]; - dst->m[13] = m1.m[13] - m2.m[13]; - dst->m[14] = m1.m[14] - m2.m[14]; - dst->m[15] = m1.m[15] - m2.m[15]; -} - -void Matrix4::multiply(float scalar) -{ - multiply(scalar, this); -} - -void Matrix4::multiply(float scalar, Matrix4* dst) const -{ - multiply(*this, scalar, dst); -} - -void Matrix4::multiply(const Matrix4& mat, float scalar, Matrix4* dst) -{ - assert(dst); - dst->m[0] = mat.m[0] * scalar; - dst->m[1] = mat.m[1] * scalar; - dst->m[2] = mat.m[2] * scalar; - dst->m[3] = mat.m[3] * scalar; - dst->m[4] = mat.m[4] * scalar; - dst->m[5] = mat.m[5] * scalar; - dst->m[6] = mat.m[6] * scalar; - dst->m[7] = mat.m[7] * scalar; - dst->m[8] = mat.m[8] * scalar; - dst->m[9] = mat.m[9] * scalar; - dst->m[10] = mat.m[10] * scalar; - dst->m[11] = mat.m[11] * scalar; - dst->m[12] = mat.m[12] * scalar; - dst->m[13] = mat.m[13] * scalar; - dst->m[14] = mat.m[14] * scalar; - dst->m[15] = mat.m[15] * scalar; -} - -void Matrix4::multiply(const Matrix4& mat) -{ - multiply(*this, mat, this); -} - -void Matrix4::multiply(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] * m2.m[0]; - dst->m[1] = m1.m[1] * m2.m[1]; - dst->m[2] = m1.m[2] * m2.m[2]; - dst->m[3] = m1.m[3] * m2.m[3]; - dst->m[4] = m1.m[4] * m2.m[4]; - dst->m[5] = m1.m[5] * m2.m[5]; - dst->m[6] = m1.m[6] * m2.m[6]; - dst->m[7] = m1.m[7] * m2.m[7]; - dst->m[8] = m1.m[8] * m2.m[8]; - dst->m[9] = m1.m[9] * m2.m[9]; - dst->m[10] = m1.m[10] * m2.m[10]; - dst->m[11] = m1.m[11] * m2.m[11]; - dst->m[12] = m1.m[12] * m2.m[12]; - dst->m[13] = m1.m[13] * m2.m[13]; - dst->m[14] = m1.m[14] * m2.m[14]; - dst->m[15] = m1.m[15] * m2.m[15]; -} - -const Matrix4 Matrix4::operator+(const Matrix4& mat) const -{ - Matrix4 result(*this); - result.add(mat); - return result; -} - -Matrix4& Matrix4::operator+=(const Matrix4& mat) -{ - add(mat); - return *this; -} - -const Matrix4 Matrix4::operator-(const Matrix4& mat) const -{ - Matrix4 result(*this); - result.subtract(mat); - return result; -} - -Matrix4& Matrix4::operator-=(const Matrix4& mat) -{ - subtract(mat); - return *this; -} - -const Matrix4 Matrix4::operator-() const -{ - Matrix4 mat(*this); - mat.negate(); - return mat; -} - -const Matrix4 Matrix4::operator*(const Matrix4& mat) const -{ - Matrix4 result(*this); - result.multiply(mat); - return result; -} - -Matrix4& Matrix4::operator*=(const Matrix4& mat) -{ - multiply(mat); - return *this; -} - -const Matrix4 Matrix4::operator+(float scalar) const -{ - Matrix4 result(*this); - result.add(scalar); - return result; -} - -Matrix4& Matrix4::operator+=(float scalar) -{ - add(scalar); - return *this; -} - -const Matrix4 Matrix4::operator-(float scalar) const -{ - Matrix4 result(*this); - result.add(-scalar); - return result; -} - -Matrix4& Matrix4::operator-=(float scalar) -{ - add(-scalar); - return *this; -} - -const Matrix4 Matrix4::operator*(float scalar) const -{ - Matrix4 result(*this); - result.multiply(scalar); - return result; -} - -Matrix4& Matrix4::operator*=(float scalar) -{ - multiply(scalar); - return *this; -} - - -const Matrix3 Matrix3::IDENTITY = Matrix3( - 1.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 1.0f); -Matrix3::Matrix3() { - *this = IDENTITY; -} - -Matrix3::Matrix3(const float* mat) { - set(mat); -} - -Matrix3::Matrix3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { - set(m11, m12, m13, m21, m22, m23, m31, m32, m33); -} - -Matrix3::Matrix3(const Matrix3& copy) { - memcpy(m, copy.m, sizeof(float) * 9); -} - -Matrix3::~Matrix3() { - -} - -void Matrix3::set(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { - m[0] = m11; - m[1] = m21; - m[2] = m31; - m[3] = m12; - m[4] = m22; - m[5] = m32; - m[6] = m13; - m[7] = m23; - m[8] = m33; -} - -void Matrix3::set(const float* mat) { - assert(mat); - memcpy(this->m, mat, sizeof(float) * 9); -} - -void Matrix3::set(const Matrix3& mat) { - memcpy(this->m, mat.m, sizeof(float) * 9); -} - -void Matrix3::setIdentity() { - memcpy(m, &IDENTITY, sizeof(float) * 9); -} - -void Matrix3::negate() -{ - m[0] = -m[0]; - m[1] = -m[1]; - m[2] = -m[2]; - m[3] = -m[3]; - m[4] = -m[4]; - m[5] = -m[5]; - m[6] = -m[6]; - m[7] = -m[7]; - m[8] = -m[8]; -} - -Matrix3 Matrix3::getNegated() const -{ - Matrix3 mat(*this); - mat.negate(); - return mat; -} - -void Matrix3::transpose() { - float tmp; - tmp = m[1]; m[1] = m[3]; m[3] = tmp; - tmp = m[2]; m[2] = m[6]; m[6] = tmp; - tmp = m[5]; m[5] = m[7]; m[7] = tmp; -} - -Matrix3 Matrix3::getTransposed() const { - Matrix3 mat(*this); - mat.transpose(); - return mat; -} - -void Matrix3::add(float scalar) -{ - add(scalar, this); -} - -void Matrix3::add(float scalar, Matrix3* dst) const -{ - assert(dst); - dst->m[0] = this->m[0] + scalar; - dst->m[1] = this->m[1] + scalar; - dst->m[2] = this->m[2] + scalar; - dst->m[3] = this->m[3] + scalar; - dst->m[4] = this->m[4] + scalar; - dst->m[5] = this->m[5] + scalar; - dst->m[6] = this->m[6] + scalar; - dst->m[7] = this->m[7] + scalar; - dst->m[8] = this->m[8] + scalar; -} - -void Matrix3::add(const Matrix3& mat) -{ - add(*this, mat, this); -} - -void Matrix3::add(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] + m2.m[0]; - dst->m[1] = m1.m[1] + m2.m[1]; - dst->m[2] = m1.m[2] + m2.m[2]; - dst->m[3] = m1.m[3] + m2.m[3]; - dst->m[4] = m1.m[4] + m2.m[4]; - dst->m[5] = m1.m[5] + m2.m[5]; - dst->m[6] = m1.m[6] + m2.m[6]; - dst->m[7] = m1.m[7] + m2.m[7]; - dst->m[8] = m1.m[8] + m2.m[8]; -} - -void Matrix3::subtract(const Matrix3& mat) -{ - subtract(*this, mat, this); -} - -void Matrix3::subtract(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] - m2.m[0]; - dst->m[1] = m1.m[1] - m2.m[1]; - dst->m[2] = m1.m[2] - m2.m[2]; - dst->m[3] = m1.m[3] - m2.m[3]; - dst->m[4] = m1.m[4] - m2.m[4]; - dst->m[5] = m1.m[5] - m2.m[5]; - dst->m[6] = m1.m[6] - m2.m[6]; - dst->m[7] = m1.m[7] - m2.m[7]; - dst->m[8] = m1.m[8] - m2.m[8]; -} - -void Matrix3::multiply(float scalar) -{ - multiply(scalar, this); -} - -void Matrix3::multiply(float scalar, Matrix3* dst) const -{ - multiply(*this, scalar, dst); -} - -void Matrix3::multiply(const Matrix3& mat, float scalar, Matrix3* dst) -{ - assert(dst); - dst->m[0] = mat.m[0] * scalar; - dst->m[1] = mat.m[1] * scalar; - dst->m[2] = mat.m[2] * scalar; - dst->m[3] = mat.m[3] * scalar; - dst->m[4] = mat.m[4] * scalar; - dst->m[5] = mat.m[5] * scalar; - dst->m[6] = mat.m[6] * scalar; - dst->m[7] = mat.m[7] * scalar; - dst->m[8] = mat.m[8] * scalar; -} - -void Matrix3::multiply(const Matrix3& mat) -{ - multiply(*this, mat, this); -} - -void Matrix3::multiply(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] * m2.m[0]; - dst->m[1] = m1.m[1] * m2.m[1]; - dst->m[2] = m1.m[2] * m2.m[2]; - dst->m[3] = m1.m[3] * m2.m[3]; - dst->m[4] = m1.m[4] * m2.m[4]; - dst->m[5] = m1.m[5] * m2.m[5]; - dst->m[6] = m1.m[6] * m2.m[6]; - dst->m[7] = m1.m[7] * m2.m[7]; - dst->m[8] = m1.m[8] * m2.m[8]; -} - -const Matrix3 Matrix3::operator+(const Matrix3& mat) const -{ - Matrix3 result(*this); - result.add(mat); - return result; -} - -Matrix3& Matrix3::operator+=(const Matrix3& mat) -{ - add(mat); - return *this; -} - -const Matrix3 Matrix3::operator-(const Matrix3& mat) const -{ - Matrix3 result(*this); - result.subtract(mat); - return result; -} - -Matrix3& Matrix3::operator-=(const Matrix3& mat) -{ - subtract(mat); - return *this; -} - -const Matrix3 Matrix3::operator-() const -{ - Matrix3 mat(*this); - mat.negate(); - return mat; -} - -const Matrix3 Matrix3::operator*(const Matrix3& mat) const -{ - Matrix3 result(*this); - result.multiply(mat); - return result; -} - -Matrix3& Matrix3::operator*=(const Matrix3& mat) -{ - multiply(mat); - return *this; -} - -const Matrix3 Matrix3::operator+(float scalar) const -{ - Matrix3 result(*this); - result.add(scalar); - return result; -} - -Matrix3& Matrix3::operator+=(float scalar) -{ - add(scalar); - return *this; -} - -const Matrix3 Matrix3::operator-(float scalar) const -{ - Matrix3 result(*this); - result.add(-scalar); - return result; -} - -Matrix3& Matrix3::operator-=(float scalar) -{ - add(-scalar); - return *this; -} - -const Matrix3 Matrix3::operator*(float scalar) const -{ - Matrix3 result(*this); - result.multiply(scalar); - return result; -} - -Matrix3& Matrix3::operator*=(float scalar) -{ - multiply(scalar); - return *this; -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/math.hpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/math.hpp deleted file mode 100755 index 5c2166b..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/math.hpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef math_hpp -#define math_hpp - -#include "macros.h" - -NS_GI_BEGIN - -class Vector2 -{ -public: - - float x; - float y; - - Vector2(); - Vector2(float xx, float yy); - Vector2(const float* array); - Vector2(const Vector2& p1, const Vector2& p2); - Vector2(const Vector2& copy); - ~Vector2(); - - bool isZero() const; - bool isOne() const; - static float angle(const Vector2& v1, const Vector2& v2); - void add(const Vector2& v); - static void add(const Vector2& v1, const Vector2& v2, Vector2* dst); - void clamp(const Vector2& min, const Vector2& max); - static void clamp(const Vector2& v, const Vector2& min, const Vector2& max, Vector2* dst); - float distance(const Vector2& v) const; - float distanceSquared(const Vector2& v) const; - float dot(const Vector2& v) const; - static float dot(const Vector2& v1, const Vector2& v2); - float length() const; - float lengthSquared() const; - void negate(); - void normalize(); - Vector2 getNormalized() const; - void scale(float scalar); - void scale(const Vector2& scale); - void rotate(const Vector2& point, float angle); - void set(float xx, float yy); - void set(const Vector2& v); - void set(const Vector2& p1, const Vector2& p2); - void setZero(); - void subtract(const Vector2& v); - static void subtract(const Vector2& v1, const Vector2& v2, Vector2* dst); - void smooth(const Vector2& target, float elapsedTime, float responseTime); - const Vector2 operator+(const Vector2& v) const; - Vector2& operator+=(const Vector2& v); - const Vector2 operator-(const Vector2& v) const; - Vector2& operator-=(const Vector2& v); - const Vector2 operator-() const; - const Vector2 operator*(float s) const; - Vector2& operator*=(float s); - const Vector2 operator/(float s) const; - bool operator<(const Vector2& v) const; - bool operator>(const Vector2& v) const; - bool operator==(const Vector2& v) const; - bool operator!=(const Vector2& v) const; -}; - -class Vector3 { - -}; - -class Matrix4 { -public: - float m[16]; - Matrix4(); - Matrix4(const float* mat); - Matrix4(float m11, float m12, float m13, float m14, float m21, float m22, float m23,float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44); - Matrix4(const Matrix4& copy); - ~Matrix4(); - - void set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44); - void set(const float* mat); - void set(const Matrix4& mat); - void setIdentity(); - - void negate(); - Matrix4 getNegated() const; - - void transpose(); - Matrix4 getTransposed() const; - - void add(float scalar); - void add(float scalar, Matrix4* dst) const; - void add(const Matrix4& mat); - static void add(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); - - void subtract(const Matrix4& mat); - static void subtract(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); - - void multiply(float scalar); - void multiply(float scalar, Matrix4* dst) const; - static void multiply(const Matrix4& mat, float scalar, Matrix4* dst); - void multiply(const Matrix4& mat); - static void multiply(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); - - const Matrix4 operator+(const Matrix4& mat) const; - Matrix4& operator+=(const Matrix4& mat); - const Matrix4 operator-(const Matrix4& mat) const; - Matrix4& operator-=(const Matrix4& mat); - const Matrix4 operator-() const; - const Matrix4 operator*(const Matrix4& mat) const; - Matrix4& operator*=(const Matrix4& mat); - - const Matrix4 operator+(float scalar) const; - Matrix4& operator+=(float scalar); - const Matrix4 operator-(float scalar) const; - Matrix4& operator-=(float scalar); - const Matrix4 operator*(float scalar) const; - Matrix4& operator*=(float scalar); - - static const Matrix4 IDENTITY; -}; - -class Matrix3 { -public: - float m[9]; - Matrix3(); - Matrix3(const float* mat); - Matrix3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33); - Matrix3(const Matrix3& copy); - ~Matrix3(); - - void set(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33); - void set(const float* mat); - void set(const Matrix3& mat); - void setIdentity(); - - void negate(); - Matrix3 getNegated() const; - - void transpose(); - Matrix3 getTransposed() const; - - void add(float scalar); - void add(float scalar, Matrix3* dst) const; - void add(const Matrix3& mat); - static void add(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); - - void subtract(const Matrix3& mat); - static void subtract(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); - - void multiply(float scalar); - void multiply(float scalar, Matrix3* dst) const; - static void multiply(const Matrix3& mat, float scalar, Matrix3* dst); - void multiply(const Matrix3& mat); - static void multiply(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); - - const Matrix3 operator+(const Matrix3& mat) const; - Matrix3& operator+=(const Matrix3& mat); - const Matrix3 operator-(const Matrix3& mat) const; - Matrix3& operator-=(const Matrix3& mat); - const Matrix3 operator-() const; - const Matrix3 operator*(const Matrix3& mat) const; - Matrix3& operator*=(const Matrix3& mat); - - const Matrix3 operator+(float scalar) const; - Matrix3& operator+=(float scalar); - const Matrix3 operator-(float scalar) const; - Matrix3& operator-=(float scalar); - const Matrix3 operator*(float scalar) const; - Matrix3& operator*=(float scalar); - - static const Matrix3 IDENTITY; -}; - -NS_GI_END - -#endif /* math_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/Source.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/Source.cpp deleted file mode 100755 index 175a3da..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/Source.cpp +++ /dev/null @@ -1,186 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Source.hpp" -#include "../util.h" -#include "../Context.hpp" - -#if PLATFORM == PLATFORM_IOS -#include "IOSTarget.hpp" -#endif - -NS_GI_BEGIN - - -Source::Source() -:_framebuffer(0) -,_outputRotation(RotationMode::NoRotation) -,_framebufferScale(1.0) -{ - -} - -Source::~Source() { - if (_framebuffer != 0) { - _framebuffer->release(); - _framebuffer = 0; - } - - removeAllTargets(); -} - -Source* Source::addTarget(Target* target) { - int targetTexIdx = target->getNextAvailableTextureIndex(); - return addTarget(target, targetTexIdx); -} - -Source* Source::addTarget(Target* target, int texIdx) { - if (!hasTarget(target)) { - _targets[target] = texIdx; - target->setInputFramebuffer(_framebuffer, RotationMode::NoRotation, texIdx); -// Ref *ref = dynamic_cast(target); -// if (ref) { -// ref->retain(); -// } - target->retain(); - } - return dynamic_cast(target); -} - -#if PLATFORM == PLATFORM_IOS -Source* Source::addTarget(id target) { - IOSTarget* iosTarget = new IOSTarget(target); - addTarget(iosTarget); - iosTarget->release(); - return 0; -} -#endif - -bool Source::hasTarget(const Target* target) const { - if (_targets.find(const_cast(target)) != _targets.end()) - return true; - else - return false; -} - -void Source::removeTarget(Target* target) { - std::map::iterator itr = _targets.find(target); - if (itr != _targets.end()) { - Ref* ref = (Ref*)(itr->first); - if (ref) { - ref->release(); - } - _targets.erase(itr); - } -} - -void Source::removeAllTargets() { - for (auto const& target : _targets ) { - Ref* ref = (Ref*)(target.first); - if (ref) { - ref->release(); - } - } - _targets.clear(); -} - -bool Source::proceed(bool bUpdateTargets/* = true*/) { - if (bUpdateTargets) - updateTargets(0); - return true; -} - -void Source::updateTargets(float frameTime) { - for(auto& it : _targets){ - Target* target = it.first; - target->setInputFramebuffer(_framebuffer, _outputRotation, _targets[target]); - if (target->isPrepared()) { - target->update(frameTime); - target->unPrepear(); - } - } -} - -unsigned char* Source::captureAProcessedFrameData(Filter* upToFilter, int width/* = 0*/, int height/* = 0*/) { - if (Context::getInstance()->isCapturingFrame) return 0 ; - - if (width <= 0 || height <= 0) { - if (!_framebuffer) return 0; - width = getRotatedFramebufferWidth(); - height = getRotatedFramebufferHeight(); - } - - Context::getInstance()->isCapturingFrame = true; - Context::getInstance()->captureWidth = width; - Context::getInstance()->captureHeight = height; - Context::getInstance()->captureUpToFilter = upToFilter; - - proceed(true); - unsigned char* processedFrameData = Context::getInstance()->capturedFrameData; - - Context::getInstance()->capturedFrameData = 0; - Context::getInstance()->captureWidth = 0; - Context::getInstance()->captureHeight = 0; - Context::getInstance()->isCapturingFrame = false; - - return processedFrameData; -} - -void Source::setFramebuffer(Framebuffer* fb, RotationMode outputRotation/* = RotationMode::NoRotation*/) { - if (_framebuffer != fb && _framebuffer != 0) { - _framebuffer->release(); - _framebuffer = 0; - } - _framebuffer = fb; - if (_framebuffer) - _framebuffer->retain(); - _outputRotation = outputRotation; -} - -int Source::getRotatedFramebufferWidth() const { - if (_framebuffer) - if (rotationSwapsSize(_outputRotation)) - return _framebuffer->getHeight(); - else - return _framebuffer->getWidth(); - else - return 0; -} - -int Source::getRotatedFramebufferHeight() const { - if (_framebuffer) - if (rotationSwapsSize(_outputRotation)) - return _framebuffer->getWidth(); - else - return _framebuffer->getHeight(); - else - return 0; -} - -Framebuffer* Source::getFramebuffer() const { - return _framebuffer; -} - -void Source::releaseFramebuffer(bool returnToCache/* = true*/) { - if (_framebuffer != 0) { - _framebuffer->release(returnToCache); - _framebuffer = 0; - } -} - -NS_GI_END diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceCamera.cpp b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceCamera.cpp deleted file mode 100755 index a343047..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceCamera.cpp +++ /dev/null @@ -1,323 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SourceCamera.h" -#include "../Context.hpp" -#include "../util.h" - -USING_NS_GI - -SourceCamera::SourceCamera() { -#if PLATFORM == PLATFORM_IOS - _videoDataOutputSampleBufferDelegate = [[VideoDataOutputSampleBufferDelegate alloc] init]; - _videoDataOutputSampleBufferDelegate.sourceCamera = this; - - _horizontallyMirrorFrontFacingCamera = false; - _horizontallyMirrorRearFacingCamera = false; -#endif -} - -SourceCamera::~SourceCamera() { -#if PLATFORM == PLATFORM_IOS - stop(); - _videoDataOutputSampleBufferDelegate = 0; -#endif -} - -SourceCamera* SourceCamera::create() { - SourceCamera* sourceCamera = new SourceCamera(); -#if PLATFORM == PLATFORM_IOS - if (!sourceCamera->init()) { - sourceCamera = 0; - } -#endif - return sourceCamera; -} - -void SourceCamera::setFrameData(int width, int height, const void* pixels, RotationMode outputRotation/* = RotationMode::NoRotation*/) { - this->setFramebuffer(0); - Framebuffer* framebuffer = Context::getInstance()->getFramebufferCache()->fetchFramebuffer(width, height, true); - this->setFramebuffer(framebuffer, outputRotation); - framebuffer->release(); - - CHECK_GL(glBindTexture(GL_TEXTURE_2D, this->getFramebuffer()->getTexture())); -#if PLATFORM == PLATFORM_IOS - CHECK_GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, pixels)); -#elif PLATFORM == PLATFORM_ANDROID - CHECK_GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); -#endif - CHECK_GL(glBindTexture(GL_TEXTURE_2D, 0)); -} - -#if PLATFORM == PLATFORM_IOS -bool SourceCamera::init() { - if (isCameraExist(AVCaptureDevicePositionFront)) - return init(AVCaptureSessionPreset640x480, AVCaptureDevicePositionFront); - else - return init(AVCaptureSessionPreset640x480, AVCaptureDevicePositionBack); -} - -bool SourceCamera::init(NSString* sessionPreset, AVCaptureDevicePosition cameraPosition) { - _outputRotation = GPUImage::NoRotation; - //internalRotation = GPUImage::NoRotation; - _capturePaused = NO; - - _captureSession = [[AVCaptureSession alloc] init]; - _captureSession.sessionPreset = sessionPreset; - - // input - AVCaptureDevice* device = 0; - for(AVCaptureDevice* dev in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) - { - if([dev position] == cameraPosition) - { - device = dev; - break; - } - } - if (!device) return false; - - NSError *error = nil; - _captureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; - if ([_captureSession canAddInput:_captureDeviceInput]) - { - [_captureSession addInput:_captureDeviceInput]; - } else { - return false; - } - - // output - _captureVideoDataOutput = [[AVCaptureVideoDataOutput alloc] init]; - [_captureVideoDataOutput setAlwaysDiscardsLateVideoFrames:YES]; - [_captureSession addOutput:_captureVideoDataOutput]; - dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); - [_captureVideoDataOutput setSampleBufferDelegate:_videoDataOutputSampleBufferDelegate queue:queue]; - _captureVideoDataOutput.videoSettings = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt:kCVPixelFormatType_32BGRA], kCVPixelBufferPixelFormatTypeKey, - nil]; - - setOutputImageOrientation(UIInterfaceOrientationPortrait); - - return true; -} - -bool SourceCamera::isCameraExist(AVCaptureDevicePosition cameraPosition) { - NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]; - for (AVCaptureDevice *device in devices) - { - if ([device position] == cameraPosition) - return true; - } - return false; -} - -void SourceCamera::start() { - if (![_captureSession isRunning]) - { - _videoDataOutputSampleBufferDelegate.sourceCamera = this; - [_captureSession startRunning]; - }; -} - -void SourceCamera::stop() { - if ([_captureSession isRunning]) - { - _videoDataOutputSampleBufferDelegate.sourceCamera = 0; - [_captureSession stopRunning]; - } -} - -void SourceCamera::pause() { - _capturePaused = true; -} - -void SourceCamera::resume() { - _capturePaused = false; -} - -bool SourceCamera::isRunning() { - return [_captureSession isRunning]; -} - -bool SourceCamera::flip() { - AVCaptureDevicePosition cameraPosition = [[_captureDeviceInput device] position]; - if (cameraPosition == AVCaptureDevicePositionBack) - { - cameraPosition = AVCaptureDevicePositionFront; - } - else - { - cameraPosition = AVCaptureDevicePositionBack; - } - - if (!isCameraExist(cameraPosition)) - return false; - - AVCaptureDevice* device = 0; - for(AVCaptureDevice* dev in [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo]) - { - if([dev position] == cameraPosition) - { - device = dev; - break; - } - } - if (!device) return false; - - NSError *error = nil; - AVCaptureDeviceInput* newCaptureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; - if (!newCaptureDeviceInput) return false; - - [_captureSession beginConfiguration]; - - [_captureSession removeInput:_captureDeviceInput]; - if ([_captureSession canAddInput:newCaptureDeviceInput]) - { - [_captureSession addInput:newCaptureDeviceInput]; - _captureDeviceInput = newCaptureDeviceInput; - } - else - { - [_captureSession addInput:_captureDeviceInput]; - } - [_captureSession commitConfiguration]; - - _updateOutputRotation(); - - return true; -} - -AVCaptureDevicePosition SourceCamera::getCameraPosition() -{ - return [[_captureDeviceInput device] position]; -} - -void SourceCamera::setOutputImageOrientation(UIInterfaceOrientation orientation) { - _outputImageOrientation = orientation; - _updateOutputRotation(); -} - -void SourceCamera::setHorizontallyMirrorFrontFacingCamera(bool newValue) -{ - _horizontallyMirrorFrontFacingCamera = newValue; - _updateOutputRotation(); -} - -void SourceCamera::setHorizontallyMirrorRearFacingCamera(bool newValue) -{ - _horizontallyMirrorRearFacingCamera = newValue; - _updateOutputRotation(); -} - -void SourceCamera::_updateOutputRotation() -{ - if (getCameraPosition() == AVCaptureDevicePositionBack) - { - if (_horizontallyMirrorRearFacingCamera) - { - switch(_outputImageOrientation) - { - case UIInterfaceOrientationPortrait: - _outputRotation = GPUImage::RotateRightFlipVertical; break; - case UIInterfaceOrientationPortraitUpsideDown: - _outputRotation = GPUImage::Rotate180; break; - case UIInterfaceOrientationLandscapeLeft: - _outputRotation = GPUImage::FlipHorizontal; break; - case UIInterfaceOrientationLandscapeRight: - _outputRotation = GPUImage::FlipVertical; break; - default: - _outputRotation = GPUImage::NoRotation; - } - } - else - { - switch(_outputImageOrientation) - { - case UIInterfaceOrientationPortrait: - _outputRotation = GPUImage::RotateRight; break; - case UIInterfaceOrientationPortraitUpsideDown: - _outputRotation = GPUImage::RotateLeft; break; - case UIInterfaceOrientationLandscapeLeft: - _outputRotation = GPUImage::Rotate180; break; - case UIInterfaceOrientationLandscapeRight: - _outputRotation = GPUImage::NoRotation; break; - default: - _outputRotation = GPUImage::NoRotation; - } - } - } - else - { - if (_horizontallyMirrorFrontFacingCamera) - { - switch(_outputImageOrientation) - { - case UIInterfaceOrientationPortrait: - _outputRotation = GPUImage::RotateRightFlipVertical; break; - case UIInterfaceOrientationPortraitUpsideDown: - _outputRotation = GPUImage::RotateRightFlipHorizontal; break; - case UIInterfaceOrientationLandscapeLeft: - _outputRotation = GPUImage::FlipHorizontal; break; - case UIInterfaceOrientationLandscapeRight: - _outputRotation = GPUImage::FlipVertical; break; - default: - _outputRotation = GPUImage::NoRotation; - } - } - else - { - switch(_outputImageOrientation) - { - case UIInterfaceOrientationPortrait: - _outputRotation = GPUImage::RotateRight; break; - case UIInterfaceOrientationPortraitUpsideDown: - _outputRotation = GPUImage::RotateLeft; break; - case UIInterfaceOrientationLandscapeLeft: - _outputRotation = GPUImage::NoRotation; break; - case UIInterfaceOrientationLandscapeRight: - _outputRotation = GPUImage::Rotate180; break; - default: - _outputRotation = GPUImage::NoRotation; - } - } - } - _videoDataOutputSampleBufferDelegate.rotation = _outputRotation; -} -#endif - - -#if PLATFORM == PLATFORM_IOS -@implementation VideoDataOutputSampleBufferDelegate -#pragma mark AVCaptureVideoDataOutputSampleBufferDelegate -- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection -{ - if (_sourceCamera) { - Context::getInstance()->runSync([&]{ - CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer); - CVPixelBufferLockBaseAddress(imageBuffer, 0); - _sourceCamera->setFrameData((int) CVPixelBufferGetWidth(imageBuffer), - (int) CVPixelBufferGetHeight(imageBuffer), - CVPixelBufferGetBaseAddress(imageBuffer), - _rotation); - CVPixelBufferUnlockBaseAddress(imageBuffer, 0); - _sourceCamera->proceed(); - }); - } -} -@end -#endif diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageView.h b/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageView.h deleted file mode 100755 index fa92345..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageView.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if PLATFORM == PLATFORM_IOS - -#import -#import "GPUImageTarget.h" -#include "TargetView.h" - -@interface GPUImageView : UIView - -@property(readwrite, nonatomic) GPUImage::TargetView::FillMode fillMode; - -@end - -#endif diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/.gitignore b/GPUImage-x/proj.android/GPUImage-x/sample/.gitignore deleted file mode 100644 index 87e7e72..0000000 --- a/GPUImage-x/proj.android/GPUImage-x/sample/.gitignore +++ /dev/null @@ -1,45 +0,0 @@ -# Created by .ignore support plugin (hsz.mobi) -### Android template -# Built application files -*.apk -*.ap_ - -# Files for the ART/Dalvik VM -*.dex - -# Java class files -*.class - -# Generated files -bin/ -gen/ -out/ - -# Gradle files -.gradle/ -build/ - -# Local configuration file (sdk path, etc) -local.properties - -# Proguard folder generated by Eclipse -proguard/ - -# Log Files -*.log - -# Android Studio Navigation editor temp files -.navigation/ - -# Android Studio captures folder -captures/ - -# Intellij -*.iml -.idea/ - -# Keystore files -*.jks -*.DS_Store - -.externalNativeBuild diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100755 index 23121f7..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.xcworkspace/xcuserdata/jin.xcuserdatad/UserInterfaceState.xcuserstate b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.xcworkspace/xcuserdata/jin.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100755 index ad0fc25..0000000 Binary files a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.xcworkspace/xcuserdata/jin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/GPUImage-x.xcscheme b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/GPUImage-x.xcscheme deleted file mode 100755 index 60e59e0..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/GPUImage-x.xcscheme +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/xcschememanagement.plist b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100755 index b3bffa3..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - SchemeUserState - - GPUImage-x.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 3CFDD56D1D7AB2F500E37EA3 - - primary - - - - - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Context.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Context.cpp deleted file mode 100755 index 1484b29..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Context.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Context.hpp" -#include "util.h" - -#if PLATFORM == PLATFORM_IOS -#import -#import -#endif - -NS_GI_BEGIN - -#if PLATFORM == PLATFORM_IOS -#define GL_CONTEXT_QUEUE "com.jin.GPUImage-x.openglESContextQueue" -#endif - -Context* Context::_instance = 0; -std::mutex Context::_mutex; - -Context::Context() -:_curShaderProgram(0) -,isCapturingFrame(false) -,captureUpToFilter(0) -,capturedFrameData(0) -{ - _framebufferCache = new FramebufferCache(); - -#if PLATFORM == PLATFORM_IOS - _contextQueue = dispatch_queue_create(GL_CONTEXT_QUEUE, DISPATCH_QUEUE_SERIAL); - _eglContext = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; - [EAGLContext setCurrentContext:_eglContext]; -#endif -} - -Context::~Context() { - delete _framebufferCache; -} - -Context* Context::getInstance() { - if (!_instance) - { - std::unique_lock lock(_mutex); - if (!_instance) { - _instance = new (std::nothrow) Context; - } - } - return _instance; -}; - -void Context::init() { - destroy(); - getInstance(); -} - -void Context::destroy() { - if (_instance) { - delete _instance; - _instance = 0; - } -} - -FramebufferCache* Context::getFramebufferCache() const { - return _framebufferCache; -} - -void Context::setActiveShaderProgram(GLProgram* shaderProgram) { - if (_curShaderProgram != shaderProgram) - { - _curShaderProgram = shaderProgram; - shaderProgram->use(); - } -} - -void Context::purge() { - _framebufferCache->purge(); -} - -#if PLATFORM == PLATFORM_IOS -void Context::runSync(std::function func) { - useAsCurrent(); - dispatch_queue_t contextQueue = Context::getInstance()->getContextQueue(); - - if (dispatch_get_current_queue() == contextQueue) - { - func(); - }else - { - dispatch_sync(contextQueue, ^{ func(); }); - } -} - -void Context::runAsync(std::function func) { - useAsCurrent(); - dispatch_queue_t contextQueue = Context::getInstance()->getContextQueue(); - - if (dispatch_get_current_queue() == contextQueue) - { - func(); - }else - { - dispatch_async(contextQueue, ^{ func(); }); - } -} - -void Context::useAsCurrent(void) -{ - if ([EAGLContext currentContext] != _eglContext) - { - [EAGLContext setCurrentContext:_eglContext]; - } -} - -void Context::presentBufferForDisplay() { - [_eglContext presentRenderbuffer:GL_RENDERBUFFER ]; -} -#endif - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Framebuffer.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Framebuffer.cpp deleted file mode 100755 index 3f8b15d..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Framebuffer.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Framebuffer.hpp" -#include -#include -#include "Context.hpp" -#include "util.h" - - -NS_GI_BEGIN - -std::vector Framebuffer::_framebuffers; - -TextureAttributes Framebuffer::defaultTextureAttribures = { - .minFilter = GL_LINEAR, - .magFilter = GL_LINEAR, - .wrapS = GL_CLAMP_TO_EDGE, - .wrapT = GL_CLAMP_TO_EDGE, - .internalFormat = GL_RGBA, - .format = GL_RGBA, - .type = GL_UNSIGNED_BYTE -}; - -Framebuffer::Framebuffer(int width, int height, bool onlyGenerateTexture/* = false*/, const TextureAttributes textureAttributes/* = defaultTextureAttribures*/) -:_texture(-1) -,_framebuffer(-1) -{ - _width = width; - _height = height; - _textureAttributes = textureAttributes; - _hasFB = !onlyGenerateTexture; - - if (_hasFB) { - _generateFramebuffer(); - } else { - _generateTexture(); - } - - _framebuffers.push_back(this); -} - -Framebuffer::~Framebuffer() { - // todo - std::vector::iterator itr = std::find(_framebuffers.begin(), _framebuffers.end(), this); - if (itr != _framebuffers.end()) { - _framebuffers.erase(itr); - } - - bool bDeleteTex = (_texture != -1); - bool bDeleteFB = (_framebuffer != -1); - - for (auto const& framebuffer : _framebuffers ) { - if (bDeleteTex) { - if (_texture == framebuffer->getTexture()) { - bDeleteTex = false; - } - } - - if (bDeleteFB) { - if (framebuffer->hasFramebuffer() && _framebuffer == framebuffer->getFramebuffer()) { - bDeleteFB = false; - } - } - } - - if (bDeleteTex) { - CHECK_GL(glDeleteTextures(1, &_texture)); - _texture = -1; - } - if (bDeleteFB) { - CHECK_GL(glDeleteFramebuffers(1, &_framebuffer)); - _framebuffer = -1; - } -} - -void Framebuffer::release(bool returnToCache/* = true*/) { - if (returnToCache) { - assert(_referenceCount > 0); - --_referenceCount; - if (_referenceCount == 0) { - Context::getInstance()->getFramebufferCache()->returnFramebuffer(this); - } - } else { - Ref::release(); - } -} - -void Framebuffer::active() { - CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer)); - CHECK_GL(glViewport(0, 0, _width, _height)); -} - -void Framebuffer::inactive() { - CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER, 0)); -} - -void Framebuffer::_generateTexture() { - CHECK_GL(glGenTextures(1, &_texture)); - CHECK_GL(glBindTexture(GL_TEXTURE_2D, _texture)); - CHECK_GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, _textureAttributes.minFilter)); - CHECK_GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, _textureAttributes.magFilter)); - CHECK_GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, _textureAttributes.wrapS)); - CHECK_GL(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, _textureAttributes.wrapT)); - - // TODO: Handle mipmaps - CHECK_GL(glBindTexture(GL_TEXTURE_2D, 0)); -} - -void Framebuffer::_generateFramebuffer() { - CHECK_GL(glGenFramebuffers(1, &_framebuffer)); - CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER, _framebuffer)); - _generateTexture(); - CHECK_GL(glBindTexture(GL_TEXTURE_2D, _texture)); - CHECK_GL(glTexImage2D(GL_TEXTURE_2D, 0, _textureAttributes.internalFormat, _width, _height, 0, _textureAttributes.format, _textureAttributes.type, 0)); - CHECK_GL(glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture, 0)); - CHECK_GL(glBindTexture(GL_TEXTURE_2D, 0)); - CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER, 0)); -} - - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Framebuffer.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Framebuffer.hpp deleted file mode 100755 index 38aac27..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Framebuffer.hpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Framebuffer_hpp -#define Framebuffer_hpp - -#include "macros.h" -#if PLATFORM == PLATFORM_IOS -#import -#import -#elif PLATFORM == PLATFORM_ANDROID -#include -#include -#endif -#include -#include "Ref.hpp" - -NS_GI_BEGIN - -typedef struct { - GLenum minFilter; - GLenum magFilter; - GLenum wrapS; - GLenum wrapT; - GLenum internalFormat; - GLenum format; - GLenum type; -} TextureAttributes; - - -class Framebuffer : public Ref{ -public: - Framebuffer(int width, int height, bool onlyGenerateTexture = false, const TextureAttributes textureAttributes = defaultTextureAttribures); - ~Framebuffer(); - - virtual void release(bool returnToCache = true); - - GLuint getTexture() const { - return _texture; - } - - GLuint getFramebuffer() const { - return _framebuffer; - } - - int getWidth() const { return _width; } - int getHeight() const { return _height; } - const TextureAttributes& getTextureAttributes() const { return _textureAttributes; }; - bool hasFramebuffer() { return _hasFB; }; - - void active(); - void inactive(); - - static TextureAttributes defaultTextureAttribures; - -private: - int _width, _height; - TextureAttributes _textureAttributes; - bool _hasFB; - GLuint _texture; - GLuint _framebuffer; - - void _generateTexture(); - void _generateFramebuffer(); - - static std::vector _framebuffers; -}; - - -NS_GI_END - -#endif /* Framebuffer_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/FramebufferCache.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/FramebufferCache.cpp deleted file mode 100755 index 34f34f7..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/FramebufferCache.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "FramebufferCache.hpp" -#include "util.h" - -NS_GI_BEGIN - - -FramebufferCache::FramebufferCache() -{ -} - -FramebufferCache::~FramebufferCache() { - purge(); -} - -Framebuffer* FramebufferCache::fetchFramebuffer(int width, int height, bool onlyTexture/* = false*/, const TextureAttributes textureAttributes/* = defaultTextureAttribure*/) { - - Framebuffer* framebufferFromCache = 0; - std::string lookupHash = _getHash(width, height, onlyTexture, textureAttributes); - int numberOfMatchingFramebuffers = 0; - if(_framebufferTypeCounts.find(lookupHash) != _framebufferTypeCounts.end()) { - numberOfMatchingFramebuffers = _framebufferTypeCounts[lookupHash]; - } - if (numberOfMatchingFramebuffers < 1) { - framebufferFromCache = new Framebuffer(width, height, onlyTexture, textureAttributes); - } else { - int curFramebufferId = numberOfMatchingFramebuffers - 1; - while (!framebufferFromCache && curFramebufferId >= 0) { - std::string framebufferHash = str_format("%s-%ld", lookupHash.c_str(), curFramebufferId); - if (_framebuffers.find(framebufferHash) != _framebuffers.end()) { - framebufferFromCache = _framebuffers[framebufferHash]; - _framebuffers.erase(framebufferHash); - } else - framebufferFromCache = 0; - curFramebufferId--; - } - curFramebufferId++; - _framebufferTypeCounts[lookupHash] = curFramebufferId; - - if (!framebufferFromCache) { - framebufferFromCache = new Framebuffer(width, height, onlyTexture, textureAttributes); - } - } - - // make sure this framebuffer is not referenced by others - framebufferFromCache->resetRefenceCount(); - return framebufferFromCache; -} - -void FramebufferCache::returnFramebuffer(Framebuffer* framebuffer) { - if (framebuffer == 0) return; - int width = framebuffer->getWidth(); - int height = framebuffer->getHeight(); - const TextureAttributes& textureAttributes = framebuffer->getTextureAttributes(); - std::string lookupHash = _getHash(width, height, !framebuffer->hasFramebuffer(), textureAttributes); - int numberOfMatchingFramebuffers = 0; - if(_framebufferTypeCounts.find(lookupHash) != _framebufferTypeCounts.end()) { - numberOfMatchingFramebuffers = _framebufferTypeCounts[lookupHash]; - } - std::string framebufferHash = str_format("%s-%ld", lookupHash.c_str(), numberOfMatchingFramebuffers); - _framebuffers[framebufferHash] = framebuffer; - _framebufferTypeCounts[lookupHash] = numberOfMatchingFramebuffers + 1; -} - -std::string FramebufferCache::_getHash(int width, int height, bool onlyTexture, const TextureAttributes textureAttributes) const { - if (onlyTexture) - { - return str_format("%.1dx%.1d-%d:%d:%d:%d:%d:%d:%d-NOFB", width, height, textureAttributes.minFilter, textureAttributes.magFilter, textureAttributes.wrapS, textureAttributes.wrapT, textureAttributes.internalFormat, textureAttributes.format, textureAttributes.type); - } - else - { - return str_format("%.1dx%.1d-%d:%d:%d:%d:%d:%d:%d", width, height, textureAttributes.minFilter, textureAttributes.magFilter, textureAttributes.wrapS, textureAttributes.wrapT, textureAttributes.internalFormat, textureAttributes.format, textureAttributes.type); - } -} - -Framebuffer* FramebufferCache::_getFramebufferByHash(const std::string& hash) { - return _framebuffers[hash]; -} - -void FramebufferCache::purge() { - for(const auto kvp : _framebuffers) - { - delete kvp.second; - } - _framebuffers.clear(); - _framebufferTypeCounts.clear(); -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/FramebufferCache.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/FramebufferCache.hpp deleted file mode 100755 index 21017df..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/FramebufferCache.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FramebufferCache_hpp -#define FramebufferCache_hpp - -#include "macros.h" -#include "Framebuffer.hpp" -#include -#include - -NS_GI_BEGIN - -class FramebufferCache { -public: - FramebufferCache(); - ~FramebufferCache(); - Framebuffer* fetchFramebuffer(int width, int height, bool onlyTexture = false, const TextureAttributes textureAttributes = Framebuffer::defaultTextureAttribures ); - void returnFramebuffer(Framebuffer* framebuffer); - void purge(); - - -private: - std::string _getHash(int width, int height, bool onlyTexture, const TextureAttributes textureAttributes) const; - Framebuffer* _getFramebufferByHash(const std::string& hash); - - std::map _framebuffers; - std::map _framebufferTypeCounts; - -}; - -NS_GI_END - -#endif /* FramebufferCache_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GLProgram.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GLProgram.hpp deleted file mode 100755 index dcf24a6..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GLProgram.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Shader_hpp -#define Shader_hpp - -#include "macros.h" -#include "string" -#if PLATFORM == PLATFORM_ANDROID -#include -#include -#elif PLATFORM == PLATFORM_IOS -#import -#import -#endif -#include -#include "math.hpp" - -NS_GI_BEGIN - -class GLProgram{ -public: - GLProgram(); - ~GLProgram(); - - static GLProgram* createByShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource); - void use(); - GLuint getID() const { return _program; } - - GLuint getAttribLocation(const std::string& attribute); - GLuint getUniformLocation(const std::string& uniformName); - - void setUniformValue(const std::string& uniformName, int value); - void setUniformValue(const std::string& uniformName, float value); - void setUniformValue(const std::string& uniformName, Vector2 value); - void setUniformValue(const std::string& uniformName, Matrix3 value); - void setUniformValue(const std::string& uniformName, Matrix4 value); - - void setUniformValue(int uniformLocation, int value); - void setUniformValue(int uniformLocation, float value); - void setUniformValue(int uniformLocation, Vector2 value); - void setUniformValue(int uniformLocation, Matrix3 value); - void setUniformValue(int uniformLocation, Matrix4 value); - -private: - static std::vector _programs; - GLuint _program; - bool _initWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource); -}; - - -NS_GI_END - -#endif /* GLProgram_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GPUImage-x.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GPUImage-x.h deleted file mode 100755 index 61a78d7..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GPUImage-x.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GPUImage_x_h -#define GPUImage_x_h - - -#include "Context.hpp" -#include "Framebuffer.hpp" -#include "FramebufferCache.hpp" -#include "GLProgram.hpp" -#include "macros.h" -#include "math.hpp" -#include "Ref.hpp" -#include "util.h" -#include "source/Source.hpp" -#include "source/SourceImage.h" -#include "source/SourceCamera.h" -#include "target/Target.hpp" -#include "target/TargetView.h" -#if PLATFORM == PLATFORM_IOS -#include "target/iOS/IOSTarget.hpp" -#include "target/iOS/GPUImageTarget.h" -#include "target/iOS/GPUImageView.h" -#endif - -#include "filter/Filter.hpp" -#include "filter/FilterGroup.hpp" -#include "filter/BrightnessFilter.hpp" -#include "filter/BilateralFilter.hpp" -#include "filter/BeautifyFilter.hpp" -#include "filter/CannyEdgeDetectionFilter.hpp" -#include "filter/ColorInvertFilter.hpp" -#include "filter/ColorMatrixFilter.hpp" -#include "filter/NonMaximumSuppressionFilter.hpp" -#include "filter/DirectionalNonMaximumSuppressionFilter.hpp" -#include "filter/DirectionalSobelEdgeDetectionFilter.hpp" -#include "filter/GaussianBlurFilter.hpp" -#include "filter/GaussianBlurMonoFilter.hpp" -#include "filter/SingleComponentGaussianBlurFilter.hpp" -#include "filter/SingleComponentGaussianBlurMonoFilter.hpp" -#include "filter/GrayscaleFilter.hpp" -#include "filter/HSBFilter.hpp" -#include "filter/NearbySampling3x3Filter.hpp" -#include "filter/WeakPixelInclusionFilter.hpp" -#include "filter/SobelEdgeDetectionFilter.hpp" -#include "filter/SketchFilter.hpp" -#include "filter/ToonFilter.hpp" -#include "filter/SmoothToonFilter.hpp" -#include "filter/PosterizeFilter.hpp" -#include "filter/PixellationFilter.hpp" -#include "filter/SaturationFilter.hpp" -#include "filter/ContrastFilter.hpp" -#include "filter/ExposureFilter.hpp" -#include "filter/RGBFilter.hpp" -#include "filter/HueFilter.hpp" -#include "filter/WhiteBalanceFilter.hpp" -#include "filter/LuminanceRangeFilter.hpp" -#include "filter/IOSBlurFilter.hpp" -#include "filter/Convolution3x3Filter.hpp" -#include "filter/EmbossFilter.hpp" -#include "filter/HalftoneFilter.hpp" -#include "filter/CrosshatchFilter.hpp" -#include "filter/SphereRefractionFilter.hpp" -#include "filter/GlassSphereFilter.hpp" - -#endif /* GPUImage_x_h */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GPUImagexJNI.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GPUImagexJNI.cpp deleted file mode 100755 index 5007bbf..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GPUImagexJNI.cpp +++ /dev/null @@ -1,392 +0,0 @@ -#if PLATFORM == PLATFORM_ANDROID - -#include -#include -#include -#include "source/SourceImage.h" -#include "source/SourceCamera.h" -#include "target/TargetView.h" -#include "filter/Filter.hpp" -#include "Context.hpp" - -USING_NS_GI - -extern "C" -jlong Java_com_jin_gpuimage_GPUImage_nativeSourceImageNew( - JNIEnv *env, - jobject) -{ - return (uintptr_t)(new SourceImage()); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceImageDestroy( - JNIEnv *env, - jobject, - jlong classId) -{ - ((SourceImage*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceImageFinalize( - JNIEnv *env, - jobject, - jlong classId) -{ - ((SourceImage*)classId)->releaseFramebuffer(false); - ((SourceImage*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceImageSetImage( - JNIEnv *env, - jobject, - jlong classId, - jobject bitmap) -{ - char* pData = 0; - AndroidBitmapInfo info; - void* pixels; - if ((AndroidBitmap_getInfo(env, bitmap, &info)) < 0){ - //ERROR - return; - } - - if ((AndroidBitmap_lockPixels(env, bitmap, &pixels)) >= 0){ - ((SourceImage*)classId)->setImage(info.width, info.height, pixels); - } - - AndroidBitmap_unlockPixels(env, bitmap); -}; - -extern "C" -jlong Java_com_jin_gpuimage_GPUImage_nativeSourceCameraNew( - JNIEnv *env, - jobject) -{ - return (uintptr_t)(new SourceCamera()); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceCameraDestroy( - JNIEnv *env, - jobject, - jlong classId) -{ - ((SourceCamera*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceCameraFinalize( - JNIEnv *env, - jobject, - jlong classId) -{ - ((SourceCamera*)classId)->releaseFramebuffer(false); - ((SourceCamera*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceCameraSetFrame( - JNIEnv *env, - jobject, - jlong classId, - jint width, - jint height, - jintArray jdata, - jint rotation) -{ - jint* data = (jint*) (env->GetPrimitiveArrayCritical(jdata, 0)); - ((SourceCamera*)classId)->setFrameData(width, height, data, (RotationMode)rotation); - env->ReleasePrimitiveArrayCritical(jdata, data, 0); -}; - -extern "C" -jlong Java_com_jin_gpuimage_GPUImage_nativeSourceAddTarget( - JNIEnv *env, - jobject, - jlong classId, - jlong targetClassId, - jint texID, - jboolean isFilter) -{ - Source* source = (Source *) classId; - Target* target = isFilter ? dynamic_cast((Filter*)targetClassId) : (Target*)targetClassId; - if (texID >= 0) { - return (uintptr_t) (source->addTarget(target, texID)); - } else { - return (uintptr_t) (source->addTarget(target)); - } -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceRemoveTarget( - JNIEnv *env, - jobject, - jlong classId, - jlong targetClassId, - jboolean isFilter) -{ - Source* source = (Source *) classId; - Target* target = isFilter ? dynamic_cast((Filter*)targetClassId) : (Target*)targetClassId; - source->removeTarget(target); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeSourceRemoveAllTargets( - JNIEnv *env, - jobject, - jlong classId) -{ - ((Source *) classId)->removeAllTargets(); -}; - -extern "C" -jlong Java_com_jin_gpuimage_GPUImage_nativeSourceProceed( - JNIEnv *env, - jobject, - jlong classId, - jboolean bUpdateTargets ) -{ - return ((Source *) classId)->proceed(bUpdateTargets); -}; - -extern "C" -jint Java_com_jin_gpuimage_GPUImage_nativeSourceGetRotatedFramebuferWidth( - JNIEnv *env, - jobject, - jlong classId) -{ - return ((Source *) classId)->getRotatedFramebufferWidth(); -}; - -extern "C" -jint Java_com_jin_gpuimage_GPUImage_nativeSourceGetRotatedFramebuferHeight( - JNIEnv *env, - jobject, - jlong classId) -{ - return ((Source *) classId)->getRotatedFramebufferHeight(); -}; - -extern "C" -jbyteArray Java_com_jin_gpuimage_GPUImage_nativeSourceCaptureAProcessedFrameData( - JNIEnv *env, - jobject, - jlong classId, - jlong upToFilterClassId, - jint width, - jint height ) -{ - unsigned char* processedFrameData = ((Source *) classId)->captureAProcessedFrameData((Filter*)upToFilterClassId, width, height); - int frameSize = width * height * 4 * sizeof(unsigned char); - - jbyteArray jresult = NULL; - if (processedFrameData) { - jbyte* by = (jbyte*)processedFrameData; - jresult = env->NewByteArray(frameSize); - env->SetByteArrayRegion(jresult, 0, frameSize, by); - delete[] processedFrameData; - processedFrameData = 0; - } - - return jresult; -}; - -extern "C" -jlong Java_com_jin_gpuimage_GPUImage_nativeTargetViewNew( - JNIEnv *env, - jobject obj) -{ - return (uintptr_t)(new TargetView()); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeTargetViewFinalize( - JNIEnv *env, - jobject, - jlong classId) -{ - ((TargetView*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeTargetViewOnSizeChanged( - JNIEnv *env, - jobject, - jlong classId, - jint width, - jint height) -{ - ((TargetView*)classId)->onSizeChanged(width, height); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeTargetViewSetFillMode( - JNIEnv *env, - jobject, - jlong classId, - jint fillMode) -{ - ((TargetView*)classId)->setFillMode((TargetView::FillMode)fillMode); -}; - -extern "C" -jlong Java_com_jin_gpuimage_GPUImage_nativeFilterCreate( - JNIEnv *env, - jobject obj, - jstring jFilterClassName) -{ - const char* filterClassName = env->GetStringUTFChars(jFilterClassName, 0); - long ret = (uintptr_t)(Filter::create(filterClassName)); - env->ReleaseStringUTFChars(jFilterClassName, filterClassName); - return ret; -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeFilterDestroy( - JNIEnv *env, - jobject obj, - jlong classId) -{ - ((Filter*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeFilterFinalize( - JNIEnv *env, - jobject obj, - jlong classId) -{ - ((Filter*)classId)->releaseFramebuffer(false); - ((Filter*)classId)->release(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeFilterSetPropertyFloat( - JNIEnv *env, - jobject obj, - jlong classId, - jstring jProperty, - jfloat value) -{ - const char* property = env->GetStringUTFChars(jProperty, 0); - ((Filter*)classId)->setProperty(property, value); - env->ReleaseStringUTFChars(jProperty, property); - -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeFilterSetPropertyInt( - JNIEnv *env, - jobject obj, - jlong classId, - jstring jProperty, - jint value) -{ - const char* property = env->GetStringUTFChars(jProperty, 0); - ((Filter*)classId)->setProperty(property, value); - env->ReleaseStringUTFChars(jProperty, property); - -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeFilterSetPropertyString( - JNIEnv *env, - jobject obj, - jlong classId, - jstring jProperty, - jstring jValue) -{ - const char* property = env->GetStringUTFChars(jProperty, 0); - const char* value = env->GetStringUTFChars(jValue, 0); - ((Filter*)classId)->setProperty(property, value); - env->ReleaseStringUTFChars(jProperty, property); - env->ReleaseStringUTFChars(jValue, value); - -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeContextInit( - JNIEnv *env, - jobject obj) -{ - Context::init(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeContextDestroy( - JNIEnv *env, - jobject obj) -{ - Context::destroy(); -}; - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeContextPurge( - JNIEnv *env, - jobject obj) -{ - Context::getInstance()->purge(); -}; - - -extern "C" -void Java_com_jin_gpuimage_GPUImage_nativeYUVtoRBGA(JNIEnv * env, jobject obj, jbyteArray yuv420sp, jint width, jint height, jintArray rgbOut) -{ - int sz; - int i; - int j; - int Y; - int Cr = 0; - int Cb = 0; - int pixPtr = 0; - int jDiv2 = 0; - int R = 0; - int G = 0; - int B = 0; - int cOff; - int w = width; - int h = height; - sz = w * h; - - jint *rgbData = (jint*) (env->GetPrimitiveArrayCritical(rgbOut, 0)); - jbyte* yuv = (jbyte*) env->GetPrimitiveArrayCritical(yuv420sp, 0); - - for(j = 0; j < h; j++) { - pixPtr = j * w; - jDiv2 = j >> 1; - for(i = 0; i < w; i++) { - Y = yuv[pixPtr]; - if(Y < 0) Y += 255; - if((i & 0x1) != 1) { - cOff = sz + jDiv2 * w + (i >> 1) * 2; - Cb = yuv[cOff]; - if(Cb < 0) Cb += 127; else Cb -= 128; - Cr = yuv[cOff + 1]; - if(Cr < 0) Cr += 127; else Cr -= 128; - } - - //ITU-R BT.601 conversion - // - //R = 1.164*(Y-16) + 2.018*(Cr-128); - //G = 1.164*(Y-16) - 0.813*(Cb-128) - 0.391*(Cr-128); - //B = 1.164*(Y-16) + 1.596*(Cb-128); - // - Y = Y + (Y >> 3) + (Y >> 5) + (Y >> 7); - R = Y + (Cr << 1) + (Cr >> 6); - if(R < 0) R = 0; else if(R > 255) R = 255; - G = Y - Cb + (Cb >> 3) + (Cb >> 4) - (Cr >> 1) + (Cr >> 3); - if(G < 0) G = 0; else if(G > 255) G = 255; - B = Y + Cb + (Cb >> 1) + (Cb >> 4) + (Cb >> 5); - if(B < 0) B = 0; else if(B > 255) B = 255; - rgbData[pixPtr++] = 0xff000000 + (R << 16) + (G << 8) + B; - } - } - - env->ReleasePrimitiveArrayCritical(rgbOut, rgbData, 0); - env->ReleasePrimitiveArrayCritical(yuv420sp, yuv, 0); -} - -#endif \ No newline at end of file diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Ref.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Ref.cpp deleted file mode 100755 index ac415c5..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Ref.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Ref.hpp" -#include -#include "Context.hpp" -#include "util.h" - -NS_GI_BEGIN - -Ref::Ref() -:_referenceCount(1) -{ -} - -Ref::~Ref() { -} - -void Ref::retain() { - assert(_referenceCount > 0); - ++_referenceCount; -} - -void Ref::release() { - assert(_referenceCount > 0); - --_referenceCount; - if (_referenceCount == 0) { - delete this; - } -} - -void Ref::resetRefenceCount() { - _referenceCount = 1; -} - -unsigned int Ref::getReferenceCount() const { - return _referenceCount; -} - - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Ref.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Ref.hpp deleted file mode 100755 index 2371e9b..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Ref.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Ref_hpp -#define Ref_hpp - -#include "macros.h" - -NS_GI_BEGIN - -class Ref { -public: - virtual ~Ref(); - - void retain(); - virtual void release(); - void resetRefenceCount(); - unsigned int getReferenceCount() const; - -protected: - unsigned int _referenceCount; - Ref(); - -}; - -NS_GI_END - -#endif /* Ref_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BeautifyFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BeautifyFilter.hpp deleted file mode 100755 index a548d12..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BeautifyFilter.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BeautifyFilter_hpp -#define BeautifyFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "BilateralFilter.hpp" -#include "CannyEdgeDetectionFilter.hpp" -#include "ColorInvertFilter.hpp" -#include "GrayscaleFilter.hpp" -#include "HSBFilter.hpp" - -NS_GI_BEGIN - -class CombinationFilter; - -class BeautifyFilter : public FilterGroup { -public: - static BeautifyFilter* create(); - bool init(); - bool proceed(bool bUpdateTargets = true) override; - - virtual void setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode = NoRotation, int texIdx = 0) override; - -protected: - BeautifyFilter(); - ~BeautifyFilter(); - - BilateralFilter* _bilateralFilter; - CannyEdgeDetectionFilter* _cannyEdgeDetectionFilter; - CombinationFilter* _combinationFilter; - HSBFilter* _hsbFilter; -}; - -NS_GI_END - -#endif /* BeautifyFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BrightnessFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BrightnessFilter.cpp deleted file mode 100755 index 3d3c7b6..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BrightnessFilter.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "BrightnessFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(BrightnessFilter) - -const std::string kBrightnessFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float brightness; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - gl_FragColor = vec4((color.rgb + vec3(brightness)), color.a); - } -); - - -BrightnessFilter* BrightnessFilter::create(float brightness/* = 0.0*/) { - BrightnessFilter* ret = new (std::nothrow) BrightnessFilter(); - if (ret && !ret->init(brightness)) { - delete ret; - ret = 0; - } - return ret; -} - -bool BrightnessFilter::init(float brightness) { - if (!initWithFragmentShaderString(kBrightnessFragmentShaderString)) return false; - - _brightness = brightness; - registerProperty("brightness", _brightness, "The brightness of filter with range between -1 and 1.", [this](float& brightness){ - setBrightness(brightness); - }); - - return true; -} - -void BrightnessFilter::setBrightness(float brightness) { - _brightness = brightness; - if (_brightness > 1.0) _brightness = 1.0; - else if (_brightness < -1.0) _brightness = -1.0; -} - -bool BrightnessFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("brightness", _brightness); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BrightnessFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BrightnessFilter.hpp deleted file mode 100755 index cd33d64..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BrightnessFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef BrightnessFilter_hpp -#define BrightnessFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class BrightnessFilter : public Filter { -public: - static BrightnessFilter* create(float brightness = 0.0); - bool init(float brightness); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setBrightness(float brightness); - -protected: - BrightnessFilter() {}; - - float _brightness; -}; - -NS_GI_END - -#endif /* BrightnessFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CannyEdgeDetectionFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CannyEdgeDetectionFilter.cpp deleted file mode 100755 index 09e6dff..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CannyEdgeDetectionFilter.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CannyEdgeDetectionFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(CannyEdgeDetectionFilter) - -CannyEdgeDetectionFilter::CannyEdgeDetectionFilter() -:_grayscaleFilter(0) -,_blurFilter(0) -,_edgeDetectionFilter(0) -,_nonMaximumSuppressionFilter(0) -,_weakPixelInclusionFilter(0) -{ -} - -CannyEdgeDetectionFilter::~CannyEdgeDetectionFilter() { - if (_grayscaleFilter) { - _grayscaleFilter->release(); - _grayscaleFilter = 0; - } - if (_blurFilter) { - _blurFilter->release(); - _blurFilter = 0; - } - if (_edgeDetectionFilter) { - _edgeDetectionFilter->release(); - _edgeDetectionFilter = 0; - } - if (_nonMaximumSuppressionFilter) { - _nonMaximumSuppressionFilter->release(); - _nonMaximumSuppressionFilter = 0; - } - if (_weakPixelInclusionFilter) { - _weakPixelInclusionFilter->release(); - _weakPixelInclusionFilter = 0; - } -} - -CannyEdgeDetectionFilter* CannyEdgeDetectionFilter::create() { - CannyEdgeDetectionFilter* ret = new (std::nothrow) CannyEdgeDetectionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool CannyEdgeDetectionFilter::init() { - if (!FilterGroup::init()) { - return false; - } - - // 1. convert image to luminance - _grayscaleFilter = GrayscaleFilter::create(); - - // 2. apply a varialbe Gaussian blur - _blurFilter = SingleComponentGaussianBlurFilter::create(); - - // 3. soble edge detection - _edgeDetectionFilter = DirectionalSobelEdgeDetectionFilter::create(); - - // 4. apply non-maximum suppression - _nonMaximumSuppressionFilter = DirectionalNonMaximumSuppressionFilter::create(); - - // 5. include weak pixels to complete edges - _weakPixelInclusionFilter = WeakPixelInclusionFilter::create(); - - - _grayscaleFilter->addTarget(_blurFilter)->addTarget(_edgeDetectionFilter)->addTarget(_nonMaximumSuppressionFilter)->addTarget(_weakPixelInclusionFilter); - addFilter(_grayscaleFilter); - - return true; -} - - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorInvertFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorInvertFilter.cpp deleted file mode 100755 index 40333b7..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorInvertFilter.cpp +++ /dev/null @@ -1,59 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ColorInvertFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(ColorInvertFilter) - -const std::string kColorInvertFragmentShaderString = SHADER_STRING -( - - uniform sampler2D colorMap; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - gl_FragColor = vec4((1.0 - color.rgb), color.a); - } -); - - -ColorInvertFilter* ColorInvertFilter::create() { - ColorInvertFilter* ret = new (std::nothrow) ColorInvertFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool ColorInvertFilter::init() { - if (!Filter::initWithFragmentShaderString(kColorInvertFragmentShaderString)) return false; - return true; -} - - -bool ColorInvertFilter::proceed(bool bUpdateTargets/* = true*/) { - return Filter::proceed(bUpdateTargets); -} - - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorInvertFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorInvertFilter.hpp deleted file mode 100755 index 1cf4bad..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorInvertFilter.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ColorInvertFilter_hpp -#define ColorInvertFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class ColorInvertFilter : public Filter { -public: - - static ColorInvertFilter* create(); - bool init(); - - virtual bool proceed(bool bUpdateTargets = true) override; -protected: - ColorInvertFilter() {}; -}; - -NS_GI_END - -#endif /* ColorInvertFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorMatrixFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorMatrixFilter.cpp deleted file mode 100755 index 0f9ba81..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorMatrixFilter.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ColorMatrixFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(ColorMatrixFilter) - -const std::string kColorMatrixFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp mat4 colorMatrix; - uniform lowp float intensity; - - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 textureColor = texture2D(colorMap, vTexCoord); - lowp vec4 outputColor = textureColor * colorMatrix; - - gl_FragColor = (intensity * outputColor) + ((1.0 - intensity) * textureColor); - } -); - - -const std::string kBrightnessFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float brightness; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - gl_FragColor = vec4((color.rgb + vec3(brightness)), color.w); - } - ); - -ColorMatrixFilter::ColorMatrixFilter() -:_intensity(1.0) -,_colorMatrix(Matrix4::IDENTITY) -{ - -} - -ColorMatrixFilter* ColorMatrixFilter::create() { - ColorMatrixFilter* ret = new (std::nothrow) ColorMatrixFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool ColorMatrixFilter::init() { - if ( !Filter::initWithFragmentShaderString(kColorMatrixFragmentShaderString)) return false; - - registerProperty("intensity", _intensity, "The percentage of color applied by color matrix with range between 0 and 1.", [this](float& intensity){ - if (intensity > 1.0) intensity = 1.0; - else if (intensity < 0.0) intensity = 0.0; - setIntensity(1.0); - }); - - // todo register paoperty of color matrix - - return true; -} - -bool ColorMatrixFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("intensity", _intensity); - _filterProgram->setUniformValue("colorMatrix", _colorMatrix); - return Filter::proceed(bUpdateTargets); -} - - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ContrastFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ContrastFilter.hpp deleted file mode 100755 index 036a22c..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ContrastFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ContrastFilter_hpp -#define ContrastFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class ContrastFilter : public Filter { -public: - static ContrastFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setContrast(float contrast); - -protected: - ContrastFilter() {}; - - float _contrast; -}; - -NS_GI_END - -#endif /* ContrastFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Convolution3x3Filter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Convolution3x3Filter.cpp deleted file mode 100755 index b7bc1ff..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Convolution3x3Filter.cpp +++ /dev/null @@ -1,82 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Convolution3x3Filter.hpp" - - - -NS_GI_BEGIN - - - -const std::string kConvolution3x3FragmentShaderString = SHADER_STRING -( - precision highp float; - uniform sampler2D colorMap; - uniform mediump mat3 convolutionMatrix; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - - - void main() - { - mediump vec3 bottomColor = texture2D(colorMap, vBottomTexCoord).rgb; - mediump vec3 bottomLeftColor = texture2D(colorMap, vBottomLeftTexCoord).rgb; - mediump vec3 bottomRightColor = texture2D(colorMap, vBottomRightTexCoord).rgb; - mediump vec4 centerColor = texture2D(colorMap, vTexCoord); - mediump vec3 leftColor = texture2D(colorMap, vLeftTexCoord).rgb; - mediump vec3 rightColor = texture2D(colorMap, vRightTexCoord).rgb; - mediump vec3 topColor = texture2D(colorMap, vTopTexCoord).rgb; - mediump vec3 topRightColor = texture2D(colorMap, vTopRightTexCoord).rgb; - mediump vec3 topLeftColor = texture2D(colorMap, vTopLeftTexCoord).rgb; - - mediump vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2]; - resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2]; - resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2]; - - gl_FragColor = vec4(resultColor, centerColor.a); - } - ); - - -bool Convolution3x3Filter::init() { - if(!NearbySampling3x3Filter::initWithFragmentShaderString(kConvolution3x3FragmentShaderString)) return false; - - _convolutionKernel.set(0.f, 0.f, 0.f, - 0.f, 1.f, 0.f, - 0.f, 0.f, 0.f); - - - return true; -} - -bool Convolution3x3Filter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("convolutionMatrix", _convolutionKernel); - return NearbySampling3x3Filter::proceed(bUpdateTargets); -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Convolution3x3Filter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Convolution3x3Filter.hpp deleted file mode 100755 index c430453..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Convolution3x3Filter.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Convolution3x3Filter_hpp -#define Convolution3x3Filter_hpp - -#include "../macros.h" -#include "NearbySampling3x3Filter.hpp" -#include "../math.hpp" - -NS_GI_BEGIN - -class Convolution3x3Filter : public NearbySampling3x3Filter { -public: - virtual bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; -protected: - Convolution3x3Filter() {}; - - - //The convolution kernel is a 3x3 matrix of values to apply to the pixel and its 8 surrounding pixels. - Matrix3 _convolutionKernel; -}; - -NS_GI_END - -#endif /* Convolution3x3Filter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CrosshatchFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CrosshatchFilter.cpp deleted file mode 100755 index 03caf16..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CrosshatchFilter.cpp +++ /dev/null @@ -1,114 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "CrosshatchFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(CrosshatchFilter) - -const std::string kCrosshatchFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - varying highp vec2 vTexCoord; - uniform highp float crossHatchSpacing; - uniform highp float lineWidth; - - const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); - - void main() - { - highp float luminance = dot(texture2D(colorMap, vTexCoord).rgb, W); - - lowp vec4 colorToDisplay = vec4(1.0, 1.0, 1.0, 1.0); - if (luminance < 1.00) - { - if (mod(vTexCoord.x + vTexCoord.y, crossHatchSpacing) <= lineWidth) - { - colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); - } - } - if (luminance < 0.75) - { - if (mod(vTexCoord.x - vTexCoord.y, crossHatchSpacing) <= lineWidth) - { - colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); - } - } - if (luminance < 0.50) - { - if (mod(vTexCoord.x + vTexCoord.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) - { - colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); - } - } - if (luminance < 0.3) - { - if (mod(vTexCoord.x - vTexCoord.y - (crossHatchSpacing / 2.0), crossHatchSpacing) <= lineWidth) - { - colorToDisplay = vec4(0.0, 0.0, 0.0, 1.0); - } - } - - gl_FragColor = colorToDisplay; - } - -); - - - - -CrosshatchFilter* CrosshatchFilter::create() { - CrosshatchFilter* ret = new (std::nothrow) CrosshatchFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool CrosshatchFilter::init() { - if (!initWithFragmentShaderString(kCrosshatchFragmentShaderString)) return false; - - - setCrossHatchSpacing(0.03); - registerProperty("crossHatchSpacing", _crossHatchSpacing, "The fractional width of the image to use as the spacing for the crosshatch. The default is 0.03.", [this](float& crossHatchSpacing){ - setCrossHatchSpacing(crossHatchSpacing); - }); - - setLineWidth(0.003); - registerProperty("lineWidth", _lineWidth, "A relative width for the crosshatch lines. The default is 0.003.", [this](float& lineWidth){ - setLineWidth(lineWidth); - }); - return true; -} - -bool CrosshatchFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("crossHatchSpacing", _crossHatchSpacing); - _filterProgram->setUniformValue("lineWidth", _lineWidth); - return Filter::proceed(bUpdateTargets); -} - -void CrosshatchFilter::setCrossHatchSpacing(float crossHatchSpacing) { - _crossHatchSpacing = crossHatchSpacing; -} - -void CrosshatchFilter::setLineWidth(float lineWidth) { - _lineWidth = lineWidth; -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CrosshatchFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CrosshatchFilter.hpp deleted file mode 100755 index 3c52332..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CrosshatchFilter.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef CrosshatchFilter_hpp -#define CrosshatchFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class CrosshatchFilter : public Filter { -public: - static CrosshatchFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setCrossHatchSpacing(float crossHatchSpacing); - void setLineWidth(float lineWidth); - -protected: - CrosshatchFilter() {}; - - float _crossHatchSpacing; - float _lineWidth; -}; - -NS_GI_END - -#endif /* CrosshatchFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalNonMaximumSuppressionFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalNonMaximumSuppressionFilter.hpp deleted file mode 100755 index 9f341ab..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalNonMaximumSuppressionFilter.hpp +++ /dev/null @@ -1,44 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DirectionalNonMaximumSuppressionFilter_hpp -#define DirectionalNonMaximumSuppressionFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class DirectionalNonMaximumSuppressionFilter : public Filter { -public: - static DirectionalNonMaximumSuppressionFilter* create(); - bool init(); - - virtual bool proceed(bool bUpdateTargets = true) override; - - -protected: - GLuint _texelWidthUniform; - GLuint _texelHeightUniform; - DirectionalNonMaximumSuppressionFilter() {}; -}; - -NS_GI_END - - -#endif /* DirectionalNonMaximumSuppressionFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalSobelEdgeDetectionFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalSobelEdgeDetectionFilter.hpp deleted file mode 100755 index da3c1b1..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalSobelEdgeDetectionFilter.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef DirectionalSobelEdgeDetectionFilter_hpp -#define DirectionalSobelEdgeDetectionFilter_hpp - -#include "../macros.h" -#include "NearbySampling3x3Filter.hpp" - -NS_GI_BEGIN - -class DirectionalSobelEdgeDetectionFilter : public NearbySampling3x3Filter { -public: - static DirectionalSobelEdgeDetectionFilter* create(); - bool init(); - - -protected: - - DirectionalSobelEdgeDetectionFilter() {}; -}; - -NS_GI_END - -#endif /* DirectionalSobelEdgeDetectionFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/EmbossFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/EmbossFilter.cpp deleted file mode 100755 index 7d3ee8e..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/EmbossFilter.cpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "EmbossFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(EmbossFilter) - -EmbossFilter* EmbossFilter::create() { - EmbossFilter* ret = new (std::nothrow) EmbossFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool EmbossFilter::init() { - if (!Convolution3x3Filter::init()) return false; - - _intensity = 1.0; - setIntensity(_intensity); - - registerProperty("intensity", _intensity, "The strength of the embossing, from 0.0 to 4.0, with 1.0 as the normal level", [this](float& intensity){ - setIntensity(intensity); - }); - - return true; -} - -void EmbossFilter::setIntensity(float intensity) { - _intensity = intensity; - if (_intensity > 4.0) _intensity = 4.0; - else if (_intensity < 0.0) _intensity = 0.0; - - _convolutionKernel.set(-2.0 * _intensity, -_intensity, 0.0, - -_intensity, 1.0, _intensity, - 0.0, _intensity, _intensity * 2.0 - ); -} - - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/EmbossFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/EmbossFilter.hpp deleted file mode 100755 index 9de8ea3..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/EmbossFilter.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef EmbossFilter_hpp -#define EmbossFilter_hpp - -#include "../macros.h" -#include "Convolution3x3Filter.hpp" - -NS_GI_BEGIN - -class EmbossFilter : public Convolution3x3Filter { -public: - static EmbossFilter* create(); - bool init(); - - void setIntensity(float intensity); - -protected: - EmbossFilter() {}; - - float _intensity; -}; - -NS_GI_END - -#endif /* EmbossFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ExposureFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ExposureFilter.cpp deleted file mode 100755 index 58c7cc9..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ExposureFilter.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "ExposureFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(ExposureFilter) - -const std::string kExposureFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float exposure; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - gl_FragColor = vec4(color.rgb * pow(2.0, exposure), color.a); - } -); - - -ExposureFilter* ExposureFilter::create() { - ExposureFilter* ret = new (std::nothrow) ExposureFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool ExposureFilter::init() { - if (!initWithFragmentShaderString(kExposureFragmentShaderString)) return false; - - _exposure = 0.0; - registerProperty("exposure", _exposure, "The exposure of the image. Exposure ranges from -10.0 to 10.0 (max contrast), with 0.0 as the normal level", [this](float& exposure){ - setExposure(exposure); - }); - - return true; -} - -void ExposureFilter::setExposure(float exposure) { - _exposure = exposure; - if (_exposure > 10.0) _exposure = 10.0; - else if (_exposure < -10.0) _exposure = -10.0; -} - -bool ExposureFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("exposure", _exposure); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ExposureFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ExposureFilter.hpp deleted file mode 100755 index 9dbb52f..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ExposureFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ExposureFilter_hpp -#define ExposureFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class ExposureFilter : public Filter { -public: - static ExposureFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setExposure(float exposure); - -protected: - ExposureFilter() {}; - - float _exposure; -}; - -NS_GI_END - -#endif /* BrightnessFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/FilterGroup.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/FilterGroup.hpp deleted file mode 100755 index 2e73118..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/FilterGroup.hpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef FilterGroup_hpp -#define FilterGroup_hpp - -#include "../macros.h" -#include "../source/Source.hpp" -#include "../target/Target.hpp" -#include -#include "Filter.hpp" - -NS_GI_BEGIN - -class FilterGroup : public Filter { -public: - virtual ~FilterGroup(); - - static FilterGroup* create(); - static FilterGroup* create(std::vector filters); - - bool init(); - bool init(std::vector filters); - bool hasFilter(const Filter* filter) const; - void addFilter(Filter* filter); - void removeFilter(Filter* filter); - void removeAllFilters(); - - // Manually specify the terminal filter, which is the final output filter of sequence - // Most often, it's not necessary to specify the terminal filter manually, - // as the terminal filter will be specified automatically. - void setTerminalFilter(Filter* filter) { _terminalFilter = filter; } - - virtual Source* addTarget(Target* target) override; -//#if GI_TARGET_PLATFORM == GI_PLATFORM_IOS -// virtual Source* addTarget(id target) override; -//#endif - virtual void removeTarget(Target* target) override; - virtual void removeAllTargets() override; - virtual bool hasTarget(const Target* target) const override; - virtual std::map& getTargets() override; - virtual bool proceed(bool bUpdateTargets = true) override; - virtual void update(float frameTime) override; - virtual void updateTargets(float frameTime) override; - virtual void setFramebuffer(Framebuffer* fb, RotationMode outputRotation = RotationMode::NoRotation) override; - virtual Framebuffer* getFramebuffer() const override; - virtual void setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode = NoRotation, int texIdx = 0) override; - virtual bool isPrepared() const override; - virtual void unPrepear() override; - -protected: - std::vector _filters; - Filter* _terminalFilter; - - FilterGroup(); - static Filter* _predictTerminalFilter(Filter* filter); - -}; - -NS_GI_END - -#endif /* FilterGroup_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurFilter.cpp deleted file mode 100755 index 8e977ad..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurFilter.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "GaussianBlurFilter.hpp" -#include "../util.h" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(GaussianBlurFilter) - -GaussianBlurFilter::GaussianBlurFilter() -:_hBlurFilter(0) -,_vBlurFilter(0) -{ -} - -GaussianBlurFilter::~GaussianBlurFilter() { - if (_hBlurFilter) { - _hBlurFilter->release(); - _hBlurFilter = 0; - } - - if (_vBlurFilter) { - _vBlurFilter->release(); - _vBlurFilter = 0; - } - -} - -GaussianBlurFilter* GaussianBlurFilter::create(int radius/* = 4*/, float sigma/* = 2.0*/) { - GaussianBlurFilter* ret = new (std::nothrow) GaussianBlurFilter(); - if (ret && !ret->init(radius, sigma)) { - delete ret; - ret = 0; - } - return ret; -} - -bool GaussianBlurFilter::init(int radius, float sigma) { - if (!FilterGroup::init()) { - return false; - } - - _hBlurFilter = GaussianBlurMonoFilter::create(GaussianBlurMonoFilter::HORIZONTAL, radius, sigma); - _vBlurFilter = GaussianBlurMonoFilter::create(GaussianBlurMonoFilter::VERTICAL, radius, sigma); - _hBlurFilter->addTarget(_vBlurFilter); - addFilter(_hBlurFilter); - - registerProperty("radius", 4, "", [this](int& radius){ - setRadius(radius); - }); - - registerProperty("sigma", 2.0, "", [this](float& sigma){ - setSigma(sigma); - }); - - return true; -} - -void GaussianBlurFilter::setRadius(int radius) { - _hBlurFilter->setRadius(radius); - _vBlurFilter->setRadius(radius); -} - -void GaussianBlurFilter::setSigma(float sigma) { - _hBlurFilter->setSigma(sigma); - _vBlurFilter->setSigma(sigma); -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurFilter.hpp deleted file mode 100755 index 068250c..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurFilter.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GaussianBlurFilter_hpp -#define GaussianBlurFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "GaussianBlurMonoFilter.hpp" - -NS_GI_BEGIN - -class GaussianBlurFilter : public FilterGroup { -public: - virtual ~GaussianBlurFilter(); - - static GaussianBlurFilter* create(int radius = 4, float sigma = 2.0); - bool init(int radius, float sigma); - void setRadius(int radius); - void setSigma(float sigma); - -protected: - GaussianBlurFilter(); - -private: - GaussianBlurMonoFilter* _hBlurFilter; - GaussianBlurMonoFilter* _vBlurFilter; -}; - - -NS_GI_END - -#endif /* GaussianBlurFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurMonoFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurMonoFilter.hpp deleted file mode 100755 index 645cf31..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurMonoFilter.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GaussianBlurMonoFilter_hpp -#define GaussianBlurMonoFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" - -NS_GI_BEGIN - -class GaussianBlurMonoFilter : public Filter { -public: - enum Type {HORIZONTAL, VERTICAL}; - - static GaussianBlurMonoFilter* create(Type type = HORIZONTAL, int radius = 4, float sigma = 2.0); - bool init(int radius, float sigma); - - void setRadius(int radius); - void setSigma(float sigma); - - virtual bool proceed(bool bUpdateTargets = true) override; -protected: - GaussianBlurMonoFilter(Type type = HORIZONTAL); - Type _type; - int _radius; - float _sigma; - -private: - virtual std::string _generateVertexShaderString(int radius, float sigma); - virtual std::string _generateFragmentShaderString(int radius, float sigma); - - virtual std::string _generateOptimizedVertexShaderString(int radius, float sigma); - virtual std::string _generateOptimizedFragmentShaderString(int radius, float sigma); -}; - - -NS_GI_END - -#endif /* GaussianBlurMonoFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GlassSphereFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GlassSphereFilter.cpp deleted file mode 100755 index ad2369c..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GlassSphereFilter.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "GlassSphereFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(GlassSphereFilter) - -const std::string kGlassSphereFragmentShaderString = SHADER_STRING -( - - uniform sampler2D colorMap; - varying highp vec2 vTexCoord; - - uniform highp vec2 center; - uniform highp float radius; - uniform highp float aspectRatio; - uniform highp float refractiveIndex; - - const highp vec3 lightPosition = vec3(-0.5, 0.5, 1.0); - const highp vec3 ambientLightPosition = vec3(0.0, 0.0, 1.0); - - - void main() - { - highp vec2 textureCoordinateToUse = vec2(vTexCoord.x, (vTexCoord.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); - - highp float distanceFromCenter = distance(center, textureCoordinateToUse); - lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius); - - distanceFromCenter = distanceFromCenter / radius; - - highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); - highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); - - highp vec3 refractedVector = 2.0 * refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); - refractedVector.xy = -refractedVector.xy; - - highp vec3 finalSphereColor = texture2D(colorMap, (refractedVector.xy + 1.0) * 0.5 + center - vec2(0.5)).rgb; - - // Grazing angle lighting - highp float lightingIntensity = 2.5 * (1.0 - pow(clamp(dot(ambientLightPosition, sphereNormal), 0.0, 1.0), 0.25)); - finalSphereColor += lightingIntensity; - - // Specular lighting - //lightingIntensity = clamp(dot(normalize(lightPosition), sphereNormal), 0.0, 1.0); - //lightingIntensity = pow(lightingIntensity, 15.0); - //finalSphereColor += vec3(0.8, 0.8, 0.8) * lightingIntensity; - - gl_FragColor = vec4(finalSphereColor, 1.0) * checkForPresenceWithinSphere; - } - ); - - - -GlassSphereFilter* GlassSphereFilter::create() { - GlassSphereFilter* ret = new (std::nothrow) GlassSphereFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool GlassSphereFilter::init() { - if (!initWithFragmentShaderString(kGlassSphereFragmentShaderString)) return false; - - setPositionX(0.5); - registerProperty("positionX", _position.x, "The position of x about which to apply the distortion, with a default of 0.5", [this](float& positionX){ - setPositionX(positionX); - }); - - setPositionY(0.5); - registerProperty("positionY", _position.y, "The position of y about which to apply the distortion, with a default of 0.5", [this](float& positionY){ - setPositionY(positionY); - }); - - setRadius(0.25); - registerProperty("radius", _radius, "The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.25", [this](float& radius){ - setRadius(radius); - }); - - setRefractiveIndex(0.71); - registerProperty("refractiveIndex", _refractiveIndex, "The index of refraction for the sphere, with a default of 0.71", [this](float& refractiveIndex){ - setRefractiveIndex(refractiveIndex); - }); - - return true; -} diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GlassSphereFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GlassSphereFilter.hpp deleted file mode 100755 index 8fe31ee..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GlassSphereFilter.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GlassSphereFilter_hpp -#define GlassSphereFilter_hpp - -#include "../macros.h" -#include "SphereRefractionFilter.hpp" - -NS_GI_BEGIN - -class GlassSphereFilter : public SphereRefractionFilter { -public: - static GlassSphereFilter* create(); - bool init(); - -protected: - GlassSphereFilter() {}; -}; - -NS_GI_END - -#endif /* GlassSphereFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GrayscaleFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GrayscaleFilter.cpp deleted file mode 100755 index 9a92a14..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GrayscaleFilter.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "GrayscaleFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(GrayscaleFilter) - -const std::string kGrayscaleFragmentShaderString = SHADER_STRING -( - precision highp float; - uniform sampler2D colorMap; - varying highp vec2 vTexCoord; - - const highp vec3 W = vec3(0.2125, 0.7154, 0.0721); - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - float luminance = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721)); - gl_FragColor = vec4(vec3(luminance), color.a); - } -); - - -GrayscaleFilter* GrayscaleFilter::create() { - GrayscaleFilter* ret = new (std::nothrow) GrayscaleFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool GrayscaleFilter::init() { - if (Filter::initWithFragmentShaderString(kGrayscaleFragmentShaderString)) { - return true; - } - return false; -} - -bool GrayscaleFilter::proceed(bool bUpdateTargets/* = true*/) { - return Filter::proceed(bUpdateTargets); -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GrayscaleFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GrayscaleFilter.hpp deleted file mode 100755 index 5d4405d..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GrayscaleFilter.hpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GrayscaleFilter_hpp -#define GrayscaleFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class GrayscaleFilter : public Filter { -public: - static GrayscaleFilter* create(); - bool init(); - - virtual bool proceed(bool bUpdateTargets = true) override; - -protected: - GrayscaleFilter() {}; -}; - - -NS_GI_END - -#endif /* GrayscaleFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HSBFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HSBFilter.hpp deleted file mode 100755 index bf47895..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HSBFilter.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HSBFilter_hpp -#define HSBFilter_hpp - -#include "../macros.h" -#include "ColorMatrixFilter.hpp" - -NS_GI_BEGIN - - -class HSBFilter : public ColorMatrixFilter { -public: - static HSBFilter* create(); - bool init(); - - /** Reset the filter to have no transformations. - */ - void reset(); - - /** Add a hue rotation to the filter. - The hue rotation is in the range [-360, 360] with 0 being no-change. - Note that this adjustment is additive, so use the reset method if you need to. - */ - void rotateHue(float h); - - /** Add a saturation adjustment to the filter. - The saturation adjustment is in the range [0.0, 2.0] with 1.0 being no-change. - Note that this adjustment is additive, so use the reset method if you need to. - */ - void adjustSaturation(float s); - - /** Add a brightness adjustment to the filter. - The brightness adjustment is in the range [0.0, 2.0] with 1.0 being no-change. - Note that this adjustment is additive, so use the reset method if you need to. - */ - void adjustBrightness(float b); - -protected: - HSBFilter() {}; -}; - - -NS_GI_END - -#endif /* HSBFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HalftoneFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HalftoneFilter.hpp deleted file mode 100755 index e94a23b..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HalftoneFilter.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HalftoneFilter_hpp -#define HalftoneFilter_hpp - -#include "../macros.h" -#include "PixellationFilter.hpp" - -NS_GI_BEGIN - -class HalftoneFilter : public PixellationFilter { -public: - static HalftoneFilter* create(); - bool init(); - -protected: - HalftoneFilter() {}; -}; - -NS_GI_END - -#endif /* HalftoneFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HueFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HueFilter.hpp deleted file mode 100755 index afc6135..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HueFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef HueFilter_hpp -#define HueFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class HueFilter : public Filter { -public: - static HueFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setHueAdjustment(float hueAdjustment); - -protected: - HueFilter() {}; - - float _hueAdjustment; -}; - -NS_GI_END - -#endif /* HueFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/IOSBlurFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/IOSBlurFilter.hpp deleted file mode 100755 index 28f1680..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/IOSBlurFilter.hpp +++ /dev/null @@ -1,58 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef IOSBlurFilter_hpp -#define IOSBlurFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "SaturationFilter.hpp" -#include "GaussianBlurFilter.hpp" -#include "LuminanceRangeFilter.hpp" - -NS_GI_BEGIN - -class IOSBlurFilter : public FilterGroup { -public: - virtual ~IOSBlurFilter(); - - static IOSBlurFilter* create(); - bool init(); - - void setBlurSigma(float blurSigma); - void setSaturation(float saturation); - void setRangeReductionFactor(float rangeReductionFactor); - void setDownSampling(float downSampling); - -protected: - - IOSBlurFilter(); - SaturationFilter* _saturationFilter; - GaussianBlurFilter* _blurFilter; - LuminanceRangeFilter* _luminanceRangeFilter; - - float _blurSigma; - float _saturation; - float _rangeReductionFactor; - float _downSampling; -}; - - -NS_GI_END - -#endif /* IOSBlurFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/LuminanceRangeFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/LuminanceRangeFilter.hpp deleted file mode 100755 index f496a8f..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/LuminanceRangeFilter.hpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef LuminanceRangeFilter_hpp -#define LuminanceRangeFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class LuminanceRangeFilter : public Filter { -public: - static LuminanceRangeFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setRangeReductionFactor(float rangeReductionFactor); - -protected: - LuminanceRangeFilter() {}; - float _rangeReductionFactor; -}; - -NS_GI_END - -#endif /* LuminanceRangeFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NearbySampling3x3Filter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NearbySampling3x3Filter.cpp deleted file mode 100755 index 4849350..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NearbySampling3x3Filter.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "NearbySampling3x3Filter.hpp" - - - -NS_GI_BEGIN - - - -const std::string kNearbySampling3x3SamplingVertexShaderString = SHADER_STRING -( - attribute vec4 position; - attribute vec4 texCoord; - - uniform float texelWidth; - uniform float texelHeight; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - void main() - { - gl_Position = position; - - vec2 widthStep = vec2(texelWidth, 0.0); - vec2 heightStep = vec2(0.0, texelHeight); - vec2 widthHeightStep = vec2(texelWidth, texelHeight); - vec2 widthNegativeHeightStep = vec2(texelWidth, -texelHeight); - - vTexCoord = texCoord.xy; - vLeftTexCoord = texCoord.xy - widthStep; - vRightTexCoord = texCoord.xy + widthStep; - - vTopTexCoord = texCoord.xy - heightStep; - vTopLeftTexCoord = texCoord.xy - widthHeightStep; - vTopRightTexCoord = texCoord.xy + widthNegativeHeightStep; - - vBottomTexCoord = texCoord.xy + heightStep; - vBottomLeftTexCoord = texCoord.xy - widthNegativeHeightStep; - vBottomRightTexCoord = texCoord.xy + widthHeightStep; - } - ); - - -bool NearbySampling3x3Filter::initWithFragmentShaderString(const std::string& fragmentShaderSource, int inputNumber/* = 1*/) { - if(Filter::initWithShaderString(kNearbySampling3x3SamplingVertexShaderString, fragmentShaderSource)) { - _texelSizeMultiplier = 1.0; - _texelWidthUniform = _filterProgram->getUniformLocation("texelWidth"); - _texelHeightUniform = _filterProgram->getUniformLocation("texelHeight"); - - registerProperty("texelSizeMultiplier", _texelSizeMultiplier, "", [this](float& texelSizeMultiplier){ - setTexelSizeMultiplier(texelSizeMultiplier); - }); - - return true; - } - return false; -} - - -bool NearbySampling3x3Filter::proceed(bool bUpdateTargets/* = true*/) { - - float texelWidth = _texelSizeMultiplier / _framebuffer->getWidth(); - float texelHeight = _texelSizeMultiplier / _framebuffer->getHeight(); - - RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; - if (rotationSwapsSize(inputRotation)){ - texelWidth = _texelSizeMultiplier / _framebuffer->getHeight(); - texelHeight = _texelSizeMultiplier / _framebuffer->getWidth(); - } - - _filterProgram->setUniformValue(_texelWidthUniform, texelWidth); - _filterProgram->setUniformValue(_texelHeightUniform, texelHeight); - return Filter::proceed(bUpdateTargets); -} - -void NearbySampling3x3Filter::setTexelSizeMultiplier(float texelSizeMultiplier) { - if (texelSizeMultiplier > 0) - _texelSizeMultiplier = texelSizeMultiplier; -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NearbySampling3x3Filter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NearbySampling3x3Filter.hpp deleted file mode 100755 index ce439f9..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NearbySampling3x3Filter.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NearbySampling3x3Filter_hpp -#define NearbySampling3x3Filter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -extern const std::string kNearbySampling3x3SamplingVertexShaderString; - -class NearbySampling3x3Filter : public Filter { -public: - virtual bool initWithFragmentShaderString(const std::string& fragmentShaderSource, int inputNumber = 1) override; - virtual bool proceed(bool bUpdateTargets = true) override; - - void setTexelSizeMultiplier(float texelSizeMultiplier); -protected: - NearbySampling3x3Filter() {}; - - float _texelSizeMultiplier; - GLuint _texelWidthUniform; - GLuint _texelHeightUniform; -}; - -NS_GI_END - -#endif /* NearbySampling3x3Filter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NonMaximumSuppressionFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NonMaximumSuppressionFilter.hpp deleted file mode 100755 index e135322..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NonMaximumSuppressionFilter.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef NonMaximumSuppressionFilter_hpp -#define NonMaximumSuppressionFilter_hpp - -#include "../macros.h" -#include "NearbySampling3x3Filter.hpp" - -NS_GI_BEGIN - -class NonMaximumSuppressionFilter : public NearbySampling3x3Filter { -public: - static NonMaximumSuppressionFilter* create(); - bool init(); - - -protected: - - NonMaximumSuppressionFilter() {}; -}; - -NS_GI_END - -#endif /* NonMaximumSuppressionFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PixellationFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PixellationFilter.cpp deleted file mode 100755 index 0172575..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PixellationFilter.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "PixellationFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(PixellationFilter) - -const std::string kPixellationFragmentShaderString = SHADER_STRING -( - uniform highp float pixelSize; - uniform highp float aspectRatio; - - uniform sampler2D colorMap; - varying highp vec2 vTexCoord; - - void main() - { - highp vec2 pixelSizeVec = vec2(pixelSize, pixelSize / aspectRatio); - highp vec2 samplePos = floor(vTexCoord / pixelSizeVec) * pixelSizeVec + 0.5 * pixelSizeVec; - gl_FragColor = texture2D(colorMap, samplePos); - } - ); - - -PixellationFilter* PixellationFilter::create() { - PixellationFilter* ret = new (std::nothrow) PixellationFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool PixellationFilter::init() { - if (!initWithFragmentShaderString(kPixellationFragmentShaderString)) return false; - - _pixelSize = 0.1; - registerProperty("pixelSize", _pixelSize, "The size of a pixel that you want to pixellate, ranges from 0 to 1.", [this](float& pixelSize){ - setPixelSize(pixelSize); - }); - - return true; -} - -void PixellationFilter::setPixelSize(float pixelSize) { - _pixelSize = pixelSize; - if (_pixelSize > 1.0) _pixelSize = 1.0; - else if (_pixelSize < 0.0) _pixelSize = 0.0; - -} - -bool PixellationFilter::proceed(bool bUpdateTargets/* = true*/) { - - float aspectRatio = 1.0; - Framebuffer* firstInputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - aspectRatio = firstInputFramebuffer->getHeight() / (float)(firstInputFramebuffer->getWidth()); - _filterProgram->setUniformValue("aspectRatio", aspectRatio); - - float pixelSize = _pixelSize; - float singlePixelWidth = 1.0 / firstInputFramebuffer->getWidth(); - if (pixelSize < singlePixelWidth) - { - pixelSize = singlePixelWidth; - } - _filterProgram->setUniformValue("pixelSize", pixelSize); - - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PixellationFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PixellationFilter.hpp deleted file mode 100755 index 1931551..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PixellationFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PixellationFilter_hpp -#define PixellationFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class PixellationFilter : public Filter { -public: - static PixellationFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setPixelSize(float pixelSize); - -protected: - PixellationFilter() {}; - - float _pixelSize; -}; - -NS_GI_END - -#endif /* PixellationFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PosterizeFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PosterizeFilter.hpp deleted file mode 100755 index d8d6234..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PosterizeFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef PosterizeFilter_hpp -#define PosterizeFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class PosterizeFilter : public Filter { -public: - static PosterizeFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setColorLevels(int colorLevels); - -protected: - PosterizeFilter() {}; - - int _colorLevels; -}; - -NS_GI_END - -#endif /* PosterizeFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/RGBFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/RGBFilter.cpp deleted file mode 100755 index 012e73b..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/RGBFilter.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "RGBFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(RGBFilter) - -const std::string kRGBFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform highp float redAdjustment; - uniform highp float greenAdjustment; - uniform highp float blueAdjustment; - varying highp vec2 vTexCoord; - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - gl_FragColor = vec4(color.r * redAdjustment, color.g * greenAdjustment, color.b * blueAdjustment, color.a); - } -); - - -RGBFilter* RGBFilter::create() { - RGBFilter* ret = new (std::nothrow) RGBFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool RGBFilter::init() { - if (!initWithFragmentShaderString(kRGBFragmentShaderString)) return false; - - _redAdjustment = 1.0; - _greenAdjustment = 1.0; - _blueAdjustment = 1.0; - - registerProperty("redAdjustment", _redAdjustment, "The red adjustment of the image.The range is from 0.0 up, with 1.0 as the default.", [this](float& redAdjustment){ - setRedAdjustment(redAdjustment); - }); - - registerProperty("greenAdjustment", _greenAdjustment, "The green adjustment of the image.The range is from 0.0 up, with 1.0 as the default.", [this](float& greenAdjustment){ - setGreenAdjustment(greenAdjustment); - }); - - registerProperty("blueAdjustment", _blueAdjustment, "The blue adjustment of the image.The range is from 0.0 up, with 1.0 as the default.", [this](float& blueAdjustment){ - setBlueAdjustment(blueAdjustment); - }); - - return true; -} - -void RGBFilter::setRedAdjustment(float redAdjustment) { - _redAdjustment = redAdjustment; - if (_redAdjustment < 0.0) _redAdjustment = 0.0; -} - -void RGBFilter::setGreenAdjustment(float greenAdjustment) { - _greenAdjustment = greenAdjustment; - if (_greenAdjustment < 0.0) _greenAdjustment = 0.0; -} - -void RGBFilter::setBlueAdjustment(float blueAdjustment) { - _blueAdjustment = blueAdjustment; - if (_blueAdjustment < 0.0) _blueAdjustment = 0.0; -} -bool RGBFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("redAdjustment", _redAdjustment); - _filterProgram->setUniformValue("greenAdjustment", _greenAdjustment); - _filterProgram->setUniformValue("blueAdjustment", _blueAdjustment); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/RGBFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/RGBFilter.hpp deleted file mode 100755 index c917167..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/RGBFilter.hpp +++ /dev/null @@ -1,47 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef RGBFilter_hpp -#define RGBFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class RGBFilter : public Filter { -public: - static RGBFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setRedAdjustment(float redAdjustment); - void setGreenAdjustment(float greenAdjustment); - void setBlueAdjustment(float blueAdjustment); - -protected: - RGBFilter() {}; - - float _redAdjustment; - float _greenAdjustment; - float _blueAdjustment; -}; - -NS_GI_END - -#endif /* RGBFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SaturationFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SaturationFilter.hpp deleted file mode 100755 index 47aa2a2..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SaturationFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SaturationFilter_hpp -#define SaturationFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class SaturationFilter : public Filter { -public: - static SaturationFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setSaturation(float saturation); - -protected: - SaturationFilter() {}; - - float _saturation; -}; - -NS_GI_END - -#endif /* SaturationFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurFilter.cpp deleted file mode 100755 index 7892208..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurFilter.cpp +++ /dev/null @@ -1,86 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include "SingleComponentGaussianBlurFilter.hpp" -#include "../util.h" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(SingleComponentGaussianBlurFilter) - -SingleComponentGaussianBlurFilter::SingleComponentGaussianBlurFilter() -:_hBlurFilter(0) -,_vBlurFilter(0) -{ -} - -SingleComponentGaussianBlurFilter::~SingleComponentGaussianBlurFilter() { - if (_hBlurFilter) { - _hBlurFilter->release(); - _hBlurFilter = 0; - } - - if (_vBlurFilter) { - _vBlurFilter->release(); - _vBlurFilter = 0; - } - -} - -SingleComponentGaussianBlurFilter* SingleComponentGaussianBlurFilter::create(int radius/* = 4*/, float sigma/* = 2.0*/) { - SingleComponentGaussianBlurFilter* ret = new (std::nothrow) SingleComponentGaussianBlurFilter(); - if (ret && !ret->init(radius, sigma)) { - delete ret; - ret = 0; - } - return ret; -} - -bool SingleComponentGaussianBlurFilter::init(int radius, float sigma) { - if (!FilterGroup::init()) { - return false; - } - - _hBlurFilter = SingleComponentGaussianBlurMonoFilter::create(SingleComponentGaussianBlurMonoFilter::HORIZONTAL, radius, sigma); - _vBlurFilter = SingleComponentGaussianBlurMonoFilter::create(SingleComponentGaussianBlurMonoFilter::VERTICAL, radius, sigma); - _hBlurFilter->addTarget(_vBlurFilter); - addFilter(_hBlurFilter); - - registerProperty("radius", 4, "", [this](int& radius){ - setRadius(radius); - }); - - registerProperty("sigma", 2.0, "", [this](float& sigma){ - setSigma(sigma); - }); - - return true; -} - -void SingleComponentGaussianBlurFilter::setRadius(int radius) { - _hBlurFilter->setRadius(radius); - _vBlurFilter->setRadius(radius); -} - -void SingleComponentGaussianBlurFilter::setSigma(float sigma) { - _hBlurFilter->setSigma(sigma); - _vBlurFilter->setSigma(sigma); -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurFilter.hpp deleted file mode 100755 index 3b30c31..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurFilter.hpp +++ /dev/null @@ -1,48 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SingleComponentGaussianBlurFilter_hpp -#define SingleComponentGaussianBlurFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "SingleComponentGaussianBlurMonoFilter.hpp" - -NS_GI_BEGIN - -class SingleComponentGaussianBlurFilter : public FilterGroup { -public: - virtual ~SingleComponentGaussianBlurFilter(); - - static SingleComponentGaussianBlurFilter* create(int radius = 4, float sigma = 2.0); - bool init(int radius, float sigma); - void setRadius(int radius); - void setSigma(float sigma); - -protected: - SingleComponentGaussianBlurFilter(); - -private: - SingleComponentGaussianBlurMonoFilter* _hBlurFilter; - SingleComponentGaussianBlurMonoFilter* _vBlurFilter; -}; - - -NS_GI_END - -#endif /* GaussianBlurFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurMonoFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurMonoFilter.cpp deleted file mode 100755 index 810e88e..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurMonoFilter.cpp +++ /dev/null @@ -1,187 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SingleComponentGaussianBlurMonoFilter.hpp" -#include - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(SingleComponentGaussianBlurMonoFilter) - -SingleComponentGaussianBlurMonoFilter::SingleComponentGaussianBlurMonoFilter(Type type/* = HORIZONTAL*/) -:GaussianBlurMonoFilter(type) -{ -} - -SingleComponentGaussianBlurMonoFilter* SingleComponentGaussianBlurMonoFilter::create(Type type/* = HORIZONTAL*/, int radius/* = 4*/, float sigma/* = 2.0*/) { - SingleComponentGaussianBlurMonoFilter* ret = new (std::nothrow) SingleComponentGaussianBlurMonoFilter(type); - if (ret && !ret->init(radius, sigma)) { - delete ret; - ret = 0; - } - return ret; -} - -std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedVertexShaderString(int radius, float sigma) -{ - if (radius < 1 || sigma <= 0.0) - { - return kDefaultVertexShader; - } - - // 1. generate the normal Gaussian weights for a given sigma - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); - if (i == 0) - sumOfWeights += standardGaussianWeights[i]; - else - sumOfWeights += 2.0 * standardGaussianWeights[i]; - } - - // 2. normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; - } - - // 3. From these weights we calculate the offsets to read interpolated values from - int numberOfOptimizedOffsets = fmin(radius / 2 + (radius % 2), 7); - float* optimizedGaussianOffsets = new float[numberOfOptimizedOffsets]; - - for (int i = 0; i < numberOfOptimizedOffsets; ++i) - { - GLfloat firstWeight = standardGaussianWeights[i * 2 + 1]; - GLfloat secondWeight = standardGaussianWeights[i * 2 + 2]; - - GLfloat optimizedWeight = firstWeight + secondWeight; - - optimizedGaussianOffsets[i] = (firstWeight * (i * 2 + 1) + secondWeight * (i * 2 + 2)) / optimizedWeight; - } - - std::string shaderStr = - str_format("\ - attribute vec4 position;\n\ - attribute vec4 texCoord;\n\ - uniform float texelWidthOffset;\n\ - uniform float texelHeightOffset;\n\ - varying highp vec2 blurCoordinates[%d];\n\ - void main()\n\ - {\n\ - gl_Position = position;\n\ - vec2 texelSpacing = vec2(texelWidthOffset, texelHeightOffset);\n\ - ", numberOfOptimizedOffsets * 2 + 1); - - shaderStr = shaderStr + str_format("blurCoordinates[0] = texCoord.xy;\n"); - for (int i = 0; i < numberOfOptimizedOffsets; ++i) { - shaderStr = shaderStr + str_format( - "blurCoordinates[%d] = texCoord.xy + texelSpacing * (%f);\n\ - blurCoordinates[%d] = texCoord.xy - texelSpacing * (%f);", - i * 2 + 1, - optimizedGaussianOffsets[i], - i * 2 + 2, - optimizedGaussianOffsets[i]); - } - - shaderStr += "}\n"; - - delete[] standardGaussianWeights; - delete[] optimizedGaussianOffsets; - - return shaderStr; -} - -std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedFragmentShaderString(int radius, float sigma) -{ - if (radius < 1 || sigma <= 0.0) - { - return kDefaultFragmentShader; - } - - // 1. generate the normal Gaussian weights for a given sigma - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); - if (i == 0) - sumOfWeights += standardGaussianWeights[i]; - else - sumOfWeights += 2.0 * standardGaussianWeights[i]; - } - - // 2. normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance - for (int i = 0; i < radius + 1; ++i) - { - standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; - } - - // 3. From these weights we calculate the offsets to read interpolated values from - int trueNumberOfOptimizedOffsets = radius / 2 + (radius % 2); - int numberOfOptimizedOffsets = fmin(trueNumberOfOptimizedOffsets, 7); - - std::string shaderStr = - str_format("\ - uniform sampler2D colorMap;\n\ - uniform highp float texelWidthOffset;\n\ - uniform highp float texelHeightOffset;\n\ - varying highp vec2 blurCoordinates[%d];\n\ - void main()\n\ - {\n\ - lowp float sum = 0.0;\n", numberOfOptimizedOffsets * 2 + 1); - - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[0]) * %f;\n", standardGaussianWeights[0]); - for (int i = 0; i < numberOfOptimizedOffsets; ++i) { - float firstWeight = standardGaussianWeights[i * 2 + 1]; - float secondWeight = standardGaussianWeights[i * 2 + 2]; - float optimizedWeight = firstWeight + secondWeight; - - shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[%d]).r * %f;\n", i * 2 + 1, optimizedWeight); - shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[%d]).r * %f;\n", i * 2 + 2, optimizedWeight); - } - - // If the number of required samples exceeds the amount we can pass in via varyings, we have to do dependent texture reads in the fragment shader - if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) - { - shaderStr += str_format("highp vec2 texelSpacing = vec2(texelWidthOffset, texelHeightOffset);\n"); - - for (int i = numberOfOptimizedOffsets; i < trueNumberOfOptimizedOffsets; i++) - { - float firstWeight = standardGaussianWeights[i * 2 + 1]; - float secondWeight = standardGaussianWeights[i * 2 + 2]; - - float optimizedWeight = firstWeight + secondWeight; - float optimizedOffset = (firstWeight * (i * 2 + 1) + secondWeight * (i * 2 + 2)) / optimizedWeight; - - shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[0] + texelSpacing * %f).r * %f;\n", optimizedOffset, optimizedWeight); - - shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[0] - texelSpacing * %f).r * %f;\n", optimizedOffset, optimizedWeight); - } - } - - shaderStr += - "gl_FragColor = vec4(sum, sum, sum, 1.0);\n\ - }"; - - delete[] standardGaussianWeights; standardGaussianWeights = 0; - return shaderStr; -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurMonoFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurMonoFilter.hpp deleted file mode 100755 index 8c306a1..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SingleComponentGaussianBlurMonoFilter.hpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SingleComponentGaussianBlurMonoFilter_hpp -#define SingleComponentGaussianBlurMonoFilter_hpp - -#include "../macros.h" -#include "GaussianBlurMonoFilter.hpp" - -NS_GI_BEGIN - -class SingleComponentGaussianBlurMonoFilter : public GaussianBlurMonoFilter { -public: - - static SingleComponentGaussianBlurMonoFilter* create(Type type = HORIZONTAL, int radius = 4, float sigma = 2.0); - -protected: - SingleComponentGaussianBlurMonoFilter(Type type = HORIZONTAL); - -private: - std::string _generateOptimizedVertexShaderString(int radius, float sigma) override; - std::string _generateOptimizedFragmentShaderString(int radius, float sigma) override; -}; - - -NS_GI_END - -#endif /* SingleComponentGaussianBlurMonoFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SketchFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SketchFilter.hpp deleted file mode 100755 index de3d3b7..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SketchFilter.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SketchFilter_hpp -#define SketchFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "GrayscaleFilter.hpp" -#include "NearbySampling3x3Filter.hpp" - -NS_GI_BEGIN - -// Sketch filter is just the Sobel edge detection filter with the colors inverted. - -class _SketchFilter; - -class SketchFilter : public FilterGroup { -public: - static SketchFilter* create(); - bool init(); - -protected: - SketchFilter(); - ~SketchFilter(); - - GrayscaleFilter* _grayscaleFilter; - _SketchFilter* _sketchFilter; - - float _edgeStrength; -}; - -class _SketchFilter : public NearbySampling3x3Filter { -public: - static _SketchFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setEdgeStrength(float edgeStrength); - -protected: - _SketchFilter() {}; - - float _edgeStrength; -}; - -NS_GI_END - -#endif /* SketchFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SmoothToonFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SmoothToonFilter.hpp deleted file mode 100755 index b70bb24..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SmoothToonFilter.hpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SmoothToonFilter_hpp -#define SmoothToonFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "GaussianBlurFilter.hpp" -#include "ToonFilter.hpp" - -NS_GI_BEGIN - -class SmoothToonFilter : public FilterGroup { -public: - virtual ~SmoothToonFilter(); - - static SmoothToonFilter* create(); - bool init(); - - void setBlurRadius(int blurRadius); - void setToonThreshold(float toonThreshold); - void setToonQuantizationLevels(float toonQuantizationLevels); - -protected: - SmoothToonFilter(); - -private: - GaussianBlurFilter* _gaussianBlurFilter; - ToonFilter* _toonFilter; - - float _blurRadius; - float _toonThreshold; - float _toonQuantizationLevels; -}; - - -NS_GI_END - -#endif /* SmoothToonFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SobelEdgeDetectionFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SobelEdgeDetectionFilter.hpp deleted file mode 100755 index 353a997..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SobelEdgeDetectionFilter.hpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SobelEdgeDetectionFilter_hpp -#define SobelEdgeDetectionFilter_hpp - -#include "../macros.h" -#include "FilterGroup.hpp" -#include "GrayscaleFilter.hpp" -#include "NearbySampling3x3Filter.hpp" - -NS_GI_BEGIN - -class _SobelEdgeDetectionFilter; - -class SobelEdgeDetectionFilter : public FilterGroup { -public: - static SobelEdgeDetectionFilter* create(); - bool init(); - -protected: - SobelEdgeDetectionFilter(); - ~SobelEdgeDetectionFilter(); - - GrayscaleFilter* _grayscaleFilter; - _SobelEdgeDetectionFilter* _sobelEdgeDetectionFilter; - - float _edgeStrength; -}; - -class _SobelEdgeDetectionFilter : public NearbySampling3x3Filter { -public: - static _SobelEdgeDetectionFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setEdgeStrength(float edgeStrength); - -protected: - _SobelEdgeDetectionFilter() {}; - - float _edgeStrength; -}; - -NS_GI_END - -#endif /* SobelEdgeDetectionFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SphereRefractionFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SphereRefractionFilter.cpp deleted file mode 100755 index b3c1033..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SphereRefractionFilter.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SphereRefractionFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(SphereRefractionFilter) - -const std::string kSphereRefractionShaderString = SHADER_STRING -( - - uniform sampler2D colorMap; - uniform highp vec2 center; - uniform highp float radius; - uniform highp float aspectRatio; - uniform highp float refractiveIndex; - - varying highp vec2 vTexCoord; - - void main() - { - highp vec2 textureCoordinateToUse = vec2(vTexCoord.x, (vTexCoord.y * aspectRatio + 0.5 - 0.5 * aspectRatio)); - highp float distanceFromCenter = distance(center, textureCoordinateToUse); - lowp float checkForPresenceWithinSphere = step(distanceFromCenter, radius); - - distanceFromCenter = distanceFromCenter / radius; - - highp float normalizedDepth = radius * sqrt(1.0 - distanceFromCenter * distanceFromCenter); - highp vec3 sphereNormal = normalize(vec3(textureCoordinateToUse - center, normalizedDepth)); - - highp vec3 refractedVector = refract(vec3(0.0, 0.0, -1.0), sphereNormal, refractiveIndex); - - gl_FragColor = texture2D(colorMap, (refractedVector.xy + 1.0) * 0.5) * checkForPresenceWithinSphere; - } - -); - - -SphereRefractionFilter* SphereRefractionFilter::create() { - SphereRefractionFilter* ret = new (std::nothrow) SphereRefractionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool SphereRefractionFilter::init() { - if (!initWithFragmentShaderString(kSphereRefractionShaderString)) return false; - - - setPositionX(0.5); - registerProperty("positionX", _position.x, "The position of x about which to apply the distortion, with a default of 0.5", [this](float& positionX){ - setPositionX(positionX); - }); - - setPositionY(0.5); - registerProperty("positionY", _position.y, "The position of y about which to apply the distortion, with a default of 0.5", [this](float& positionY){ - setPositionY(positionY); - }); - - setRadius(0.25); - registerProperty("radius", _radius, "The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.25", [this](float& radius){ - setRadius(radius); - }); - - setRefractiveIndex(0.71); - registerProperty("refractiveIndex", _refractiveIndex, "The index of refraction for the sphere, with a default of 0.71", [this](float& refractiveIndex){ - setRefractiveIndex(refractiveIndex); - }); - - return true; -} - -bool SphereRefractionFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("center", _position); - _filterProgram->setUniformValue("radius", _radius); - _filterProgram->setUniformValue("refractiveIndex", _refractiveIndex); - - float aspectRatio = 1.0; - Framebuffer* firstInputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; - aspectRatio = firstInputFramebuffer->getHeight() / (float)(firstInputFramebuffer->getWidth()); - _filterProgram->setUniformValue("aspectRatio", aspectRatio); - - return Filter::proceed(bUpdateTargets); -} - -void SphereRefractionFilter::setPositionX(float x) { - _position.x = x; -} - -void SphereRefractionFilter::setPositionY(float y) { - _position.y = y; -} - -void SphereRefractionFilter::setRadius(float radius) { - _radius = radius; -} - -void SphereRefractionFilter::setRefractiveIndex(float refractiveIndex) { - _refractiveIndex = refractiveIndex; -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SphereRefractionFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SphereRefractionFilter.hpp deleted file mode 100755 index 4350f29..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SphereRefractionFilter.hpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef SphereRefractionFilter_hpp -#define SphereRefractionFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class SphereRefractionFilter : public Filter { -public: - static SphereRefractionFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setPositionX(float x); - void setPositionY(float y); - void setRadius(float radius); - void setRefractiveIndex(float refractiveIndex); - -protected: - SphereRefractionFilter() {}; - - // The position about which to apply the distortion, with a default of (0.5, 0.5) - Vector2 _position; - - // The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.25 - float _radius; - - // The index of refraction for the sphere, with a default of 0.71 - float _refractiveIndex; - -}; - -NS_GI_END - -#endif /* SphereRefractionFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ToonFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ToonFilter.hpp deleted file mode 100755 index fff4b25..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ToonFilter.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef ToonFilter_hpp -#define ToonFilter_hpp - -#include "../macros.h" -#include "NearbySampling3x3Filter.hpp" - -NS_GI_BEGIN - -class ToonFilter : public NearbySampling3x3Filter { -public: - static ToonFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setThreshold(float threshold); - void setQuantizatinLevels(float quantizationLevels); - -protected: - ToonFilter() {}; - - float _threshold; - float _quantizationLevels; -}; - -NS_GI_END - -#endif /* ToonFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WeakPixelInclusionFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WeakPixelInclusionFilter.cpp deleted file mode 100755 index 9f4e7b0..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WeakPixelInclusionFilter.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WeakPixelInclusionFilter.hpp" - -NS_GI_BEGIN - -REGISTER_FILTER_CLASS(WeakPixelInclusionFilter) - -const std::string kWeakPixelInclusionFragmentShaderString = SHADER_STRING -( - precision mediump float; - uniform sampler2D colorMap; - - varying vec2 vTexCoord; - varying vec2 vLeftTexCoord; - varying vec2 vRightTexCoord; - - varying vec2 vTopTexCoord; - varying vec2 vTopLeftTexCoord; - varying vec2 vTopRightTexCoord; - - varying vec2 vBottomTexCoord; - varying vec2 vBottomLeftTexCoord; - varying vec2 vBottomRightTexCoord; - - void main() - { - float bottomLeftIntensity = texture2D(colorMap, vBottomLeftTexCoord).r; - float topRightIntensity = texture2D(colorMap, vTopRightTexCoord).r; - float topLeftIntensity = texture2D(colorMap, vTopLeftTexCoord).r; - float bottomRightIntensity = texture2D(colorMap, vBottomRightTexCoord).r; - float leftIntensity = texture2D(colorMap, vLeftTexCoord).r; - float rightIntensity = texture2D(colorMap, vRightTexCoord).r; - float bottomIntensity = texture2D(colorMap, vBottomTexCoord).r; - float topIntensity = texture2D(colorMap, vTopTexCoord).r; - float centerIntensity = texture2D(colorMap, vTexCoord).r; - - float pixelIntensitySum = bottomLeftIntensity + topRightIntensity + topLeftIntensity + bottomRightIntensity + leftIntensity + rightIntensity + bottomIntensity + topIntensity + centerIntensity; - float sumTest = step(1.5, pixelIntensitySum); - float pixelTest = step(0.01, centerIntensity); - - gl_FragColor = vec4(vec3(sumTest * pixelTest), 1.0); - } - ); - - -WeakPixelInclusionFilter* WeakPixelInclusionFilter::create() { - WeakPixelInclusionFilter* ret = new (std::nothrow) WeakPixelInclusionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool WeakPixelInclusionFilter::init() { - if (initWithFragmentShaderString(kWeakPixelInclusionFragmentShaderString)) { - return true; - } - return false; -} - - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WeakPixelInclusionFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WeakPixelInclusionFilter.hpp deleted file mode 100755 index 0777abf..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WeakPixelInclusionFilter.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WeakPixelInclusionFilter_hpp -#define WeakPixelInclusionFilter_hpp - -#include "../macros.h" -#include "NearbySampling3x3Filter.hpp" - -NS_GI_BEGIN - -class WeakPixelInclusionFilter : public NearbySampling3x3Filter { -public: - static WeakPixelInclusionFilter* create(); - bool init(); - - -protected: - - WeakPixelInclusionFilter() {}; -}; - -NS_GI_END - -#endif /* WeakPixelInclusionFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WhiteBalanceFilter.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WhiteBalanceFilter.cpp deleted file mode 100755 index a2358c3..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WhiteBalanceFilter.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "WhiteBalanceFilter.hpp" - -USING_NS_GI - -REGISTER_FILTER_CLASS(WhiteBalanceFilter) - -const std::string kWhiteBalanceFragmentShaderString = SHADER_STRING -( - uniform sampler2D colorMap; - uniform lowp float temperature; - uniform lowp float tint; - varying highp vec2 vTexCoord; - const lowp vec3 warmFilter = vec3(0.93, 0.54, 0.0); - const mediump mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.212, -0.523, 0.311); - const mediump mat3 YIQtoRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.105, 1.702); - - void main() - { - lowp vec4 color = texture2D(colorMap, vTexCoord); - mediump vec3 yiq = RGBtoYIQ * color.rgb; //adjusting tint - yiq.b = clamp(yiq.b + tint * 0.5226 * 0.1, -0.5226, 0.5226); - lowp vec3 rgb = YIQtoRGB * yiq; - lowp vec3 processed = vec3( - (rgb.r < 0.5 ? (2.0 * rgb.r * warmFilter.r) : (1.0 - 2.0 * (1.0 - rgb.r) * (1.0 - warmFilter.r))), //adjusting temperature - (rgb.g < 0.5 ? (2.0 * rgb.g * warmFilter.g) : (1.0 - 2.0 * (1.0 - rgb.g) * (1.0 - warmFilter.g))), - (rgb.b < 0.5 ? (2.0 * rgb.b * warmFilter.b) : (1.0 - 2.0 * (1.0 - rgb.b) * (1.0 - warmFilter.b)))); - - gl_FragColor = vec4(mix(rgb, processed, temperature), color.a); - - } -); - - -WhiteBalanceFilter* WhiteBalanceFilter::create() { - WhiteBalanceFilter* ret = new (std::nothrow) WhiteBalanceFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - -bool WhiteBalanceFilter::init() { - if (!initWithFragmentShaderString(kWhiteBalanceFragmentShaderString)) return false; - - setTemperature(5000.0); - registerProperty("temperature", 5000.0, "Adjustment of color temperature (in degrees Kelvin) in terms of what an image was effectively shot in. This means higher Kelvin values will warm the image, while lower values will cool it.", [this](float& temperature){ - setTemperature(temperature); - }); - - setTint(0.0); - registerProperty("tint", _tint, "adjust tint to compensate", [this](float& tint){ - setTint(tint); - }); - - return true; -} - -void WhiteBalanceFilter::setTemperature(float temperature) { - _temperature = temperature < 5000 ? 0.0004 * (temperature - 5000.0) : 0.00006 * (temperature - 5000.0); -} - -void WhiteBalanceFilter::setTint(float tint) { - _tint = tint / 100.0; -} - -bool WhiteBalanceFilter::proceed(bool bUpdateTargets/* = true*/) { - _filterProgram->setUniformValue("temperature", _temperature); - _filterProgram->setUniformValue("tint", _tint); - return Filter::proceed(bUpdateTargets); -} - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WhiteBalanceFilter.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WhiteBalanceFilter.hpp deleted file mode 100755 index a0d70ad..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/WhiteBalanceFilter.hpp +++ /dev/null @@ -1,45 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef WhiteBalanceFilter_hpp -#define WhiteBalanceFilter_hpp - -#include "../macros.h" -#include "Filter.hpp" - -NS_GI_BEGIN - -class WhiteBalanceFilter : public Filter { -public: - static WhiteBalanceFilter* create(); - bool init(); - virtual bool proceed(bool bUpdateTargets = true) override; - - void setTemperature(float temperature); - void setTint(float tint); - -protected: - WhiteBalanceFilter() {}; - - float _temperature; - float _tint; -}; - -NS_GI_END - -#endif /* WhiteBalanceFilter_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/macros.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/macros.h deleted file mode 100755 index 5eef55a..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/macros.h +++ /dev/null @@ -1,71 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef macros_h -#define macros_h - -#define PLATFORM_UNKNOW 0 -#define PLATFORM_ANDROID 1 -#define PLATFORM_IOS 2 - -#define PLATFORM PLATFORM_UNKNOW - -#if defined(__ANDROID__) || defined(ANDROID) - #undef PLATFORM - #define PLATFORM PLATFORM_ANDROID -#elif defined(__APPLE__) - #undef PLATFORM - #define PLATFORM PLATFORM_IOS -#endif - -#define NS_GI_BEGIN namespace GPUImage { -#define NS_GI_END } -#define USING_NS_GI using namespace GPUImage; - - -#define STRINGIZE(x) #x -#define SHADER_STRING(text) STRINGIZE(text) - -#define PI 3.14159265358979323846264338327950288 - -#define ENABLE_GL_CHECK false - -#if ENABLE_GL_CHECK - #define CHECK_GL(glFunc) \ - glFunc; \ - { \ - int e = glGetError(); \ - if (e != 0) \ - { \ - std::string errorString = ""; \ - switch(e) \ - { \ - case GL_INVALID_ENUM: errorString = "GL_INVALID_ENUM"; break; \ - case GL_INVALID_VALUE: errorString = "GL_INVALID_VALUE"; break; \ - case GL_INVALID_OPERATION: errorString = "GL_INVALID_OPERATION"; break; \ - case GL_OUT_OF_MEMORY: errorString = "GL_OUT_OF_MEMORY"; break; \ - default: break; \ - } \ - Log("ERROR", "GL ERROR 0x%04X %s in %s at line %i\n", e, errorString.c_str(), __PRETTY_FUNCTION__, __LINE__); \ - } \ - } -#else - #define CHECK_GL(glFunc) glFunc; -#endif - -#endif /* macros_h */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/math.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/math.cpp deleted file mode 100755 index 8096794..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/math.cpp +++ /dev/null @@ -1,818 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "math.hpp" -#include -#include - -NS_GI_BEGIN - -Vector2::Vector2() -: x(0.0f), y(0.0f) -{ -} - -Vector2::Vector2(float xx, float yy) -: x(xx), y(yy) -{ -} - -Vector2::Vector2(const float* array) -{ - set(array); -} - -Vector2::Vector2(const Vector2& p1, const Vector2& p2) -{ - set(p1, p2); -} - -Vector2::Vector2(const Vector2& copy) -{ - set(copy); -} - -Vector2::~Vector2() -{ -} - -bool Vector2::isZero() const -{ - return x == 0.0f && y == 0.0f; -} - -bool Vector2::isOne() const -{ - return x == 1.0f && y == 1.0f; -} - -void Vector2::add(const Vector2& v) -{ - x += v.x; - y += v.y; -} - -float Vector2::distanceSquared(const Vector2& v) const -{ - float dx = v.x - x; - float dy = v.y - y; - return (dx * dx + dy * dy); -} - -float Vector2::dot(const Vector2& v) const -{ - return (x * v.x + y * v.y); -} - -float Vector2::lengthSquared() const -{ - return (x * x + y * y); -} - -void Vector2::negate() -{ - x = -x; - y = -y; -} - -void Vector2::scale(float scalar) -{ - x *= scalar; - y *= scalar; -} - -void Vector2::scale(const Vector2& scale) -{ - x *= scale.x; - y *= scale.y; -} - -void Vector2::set(float xx, float yy) -{ - this->x = xx; - this->y = yy; -} - -void Vector2::set(const Vector2& v) -{ - this->x = v.x; - this->y = v.y; -} - -void Vector2::set(const Vector2& p1, const Vector2& p2) -{ - x = p2.x - p1.x; - y = p2.y - p1.y; -} - -void Vector2::setZero() -{ - x = y = 0.0f; -} - -void Vector2::subtract(const Vector2& v) -{ - x -= v.x; - y -= v.y; -} - -void Vector2::smooth(const Vector2& target, float elapsedTime, float responseTime) -{ - if (elapsedTime > 0) - { - *this += (target - *this) * (elapsedTime / (elapsedTime + responseTime)); - } -} - -const Vector2 Vector2::operator+(const Vector2& v) const -{ - Vector2 result(*this); - result.add(v); - return result; -} - -Vector2& Vector2::operator+=(const Vector2& v) -{ - add(v); - return *this; -} - -const Vector2 Vector2::operator-(const Vector2& v) const -{ - Vector2 result(*this); - result.subtract(v); - return result; -} - -Vector2& Vector2::operator-=(const Vector2& v) -{ - subtract(v); - return *this; -} - -const Vector2 Vector2::operator-() const -{ - Vector2 result(*this); - result.negate(); - return result; -} - -const Vector2 Vector2::operator*(float s) const -{ - Vector2 result(*this); - result.scale(s); - return result; -} - -Vector2& Vector2::operator*=(float s) -{ - scale(s); - return *this; -} - -const Vector2 Vector2::operator/(const float s) const -{ - return Vector2(this->x / s, this->y / s); -} - -bool Vector2::operator<(const Vector2& v) const -{ - if (x == v.x) - { - return y < v.y; - } - return x < v.x; -} - -bool Vector2::operator>(const Vector2& v) const -{ - if (x == v.x) - { - return y > v.y; - } - return x > v.x; -} - -bool Vector2::operator==(const Vector2& v) const -{ - return x==v.x && y==v.y; -} - -bool Vector2::operator!=(const Vector2& v) const -{ - return x!=v.x || y!=v.y; -} - -const Vector2 operator*(float x, const Vector2& v) -{ - Vector2 result(v); - result.scale(x); - return result; -} - - -const Matrix4 Matrix4::IDENTITY = Matrix4( - 1.0f, 0.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, 0.0f, - 0.0f, 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 0.0f, 1.0f); - -Matrix4::Matrix4() { - *this = IDENTITY; -} - -Matrix4::Matrix4(const float* mat) { - set(mat); -} - -Matrix4::Matrix4(float m11, float m12, float m13, float m14, float m21, float m22, float m23,float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { - set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); -} - -Matrix4::Matrix4(const Matrix4& copy) { - memcpy(m, copy.m, sizeof(float) * 16); -} - -Matrix4::~Matrix4() { - -} - -void Matrix4::set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { - m[0] = m11; - m[1] = m21; - m[2] = m31; - m[3] = m41; - m[4] = m12; - m[5] = m22; - m[6] = m32; - m[7] = m42; - m[8] = m13; - m[9] = m23; - m[10] = m33; - m[11] = m43; - m[12] = m14; - m[13] = m24; - m[14] = m34; - m[15] = m44; -} - -void Matrix4::set(const float* mat) { - assert(mat); - memcpy(this->m, mat, sizeof(float) * 16); -} - -void Matrix4::set(const Matrix4& mat) { - memcpy(this->m, mat.m, sizeof(float) * 16); -} - -void Matrix4::setIdentity() { - memcpy(m, &IDENTITY, sizeof(float) * 16); -} - -void Matrix4::negate() -{ - m[0] = -m[0]; - m[1] = -m[1]; - m[2] = -m[2]; - m[3] = -m[3]; - m[4] = -m[4]; - m[5] = -m[5]; - m[6] = -m[6]; - m[7] = -m[7]; - m[8] = -m[8]; - m[9] = -m[9]; - m[10] = -m[10]; - m[11] = -m[11]; - m[12] = -m[12]; - m[13] = -m[13]; - m[14] = -m[14]; - m[15] = -m[15]; -} - -Matrix4 Matrix4::getNegated() const -{ - Matrix4 mat(*this); - mat.negate(); - return mat; -} - -void Matrix4::transpose() { - float tmp; - tmp = m[1]; m[1] = m[4]; m[4] = tmp; - tmp = m[2]; m[2] = m[8]; m[8] = tmp; - tmp = m[6]; m[6] = m[9]; m[9] = tmp; - tmp = m[3]; m[3] = m[12]; m[12] = tmp; - tmp = m[7]; m[7] = m[13]; m[13] = tmp; - tmp = m[11]; m[11] = m[14]; m[14] = tmp; -} - -Matrix4 Matrix4::getTransposed() const { - Matrix4 mat(*this); - mat.transpose(); - return mat; -} - -void Matrix4::add(float scalar) -{ - add(scalar, this); -} - -void Matrix4::add(float scalar, Matrix4* dst) const -{ - assert(dst); - dst->m[0] = this->m[0] + scalar; - dst->m[1] = this->m[1] + scalar; - dst->m[2] = this->m[2] + scalar; - dst->m[3] = this->m[3] + scalar; - dst->m[4] = this->m[4] + scalar; - dst->m[5] = this->m[5] + scalar; - dst->m[6] = this->m[6] + scalar; - dst->m[7] = this->m[7] + scalar; - dst->m[8] = this->m[8] + scalar; - dst->m[9] = this->m[9] + scalar; - dst->m[10] = this->m[10] + scalar; - dst->m[11] = this->m[11] + scalar; - dst->m[12] = this->m[12] + scalar; - dst->m[13] = this->m[13] + scalar; - dst->m[14] = this->m[14] + scalar; - dst->m[15] = this->m[15] + scalar; -} - -void Matrix4::add(const Matrix4& mat) -{ - add(*this, mat, this); -} - -void Matrix4::add(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] + m2.m[0]; - dst->m[1] = m1.m[1] + m2.m[1]; - dst->m[2] = m1.m[2] + m2.m[2]; - dst->m[3] = m1.m[3] + m2.m[3]; - dst->m[4] = m1.m[4] + m2.m[4]; - dst->m[5] = m1.m[5] + m2.m[5]; - dst->m[6] = m1.m[6] + m2.m[6]; - dst->m[7] = m1.m[7] + m2.m[7]; - dst->m[8] = m1.m[8] + m2.m[8]; - dst->m[9] = m1.m[9] + m2.m[9]; - dst->m[10] = m1.m[10] + m2.m[10]; - dst->m[11] = m1.m[11] + m2.m[11]; - dst->m[12] = m1.m[12] + m2.m[12]; - dst->m[13] = m1.m[13] + m2.m[13]; - dst->m[14] = m1.m[14] + m2.m[14]; - dst->m[15] = m1.m[15] + m2.m[15]; -} - -void Matrix4::subtract(const Matrix4& mat) -{ - subtract(*this, mat, this); -} - -void Matrix4::subtract(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] - m2.m[0]; - dst->m[1] = m1.m[1] - m2.m[1]; - dst->m[2] = m1.m[2] - m2.m[2]; - dst->m[3] = m1.m[3] - m2.m[3]; - dst->m[4] = m1.m[4] - m2.m[4]; - dst->m[5] = m1.m[5] - m2.m[5]; - dst->m[6] = m1.m[6] - m2.m[6]; - dst->m[7] = m1.m[7] - m2.m[7]; - dst->m[8] = m1.m[8] - m2.m[8]; - dst->m[9] = m1.m[9] - m2.m[9]; - dst->m[10] = m1.m[10] - m2.m[10]; - dst->m[11] = m1.m[11] - m2.m[11]; - dst->m[12] = m1.m[12] - m2.m[12]; - dst->m[13] = m1.m[13] - m2.m[13]; - dst->m[14] = m1.m[14] - m2.m[14]; - dst->m[15] = m1.m[15] - m2.m[15]; -} - -void Matrix4::multiply(float scalar) -{ - multiply(scalar, this); -} - -void Matrix4::multiply(float scalar, Matrix4* dst) const -{ - multiply(*this, scalar, dst); -} - -void Matrix4::multiply(const Matrix4& mat, float scalar, Matrix4* dst) -{ - assert(dst); - dst->m[0] = mat.m[0] * scalar; - dst->m[1] = mat.m[1] * scalar; - dst->m[2] = mat.m[2] * scalar; - dst->m[3] = mat.m[3] * scalar; - dst->m[4] = mat.m[4] * scalar; - dst->m[5] = mat.m[5] * scalar; - dst->m[6] = mat.m[6] * scalar; - dst->m[7] = mat.m[7] * scalar; - dst->m[8] = mat.m[8] * scalar; - dst->m[9] = mat.m[9] * scalar; - dst->m[10] = mat.m[10] * scalar; - dst->m[11] = mat.m[11] * scalar; - dst->m[12] = mat.m[12] * scalar; - dst->m[13] = mat.m[13] * scalar; - dst->m[14] = mat.m[14] * scalar; - dst->m[15] = mat.m[15] * scalar; -} - -void Matrix4::multiply(const Matrix4& mat) -{ - multiply(*this, mat, this); -} - -void Matrix4::multiply(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] * m2.m[0]; - dst->m[1] = m1.m[1] * m2.m[1]; - dst->m[2] = m1.m[2] * m2.m[2]; - dst->m[3] = m1.m[3] * m2.m[3]; - dst->m[4] = m1.m[4] * m2.m[4]; - dst->m[5] = m1.m[5] * m2.m[5]; - dst->m[6] = m1.m[6] * m2.m[6]; - dst->m[7] = m1.m[7] * m2.m[7]; - dst->m[8] = m1.m[8] * m2.m[8]; - dst->m[9] = m1.m[9] * m2.m[9]; - dst->m[10] = m1.m[10] * m2.m[10]; - dst->m[11] = m1.m[11] * m2.m[11]; - dst->m[12] = m1.m[12] * m2.m[12]; - dst->m[13] = m1.m[13] * m2.m[13]; - dst->m[14] = m1.m[14] * m2.m[14]; - dst->m[15] = m1.m[15] * m2.m[15]; -} - -const Matrix4 Matrix4::operator+(const Matrix4& mat) const -{ - Matrix4 result(*this); - result.add(mat); - return result; -} - -Matrix4& Matrix4::operator+=(const Matrix4& mat) -{ - add(mat); - return *this; -} - -const Matrix4 Matrix4::operator-(const Matrix4& mat) const -{ - Matrix4 result(*this); - result.subtract(mat); - return result; -} - -Matrix4& Matrix4::operator-=(const Matrix4& mat) -{ - subtract(mat); - return *this; -} - -const Matrix4 Matrix4::operator-() const -{ - Matrix4 mat(*this); - mat.negate(); - return mat; -} - -const Matrix4 Matrix4::operator*(const Matrix4& mat) const -{ - Matrix4 result(*this); - result.multiply(mat); - return result; -} - -Matrix4& Matrix4::operator*=(const Matrix4& mat) -{ - multiply(mat); - return *this; -} - -const Matrix4 Matrix4::operator+(float scalar) const -{ - Matrix4 result(*this); - result.add(scalar); - return result; -} - -Matrix4& Matrix4::operator+=(float scalar) -{ - add(scalar); - return *this; -} - -const Matrix4 Matrix4::operator-(float scalar) const -{ - Matrix4 result(*this); - result.add(-scalar); - return result; -} - -Matrix4& Matrix4::operator-=(float scalar) -{ - add(-scalar); - return *this; -} - -const Matrix4 Matrix4::operator*(float scalar) const -{ - Matrix4 result(*this); - result.multiply(scalar); - return result; -} - -Matrix4& Matrix4::operator*=(float scalar) -{ - multiply(scalar); - return *this; -} - - -const Matrix3 Matrix3::IDENTITY = Matrix3( - 1.0f, 0.0f, 0.0f, - 0.0f, 1.0f, 0.0f, - 0.0f, 0.0f, 1.0f); -Matrix3::Matrix3() { - *this = IDENTITY; -} - -Matrix3::Matrix3(const float* mat) { - set(mat); -} - -Matrix3::Matrix3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { - set(m11, m12, m13, m21, m22, m23, m31, m32, m33); -} - -Matrix3::Matrix3(const Matrix3& copy) { - memcpy(m, copy.m, sizeof(float) * 9); -} - -Matrix3::~Matrix3() { - -} - -void Matrix3::set(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { - m[0] = m11; - m[1] = m21; - m[2] = m31; - m[3] = m12; - m[4] = m22; - m[5] = m32; - m[6] = m13; - m[7] = m23; - m[8] = m33; -} - -void Matrix3::set(const float* mat) { - assert(mat); - memcpy(this->m, mat, sizeof(float) * 9); -} - -void Matrix3::set(const Matrix3& mat) { - memcpy(this->m, mat.m, sizeof(float) * 9); -} - -void Matrix3::setIdentity() { - memcpy(m, &IDENTITY, sizeof(float) * 9); -} - -void Matrix3::negate() -{ - m[0] = -m[0]; - m[1] = -m[1]; - m[2] = -m[2]; - m[3] = -m[3]; - m[4] = -m[4]; - m[5] = -m[5]; - m[6] = -m[6]; - m[7] = -m[7]; - m[8] = -m[8]; -} - -Matrix3 Matrix3::getNegated() const -{ - Matrix3 mat(*this); - mat.negate(); - return mat; -} - -void Matrix3::transpose() { - float tmp; - tmp = m[1]; m[1] = m[3]; m[3] = tmp; - tmp = m[2]; m[2] = m[6]; m[6] = tmp; - tmp = m[5]; m[5] = m[7]; m[7] = tmp; -} - -Matrix3 Matrix3::getTransposed() const { - Matrix3 mat(*this); - mat.transpose(); - return mat; -} - -void Matrix3::add(float scalar) -{ - add(scalar, this); -} - -void Matrix3::add(float scalar, Matrix3* dst) const -{ - assert(dst); - dst->m[0] = this->m[0] + scalar; - dst->m[1] = this->m[1] + scalar; - dst->m[2] = this->m[2] + scalar; - dst->m[3] = this->m[3] + scalar; - dst->m[4] = this->m[4] + scalar; - dst->m[5] = this->m[5] + scalar; - dst->m[6] = this->m[6] + scalar; - dst->m[7] = this->m[7] + scalar; - dst->m[8] = this->m[8] + scalar; -} - -void Matrix3::add(const Matrix3& mat) -{ - add(*this, mat, this); -} - -void Matrix3::add(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] + m2.m[0]; - dst->m[1] = m1.m[1] + m2.m[1]; - dst->m[2] = m1.m[2] + m2.m[2]; - dst->m[3] = m1.m[3] + m2.m[3]; - dst->m[4] = m1.m[4] + m2.m[4]; - dst->m[5] = m1.m[5] + m2.m[5]; - dst->m[6] = m1.m[6] + m2.m[6]; - dst->m[7] = m1.m[7] + m2.m[7]; - dst->m[8] = m1.m[8] + m2.m[8]; -} - -void Matrix3::subtract(const Matrix3& mat) -{ - subtract(*this, mat, this); -} - -void Matrix3::subtract(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] - m2.m[0]; - dst->m[1] = m1.m[1] - m2.m[1]; - dst->m[2] = m1.m[2] - m2.m[2]; - dst->m[3] = m1.m[3] - m2.m[3]; - dst->m[4] = m1.m[4] - m2.m[4]; - dst->m[5] = m1.m[5] - m2.m[5]; - dst->m[6] = m1.m[6] - m2.m[6]; - dst->m[7] = m1.m[7] - m2.m[7]; - dst->m[8] = m1.m[8] - m2.m[8]; -} - -void Matrix3::multiply(float scalar) -{ - multiply(scalar, this); -} - -void Matrix3::multiply(float scalar, Matrix3* dst) const -{ - multiply(*this, scalar, dst); -} - -void Matrix3::multiply(const Matrix3& mat, float scalar, Matrix3* dst) -{ - assert(dst); - dst->m[0] = mat.m[0] * scalar; - dst->m[1] = mat.m[1] * scalar; - dst->m[2] = mat.m[2] * scalar; - dst->m[3] = mat.m[3] * scalar; - dst->m[4] = mat.m[4] * scalar; - dst->m[5] = mat.m[5] * scalar; - dst->m[6] = mat.m[6] * scalar; - dst->m[7] = mat.m[7] * scalar; - dst->m[8] = mat.m[8] * scalar; -} - -void Matrix3::multiply(const Matrix3& mat) -{ - multiply(*this, mat, this); -} - -void Matrix3::multiply(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) -{ - assert(dst); - dst->m[0] = m1.m[0] * m2.m[0]; - dst->m[1] = m1.m[1] * m2.m[1]; - dst->m[2] = m1.m[2] * m2.m[2]; - dst->m[3] = m1.m[3] * m2.m[3]; - dst->m[4] = m1.m[4] * m2.m[4]; - dst->m[5] = m1.m[5] * m2.m[5]; - dst->m[6] = m1.m[6] * m2.m[6]; - dst->m[7] = m1.m[7] * m2.m[7]; - dst->m[8] = m1.m[8] * m2.m[8]; -} - -const Matrix3 Matrix3::operator+(const Matrix3& mat) const -{ - Matrix3 result(*this); - result.add(mat); - return result; -} - -Matrix3& Matrix3::operator+=(const Matrix3& mat) -{ - add(mat); - return *this; -} - -const Matrix3 Matrix3::operator-(const Matrix3& mat) const -{ - Matrix3 result(*this); - result.subtract(mat); - return result; -} - -Matrix3& Matrix3::operator-=(const Matrix3& mat) -{ - subtract(mat); - return *this; -} - -const Matrix3 Matrix3::operator-() const -{ - Matrix3 mat(*this); - mat.negate(); - return mat; -} - -const Matrix3 Matrix3::operator*(const Matrix3& mat) const -{ - Matrix3 result(*this); - result.multiply(mat); - return result; -} - -Matrix3& Matrix3::operator*=(const Matrix3& mat) -{ - multiply(mat); - return *this; -} - -const Matrix3 Matrix3::operator+(float scalar) const -{ - Matrix3 result(*this); - result.add(scalar); - return result; -} - -Matrix3& Matrix3::operator+=(float scalar) -{ - add(scalar); - return *this; -} - -const Matrix3 Matrix3::operator-(float scalar) const -{ - Matrix3 result(*this); - result.add(-scalar); - return result; -} - -Matrix3& Matrix3::operator-=(float scalar) -{ - add(-scalar); - return *this; -} - -const Matrix3 Matrix3::operator*(float scalar) const -{ - Matrix3 result(*this); - result.multiply(scalar); - return result; -} - -Matrix3& Matrix3::operator*=(float scalar) -{ - multiply(scalar); - return *this; -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/math.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/math.hpp deleted file mode 100755 index 5c2166b..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/math.hpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef math_hpp -#define math_hpp - -#include "macros.h" - -NS_GI_BEGIN - -class Vector2 -{ -public: - - float x; - float y; - - Vector2(); - Vector2(float xx, float yy); - Vector2(const float* array); - Vector2(const Vector2& p1, const Vector2& p2); - Vector2(const Vector2& copy); - ~Vector2(); - - bool isZero() const; - bool isOne() const; - static float angle(const Vector2& v1, const Vector2& v2); - void add(const Vector2& v); - static void add(const Vector2& v1, const Vector2& v2, Vector2* dst); - void clamp(const Vector2& min, const Vector2& max); - static void clamp(const Vector2& v, const Vector2& min, const Vector2& max, Vector2* dst); - float distance(const Vector2& v) const; - float distanceSquared(const Vector2& v) const; - float dot(const Vector2& v) const; - static float dot(const Vector2& v1, const Vector2& v2); - float length() const; - float lengthSquared() const; - void negate(); - void normalize(); - Vector2 getNormalized() const; - void scale(float scalar); - void scale(const Vector2& scale); - void rotate(const Vector2& point, float angle); - void set(float xx, float yy); - void set(const Vector2& v); - void set(const Vector2& p1, const Vector2& p2); - void setZero(); - void subtract(const Vector2& v); - static void subtract(const Vector2& v1, const Vector2& v2, Vector2* dst); - void smooth(const Vector2& target, float elapsedTime, float responseTime); - const Vector2 operator+(const Vector2& v) const; - Vector2& operator+=(const Vector2& v); - const Vector2 operator-(const Vector2& v) const; - Vector2& operator-=(const Vector2& v); - const Vector2 operator-() const; - const Vector2 operator*(float s) const; - Vector2& operator*=(float s); - const Vector2 operator/(float s) const; - bool operator<(const Vector2& v) const; - bool operator>(const Vector2& v) const; - bool operator==(const Vector2& v) const; - bool operator!=(const Vector2& v) const; -}; - -class Vector3 { - -}; - -class Matrix4 { -public: - float m[16]; - Matrix4(); - Matrix4(const float* mat); - Matrix4(float m11, float m12, float m13, float m14, float m21, float m22, float m23,float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44); - Matrix4(const Matrix4& copy); - ~Matrix4(); - - void set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44); - void set(const float* mat); - void set(const Matrix4& mat); - void setIdentity(); - - void negate(); - Matrix4 getNegated() const; - - void transpose(); - Matrix4 getTransposed() const; - - void add(float scalar); - void add(float scalar, Matrix4* dst) const; - void add(const Matrix4& mat); - static void add(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); - - void subtract(const Matrix4& mat); - static void subtract(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); - - void multiply(float scalar); - void multiply(float scalar, Matrix4* dst) const; - static void multiply(const Matrix4& mat, float scalar, Matrix4* dst); - void multiply(const Matrix4& mat); - static void multiply(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); - - const Matrix4 operator+(const Matrix4& mat) const; - Matrix4& operator+=(const Matrix4& mat); - const Matrix4 operator-(const Matrix4& mat) const; - Matrix4& operator-=(const Matrix4& mat); - const Matrix4 operator-() const; - const Matrix4 operator*(const Matrix4& mat) const; - Matrix4& operator*=(const Matrix4& mat); - - const Matrix4 operator+(float scalar) const; - Matrix4& operator+=(float scalar); - const Matrix4 operator-(float scalar) const; - Matrix4& operator-=(float scalar); - const Matrix4 operator*(float scalar) const; - Matrix4& operator*=(float scalar); - - static const Matrix4 IDENTITY; -}; - -class Matrix3 { -public: - float m[9]; - Matrix3(); - Matrix3(const float* mat); - Matrix3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33); - Matrix3(const Matrix3& copy); - ~Matrix3(); - - void set(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33); - void set(const float* mat); - void set(const Matrix3& mat); - void setIdentity(); - - void negate(); - Matrix3 getNegated() const; - - void transpose(); - Matrix3 getTransposed() const; - - void add(float scalar); - void add(float scalar, Matrix3* dst) const; - void add(const Matrix3& mat); - static void add(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); - - void subtract(const Matrix3& mat); - static void subtract(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); - - void multiply(float scalar); - void multiply(float scalar, Matrix3* dst) const; - static void multiply(const Matrix3& mat, float scalar, Matrix3* dst); - void multiply(const Matrix3& mat); - static void multiply(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); - - const Matrix3 operator+(const Matrix3& mat) const; - Matrix3& operator+=(const Matrix3& mat); - const Matrix3 operator-(const Matrix3& mat) const; - Matrix3& operator-=(const Matrix3& mat); - const Matrix3 operator-() const; - const Matrix3 operator*(const Matrix3& mat) const; - Matrix3& operator*=(const Matrix3& mat); - - const Matrix3 operator+(float scalar) const; - Matrix3& operator+=(float scalar); - const Matrix3 operator-(float scalar) const; - Matrix3& operator-=(float scalar); - const Matrix3 operator*(float scalar) const; - Matrix3& operator*=(float scalar); - - static const Matrix3 IDENTITY; -}; - -NS_GI_END - -#endif /* math_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/Source.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/Source.hpp deleted file mode 100755 index 59654ad..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/Source.hpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Source_hpp -#define Source_hpp - -#include "../macros.h" -#include "../target/Target.hpp" -#include -#include -#include "../target/Target.hpp" - -#if PLATFORM == PLATFORM_IOS -#import "GPUImageTarget.h" -#endif - -NS_GI_BEGIN - -class Filter; -class Source : public virtual Ref { -public: - Source(); - virtual ~Source(); - virtual Source* addTarget(Target* target); - virtual Source* addTarget(Target* target, int texIdx); -#if PLATFORM == PLATFORM_IOS - virtual Source* addTarget(id target); -#endif - virtual void removeTarget(Target* target); - virtual void removeAllTargets(); - virtual bool hasTarget(const Target* target) const; - virtual std::map& getTargets() { return _targets; }; - - virtual void setFramebuffer(Framebuffer* fb, RotationMode outputRotation = RotationMode::NoRotation); - virtual Framebuffer* getFramebuffer() const; - virtual void releaseFramebuffer(bool returnToCache = true); - - void setFramebufferScale(float framebufferScale) { _framebufferScale = framebufferScale; } - int getRotatedFramebufferWidth() const; - int getRotatedFramebufferHeight() const; - - virtual bool proceed(bool bUpdateTargets = true); - virtual void updateTargets(float frameTime); - - virtual unsigned char* captureAProcessedFrameData(Filter* upToFilter, int width = 0, int height = 0); - -protected: - Framebuffer* _framebuffer; - RotationMode _outputRotation; - std::map _targets; - float _framebufferScale; -}; - - -NS_GI_END - -#endif /* Source_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceCamera.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceCamera.h deleted file mode 100755 index 856f9a3..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceCamera.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GPUIMAGE_X_SOURCECAMERA_H -#define GPUIMAGE_X_SOURCECAMERA_H - - -#include "Source.hpp" - -#if PLATFORM == PLATFORM_IOS -#import - -@class VideoDataOutputSampleBufferDelegate; -#endif - -NS_GI_BEGIN - -class SourceCamera : public Source{ -public: - SourceCamera(); - virtual ~SourceCamera(); - - static SourceCamera* create(); - - void setFrameData(int width, int height, const void* pixels, RotationMode outputRotation = RotationMode::NoRotation); -#if PLATFORM == PLATFORM_IOS - bool init(); - bool init(NSString* sessionPreset, AVCaptureDevicePosition cameraPosition); - static bool isCameraExist(AVCaptureDevicePosition cameraPosition); - void start(); - void stop(); - void pause(); - void resume(); - bool isRunning(); - bool flip(); - - AVCaptureDevicePosition getCameraPosition(); - void setOutputImageOrientation(UIInterfaceOrientation orientation); - void setHorizontallyMirrorFrontFacingCamera(bool newValue); - void setHorizontallyMirrorRearFacingCamera(bool newValue); -#endif - -private: -#if PLATFORM == PLATFORM_IOS - VideoDataOutputSampleBufferDelegate* _videoDataOutputSampleBufferDelegate; - AVCaptureSession* _captureSession; - BOOL _capturePaused; - GPUImage::RotationMode _outputRotation; - //GPUImage::RotationMode internalRotation; - AVCaptureDeviceInput* _captureDeviceInput; - AVCaptureVideoDataOutput* _captureVideoDataOutput; - /// This determines the rotation applied to the output image, based on the source material - UIInterfaceOrientation _outputImageOrientation; - /// These properties determine whether or not the two camera orientations should be mirrored. By default, both are NO. - bool _horizontallyMirrorFrontFacingCamera, _horizontallyMirrorRearFacingCamera; - void _updateOutputRotation(); -#endif -}; - -NS_GI_END - -#endif //GPUIMAGE_X_SOURCECAMERA_H - -#if PLATFORM == PLATFORM_IOS -@interface VideoDataOutputSampleBufferDelegate : NSObject -@property (nonatomic) GPUImage::SourceCamera* sourceCamera; -@property (nonatomic) GPUImage::RotationMode rotation; -@end -#endif diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceImage.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceImage.cpp deleted file mode 100755 index dd2fa86..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceImage.cpp +++ /dev/null @@ -1,167 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "SourceImage.h" -#include "../Context.hpp" -#include "../util.h" - -USING_NS_GI - -SourceImage* SourceImage::create(int width, int height, const void* pixels) { - SourceImage* sourceImage = new SourceImage(); - sourceImage->setImage(width, height, pixels); - return sourceImage; -} - -SourceImage* SourceImage::setImage(int width, int height, const void* pixels) { - this->setFramebuffer(0); - Framebuffer* framebuffer = Context::getInstance()->getFramebufferCache()->fetchFramebuffer(width, height, true); - this->setFramebuffer(framebuffer); - framebuffer->release(); - - CHECK_GL(glBindTexture(GL_TEXTURE_2D, this->getFramebuffer()->getTexture())); - CHECK_GL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pixels)); - CHECK_GL(glBindTexture(GL_TEXTURE_2D, 0)); - return this; -} - -#if PLATFORM == PLATFORM_IOS -SourceImage* SourceImage::create(NSURL* imageUrl) { - SourceImage* sourceImage = new SourceImage(); - sourceImage->setImage(imageUrl); - return sourceImage; -} - -SourceImage* SourceImage::setImage(NSURL* imageUrl) { - NSData *imageData = [[NSData alloc] initWithContentsOfURL:imageUrl]; - setImage(imageData); - return this; -} - -SourceImage* SourceImage::create(NSData* imageData) { - SourceImage* sourceImage = new SourceImage(); - sourceImage->setImage(imageData); - return sourceImage; -} - -SourceImage* SourceImage::setImage(NSData* imageData) { - UIImage* inputImage = [[UIImage alloc] initWithData:imageData]; - setImage(inputImage); - return this; -} - -SourceImage* SourceImage::create(UIImage* image) { - SourceImage* sourceImage = new SourceImage(); - sourceImage->setImage(image); - return sourceImage; -} - -SourceImage* SourceImage::setImage(UIImage* image) { - UIImage* img = _adjustImageOrientation(image); - setImage([img CGImage]); - return this; -} - -SourceImage* SourceImage::create(CGImageRef image) { - SourceImage* sourceImage = new SourceImage(); - sourceImage->setImage(image); - return sourceImage; -} - -SourceImage* SourceImage::setImage(CGImageRef image) { - GLubyte *imageData = NULL; - CFDataRef dataFromImageDataProvider = CGDataProviderCopyData(CGImageGetDataProvider(image)); - imageData = (GLubyte *)CFDataGetBytePtr(dataFromImageDataProvider); - int width = (int)CGImageGetWidth(image); - int height = (int)CGImageGetHeight(image); - assert((width > 0 && height > 0) && "image can not be empty"); - - setImage(width, height, imageData); - - CFRelease(dataFromImageDataProvider); - - return this; - -} - -UIImage* SourceImage::_adjustImageOrientation(UIImage* image) -{ - if (image.imageOrientation == UIImageOrientationUp) - return image; - - CGAffineTransform transform = CGAffineTransformIdentity; - switch (image.imageOrientation) { - case UIImageOrientationDown: - case UIImageOrientationDownMirrored: - transform = CGAffineTransformTranslate(transform, image.size.width, image.size.height); - transform = CGAffineTransformRotate(transform, M_PI); - break; - case UIImageOrientationLeft: - case UIImageOrientationLeftMirrored: - transform = CGAffineTransformTranslate(transform, image.size.width, 0); - transform = CGAffineTransformRotate(transform, M_PI_2); - break; - case UIImageOrientationRight: - case UIImageOrientationRightMirrored: - transform = CGAffineTransformTranslate(transform, 0, image.size.height); - transform = CGAffineTransformRotate(transform, -M_PI_2); - break; - default: - break; - } - - switch (image.imageOrientation) { - case UIImageOrientationUpMirrored: - case UIImageOrientationDownMirrored: - transform = CGAffineTransformTranslate(transform, image.size.width, 0); - transform = CGAffineTransformScale(transform, -1, 1); - break; - case UIImageOrientationLeftMirrored: - case UIImageOrientationRightMirrored: - transform = CGAffineTransformTranslate(transform, image.size.height, 0); - transform = CGAffineTransformScale(transform, -1, 1); - break; - default: - break; - } - - CGContextRef ctx = CGBitmapContextCreate(NULL, image.size.width, image.size.height, - CGImageGetBitsPerComponent(image.CGImage), 0, - CGImageGetColorSpace(image.CGImage), - CGImageGetBitmapInfo(image.CGImage)); - CGContextConcatCTM(ctx, transform); - switch (image.imageOrientation) { - case UIImageOrientationLeft: - case UIImageOrientationLeftMirrored: - case UIImageOrientationRight: - case UIImageOrientationRightMirrored: - CGContextDrawImage(ctx, CGRectMake(0,0,image.size.height,image.size.width), image.CGImage); - break; - default: - CGContextDrawImage(ctx, CGRectMake(0,0,image.size.width,image.size.height), image.CGImage); - break; - } - - CGImageRef cgImage = CGBitmapContextCreateImage(ctx); - UIImage* newImage = [UIImage imageWithCGImage:cgImage]; - CGContextRelease(ctx); - CGImageRelease(cgImage); - return newImage; -} - -#endif diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceImage.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceImage.h deleted file mode 100755 index 69ad4dd..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceImage.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GPUIMAGE_X_SOURCEIMAGE_H -#define GPUIMAGE_X_SOURCEIMAGE_H - -#include "Source.hpp" - -NS_GI_BEGIN - -class SourceImage : public Source{ -public: - SourceImage() {} - - static SourceImage* create(int width, int height, const void* pixels); - SourceImage* setImage(int width, int height, const void* pixels); - -#if PLATFORM == PLATFORM_IOS - static SourceImage* create(NSURL* imageUrl); - SourceImage* setImage(NSURL* imageUrl); - - static SourceImage* create(NSData* imageData); - SourceImage* setImage(NSData* imageData); - - static SourceImage* create(UIImage* image); - SourceImage* setImage(UIImage* image); - - static SourceImage* create(CGImageRef image); - SourceImage* setImage(CGImageRef image); - -private: - UIImage* _adjustImageOrientation(UIImage* image); -#endif -}; - -NS_GI_END - -#endif //GPUIMAGE_X_SOURCEIMAGE_H diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/Target.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/Target.cpp deleted file mode 100755 index 517aa8e..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/Target.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "Target.hpp" -#include "../util.h" - -NS_GI_BEGIN - -Target::Target(int inputNumber/* = 1*/) -:_inputNum(inputNumber) -{ -} - -Target::~Target() -{ - for (std::map::iterator it = _inputFramebuffers.begin(); it != _inputFramebuffers.end(); ++it) { - if (it->second.frameBuffer) { - it->second.frameBuffer->release(); - it->second.frameBuffer = 0; - } - } - _inputFramebuffers.clear(); -} - -void Target::setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode/* = NoRotation*/, int texIdx/* = 0*/) { - InputFrameBufferInfo inputFrameBufferInfo; - inputFrameBufferInfo.frameBuffer = framebuffer; - inputFrameBufferInfo.rotationMode = rotationMode; - inputFrameBufferInfo.texIndex = texIdx; - inputFrameBufferInfo.ignoreForPrepare = false; - if (_inputFramebuffers.find(texIdx) != _inputFramebuffers.end() && _inputFramebuffers[texIdx].frameBuffer) { - _inputFramebuffers[texIdx].frameBuffer->release(); - _inputFramebuffers[texIdx].frameBuffer = 0; - } - _inputFramebuffers[texIdx] = inputFrameBufferInfo; - if (_inputFramebuffers[texIdx].frameBuffer) { - _inputFramebuffers[texIdx].frameBuffer->retain(); - } -} - -int Target::getNextAvailableTextureIndex() const { - for (int i = 0; i < _inputNum; ++i) { - if (_inputFramebuffers.find(i) == _inputFramebuffers.end()) - return i; - } - return _inputNum - 1; -} - -bool Target::isPrepared() const { - int preparedNum = 0; - int ignoreForPrepareNum = 0; - for (std::map::const_iterator it = _inputFramebuffers.begin(); it != _inputFramebuffers.end(); ++it) { - if (it->second.ignoreForPrepare) - ignoreForPrepareNum++; - else if (it->second.frameBuffer) - preparedNum++; - } - if (ignoreForPrepareNum + preparedNum >= _inputNum) - return true; - else - return false; -} - -void Target::unPrepear() { - for (std::map::iterator it = _inputFramebuffers.begin(); it != _inputFramebuffers.end(); ++it) { - if (!it->second.ignoreForPrepare) { - if (it->second.frameBuffer) { - it->second.frameBuffer->release(); - it->second.frameBuffer = 0; - } - } - } -} - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/Target.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/Target.hpp deleted file mode 100755 index 2afbc7d..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/Target.hpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef Target_hpp -#define Target_hpp - - -#include "../macros.h" -#include "../Framebuffer.hpp" -#include - -NS_GI_BEGIN - -enum RotationMode { - NoRotation = 0, - RotateLeft, - RotateRight, - FlipVertical, - FlipHorizontal, - RotateRightFlipVertical, - RotateRightFlipHorizontal, - Rotate180 -}; - -class Target : public virtual Ref { -public: - Target(int inputNumber = 1); - virtual ~Target(); - virtual void setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode = NoRotation, int texIdx = 0); - virtual bool isPrepared() const; - virtual void unPrepear(); - virtual void update(float frameTime) {}; - virtual int getNextAvailableTextureIndex() const; - //virtual void setInputSizeWithIdx(int width, int height, int textureIdx) {}; -protected: - struct InputFrameBufferInfo { - Framebuffer* frameBuffer; - RotationMode rotationMode; - int texIndex; - bool ignoreForPrepare; - }; - - std::map _inputFramebuffers; - int _inputNum; -}; - -NS_GI_END - -#endif /* Target_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/TargetView.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/TargetView.cpp deleted file mode 100755 index e27d9a4..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/TargetView.cpp +++ /dev/null @@ -1,230 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "TargetView.h" -#include "../Context.hpp" -#include "../util.h" -#include "../filter/Filter.hpp" - -USING_NS_GI - -TargetView::TargetView() -:_viewWidth(0) -,_viewHeight(0) - ,_fillMode(FillMode::PreserveAspectRatio) -,_displayProgram(0) -,_positionAttribLocation(0) -,_texCoordAttribLocation(0) -,_colorMapUniformLocation(0) -{ - _backgroundColor.r = 0.0; - _backgroundColor.g = 0.0; - _backgroundColor.b = 0.0; - _backgroundColor.a = 0.0; - init(); -} - -TargetView::~TargetView() -{ - if (_displayProgram) { - delete _displayProgram; - _displayProgram = 0; - } -} - -void TargetView::init() { - _displayProgram = GLProgram::createByShaderString(kDefaultVertexShader, kDefaultFragmentShader); - _positionAttribLocation = _displayProgram->getAttribLocation("position"); - _texCoordAttribLocation = _displayProgram->getAttribLocation("texCoord"); - _colorMapUniformLocation = _displayProgram->getUniformLocation("colorMap"); - Context::getInstance()->setActiveShaderProgram(_displayProgram); - CHECK_GL(glEnableVertexAttribArray(_positionAttribLocation)); - CHECK_GL(glEnableVertexAttribArray(_texCoordAttribLocation)); - -}; - -void TargetView::setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode/* = NoRotation*/, int texIdx/* = 0*/) -{ - Framebuffer* lastInputFramebuffer = 0; - RotationMode lastInputRotation = NoRotation; - if (_inputFramebuffers.find(0) != _inputFramebuffers.end()) { - lastInputFramebuffer = _inputFramebuffers[0].frameBuffer; - lastInputRotation = _inputFramebuffers[0].rotationMode; - } - - Target::setInputFramebuffer(framebuffer, rotationMode, texIdx); - - if (lastInputFramebuffer != framebuffer && framebuffer && - (!lastInputFramebuffer || - !(lastInputFramebuffer->getWidth() == framebuffer->getWidth() && - lastInputFramebuffer->getHeight() == framebuffer->getHeight() && - lastInputRotation == rotationMode) - )) { - _updateDisplayVertices(); - } -} - -void TargetView::setFillMode(FillMode fillMode) { - if (_fillMode != fillMode) { - _fillMode = fillMode; - _updateDisplayVertices(); - } -} - -void TargetView::onSizeChanged(int width, int height) { - if (_viewWidth != width || _viewHeight != height) { - _viewWidth = width; - _viewHeight = height; - _updateDisplayVertices(); - } -} - -void TargetView::update(float frameTime) -{ - CHECK_GL(glBindFramebuffer(GL_FRAMEBUFFER, 0)); - CHECK_GL(glViewport(0, 0, _viewWidth, _viewHeight)); - CHECK_GL(glClearColor(_backgroundColor.r, _backgroundColor.g, _backgroundColor.b, _backgroundColor.a)); - CHECK_GL(glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)); - Context::getInstance()->setActiveShaderProgram(_displayProgram); - CHECK_GL(glActiveTexture(GL_TEXTURE0)); - CHECK_GL(glBindTexture(GL_TEXTURE_2D, _inputFramebuffers[0].frameBuffer->getTexture())); - CHECK_GL(glUniform1i(_colorMapUniformLocation, 0)); - CHECK_GL(glVertexAttribPointer(_positionAttribLocation, 2, GL_FLOAT, 0, 0, _displayVertices)); - CHECK_GL(glVertexAttribPointer(_texCoordAttribLocation, 2, GL_FLOAT, 0, 0, _getTexureCoordinate(_inputFramebuffers[0].rotationMode))); - CHECK_GL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); -} - -void TargetView::_updateDisplayVertices() -{ - if (_inputFramebuffers.find(0) == _inputFramebuffers.end() || _inputFramebuffers[0].frameBuffer == 0) return; - - Framebuffer* inputFramebuffer = _inputFramebuffers[0].frameBuffer; - RotationMode inputRotation = _inputFramebuffers[0].rotationMode; - - int rotatedFramebufferWidth = inputFramebuffer->getWidth(); - int rotatedFramebufferHeight = inputFramebuffer->getHeight(); - if (rotationSwapsSize(inputRotation)) - { - rotatedFramebufferWidth = inputFramebuffer->getHeight(); - rotatedFramebufferHeight = inputFramebuffer->getWidth(); - } - - float framebufferAspectRatio = rotatedFramebufferHeight / (float)rotatedFramebufferWidth; - float viewAspectRatio = _viewHeight / (float)_viewWidth; - - float insetFramebufferWidth = 0.0; - float insetFramebufferHeight = 0.0; - if (framebufferAspectRatio > viewAspectRatio) { - insetFramebufferWidth = _viewHeight / (float)rotatedFramebufferHeight * rotatedFramebufferWidth; - insetFramebufferHeight = _viewHeight; - } else { - insetFramebufferWidth = _viewWidth; - insetFramebufferHeight = _viewWidth / (float)rotatedFramebufferWidth * rotatedFramebufferHeight; - } - - float scaledWidth = 1.0; - float scaledHeight = 1.0; - if (_fillMode == FillMode::PreserveAspectRatio) { - scaledWidth = insetFramebufferWidth / _viewWidth; - scaledHeight = insetFramebufferHeight / _viewHeight; - } else if (_fillMode == FillMode::PreserveAspectRatioAndFill) { - scaledWidth = _viewWidth / insetFramebufferHeight; - scaledHeight = _viewHeight / insetFramebufferWidth; - } - - _displayVertices[0] = -scaledWidth; - _displayVertices[1] = -scaledHeight; - _displayVertices[2] = scaledWidth; - _displayVertices[3] = -scaledHeight; - _displayVertices[4] = -scaledWidth; - _displayVertices[5] = scaledHeight; - _displayVertices[6] = scaledWidth; - _displayVertices[7] = scaledHeight; - -} - -const GLfloat* TargetView::_getTexureCoordinate(RotationMode rotationMode) -{ - static const GLfloat noRotationTextureCoordinates[] = { - 0.0f, 1.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 0.0f, - }; - - static const GLfloat rotateRightTextureCoordinates[] = { - 1.0f, 1.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 0.0f, 0.0f, - }; - - static const GLfloat rotateLeftTextureCoordinates[] = { - 0.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 1.0f, 1.0f, - }; - - static const GLfloat verticalFlipTextureCoordinates[] = { - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, - }; - - static const GLfloat horizontalFlipTextureCoordinates[] = { - 1.0f, 1.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 0.0f, 0.0f, - }; - - static const GLfloat rotateRightVerticalFlipTextureCoordinates[] = { - 1.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 0.0f, 1.0f, - }; - - static const GLfloat rotateRightHorizontalFlipTextureCoordinates[] = { - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f, - }; - - static const GLfloat rotate180TextureCoordinates[] = { - 1.0f, 0.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 1.0f, - }; - - switch(rotationMode) - { - case NoRotation: return noRotationTextureCoordinates; - case RotateLeft: return rotateLeftTextureCoordinates; - case RotateRight: return rotateRightTextureCoordinates; - case FlipVertical: return verticalFlipTextureCoordinates; - case FlipHorizontal: return horizontalFlipTextureCoordinates; - case RotateRightFlipVertical: return rotateRightVerticalFlipTextureCoordinates; - case RotateRightFlipHorizontal: return rotateRightHorizontalFlipTextureCoordinates; - case Rotate180: return rotate180TextureCoordinates; - } -} diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/TargetView.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/TargetView.h deleted file mode 100755 index a492ab0..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/TargetView.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef GPUIMAGE_X_TARGETVIEW_H -#define GPUIMAGE_X_TARGETVIEW_H - -#include "Target.hpp" -#include "../GLProgram.hpp" - -NS_GI_BEGIN - -class TargetView : public Target { -public: - enum FillMode { - Stretch = 0, // Stretch to fill the view, and may distort the image - PreserveAspectRatio = 1, // preserve the aspect ratio of the image - PreserveAspectRatioAndFill = 2 // preserve the aspect ratio, and zoom in to fill the view - }; - -public: - TargetView(); - ~TargetView(); - - void init(); - virtual void setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode = NoRotation, int texIdx = 0) override; - void setFillMode(FillMode fillMode); - void onSizeChanged(int width, int height); - virtual void update(float frameTime) override; - -private: - int _viewWidth; - int _viewHeight; - FillMode _fillMode; - GLProgram* _displayProgram; - GLuint _positionAttribLocation; - GLuint _texCoordAttribLocation; - GLuint _colorMapUniformLocation; - struct { - float r; float g; float b; float a; - } _backgroundColor; - - GLfloat _displayVertices[8]; - - void _updateDisplayVertices(); - const GLfloat* _getTexureCoordinate(RotationMode rotationMode); -}; - -NS_GI_END - -#endif //GPUIMAGE_X_TARGETVIEW_H diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageTarget.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageTarget.h deleted file mode 100755 index 1e02aea..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageTarget.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if PLATFORM == PLATFORM_IOS - -#import -#include "Framebuffer.hpp" -#include "Target.hpp" - -@protocol GPUImageTarget - -@required -- (void)update:(float)frameTime; -- (void)setInputFramebuffer:(GPUImage::Framebuffer*)inputFramebuffer withRotation:(GPUImage::RotationMode)rotationMode atIndex:(NSInteger)texIdx; -@optional -- (bool)isPrepared; -- (void)unPrepared; - -@end - -#endif - diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageTarget.mm b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageTarget.mm deleted file mode 100755 index 731a3a9..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageTarget.mm +++ /dev/null @@ -1,23 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if PLATFORM == PLATFORM_IOS - -#import "GPUImageTarget.h" - -#endif diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageView.mm b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageView.mm deleted file mode 100755 index 2ad8f20..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageView.mm +++ /dev/null @@ -1,334 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if PLATFORM == PLATFORM_IOS - -#import "GPUImageView.h" -#include "Context.hpp" -#include "GLProgram.hpp" -#include "Filter.hpp" -#import - - -@interface GPUImageView() -{ - GPUImage::Framebuffer* inputFramebuffer; - GPUImage::RotationMode inputRotation; - GLuint displayFramebuffer; - GLuint displayRenderbuffer; - GPUImage::GLProgram* displayProgram; - GLuint positionAttribLocation; - GLuint texCoordAttribLocation; - GLuint colorMapUniformLocation; - - GLfloat displayVertices[8]; - GLint framebufferWidth, framebufferHeight; - CGSize lastBoundsSize; - - GLfloat backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha; - -} - -@end - - -@implementation GPUImageView - -+ (Class)layerClass -{ - return [CAEAGLLayer class]; -} - -- (id)initWithFrame:(CGRect)frame -{ - if (!(self = [super initWithFrame:frame])) - { - return nil; - } - - [self commonInit]; - - return self; -} - -- (void)commonInit; -{ - inputRotation = GPUImage::NoRotation; - self.opaque = YES; - self.hidden = NO; - CAEAGLLayer* eaglLayer = (CAEAGLLayer*)self.layer; - eaglLayer.opaque = YES; - eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; - - GPUImage::Context::getInstance()->runSync([&]{ - displayProgram = GPUImage::GLProgram::createByShaderString(GPUImage::kDefaultVertexShader, GPUImage::kDefaultFragmentShader); - - positionAttribLocation = displayProgram->getAttribLocation("position"); - texCoordAttribLocation = displayProgram->getAttribLocation("texCoord"); - colorMapUniformLocation = displayProgram->getUniformLocation("colorMap"); - - GPUImage::Context::getInstance()->setActiveShaderProgram(displayProgram); - glEnableVertexAttribArray(positionAttribLocation); - glEnableVertexAttribArray(texCoordAttribLocation); - - [self setBackgroundColorRed:0.0 green:0.0 blue:0.0 alpha:0.0]; - _fillMode = GPUImage::TargetView::FillMode::PreserveAspectRatio; - [self createDisplayFramebuffer]; - }); -} - -- (void)layoutSubviews { - [super layoutSubviews]; - - if (!CGSizeEqualToSize(self.bounds.size, lastBoundsSize) && - !CGSizeEqualToSize(self.bounds.size, CGSizeZero)) { - [self destroyDisplayFramebuffer]; - [self createDisplayFramebuffer]; - } -} - -- (void)dealloc -{ - [self destroyDisplayFramebuffer]; -} - -- (void)createDisplayFramebuffer; -{ - GPUImage::Context::getInstance()->runSync([&]{ - - glGenRenderbuffers(1, &displayRenderbuffer); - glBindRenderbuffer(GL_RENDERBUFFER, displayRenderbuffer); - [GPUImage::Context::getInstance()->getEglContext() renderbufferStorage:GL_RENDERBUFFER fromDrawable:(CAEAGLLayer*)self.layer]; - - glGenFramebuffers(1, &displayFramebuffer); - glBindFramebuffer(GL_FRAMEBUFFER, displayFramebuffer); - glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, - GL_RENDERBUFFER, displayRenderbuffer); - - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, &framebufferWidth); - glGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &framebufferHeight); - - lastBoundsSize = self.bounds.size; - [self updateDisplayVertices]; - }); -} - -- (void)destroyDisplayFramebuffer; -{ - GPUImage::Context::getInstance()->runSync([&]{ - - if (displayFramebuffer) - { - glDeleteFramebuffers(1, &displayFramebuffer); - displayFramebuffer = 0; - } - - if (displayRenderbuffer) - { - glDeleteRenderbuffers(1, &displayRenderbuffer); - displayRenderbuffer = 0; - } - }); -} - -- (void)setDisplayFramebuffer; -{ - if (!displayFramebuffer) - { - [self createDisplayFramebuffer]; - } - - GPUImage::Context::getInstance()->runSync([&]{ - glBindFramebuffer(GL_FRAMEBUFFER, displayFramebuffer); - glViewport(0, 0, framebufferWidth, framebufferHeight); - }); -} - -- (void)presentFramebuffer; -{ - GPUImage::Context::getInstance()->runAsync([&]{ - glBindRenderbuffer(GL_RENDERBUFFER, displayRenderbuffer); - GPUImage::Context::getInstance()->presentBufferForDisplay(); - }); -} - -- (void)setBackgroundColorRed:(GLfloat)redComponent green:(GLfloat)greenComponent blue:(GLfloat)blueComponent alpha:(GLfloat)alphaComponent; -{ - backgroundColorRed = redComponent; - backgroundColorGreen = greenComponent; - backgroundColorBlue = blueComponent; - backgroundColorAlpha = alphaComponent; -} - -- (void)update:(float)frameTime { - - GPUImage::Context::getInstance()->runSync([&]{ - GPUImage::Context::getInstance()->setActiveShaderProgram(displayProgram); - [self setDisplayFramebuffer]; - glClearColor(backgroundColorRed, backgroundColorGreen, backgroundColorBlue, backgroundColorAlpha); - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, inputFramebuffer->getTexture()); - glUniform1i(colorMapUniformLocation, 0); - - glVertexAttribPointer(positionAttribLocation, 2, GL_FLOAT, 0, 0, displayVertices); - glVertexAttribPointer(texCoordAttribLocation, 2, GL_FLOAT, 0, 0, [self textureCoordinatesForRotation:inputRotation] ); - - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - - [self presentFramebuffer]; - }); -} - -- (void)setInputFramebuffer:(GPUImage::Framebuffer*)newInputFramebuffer withRotation:(GPUImage::RotationMode)rotation atIndex:(NSInteger)texIdx { - GPUImage::Framebuffer* lastFramebuffer = inputFramebuffer; - GPUImage::RotationMode lastInputRotation = inputRotation; - - inputRotation = rotation; - inputFramebuffer = newInputFramebuffer; - - if (lastFramebuffer != newInputFramebuffer && newInputFramebuffer && - ( !lastFramebuffer || - !(lastFramebuffer->getWidth() == newInputFramebuffer->getWidth() && - lastFramebuffer->getHeight() == newInputFramebuffer->getHeight() && - lastInputRotation == rotation) - )) - { - [self updateDisplayVertices]; - } -} - -- (void)setFillMode:(GPUImage::TargetView::FillMode)newValue; -{ - if (_fillMode != newValue) { - _fillMode = newValue; - [self updateDisplayVertices]; - } -} - -- (void)updateDisplayVertices; -{ - if (inputFramebuffer == 0) return; - - CGFloat scaledWidth = 1.0; - CGFloat scaledHeight = 1.0; - - int rotatedFramebufferWidth = inputFramebuffer->getWidth(); - int rotatedFramebufferHeight = inputFramebuffer->getHeight(); - if (rotationSwapsSize(inputRotation)) - { - rotatedFramebufferWidth = inputFramebuffer->getHeight(); - rotatedFramebufferHeight = inputFramebuffer->getWidth(); - } - - CGRect insetRect = AVMakeRectWithAspectRatioInsideRect(CGSizeMake(rotatedFramebufferWidth, rotatedFramebufferHeight), self.bounds); - - if (_fillMode == GPUImage::TargetView::FillMode::PreserveAspectRatio) { - scaledWidth = insetRect.size.width / self.bounds.size.width; - scaledHeight = insetRect.size.height / self.bounds.size.height; - } else if (_fillMode == GPUImage::TargetView::FillMode::PreserveAspectRatioAndFill) { - scaledWidth = self.bounds.size.height / insetRect.size.height; - scaledHeight = self.bounds.size.width / insetRect.size.width; - } - - displayVertices[0] = -scaledWidth; - displayVertices[1] = -scaledHeight; - displayVertices[2] = scaledWidth; - displayVertices[3] = -scaledHeight; - displayVertices[4] = -scaledWidth; - displayVertices[5] = scaledHeight; - displayVertices[6] = scaledWidth; - displayVertices[7] = scaledHeight; -} - - -- (const GLfloat *)textureCoordinatesForRotation:(GPUImage::RotationMode)rotationMode; -{ - static const GLfloat noRotationTextureCoordinates[] = { - 0.0f, 1.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 0.0f, - }; - - static const GLfloat rotateRightTextureCoordinates[] = { - 1.0f, 1.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 0.0f, 0.0f, - }; - - static const GLfloat rotateLeftTextureCoordinates[] = { - 0.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 1.0f, 1.0f, - }; - - static const GLfloat verticalFlipTextureCoordinates[] = { - 0.0f, 0.0f, - 1.0f, 0.0f, - 0.0f, 1.0f, - 1.0f, 1.0f, - }; - - static const GLfloat horizontalFlipTextureCoordinates[] = { - 1.0f, 1.0f, - 0.0f, 1.0f, - 1.0f, 0.0f, - 0.0f, 0.0f, - }; - - static const GLfloat rotateRightVerticalFlipTextureCoordinates[] = { - 1.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 0.0f, - 0.0f, 1.0f, - }; - - static const GLfloat rotateRightHorizontalFlipTextureCoordinates[] = { - 0.0f, 1.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 1.0f, 0.0f, - }; - - static const GLfloat rotate180TextureCoordinates[] = { - 1.0f, 0.0f, - 0.0f, 0.0f, - 1.0f, 1.0f, - 0.0f, 1.0f, - }; - - switch(inputRotation) - { - case GPUImage::NoRotation: return noRotationTextureCoordinates; - case GPUImage::RotateLeft: return rotateLeftTextureCoordinates; - case GPUImage::RotateRight: return rotateRightTextureCoordinates; - case GPUImage::FlipVertical: return verticalFlipTextureCoordinates; - case GPUImage::FlipHorizontal: return horizontalFlipTextureCoordinates; - case GPUImage::RotateRightFlipVertical: return rotateRightVerticalFlipTextureCoordinates; - case GPUImage::RotateRightFlipHorizontal: return rotateRightHorizontalFlipTextureCoordinates; - case GPUImage::Rotate180: return rotate180TextureCoordinates; - } -} - -@end - -#endif diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/IOSTarget.hpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/IOSTarget.hpp deleted file mode 100755 index 430e198..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/IOSTarget.hpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#if PLATFORM == PLATFORM_IOS - -#ifndef IOSTarget_hpp -#define IOSTarget_hpp - -#include "Target.hpp" -#import "GPUImageTarget.h" - -NS_GI_BEGIN - -class IOSTarget : public Target{ -public: - IOSTarget(id realTarget) { - _realTarget = realTarget; - } - - virtual ~IOSTarget() { _realTarget = 0; } - - virtual void update(float frameTime) override { - [_realTarget update:frameTime]; - }; - - virtual void setInputFramebuffer(Framebuffer* framebuffer, RotationMode rotationMode = NoRotation, int texIdx = 0) override { - [ _realTarget setInputFramebuffer:framebuffer withRotation:rotationMode atIndex:texIdx]; - }; - - virtual bool isPrepared() const override { - if ([_realTarget respondsToSelector:@selector(isPrepared)]) - return [_realTarget isPrepared]; - else - return true; - } - - virtual void unPrepear() override { - if ([_realTarget respondsToSelector:@selector(unPrepared)]) - [_realTarget unPrepared]; - } - -private: - id _realTarget; - -}; - -NS_GI_END - -#endif // IOSTarget_hpp - -#endif diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/util.cpp b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/util.cpp deleted file mode 100755 index b7a1642..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/util.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "util.h" - -#if PLATFORM == PLATFORM_ANDROID -#include -#elif PLATFORM == PLATFORM_IOS -#import -#endif - - -NS_GI_BEGIN - - std::string str_format(const char *fmt,...) { - std::string strResult=""; - if (NULL != fmt) - { - va_list marker; - va_start(marker, fmt); - char *buf = 0; - int result = vasprintf (&buf, fmt, marker); - if (!buf) - { - va_end(marker); - return strResult; - } - - if (result < 0) - { - free (buf); - va_end(marker); - return strResult; - } - - result = (int)strlen (buf); - strResult.append(buf,result); - free(buf); - va_end(marker); - } - return strResult; - } - - void Log(const std::string& tag, const std::string& format, ...) - { - char buffer[10240]; - va_list args; - va_start(args, format); - vsprintf(buffer, format.c_str(), args); - va_end(args); -#if PLATFORM == PLATFORM_ANDROID - __android_log_print(ANDROID_LOG_INFO, tag.c_str(), "%s", buffer); -#elif PLATFORM == PLATFORM_IOS - NSLog(@"%s", buffer); -#endif - - } - -NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/util.h b/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/util.h deleted file mode 100755 index ed94d28..0000000 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/util.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - * GPUImage-x - * - * Copyright (C) 2017 Yijin Wang, Yiqian Wang - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef util_h -#define util_h - -#include -#include -#include "macros.h" - -NS_GI_BEGIN - - std::string str_format(const char *fmt,...); - void Log(const std::string& tag, const std::string& format, ...); - -#define rotationSwapsSize(rotation) ((rotation) == GPUImage::RotateLeft || (rotation) == GPUImage::RotateRight || (rotation) == GPUImage::RotateRightFlipVertical || (rotation) == GPUImage::RotateRightFlipHorizontal) - -NS_GI_END - -#endif /* util_h */ diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100755 index 64653a9..0000000 --- a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.xcworkspace/xcuserdata/jin.xcuserdatad/UserInterfaceState.xcuserstate b/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.xcworkspace/xcuserdata/jin.xcuserdatad/UserInterfaceState.xcuserstate deleted file mode 100755 index b50a072..0000000 Binary files a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.xcworkspace/xcuserdata/jin.xcuserdatad/UserInterfaceState.xcuserstate and /dev/null differ diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/GPUImage-x-Sample.xcscheme b/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/GPUImage-x-Sample.xcscheme deleted file mode 100755 index 54e74e4..0000000 --- a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/GPUImage-x-Sample.xcscheme +++ /dev/null @@ -1,91 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/xcschememanagement.plist b/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/xcschememanagement.plist deleted file mode 100755 index 9b75b32..0000000 --- a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/xcuserdata/jin.xcuserdatad/xcschemes/xcschememanagement.plist +++ /dev/null @@ -1,22 +0,0 @@ - - - - - SchemeUserState - - GPUImage-x-Sample.xcscheme - - orderHint - 0 - - - SuppressBuildableAutocreation - - 3C4DE12E1E7D84F4006ADF0A - - primary - - - - - diff --git a/GPUImage-x/proj.android/GPUImage-x/.gitignore b/android/.gitignore similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/.gitignore rename to android/.gitignore diff --git a/GPUImage-x/proj.android/GPUImage-x/build.gradle b/android/build.gradle old mode 100755 new mode 100644 similarity index 73% rename from GPUImage-x/proj.android/GPUImage-x/build.gradle rename to android/build.gradle index 09866c1..9806251 --- a/GPUImage-x/proj.android/GPUImage-x/build.gradle +++ b/android/build.gradle @@ -2,16 +2,18 @@ buildscript { repositories { + google() jcenter() } + dependencies { - classpath 'com.android.tools.build:gradle:2.2.2' - classpath 'com.novoda:bintray-release:0.3.4' + classpath 'com.android.tools.build:gradle:3.1.2' } } allprojects { repositories { + google() jcenter() } } diff --git a/GPUImage-x/proj.android/GPUImage-x/gradle.properties b/android/gradle.properties old mode 100755 new mode 100644 similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/gradle.properties rename to android/gradle.properties diff --git a/GPUImage-x/proj.android/GPUImage-x/gradle/wrapper/gradle-wrapper.jar b/android/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/gradle/wrapper/gradle-wrapper.jar rename to android/gradle/wrapper/gradle-wrapper.jar diff --git a/GPUImage-x/proj.android/GPUImage-x/gradle/wrapper/gradle-wrapper.properties b/android/gradle/wrapper/gradle-wrapper.properties similarity index 92% rename from GPUImage-x/proj.android/GPUImage-x/gradle/wrapper/gradle-wrapper.properties rename to android/gradle/wrapper/gradle-wrapper.properties index 04e285f..24e7c39 100755 --- a/GPUImage-x/proj.android/GPUImage-x/gradle/wrapper/gradle-wrapper.properties +++ b/android/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-2.14.1-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip diff --git a/GPUImage-x/proj.android/GPUImage-x/gradlew b/android/gradlew similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/gradlew rename to android/gradlew diff --git a/GPUImage-x/proj.android/GPUImage-x/gradlew.bat b/android/gradlew.bat similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/gradlew.bat rename to android/gradlew.bat diff --git a/GPUImage-x/proj.android/GPUImage-x/library/CMakeLists.txt b/android/library/CMakeLists.txt old mode 100755 new mode 100644 similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/CMakeLists.txt rename to android/library/CMakeLists.txt index bb25893..90b3c50 --- a/GPUImage-x/proj.android/GPUImage-x/library/CMakeLists.txt +++ b/android/library/CMakeLists.txt @@ -8,8 +8,12 @@ add_library( GPUImage-x src/main/cpp/Framebuffer.cpp src/main/cpp/GLProgram.cpp src/main/cpp/Context.cpp - src/main/cpp/math.cpp src/main/cpp/GPUImagexJNI.cpp + src/main/cpp/math/Matrix3.cpp + src/main/cpp/math/Matrix4.cpp + src/main/cpp/math/Vector2.cpp + src/main/cpp/math/Vector3.cpp + src/main/cpp/math/Vector4.cpp src/main/cpp/source/Source.cpp src/main/cpp/source/SourceImage.cpp src/main/cpp/source/SourceCamera.cpp diff --git a/android/library/build.gradle b/android/library/build.gradle new file mode 100644 index 0000000..5c2df1b --- /dev/null +++ b/android/library/build.gradle @@ -0,0 +1,31 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 27 + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 27 + versionCode 1 + versionName '1.0' + + externalNativeBuild { + cmake { + arguments '-DANDROID_ARM_NEON=TRUE' + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + externalNativeBuild { + cmake { + path 'CMakeLists.txt' + } + } +} diff --git a/GPUImage-x/proj.android/GPUImage-x/library/proguard-rules.pro b/android/library/proguard-rules.pro old mode 100755 new mode 100644 similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/proguard-rules.pro rename to android/library/proguard-rules.pro diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/AndroidManifest.xml b/android/library/src/main/AndroidManifest.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/AndroidManifest.xml rename to android/library/src/main/AndroidManifest.xml diff --git a/android/library/src/main/cpp b/android/library/src/main/cpp new file mode 120000 index 0000000..b3e266f --- /dev/null +++ b/android/library/src/main/cpp @@ -0,0 +1 @@ +../../../../src \ No newline at end of file diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImage.java b/android/library/src/main/java/com/jin/gpuimage/GPUImage.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImage.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImage.java diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageFilter.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageFilter.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageFilter.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageFilter.java diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageRenderer.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageRenderer.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageRenderer.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageRenderer.java diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSource.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageSource.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSource.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageSource.java diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSourceCamera.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageSourceCamera.java similarity index 95% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSourceCamera.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageSourceCamera.java index 3d7b830..a39df8b 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSourceCamera.java +++ b/android/library/src/main/java/com/jin/gpuimage/GPUImageSourceCamera.java @@ -49,6 +49,14 @@ public void run() { }); } + public Camera.Parameters getCameraParameters() { + if (mCamera == null) { + return null; + } + + return mCamera.getParameters(); + } + @Override public void onPreviewFrame(final byte[] data, Camera camera) { final Camera.Size previewSize = camera.getParameters().getPreviewSize(); diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSourceImage.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageSourceImage.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageSourceImage.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageSourceImage.java diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageTarget.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageTarget.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageTarget.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageTarget.java diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageView.java b/android/library/src/main/java/com/jin/gpuimage/GPUImageView.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/java/com/jin/gpuimage/GPUImageView.java rename to android/library/src/main/java/com/jin/gpuimage/GPUImageView.java diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/build.gradle b/android/sample/build.gradle old mode 100755 new mode 100644 similarity index 55% rename from GPUImage-x/proj.android/GPUImage-x/sample/build.gradle rename to android/sample/build.gradle index d18327d..13e2d8d --- a/GPUImage-x/proj.android/GPUImage-x/sample/build.gradle +++ b/android/sample/build.gradle @@ -1,17 +1,16 @@ apply plugin: 'com.android.application' android { - compileSdkVersion 25 - buildToolsVersion "25.0.0" + compileSdkVersion 27 defaultConfig { applicationId "com.jin.gpuimage.sample" - minSdkVersion 9 - targetSdkVersion 25 + minSdkVersion 14 + targetSdkVersion 27 versionCode 1 versionName "1.0" - } + buildTypes { release { minifyEnabled false @@ -21,8 +20,8 @@ android { } dependencies { - compile fileTree(dir: 'libs', include: ['*.jar']) - compile project(':library') -// compile 'com.jin.gpuimage-x:gpuimage-x:1.0.1' - compile 'com.android.support:support-v4:25.1.1' + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation 'com.android.support:appcompat-v7:27.1.1' + + api project(':library') } diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/proguard-rules.pro b/android/sample/proguard-rules.pro old mode 100755 new mode 100644 similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/proguard-rules.pro rename to android/sample/proguard-rules.pro diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/AndroidManifest.xml b/android/sample/src/main/AndroidManifest.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/AndroidManifest.xml rename to android/sample/src/main/AndroidManifest.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/assets/test.jpg b/android/sample/src/main/assets/test.jpg similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/assets/test.jpg rename to android/sample/src/main/assets/test.jpg diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/CameraSampleActivity.java b/android/sample/src/main/java/com/jin/gpuimage/sample/CameraSampleActivity.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/CameraSampleActivity.java rename to android/sample/src/main/java/com/jin/gpuimage/sample/CameraSampleActivity.java diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/FilterHelper.java b/android/sample/src/main/java/com/jin/gpuimage/sample/FilterHelper.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/FilterHelper.java rename to android/sample/src/main/java/com/jin/gpuimage/sample/FilterHelper.java diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/ImageSampleActivity.java b/android/sample/src/main/java/com/jin/gpuimage/sample/ImageSampleActivity.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/ImageSampleActivity.java rename to android/sample/src/main/java/com/jin/gpuimage/sample/ImageSampleActivity.java diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/MainActivity.java b/android/sample/src/main/java/com/jin/gpuimage/sample/MainActivity.java similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/java/com/jin/gpuimage/sample/MainActivity.java rename to android/sample/src/main/java/com/jin/gpuimage/sample/MainActivity.java diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/layout/activity_camera_sample.xml b/android/sample/src/main/res/layout/activity_camera_sample.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/layout/activity_camera_sample.xml rename to android/sample/src/main/res/layout/activity_camera_sample.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/layout/activity_image_sample.xml b/android/sample/src/main/res/layout/activity_image_sample.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/layout/activity_image_sample.xml rename to android/sample/src/main/res/layout/activity_image_sample.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/layout/activity_main.xml b/android/sample/src/main/res/layout/activity_main.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/layout/activity_main.xml rename to android/sample/src/main/res/layout/activity_main.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-hdpi/icon.jpg b/android/sample/src/main/res/mipmap-hdpi/icon.jpg similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-hdpi/icon.jpg rename to android/sample/src/main/res/mipmap-hdpi/icon.jpg diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-mdpi/icon.jpg b/android/sample/src/main/res/mipmap-mdpi/icon.jpg similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-mdpi/icon.jpg rename to android/sample/src/main/res/mipmap-mdpi/icon.jpg diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-xhdpi/icon.jpg b/android/sample/src/main/res/mipmap-xhdpi/icon.jpg similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-xhdpi/icon.jpg rename to android/sample/src/main/res/mipmap-xhdpi/icon.jpg diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-xxhdpi/icon.jpg b/android/sample/src/main/res/mipmap-xxhdpi/icon.jpg similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-xxhdpi/icon.jpg rename to android/sample/src/main/res/mipmap-xxhdpi/icon.jpg diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-xxxhdpi/icon.jpg b/android/sample/src/main/res/mipmap-xxxhdpi/icon.jpg similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/mipmap-xxxhdpi/icon.jpg rename to android/sample/src/main/res/mipmap-xxxhdpi/icon.jpg diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values-w820dp/dimens.xml b/android/sample/src/main/res/values-w820dp/dimens.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values-w820dp/dimens.xml rename to android/sample/src/main/res/values-w820dp/dimens.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/colors.xml b/android/sample/src/main/res/values/colors.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/colors.xml rename to android/sample/src/main/res/values/colors.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/dimens.xml b/android/sample/src/main/res/values/dimens.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/dimens.xml rename to android/sample/src/main/res/values/dimens.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/strings.xml b/android/sample/src/main/res/values/strings.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/strings.xml rename to android/sample/src/main/res/values/strings.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/styles.xml b/android/sample/src/main/res/values/styles.xml similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/sample/src/main/res/values/styles.xml rename to android/sample/src/main/res/values/styles.xml diff --git a/GPUImage-x/proj.android/GPUImage-x/settings.gradle b/android/settings.gradle old mode 100755 new mode 100644 similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/settings.gradle rename to android/settings.gradle diff --git a/ios/library/GPUImage-x b/ios/library/GPUImage-x new file mode 120000 index 0000000..929cb3d --- /dev/null +++ b/ios/library/GPUImage-x @@ -0,0 +1 @@ +../../src \ No newline at end of file diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.pbxproj b/ios/library/GPUImage-x.xcodeproj/project.pbxproj similarity index 93% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.pbxproj rename to ios/library/GPUImage-x.xcodeproj/project.pbxproj index d3a912a..5eeaab1 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x.xcodeproj/project.pbxproj +++ b/ios/library/GPUImage-x.xcodeproj/project.pbxproj @@ -7,6 +7,8 @@ objects = { /* Begin PBXBuildFile section */ + 1A71D25321502A8B00ADDA5A /* Vector3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A71D25121502A8B00ADDA5A /* Vector3.cpp */; }; + 1A71D25621502D1600ADDA5A /* Vector4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 1A71D25521502D1500ADDA5A /* Vector4.cpp */; }; 3C0F8F041E967FDB007E34AF /* Convolution3x3Filter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C0F8F021E967FDB007E34AF /* Convolution3x3Filter.cpp */; }; 3C0F8F071E968AF5007E34AF /* EmbossFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C0F8F051E968AF5007E34AF /* EmbossFilter.cpp */; }; 3C21FAD01E8A9719007DFE11 /* PosterizeFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C21FACE1E8A9719007DFE11 /* PosterizeFilter.cpp */; }; @@ -21,7 +23,7 @@ 3C5FF5F01E7055FE00BF0874 /* Framebuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5DF1E7055FE00BF0874 /* Framebuffer.cpp */; }; 3C5FF5F11E7055FE00BF0874 /* FramebufferCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5E11E7055FE00BF0874 /* FramebufferCache.cpp */; }; 3C5FF5F21E7055FE00BF0874 /* GLProgram.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5E31E7055FE00BF0874 /* GLProgram.cpp */; }; - 3C5FF5F41E7055FE00BF0874 /* math.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5E71E7055FE00BF0874 /* math.cpp */; }; + 3C5FF5F41E7055FE00BF0874 /* Vector2.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5E71E7055FE00BF0874 /* Vector2.cpp */; }; 3C5FF5F51E7055FE00BF0874 /* Ref.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5E91E7055FE00BF0874 /* Ref.cpp */; }; 3C5FF5F61E7055FE00BF0874 /* util.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C5FF5ED1E7055FE00BF0874 /* util.cpp */; }; 3C74D7691EA119600074FEF5 /* HalftoneFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3C74D7671EA119600074FEF5 /* HalftoneFilter.cpp */; }; @@ -66,6 +68,8 @@ 3CAE3C3D1EA8F7D800757974 /* GlassSphereFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CAE3C3B1EA8F7D800757974 /* GlassSphereFilter.cpp */; }; 3CC8ECF61E894FA300ADD376 /* SmoothToonFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CC8ECF41E894FA300ADD376 /* SmoothToonFilter.cpp */; }; 3CFE65271E8C1A5400E7C5CF /* NonMaximumSuppressionFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3CFE65251E8C1A5400E7C5CF /* NonMaximumSuppressionFilter.cpp */; }; + F6A1C3792151BFAB001C1ADD /* Matrix3.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6A1C3772151BFAB001C1ADD /* Matrix3.cpp */; }; + F6A1C37C2151C1A1001C1ADD /* Matrix4.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F6A1C37A2151C1A1001C1ADD /* Matrix4.cpp */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -81,6 +85,10 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 1A71D25121502A8B00ADDA5A /* Vector3.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = Vector3.cpp; path = ../../../../src/Math/Vector3.cpp; sourceTree = ""; }; + 1A71D25221502A8B00ADDA5A /* Vector3.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = Vector3.hpp; path = ../../../../src/Math/Vector3.hpp; sourceTree = ""; }; + 1A71D25421502D1500ADDA5A /* Vector4.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Vector4.hpp; sourceTree = ""; }; + 1A71D25521502D1500ADDA5A /* Vector4.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Vector4.cpp; sourceTree = ""; }; 3C0F8F021E967FDB007E34AF /* Convolution3x3Filter.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; name = Convolution3x3Filter.cpp; path = filter/Convolution3x3Filter.cpp; sourceTree = ""; }; 3C0F8F031E967FDB007E34AF /* Convolution3x3Filter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = Convolution3x3Filter.hpp; path = filter/Convolution3x3Filter.hpp; sourceTree = ""; }; 3C0F8F051E968AF5007E34AF /* EmbossFilter.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; name = EmbossFilter.cpp; path = filter/EmbossFilter.cpp; sourceTree = ""; }; @@ -111,7 +119,7 @@ 3C5FF5E31E7055FE00BF0874 /* GLProgram.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; path = GLProgram.cpp; sourceTree = ""; }; 3C5FF5E41E7055FE00BF0874 /* GLProgram.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = GLProgram.hpp; sourceTree = ""; }; 3C5FF5E61E7055FE00BF0874 /* macros.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = macros.h; sourceTree = ""; }; - 3C5FF5E71E7055FE00BF0874 /* math.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; path = math.cpp; sourceTree = ""; }; + 3C5FF5E71E7055FE00BF0874 /* Vector2.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; path = Vector2.cpp; sourceTree = ""; }; 3C5FF5E81E7055FE00BF0874 /* math.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = math.hpp; sourceTree = ""; }; 3C5FF5E91E7055FE00BF0874 /* Ref.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; path = Ref.cpp; sourceTree = ""; }; 3C5FF5EA1E7055FE00BF0874 /* Ref.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Ref.hpp; sourceTree = ""; }; @@ -194,6 +202,11 @@ 3CFDD56E1D7AB2F500E37EA3 /* libGPUImage-x iOS.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libGPUImage-x iOS.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 3CFE65251E8C1A5400E7C5CF /* NonMaximumSuppressionFilter.cpp */ = {isa = PBXFileReference; explicitFileType = sourcecode.cpp.objcpp.preprocessed; fileEncoding = 4; name = NonMaximumSuppressionFilter.cpp; path = filter/NonMaximumSuppressionFilter.cpp; sourceTree = ""; }; 3CFE65261E8C1A5400E7C5CF /* NonMaximumSuppressionFilter.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = NonMaximumSuppressionFilter.hpp; path = filter/NonMaximumSuppressionFilter.hpp; sourceTree = ""; }; + F6A1C3762151BEBB001C1ADD /* Vector2.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = Vector2.hpp; path = ../../../../src/Math/Vector2.hpp; sourceTree = ""; }; + F6A1C3772151BFAB001C1ADD /* Matrix3.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Matrix3.cpp; sourceTree = ""; }; + F6A1C3782151BFAB001C1ADD /* Matrix3.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Matrix3.hpp; sourceTree = ""; }; + F6A1C37A2151C1A1001C1ADD /* Matrix4.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = Matrix4.cpp; sourceTree = ""; }; + F6A1C37B2151C1A1001C1ADD /* Matrix4.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = Matrix4.hpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -209,6 +222,23 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 1A71D25021502A7500ADDA5A /* math */ = { + isa = PBXGroup; + children = ( + F6A1C3772151BFAB001C1ADD /* Matrix3.cpp */, + F6A1C3782151BFAB001C1ADD /* Matrix3.hpp */, + F6A1C37A2151C1A1001C1ADD /* Matrix4.cpp */, + F6A1C37B2151C1A1001C1ADD /* Matrix4.hpp */, + 3C5FF5E71E7055FE00BF0874 /* Vector2.cpp */, + F6A1C3762151BEBB001C1ADD /* Vector2.hpp */, + 1A71D25121502A8B00ADDA5A /* Vector3.cpp */, + 1A71D25221502A8B00ADDA5A /* Vector3.hpp */, + 1A71D25521502D1500ADDA5A /* Vector4.cpp */, + 1A71D25421502D1500ADDA5A /* Vector4.hpp */, + ); + path = math; + sourceTree = ""; + }; 3C50030A1E7ADC58006A49F9 /* iOS */ = { isa = PBXGroup; children = ( @@ -364,6 +394,7 @@ 3C938F991E74391D00EE753C /* target */, 3C938F8C1E74358A00EE753C /* source */, 3C938F5B1E74356F00EE753C /* filter */, + 1A71D25021502A7500ADDA5A /* math */, 3C5FF5DC1E7055FE00BF0874 /* Context.cpp */, 3C5FF5DD1E7055FE00BF0874 /* Context.hpp */, 3C5FF5DF1E7055FE00BF0874 /* Framebuffer.cpp */, @@ -373,7 +404,6 @@ 3C5FF5E31E7055FE00BF0874 /* GLProgram.cpp */, 3C5FF5E41E7055FE00BF0874 /* GLProgram.hpp */, 3C5FF5E61E7055FE00BF0874 /* macros.h */, - 3C5FF5E71E7055FE00BF0874 /* math.cpp */, 3C5FF5E81E7055FE00BF0874 /* math.hpp */, 3C5FF5E91E7055FE00BF0874 /* Ref.cpp */, 3C5FF5EA1E7055FE00BF0874 /* Ref.hpp */, @@ -440,6 +470,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( + F6A1C3792151BFAB001C1ADD /* Matrix3.cpp in Sources */, 3C938F961E74391000EE753C /* Source.hpp in Sources */, 3CA677A91E86DC5300295EEC /* SketchFilter.cpp in Sources */, 3C4151641E8D45FE00ED6F6D /* SingleComponentGaussianBlurMonoFilter.cpp in Sources */, @@ -470,10 +501,12 @@ 3C5003121E7ADCCD006A49F9 /* GPUImageView.mm in Sources */, 3CA677BC1E88082900295EEC /* RGBFilter.cpp in Sources */, 3C5FF5F11E7055FE00BF0874 /* FramebufferCache.cpp in Sources */, + 1A71D25321502A8B00ADDA5A /* Vector3.cpp in Sources */, 3C5FF5F51E7055FE00BF0874 /* Ref.cpp in Sources */, 3C938F9F1E74392E00EE753C /* Target.cpp in Sources */, 3C0F8F071E968AF5007E34AF /* EmbossFilter.cpp in Sources */, 3CAE3C3D1EA8F7D800757974 /* GlassSphereFilter.cpp in Sources */, + 1A71D25621502D1600ADDA5A /* Vector4.cpp in Sources */, 3C938F811E74357C00EE753C /* ColorMatrixFilter.cpp in Sources */, 3C938F821E74357C00EE753C /* DirectionalNonMaximumSuppressionFilter.cpp in Sources */, 3C5FF5F01E7055FE00BF0874 /* Framebuffer.cpp in Sources */, @@ -483,11 +516,12 @@ 3C5003131E7ADCCD006A49F9 /* IOSTarget.cpp in Sources */, 3C74D76C1EA121300074FEF5 /* CrosshatchFilter.cpp in Sources */, 3C938F891E74357C00EE753C /* HSBFilter.cpp in Sources */, - 3C5FF5F41E7055FE00BF0874 /* math.cpp in Sources */, + 3C5FF5F41E7055FE00BF0874 /* Vector2.cpp in Sources */, 3C21FAD01E8A9719007DFE11 /* PosterizeFilter.cpp in Sources */, 3CA677B61E88034100295EEC /* ContrastFilter.cpp in Sources */, 3CA677B01E8769A900295EEC /* PixellationFilter.cpp in Sources */, 3C21FAD31E8A9D47007DFE11 /* LuminanceRangeFilter.cpp in Sources */, + F6A1C37C2151C1A1001C1ADD /* Matrix4.cpp in Sources */, 3CA677AD1E86DF8E00295EEC /* ToonFilter.cpp in Sources */, 3CC8ECF61E894FA300ADD376 /* SmoothToonFilter.cpp in Sources */, 3C5FF5F61E7055FE00BF0874 /* util.cpp in Sources */, @@ -602,6 +636,7 @@ OTHER_LDFLAGS = "-ObjC"; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + STRIP_INSTALLED_PRODUCT = NO; }; name = Debug; }; diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.pbxproj b/ios/sample/GPUImage-x-Sample.xcodeproj/project.pbxproj similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample.xcodeproj/project.pbxproj rename to ios/sample/GPUImage-x-Sample.xcodeproj/project.pbxproj diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/AppDelegate.h b/ios/sample/GPUImage-x-Sample/AppDelegate.h similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/AppDelegate.h rename to ios/sample/GPUImage-x-Sample/AppDelegate.h diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/AppDelegate.m b/ios/sample/GPUImage-x-Sample/AppDelegate.m similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/AppDelegate.m rename to ios/sample/GPUImage-x-Sample/AppDelegate.m diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/Contents.json b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/Contents.json similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/Contents.json rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/Contents.json diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120-1.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120-1.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120-1.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120-1.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_120.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_180.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_180.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_180.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_180.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_40.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_40.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_40.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_40.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_58.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_58.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_58.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_58.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_60.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_60.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_60.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_60.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_80.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_80.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_80.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_80.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_87.png b/ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_87.png similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_87.png rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/AppIcon.appiconset/icon_87.png diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/Contents.json b/ios/sample/GPUImage-x-Sample/Assets.xcassets/Contents.json similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/Contents.json rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/Contents.json diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/Contents.json b/ios/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/Contents.json similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/Contents.json rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/Contents.json diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/test.jpg b/ios/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/test.jpg similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/test.jpg rename to ios/sample/GPUImage-x-Sample/Assets.xcassets/test.imageset/test.jpg diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/CameraSampleViewController.h b/ios/sample/GPUImage-x-Sample/CameraSampleViewController.h similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/CameraSampleViewController.h rename to ios/sample/GPUImage-x-Sample/CameraSampleViewController.h diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/CameraSampleViewController.mm b/ios/sample/GPUImage-x-Sample/CameraSampleViewController.mm similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/CameraSampleViewController.mm rename to ios/sample/GPUImage-x-Sample/CameraSampleViewController.mm diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterHelper.h b/ios/sample/GPUImage-x-Sample/FilterHelper.h similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterHelper.h rename to ios/sample/GPUImage-x-Sample/FilterHelper.h diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterHelper.mm b/ios/sample/GPUImage-x-Sample/FilterHelper.mm similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterHelper.mm rename to ios/sample/GPUImage-x-Sample/FilterHelper.mm diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterListViewController.h b/ios/sample/GPUImage-x-Sample/FilterListViewController.h similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterListViewController.h rename to ios/sample/GPUImage-x-Sample/FilterListViewController.h diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterListViewController.mm b/ios/sample/GPUImage-x-Sample/FilterListViewController.mm similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/FilterListViewController.mm rename to ios/sample/GPUImage-x-Sample/FilterListViewController.mm diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/ImageSampleViewController.h b/ios/sample/GPUImage-x-Sample/ImageSampleViewController.h similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/ImageSampleViewController.h rename to ios/sample/GPUImage-x-Sample/ImageSampleViewController.h diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/ImageSampleViewController.mm b/ios/sample/GPUImage-x-Sample/ImageSampleViewController.mm similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/ImageSampleViewController.mm rename to ios/sample/GPUImage-x-Sample/ImageSampleViewController.mm diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Info.plist b/ios/sample/GPUImage-x-Sample/Info.plist similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/Info.plist rename to ios/sample/GPUImage-x-Sample/Info.plist diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/MenuViewController.h b/ios/sample/GPUImage-x-Sample/MenuViewController.h similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/MenuViewController.h rename to ios/sample/GPUImage-x-Sample/MenuViewController.h diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/MenuViewController.m b/ios/sample/GPUImage-x-Sample/MenuViewController.m similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/MenuViewController.m rename to ios/sample/GPUImage-x-Sample/MenuViewController.m diff --git a/GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/main.m b/ios/sample/GPUImage-x-Sample/main.m similarity index 100% rename from GPUImage-x/proj.iOS/sample/GPUImage-x-Sample/main.m rename to ios/sample/GPUImage-x-Sample/main.m diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Context.cpp b/src/Context.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Context.cpp rename to src/Context.cpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Context.hpp b/src/Context.hpp similarity index 98% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Context.hpp rename to src/Context.hpp index 1799dcf..d09ae7c 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/Context.hpp +++ b/src/Context.hpp @@ -59,7 +59,7 @@ class Context { // used for capturing a processed frame data bool isCapturingFrame; Filter* captureUpToFilter; - unsigned char* capturedFrameData; + uint8_t* capturedFrameData; int captureWidth; int captureHeight; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Framebuffer.cpp b/src/Framebuffer.cpp similarity index 97% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Framebuffer.cpp rename to src/Framebuffer.cpp index 3f8b15d..0a82649 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Framebuffer.cpp +++ b/src/Framebuffer.cpp @@ -33,7 +33,11 @@ TextureAttributes Framebuffer::defaultTextureAttribures = { .wrapS = GL_CLAMP_TO_EDGE, .wrapT = GL_CLAMP_TO_EDGE, .internalFormat = GL_RGBA, +#if PLATFORM == PLATFORM_IOS + .format = GL_BGRA, +#elif PLATFORM == PLATFORM_ANDROID .format = GL_RGBA, +#endif .type = GL_UNSIGNED_BYTE }; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Framebuffer.hpp b/src/Framebuffer.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Framebuffer.hpp rename to src/Framebuffer.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/FramebufferCache.cpp b/src/FramebufferCache.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/FramebufferCache.cpp rename to src/FramebufferCache.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/FramebufferCache.hpp b/src/FramebufferCache.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/FramebufferCache.hpp rename to src/FramebufferCache.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GLProgram.cpp b/src/GLProgram.cpp similarity index 86% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GLProgram.cpp rename to src/GLProgram.cpp index 9b58df4..511f061 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/GLProgram.cpp +++ b/src/GLProgram.cpp @@ -129,6 +129,16 @@ void GLProgram::setUniformValue(const std::string& uniformName, Vector2 value) { setUniformValue(getUniformLocation(uniformName), value); } +void GLProgram::setUniformValue(const std::string& uniformName, Vector3 value) { + Context::getInstance()->setActiveShaderProgram(this); + setUniformValue(getUniformLocation(uniformName), value); +} + +void GLProgram::setUniformValue(const std::string& uniformName, Vector4 value) { + Context::getInstance()->setActiveShaderProgram(this); + setUniformValue(getUniformLocation(uniformName), value); +} + void GLProgram::setUniformValue(const std::string& uniformName, Matrix3 value) { Context::getInstance()->setActiveShaderProgram(this); setUniformValue(getUniformLocation(uniformName), value); @@ -154,6 +164,16 @@ void GLProgram::setUniformValue(int uniformLocation, Vector2 value) { CHECK_GL(glUniform2f(uniformLocation, value.x, value.y)); } +void GLProgram::setUniformValue(int uniformLocation, Vector3 value) { + Context::getInstance()->setActiveShaderProgram(this); + CHECK_GL(glUniform3f(uniformLocation, value.x, value.y, value.z)); +} + +void GLProgram::setUniformValue(int uniformLocation, Vector4 value) { + Context::getInstance()->setActiveShaderProgram(this); + CHECK_GL(glUniform4f(uniformLocation, value.x, value.y, value.z, value.w)); +} + void GLProgram::setUniformValue(int uniformLocation, Matrix3 value) { Context::getInstance()->setActiveShaderProgram(this); CHECK_GL(glUniformMatrix3fv(uniformLocation, 1, GL_FALSE, (GLfloat *)&value)); diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GLProgram.hpp b/src/GLProgram.hpp similarity index 88% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GLProgram.hpp rename to src/GLProgram.hpp index dcf24a6..5a1e255 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GLProgram.hpp +++ b/src/GLProgram.hpp @@ -20,7 +20,8 @@ #define Shader_hpp #include "macros.h" -#include "string" +#include "math.hpp" + #if PLATFORM == PLATFORM_ANDROID #include #include @@ -28,8 +29,9 @@ #import #import #endif + +#include #include -#include "math.hpp" NS_GI_BEGIN @@ -48,12 +50,16 @@ class GLProgram{ void setUniformValue(const std::string& uniformName, int value); void setUniformValue(const std::string& uniformName, float value); void setUniformValue(const std::string& uniformName, Vector2 value); + void setUniformValue(const std::string& uniformName, Vector3 value); + void setUniformValue(const std::string& uniformName, Vector4 value); void setUniformValue(const std::string& uniformName, Matrix3 value); void setUniformValue(const std::string& uniformName, Matrix4 value); void setUniformValue(int uniformLocation, int value); void setUniformValue(int uniformLocation, float value); void setUniformValue(int uniformLocation, Vector2 value); + void setUniformValue(int uniformLocation, Vector3 value); + void setUniformValue(int uniformLocation, Vector4 value); void setUniformValue(int uniformLocation, Matrix3 value); void setUniformValue(int uniformLocation, Matrix4 value); @@ -63,7 +69,6 @@ class GLProgram{ bool _initWithShaderString(const std::string& vertexShaderSource, const std::string& fragmentShaderSource); }; - NS_GI_END #endif /* GLProgram_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GPUImage-x.h b/src/GPUImage-x.h similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GPUImage-x.h rename to src/GPUImage-x.h diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GPUImagexJNI.cpp b/src/GPUImagexJNI.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/GPUImagexJNI.cpp rename to src/GPUImagexJNI.cpp diff --git a/src/Math/Vector3.cpp b/src/Math/Vector3.cpp new file mode 100644 index 0000000..5acd974 --- /dev/null +++ b/src/Math/Vector3.cpp @@ -0,0 +1,226 @@ +// +// Vector3.cpp +// GPUImage-x iOS +// +// Created by James Perlman on 9/17/18. +// Copyright © 2018 Jin. All rights reserved. +// + +#include "Vector3.hpp" + +USING_NS_GI + +Vector3::Vector3() +: x(0.0f), y(0.0f), z(0.0f) +{ +} + +Vector3::Vector3(float xx, float yy, float zz) +: x(xx), y(yy), z(zz) +{ +} + +Vector3::Vector3(const float* array) +{ + set(array); +} + +Vector3::Vector3(const Vector3& p1, const Vector3& p2) +{ + set(p1, p2); +} + +Vector3::Vector3(const Vector3& copy) +{ + set(copy); +} + +Vector3::~Vector3() +{ +} + +bool Vector3::isZero() const +{ + return x == 0.0f && y == 0.0f && z == 0.0f; +} + +bool Vector3::isOne() const +{ + return x == 1.0f && y == 1.0f && z == 1.0f; +} + +void Vector3::add(const Vector3& v) +{ + x += v.x; + y += v.y; + z += v.z; +} + +float Vector3::distanceSquared(const Vector3& v) const +{ + float dx = v.x - x; + float dy = v.y - y; + float dz = v.z - z; + return (dx * dx + dy * dy + dz * dz); +} + +float Vector3::dot(const Vector3& v) const +{ + return (x * v.x + y * v.y + z * v.z); +} + +float Vector3::lengthSquared() const +{ + return (x * x + y * y + z * z); +} + +void Vector3::negate() +{ + x = -x; + y = -y; + z = -z; +} + +void Vector3::scale(float scalar) +{ + x *= scalar; + y *= scalar; + z *= scalar; +} + +void Vector3::scale(const Vector3& scale) +{ + x *= scale.x; + y *= scale.y; + z *= scale.z; +} + +void Vector3::set(float xx, float yy, float zz) +{ + this->x = xx; + this->y = yy; + this->z = zz; +} + +void Vector3::set(const Vector3& v) +{ + this->x = v.x; + this->y = v.y; + this->z = v.z; +} + +void Vector3::set(const Vector3& p1, const Vector3& p2) +{ + x = p2.x - p1.x; + y = p2.y - p1.y; +} + +void Vector3::setZero() +{ + x = y = z = 0.0f; +} + +void Vector3::subtract(const Vector3& v) +{ + x -= v.x; + y -= v.y; + z -= v.z; +} + +void Vector3::smooth(const Vector3& target, float elapsedTime, float responseTime) +{ + if (elapsedTime > 0) + { + *this += (target - *this) * (elapsedTime / (elapsedTime + responseTime)); + } +} + +const Vector3 Vector3::operator+(const Vector3& v) const +{ + Vector3 result(*this); + result.add(v); + return result; +} + +Vector3& Vector3::operator+=(const Vector3& v) +{ + add(v); + return *this; +} + +const Vector3 Vector3::operator-(const Vector3& v) const +{ + Vector3 result(*this); + result.subtract(v); + return result; +} + +Vector3& Vector3::operator-=(const Vector3& v) +{ + subtract(v); + return *this; +} + +const Vector3 Vector3::operator-() const +{ + Vector3 result(*this); + result.negate(); + return result; +} + +const Vector3 Vector3::operator*(float s) const +{ + Vector3 result(*this); + result.scale(s); + return result; +} + +Vector3& Vector3::operator*=(float s) +{ + scale(s); + return *this; +} + +const Vector3 Vector3::operator/(const float s) const +{ + return Vector3(this->x / s, this->y / s, this->z / s); +} + +bool Vector3::operator<(const Vector3& v) const +{ + if (x == v.x) { + if (y == v.y) { + return z < v.z; + } + return y < v.y; + } + return x < v.x; +} + +bool Vector3::operator>(const Vector3& v) const +{ + if (x == v.x) { + if (y == v.y) { + return z > v.z; + } + return y > v.y; + } + return x > v.x; +} + +bool Vector3::operator==(const Vector3& v) const +{ + return x==v.x && y==v.y && z==v.z; +} + +bool Vector3::operator!=(const Vector3& v) const +{ + return x!=v.x || y!=v.y || z!=v.z; +} + +const Vector3 operator*(float x, const Vector3& v) +{ + Vector3 result(v); + result.scale(x); + return result; +} diff --git a/src/Math/Vector3.hpp b/src/Math/Vector3.hpp new file mode 100644 index 0000000..cb7fafc --- /dev/null +++ b/src/Math/Vector3.hpp @@ -0,0 +1,71 @@ +// +// Vector3.hpp +// GPUImage-x iOS +// +// Created by James Perlman on 9/17/18. +// Copyright © 2018 Jin. All rights reserved. +// + +#ifndef Vector3_hpp +#define Vector3_hpp + +#include "../macros.h" + +NS_GI_BEGIN + +class Vector3 { +public: + float x; + float y; + float z; + + Vector3(); + Vector3(float xx, float yy, float zz); + Vector3(const float* array); + Vector3(const Vector3& p1, const Vector3& p2); + Vector3(const Vector3& copy); + ~Vector3(); + + bool isZero() const; + bool isOne() const; + static float angle(const Vector3& v1, const Vector3& v2); + void add(const Vector3& v); + static void add(const Vector3& v1, const Vector3& v2, Vector3* dst); + void clamp(const Vector3& min, const Vector3& max); + static void clamp(const Vector3& v, const Vector3& min, const Vector3& max, Vector3* dst); + float distance(const Vector3& v) const; + float distanceSquared(const Vector3& v) const; + float dot(const Vector3& v) const; + static float dot(const Vector3& v1, const Vector3& v2); + float length() const; + float lengthSquared() const; + void negate(); + void normalize(); + Vector3 getNormalized() const; + void scale(float scalar); + void scale(const Vector3& scale); + void rotate(const Vector3& point, float angle); + void set(float xx, float yy, float zz); + void set(const Vector3& v); + void set(const Vector3& p1, const Vector3& p2); + void setZero(); + void subtract(const Vector3& v); + static void subtract(const Vector3& v1, const Vector3& v2, Vector3* dst); + void smooth(const Vector3& target, float elapsedTime, float responseTime); + const Vector3 operator+(const Vector3& v) const; + Vector3& operator+=(const Vector3& v); + const Vector3 operator-(const Vector3& v) const; + Vector3& operator-=(const Vector3& v); + const Vector3 operator-() const; + const Vector3 operator*(float s) const; + Vector3& operator*=(float s); + const Vector3 operator/(float s) const; + bool operator<(const Vector3& v) const; + bool operator>(const Vector3& v) const; + bool operator==(const Vector3& v) const; + bool operator!=(const Vector3& v) const; +}; + +NS_GI_END + +#endif /* Vector3_hpp */ diff --git a/src/Math/Vector4.cpp b/src/Math/Vector4.cpp new file mode 100644 index 0000000..7d4e219 --- /dev/null +++ b/src/Math/Vector4.cpp @@ -0,0 +1,241 @@ +// +// Vector4.cpp +// Rectomatic +// +// Created by James Perlman on 8/30/18. +// + +#include "Vector4.hpp" + +USING_NS_GI + +Vector4::Vector4() +: x(0.0f), y(0.0f), z(0.0f), w(0.0f) +{ +} + +Vector4::Vector4(float xx, float yy, float zz, float ww) +: x(xx), y(yy), z(zz), w(ww) +{ +} + +Vector4::Vector4(const float* array) +{ + set(array); +} + +Vector4::Vector4(const Vector4& p1, const Vector4& p2) +{ + set(p1, p2); +} + +Vector4::Vector4(const Vector4& copy) +{ + set(copy); +} + +Vector4::~Vector4() +{ +} + +bool Vector4::isZero() const +{ + return x == 0.0f && y == 0.0f && z == 0.0f && w == 0.0f; +} + +bool Vector4::isOne() const +{ + return x == 1.0f && y == 1.0f && z == 0.0f && w == 0.0f; +} + +void Vector4::add(const Vector4& v) +{ + x += v.x; + y += v.y; + z += v.z; + w += v.w; +} + +float Vector4::distanceSquared(const Vector4& v) const +{ + float dx = v.x - x; + float dy = v.y - y; + float dz = v.z - z; + float dw = v.w - w; + return (dx * dx + dy * dy + dz * dz + dw * dw); +} + +float Vector4::dot(const Vector4& v) const +{ + return (x * v.x + y * v.y + z * v.z + w * v.w); +} + +float Vector4::lengthSquared() const +{ + return (x * x + y * y + z * z + w * w); +} + +void Vector4::negate() +{ + x = -x; + y = -y; + z = -z; + w = -w; +} + +void Vector4::scale(float scalar) +{ + x *= scalar; + y *= scalar; + z *= scalar; + w *= scalar; +} + +void Vector4::scale(const Vector4& scale) +{ + x *= scale.x; + y *= scale.y; + z *= scale.z; + w *= scale.w; +} + +void Vector4::set(float xx, float yy, float zz, float ww) +{ + this->x = xx; + this->y = yy; + this->z = zz; + this->w = ww; +} + +void Vector4::set(const Vector4& v) +{ + this->x = v.x; + this->y = v.y; + this->z = v.z; + this->w = v.w; +} + +void Vector4::set(const Vector4& p1, const Vector4& p2) +{ + x = p2.x - p1.x; + y = p2.y - p1.y; + z = p2.z - p1.z; + w = p2.w - p1.w; +} + +void Vector4::setZero() +{ + x = y = z = w = 0.0f; +} + +void Vector4::subtract(const Vector4& v) +{ + x -= v.x; + y -= v.y; + z -= v.z; + w -= v.w; +} + +void Vector4::smooth(const Vector4& target, float elapsedTime, float responseTime) +{ + if (elapsedTime > 0) + { + *this += (target - *this) * (elapsedTime / (elapsedTime + responseTime)); + } +} + +const Vector4 Vector4::operator+(const Vector4& v) const +{ + Vector4 result(*this); + result.add(v); + return result; +} + +Vector4& Vector4::operator+=(const Vector4& v) +{ + add(v); + return *this; +} + +const Vector4 Vector4::operator-(const Vector4& v) const +{ + Vector4 result(*this); + result.subtract(v); + return result; +} + +Vector4& Vector4::operator-=(const Vector4& v) +{ + subtract(v); + return *this; +} + +const Vector4 Vector4::operator-() const +{ + Vector4 result(*this); + result.negate(); + return result; +} + +const Vector4 Vector4::operator*(float s) const +{ + Vector4 result(*this); + result.scale(s); + return result; +} + +Vector4& Vector4::operator*=(float s) +{ + scale(s); + return *this; +} + +const Vector4 Vector4::operator/(const float s) const +{ + return Vector4(this->x / s, this->y / s, this->z / s, this->w / s); +} + +bool Vector4::operator<(const Vector4& v) const +{ + if (x == v.x) { + if (y == v.y) { + if (z == v.z) { + return w < v.w; + } + return z < v.z; + } + return y < v.y; + } + return x < v.x; +} + +bool Vector4::operator>(const Vector4& v) const +{ + if (x == v.x) { + if (y == v.y) { + if (z == v.z) { + return w < v.w; + } + return z > v.z; + } + return y > v.y; + } + return x > v.x; +} + +bool Vector4::operator==(const Vector4& v) const +{ + return x == v.x && y == v.y && z == v.z && w == v.w; +} + +bool Vector4::operator!=(const Vector4& v) const +{ + return x != v.x || y != v.y || z != v.z || w != v.w; +} + +const Vector4 operator*(float x, const Vector4& v) +{ + Vector4 result(v); + result.scale(x); + return result; +} diff --git a/src/Math/Vector4.hpp b/src/Math/Vector4.hpp new file mode 100644 index 0000000..9718d44 --- /dev/null +++ b/src/Math/Vector4.hpp @@ -0,0 +1,74 @@ +// +// Vector4.hpp +// Rectomatic +// +// Created by James Perlman on 8/30/18. +// Copyright © 2018 Lottery.com. All rights reserved. +// + +#ifndef Vector4_hpp +#define Vector4_hpp + +#include "../macros.h" + +NS_GI_BEGIN + +class Vector4 +{ +public: + + float x; + float y; + float z; + float w; + + Vector4(); + Vector4(float xx, float yy, float zz, float ww); + Vector4(const float* array); + Vector4(const Vector4& p1, const Vector4& p2); + Vector4(const Vector4& copy); + ~Vector4(); + + bool isZero() const; + bool isOne() const; + static float angle(const Vector4& v1, const Vector4& v2); + void add(const Vector4& v); + static void add(const Vector4& v1, const Vector4& v2, Vector4* dst); + void clamp(const Vector4& min, const Vector4& max); + static void clamp(const Vector4& v, const Vector4& min, const Vector4& max, Vector4* dst); + float distance(const Vector4& v) const; + float distanceSquared(const Vector4& v) const; + float dot(const Vector4& v) const; + static float dot(const Vector4& v1, const Vector4& v2); + float length() const; + float lengthSquared() const; + void negate(); + void normalize(); + Vector4 getNormalized() const; + void scale(float scalar); + void scale(const Vector4& scale); + void rotate(const Vector4& point, float angle); + void set(float xx, float yy, float zz, float ww); + void set(const Vector4& v); + void set(const Vector4& p1, const Vector4& p2); + void setZero(); + void subtract(const Vector4& v); + static void subtract(const Vector4& v1, const Vector4& v2, Vector4* dst); + void smooth(const Vector4& target, float elapsedTime, float responseTime); + const Vector4 operator+(const Vector4& v) const; + Vector4& operator+=(const Vector4& v); + const Vector4 operator-(const Vector4& v) const; + Vector4& operator-=(const Vector4& v); + const Vector4 operator-() const; + const Vector4 operator*(float s) const; + Vector4& operator*=(float s); + const Vector4 operator/(float s) const; + bool operator<(const Vector4& v) const; + bool operator>(const Vector4& v) const; + bool operator==(const Vector4& v) const; + bool operator!=(const Vector4& v) const; +}; + +NS_GI_END + +#endif /* Vector4_hpp */ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Ref.cpp b/src/Ref.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Ref.cpp rename to src/Ref.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Ref.hpp b/src/Ref.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/Ref.hpp rename to src/Ref.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BeautifyFilter.cpp b/src/filter/BeautifyFilter.cpp similarity index 96% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BeautifyFilter.cpp rename to src/filter/BeautifyFilter.cpp index cc90f94..d39c5d9 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BeautifyFilter.cpp +++ b/src/filter/BeautifyFilter.cpp @@ -97,6 +97,8 @@ class CombinationFilter : public Filter { REGISTER_FILTER_CLASS(BeautifyFilter) +DEFINE_FILTER_CREATE_METHOD(BeautifyFilter) + BeautifyFilter::BeautifyFilter() :_bilateralFilter(0) ,_cannyEdgeDetectionFilter(0) @@ -124,15 +126,6 @@ BeautifyFilter::~BeautifyFilter() { } } -BeautifyFilter* BeautifyFilter::create() { - BeautifyFilter* ret = new (std::nothrow) BeautifyFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool BeautifyFilter::init() { if (!FilterGroup::init()) { return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BeautifyFilter.hpp b/src/filter/BeautifyFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BeautifyFilter.hpp rename to src/filter/BeautifyFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BilateralFilter.cpp b/src/filter/BilateralFilter.cpp similarity index 97% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BilateralFilter.cpp rename to src/filter/BilateralFilter.cpp index b1e990e..6b4b6ef 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BilateralFilter.cpp +++ b/src/filter/BilateralFilter.cpp @@ -182,6 +182,8 @@ void BilateralMonoFilter::setDistanceNormalizationFactor(float value) { REGISTER_FILTER_CLASS(BilateralFilter) +DEFINE_FILTER_CREATE_METHOD(BilateralFilter) + BilateralFilter::BilateralFilter() :_hBlurFilter(0) ,_vBlurFilter(0) @@ -201,15 +203,6 @@ BilateralFilter::~BilateralFilter() { } -BilateralFilter* BilateralFilter::create() { - BilateralFilter* ret = new (std::nothrow) BilateralFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool BilateralFilter::init() { if (!FilterGroup::init()) { return false; diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BilateralFilter.hpp b/src/filter/BilateralFilter.hpp similarity index 96% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BilateralFilter.hpp rename to src/filter/BilateralFilter.hpp index f2bb7d9..5ec6051 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/BilateralFilter.hpp +++ b/src/filter/BilateralFilter.hpp @@ -29,7 +29,7 @@ class BilateralMonoFilter : public Filter { public: enum Type {HORIZONTAL, VERTICAL}; - static BilateralMonoFilter* create(Type type = HORIZONTAL); + static BilateralMonoFilter* create(Type type = VERTICAL); bool init(); virtual bool proceed(bool bUpdateTargets = true) override; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BrightnessFilter.cpp b/src/filter/BrightnessFilter.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BrightnessFilter.cpp rename to src/filter/BrightnessFilter.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BrightnessFilter.hpp b/src/filter/BrightnessFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/BrightnessFilter.hpp rename to src/filter/BrightnessFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CannyEdgeDetectionFilter.cpp b/src/filter/CannyEdgeDetectionFilter.cpp similarity index 70% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CannyEdgeDetectionFilter.cpp rename to src/filter/CannyEdgeDetectionFilter.cpp index 09e6dff..81aa578 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CannyEdgeDetectionFilter.cpp +++ b/src/filter/CannyEdgeDetectionFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(CannyEdgeDetectionFilter) +DEFINE_FILTER_CREATE_METHOD(CannyEdgeDetectionFilter) + CannyEdgeDetectionFilter::CannyEdgeDetectionFilter() :_grayscaleFilter(0) ,_blurFilter(0) @@ -54,15 +56,6 @@ CannyEdgeDetectionFilter::~CannyEdgeDetectionFilter() { } } -CannyEdgeDetectionFilter* CannyEdgeDetectionFilter::create() { - CannyEdgeDetectionFilter* ret = new (std::nothrow) CannyEdgeDetectionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool CannyEdgeDetectionFilter::init() { if (!FilterGroup::init()) { return false; @@ -83,12 +76,41 @@ bool CannyEdgeDetectionFilter::init() { // 5. include weak pixels to complete edges _weakPixelInclusionFilter = WeakPixelInclusionFilter::create(); - _grayscaleFilter->addTarget(_blurFilter)->addTarget(_edgeDetectionFilter)->addTarget(_nonMaximumSuppressionFilter)->addTarget(_weakPixelInclusionFilter); addFilter(_grayscaleFilter); + + setTerminalFilter(_weakPixelInclusionFilter); return true; } +/** + Getters and setters for various filter props + */ +/* +int CannyEdgeDetectionFilter::getBlurRadiusInPixels() { + return _blurFilter->getRadius(); +} +void CannyEdgeDetectionFilter::setBlurRadiusInPixels(int newValue) { + _blurFilter->setRadius(newValue); +} + +float CannyEdgeDetectionFilter::getBlurTexelSpacingMultiplier() { + return _edgeDetectionFilter->_texelSizeMultiplier +} +void CannyEdgeDetectionFilter::setBlurTexelSpacingMultiplier(float newValue); + +float CannyEdgeDetectionFilter::getTexelWidth(); +void CannyEdgeDetectionFilter::setTexelWidth(float newValue); + +float CannyEdgeDetectionFilter::getTexelHeight(); +void CannyEdgeDetectionFilter::setTexelHeight(float newValue); + +float CannyEdgeDetectionFilter::getUpperThreshold(); +void CannyEdgeDetectionFilter::setUpperThreshold(float newValue); + +float CannyEdgeDetectionFilter::getLowerThreshold(); +void CannyEdgeDetectionFilter::setLowerThreshold(float newValue); +*/ NS_GI_END diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CannyEdgeDetectionFilter.hpp b/src/filter/CannyEdgeDetectionFilter.hpp similarity index 75% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CannyEdgeDetectionFilter.hpp rename to src/filter/CannyEdgeDetectionFilter.hpp index 3fbca0a..02e6304 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/CannyEdgeDetectionFilter.hpp +++ b/src/filter/CannyEdgeDetectionFilter.hpp @@ -33,7 +33,25 @@ class CannyEdgeDetectionFilter : public FilterGroup { public: static CannyEdgeDetectionFilter* create(); bool init(); + /* + float getBlurRadiusInPixels(); + void setBlurRadiusInPixels(float newValue); + float getBlurTexelSpacingMultiplier(); + void setBlurTexelSpacingMultiplier(float newValue); + + float getTexelWidth(); + void setTexelWidth(float newValue); + + float getTexelHeight(); + void setTexelHeight(float newValue); + + float getUpperThreshold(); + void setUpperThreshold(float newValue); + + float getLowerThreshold(); + void setLowerThreshold(float newValue); + */ protected: CannyEdgeDetectionFilter(); ~CannyEdgeDetectionFilter(); diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorInvertFilter.cpp b/src/filter/ColorInvertFilter.cpp similarity index 85% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorInvertFilter.cpp rename to src/filter/ColorInvertFilter.cpp index 40333b7..803d540 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorInvertFilter.cpp +++ b/src/filter/ColorInvertFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(ColorInvertFilter) +DEFINE_FILTER_CREATE_METHOD(ColorInvertFilter) + const std::string kColorInvertFragmentShaderString = SHADER_STRING ( @@ -35,16 +37,6 @@ const std::string kColorInvertFragmentShaderString = SHADER_STRING } ); - -ColorInvertFilter* ColorInvertFilter::create() { - ColorInvertFilter* ret = new (std::nothrow) ColorInvertFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool ColorInvertFilter::init() { if (!Filter::initWithFragmentShaderString(kColorInvertFragmentShaderString)) return false; return true; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorInvertFilter.hpp b/src/filter/ColorInvertFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorInvertFilter.hpp rename to src/filter/ColorInvertFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorMatrixFilter.cpp b/src/filter/ColorMatrixFilter.cpp similarity index 91% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorMatrixFilter.cpp rename to src/filter/ColorMatrixFilter.cpp index 0f9ba81..0f6f68c 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ColorMatrixFilter.cpp +++ b/src/filter/ColorMatrixFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(ColorMatrixFilter) +DEFINE_FILTER_CREATE_METHOD(ColorMatrixFilter) + const std::string kColorMatrixFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -51,7 +53,7 @@ const std::string kBrightnessFragmentShaderString = SHADER_STRING lowp vec4 color = texture2D(colorMap, vTexCoord); gl_FragColor = vec4((color.rgb + vec3(brightness)), color.w); } - ); +); ColorMatrixFilter::ColorMatrixFilter() :_intensity(1.0) @@ -60,15 +62,6 @@ ColorMatrixFilter::ColorMatrixFilter() } -ColorMatrixFilter* ColorMatrixFilter::create() { - ColorMatrixFilter* ret = new (std::nothrow) ColorMatrixFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool ColorMatrixFilter::init() { if ( !Filter::initWithFragmentShaderString(kColorMatrixFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorMatrixFilter.hpp b/src/filter/ColorMatrixFilter.hpp similarity index 98% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorMatrixFilter.hpp rename to src/filter/ColorMatrixFilter.hpp index fe3e123..db19742 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ColorMatrixFilter.hpp +++ b/src/filter/ColorMatrixFilter.hpp @@ -21,7 +21,6 @@ #include "../macros.h" #include "Filter.hpp" -#include "../math.hpp" NS_GI_BEGIN diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ContrastFilter.cpp b/src/filter/ContrastFilter.cpp similarity index 89% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ContrastFilter.cpp rename to src/filter/ContrastFilter.cpp index 07f6668..83815ad 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ContrastFilter.cpp +++ b/src/filter/ContrastFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(ContrastFilter) +DEFINE_FILTER_CREATE_METHOD(ContrastFilter) + const std::string kContrastFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -35,16 +37,6 @@ const std::string kContrastFragmentShaderString = SHADER_STRING } ); - -ContrastFilter* ContrastFilter::create() { - ContrastFilter* ret = new (std::nothrow) ContrastFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool ContrastFilter::init() { if (!initWithFragmentShaderString(kContrastFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ContrastFilter.hpp b/src/filter/ContrastFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ContrastFilter.hpp rename to src/filter/ContrastFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Convolution3x3Filter.cpp b/src/filter/Convolution3x3Filter.cpp similarity index 99% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Convolution3x3Filter.cpp rename to src/filter/Convolution3x3Filter.cpp index b7bc1ff..76b36aa 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Convolution3x3Filter.cpp +++ b/src/filter/Convolution3x3Filter.cpp @@ -40,8 +40,6 @@ const std::string kConvolution3x3FragmentShaderString = SHADER_STRING varying vec2 vBottomLeftTexCoord; varying vec2 vBottomRightTexCoord; - - void main() { mediump vec3 bottomColor = texture2D(colorMap, vBottomTexCoord).rgb; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Convolution3x3Filter.hpp b/src/filter/Convolution3x3Filter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Convolution3x3Filter.hpp rename to src/filter/Convolution3x3Filter.hpp index c430453..8f7329d 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/Convolution3x3Filter.hpp +++ b/src/filter/Convolution3x3Filter.hpp @@ -20,8 +20,8 @@ #define Convolution3x3Filter_hpp #include "../macros.h" -#include "NearbySampling3x3Filter.hpp" #include "../math.hpp" +#include "NearbySampling3x3Filter.hpp" NS_GI_BEGIN diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CrosshatchFilter.cpp b/src/filter/CrosshatchFilter.cpp similarity index 93% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CrosshatchFilter.cpp rename to src/filter/CrosshatchFilter.cpp index 03caf16..f65a6f3 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CrosshatchFilter.cpp +++ b/src/filter/CrosshatchFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(CrosshatchFilter) +DEFINE_FILTER_CREATE_METHOD(CrosshatchFilter) + const std::string kCrosshatchFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -70,18 +72,6 @@ const std::string kCrosshatchFragmentShaderString = SHADER_STRING ); - - - -CrosshatchFilter* CrosshatchFilter::create() { - CrosshatchFilter* ret = new (std::nothrow) CrosshatchFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool CrosshatchFilter::init() { if (!initWithFragmentShaderString(kCrosshatchFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CrosshatchFilter.hpp b/src/filter/CrosshatchFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/CrosshatchFilter.hpp rename to src/filter/CrosshatchFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalNonMaximumSuppressionFilter.cpp b/src/filter/DirectionalNonMaximumSuppressionFilter.cpp similarity index 88% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalNonMaximumSuppressionFilter.cpp rename to src/filter/DirectionalNonMaximumSuppressionFilter.cpp index 485d2c5..fa5c0fd 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalNonMaximumSuppressionFilter.cpp +++ b/src/filter/DirectionalNonMaximumSuppressionFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(DirectionalNonMaximumSuppressionFilter) +DEFINE_FILTER_CREATE_METHOD(DirectionalNonMaximumSuppressionFilter) + const std::string kDirectionalNonmaximumSuppressionFragmentShaderString = SHADER_STRING ( precision mediump float; @@ -50,24 +52,14 @@ const std::string kDirectionalNonmaximumSuppressionFragmentShaderString = SHADER gl_FragColor = vec4(multiplier, multiplier, multiplier, 1.0); } - ); - - -DirectionalNonMaximumSuppressionFilter* DirectionalNonMaximumSuppressionFilter::create() { - DirectionalNonMaximumSuppressionFilter* ret = new (std::nothrow) DirectionalNonMaximumSuppressionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool DirectionalNonMaximumSuppressionFilter::init() { if (initWithFragmentShaderString(kDirectionalNonmaximumSuppressionFragmentShaderString)) { _texelWidthUniform = _filterProgram->getUniformLocation("texelWidth"); - _texelHeightUniform = _filterProgram->getUniformLocation("texelWidth"); + _texelHeightUniform = _filterProgram->getUniformLocation("texelHeight"); - _filterProgram->setUniformValue("upperThreshold", (float)0.5); + _filterProgram->setUniformValue("upperThreshold", (float)0.4); _filterProgram->setUniformValue("lowerThreshold", (float)0.1); return true; @@ -80,7 +72,6 @@ bool DirectionalNonMaximumSuppressionFilter::proceed(bool bUpdateTargets/* = tru float texelWidth = 1.0 / _framebuffer->getWidth(); float texelHeight = 1.0 / _framebuffer->getHeight(); - Framebuffer* inputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; if (rotationSwapsSize(inputRotation)){ diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalNonMaximumSuppressionFilter.hpp b/src/filter/DirectionalNonMaximumSuppressionFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalNonMaximumSuppressionFilter.hpp rename to src/filter/DirectionalNonMaximumSuppressionFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalSobelEdgeDetectionFilter.cpp b/src/filter/DirectionalSobelEdgeDetectionFilter.cpp similarity index 90% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalSobelEdgeDetectionFilter.cpp rename to src/filter/DirectionalSobelEdgeDetectionFilter.cpp index c184cc4..d4dba82 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/DirectionalSobelEdgeDetectionFilter.cpp +++ b/src/filter/DirectionalSobelEdgeDetectionFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(DirectionalSobelEdgeDetectionFilter) +DEFINE_FILTER_CREATE_METHOD(DirectionalSobelEdgeDetectionFilter) + const std::string kDirectionalSobelEdgeDetectionFragmentShaderString = SHADER_STRING ( precision mediump float; @@ -62,17 +64,7 @@ const std::string kDirectionalSobelEdgeDetectionFragmentShaderString = SHADER_ST gl_FragColor = vec4(gradientMagnitude, normalizedDirection.x, normalizedDirection.y, 1.0); } - ); - - -DirectionalSobelEdgeDetectionFilter* DirectionalSobelEdgeDetectionFilter::create() { - DirectionalSobelEdgeDetectionFilter* ret = new (std::nothrow) DirectionalSobelEdgeDetectionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool DirectionalSobelEdgeDetectionFilter::init() { if (initWithFragmentShaderString(kDirectionalSobelEdgeDetectionFragmentShaderString)) { diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalSobelEdgeDetectionFilter.hpp b/src/filter/DirectionalSobelEdgeDetectionFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/DirectionalSobelEdgeDetectionFilter.hpp rename to src/filter/DirectionalSobelEdgeDetectionFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/EmbossFilter.cpp b/src/filter/EmbossFilter.cpp similarity index 88% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/EmbossFilter.cpp rename to src/filter/EmbossFilter.cpp index 7d3ee8e..b65fdbf 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/EmbossFilter.cpp +++ b/src/filter/EmbossFilter.cpp @@ -22,14 +22,7 @@ USING_NS_GI REGISTER_FILTER_CLASS(EmbossFilter) -EmbossFilter* EmbossFilter::create() { - EmbossFilter* ret = new (std::nothrow) EmbossFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +DEFINE_FILTER_CREATE_METHOD(EmbossFilter) bool EmbossFilter::init() { if (!Convolution3x3Filter::init()) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/EmbossFilter.hpp b/src/filter/EmbossFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/EmbossFilter.hpp rename to src/filter/EmbossFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ExposureFilter.cpp b/src/filter/ExposureFilter.cpp similarity index 89% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ExposureFilter.cpp rename to src/filter/ExposureFilter.cpp index 58c7cc9..51cbba8 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ExposureFilter.cpp +++ b/src/filter/ExposureFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(ExposureFilter) +DEFINE_FILTER_CREATE_METHOD(ExposureFilter) + const std::string kExposureFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -35,16 +37,6 @@ const std::string kExposureFragmentShaderString = SHADER_STRING } ); - -ExposureFilter* ExposureFilter::create() { - ExposureFilter* ret = new (std::nothrow) ExposureFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool ExposureFilter::init() { if (!initWithFragmentShaderString(kExposureFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ExposureFilter.hpp b/src/filter/ExposureFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ExposureFilter.hpp rename to src/filter/ExposureFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Filter.cpp b/src/filter/Filter.cpp similarity index 94% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Filter.cpp rename to src/filter/Filter.cpp index ec2ef14..0184a46 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Filter.cpp +++ b/src/filter/Filter.cpp @@ -130,9 +130,12 @@ bool Filter::proceed(bool bUpdateTargets/* = true*/) { }; Context::getInstance()->setActiveShaderProgram(_filterProgram); + _framebuffer->active(); + CHECK_GL(glClearColor(_backgroundColor.r, _backgroundColor.g, _backgroundColor.b, _backgroundColor.a)); CHECK_GL(glClear(GL_COLOR_BUFFER_BIT)); + for (std::map::const_iterator it = _inputFramebuffers.begin(); it != _inputFramebuffers.end(); ++it) { int texIdx = it->first; Framebuffer* fb = it->second.frameBuffer; @@ -146,6 +149,7 @@ bool Filter::proceed(bool bUpdateTargets/* = true*/) { CHECK_GL(glEnableVertexAttribArray(filterTexCoordAttribute)); CHECK_GL(glVertexAttribPointer(filterTexCoordAttribute, 2, GL_FLOAT, 0, 0, _getTexureCoordinate(it->second.rotationMode))); } + CHECK_GL(glVertexAttribPointer(_filterPositionAttribute, 2, GL_FLOAT, 0, 0, imageVertices)); CHECK_GL(glDrawArrays(GL_TRIANGLE_STRIP, 0, 4)); @@ -252,7 +256,7 @@ void Filter::update(float frameTime) { proceed(false); _framebuffer->active(); - Context::getInstance()->capturedFrameData = new unsigned char[captureWidth * captureHeight * 4]; + Context::getInstance()->capturedFrameData = new uint8_t[captureWidth * captureHeight * 4]; CHECK_GL(glReadPixels(0, 0, captureWidth, captureHeight, GL_RGBA, GL_UNSIGNED_BYTE, Context::getInstance()->capturedFrameData)); _framebuffer->inactive(); } else { @@ -263,25 +267,42 @@ void Filter::update(float frameTime) { int rotatedFramebufferWidth = firstInputFramebuffer->getWidth(); int rotatedFramebufferHeight = firstInputFramebuffer->getHeight(); - if (rotationSwapsSize(firstInputRotation)) - { + + if (_overrideInputSize) { + rotatedFramebufferWidth = _forcedMaximumWidth; + rotatedFramebufferHeight = _forcedMaximumHeight; + } else if (rotationSwapsSize(firstInputRotation)) { rotatedFramebufferWidth = firstInputFramebuffer->getHeight(); rotatedFramebufferHeight = firstInputFramebuffer->getWidth(); } - if (_framebufferScale != 1.0) { - rotatedFramebufferWidth = int(rotatedFramebufferWidth * _framebufferScale); - rotatedFramebufferHeight = int(rotatedFramebufferHeight * _framebufferScale); - } - _framebuffer = Context::getInstance()->getFramebufferCache()->fetchFramebuffer(rotatedFramebufferWidth, rotatedFramebufferHeight); proceed(); } - + + if (_frameProcessingCompletionBlock) { + _frameProcessingCompletionBlock(frameTime); + } + _framebuffer->release(); _framebuffer = 0; } +void Filter::setFrameProcessingCompletionCallback(std::function callback) { + _frameProcessingCompletionBlock = callback; +} + +void Filter::forceProcessingAtSize(int width, int height) { + if (width == 0 || height == 0) { + _overrideInputSize = false; + return; + } + + _overrideInputSize = true; + _forcedMaximumWidth = width; + _forcedMaximumHeight = height; +} + bool Filter::registerProperty(const std::string& name, int defaultValue, const std::string& comment/* = ""*/, std::function setCallback/* = 0*/) { if (hasProperty(name)) return false; IntProperty property; diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Filter.hpp b/src/filter/Filter.hpp similarity index 90% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Filter.hpp rename to src/filter/Filter.hpp index ae7acba..95877cb 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/Filter.hpp +++ b/src/filter/Filter.hpp @@ -71,9 +71,14 @@ class Filter : public Source, public Target { virtual void update(float frameTime) override; virtual bool proceed(bool bUpdateTargets = true) override; + virtual void forceProcessingAtSize(int width, int height) override; + GLProgram* getProgram() const { return _filterProgram; }; // property setters & getters + + void setFrameProcessingCompletionCallback(std::function callback); + bool registerProperty(const std::string& name, int defaultValue, const std::string& comment = "", std::function setCallback = 0); bool registerProperty(const std::string& name, float defaultValue, const std::string& comment = "", std::function setCallback = 0); bool registerProperty(const std::string& name, const std::string& defaultValue, const std::string& comment = "", std::function setCallback = 0); @@ -104,6 +109,12 @@ class Filter : public Source, public Target { protected: GLProgram* _filterProgram; GLuint _filterPositionAttribute; + + bool _overrideInputSize = false; + int _forcedMaximumWidth, _forcedMaximumHeight; + + std::function _frameProcessingCompletionBlock; + std::string _filterClassName; struct { float r; float g; float b; float a; @@ -137,11 +148,22 @@ class Filter : public Source, public Target { std::function setCallback; }; std::map _stringProperties; + private: static std::map> _filterFactories; }; +#define DEFINE_FILTER_CREATE_METHOD(className) \ +className* className::create() { \ + className* ret = new (std::nothrow) className(); \ + if (ret && !ret->init()) { \ + delete ret; \ + ret = 0; \ + } \ + return ret; \ +} + #if PLATFORM == PLATFORM_ANDROID #define REGISTER_FILTER_CLASS(className) \ class className##Registry { \ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/FilterGroup.cpp b/src/filter/FilterGroup.cpp similarity index 93% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/FilterGroup.cpp rename to src/filter/FilterGroup.cpp index 3e42903..a284394 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/FilterGroup.cpp +++ b/src/filter/FilterGroup.cpp @@ -120,7 +120,9 @@ void FilterGroup::removeAllFilters() { } Filter* FilterGroup::_predictTerminalFilter(Filter* filter) { - if (filter->getTargets().size() == 0) + if (!filter) + return 0; + else if (filter->getTargets().size() == 0) return filter; else return _predictTerminalFilter(dynamic_cast(filter->getTargets().begin()->first)); @@ -189,13 +191,13 @@ void FilterGroup::updateTargets(float frameTime) { } void FilterGroup::setFramebuffer(Framebuffer* fb, RotationMode outputRotation/* = RotationMode::NoRotation*/) { - //if (_terminalFilter) - // _terminalFilter->setFramebuffer(fb); + if (_terminalFilter) + _terminalFilter->setFramebuffer(fb); } Framebuffer* FilterGroup::getFramebuffer() const { - //if (_terminalFilter) - // return _terminalFilter->getFramebuffer(); + if (_terminalFilter) + return _terminalFilter->getFramebuffer(); return 0; } @@ -205,6 +207,12 @@ void FilterGroup::setInputFramebuffer(Framebuffer* framebuffer, RotationMode rot } } +void FilterGroup::forceProcessingAtSize(int width, int height) { + for(auto& filter : _filters){ + filter->forceProcessingAtSize(width, height); + } +} + bool FilterGroup::isPrepared() const { // for (auto& filter : _filters) { // if (!filter->isPrepared()) diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/FilterGroup.hpp b/src/filter/FilterGroup.hpp similarity index 97% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/FilterGroup.hpp rename to src/filter/FilterGroup.hpp index 2e73118..4ce00ac 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/FilterGroup.hpp +++ b/src/filter/FilterGroup.hpp @@ -50,6 +50,7 @@ class FilterGroup : public Filter { //#if GI_TARGET_PLATFORM == GI_PLATFORM_IOS // virtual Source* addTarget(id target) override; //#endif + virtual void forceProcessingAtSize(int width, int height) override; virtual void removeTarget(Target* target) override; virtual void removeAllTargets() override; virtual bool hasTarget(const Target* target) const override; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurFilter.cpp b/src/filter/GaussianBlurFilter.cpp similarity index 97% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurFilter.cpp rename to src/filter/GaussianBlurFilter.cpp index 8e977ad..4cdbdb2 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurFilter.cpp +++ b/src/filter/GaussianBlurFilter.cpp @@ -62,7 +62,7 @@ bool GaussianBlurFilter::init(int radius, float sigma) { _hBlurFilter->addTarget(_vBlurFilter); addFilter(_hBlurFilter); - registerProperty("radius", 4, "", [this](int& radius){ + registerProperty("radius", 2, "", [this](int& radius){ setRadius(radius); }); diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurFilter.hpp b/src/filter/GaussianBlurFilter.hpp similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurFilter.hpp rename to src/filter/GaussianBlurFilter.hpp index 068250c..545409e 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurFilter.hpp +++ b/src/filter/GaussianBlurFilter.hpp @@ -29,7 +29,7 @@ class GaussianBlurFilter : public FilterGroup { public: virtual ~GaussianBlurFilter(); - static GaussianBlurFilter* create(int radius = 4, float sigma = 2.0); + static GaussianBlurFilter* create(int radius = 2, float sigma = 2.0); bool init(int radius, float sigma); void setRadius(int radius); void setSigma(float sigma); diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurMonoFilter.cpp b/src/filter/GaussianBlurMonoFilter.cpp similarity index 97% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurMonoFilter.cpp rename to src/filter/GaussianBlurMonoFilter.cpp index 80e8b84..38e8c18 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/GaussianBlurMonoFilter.cpp +++ b/src/filter/GaussianBlurMonoFilter.cpp @@ -47,6 +47,10 @@ bool GaussianBlurMonoFilter::init(int radius, float sigma) { return false; } +int GaussianBlurMonoFilter::getRadius() { + return _radius; +} + void GaussianBlurMonoFilter::setRadius(int radius) { if (radius == _radius) return; @@ -59,6 +63,10 @@ void GaussianBlurMonoFilter::setRadius(int radius) { initWithShaderString(_generateOptimizedVertexShaderString(_radius, _sigma), _generateOptimizedFragmentShaderString(_radius, _sigma)); } +float GaussianBlurMonoFilter::getSigma() { + return _sigma; +} + void GaussianBlurMonoFilter::setSigma(float sigma) { if (sigma == _sigma) return; @@ -128,9 +136,9 @@ std::string GaussianBlurMonoFilter::_generateVertexShaderString(int radius, floa for (int i = 0; i < radius * 2 + 1; ++i) { int offsetFromCenter = i - radius; if (offsetFromCenter == 0) { - shaderStr = shaderStr + str_format("blurCoordinates[%d] = texCoord.xy;\n", i); + shaderStr += str_format("blurCoordinates[%d] = texCoord.xy;\n", i); } else { - shaderStr = shaderStr + str_format("blurCoordinates[%d] = texCoord.xy + texelSpacing * (%f);\n", i, (float)offsetFromCenter); + shaderStr += str_format("blurCoordinates[%d] = texCoord.xy + texelSpacing * (%f);\n", i, (float)offsetFromCenter); } } diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurMonoFilter.hpp b/src/filter/GaussianBlurMonoFilter.hpp similarity index 88% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurMonoFilter.hpp rename to src/filter/GaussianBlurMonoFilter.hpp index 645cf31..4cb98b9 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GaussianBlurMonoFilter.hpp +++ b/src/filter/GaussianBlurMonoFilter.hpp @@ -28,15 +28,18 @@ class GaussianBlurMonoFilter : public Filter { public: enum Type {HORIZONTAL, VERTICAL}; - static GaussianBlurMonoFilter* create(Type type = HORIZONTAL, int radius = 4, float sigma = 2.0); + static GaussianBlurMonoFilter* create(Type type = VERTICAL, int radius = 4, float sigma = 2.0); bool init(int radius, float sigma); + int getRadius(); void setRadius(int radius); + + float getSigma(); void setSigma(float sigma); virtual bool proceed(bool bUpdateTargets = true) override; protected: - GaussianBlurMonoFilter(Type type = HORIZONTAL); + GaussianBlurMonoFilter(Type type = VERTICAL); Type _type; int _radius; float _sigma; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GlassSphereFilter.cpp b/src/filter/GlassSphereFilter.cpp similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GlassSphereFilter.cpp rename to src/filter/GlassSphereFilter.cpp index ad2369c..70d9c41 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GlassSphereFilter.cpp +++ b/src/filter/GlassSphereFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(GlassSphereFilter) +DEFINE_FILTER_CREATE_METHOD(GlassSphereFilter) + const std::string kGlassSphereFragmentShaderString = SHADER_STRING ( @@ -65,18 +67,7 @@ const std::string kGlassSphereFragmentShaderString = SHADER_STRING gl_FragColor = vec4(finalSphereColor, 1.0) * checkForPresenceWithinSphere; } - ); - - - -GlassSphereFilter* GlassSphereFilter::create() { - GlassSphereFilter* ret = new (std::nothrow) GlassSphereFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool GlassSphereFilter::init() { if (!initWithFragmentShaderString(kGlassSphereFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GlassSphereFilter.hpp b/src/filter/GlassSphereFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GlassSphereFilter.hpp rename to src/filter/GlassSphereFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GrayscaleFilter.cpp b/src/filter/GrayscaleFilter.cpp similarity index 83% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GrayscaleFilter.cpp rename to src/filter/GrayscaleFilter.cpp index 9a92a14..bfc2586 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GrayscaleFilter.cpp +++ b/src/filter/GrayscaleFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(GrayscaleFilter) +DEFINE_FILTER_CREATE_METHOD(GrayscaleFilter) + const std::string kGrayscaleFragmentShaderString = SHADER_STRING ( precision highp float; @@ -33,21 +35,12 @@ const std::string kGrayscaleFragmentShaderString = SHADER_STRING void main() { lowp vec4 color = texture2D(colorMap, vTexCoord); - float luminance = dot(color.rgb, vec3(0.2125, 0.7154, 0.0721)); + float luminance = dot(color.rgb, W); + gl_FragColor = vec4(vec3(luminance), color.a); } ); - -GrayscaleFilter* GrayscaleFilter::create() { - GrayscaleFilter* ret = new (std::nothrow) GrayscaleFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool GrayscaleFilter::init() { if (Filter::initWithFragmentShaderString(kGrayscaleFragmentShaderString)) { return true; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GrayscaleFilter.hpp b/src/filter/GrayscaleFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/GrayscaleFilter.hpp rename to src/filter/GrayscaleFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HSBFilter.cpp b/src/filter/HSBFilter.cpp similarity index 93% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HSBFilter.cpp rename to src/filter/HSBFilter.cpp index e21dc63..36a432a 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HSBFilter.cpp +++ b/src/filter/HSBFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(HSBFilter) +DEFINE_FILTER_CREATE_METHOD(HSBFilter) + /* Matrix algorithms adapted from http://www.graficaobscura.com/matrix/index.html Note about luminance vector values below from that page: @@ -36,16 +38,6 @@ REGISTER_FILTER_CLASS(HSBFilter) #define GLUM (0.59f) #define BLUM (0.11f) - -HSBFilter* HSBFilter::create() { - HSBFilter* ret = new (std::nothrow) HSBFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool HSBFilter::init() { if (!ColorMatrixFilter::init()) return false; reset(); diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HSBFilter.hpp b/src/filter/HSBFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HSBFilter.hpp rename to src/filter/HSBFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HalftoneFilter.cpp b/src/filter/HalftoneFilter.cpp similarity index 91% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HalftoneFilter.cpp rename to src/filter/HalftoneFilter.cpp index 08d28fa..492c6d3 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HalftoneFilter.cpp +++ b/src/filter/HalftoneFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(HalftoneFilter) +DEFINE_FILTER_CREATE_METHOD(HalftoneFilter) + const std::string kHalftoneFragmentShaderString = SHADER_STRING ( uniform highp float pixelSize; @@ -47,18 +49,7 @@ const std::string kHalftoneFragmentShaderString = SHADER_STRING gl_FragColor = vec4(vec3(checkForPresenceWithinDot), 1.0); } - ); - - - -HalftoneFilter* HalftoneFilter::create() { - HalftoneFilter* ret = new (std::nothrow) HalftoneFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool HalftoneFilter::init() { if (!initWithFragmentShaderString(kHalftoneFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HalftoneFilter.hpp b/src/filter/HalftoneFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HalftoneFilter.hpp rename to src/filter/HalftoneFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HueFilter.cpp b/src/filter/HueFilter.cpp similarity index 94% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HueFilter.cpp rename to src/filter/HueFilter.cpp index 48f554a..cb47515 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/HueFilter.cpp +++ b/src/filter/HueFilter.cpp @@ -23,6 +23,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(HueFilter) +DEFINE_FILTER_CREATE_METHOD(HueFilter) + // Adapted from http://stackoverflow.com/questions/9234724/how-to-change-hue-of-a-texture-with-glsl - see for code and discussion const std::string kHueFragmentShaderString = SHADER_STRING ( @@ -69,16 +71,6 @@ const std::string kHueFragmentShaderString = SHADER_STRING } ); - -HueFilter* HueFilter::create() { - HueFilter* ret = new (std::nothrow) HueFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool HueFilter::init() { if (!initWithFragmentShaderString(kHueFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HueFilter.hpp b/src/filter/HueFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/HueFilter.hpp rename to src/filter/HueFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/IOSBlurFilter.cpp b/src/filter/IOSBlurFilter.cpp similarity index 94% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/IOSBlurFilter.cpp rename to src/filter/IOSBlurFilter.cpp index 121291d..f29397d 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/IOSBlurFilter.cpp +++ b/src/filter/IOSBlurFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(IOSBlurFilter) +DEFINE_FILTER_CREATE_METHOD(IOSBlurFilter) + IOSBlurFilter::IOSBlurFilter() :_saturationFilter(0) ,_blurFilter(0) @@ -46,15 +48,6 @@ IOSBlurFilter::~IOSBlurFilter() { } } -IOSBlurFilter* IOSBlurFilter::create() { - IOSBlurFilter* ret = new (std::nothrow) IOSBlurFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool IOSBlurFilter::init() { if (!FilterGroup::init()) { return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/IOSBlurFilter.hpp b/src/filter/IOSBlurFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/IOSBlurFilter.hpp rename to src/filter/IOSBlurFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/LuminanceRangeFilter.cpp b/src/filter/LuminanceRangeFilter.cpp similarity index 91% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/LuminanceRangeFilter.cpp rename to src/filter/LuminanceRangeFilter.cpp index 7f1a046..0d66c1b 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/LuminanceRangeFilter.cpp +++ b/src/filter/LuminanceRangeFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(LuminanceRangeFilter) +DEFINE_FILTER_CREATE_METHOD(LuminanceRangeFilter) + const std::string kLuminanceRangeFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -40,15 +42,6 @@ const std::string kLuminanceRangeFragmentShaderString = SHADER_STRING } ); -LuminanceRangeFilter* LuminanceRangeFilter::create() { - LuminanceRangeFilter* ret = new (std::nothrow) LuminanceRangeFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool LuminanceRangeFilter::init() { if (!initWithFragmentShaderString(kLuminanceRangeFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/LuminanceRangeFilter.hpp b/src/filter/LuminanceRangeFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/LuminanceRangeFilter.hpp rename to src/filter/LuminanceRangeFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NearbySampling3x3Filter.cpp b/src/filter/NearbySampling3x3Filter.cpp similarity index 99% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NearbySampling3x3Filter.cpp rename to src/filter/NearbySampling3x3Filter.cpp index 4849350..95cba2a 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NearbySampling3x3Filter.cpp +++ b/src/filter/NearbySampling3x3Filter.cpp @@ -65,7 +65,7 @@ const std::string kNearbySampling3x3SamplingVertexShaderString = SHADER_STRING vBottomLeftTexCoord = texCoord.xy - widthNegativeHeightStep; vBottomRightTexCoord = texCoord.xy + widthHeightStep; } - ); +); bool NearbySampling3x3Filter::initWithFragmentShaderString(const std::string& fragmentShaderSource, int inputNumber/* = 1*/) { diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NearbySampling3x3Filter.hpp b/src/filter/NearbySampling3x3Filter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NearbySampling3x3Filter.hpp rename to src/filter/NearbySampling3x3Filter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NonMaximumSuppressionFilter.cpp b/src/filter/NonMaximumSuppressionFilter.cpp similarity index 91% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NonMaximumSuppressionFilter.cpp rename to src/filter/NonMaximumSuppressionFilter.cpp index 2b09b0e..cc9b368 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/NonMaximumSuppressionFilter.cpp +++ b/src/filter/NonMaximumSuppressionFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(NonMaximumSuppressionFilter) +DEFINE_FILTER_CREATE_METHOD(NonMaximumSuppressionFilter) + const std::string kNonMaximumSuppressionShaderString = SHADER_STRING ( precision mediump float; @@ -65,17 +67,7 @@ const std::string kNonMaximumSuppressionShaderString = SHADER_STRING gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0); } - ); - - -NonMaximumSuppressionFilter* NonMaximumSuppressionFilter::create() { - NonMaximumSuppressionFilter* ret = new (std::nothrow) NonMaximumSuppressionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool NonMaximumSuppressionFilter::init() { if (initWithFragmentShaderString(kNonMaximumSuppressionShaderString)) { diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NonMaximumSuppressionFilter.hpp b/src/filter/NonMaximumSuppressionFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/NonMaximumSuppressionFilter.hpp rename to src/filter/NonMaximumSuppressionFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PixellationFilter.cpp b/src/filter/PixellationFilter.cpp similarity index 91% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PixellationFilter.cpp rename to src/filter/PixellationFilter.cpp index 0172575..b2d0e7b 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PixellationFilter.cpp +++ b/src/filter/PixellationFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(PixellationFilter) +DEFINE_FILTER_CREATE_METHOD(PixellationFilter) + const std::string kPixellationFragmentShaderString = SHADER_STRING ( uniform highp float pixelSize; @@ -36,17 +38,7 @@ const std::string kPixellationFragmentShaderString = SHADER_STRING highp vec2 samplePos = floor(vTexCoord / pixelSizeVec) * pixelSizeVec + 0.5 * pixelSizeVec; gl_FragColor = texture2D(colorMap, samplePos); } - ); - - -PixellationFilter* PixellationFilter::create() { - PixellationFilter* ret = new (std::nothrow) PixellationFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool PixellationFilter::init() { if (!initWithFragmentShaderString(kPixellationFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PixellationFilter.hpp b/src/filter/PixellationFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PixellationFilter.hpp rename to src/filter/PixellationFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PosterizeFilter.cpp b/src/filter/PosterizeFilter.cpp similarity index 89% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PosterizeFilter.cpp rename to src/filter/PosterizeFilter.cpp index 0b2817c..77c30d6 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/PosterizeFilter.cpp +++ b/src/filter/PosterizeFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(PosterizeFilter) +DEFINE_FILTER_CREATE_METHOD(PosterizeFilter) + const std::string kPosterizeFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -36,16 +38,6 @@ const std::string kPosterizeFragmentShaderString = SHADER_STRING } ); - -PosterizeFilter* PosterizeFilter::create() { - PosterizeFilter* ret = new (std::nothrow) PosterizeFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool PosterizeFilter::init() { if (!initWithFragmentShaderString(kPosterizeFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PosterizeFilter.hpp b/src/filter/PosterizeFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/PosterizeFilter.hpp rename to src/filter/PosterizeFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/RGBFilter.cpp b/src/filter/RGBFilter.cpp similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/RGBFilter.cpp rename to src/filter/RGBFilter.cpp index 012e73b..426f18f 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/RGBFilter.cpp +++ b/src/filter/RGBFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(RGBFilter) +DEFINE_FILTER_CREATE_METHOD(RGBFilter) + const std::string kRGBFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -37,16 +39,6 @@ const std::string kRGBFragmentShaderString = SHADER_STRING } ); - -RGBFilter* RGBFilter::create() { - RGBFilter* ret = new (std::nothrow) RGBFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool RGBFilter::init() { if (!initWithFragmentShaderString(kRGBFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/RGBFilter.hpp b/src/filter/RGBFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/RGBFilter.hpp rename to src/filter/RGBFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SaturationFilter.cpp b/src/filter/SaturationFilter.cpp similarity index 91% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SaturationFilter.cpp rename to src/filter/SaturationFilter.cpp index f9b4b8e..5bbacbf 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SaturationFilter.cpp +++ b/src/filter/SaturationFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(SaturationFilter) +DEFINE_FILTER_CREATE_METHOD(SaturationFilter) + const std::string kSaturationFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -41,16 +43,6 @@ const std::string kSaturationFragmentShaderString = SHADER_STRING } ); - -SaturationFilter* SaturationFilter::create() { - SaturationFilter* ret = new (std::nothrow) SaturationFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool SaturationFilter::init() { if (!initWithFragmentShaderString(kSaturationFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SaturationFilter.hpp b/src/filter/SaturationFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SaturationFilter.hpp rename to src/filter/SaturationFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurFilter.cpp b/src/filter/SingleComponentGaussianBlurFilter.cpp similarity index 89% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurFilter.cpp rename to src/filter/SingleComponentGaussianBlurFilter.cpp index 7892208..f9ee7ae 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurFilter.cpp +++ b/src/filter/SingleComponentGaussianBlurFilter.cpp @@ -27,6 +27,8 @@ REGISTER_FILTER_CLASS(SingleComponentGaussianBlurFilter) SingleComponentGaussianBlurFilter::SingleComponentGaussianBlurFilter() :_hBlurFilter(0) ,_vBlurFilter(0) +,_radius(4) +,_sigma(2.0) { } @@ -51,7 +53,6 @@ SingleComponentGaussianBlurFilter* SingleComponentGaussianBlurFilter::create(int } return ret; } - bool SingleComponentGaussianBlurFilter::init(int radius, float sigma) { if (!FilterGroup::init()) { return false; @@ -59,13 +60,16 @@ bool SingleComponentGaussianBlurFilter::init(int radius, float sigma) { _hBlurFilter = SingleComponentGaussianBlurMonoFilter::create(SingleComponentGaussianBlurMonoFilter::HORIZONTAL, radius, sigma); _vBlurFilter = SingleComponentGaussianBlurMonoFilter::create(SingleComponentGaussianBlurMonoFilter::VERTICAL, radius, sigma); - _hBlurFilter->addTarget(_vBlurFilter); addFilter(_hBlurFilter); + _hBlurFilter->addTarget(_vBlurFilter); + setTerminalFilter(_vBlurFilter); + _radius = radius; registerProperty("radius", 4, "", [this](int& radius){ setRadius(radius); }); + _sigma = sigma; registerProperty("sigma", 2.0, "", [this](float& sigma){ setSigma(sigma); }); @@ -73,12 +77,22 @@ bool SingleComponentGaussianBlurFilter::init(int radius, float sigma) { return true; } +int SingleComponentGaussianBlurFilter::getRadius() { + return _radius; +} + void SingleComponentGaussianBlurFilter::setRadius(int radius) { + _radius = radius; _hBlurFilter->setRadius(radius); _vBlurFilter->setRadius(radius); } +float SingleComponentGaussianBlurFilter::getSigma() { + return _sigma; +} + void SingleComponentGaussianBlurFilter::setSigma(float sigma) { + _sigma = sigma; _hBlurFilter->setSigma(sigma); _vBlurFilter->setSigma(sigma); } diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurFilter.hpp b/src/filter/SingleComponentGaussianBlurFilter.hpp similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurFilter.hpp rename to src/filter/SingleComponentGaussianBlurFilter.hpp index 3b30c31..33a299a 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurFilter.hpp +++ b/src/filter/SingleComponentGaussianBlurFilter.hpp @@ -31,11 +31,17 @@ class SingleComponentGaussianBlurFilter : public FilterGroup { static SingleComponentGaussianBlurFilter* create(int radius = 4, float sigma = 2.0); bool init(int radius, float sigma); + + int getRadius(); void setRadius(int radius); + + float getSigma(); void setSigma(float sigma); protected: SingleComponentGaussianBlurFilter(); + int _radius; + float _sigma; private: SingleComponentGaussianBlurMonoFilter* _hBlurFilter; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurMonoFilter.cpp b/src/filter/SingleComponentGaussianBlurMonoFilter.cpp similarity index 79% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurMonoFilter.cpp rename to src/filter/SingleComponentGaussianBlurMonoFilter.cpp index 810e88e..ea9a33d 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurMonoFilter.cpp +++ b/src/filter/SingleComponentGaussianBlurMonoFilter.cpp @@ -39,16 +39,15 @@ SingleComponentGaussianBlurMonoFilter* SingleComponentGaussianBlurMonoFilter::cr std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedVertexShaderString(int radius, float sigma) { - if (radius < 1 || sigma <= 0.0) - { + if (radius < 1 || sigma <= 0.0) { return kDefaultVertexShader; } // 1. generate the normal Gaussian weights for a given sigma - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { + GLfloat standardGaussianWeights[radius + 1]; + GLfloat sumOfWeights = 0.0; + + for (int i = 0; i < radius + 1; ++i) { standardGaussianWeights[i] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); if (i == 0) sumOfWeights += standardGaussianWeights[i]; @@ -57,17 +56,15 @@ std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedVertexShade } // 2. normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance - for (int i = 0; i < radius + 1; ++i) - { + for (int i = 0; i < radius + 1; ++i) { standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; } // 3. From these weights we calculate the offsets to read interpolated values from - int numberOfOptimizedOffsets = fmin(radius / 2 + (radius % 2), 7); - float* optimizedGaussianOffsets = new float[numberOfOptimizedOffsets]; + int numberOfOptimizedOffsets = std::min(radius / 2 + (radius % 2), 7); + GLfloat optimizedGaussianOffsets[numberOfOptimizedOffsets]; - for (int i = 0; i < numberOfOptimizedOffsets; ++i) - { + for (int i = 0; i < numberOfOptimizedOffsets; ++i) { GLfloat firstWeight = standardGaussianWeights[i * 2 + 1]; GLfloat secondWeight = standardGaussianWeights[i * 2 + 2]; @@ -102,24 +99,20 @@ std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedVertexShade shaderStr += "}\n"; - delete[] standardGaussianWeights; - delete[] optimizedGaussianOffsets; - return shaderStr; } std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedFragmentShaderString(int radius, float sigma) { - if (radius < 1 || sigma <= 0.0) - { + if (radius < 1 || sigma <= 0.0) { return kDefaultFragmentShader; } // 1. generate the normal Gaussian weights for a given sigma - float* standardGaussianWeights = new float[radius + 1]; - float sumOfWeights = 0.0; - for (int i = 0; i < radius + 1; ++i) - { + GLfloat standardGaussianWeights[radius + 1]; + GLfloat sumOfWeights = 0.0; + + for (int i = 0; i < radius + 1; ++i) { standardGaussianWeights[i] = (1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(i, 2.0) / (2.0 * pow(sigma, 2.0))); if (i == 0) sumOfWeights += standardGaussianWeights[i]; @@ -128,14 +121,13 @@ std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedFragmentSha } // 2. normalize these weights to prevent the clipping of the Gaussian curve at the end of the discrete samples from reducing luminance - for (int i = 0; i < radius + 1; ++i) - { + for (int i = 0; i < radius + 1; ++i) { standardGaussianWeights[i] = standardGaussianWeights[i] / sumOfWeights; } // 3. From these weights we calculate the offsets to read interpolated values from int trueNumberOfOptimizedOffsets = radius / 2 + (radius % 2); - int numberOfOptimizedOffsets = fmin(trueNumberOfOptimizedOffsets, 7); + int numberOfOptimizedOffsets = std::min(trueNumberOfOptimizedOffsets, 7); std::string shaderStr = str_format("\ @@ -147,28 +139,26 @@ std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedFragmentSha {\n\ lowp float sum = 0.0;\n", numberOfOptimizedOffsets * 2 + 1); - shaderStr += str_format("gl_FragColor += texture2D(colorMap, blurCoordinates[0]) * %f;\n", standardGaussianWeights[0]); + shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[0]).r * %f;\n", standardGaussianWeights[0]); for (int i = 0; i < numberOfOptimizedOffsets; ++i) { - float firstWeight = standardGaussianWeights[i * 2 + 1]; - float secondWeight = standardGaussianWeights[i * 2 + 2]; - float optimizedWeight = firstWeight + secondWeight; + GLfloat firstWeight = standardGaussianWeights[i * 2 + 1]; + GLfloat secondWeight = standardGaussianWeights[i * 2 + 2]; + GLfloat optimizedWeight = firstWeight + secondWeight; shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[%d]).r * %f;\n", i * 2 + 1, optimizedWeight); shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[%d]).r * %f;\n", i * 2 + 2, optimizedWeight); } // If the number of required samples exceeds the amount we can pass in via varyings, we have to do dependent texture reads in the fragment shader - if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) - { + if (trueNumberOfOptimizedOffsets > numberOfOptimizedOffsets) { shaderStr += str_format("highp vec2 texelSpacing = vec2(texelWidthOffset, texelHeightOffset);\n"); - for (int i = numberOfOptimizedOffsets; i < trueNumberOfOptimizedOffsets; i++) - { - float firstWeight = standardGaussianWeights[i * 2 + 1]; - float secondWeight = standardGaussianWeights[i * 2 + 2]; + for (int i = numberOfOptimizedOffsets; i < trueNumberOfOptimizedOffsets; i++) { + GLfloat firstWeight = standardGaussianWeights[i * 2 + 1]; + GLfloat secondWeight = standardGaussianWeights[i * 2 + 2]; - float optimizedWeight = firstWeight + secondWeight; - float optimizedOffset = (firstWeight * (i * 2 + 1) + secondWeight * (i * 2 + 2)) / optimizedWeight; + GLfloat optimizedWeight = firstWeight + secondWeight; + GLfloat optimizedOffset = (firstWeight * (i * 2 + 1) + secondWeight * (i * 2 + 2)) / optimizedWeight; shaderStr += str_format("sum += texture2D(colorMap, blurCoordinates[0] + texelSpacing * %f).r * %f;\n", optimizedOffset, optimizedWeight); @@ -180,7 +170,6 @@ std::string SingleComponentGaussianBlurMonoFilter::_generateOptimizedFragmentSha "gl_FragColor = vec4(sum, sum, sum, 1.0);\n\ }"; - delete[] standardGaussianWeights; standardGaussianWeights = 0; return shaderStr; } diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurMonoFilter.hpp b/src/filter/SingleComponentGaussianBlurMonoFilter.hpp similarity index 91% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurMonoFilter.hpp rename to src/filter/SingleComponentGaussianBlurMonoFilter.hpp index 8c306a1..c271476 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SingleComponentGaussianBlurMonoFilter.hpp +++ b/src/filter/SingleComponentGaussianBlurMonoFilter.hpp @@ -27,10 +27,10 @@ NS_GI_BEGIN class SingleComponentGaussianBlurMonoFilter : public GaussianBlurMonoFilter { public: - static SingleComponentGaussianBlurMonoFilter* create(Type type = HORIZONTAL, int radius = 4, float sigma = 2.0); + static SingleComponentGaussianBlurMonoFilter* create(Type type = VERTICAL, int radius = 2, float sigma = 2.0); protected: - SingleComponentGaussianBlurMonoFilter(Type type = HORIZONTAL); + SingleComponentGaussianBlurMonoFilter(Type type = VERTICAL); private: std::string _generateOptimizedVertexShaderString(int radius, float sigma) override; diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SketchFilter.cpp b/src/filter/SketchFilter.cpp similarity index 91% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SketchFilter.cpp rename to src/filter/SketchFilter.cpp index 1b7f260..a395609 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SketchFilter.cpp +++ b/src/filter/SketchFilter.cpp @@ -22,6 +22,9 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(SketchFilter) +DEFINE_FILTER_CREATE_METHOD(SketchFilter) +DEFINE_FILTER_CREATE_METHOD(_SketchFilter) + const std::string kSketchFilterFragmentShaderString = SHADER_STRING ( precision mediump float; @@ -77,16 +80,6 @@ SketchFilter::~SketchFilter() } } -SketchFilter* SketchFilter::create() { - SketchFilter* ret = new (std::nothrow) SketchFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - bool SketchFilter::init() { if (!FilterGroup::init()) { return false; @@ -106,16 +99,6 @@ bool SketchFilter::init() { return true; } -_SketchFilter* _SketchFilter::create() { - _SketchFilter* ret = new (std::nothrow) _SketchFilter(); - if (!ret || !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - bool _SketchFilter::init() { if (!initWithFragmentShaderString(kSketchFilterFragmentShaderString)) { return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SketchFilter.hpp b/src/filter/SketchFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SketchFilter.hpp rename to src/filter/SketchFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SmoothToonFilter.cpp b/src/filter/SmoothToonFilter.cpp similarity index 92% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SmoothToonFilter.cpp rename to src/filter/SmoothToonFilter.cpp index 8f8d367..9dbd48b 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SmoothToonFilter.cpp +++ b/src/filter/SmoothToonFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(SmoothToonFilter) +DEFINE_FILTER_CREATE_METHOD(SmoothToonFilter) + SmoothToonFilter::SmoothToonFilter() :_gaussianBlurFilter(0) ,_toonFilter(0) @@ -41,15 +43,6 @@ SmoothToonFilter::~SmoothToonFilter() { } -SmoothToonFilter* SmoothToonFilter::create() { - SmoothToonFilter* ret = new (std::nothrow) SmoothToonFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool SmoothToonFilter::init() { if (!FilterGroup::init()) { return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SmoothToonFilter.hpp b/src/filter/SmoothToonFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SmoothToonFilter.hpp rename to src/filter/SmoothToonFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SobelEdgeDetectionFilter.cpp b/src/filter/SobelEdgeDetectionFilter.cpp similarity index 93% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SobelEdgeDetectionFilter.cpp rename to src/filter/SobelEdgeDetectionFilter.cpp index 1a4edcf..63f9d47 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/SobelEdgeDetectionFilter.cpp +++ b/src/filter/SobelEdgeDetectionFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(SobelEdgeDetectionFilter) +DEFINE_FILTER_CREATE_METHOD(SobelEdgeDetectionFilter) + // Code from "Graphics Shaders: Theory and Practice" by M. Bailey and S. Cunningham const std::string kSobelEdgeDetectionFragmentShaderString = SHADER_STRING ( @@ -76,16 +78,6 @@ SobelEdgeDetectionFilter::~SobelEdgeDetectionFilter() { } } -SobelEdgeDetectionFilter* SobelEdgeDetectionFilter::create() { - SobelEdgeDetectionFilter* ret = new (std::nothrow) SobelEdgeDetectionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - - return ret; -} - bool SobelEdgeDetectionFilter::init() { if (!FilterGroup::init()) { return false; @@ -131,7 +123,6 @@ bool _SobelEdgeDetectionFilter::proceed(bool bUpdateTargets/* = true*/) { float texelWidth = 1.0 / _framebuffer->getWidth(); float texelHeight = 1.0 / _framebuffer->getHeight(); - Framebuffer* inputFramebuffer = _inputFramebuffers.begin()->second.frameBuffer; RotationMode inputRotation = _inputFramebuffers.begin()->second.rotationMode; if (rotationSwapsSize(inputRotation)){ texelWidth = 1.0 / _framebuffer->getHeight(); diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SobelEdgeDetectionFilter.hpp b/src/filter/SobelEdgeDetectionFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SobelEdgeDetectionFilter.hpp rename to src/filter/SobelEdgeDetectionFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SphereRefractionFilter.cpp b/src/filter/SphereRefractionFilter.cpp similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SphereRefractionFilter.cpp rename to src/filter/SphereRefractionFilter.cpp index b3c1033..0b50a8b 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SphereRefractionFilter.cpp +++ b/src/filter/SphereRefractionFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(SphereRefractionFilter) +DEFINE_FILTER_CREATE_METHOD(SphereRefractionFilter) + const std::string kSphereRefractionShaderString = SHADER_STRING ( @@ -48,19 +50,8 @@ const std::string kSphereRefractionShaderString = SHADER_STRING gl_FragColor = texture2D(colorMap, (refractedVector.xy + 1.0) * 0.5) * checkForPresenceWithinSphere; } - ); - -SphereRefractionFilter* SphereRefractionFilter::create() { - SphereRefractionFilter* ret = new (std::nothrow) SphereRefractionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool SphereRefractionFilter::init() { if (!initWithFragmentShaderString(kSphereRefractionShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SphereRefractionFilter.hpp b/src/filter/SphereRefractionFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/SphereRefractionFilter.hpp rename to src/filter/SphereRefractionFilter.hpp diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ToonFilter.cpp b/src/filter/ToonFilter.cpp similarity index 94% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ToonFilter.cpp rename to src/filter/ToonFilter.cpp index 8257ee8..258d7dd 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/filter/ToonFilter.cpp +++ b/src/filter/ToonFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(ToonFilter) +DEFINE_FILTER_CREATE_METHOD(ToonFilter) + const std::string kToonFragmentShaderString = SHADER_STRING ( precision mediump float; @@ -63,17 +65,7 @@ const std::string kToonFragmentShaderString = SHADER_STRING gl_FragColor = vec4(posterizedImageColor * thresholdTest, color.a); } - ); - - -ToonFilter* ToonFilter::create() { - ToonFilter* ret = new (std::nothrow) ToonFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool ToonFilter::init() { if (!initWithFragmentShaderString(kToonFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ToonFilter.hpp b/src/filter/ToonFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/ToonFilter.hpp rename to src/filter/ToonFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WeakPixelInclusionFilter.cpp b/src/filter/WeakPixelInclusionFilter.cpp similarity index 90% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WeakPixelInclusionFilter.cpp rename to src/filter/WeakPixelInclusionFilter.cpp index 9f4e7b0..0000c04 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WeakPixelInclusionFilter.cpp +++ b/src/filter/WeakPixelInclusionFilter.cpp @@ -22,6 +22,8 @@ NS_GI_BEGIN REGISTER_FILTER_CLASS(WeakPixelInclusionFilter) +DEFINE_FILTER_CREATE_METHOD(WeakPixelInclusionFilter) + const std::string kWeakPixelInclusionFragmentShaderString = SHADER_STRING ( precision mediump float; @@ -57,17 +59,7 @@ const std::string kWeakPixelInclusionFragmentShaderString = SHADER_STRING gl_FragColor = vec4(vec3(sumTest * pixelTest), 1.0); } - ); - - -WeakPixelInclusionFilter* WeakPixelInclusionFilter::create() { - WeakPixelInclusionFilter* ret = new (std::nothrow) WeakPixelInclusionFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} +); bool WeakPixelInclusionFilter::init() { if (initWithFragmentShaderString(kWeakPixelInclusionFragmentShaderString)) { diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WeakPixelInclusionFilter.hpp b/src/filter/WeakPixelInclusionFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WeakPixelInclusionFilter.hpp rename to src/filter/WeakPixelInclusionFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WhiteBalanceFilter.cpp b/src/filter/WhiteBalanceFilter.cpp similarity index 93% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WhiteBalanceFilter.cpp rename to src/filter/WhiteBalanceFilter.cpp index a2358c3..410008b 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WhiteBalanceFilter.cpp +++ b/src/filter/WhiteBalanceFilter.cpp @@ -22,6 +22,8 @@ USING_NS_GI REGISTER_FILTER_CLASS(WhiteBalanceFilter) +DEFINE_FILTER_CREATE_METHOD(WhiteBalanceFilter) + const std::string kWhiteBalanceFragmentShaderString = SHADER_STRING ( uniform sampler2D colorMap; @@ -48,16 +50,6 @@ const std::string kWhiteBalanceFragmentShaderString = SHADER_STRING } ); - -WhiteBalanceFilter* WhiteBalanceFilter::create() { - WhiteBalanceFilter* ret = new (std::nothrow) WhiteBalanceFilter(); - if (ret && !ret->init()) { - delete ret; - ret = 0; - } - return ret; -} - bool WhiteBalanceFilter::init() { if (!initWithFragmentShaderString(kWhiteBalanceFragmentShaderString)) return false; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WhiteBalanceFilter.hpp b/src/filter/WhiteBalanceFilter.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/filter/WhiteBalanceFilter.hpp rename to src/filter/WhiteBalanceFilter.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/macros.h b/src/macros.h similarity index 97% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/macros.h rename to src/macros.h index 5eef55a..6a0b6a6 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/macros.h +++ b/src/macros.h @@ -19,11 +19,11 @@ #ifndef macros_h #define macros_h -#define PLATFORM_UNKNOW 0 +#define PLATFORM_UNKNOWN 0 #define PLATFORM_ANDROID 1 #define PLATFORM_IOS 2 -#define PLATFORM PLATFORM_UNKNOW +#define PLATFORM PLATFORM_UNKNOWN #if defined(__ANDROID__) || defined(ANDROID) #undef PLATFORM diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/IOSTarget.cpp b/src/math.hpp similarity index 76% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/IOSTarget.cpp rename to src/math.hpp index 6f97f68..d90f473 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/IOSTarget.cpp +++ b/src/math.hpp @@ -16,8 +16,13 @@ * limitations under the License. */ -#if PLATFORM == PLATFORM_IOS +#ifndef math_hpp +#define math_hpp -#include "IOSTarget.hpp" +#include "math/Matrix3.hpp" +#include "math/Matrix4.hpp" +#include "math/Vector2.hpp" +#include "math/Vector3.hpp" +#include "math/Vector4.hpp" -#endif +#endif /* math_hpp */ diff --git a/src/math/Matrix3.cpp b/src/math/Matrix3.cpp new file mode 100644 index 0000000..9e9533f --- /dev/null +++ b/src/math/Matrix3.cpp @@ -0,0 +1,293 @@ +/* + * GPUImage-x + * + * Copyright (C) 2017 Yijin Wang, Yiqian Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Matrix3.hpp" + +#include +#include + +NS_GI_BEGIN + +const Matrix3 Matrix3::IDENTITY = Matrix3(1.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 1.0f); + +Matrix3::Matrix3() { + *this = IDENTITY; +} + +Matrix3::Matrix3(const float* mat) { + set(mat); +} + +Matrix3::Matrix3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { + set(m11, m12, m13, m21, m22, m23, m31, m32, m33); +} + +Matrix3::Matrix3(const Matrix3& copy) { + memcpy(m, copy.m, sizeof(float) * 9); +} + +Matrix3::~Matrix3() { + +} + +void Matrix3::set(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33) { + m[0] = m11; + m[1] = m21; + m[2] = m31; + m[3] = m12; + m[4] = m22; + m[5] = m32; + m[6] = m13; + m[7] = m23; + m[8] = m33; +} + +void Matrix3::set(const float* mat) { + assert(mat); + memcpy(this->m, mat, sizeof(float) * 9); +} + +void Matrix3::set(const Matrix3& mat) { + memcpy(this->m, mat.m, sizeof(float) * 9); +} + +void Matrix3::setIdentity() { + memcpy(m, &IDENTITY, sizeof(float) * 9); +} + +void Matrix3::negate() +{ + m[0] = -m[0]; + m[1] = -m[1]; + m[2] = -m[2]; + m[3] = -m[3]; + m[4] = -m[4]; + m[5] = -m[5]; + m[6] = -m[6]; + m[7] = -m[7]; + m[8] = -m[8]; +} + +Matrix3 Matrix3::getNegated() const +{ + Matrix3 mat(*this); + mat.negate(); + return mat; +} + +void Matrix3::transpose() { + float tmp; + tmp = m[1]; m[1] = m[3]; m[3] = tmp; + tmp = m[2]; m[2] = m[6]; m[6] = tmp; + tmp = m[5]; m[5] = m[7]; m[7] = tmp; +} + +Matrix3 Matrix3::getTransposed() const { + Matrix3 mat(*this); + mat.transpose(); + return mat; +} + +void Matrix3::add(float scalar) +{ + add(scalar, this); +} + +void Matrix3::add(float scalar, Matrix3* dst) const +{ + assert(dst); + dst->m[0] = this->m[0] + scalar; + dst->m[1] = this->m[1] + scalar; + dst->m[2] = this->m[2] + scalar; + dst->m[3] = this->m[3] + scalar; + dst->m[4] = this->m[4] + scalar; + dst->m[5] = this->m[5] + scalar; + dst->m[6] = this->m[6] + scalar; + dst->m[7] = this->m[7] + scalar; + dst->m[8] = this->m[8] + scalar; +} + +void Matrix3::add(const Matrix3& mat) +{ + add(*this, mat, this); +} + +void Matrix3::add(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) +{ + assert(dst); + dst->m[0] = m1.m[0] + m2.m[0]; + dst->m[1] = m1.m[1] + m2.m[1]; + dst->m[2] = m1.m[2] + m2.m[2]; + dst->m[3] = m1.m[3] + m2.m[3]; + dst->m[4] = m1.m[4] + m2.m[4]; + dst->m[5] = m1.m[5] + m2.m[5]; + dst->m[6] = m1.m[6] + m2.m[6]; + dst->m[7] = m1.m[7] + m2.m[7]; + dst->m[8] = m1.m[8] + m2.m[8]; +} + +void Matrix3::subtract(const Matrix3& mat) +{ + subtract(*this, mat, this); +} + +void Matrix3::subtract(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) +{ + assert(dst); + dst->m[0] = m1.m[0] - m2.m[0]; + dst->m[1] = m1.m[1] - m2.m[1]; + dst->m[2] = m1.m[2] - m2.m[2]; + dst->m[3] = m1.m[3] - m2.m[3]; + dst->m[4] = m1.m[4] - m2.m[4]; + dst->m[5] = m1.m[5] - m2.m[5]; + dst->m[6] = m1.m[6] - m2.m[6]; + dst->m[7] = m1.m[7] - m2.m[7]; + dst->m[8] = m1.m[8] - m2.m[8]; +} + +void Matrix3::multiply(float scalar) +{ + multiply(scalar, this); +} + +void Matrix3::multiply(float scalar, Matrix3* dst) const +{ + multiply(*this, scalar, dst); +} + +void Matrix3::multiply(const Matrix3& mat, float scalar, Matrix3* dst) +{ + assert(dst); + dst->m[0] = mat.m[0] * scalar; + dst->m[1] = mat.m[1] * scalar; + dst->m[2] = mat.m[2] * scalar; + dst->m[3] = mat.m[3] * scalar; + dst->m[4] = mat.m[4] * scalar; + dst->m[5] = mat.m[5] * scalar; + dst->m[6] = mat.m[6] * scalar; + dst->m[7] = mat.m[7] * scalar; + dst->m[8] = mat.m[8] * scalar; +} + +void Matrix3::multiply(const Matrix3& mat) +{ + multiply(*this, mat, this); +} + +void Matrix3::multiply(const Matrix3& m1, const Matrix3& m2, Matrix3* dst) +{ + assert(dst); + dst->m[0] = m1.m[0] * m2.m[0]; + dst->m[1] = m1.m[1] * m2.m[1]; + dst->m[2] = m1.m[2] * m2.m[2]; + dst->m[3] = m1.m[3] * m2.m[3]; + dst->m[4] = m1.m[4] * m2.m[4]; + dst->m[5] = m1.m[5] * m2.m[5]; + dst->m[6] = m1.m[6] * m2.m[6]; + dst->m[7] = m1.m[7] * m2.m[7]; + dst->m[8] = m1.m[8] * m2.m[8]; +} + +const Matrix3 Matrix3::operator+(const Matrix3& mat) const +{ + Matrix3 result(*this); + result.add(mat); + return result; +} + +Matrix3& Matrix3::operator+=(const Matrix3& mat) +{ + add(mat); + return *this; +} + +const Matrix3 Matrix3::operator-(const Matrix3& mat) const +{ + Matrix3 result(*this); + result.subtract(mat); + return result; +} + +Matrix3& Matrix3::operator-=(const Matrix3& mat) +{ + subtract(mat); + return *this; +} + +const Matrix3 Matrix3::operator-() const +{ + Matrix3 mat(*this); + mat.negate(); + return mat; +} + +const Matrix3 Matrix3::operator*(const Matrix3& mat) const +{ + Matrix3 result(*this); + result.multiply(mat); + return result; +} + +Matrix3& Matrix3::operator*=(const Matrix3& mat) +{ + multiply(mat); + return *this; +} + +const Matrix3 Matrix3::operator+(float scalar) const +{ + Matrix3 result(*this); + result.add(scalar); + return result; +} + +Matrix3& Matrix3::operator+=(float scalar) +{ + add(scalar); + return *this; +} + +const Matrix3 Matrix3::operator-(float scalar) const +{ + Matrix3 result(*this); + result.add(-scalar); + return result; +} + +Matrix3& Matrix3::operator-=(float scalar) +{ + add(-scalar); + return *this; +} + +const Matrix3 Matrix3::operator*(float scalar) const +{ + Matrix3 result(*this); + result.multiply(scalar); + return result; +} + +Matrix3& Matrix3::operator*=(float scalar) +{ + multiply(scalar); + return *this; +} + +NS_GI_END diff --git a/src/math/Matrix3.hpp b/src/math/Matrix3.hpp new file mode 100644 index 0000000..33a2223 --- /dev/null +++ b/src/math/Matrix3.hpp @@ -0,0 +1,80 @@ +/* + * GPUImage-x + * + * Copyright (C) 2017 Yijin Wang, Yiqian Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef Matrix3_hpp +#define Matrix3_hpp + +#include "../macros.h" + +NS_GI_BEGIN + +class Matrix3 { +public: + float m[9]; + Matrix3(); + Matrix3(const float* mat); + Matrix3(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33); + Matrix3(const Matrix3& copy); + ~Matrix3(); + + void set(float m11, float m12, float m13, float m21, float m22, float m23, float m31, float m32, float m33); + void set(const float* mat); + void set(const Matrix3& mat); + void setIdentity(); + + void negate(); + Matrix3 getNegated() const; + + void transpose(); + Matrix3 getTransposed() const; + + void add(float scalar); + void add(float scalar, Matrix3* dst) const; + void add(const Matrix3& mat); + static void add(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); + + void subtract(const Matrix3& mat); + static void subtract(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); + + void multiply(float scalar); + void multiply(float scalar, Matrix3* dst) const; + static void multiply(const Matrix3& mat, float scalar, Matrix3* dst); + void multiply(const Matrix3& mat); + static void multiply(const Matrix3& m1, const Matrix3& m2, Matrix3* dst); + + const Matrix3 operator+(const Matrix3& mat) const; + Matrix3& operator+=(const Matrix3& mat); + const Matrix3 operator-(const Matrix3& mat) const; + Matrix3& operator-=(const Matrix3& mat); + const Matrix3 operator-() const; + const Matrix3 operator*(const Matrix3& mat) const; + Matrix3& operator*=(const Matrix3& mat); + + const Matrix3 operator+(float scalar) const; + Matrix3& operator+=(float scalar); + const Matrix3 operator-(float scalar) const; + Matrix3& operator-=(float scalar); + const Matrix3 operator*(float scalar) const; + Matrix3& operator*=(float scalar); + + static const Matrix3 IDENTITY; +}; + +NS_GI_END + +#endif /* Matrix3_hpp */ diff --git a/src/math/Matrix4.cpp b/src/math/Matrix4.cpp new file mode 100644 index 0000000..0811bf1 --- /dev/null +++ b/src/math/Matrix4.cpp @@ -0,0 +1,347 @@ +/* + * GPUImage-x + * + * Copyright (C) 2017 Yijin Wang, Yiqian Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Matrix4.hpp" + +#include +#include + +NS_GI_BEGIN + +const Matrix4 Matrix4::IDENTITY = Matrix4(1.0f, 0.0f, 0.0f, 0.0f, + 0.0f, 1.0f, 0.0f, 0.0f, + 0.0f, 0.0f, 1.0f, 0.0f, + 0.0f, 0.0f, 0.0f, 1.0f); + +Matrix4::Matrix4() { + *this = IDENTITY; +} + +Matrix4::Matrix4(const float* mat) { + set(mat); +} + +Matrix4::Matrix4(float m11, float m12, float m13, float m14, float m21, float m22, float m23,float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { + set(m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44); +} + +Matrix4::Matrix4(const Matrix4& copy) { + memcpy(m, copy.m, sizeof(float) * 16); +} + +Matrix4::~Matrix4() { + +} + +void Matrix4::set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44) { + m[0] = m11; + m[1] = m21; + m[2] = m31; + m[3] = m41; + m[4] = m12; + m[5] = m22; + m[6] = m32; + m[7] = m42; + m[8] = m13; + m[9] = m23; + m[10] = m33; + m[11] = m43; + m[12] = m14; + m[13] = m24; + m[14] = m34; + m[15] = m44; +} + +void Matrix4::set(const float* mat) { + assert(mat); + memcpy(this->m, mat, sizeof(float) * 16); +} + +void Matrix4::set(const Matrix4& mat) { + memcpy(this->m, mat.m, sizeof(float) * 16); +} + +void Matrix4::setIdentity() { + memcpy(m, &IDENTITY, sizeof(float) * 16); +} + +void Matrix4::negate() +{ + m[0] = -m[0]; + m[1] = -m[1]; + m[2] = -m[2]; + m[3] = -m[3]; + m[4] = -m[4]; + m[5] = -m[5]; + m[6] = -m[6]; + m[7] = -m[7]; + m[8] = -m[8]; + m[9] = -m[9]; + m[10] = -m[10]; + m[11] = -m[11]; + m[12] = -m[12]; + m[13] = -m[13]; + m[14] = -m[14]; + m[15] = -m[15]; +} + +Matrix4 Matrix4::getNegated() const +{ + Matrix4 mat(*this); + mat.negate(); + return mat; +} + +void Matrix4::transpose() { + float tmp; + tmp = m[1]; m[1] = m[4]; m[4] = tmp; + tmp = m[2]; m[2] = m[8]; m[8] = tmp; + tmp = m[6]; m[6] = m[9]; m[9] = tmp; + tmp = m[3]; m[3] = m[12]; m[12] = tmp; + tmp = m[7]; m[7] = m[13]; m[13] = tmp; + tmp = m[11]; m[11] = m[14]; m[14] = tmp; +} + +Matrix4 Matrix4::getTransposed() const { + Matrix4 mat(*this); + mat.transpose(); + return mat; +} + +void Matrix4::add(float scalar) +{ + add(scalar, this); +} + +void Matrix4::add(float scalar, Matrix4* dst) const +{ + assert(dst); + dst->m[0] = this->m[0] + scalar; + dst->m[1] = this->m[1] + scalar; + dst->m[2] = this->m[2] + scalar; + dst->m[3] = this->m[3] + scalar; + dst->m[4] = this->m[4] + scalar; + dst->m[5] = this->m[5] + scalar; + dst->m[6] = this->m[6] + scalar; + dst->m[7] = this->m[7] + scalar; + dst->m[8] = this->m[8] + scalar; + dst->m[9] = this->m[9] + scalar; + dst->m[10] = this->m[10] + scalar; + dst->m[11] = this->m[11] + scalar; + dst->m[12] = this->m[12] + scalar; + dst->m[13] = this->m[13] + scalar; + dst->m[14] = this->m[14] + scalar; + dst->m[15] = this->m[15] + scalar; +} + +void Matrix4::add(const Matrix4& mat) +{ + add(*this, mat, this); +} + +void Matrix4::add(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) +{ + assert(dst); + dst->m[0] = m1.m[0] + m2.m[0]; + dst->m[1] = m1.m[1] + m2.m[1]; + dst->m[2] = m1.m[2] + m2.m[2]; + dst->m[3] = m1.m[3] + m2.m[3]; + dst->m[4] = m1.m[4] + m2.m[4]; + dst->m[5] = m1.m[5] + m2.m[5]; + dst->m[6] = m1.m[6] + m2.m[6]; + dst->m[7] = m1.m[7] + m2.m[7]; + dst->m[8] = m1.m[8] + m2.m[8]; + dst->m[9] = m1.m[9] + m2.m[9]; + dst->m[10] = m1.m[10] + m2.m[10]; + dst->m[11] = m1.m[11] + m2.m[11]; + dst->m[12] = m1.m[12] + m2.m[12]; + dst->m[13] = m1.m[13] + m2.m[13]; + dst->m[14] = m1.m[14] + m2.m[14]; + dst->m[15] = m1.m[15] + m2.m[15]; +} + +void Matrix4::subtract(const Matrix4& mat) +{ + subtract(*this, mat, this); +} + +void Matrix4::subtract(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) +{ + assert(dst); + dst->m[0] = m1.m[0] - m2.m[0]; + dst->m[1] = m1.m[1] - m2.m[1]; + dst->m[2] = m1.m[2] - m2.m[2]; + dst->m[3] = m1.m[3] - m2.m[3]; + dst->m[4] = m1.m[4] - m2.m[4]; + dst->m[5] = m1.m[5] - m2.m[5]; + dst->m[6] = m1.m[6] - m2.m[6]; + dst->m[7] = m1.m[7] - m2.m[7]; + dst->m[8] = m1.m[8] - m2.m[8]; + dst->m[9] = m1.m[9] - m2.m[9]; + dst->m[10] = m1.m[10] - m2.m[10]; + dst->m[11] = m1.m[11] - m2.m[11]; + dst->m[12] = m1.m[12] - m2.m[12]; + dst->m[13] = m1.m[13] - m2.m[13]; + dst->m[14] = m1.m[14] - m2.m[14]; + dst->m[15] = m1.m[15] - m2.m[15]; +} + +void Matrix4::multiply(float scalar) +{ + multiply(scalar, this); +} + +void Matrix4::multiply(float scalar, Matrix4* dst) const +{ + multiply(*this, scalar, dst); +} + +void Matrix4::multiply(const Matrix4& mat, float scalar, Matrix4* dst) +{ + assert(dst); + dst->m[0] = mat.m[0] * scalar; + dst->m[1] = mat.m[1] * scalar; + dst->m[2] = mat.m[2] * scalar; + dst->m[3] = mat.m[3] * scalar; + dst->m[4] = mat.m[4] * scalar; + dst->m[5] = mat.m[5] * scalar; + dst->m[6] = mat.m[6] * scalar; + dst->m[7] = mat.m[7] * scalar; + dst->m[8] = mat.m[8] * scalar; + dst->m[9] = mat.m[9] * scalar; + dst->m[10] = mat.m[10] * scalar; + dst->m[11] = mat.m[11] * scalar; + dst->m[12] = mat.m[12] * scalar; + dst->m[13] = mat.m[13] * scalar; + dst->m[14] = mat.m[14] * scalar; + dst->m[15] = mat.m[15] * scalar; +} + +void Matrix4::multiply(const Matrix4& mat) +{ + multiply(*this, mat, this); +} + +void Matrix4::multiply(const Matrix4& m1, const Matrix4& m2, Matrix4* dst) +{ + assert(dst); + dst->m[0] = m1.m[0] * m2.m[0]; + dst->m[1] = m1.m[1] * m2.m[1]; + dst->m[2] = m1.m[2] * m2.m[2]; + dst->m[3] = m1.m[3] * m2.m[3]; + dst->m[4] = m1.m[4] * m2.m[4]; + dst->m[5] = m1.m[5] * m2.m[5]; + dst->m[6] = m1.m[6] * m2.m[6]; + dst->m[7] = m1.m[7] * m2.m[7]; + dst->m[8] = m1.m[8] * m2.m[8]; + dst->m[9] = m1.m[9] * m2.m[9]; + dst->m[10] = m1.m[10] * m2.m[10]; + dst->m[11] = m1.m[11] * m2.m[11]; + dst->m[12] = m1.m[12] * m2.m[12]; + dst->m[13] = m1.m[13] * m2.m[13]; + dst->m[14] = m1.m[14] * m2.m[14]; + dst->m[15] = m1.m[15] * m2.m[15]; +} + +const Matrix4 Matrix4::operator+(const Matrix4& mat) const +{ + Matrix4 result(*this); + result.add(mat); + return result; +} + +Matrix4& Matrix4::operator+=(const Matrix4& mat) +{ + add(mat); + return *this; +} + +const Matrix4 Matrix4::operator-(const Matrix4& mat) const +{ + Matrix4 result(*this); + result.subtract(mat); + return result; +} + +Matrix4& Matrix4::operator-=(const Matrix4& mat) +{ + subtract(mat); + return *this; +} + +const Matrix4 Matrix4::operator-() const +{ + Matrix4 mat(*this); + mat.negate(); + return mat; +} + +const Matrix4 Matrix4::operator*(const Matrix4& mat) const +{ + Matrix4 result(*this); + result.multiply(mat); + return result; +} + +Matrix4& Matrix4::operator*=(const Matrix4& mat) +{ + multiply(mat); + return *this; +} + +const Matrix4 Matrix4::operator+(float scalar) const +{ + Matrix4 result(*this); + result.add(scalar); + return result; +} + +Matrix4& Matrix4::operator+=(float scalar) +{ + add(scalar); + return *this; +} + +const Matrix4 Matrix4::operator-(float scalar) const +{ + Matrix4 result(*this); + result.add(-scalar); + return result; +} + +Matrix4& Matrix4::operator-=(float scalar) +{ + add(-scalar); + return *this; +} + +const Matrix4 Matrix4::operator*(float scalar) const +{ + Matrix4 result(*this); + result.multiply(scalar); + return result; +} + +Matrix4& Matrix4::operator*=(float scalar) +{ + multiply(scalar); + return *this; +} + +NS_GI_END + diff --git a/src/math/Matrix4.hpp b/src/math/Matrix4.hpp new file mode 100644 index 0000000..a9acd0e --- /dev/null +++ b/src/math/Matrix4.hpp @@ -0,0 +1,80 @@ +/* + * GPUImage-x + * + * Copyright (C) 2017 Yijin Wang, Yiqian Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef Matrix4_hpp +#define Matrix4_hpp + +#include "../macros.h" + +NS_GI_BEGIN + +class Matrix4 { +public: + float m[16]; + Matrix4(); + Matrix4(const float* mat); + Matrix4(float m11, float m12, float m13, float m14, float m21, float m22, float m23,float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44); + Matrix4(const Matrix4& copy); + ~Matrix4(); + + void set(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44); + void set(const float* mat); + void set(const Matrix4& mat); + void setIdentity(); + + void negate(); + Matrix4 getNegated() const; + + void transpose(); + Matrix4 getTransposed() const; + + void add(float scalar); + void add(float scalar, Matrix4* dst) const; + void add(const Matrix4& mat); + static void add(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); + + void subtract(const Matrix4& mat); + static void subtract(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); + + void multiply(float scalar); + void multiply(float scalar, Matrix4* dst) const; + static void multiply(const Matrix4& mat, float scalar, Matrix4* dst); + void multiply(const Matrix4& mat); + static void multiply(const Matrix4& m1, const Matrix4& m2, Matrix4* dst); + + const Matrix4 operator+(const Matrix4& mat) const; + Matrix4& operator+=(const Matrix4& mat); + const Matrix4 operator-(const Matrix4& mat) const; + Matrix4& operator-=(const Matrix4& mat); + const Matrix4 operator-() const; + const Matrix4 operator*(const Matrix4& mat) const; + Matrix4& operator*=(const Matrix4& mat); + + const Matrix4 operator+(float scalar) const; + Matrix4& operator+=(float scalar); + const Matrix4 operator-(float scalar) const; + Matrix4& operator-=(float scalar); + const Matrix4 operator*(float scalar) const; + Matrix4& operator*=(float scalar); + + static const Matrix4 IDENTITY; +}; + +NS_GI_END + +#endif /* Matrix4_hpp */ diff --git a/src/math/Vector2.cpp b/src/math/Vector2.cpp new file mode 100755 index 0000000..201e38e --- /dev/null +++ b/src/math/Vector2.cpp @@ -0,0 +1,226 @@ +/* + * GPUImage-x + * + * Copyright (C) 2017 Yijin Wang, Yiqian Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "Vector2.hpp" + +NS_GI_BEGIN + +Vector2::Vector2() +: x(0.0f), y(0.0f) +{ +} + +Vector2::Vector2(float xx, float yy) +: x(xx), y(yy) +{ +} + +Vector2::Vector2(const float* array) +{ + set(array); +} + +Vector2::Vector2(const Vector2& p1, const Vector2& p2) +{ + set(p1, p2); +} + +Vector2::Vector2(const Vector2& copy) +{ + set(copy); +} + +Vector2::~Vector2() +{ +} + +bool Vector2::isZero() const +{ + return x == 0.0f && y == 0.0f; +} + +bool Vector2::isOne() const +{ + return x == 1.0f && y == 1.0f; +} + +void Vector2::add(const Vector2& v) +{ + x += v.x; + y += v.y; +} + +float Vector2::distanceSquared(const Vector2& v) const +{ + float dx = v.x - x; + float dy = v.y - y; + return (dx * dx + dy * dy); +} + +float Vector2::dot(const Vector2& v) const +{ + return (x * v.x + y * v.y); +} + +float Vector2::lengthSquared() const +{ + return (x * x + y * y); +} + +void Vector2::negate() +{ + x = -x; + y = -y; +} + +void Vector2::scale(float scalar) +{ + x *= scalar; + y *= scalar; +} + +void Vector2::scale(const Vector2& scale) +{ + x *= scale.x; + y *= scale.y; +} + +void Vector2::set(float xx, float yy) +{ + this->x = xx; + this->y = yy; +} + +void Vector2::set(const Vector2& v) +{ + this->x = v.x; + this->y = v.y; +} + +void Vector2::set(const Vector2& p1, const Vector2& p2) +{ + x = p2.x - p1.x; + y = p2.y - p1.y; +} + +void Vector2::setZero() +{ + x = y = 0.0f; +} + +void Vector2::subtract(const Vector2& v) +{ + x -= v.x; + y -= v.y; +} + +void Vector2::smooth(const Vector2& target, float elapsedTime, float responseTime) +{ + if (elapsedTime > 0) + { + *this += (target - *this) * (elapsedTime / (elapsedTime + responseTime)); + } +} + +const Vector2 Vector2::operator+(const Vector2& v) const +{ + Vector2 result(*this); + result.add(v); + return result; +} + +Vector2& Vector2::operator+=(const Vector2& v) +{ + add(v); + return *this; +} + +const Vector2 Vector2::operator-(const Vector2& v) const +{ + Vector2 result(*this); + result.subtract(v); + return result; +} + +Vector2& Vector2::operator-=(const Vector2& v) +{ + subtract(v); + return *this; +} + +const Vector2 Vector2::operator-() const +{ + Vector2 result(*this); + result.negate(); + return result; +} + +const Vector2 Vector2::operator*(float s) const +{ + Vector2 result(*this); + result.scale(s); + return result; +} + +Vector2& Vector2::operator*=(float s) +{ + scale(s); + return *this; +} + +const Vector2 Vector2::operator/(const float s) const +{ + return Vector2(this->x / s, this->y / s); +} + +bool Vector2::operator<(const Vector2& v) const +{ + if (x == v.x) + { + return y < v.y; + } + return x < v.x; +} + +bool Vector2::operator>(const Vector2& v) const +{ + if (x == v.x) + { + return y > v.y; + } + return x > v.x; +} + +bool Vector2::operator==(const Vector2& v) const +{ + return x==v.x && y==v.y; +} + +bool Vector2::operator!=(const Vector2& v) const +{ + return x!=v.x || y!=v.y; +} + +const Vector2 operator*(float x, const Vector2& v) +{ + Vector2 result(v); + result.scale(x); + return result; +} + +NS_GI_END diff --git a/src/math/Vector2.hpp b/src/math/Vector2.hpp new file mode 100644 index 0000000..e8a1c50 --- /dev/null +++ b/src/math/Vector2.hpp @@ -0,0 +1,82 @@ +/* + * GPUImage-x + * + * Copyright (C) 2017 Yijin Wang, Yiqian Wang + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef Vector2_hpp +#define Vector2_hpp + +#include "../macros.h" + +NS_GI_BEGIN + +class Vector2 +{ +public: + + float x; + float y; + + Vector2(); + Vector2(float xx, float yy); + Vector2(const float* array); + Vector2(const Vector2& p1, const Vector2& p2); + Vector2(const Vector2& copy); + ~Vector2(); + + bool isZero() const; + bool isOne() const; + static float angle(const Vector2& v1, const Vector2& v2); + void add(const Vector2& v); + static void add(const Vector2& v1, const Vector2& v2, Vector2* dst); + void clamp(const Vector2& min, const Vector2& max); + static void clamp(const Vector2& v, const Vector2& min, const Vector2& max, Vector2* dst); + float distance(const Vector2& v) const; + float distanceSquared(const Vector2& v) const; + float dot(const Vector2& v) const; + static float dot(const Vector2& v1, const Vector2& v2); + float length() const; + float lengthSquared() const; + void negate(); + void normalize(); + Vector2 getNormalized() const; + void scale(float scalar); + void scale(const Vector2& scale); + void rotate(const Vector2& point, float angle); + void set(float xx, float yy); + void set(const Vector2& v); + void set(const Vector2& p1, const Vector2& p2); + void setZero(); + void subtract(const Vector2& v); + static void subtract(const Vector2& v1, const Vector2& v2, Vector2* dst); + void smooth(const Vector2& target, float elapsedTime, float responseTime); + const Vector2 operator+(const Vector2& v) const; + Vector2& operator+=(const Vector2& v); + const Vector2 operator-(const Vector2& v) const; + Vector2& operator-=(const Vector2& v); + const Vector2 operator-() const; + const Vector2 operator*(float s) const; + Vector2& operator*=(float s); + const Vector2 operator/(float s) const; + bool operator<(const Vector2& v) const; + bool operator>(const Vector2& v) const; + bool operator==(const Vector2& v) const; + bool operator!=(const Vector2& v) const; +}; + +NS_GI_END + +#endif /* Vector2_hpp */ diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/Source.cpp b/src/source/Source.cpp similarity index 86% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/Source.cpp rename to src/source/Source.cpp index 175a3da..774e4bd 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/Source.cpp +++ b/src/source/Source.cpp @@ -30,7 +30,6 @@ NS_GI_BEGIN Source::Source() :_framebuffer(0) ,_outputRotation(RotationMode::NoRotation) -,_framebufferScale(1.0) { } @@ -116,7 +115,7 @@ void Source::updateTargets(float frameTime) { } } -unsigned char* Source::captureAProcessedFrameData(Filter* upToFilter, int width/* = 0*/, int height/* = 0*/) { +uint8_t* Source::captureAProcessedFrameData(Filter* upToFilter, int width/* = 0*/, int height/* = 0*/) { if (Context::getInstance()->isCapturingFrame) return 0 ; if (width <= 0 || height <= 0) { @@ -131,7 +130,7 @@ unsigned char* Source::captureAProcessedFrameData(Filter* upToFilter, int width/ Context::getInstance()->captureUpToFilter = upToFilter; proceed(true); - unsigned char* processedFrameData = Context::getInstance()->capturedFrameData; + uint8_t* processedFrameData = Context::getInstance()->capturedFrameData; Context::getInstance()->capturedFrameData = 0; Context::getInstance()->captureWidth = 0; @@ -141,14 +140,27 @@ unsigned char* Source::captureAProcessedFrameData(Filter* upToFilter, int width/ return processedFrameData; } +void Source::forceProcessingAtSize(int width, int height) { + +} + +void Source::setFramebufferScale(float framebufferScale) { + float width = _framebuffer->getWidth(); + float height = _framebuffer->getHeight(); + + forceProcessingAtSize(framebufferScale * width, framebufferScale * height); +} + void Source::setFramebuffer(Framebuffer* fb, RotationMode outputRotation/* = RotationMode::NoRotation*/) { - if (_framebuffer != fb && _framebuffer != 0) { - _framebuffer->release(); - _framebuffer = 0; + if (fb != _framebuffer) { + if (_framebuffer) { + _framebuffer->release(); + _framebuffer = 0; + } + _framebuffer = fb; + if (_framebuffer) + _framebuffer->retain(); } - _framebuffer = fb; - if (_framebuffer) - _framebuffer->retain(); _outputRotation = outputRotation; } diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/Source.hpp b/src/source/Source.hpp similarity index 86% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/Source.hpp rename to src/source/Source.hpp index 59654ad..d1e04ca 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/Source.hpp +++ b/src/source/Source.hpp @@ -21,14 +21,14 @@ #include "../macros.h" #include "../target/Target.hpp" -#include -#include -#include "../target/Target.hpp" #if PLATFORM == PLATFORM_IOS -#import "GPUImageTarget.h" +#import "../target/iOS/GPUImageTarget.h" #endif +#include +#include + NS_GI_BEGIN class Filter; @@ -50,20 +50,21 @@ class Source : public virtual Ref { virtual Framebuffer* getFramebuffer() const; virtual void releaseFramebuffer(bool returnToCache = true); - void setFramebufferScale(float framebufferScale) { _framebufferScale = framebufferScale; } + virtual void forceProcessingAtSize(int width, int height); + virtual void setFramebufferScale(float framebufferScale); + int getRotatedFramebufferWidth() const; int getRotatedFramebufferHeight() const; virtual bool proceed(bool bUpdateTargets = true); virtual void updateTargets(float frameTime); - virtual unsigned char* captureAProcessedFrameData(Filter* upToFilter, int width = 0, int height = 0); + virtual uint8_t* captureAProcessedFrameData(Filter* upToFilter, int width = 0, int height = 0); protected: Framebuffer* _framebuffer; RotationMode _outputRotation; std::map _targets; - float _framebufferScale; }; diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceCamera.cpp b/src/source/SourceCamera.cpp similarity index 94% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceCamera.cpp rename to src/source/SourceCamera.cpp index a343047..0411dd5 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/source/SourceCamera.cpp +++ b/src/source/SourceCamera.cpp @@ -64,12 +64,14 @@ void SourceCamera::setFrameData(int width, int height, const void* pixels, Rotat CHECK_GL(glBindTexture(GL_TEXTURE_2D, 0)); } -#if PLATFORM == PLATFORM_IOS -bool SourceCamera::init() { - if (isCameraExist(AVCaptureDevicePositionFront)) - return init(AVCaptureSessionPreset640x480, AVCaptureDevicePositionFront); - else - return init(AVCaptureSessionPreset640x480, AVCaptureDevicePositionBack); +#if PLATFORM == PLATFORM_IOS + +bool SourceCamera::init() { + return init(AVCaptureSessionPreset1920x1080); +}; + +bool SourceCamera::init(AVCaptureSessionPreset preset) { + return init(preset, AVCaptureDevicePositionBack); } bool SourceCamera::init(NSString* sessionPreset, AVCaptureDevicePosition cameraPosition) { @@ -90,7 +92,9 @@ bool SourceCamera::init(NSString* sessionPreset, AVCaptureDevicePosition cameraP break; } } - if (!device) return false; + if (!device) return false; + + _fieldOfView = device.activeFormat.videoFieldOfView; NSError *error = nil; _captureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:device error:&error]; @@ -205,6 +209,11 @@ bool SourceCamera::flip() { AVCaptureDevicePosition SourceCamera::getCameraPosition() { return [[_captureDeviceInput device] position]; +} + +float SourceCamera::getFieldOfView() +{ + return _fieldOfView; } void SourceCamera::setOutputImageOrientation(UIInterfaceOrientation orientation) { diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceCamera.h b/src/source/SourceCamera.h similarity index 92% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceCamera.h rename to src/source/SourceCamera.h index 856f9a3..abb16e5 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceCamera.h +++ b/src/source/SourceCamera.h @@ -38,8 +38,9 @@ class SourceCamera : public Source{ static SourceCamera* create(); void setFrameData(int width, int height, const void* pixels, RotationMode outputRotation = RotationMode::NoRotation); -#if PLATFORM == PLATFORM_IOS +#if PLATFORM == PLATFORM_IOS bool init(); + bool init(AVCaptureSessionPreset preset); bool init(NSString* sessionPreset, AVCaptureDevicePosition cameraPosition); static bool isCameraExist(AVCaptureDevicePosition cameraPosition); void start(); @@ -47,7 +48,9 @@ class SourceCamera : public Source{ void pause(); void resume(); bool isRunning(); - bool flip(); + bool flip(); + + float getFieldOfView(); AVCaptureDevicePosition getCameraPosition(); void setOutputImageOrientation(UIInterfaceOrientation orientation); @@ -59,7 +62,8 @@ class SourceCamera : public Source{ #if PLATFORM == PLATFORM_IOS VideoDataOutputSampleBufferDelegate* _videoDataOutputSampleBufferDelegate; AVCaptureSession* _captureSession; - BOOL _capturePaused; + BOOL _capturePaused; + float _fieldOfView; GPUImage::RotationMode _outputRotation; //GPUImage::RotationMode internalRotation; AVCaptureDeviceInput* _captureDeviceInput; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceImage.cpp b/src/source/SourceImage.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceImage.cpp rename to src/source/SourceImage.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceImage.h b/src/source/SourceImage.h similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/source/SourceImage.h rename to src/source/SourceImage.h diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/Target.cpp b/src/target/Target.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/Target.cpp rename to src/target/Target.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/Target.hpp b/src/target/Target.hpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/Target.hpp rename to src/target/Target.hpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/TargetView.cpp b/src/target/TargetView.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/TargetView.cpp rename to src/target/TargetView.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/TargetView.h b/src/target/TargetView.h similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/TargetView.h rename to src/target/TargetView.h diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageTarget.h b/src/target/iOS/GPUImageTarget.h similarity index 94% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageTarget.h rename to src/target/iOS/GPUImageTarget.h index 1e02aea..0145970 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageTarget.h +++ b/src/target/iOS/GPUImageTarget.h @@ -19,8 +19,9 @@ #if PLATFORM == PLATFORM_IOS #import -#include "Framebuffer.hpp" -#include "Target.hpp" + +#include "../../Framebuffer.hpp" +#include "../Target.hpp" @protocol GPUImageTarget diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageTarget.mm b/src/target/iOS/GPUImageTarget.mm similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageTarget.mm rename to src/target/iOS/GPUImageTarget.mm diff --git a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageView.h b/src/target/iOS/GPUImageView.h similarity index 96% rename from GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageView.h rename to src/target/iOS/GPUImageView.h index fa92345..faf03e5 100755 --- a/GPUImage-x/proj.iOS/GPUImage-x/GPUImage-x/target/iOS/GPUImageView.h +++ b/src/target/iOS/GPUImageView.h @@ -19,8 +19,9 @@ #if PLATFORM == PLATFORM_IOS #import + +#import "../TargetView.h" #import "GPUImageTarget.h" -#include "TargetView.h" @interface GPUImageView : UIView diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageView.mm b/src/target/iOS/GPUImageView.mm similarity index 99% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageView.mm rename to src/target/iOS/GPUImageView.mm index 2ad8f20..67d9631 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/GPUImageView.mm +++ b/src/target/iOS/GPUImageView.mm @@ -72,6 +72,7 @@ - (void)commonInit; self.opaque = YES; self.hidden = NO; CAEAGLLayer* eaglLayer = (CAEAGLLayer*)self.layer; + eaglLayer.contentsScale = [[UIScreen mainScreen] scale]; eaglLayer.opaque = YES; eaglLayer.drawableProperties = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], kEAGLDrawablePropertyRetainedBacking, kEAGLColorFormatRGBA8, kEAGLDrawablePropertyColorFormat, nil]; diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/IOSTarget.cpp b/src/target/iOS/IOSTarget.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/IOSTarget.cpp rename to src/target/iOS/IOSTarget.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/IOSTarget.hpp b/src/target/iOS/IOSTarget.hpp similarity index 98% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/IOSTarget.hpp rename to src/target/iOS/IOSTarget.hpp index 430e198..12c7dc1 100755 --- a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/target/iOS/IOSTarget.hpp +++ b/src/target/iOS/IOSTarget.hpp @@ -21,7 +21,7 @@ #ifndef IOSTarget_hpp #define IOSTarget_hpp -#include "Target.hpp" +#include "../Target.hpp" #import "GPUImageTarget.h" NS_GI_BEGIN diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/util.cpp b/src/util.cpp similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/util.cpp rename to src/util.cpp diff --git a/GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/util.h b/src/util.h similarity index 100% rename from GPUImage-x/proj.android/GPUImage-x/library/src/main/cpp/util.h rename to src/util.h