├── .gitignore
├── CHANGELOG.md
├── README.md
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── library
├── AndroidManifest.xml
├── build.gradle
├── gradle.properties
├── jni
│ ├── Android.mk
│ ├── Application.mk
│ └── yuv-decoder.c
├── proguard-rules.txt
├── project.properties
└── src
│ └── jp
│ └── co
│ └── cyberagent
│ └── android
│ └── gpuimage
│ ├── GPUImage.java
│ ├── GPUImage3x3ConvolutionFilter.java
│ ├── GPUImage3x3TextureSamplingFilter.java
│ ├── GPUImageAddBlendFilter.java
│ ├── GPUImageAlphaBlendFilter.java
│ ├── GPUImageBilateralFilter.java
│ ├── GPUImageBoxBlurFilter.java
│ ├── GPUImageBrightnessFilter.java
│ ├── GPUImageBulgeDistortionFilter.java
│ ├── GPUImageCGAColorspaceFilter.java
│ ├── GPUImageChromaKeyBlendFilter.java
│ ├── GPUImageColorBalanceFilter.java
│ ├── GPUImageColorBlendFilter.java
│ ├── GPUImageColorBurnBlendFilter.java
│ ├── GPUImageColorDodgeBlendFilter.java
│ ├── GPUImageColorInvertFilter.java
│ ├── GPUImageColorMatrixFilter.java
│ ├── GPUImageContrastFilter.java
│ ├── GPUImageCrosshatchFilter.java
│ ├── GPUImageDarkenBlendFilter.java
│ ├── GPUImageDifferenceBlendFilter.java
│ ├── GPUImageDilationFilter.java
│ ├── GPUImageDirectionalSobelEdgeDetectionFilter.java
│ ├── GPUImageDissolveBlendFilter.java
│ ├── GPUImageDivideBlendFilter.java
│ ├── GPUImageEmbossFilter.java
│ ├── GPUImageExclusionBlendFilter.java
│ ├── GPUImageExposureFilter.java
│ ├── GPUImageFalseColorFilter.java
│ ├── GPUImageFilter.java
│ ├── GPUImageFilterGroup.java
│ ├── GPUImageGammaFilter.java
│ ├── GPUImageGaussianBlurFilter.java
│ ├── GPUImageGlassSphereFilter.java
│ ├── GPUImageGrayscaleFilter.java
│ ├── GPUImageHalftoneFilter.java
│ ├── GPUImageHardLightBlendFilter.java
│ ├── GPUImageHazeFilter.java
│ ├── GPUImageHighlightShadowFilter.java
│ ├── GPUImageHueBlendFilter.java
│ ├── GPUImageHueFilter.java
│ ├── GPUImageKuwaharaFilter.java
│ ├── GPUImageLaplacianFilter.java
│ ├── GPUImageLevelsFilter.java
│ ├── GPUImageLightenBlendFilter.java
│ ├── GPUImageLinearBurnBlendFilter.java
│ ├── GPUImageLookupFilter.java
│ ├── GPUImageLuminosityBlendFilter.java
│ ├── GPUImageMixBlendFilter.java
│ ├── GPUImageMonochromeFilter.java
│ ├── GPUImageMovieWriter.java
│ ├── GPUImageMultiplyBlendFilter.java
│ ├── GPUImageNativeLibrary.java
│ ├── GPUImageNonMaximumSuppressionFilter.java
│ ├── GPUImageNormalBlendFilter.java
│ ├── GPUImageOpacityFilter.java
│ ├── GPUImageOverlayBlendFilter.java
│ ├── GPUImagePixelationFilter.java
│ ├── GPUImagePosterizeFilter.java
│ ├── GPUImageRGBDilationFilter.java
│ ├── GPUImageRGBFilter.java
│ ├── GPUImageRenderer.java
│ ├── GPUImageSaturationBlendFilter.java
│ ├── GPUImageSaturationFilter.java
│ ├── GPUImageScreenBlendFilter.java
│ ├── GPUImageSepiaFilter.java
│ ├── GPUImageSharpenFilter.java
│ ├── GPUImageSketchFilter.java
│ ├── GPUImageSmoothToonFilter.java
│ ├── GPUImageSobelEdgeDetection.java
│ ├── GPUImageSobelThresholdFilter.java
│ ├── GPUImageSoftLightBlendFilter.java
│ ├── GPUImageSourceOverBlendFilter.java
│ ├── GPUImageSphereRefractionFilter.java
│ ├── GPUImageSubtractBlendFilter.java
│ ├── GPUImageSwirlFilter.java
│ ├── GPUImageThresholdEdgeDetection.java
│ ├── GPUImageToneCurveFilter.java
│ ├── GPUImageToonFilter.java
│ ├── GPUImageTransformFilter.java
│ ├── GPUImageTwoInputFilter.java
│ ├── GPUImageTwoPassFilter.java
│ ├── GPUImageTwoPassTextureSamplingFilter.java
│ ├── GPUImageView.java
│ ├── GPUImageVignetteFilter.java
│ ├── GPUImageWeakPixelInclusionFilter.java
│ ├── GPUImageWhiteBalanceFilter.java
│ ├── OpenGlUtils.java
│ ├── PixelBuffer.java
│ ├── Rotation.java
│ ├── encoder
│ ├── EglCore.java
│ ├── EglSurfaceBase.java
│ ├── MediaAudioEncoder.java
│ ├── MediaEncoder.java
│ ├── MediaMuxerWrapper.java
│ ├── MediaVideoEncoder.java
│ └── WindowSurface.java
│ └── util
│ └── TextureRotationUtil.java
├── sample
├── AndroidManifest.xml
├── build.gradle
├── ic_launcher-web.png
├── proguard-project.txt
├── project.properties
├── res
│ ├── drawable-hdpi
│ │ ├── ic_action_search.png
│ │ ├── ic_launcher.png
│ │ └── ic_switch_camera.png
│ ├── drawable-ldpi
│ │ └── ic_launcher.png
│ ├── drawable-mdpi
│ │ ├── ic_action_search.png
│ │ └── ic_launcher.png
│ ├── drawable-nodpi
│ │ └── lookup_amatorka.png
│ ├── drawable-xhdpi
│ │ ├── ic_action_search.png
│ │ └── ic_launcher.png
│ ├── layout
│ │ ├── activity_camera.xml
│ │ ├── activity_gallery.xml
│ │ └── activity_main.xml
│ ├── raw
│ │ └── tone_cuver_sample.acv
│ ├── values-v11
│ │ └── styles.xml
│ ├── values-v14
│ │ └── styles.xml
│ └── values
│ │ ├── strings.xml
│ │ └── styles.xml
└── src
│ └── jp
│ └── co
│ └── cyberagent
│ └── android
│ └── gpuimage
│ └── sample
│ ├── GPUImageFilterTools.java
│ ├── activity
│ ├── ActivityCamera.java
│ ├── ActivityGallery.java
│ └── ActivityMain.java
│ └── utils
│ ├── CameraHelper.java
│ ├── CameraHelperBase.java
│ └── CameraHelperGB.java
├── settings.gradle
└── utils
└── Shader2String.py
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 | Thumbs.db
3 |
4 | # gradle files
5 | .gradle
6 |
7 | # Intellij project files
8 | .idea
9 | *.iml
10 |
11 | # generated files
12 | bin/
13 | gen/
14 | obj/
15 | apk/
16 | target/
17 | build/
18 |
19 | # Local configuration file (sdk path, etc)
20 | local.properties
21 |
22 | # Proguard folder generated by Eclipse
23 | proguard/
24 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | Change Log
2 | ==========
3 |
4 | Version 1.4.1 *(2016-03-15)*
5 | ----------------------------
6 |
7 | Using Bintray's JCenter.
8 |
9 |
10 | Version 1.4.0 *(2016-02-28)*
11 | ----------------------------
12 |
13 | * added GPUImageHalftoneFilter (by @ryohey)
14 | * added GPUImageTransformFilter (by @jonan)
15 | * fixed GPUImageChromaKeyBlendFilter (by @badjano)
16 | * fixed GPUImageLookupFilter (by @jonan)
17 |
18 | Version 1.3.0 *(2015-09-04)*
19 | ----------------------------
20 |
21 | * added GPUImageBilateralFilter (by @wysaid)
22 | * added flip options to `GPUImage#setRotation`
23 |
24 | Version 1.2.3-SNAPSHOT *(2014-12-15)*
25 | ----------------------------
26 |
27 | * added GPUImageLevelsFilter (by @vashisthg)
28 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # GPUImage for Android with Video Recording feature
2 | [](https://www.apache.org/licenses/LICENSE-2.0)
3 |
4 | Idea from: [iOS GPUImage framework](https://github.com/BradLarson/GPUImage)
5 | Base on: [Android GPUImage framework](https://github.com/CyberAgent/android-gpuimage)
6 |
7 | ## Requirements
8 | * Android 4.3 or higher (OpenGL ES 2.0)
9 |
10 | ## Concept
11 | 1. draw on current screen surface
12 | 2. switch to encoder input surface and draw previous frame buffer again on it
13 | 3. switch back to screen surface
14 |
15 | ## Reference
16 | 1. EGL surface helper: https://github.com/google/grafika
17 | 2. Media encoder: https://github.com/saki4510t/AudioVideoRecordingSample
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | jcenter()
6 | }
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.1.0-beta1'
9 | classpath 'com.novoda:bintray-release:0.3.4'
10 | }
11 | }
12 |
13 | allprojects {
14 | repositories {
15 | jcenter()
16 | maven { url("https://oss.sonatype.org/content/repositories/snapshots/") }
17 | }
18 | tasks.withType(JavaCompile) {
19 | options.encoding = 'UTF-8'
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | VERSION_NAME=1.4.1
2 | GROUP=jp.co.cyberagent.android.gpuimage
3 | ARTIFACT_ID=gpuimage-library
4 |
5 | COMPILE_SDK_VERSION=23
6 | BUILD_TOOLS_VERSION=23.0.2
7 | TARGET_SDK_VERSION=23
8 | MIN_SDK_VERSION=8
9 |
10 | POM_DESCRIPTION=Image filters for Android with OpenGL (based on GPUImage for iOS)
11 | POM_URL=https://github.com/cyberagent/android-gpuimage
12 | POM_SCM_URL=scm:git@github.com:CyberAgent/android-gpuimage.git
13 | POM_SCM_CONNECTION=scm:git@github.com:CyberAgent/android-gpuimage.git
14 | POM_SCM_DEV_CONNECTION=scm:git@github.com:CyberAgent/android-gpuimage.git
15 | POM_LICENCE_NAME=The Apache Software License, Version 2.0
16 | POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt
17 | POM_LICENCE_DIST=repo
18 | POM_DEVELOPER_ID=cyberagent
19 | POM_DEVELOPER_NAME=CyberAgent, Inc.
20 | ISSUE_URL=https://github.com/CyberAgent/android-gpuimage/issues
21 |
22 | android.useDeprecatedNdk=true
23 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/westbrett/android-gpuimage-videorecording/188fc974da8cc961d10bdf1236e085677d23f60a/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Dec 06 18:27:05 JST 2014
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.11-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/library/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 | *
24 | * contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level
25 | */
26 | public class GPUImageContrastFilter extends GPUImageFilter {
27 | public static final String CONTRAST_FRAGMENT_SHADER = "" +
28 | "varying highp vec2 textureCoordinate;\n" +
29 | " \n" +
30 | " uniform sampler2D inputImageTexture;\n" +
31 | " uniform lowp float contrast;\n" +
32 | " \n" +
33 | " void main()\n" +
34 | " {\n" +
35 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
36 | " \n" +
37 | " gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n" +
38 | " }";
39 |
40 | private int mContrastLocation;
41 | private float mContrast;
42 |
43 | public GPUImageContrastFilter() {
44 | this(1.2f);
45 | }
46 |
47 | public GPUImageContrastFilter(float contrast) {
48 | super(NO_FILTER_VERTEX_SHADER, CONTRAST_FRAGMENT_SHADER);
49 | mContrast = contrast;
50 | }
51 |
52 | @Override
53 | public void onInit() {
54 | super.onInit();
55 | mContrastLocation = GLES20.glGetUniformLocation(getProgram(), "contrast");
56 | }
57 |
58 | @Override
59 | public void onInitialized() {
60 | super.onInitialized();
61 | setContrast(mContrast);
62 | }
63 |
64 | public void setContrast(final float contrast) {
65 | mContrast = contrast;
66 | setFloat(mContrastLocation, mContrast);
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageDarkenBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageDarkenBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String DARKEN_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " lowp vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " lowp vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " gl_FragColor = vec4(min(overlayer.rgb * base.a, base.rgb * overlayer.a) + overlayer.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlayer.a), 1.0);\n" +
32 | " }";
33 |
34 | public GPUImageDarkenBlendFilter() {
35 | super(DARKEN_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageDifferenceBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageDifferenceBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String DIFFERENCE_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " gl_FragColor = vec4(abs(textureColor2.rgb - textureColor.rgb), textureColor.a);\n" +
31 | " }";
32 |
33 | public GPUImageDifferenceBlendFilter() {
34 | super(DIFFERENCE_BLEND_FRAGMENT_SHADER);
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageDirectionalSobelEdgeDetectionFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 |
20 | public class GPUImageDirectionalSobelEdgeDetectionFilter extends GPUImage3x3TextureSamplingFilter {
21 | public static final String DIRECTIONAL_SOBEL_EDGE_DETECTION_FRAGMENT_SHADER = "" +
22 | "precision mediump float;\n" +
23 | "\n" +
24 | "varying vec2 textureCoordinate;\n" +
25 | "varying vec2 leftTextureCoordinate;\n" +
26 | "varying vec2 rightTextureCoordinate;\n" +
27 | "\n" +
28 | "varying vec2 topTextureCoordinate;\n" +
29 | "varying vec2 topLeftTextureCoordinate;\n" +
30 | "varying vec2 topRightTextureCoordinate;\n" +
31 | "\n" +
32 | "varying vec2 bottomTextureCoordinate;\n" +
33 | "varying vec2 bottomLeftTextureCoordinate;\n" +
34 | "varying vec2 bottomRightTextureCoordinate;\n" +
35 | "\n" +
36 | "uniform sampler2D inputImageTexture;\n" +
37 | "\n" +
38 | "void main()\n" +
39 | "{\n" +
40 | " float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n" +
41 | " float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n" +
42 | " float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n" +
43 | " float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n" +
44 | " float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n" +
45 | " float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n" +
46 | " float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n" +
47 | " float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n" +
48 | "\n" +
49 | " vec2 gradientDirection;\n" +
50 | " gradientDirection.x = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n" +
51 | " gradientDirection.y = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n" +
52 | "\n" +
53 | " float gradientMagnitude = length(gradientDirection);\n" +
54 | " vec2 normalizedDirection = normalize(gradientDirection);\n" +
55 | " normalizedDirection = sign(normalizedDirection) * floor(abs(normalizedDirection) + 0.617316); // Offset by 1-sin(pi/8) to set to 0 if near axis, 1 if away\n" +
56 | " normalizedDirection = (normalizedDirection + 1.0) * 0.5; // Place -1.0 - 1.0 within 0 - 1.0\n" +
57 | "\n" +
58 | " gl_FragColor = vec4(gradientMagnitude, normalizedDirection.x, normalizedDirection.y, 1.0);\n" +
59 | "}";
60 |
61 | public GPUImageDirectionalSobelEdgeDetectionFilter() {
62 | super(DIRECTIONAL_SOBEL_EDGE_DETECTION_FRAGMENT_SHADER);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageDissolveBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Mix ranges from 0.0 (only image 1) to 1.0 (only image 2), with 0.5 (half of either) as the normal level
23 | */
24 | public class GPUImageDissolveBlendFilter extends GPUImageMixBlendFilter{
25 | public static final String DISSOLVE_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
26 | " varying highp vec2 textureCoordinate2;\n" +
27 | "\n" +
28 | " uniform sampler2D inputImageTexture;\n" +
29 | " uniform sampler2D inputImageTexture2;\n" +
30 | " uniform lowp float mixturePercent;\n" +
31 | " \n" +
32 | " void main()\n" +
33 | " {\n" +
34 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
35 | " lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
36 | " \n" +
37 | " gl_FragColor = mix(textureColor, textureColor2, mixturePercent);\n" +
38 | " }";
39 |
40 | public GPUImageDissolveBlendFilter() {
41 | super(DISSOLVE_BLEND_FRAGMENT_SHADER);
42 | }
43 |
44 | public GPUImageDissolveBlendFilter(float mix) {
45 | super(DISSOLVE_BLEND_FRAGMENT_SHADER, mix);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageDivideBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageDivideBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String DIVIDE_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " mediump float ra;\n" +
32 | " if (overlay.a == 0.0 || ((base.r / overlay.r) > (base.a / overlay.a)))\n" +
33 | " ra = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);\n" +
34 | " else\n" +
35 | " ra = (base.r * overlay.a * overlay.a) / overlay.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);\n" +
36 | " \n" +
37 | "\n" +
38 | " mediump float ga;\n" +
39 | " if (overlay.a == 0.0 || ((base.g / overlay.g) > (base.a / overlay.a)))\n" +
40 | " ga = overlay.a * base.a + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);\n" +
41 | " else\n" +
42 | " ga = (base.g * overlay.a * overlay.a) / overlay.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);\n" +
43 | "\n" +
44 | " \n" +
45 | " mediump float ba;\n" +
46 | " if (overlay.a == 0.0 || ((base.b / overlay.b) > (base.a / overlay.a)))\n" +
47 | " ba = overlay.a * base.a + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);\n" +
48 | " else\n" +
49 | " ba = (base.b * overlay.a * overlay.a) / overlay.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);\n" +
50 | "\n" +
51 | " mediump float a = overlay.a + base.a - overlay.a * base.a;\n" +
52 | " \n" +
53 | " gl_FragColor = vec4(ra, ga, ba, a);\n" +
54 | " }";
55 |
56 | public GPUImageDivideBlendFilter() {
57 | super(DIVIDE_BLEND_FRAGMENT_SHADER);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageEmbossFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | /**
20 | * Applies an emboss effect to the image.
21 | *
22 | * Intensity ranges from 0.0 to 4.0, with 1.0 as the normal level
23 | */
24 | public class GPUImageEmbossFilter extends GPUImage3x3ConvolutionFilter {
25 | private float mIntensity;
26 |
27 | public GPUImageEmbossFilter() {
28 | this(1.0f);
29 | }
30 |
31 | public GPUImageEmbossFilter(final float intensity) {
32 | super();
33 | mIntensity = intensity;
34 | }
35 |
36 | @Override
37 | public void onInit() {
38 | super.onInit();
39 | setIntensity(mIntensity);
40 | }
41 |
42 | public void setIntensity(final float intensity) {
43 | mIntensity = intensity;
44 | setConvolutionKernel(new float[] {
45 | intensity * (-2.0f), -intensity, 0.0f,
46 | -intensity, 1.0f, intensity,
47 | 0.0f, intensity, intensity * 2.0f,
48 | });
49 | }
50 |
51 | public float getIntensity() {
52 | return mIntensity;
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageExclusionBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageExclusionBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String EXCLUSION_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " // Dca = (Sca.Da + Dca.Sa - 2.Sca.Dca) + Sca.(1 - Da) + Dca.(1 - Sa)\n" +
32 | " \n" +
33 | " gl_FragColor = vec4((overlay.rgb * base.a + base.rgb * overlay.a - 2.0 * overlay.rgb * base.rgb) + overlay.rgb * (1.0 - base.a) + base.rgb * (1.0 - overlay.a), base.a);\n" +
34 | " }";
35 |
36 | public GPUImageExclusionBlendFilter() {
37 | super(EXCLUSION_BLEND_FRAGMENT_SHADER);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageExposureFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * exposure: The adjusted exposure (-10.0 - 10.0, with 0.0 as the default)
23 | */
24 | public class GPUImageExposureFilter extends GPUImageFilter {
25 | public static final String EXPOSURE_FRAGMENT_SHADER = "" +
26 | " varying highp vec2 textureCoordinate;\n" +
27 | " \n" +
28 | " uniform sampler2D inputImageTexture;\n" +
29 | " uniform highp float exposure;\n" +
30 | " \n" +
31 | " void main()\n" +
32 | " {\n" +
33 | " highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
34 | " \n" +
35 | " gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w);\n" +
36 | " } ";
37 |
38 | private int mExposureLocation;
39 | private float mExposure;
40 |
41 | public GPUImageExposureFilter() {
42 | this(1.0f);
43 | }
44 |
45 | public GPUImageExposureFilter(final float exposure) {
46 | super(NO_FILTER_VERTEX_SHADER, EXPOSURE_FRAGMENT_SHADER);
47 | mExposure = exposure;
48 | }
49 |
50 | @Override
51 | public void onInit() {
52 | super.onInit();
53 | mExposureLocation = GLES20.glGetUniformLocation(getProgram(), "exposure");
54 | }
55 |
56 | @Override
57 | public void onInitialized() {
58 | super.onInitialized();
59 | setExposure(mExposure);
60 | }
61 |
62 | public void setExposure(final float exposure) {
63 | mExposure = exposure;
64 | setFloat(mExposureLocation, mExposure);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageFalseColorFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | public class GPUImageFalseColorFilter extends GPUImageFilter {
22 | public static final String FALSECOLOR_FRAGMENT_SHADER = "" +
23 | "precision lowp float;\n" +
24 | "\n" +
25 | "varying highp vec2 textureCoordinate;\n" +
26 | "\n" +
27 | "uniform sampler2D inputImageTexture;\n" +
28 | "uniform float intensity;\n" +
29 | "uniform vec3 firstColor;\n" +
30 | "uniform vec3 secondColor;\n" +
31 | "\n" +
32 | "const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
33 | "\n" +
34 | "void main()\n" +
35 | "{\n" +
36 | "lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
37 | "float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
38 | "\n" +
39 | "gl_FragColor = vec4( mix(firstColor.rgb, secondColor.rgb, luminance), textureColor.a);\n" +
40 | "}\n";
41 |
42 | private float[] mFirstColor;
43 | private int mFirstColorLocation;
44 | private float[] mSecondColor;
45 | private int mSecondColorLocation;
46 |
47 | public GPUImageFalseColorFilter() {
48 | this(0f, 0f, 0.5f, 1f, 0f, 0f);
49 | }
50 |
51 | public GPUImageFalseColorFilter(float firstRed, float firstGreen, float firstBlue, float secondRed, float secondGreen, float secondBlue) {
52 | this(new float[]{firstRed, firstGreen, firstBlue}, new float[]{secondRed, secondGreen, secondBlue});
53 | }
54 |
55 | public GPUImageFalseColorFilter(float[] firstColor, float[] secondColor) {
56 | super(NO_FILTER_VERTEX_SHADER, FALSECOLOR_FRAGMENT_SHADER);
57 | mFirstColor = firstColor;
58 | mSecondColor = secondColor;
59 | }
60 |
61 | @Override
62 | public void onInit() {
63 | super.onInit();
64 | mFirstColorLocation = GLES20.glGetUniformLocation(getProgram(), "firstColor");
65 | mSecondColorLocation = GLES20.glGetUniformLocation(getProgram(), "secondColor");
66 | }
67 |
68 | @Override
69 | public void onInitialized() {
70 | super.onInitialized();
71 | setFirstColor(mFirstColor);
72 | setSecondColor(mSecondColor);
73 | }
74 |
75 | public void setFirstColor(final float[] firstColor) {
76 | mFirstColor = firstColor;
77 | setFloatVec3(mFirstColorLocation, firstColor);
78 | }
79 |
80 | public void setSecondColor(final float[] secondColor) {
81 | mSecondColor = secondColor;
82 | setFloatVec3(mSecondColorLocation, secondColor);
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageGammaFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * gamma value ranges from 0.0 to 3.0, with 1.0 as the normal level
23 | */
24 | public class GPUImageGammaFilter extends GPUImageFilter {
25 | public static final String GAMMA_FRAGMENT_SHADER = "" +
26 | "varying highp vec2 textureCoordinate;\n" +
27 | " \n" +
28 | " uniform sampler2D inputImageTexture;\n" +
29 | " uniform lowp float gamma;\n" +
30 | " \n" +
31 | " void main()\n" +
32 | " {\n" +
33 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
34 | " \n" +
35 | " gl_FragColor = vec4(pow(textureColor.rgb, vec3(gamma)), textureColor.w);\n" +
36 | " }";
37 |
38 | private int mGammaLocation;
39 | private float mGamma;
40 |
41 | public GPUImageGammaFilter() {
42 | this(1.2f);
43 | }
44 |
45 | public GPUImageGammaFilter(final float gamma) {
46 | super(NO_FILTER_VERTEX_SHADER, GAMMA_FRAGMENT_SHADER);
47 | mGamma = gamma;
48 | }
49 |
50 | @Override
51 | public void onInit() {
52 | super.onInit();
53 | mGammaLocation = GLES20.glGetUniformLocation(getProgram(), "gamma");
54 | }
55 |
56 | @Override
57 | public void onInitialized() {
58 | super.onInitialized();
59 | setGamma(mGamma);
60 | }
61 |
62 | public void setGamma(final float gamma) {
63 | mGamma = gamma;
64 | setFloat(mGammaLocation, mGamma);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageGrayscaleFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | /**
20 | * Applies a grayscale effect to the image.
21 | */
22 | public class GPUImageGrayscaleFilter extends GPUImageFilter {
23 | public static final String GRAYSCALE_FRAGMENT_SHADER = "" +
24 | "precision highp float;\n" +
25 | "\n" +
26 | "varying vec2 textureCoordinate;\n" +
27 | "\n" +
28 | "uniform sampler2D inputImageTexture;\n" +
29 | "\n" +
30 | "const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);\n" +
31 | "\n" +
32 | "void main()\n" +
33 | "{\n" +
34 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
35 | " float luminance = dot(textureColor.rgb, W);\n" +
36 | "\n" +
37 | " gl_FragColor = vec4(vec3(luminance), textureColor.a);\n" +
38 | "}";
39 |
40 | public GPUImageGrayscaleFilter() {
41 | super(NO_FILTER_VERTEX_SHADER, GRAYSCALE_FRAGMENT_SHADER);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageHalftoneFilter.java:
--------------------------------------------------------------------------------
1 | package jp.co.cyberagent.android.gpuimage;
2 |
3 | import android.opengl.GLES20;
4 |
5 | public class GPUImageHalftoneFilter extends GPUImageFilter {
6 | public static final String HALFTONE_FRAGMENT_SHADER = "" +
7 | "varying highp vec2 textureCoordinate;\n" +
8 |
9 | "uniform sampler2D inputImageTexture;\n" +
10 |
11 | "uniform highp float fractionalWidthOfPixel;\n" +
12 | "uniform highp float aspectRatio;\n" +
13 |
14 | "const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);\n" +
15 |
16 | "void main()\n" +
17 | "{\n" +
18 | " highp vec2 sampleDivisor = vec2(fractionalWidthOfPixel, fractionalWidthOfPixel / aspectRatio);\n" +
19 | " highp vec2 samplePos = textureCoordinate - mod(textureCoordinate, sampleDivisor) + 0.5 * sampleDivisor;\n" +
20 | " highp vec2 textureCoordinateToUse = vec2(textureCoordinate.x, (textureCoordinate.y * aspectRatio + 0.5 - 0.5 * aspectRatio));\n" +
21 | " highp vec2 adjustedSamplePos = vec2(samplePos.x, (samplePos.y * aspectRatio + 0.5 - 0.5 * aspectRatio));\n" +
22 | " highp float distanceFromSamplePoint = distance(adjustedSamplePos, textureCoordinateToUse);\n" +
23 | " lowp vec3 sampledColor = texture2D(inputImageTexture, samplePos).rgb;\n" +
24 | " highp float dotScaling = 1.0 - dot(sampledColor, W);\n" +
25 | " lowp float checkForPresenceWithinDot = 1.0 - step(distanceFromSamplePoint, (fractionalWidthOfPixel * 0.5) * dotScaling);\n" +
26 | " gl_FragColor = vec4(vec3(checkForPresenceWithinDot), 1.0);\n" +
27 | "}";
28 |
29 | private int mFractionalWidthOfPixelLocation;
30 | private int mAspectRatioLocation;
31 |
32 | private float mFractionalWidthOfAPixel;
33 | private float mAspectRatio;
34 |
35 | public GPUImageHalftoneFilter() {
36 | this(0.01f);
37 | }
38 |
39 | public GPUImageHalftoneFilter(float fractionalWidthOfAPixel) {
40 | super(NO_FILTER_VERTEX_SHADER, HALFTONE_FRAGMENT_SHADER);
41 | mFractionalWidthOfAPixel = fractionalWidthOfAPixel;
42 | }
43 |
44 | @Override
45 | public void onInit() {
46 | super.onInit();
47 | mFractionalWidthOfPixelLocation = GLES20.glGetUniformLocation(getProgram(), "fractionalWidthOfPixel");
48 | mAspectRatioLocation = GLES20.glGetUniformLocation(getProgram(), "aspectRatio");
49 | setFractionalWidthOfAPixel(mFractionalWidthOfAPixel);
50 | }
51 |
52 | @Override
53 | public void onOutputSizeChanged(final int width, final int height) {
54 | super.onOutputSizeChanged(width, height);
55 | setAspectRatio((float)height / (float) width);
56 | }
57 |
58 | public void setFractionalWidthOfAPixel(final float fractionalWidthOfAPixel) {
59 | mFractionalWidthOfAPixel = fractionalWidthOfAPixel;
60 | setFloat(mFractionalWidthOfPixelLocation, mFractionalWidthOfAPixel);
61 | }
62 |
63 | public void setAspectRatio(final float aspectRatio) {
64 | mAspectRatio = aspectRatio;
65 | setFloat(mAspectRatioLocation, mAspectRatio);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageHardLightBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageHardLightBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String HARD_LIGHT_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | "\n" +
26 | " const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);\n" +
27 | "\n" +
28 | " void main()\n" +
29 | " {\n" +
30 | " mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
31 | " mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);\n" +
32 | "\n" +
33 | " highp float ra;\n" +
34 | " if (2.0 * overlay.r < overlay.a) {\n" +
35 | " ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);\n" +
36 | " } else {\n" +
37 | " ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);\n" +
38 | " }\n" +
39 | " \n" +
40 | " highp float ga;\n" +
41 | " if (2.0 * overlay.g < overlay.a) {\n" +
42 | " ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);\n" +
43 | " } else {\n" +
44 | " ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);\n" +
45 | " }\n" +
46 | " \n" +
47 | " highp float ba;\n" +
48 | " if (2.0 * overlay.b < overlay.a) {\n" +
49 | " ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);\n" +
50 | " } else {\n" +
51 | " ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);\n" +
52 | " }\n" +
53 | " \n" +
54 | " gl_FragColor = vec4(ra, ga, ba, 1.0);\n" +
55 | " }";
56 |
57 | public GPUImageHardLightBlendFilter() {
58 | super(HARD_LIGHT_BLEND_FRAGMENT_SHADER);
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageHazeFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * The haze filter can be used to add or remove haze.
23 | *
24 | * This is similar to a UV filter.
25 | */
26 | public class GPUImageHazeFilter extends GPUImageFilter {
27 | public static final String HAZE_FRAGMENT_SHADER = "" +
28 | "varying highp vec2 textureCoordinate;\n" +
29 | "\n" +
30 | "uniform sampler2D inputImageTexture;\n" +
31 | "\n" +
32 | "uniform lowp float distance;\n" +
33 | "uniform highp float slope;\n" +
34 | "\n" +
35 | "void main()\n" +
36 | "{\n" +
37 | " //todo reconsider precision modifiers \n" +
38 | " highp vec4 color = vec4(1.0);//todo reimplement as a parameter\n" +
39 | "\n" +
40 | " highp float d = textureCoordinate.y * slope + distance; \n" +
41 | "\n" +
42 | " highp vec4 c = texture2D(inputImageTexture, textureCoordinate) ; // consider using unpremultiply\n" +
43 | "\n" +
44 | " c = (c - d * color) / (1.0 -d);\n" +
45 | "\n" +
46 | " gl_FragColor = c; //consider using premultiply(c);\n" +
47 | "}\n";
48 |
49 | private float mDistance;
50 | private int mDistanceLocation;
51 | private float mSlope;
52 | private int mSlopeLocation;
53 |
54 | public GPUImageHazeFilter() {
55 | this(0.2f, 0.0f);
56 | }
57 |
58 | public GPUImageHazeFilter(float distance, float slope) {
59 | super(NO_FILTER_VERTEX_SHADER, HAZE_FRAGMENT_SHADER);
60 | mDistance = distance;
61 | mSlope = slope;
62 | }
63 |
64 | @Override
65 | public void onInit() {
66 | super.onInit();
67 | mDistanceLocation = GLES20.glGetUniformLocation(getProgram(), "distance");
68 | mSlopeLocation = GLES20.glGetUniformLocation(getProgram(), "slope");
69 | }
70 |
71 | @Override
72 | public void onInitialized() {
73 | super.onInitialized();
74 | setDistance(mDistance);
75 | setSlope(mSlope);
76 | }
77 |
78 | /**
79 | * Strength of the color applied. Default 0. Values between -.3 and .3 are best.
80 | *
81 | * @param distance -0.3 to 0.3 are best, default 0
82 | */
83 | public void setDistance(float distance) {
84 | mDistance = distance;
85 | setFloat(mDistanceLocation, distance);
86 | }
87 |
88 | /**
89 | * Amount of color change. Default 0. Values between -.3 and .3 are best.
90 | *
91 | * @param slope -0.3 to 0.3 are best, default 0
92 | */
93 | public void setSlope(float slope) {
94 | mSlope = slope;
95 | setFloat(mSlopeLocation, slope);
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageHighlightShadowFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Adjusts the shadows and highlights of an image
23 | * shadows: Increase to lighten shadows, from 0.0 to 1.0, with 0.0 as the default.
24 | * highlights: Decrease to darken highlights, from 0.0 to 1.0, with 1.0 as the default.
25 | */
26 | public class GPUImageHighlightShadowFilter extends GPUImageFilter {
27 | public static final String HIGHLIGHT_SHADOW_FRAGMENT_SHADER = "" +
28 | " uniform sampler2D inputImageTexture;\n" +
29 | " varying highp vec2 textureCoordinate;\n" +
30 | " \n" +
31 | " uniform lowp float shadows;\n" +
32 | " uniform lowp float highlights;\n" +
33 | " \n" +
34 | " const mediump vec3 luminanceWeighting = vec3(0.3, 0.3, 0.3);\n" +
35 | " \n" +
36 | " void main()\n" +
37 | " {\n" +
38 | " lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);\n" +
39 | " mediump float luminance = dot(source.rgb, luminanceWeighting);\n" +
40 | " \n" +
41 | " mediump float shadow = clamp((pow(luminance, 1.0/(shadows+1.0)) + (-0.76)*pow(luminance, 2.0/(shadows+1.0))) - luminance, 0.0, 1.0);\n" +
42 | " mediump float highlight = clamp((1.0 - (pow(1.0-luminance, 1.0/(2.0-highlights)) + (-0.8)*pow(1.0-luminance, 2.0/(2.0-highlights)))) - luminance, -1.0, 0.0);\n" +
43 | " lowp vec3 result = vec3(0.0, 0.0, 0.0) + ((luminance + shadow + highlight) - 0.0) * ((source.rgb - vec3(0.0, 0.0, 0.0))/(luminance - 0.0));\n" +
44 | " \n" +
45 | " gl_FragColor = vec4(result.rgb, source.a);\n" +
46 | " }";
47 |
48 | private int mShadowsLocation;
49 | private float mShadows;
50 | private int mHighlightsLocation;
51 | private float mHighlights;
52 |
53 | public GPUImageHighlightShadowFilter() {
54 | this(0.0f, 1.0f);
55 | }
56 |
57 | public GPUImageHighlightShadowFilter(final float shadows, final float highlights) {
58 | super(NO_FILTER_VERTEX_SHADER, HIGHLIGHT_SHADOW_FRAGMENT_SHADER);
59 | mHighlights = highlights;
60 | mShadows = shadows;
61 | }
62 |
63 | @Override
64 | public void onInit() {
65 | super.onInit();
66 | mHighlightsLocation = GLES20.glGetUniformLocation(getProgram(), "highlights");
67 | mShadowsLocation = GLES20.glGetUniformLocation(getProgram(), "shadows");
68 | }
69 |
70 | @Override
71 | public void onInitialized() {
72 | super.onInitialized();
73 | setHighlights(mHighlights);
74 | setShadows(mShadows);
75 | }
76 |
77 | public void setHighlights(final float highlights) {
78 | mHighlights = highlights;
79 | setFloat(mHighlightsLocation, mHighlights);
80 | }
81 |
82 | public void setShadows(final float shadows) {
83 | mShadows = shadows;
84 | setFloat(mShadowsLocation, mShadows);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageHueFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | public class GPUImageHueFilter extends GPUImageFilter {
22 | public static final String HUE_FRAGMENT_SHADER = "" +
23 | "precision highp float;\n" +
24 | "varying highp vec2 textureCoordinate;\n" +
25 | "\n" +
26 | "uniform sampler2D inputImageTexture;\n" +
27 | "uniform mediump float hueAdjust;\n" +
28 | "const highp vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);\n" +
29 | "const highp vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0);\n" +
30 | "const highp vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0);\n" +
31 | "\n" +
32 | "const highp vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0);\n" +
33 | "const highp vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0);\n" +
34 | "const highp vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0);\n" +
35 | "\n" +
36 | "void main ()\n" +
37 | "{\n" +
38 | " // Sample the input pixel\n" +
39 | " highp vec4 color = texture2D(inputImageTexture, textureCoordinate);\n" +
40 | "\n" +
41 | " // Convert to YIQ\n" +
42 | " highp float YPrime = dot (color, kRGBToYPrime);\n" +
43 | " highp float I = dot (color, kRGBToI);\n" +
44 | " highp float Q = dot (color, kRGBToQ);\n" +
45 | "\n" +
46 | " // Calculate the hue and chroma\n" +
47 | " highp float hue = atan (Q, I);\n" +
48 | " highp float chroma = sqrt (I * I + Q * Q);\n" +
49 | "\n" +
50 | " // Make the user's adjustments\n" +
51 | " hue += (-hueAdjust); //why negative rotation?\n" +
52 | "\n" +
53 | " // Convert back to YIQ\n" +
54 | " Q = chroma * sin (hue);\n" +
55 | " I = chroma * cos (hue);\n" +
56 | "\n" +
57 | " // Convert back to RGB\n" +
58 | " highp vec4 yIQ = vec4 (YPrime, I, Q, 0.0);\n" +
59 | " color.r = dot (yIQ, kYIQToR);\n" +
60 | " color.g = dot (yIQ, kYIQToG);\n" +
61 | " color.b = dot (yIQ, kYIQToB);\n" +
62 | "\n" +
63 | " // Save the result\n" +
64 | " gl_FragColor = color;\n" +
65 | "}\n";
66 |
67 | private float mHue;
68 | private int mHueLocation;
69 |
70 | public GPUImageHueFilter() {
71 | this(90.0f);
72 | }
73 |
74 | public GPUImageHueFilter(final float hue) {
75 | super(NO_FILTER_VERTEX_SHADER, HUE_FRAGMENT_SHADER);
76 | mHue = hue;
77 | }
78 |
79 | @Override
80 | public void onInit() {
81 | super.onInit();
82 | mHueLocation = GLES20.glGetUniformLocation(getProgram(), "hueAdjust");
83 | }
84 |
85 | @Override
86 | public void onInitialized() {
87 | super.onInitialized();
88 | setHue(mHue);
89 | }
90 |
91 | public void setHue(final float hue) {
92 | mHue = hue;
93 | float hueAdjust = (mHue % 360.0f) * (float) Math.PI / 180.0f;
94 | setFloat(mHueLocation, hueAdjust);
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageLaplacianFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | public class GPUImageLaplacianFilter extends GPUImage3x3TextureSamplingFilter {
22 | public static final String LAPLACIAN_FRAGMENT_SHADER = "" +
23 | "precision highp float;\n" +
24 | "\n" +
25 | "uniform sampler2D inputImageTexture;\n" +
26 | "\n" +
27 | "uniform mediump mat3 convolutionMatrix;\n" +
28 | "\n" +
29 | "varying vec2 textureCoordinate;\n" +
30 | "varying vec2 leftTextureCoordinate;\n" +
31 | "varying vec2 rightTextureCoordinate;\n" +
32 | "\n" +
33 | "varying vec2 topTextureCoordinate;\n" +
34 | "varying vec2 topLeftTextureCoordinate;\n" +
35 | "varying vec2 topRightTextureCoordinate;\n" +
36 | "\n" +
37 | "varying vec2 bottomTextureCoordinate;\n" +
38 | "varying vec2 bottomLeftTextureCoordinate;\n" +
39 | "varying vec2 bottomRightTextureCoordinate;\n" +
40 | "\n" +
41 | "void main()\n" +
42 | "{\n" +
43 | "mediump vec3 bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb;\n" +
44 | "mediump vec3 bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).rgb;\n" +
45 | "mediump vec3 bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).rgb;\n" +
46 | "mediump vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);\n" +
47 | "mediump vec3 leftColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb;\n" +
48 | "mediump vec3 rightColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb;\n" +
49 | "mediump vec3 topColor = texture2D(inputImageTexture, topTextureCoordinate).rgb;\n" +
50 | "mediump vec3 topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).rgb;\n" +
51 | "mediump vec3 topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).rgb;\n" +
52 | "\n" +
53 | "mediump vec3 resultColor = topLeftColor * convolutionMatrix[0][0] + topColor * convolutionMatrix[0][1] + topRightColor * convolutionMatrix[0][2];\n" +
54 | "resultColor += leftColor * convolutionMatrix[1][0] + centerColor.rgb * convolutionMatrix[1][1] + rightColor * convolutionMatrix[1][2];\n" +
55 | "resultColor += bottomLeftColor * convolutionMatrix[2][0] + bottomColor * convolutionMatrix[2][1] + bottomRightColor * convolutionMatrix[2][2];\n" +
56 | "\n" +
57 | "// Normalize the results to allow for negative gradients in the 0.0-1.0 colorspace\n" +
58 | "resultColor = resultColor + 0.5;\n" +
59 | "\n" +
60 | "gl_FragColor = vec4(resultColor, centerColor.a);\n" +
61 | "}\n";
62 |
63 | private float[] mConvolutionKernel;
64 | private int mUniformConvolutionMatrix;
65 |
66 | public GPUImageLaplacianFilter() {
67 | this(new float[]{
68 | 0.5f, 1.0f, 0.5f,
69 | 1.0f, -6.0f, 1.0f,
70 | 0.5f, 1.0f, 0.5f
71 | });
72 | }
73 |
74 | private GPUImageLaplacianFilter(final float[] convolutionKernel) {
75 | super(LAPLACIAN_FRAGMENT_SHADER);
76 | mConvolutionKernel = convolutionKernel;
77 | }
78 |
79 | @Override
80 | public void onInit() {
81 | super.onInit();
82 | mUniformConvolutionMatrix = GLES20.glGetUniformLocation(getProgram(), "convolutionMatrix");
83 | setConvolutionKernel(mConvolutionKernel);
84 | }
85 |
86 | private void setConvolutionKernel(final float[] convolutionKernel) {
87 | mConvolutionKernel = convolutionKernel;
88 | setUniformMatrix3f(mUniformConvolutionMatrix, mConvolutionKernel);
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageLevelsFilter.java:
--------------------------------------------------------------------------------
1 | package jp.co.cyberagent.android.gpuimage;
2 |
3 | import android.opengl.GLES20;
4 | import android.util.Log;
5 |
6 | /**
7 | * Created by vashisthg 30/05/14.
8 | */
9 | public class GPUImageLevelsFilter extends GPUImageFilter{
10 |
11 | private static final String LOGTAG = GPUImageLevelsFilter.class.getSimpleName();
12 |
13 | public static final String LEVELS_FRAGMET_SHADER =
14 |
15 | " varying highp vec2 textureCoordinate;\n" +
16 | " \n" +
17 | " uniform sampler2D inputImageTexture;\n" +
18 | " uniform mediump vec3 levelMinimum;\n" +
19 | " uniform mediump vec3 levelMiddle;\n" +
20 | " uniform mediump vec3 levelMaximum;\n" +
21 | " uniform mediump vec3 minOutput;\n" +
22 | " uniform mediump vec3 maxOutput;\n" +
23 | " \n" +
24 | " void main()\n" +
25 | " {\n" +
26 | " mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
27 | " \n" +
28 | " gl_FragColor = vec4( mix(minOutput, maxOutput, pow(min(max(textureColor.rgb -levelMinimum, vec3(0.0)) / (levelMaximum - levelMinimum ), vec3(1.0)), 1.0 /levelMiddle)) , textureColor.a);\n" +
29 | " }\n";
30 |
31 | private int mMinLocation;
32 | private float[] mMin;
33 | private int mMidLocation;
34 | private float[] mMid;
35 | private int mMaxLocation;
36 | private float[] mMax;
37 | private int mMinOutputLocation;
38 | private float[] mMinOutput;
39 | private int mMaxOutputLocation;
40 | private float[] mMaxOutput;
41 |
42 | public GPUImageLevelsFilter() {
43 | this(new float[] {0.0f,0.0f,0.0f}, new float[] {1.0f, 1.0f, 1.0f }, new float[] {1.0f, 1.0f ,1.0f}, new float[] {0.0f, 0.0f, 0.0f}, new float[] {1.0f,1.0f,1.0f});
44 | }
45 |
46 | private GPUImageLevelsFilter(final float[] min, final float[] mid, final float[] max, final float[] minOUt, final float[] maxOut) {
47 | super(NO_FILTER_VERTEX_SHADER, LEVELS_FRAGMET_SHADER);
48 |
49 | mMin = min;
50 | mMid = mid;
51 | mMax = max;
52 | mMinOutput = minOUt;
53 | mMaxOutput = maxOut;
54 | setMin(0.0f, 1.0f, 1.0f, 0.0f, 1.0f);
55 | }
56 |
57 | @Override
58 | public void onInit() {
59 | super.onInit();
60 | mMinLocation = GLES20.glGetUniformLocation(getProgram(), "levelMinimum");
61 | mMidLocation = GLES20.glGetUniformLocation(getProgram(), "levelMiddle");
62 | mMaxLocation = GLES20.glGetUniformLocation(getProgram(), "levelMaximum");
63 | mMinOutputLocation = GLES20.glGetUniformLocation(getProgram(), "minOutput");
64 | mMaxOutputLocation = GLES20.glGetUniformLocation(getProgram(), "maxOutput");
65 | }
66 |
67 | @Override
68 | public void onInitialized() {
69 | super.onInitialized();
70 | updateUniforms();
71 | }
72 |
73 |
74 | public void updateUniforms () {
75 | setFloatVec3(mMinLocation, mMin);
76 | setFloatVec3(mMidLocation, mMid);
77 | setFloatVec3(mMaxLocation, mMax);
78 | setFloatVec3(mMinOutputLocation, mMinOutput);
79 | setFloatVec3(mMaxOutputLocation, mMaxOutput);
80 | }
81 |
82 | public void setMin(float min, float mid , float max ,float minOut , float maxOut) {
83 | setRedMin(min, mid, max, minOut, maxOut);
84 | setGreenMin(min, mid, max, minOut, maxOut);
85 | setBlueMin(min, mid, max, minOut, maxOut);
86 | }
87 |
88 | public void setMin(float min, float mid , float max ) {
89 | setMin(min, mid, max, 0.0f, 1.0f);
90 | }
91 |
92 | public void setRedMin(float min, float mid , float max ,float minOut , float maxOut) {
93 | mMin[0] = min;
94 | mMid[0] = mid;
95 | mMax[0] = max;
96 | mMinOutput[0] = minOut;
97 | mMaxOutput[0] = maxOut;
98 | updateUniforms();
99 | }
100 |
101 | public void setRedMin(float min, float mid , float max ){
102 | setRedMin(min, mid, max, 0, 1);
103 | }
104 |
105 | public void setGreenMin(float min, float mid , float max ,float minOut , float maxOut) {
106 | mMin[1] = min;
107 | mMid[1] = mid;
108 | mMax[1] = max;
109 | mMinOutput[1] = minOut;
110 | mMaxOutput[1] = maxOut;
111 | updateUniforms();
112 | }
113 |
114 | public void setGreenMin(float min, float mid , float max ){
115 | setGreenMin(min, mid, max, 0, 1);
116 | }
117 |
118 | public void setBlueMin(float min, float mid , float max ,float minOut , float maxOut) {
119 | mMin[2] = min;
120 | mMid[2] = mid;
121 | mMax[2] = max;
122 | mMinOutput[2] = minOut;
123 | mMaxOutput[2] = maxOut;
124 | updateUniforms();
125 | }
126 |
127 | public void setBlueMin(float min, float mid , float max ){
128 | setBlueMin(min, mid, max, 0, 1);
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageLightenBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageLightenBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String LIGHTEN_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " gl_FragColor = max(textureColor, textureColor2);\n" +
32 | " }";
33 |
34 | public GPUImageLightenBlendFilter() {
35 | super(LIGHTEN_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageLinearBurnBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageLinearBurnBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String LINEAR_BURN_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | " \n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " gl_FragColor = vec4(clamp(textureColor.rgb + textureColor2.rgb - vec3(1.0), vec3(0.0), vec3(1.0)), textureColor.a);\n" +
32 | " }";
33 |
34 | public GPUImageLinearBurnBlendFilter() {
35 | super(LINEAR_BURN_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageLookupFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | public class GPUImageLookupFilter extends GPUImageTwoInputFilter {
22 |
23 | public static final String LOOKUP_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
24 | " varying highp vec2 textureCoordinate2; // TODO: This is not used\n" +
25 | " \n" +
26 | " uniform sampler2D inputImageTexture;\n" +
27 | " uniform sampler2D inputImageTexture2; // lookup texture\n" +
28 | " \n" +
29 | " uniform lowp float intensity;\n" +
30 | " \n" +
31 | " void main()\n" +
32 | " {\n" +
33 | " highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
34 | " \n" +
35 | " highp float blueColor = textureColor.b * 63.0;\n" +
36 | " \n" +
37 | " highp vec2 quad1;\n" +
38 | " quad1.y = floor(floor(blueColor) / 8.0);\n" +
39 | " quad1.x = floor(blueColor) - (quad1.y * 8.0);\n" +
40 | " \n" +
41 | " highp vec2 quad2;\n" +
42 | " quad2.y = floor(ceil(blueColor) / 8.0);\n" +
43 | " quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n" +
44 | " \n" +
45 | " highp vec2 texPos1;\n" +
46 | " texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n" +
47 | " texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n" +
48 | " \n" +
49 | " highp vec2 texPos2;\n" +
50 | " texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n" +
51 | " texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n" +
52 | " \n" +
53 | " lowp vec4 newColor1 = texture2D(inputImageTexture2, texPos1);\n" +
54 | " lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2);\n" +
55 | " \n" +
56 | " lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n" +
57 | " gl_FragColor = mix(textureColor, vec4(newColor.rgb, textureColor.w), intensity);\n" +
58 | " }";
59 |
60 | private int mIntensityLocation;
61 | private float mIntensity;
62 |
63 | public GPUImageLookupFilter() {
64 | this(1.0f);
65 | }
66 |
67 | public GPUImageLookupFilter(final float intensity) {
68 | super(LOOKUP_FRAGMENT_SHADER);
69 | mIntensity = intensity;
70 | }
71 |
72 | @Override
73 | public void onInit() {
74 | super.onInit();
75 | mIntensityLocation = GLES20.glGetUniformLocation(getProgram(), "intensity");
76 | }
77 |
78 | @Override
79 | public void onInitialized() {
80 | super.onInitialized();
81 | setIntensity(mIntensity);
82 | }
83 |
84 | public void setIntensity(final float intensity) {
85 | mIntensity = intensity;
86 | setFloat(mIntensityLocation, mIntensity);
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageLuminosityBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageLuminosityBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String LUMINOSITY_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | " \n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " highp float lum(lowp vec3 c) {\n" +
27 | " return dot(c, vec3(0.3, 0.59, 0.11));\n" +
28 | " }\n" +
29 | " \n" +
30 | " lowp vec3 clipcolor(lowp vec3 c) {\n" +
31 | " highp float l = lum(c);\n" +
32 | " lowp float n = min(min(c.r, c.g), c.b);\n" +
33 | " lowp float x = max(max(c.r, c.g), c.b);\n" +
34 | " \n" +
35 | " if (n < 0.0) {\n" +
36 | " c.r = l + ((c.r - l) * l) / (l - n);\n" +
37 | " c.g = l + ((c.g - l) * l) / (l - n);\n" +
38 | " c.b = l + ((c.b - l) * l) / (l - n);\n" +
39 | " }\n" +
40 | " if (x > 1.0) {\n" +
41 | " c.r = l + ((c.r - l) * (1.0 - l)) / (x - l);\n" +
42 | " c.g = l + ((c.g - l) * (1.0 - l)) / (x - l);\n" +
43 | " c.b = l + ((c.b - l) * (1.0 - l)) / (x - l);\n" +
44 | " }\n" +
45 | " \n" +
46 | " return c;\n" +
47 | " }\n" +
48 | " \n" +
49 | " lowp vec3 setlum(lowp vec3 c, highp float l) {\n" +
50 | " highp float d = l - lum(c);\n" +
51 | " c = c + vec3(d);\n" +
52 | " return clipcolor(c);\n" +
53 | " }\n" +
54 | " \n" +
55 | " void main()\n" +
56 | " {\n" +
57 | " highp vec4 baseColor = texture2D(inputImageTexture, textureCoordinate);\n" +
58 | " highp vec4 overlayColor = texture2D(inputImageTexture2, textureCoordinate2);\n" +
59 | " \n" +
60 | " gl_FragColor = vec4(baseColor.rgb * (1.0 - overlayColor.a) + setlum(baseColor.rgb, lum(overlayColor.rgb)) * overlayColor.a, baseColor.a);\n" +
61 | " }";
62 |
63 | public GPUImageLuminosityBlendFilter() {
64 | super(LUMINOSITY_BLEND_FRAGMENT_SHADER);
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageMixBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | public class GPUImageMixBlendFilter extends GPUImageTwoInputFilter {
22 |
23 | private int mMixLocation;
24 | private float mMix;
25 |
26 | public GPUImageMixBlendFilter(String fragmentShader) {
27 | this(fragmentShader, 0.5f);
28 | }
29 |
30 | public GPUImageMixBlendFilter(String fragmentShader, float mix) {
31 | super(fragmentShader);
32 | mMix = mix;
33 | }
34 |
35 | @Override
36 | public void onInit() {
37 | super.onInit();
38 | mMixLocation = GLES20.glGetUniformLocation(getProgram(), "mixturePercent");
39 | }
40 |
41 | @Override
42 | public void onInitialized() {
43 | super.onInitialized();
44 | setMix(mMix);
45 | }
46 |
47 | /**
48 | * @param mix ranges from 0.0 (only image 1) to 1.0 (only image 2), with 0.5 (half of either) as the normal level
49 | */
50 | public void setMix(final float mix) {
51 | mMix = mix;
52 | setFloat(mMixLocation, mMix);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageMonochromeFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Converts the image to a single-color version, based on the luminance of each pixel
23 | * intensity: The degree to which the specific color replaces the normal image color (0.0 - 1.0, with 1.0 as the default)
24 | * color: The color to use as the basis for the effect, with (0.6, 0.45, 0.3, 1.0) as the default.
25 | */
26 | public class GPUImageMonochromeFilter extends GPUImageFilter {
27 | public static final String MONOCHROME_FRAGMENT_SHADER = "" +
28 | " precision lowp float;\n" +
29 | " \n" +
30 | " varying highp vec2 textureCoordinate;\n" +
31 | " \n" +
32 | " uniform sampler2D inputImageTexture;\n" +
33 | " uniform float intensity;\n" +
34 | " uniform vec3 filterColor;\n" +
35 | " \n" +
36 | " const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
37 | " \n" +
38 | " void main()\n" +
39 | " {\n" +
40 | " //desat, then apply overlay blend\n" +
41 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
42 | " float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
43 | " \n" +
44 | " lowp vec4 desat = vec4(vec3(luminance), 1.0);\n" +
45 | " \n" +
46 | " //overlay\n" +
47 | " lowp vec4 outputColor = vec4(\n" +
48 | " (desat.r < 0.5 ? (2.0 * desat.r * filterColor.r) : (1.0 - 2.0 * (1.0 - desat.r) * (1.0 - filterColor.r))),\n" +
49 | " (desat.g < 0.5 ? (2.0 * desat.g * filterColor.g) : (1.0 - 2.0 * (1.0 - desat.g) * (1.0 - filterColor.g))),\n" +
50 | " (desat.b < 0.5 ? (2.0 * desat.b * filterColor.b) : (1.0 - 2.0 * (1.0 - desat.b) * (1.0 - filterColor.b))),\n" +
51 | " 1.0\n" +
52 | " );\n" +
53 | " \n" +
54 | " //which is better, or are they equal?\n" +
55 | " gl_FragColor = vec4( mix(textureColor.rgb, outputColor.rgb, intensity), textureColor.a);\n" +
56 | " }";
57 |
58 | private int mIntensityLocation;
59 | private float mIntensity;
60 | private int mFilterColorLocation;
61 | private float[] mColor;
62 |
63 | public GPUImageMonochromeFilter() {
64 | this(1.0f, new float[] {0.6f, 0.45f, 0.3f, 1.0f});
65 | }
66 |
67 | public GPUImageMonochromeFilter(final float intensity, final float[] color) {
68 | super(NO_FILTER_VERTEX_SHADER, MONOCHROME_FRAGMENT_SHADER);
69 | mIntensity = intensity;
70 | mColor = color;
71 | }
72 |
73 | @Override
74 | public void onInit() {
75 | super.onInit();
76 | mIntensityLocation = GLES20.glGetUniformLocation(getProgram(), "intensity");
77 | mFilterColorLocation = GLES20.glGetUniformLocation(getProgram(), "filterColor");
78 | }
79 |
80 | @Override
81 | public void onInitialized() {
82 | super.onInitialized();
83 | setIntensity(1.0f);
84 | setColor(new float[]{ 0.6f, 0.45f, 0.3f, 1.f });
85 | }
86 |
87 | public void setIntensity(final float intensity) {
88 | mIntensity = intensity;
89 | setFloat(mIntensityLocation, mIntensity);
90 | }
91 |
92 | public void setColor(final float[] color) {
93 | mColor = color;
94 | setColorRed(mColor[0], mColor[1], mColor[2]);
95 |
96 | }
97 |
98 | public void setColorRed(final float red, final float green, final float blue) {
99 | setFloatVec3(mFilterColorLocation, new float[]{ red, green, blue });
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageMultiplyBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageMultiplyBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String MULTIPLY_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " lowp vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " lowp vec4 overlayer = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " gl_FragColor = overlayer * base + overlayer * (1.0 - base.a) + base * (1.0 - overlayer.a);\n" +
32 | " }";
33 |
34 | public GPUImageMultiplyBlendFilter() {
35 | super(MULTIPLY_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageNativeLibrary.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageNativeLibrary {
20 | static {
21 | System.loadLibrary("gpuimage-library");
22 | }
23 |
24 | public static native void YUVtoRBGA(byte[] yuv, int width, int height, int[] out);
25 |
26 | public static native void YUVtoARBG(byte[] yuv, int width, int height, int[] out);
27 | }
28 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageNonMaximumSuppressionFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageNonMaximumSuppressionFilter extends GPUImage3x3TextureSamplingFilter {
20 | public static final String NMS_FRAGMENT_SHADER = "" +
21 | "uniform sampler2D inputImageTexture;\n" +
22 | "\n" +
23 | "varying highp vec2 textureCoordinate;\n" +
24 | "varying highp vec2 leftTextureCoordinate;\n" +
25 | "varying highp vec2 rightTextureCoordinate;\n" +
26 | "\n" +
27 | "varying highp vec2 topTextureCoordinate;\n" +
28 | "varying highp vec2 topLeftTextureCoordinate;\n" +
29 | "varying highp vec2 topRightTextureCoordinate;\n" +
30 | "\n" +
31 | "varying highp vec2 bottomTextureCoordinate;\n" +
32 | "varying highp vec2 bottomLeftTextureCoordinate;\n" +
33 | "varying highp vec2 bottomRightTextureCoordinate;\n" +
34 | "\n" +
35 | "void main()\n" +
36 | "{\n" +
37 | "lowp float bottomColor = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n" +
38 | "lowp float bottomLeftColor = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n" +
39 | "lowp float bottomRightColor = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n" +
40 | "lowp vec4 centerColor = texture2D(inputImageTexture, textureCoordinate);\n" +
41 | "lowp float leftColor = texture2D(inputImageTexture, leftTextureCoordinate).r;\n" +
42 | "lowp float rightColor = texture2D(inputImageTexture, rightTextureCoordinate).r;\n" +
43 | "lowp float topColor = texture2D(inputImageTexture, topTextureCoordinate).r;\n" +
44 | "lowp float topRightColor = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n" +
45 | "lowp float topLeftColor = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n" +
46 | "\n" +
47 | "// Use a tiebreaker for pixels to the left and immediately above this one\n" +
48 | "lowp float multiplier = 1.0 - step(centerColor.r, topColor);\n" +
49 | "multiplier = multiplier * 1.0 - step(centerColor.r, topLeftColor);\n" +
50 | "multiplier = multiplier * 1.0 - step(centerColor.r, leftColor);\n" +
51 | "multiplier = multiplier * 1.0 - step(centerColor.r, bottomLeftColor);\n" +
52 | "\n" +
53 | "lowp float maxValue = max(centerColor.r, bottomColor);\n" +
54 | "maxValue = max(maxValue, bottomRightColor);\n" +
55 | "maxValue = max(maxValue, rightColor);\n" +
56 | "maxValue = max(maxValue, topRightColor);\n" +
57 | "\n" +
58 | "gl_FragColor = vec4((centerColor.rgb * step(maxValue, centerColor.r) * multiplier), 1.0);\n" +
59 | "}\n";
60 |
61 | public GPUImageNonMaximumSuppressionFilter() {
62 | super(NMS_FRAGMENT_SHADER);
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageNormalBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | /**
20 | * This equation is a simplification of the general blending equation. It assumes the destination color is opaque, and therefore drops the destination color's alpha term.
21 | *
22 | * D = C1 * C1a + C2 * C2a * (1 - C1a)
23 | * where D is the resultant color, C1 is the color of the first element, C1a is the alpha of the first element, C2 is the second element color, C2a is the alpha of the second element. The destination alpha is calculated with:
24 | *
25 | * Da = C1a + C2a * (1 - C1a)
26 | * The resultant color is premultiplied with the alpha. To restore the color to the unmultiplied values, just divide by Da, the resultant alpha.
27 | *
28 | * http://stackoverflow.com/questions/1724946/blend-mode-on-a-transparent-and-semi-transparent-background
29 | *
30 | * For some reason Photoshop behaves
31 | * D = C1 + C2 * C2a * (1 - C1a)
32 | */
33 | public class GPUImageNormalBlendFilter extends GPUImageTwoInputFilter {
34 | public static final String NORMAL_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
35 | " varying highp vec2 textureCoordinate2;\n" +
36 | " \n" +
37 | " uniform sampler2D inputImageTexture;\n" +
38 | " uniform sampler2D inputImageTexture2;\n" +
39 | " \n" +
40 | " void main()\n" +
41 | " {\n" +
42 | " lowp vec4 c2 = texture2D(inputImageTexture, textureCoordinate);\n" +
43 | "\t lowp vec4 c1 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
44 | " \n" +
45 | " lowp vec4 outputColor;\n" +
46 | " \n" +
47 | " outputColor.r = c1.r + c2.r * c2.a * (1.0 - c1.a);\n" +
48 | "\n" +
49 | " outputColor.g = c1.g + c2.g * c2.a * (1.0 - c1.a);\n" +
50 | " \n" +
51 | " outputColor.b = c1.b + c2.b * c2.a * (1.0 - c1.a);\n" +
52 | " \n" +
53 | " outputColor.a = c1.a + c2.a * (1.0 - c1.a);\n" +
54 | " \n" +
55 | " gl_FragColor = outputColor;\n" +
56 | " }";
57 |
58 | public GPUImageNormalBlendFilter() {
59 | super(NORMAL_BLEND_FRAGMENT_SHADER);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageOpacityFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Adjusts the alpha channel of the incoming image
23 | * opacity: The value to multiply the incoming alpha channel for each pixel by (0.0 - 1.0, with 1.0 as the default)
24 | */
25 | public class GPUImageOpacityFilter extends GPUImageFilter {
26 | public static final String OPACITY_FRAGMENT_SHADER = "" +
27 | " varying highp vec2 textureCoordinate;\n" +
28 | " \n" +
29 | " uniform sampler2D inputImageTexture;\n" +
30 | " uniform lowp float opacity;\n" +
31 | " \n" +
32 | " void main()\n" +
33 | " {\n" +
34 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
35 | " \n" +
36 | " gl_FragColor = vec4(textureColor.rgb, textureColor.a * opacity);\n" +
37 | " }\n";
38 |
39 | private int mOpacityLocation;
40 | private float mOpacity;
41 |
42 | public GPUImageOpacityFilter() {
43 | this(1.0f);
44 | }
45 |
46 | public GPUImageOpacityFilter(final float opacity) {
47 | super(NO_FILTER_VERTEX_SHADER, OPACITY_FRAGMENT_SHADER);
48 | mOpacity = opacity;
49 | }
50 |
51 | @Override
52 | public void onInit() {
53 | super.onInit();
54 | mOpacityLocation = GLES20.glGetUniformLocation(getProgram(), "opacity");
55 | }
56 |
57 | @Override
58 | public void onInitialized() {
59 | super.onInitialized();
60 | setOpacity(mOpacity);
61 | }
62 |
63 | public void setOpacity(final float opacity) {
64 | mOpacity = opacity;
65 | setFloat(mOpacityLocation, mOpacity);
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageOverlayBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageOverlayBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String OVERLAY_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " mediump float ra;\n" +
32 | " if (2.0 * base.r < base.a) {\n" +
33 | " ra = 2.0 * overlay.r * base.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);\n" +
34 | " } else {\n" +
35 | " ra = overlay.a * base.a - 2.0 * (base.a - base.r) * (overlay.a - overlay.r) + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);\n" +
36 | " }\n" +
37 | " \n" +
38 | " mediump float ga;\n" +
39 | " if (2.0 * base.g < base.a) {\n" +
40 | " ga = 2.0 * overlay.g * base.g + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);\n" +
41 | " } else {\n" +
42 | " ga = overlay.a * base.a - 2.0 * (base.a - base.g) * (overlay.a - overlay.g) + overlay.g * (1.0 - base.a) + base.g * (1.0 - overlay.a);\n" +
43 | " }\n" +
44 | " \n" +
45 | " mediump float ba;\n" +
46 | " if (2.0 * base.b < base.a) {\n" +
47 | " ba = 2.0 * overlay.b * base.b + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);\n" +
48 | " } else {\n" +
49 | " ba = overlay.a * base.a - 2.0 * (base.a - base.b) * (overlay.a - overlay.b) + overlay.b * (1.0 - base.a) + base.b * (1.0 - overlay.a);\n" +
50 | " }\n" +
51 | " \n" +
52 | " gl_FragColor = vec4(ra, ga, ba, 1.0);\n" +
53 | " }";
54 |
55 | public GPUImageOverlayBlendFilter() {
56 | super(OVERLAY_BLEND_FRAGMENT_SHADER);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImagePixelationFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 | /**
21 | * Applies a grayscale effect to the image.
22 | */
23 | public class GPUImagePixelationFilter extends GPUImageFilter {
24 | public static final String PIXELATION_FRAGMENT_SHADER = "" +
25 | "precision highp float;\n" +
26 |
27 | "varying vec2 textureCoordinate;\n" +
28 |
29 | "uniform float imageWidthFactor;\n" +
30 | "uniform float imageHeightFactor;\n" +
31 | "uniform sampler2D inputImageTexture;\n" +
32 | "uniform float pixel;\n" +
33 |
34 | "void main()\n" +
35 | "{\n" +
36 | " vec2 uv = textureCoordinate.xy;\n" +
37 | " float dx = pixel * imageWidthFactor;\n" +
38 | " float dy = pixel * imageHeightFactor;\n" +
39 | " vec2 coord = vec2(dx * floor(uv.x / dx), dy * floor(uv.y / dy));\n" +
40 | " vec3 tc = texture2D(inputImageTexture, coord).xyz;\n" +
41 | " gl_FragColor = vec4(tc, 1.0);\n" +
42 | "}";
43 |
44 | private int mImageWidthFactorLocation;
45 | private int mImageHeightFactorLocation;
46 | private float mPixel;
47 | private int mPixelLocation;
48 |
49 | public GPUImagePixelationFilter() {
50 | super(NO_FILTER_VERTEX_SHADER, PIXELATION_FRAGMENT_SHADER);
51 | mPixel = 1.0f;
52 | }
53 |
54 | @Override
55 | public void onInit() {
56 | super.onInit();
57 | mImageWidthFactorLocation = GLES20.glGetUniformLocation(getProgram(), "imageWidthFactor");
58 | mImageHeightFactorLocation = GLES20.glGetUniformLocation(getProgram(), "imageHeightFactor");
59 | mPixelLocation = GLES20.glGetUniformLocation(getProgram(), "pixel");
60 | setPixel(mPixel);
61 | }
62 |
63 | @Override
64 | public void onOutputSizeChanged(final int width, final int height) {
65 | super.onOutputSizeChanged(width, height);
66 | setFloat(mImageWidthFactorLocation, 1.0f / width);
67 | setFloat(mImageHeightFactorLocation, 1.0f / height);
68 | }
69 |
70 | public void setPixel(final float pixel) {
71 | mPixel = pixel;
72 | setFloat(mPixelLocation, mPixel);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImagePosterizeFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Reduces the color range of the image.
23 | *
24 | * colorLevels: ranges from 1 to 256, with a default of 10
25 | */
26 | public class GPUImagePosterizeFilter extends GPUImageFilter {
27 | public static final String POSTERIZE_FRAGMENT_SHADER = "" +
28 | "varying highp vec2 textureCoordinate;\n" +
29 | "\n" +
30 | "uniform sampler2D inputImageTexture;\n" +
31 | "uniform highp float colorLevels;\n" +
32 | "\n" +
33 | "void main()\n" +
34 | "{\n" +
35 | " highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
36 | " \n" +
37 | " gl_FragColor = floor((textureColor * colorLevels) + vec4(0.5)) / colorLevels;\n" +
38 | "}";
39 |
40 | private int mGLUniformColorLevels;
41 | private int mColorLevels;
42 |
43 | public GPUImagePosterizeFilter() {
44 | this(10);
45 | }
46 |
47 | public GPUImagePosterizeFilter(final int colorLevels) {
48 | super(GPUImageFilter.NO_FILTER_VERTEX_SHADER, POSTERIZE_FRAGMENT_SHADER);
49 | mColorLevels = colorLevels;
50 | }
51 |
52 | @Override
53 | public void onInit() {
54 | super.onInit();
55 | mGLUniformColorLevels = GLES20.glGetUniformLocation(getProgram(), "colorLevels");
56 | setColorLevels(mColorLevels);
57 | }
58 |
59 | public void setColorLevels(final int colorLevels) {
60 | mColorLevels = colorLevels;
61 | setFloat(mGLUniformColorLevels, colorLevels);
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageRGBFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Adjusts the individual RGB channels of an image
23 | * red: Normalized values by which each color channel is multiplied. The range is from 0.0 up, with 1.0 as the default.
24 | * green:
25 | * blue:
26 | */
27 | public class GPUImageRGBFilter extends GPUImageFilter {
28 | public static final String RGB_FRAGMENT_SHADER = "" +
29 | " varying highp vec2 textureCoordinate;\n" +
30 | " \n" +
31 | " uniform sampler2D inputImageTexture;\n" +
32 | " uniform highp float red;\n" +
33 | " uniform highp float green;\n" +
34 | " uniform highp float blue;\n" +
35 | " \n" +
36 | " void main()\n" +
37 | " {\n" +
38 | " highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
39 | " \n" +
40 | " gl_FragColor = vec4(textureColor.r * red, textureColor.g * green, textureColor.b * blue, 1.0);\n" +
41 | " }\n";
42 |
43 | private int mRedLocation;
44 | private float mRed;
45 | private int mGreenLocation;
46 | private float mGreen;
47 | private int mBlueLocation;
48 | private float mBlue;
49 | private boolean mIsInitialized = false;
50 |
51 | public GPUImageRGBFilter() {
52 | this(1.0f, 1.0f, 1.0f);
53 | }
54 |
55 | public GPUImageRGBFilter(final float red, final float green, final float blue) {
56 | super(NO_FILTER_VERTEX_SHADER, RGB_FRAGMENT_SHADER);
57 | mRed = red;
58 | mGreen = green;
59 | mBlue = blue;
60 | }
61 |
62 | @Override
63 | public void onInit() {
64 | super.onInit();
65 | mRedLocation = GLES20.glGetUniformLocation(getProgram(), "red");
66 | mGreenLocation = GLES20.glGetUniformLocation(getProgram(), "green");
67 | mBlueLocation = GLES20.glGetUniformLocation(getProgram(), "blue");
68 | mIsInitialized = true;
69 | setRed(mRed);
70 | setGreen(mGreen);
71 | setBlue(mBlue);
72 | }
73 |
74 | public void setRed(final float red) {
75 | mRed = red;
76 | if (mIsInitialized) {
77 | setFloat(mRedLocation, mRed);
78 | }
79 | }
80 |
81 | public void setGreen(final float green) {
82 | mGreen = green;
83 | if (mIsInitialized) {
84 | setFloat(mGreenLocation, mGreen);
85 | }
86 | }
87 |
88 | public void setBlue(final float blue) {
89 | mBlue = blue;
90 | if (mIsInitialized) {
91 | setFloat(mBlueLocation, mBlue);
92 | }
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSaturationFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * saturation: The degree of saturation or desaturation to apply to the image (0.0 - 2.0, with 1.0 as the default)
23 | */
24 | public class GPUImageSaturationFilter extends GPUImageFilter {
25 | public static final String SATURATION_FRAGMENT_SHADER = "" +
26 | " varying highp vec2 textureCoordinate;\n" +
27 | " \n" +
28 | " uniform sampler2D inputImageTexture;\n" +
29 | " uniform lowp float saturation;\n" +
30 | " \n" +
31 | " // Values from \"Graphics Shaders: Theory and Practice\" by Bailey and Cunningham\n" +
32 | " const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" +
33 | " \n" +
34 | " void main()\n" +
35 | " {\n" +
36 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
37 | " lowp float luminance = dot(textureColor.rgb, luminanceWeighting);\n" +
38 | " lowp vec3 greyScaleColor = vec3(luminance);\n" +
39 | " \n" +
40 | " gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);\n" +
41 | " \n" +
42 | " }";
43 |
44 | private int mSaturationLocation;
45 | private float mSaturation;
46 |
47 | public GPUImageSaturationFilter() {
48 | this(1.0f);
49 | }
50 |
51 | public GPUImageSaturationFilter(final float saturation) {
52 | super(NO_FILTER_VERTEX_SHADER, SATURATION_FRAGMENT_SHADER);
53 | mSaturation = saturation;
54 | }
55 |
56 | @Override
57 | public void onInit() {
58 | super.onInit();
59 | mSaturationLocation = GLES20.glGetUniformLocation(getProgram(), "saturation");
60 | }
61 |
62 | @Override
63 | public void onInitialized() {
64 | super.onInitialized();
65 | setSaturation(mSaturation);
66 | }
67 |
68 | public void setSaturation(final float saturation) {
69 | mSaturation = saturation;
70 | setFloat(mSaturationLocation, mSaturation);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageScreenBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageScreenBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String SCREEN_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " mediump vec4 whiteColor = vec4(1.0);\n" +
31 | " gl_FragColor = whiteColor - ((whiteColor - textureColor2) * (whiteColor - textureColor));\n" +
32 | " }";
33 |
34 | public GPUImageScreenBlendFilter() {
35 | super(SCREEN_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSepiaFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | /**
20 | * Applies a simple sepia effect.
21 | */
22 | public class GPUImageSepiaFilter extends GPUImageColorMatrixFilter {
23 |
24 | public GPUImageSepiaFilter() {
25 | this(1.0f);
26 | }
27 |
28 | public GPUImageSepiaFilter(final float intensity) {
29 | super(intensity, new float[] {
30 | 0.3588f, 0.7044f, 0.1368f, 0.0f,
31 | 0.2990f, 0.5870f, 0.1140f, 0.0f,
32 | 0.2392f, 0.4696f, 0.0912f, 0.0f,
33 | 0f, 0f, 0f, 1.0f
34 | });
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSketchFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Converts video to look like a sketch.
24 | * This is just the Sobel edge detection filter with the colors inverted.
25 | */
26 | public class GPUImageSketchFilter extends GPUImageFilterGroup {
27 | public static final String SKETCH_FRAGMENT_SHADER = "" +
28 | "precision mediump float;\n" +
29 | "\n" +
30 | "varying vec2 textureCoordinate;\n" +
31 | "varying vec2 leftTextureCoordinate;\n" +
32 | "varying vec2 rightTextureCoordinate;\n" +
33 | "\n" +
34 | "varying vec2 topTextureCoordinate;\n" +
35 | "varying vec2 topLeftTextureCoordinate;\n" +
36 | "varying vec2 topRightTextureCoordinate;\n" +
37 | "\n" +
38 | "varying vec2 bottomTextureCoordinate;\n" +
39 | "varying vec2 bottomLeftTextureCoordinate;\n" +
40 | "varying vec2 bottomRightTextureCoordinate;\n" +
41 | "\n" +
42 | "uniform sampler2D inputImageTexture;\n" +
43 | "\n" +
44 | "void main()\n" +
45 | "{\n" +
46 | "float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n" +
47 | "float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n" +
48 | "float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n" +
49 | "float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n" +
50 | "float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n" +
51 | "float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n" +
52 | "float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n" +
53 | "float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n" +
54 | "float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n" +
55 | "float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n" +
56 | "\n" +
57 | "float mag = 1.0 - length(vec2(h, v));\n" +
58 | "\n" +
59 | "gl_FragColor = vec4(vec3(mag), 1.0);\n" +
60 | "}\n";
61 |
62 | public GPUImageSketchFilter() {
63 | super();
64 | addFilter(new GPUImageGrayscaleFilter());
65 | addFilter(new GPUImage3x3TextureSamplingFilter(SKETCH_FRAGMENT_SHADER));
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSmoothToonFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * This uses a similar process as the GPUImageToonFilter, only it precedes the toon effect
23 | * with a Gaussian blur to smooth out noise.
24 | */
25 | public class GPUImageSmoothToonFilter extends GPUImageFilterGroup {
26 | GPUImageGaussianBlurFilter blurFilter;
27 | GPUImageToonFilter toonFilter;
28 |
29 | /**
30 | * Setup and Tear down
31 | */
32 | public GPUImageSmoothToonFilter() {
33 | // First pass: apply a variable Gaussian blur
34 | blurFilter = new GPUImageGaussianBlurFilter();
35 | addFilter(blurFilter);
36 |
37 | // Second pass: run the Sobel edge detection on this blurred image, along with a posterization effect
38 | toonFilter = new GPUImageToonFilter();
39 | addFilter(toonFilter);
40 |
41 | getFilters().add(blurFilter);
42 |
43 | setBlurSize(0.5f);
44 | setThreshold(0.2f);
45 | setQuantizationLevels(10.0f);
46 | }
47 |
48 | /**
49 | * Accessors
50 | */
51 | public void setTexelWidth(float value) {
52 | toonFilter.setTexelWidth(value);
53 | }
54 |
55 | public void setTexelHeight(float value) {
56 | toonFilter.setTexelHeight(value);
57 | }
58 |
59 | public void setBlurSize(float value) {
60 | blurFilter.setBlurSize(value);
61 | }
62 |
63 | public void setThreshold(float value) {
64 | toonFilter.setThreshold(value);
65 | }
66 |
67 | public void setQuantizationLevels(float value) {
68 | toonFilter.setQuantizationLevels(value);
69 | }
70 |
71 | }
72 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSobelEdgeDetection.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | /**
23 | * Applies sobel edge detection on the image.
24 | */
25 | public class GPUImageSobelEdgeDetection extends GPUImageFilterGroup {
26 | public static final String SOBEL_EDGE_DETECTION = "" +
27 | "precision mediump float;\n" +
28 | "\n" +
29 | "varying vec2 textureCoordinate;\n" +
30 | "varying vec2 leftTextureCoordinate;\n" +
31 | "varying vec2 rightTextureCoordinate;\n" +
32 | "\n" +
33 | "varying vec2 topTextureCoordinate;\n" +
34 | "varying vec2 topLeftTextureCoordinate;\n" +
35 | "varying vec2 topRightTextureCoordinate;\n" +
36 | "\n" +
37 | "varying vec2 bottomTextureCoordinate;\n" +
38 | "varying vec2 bottomLeftTextureCoordinate;\n" +
39 | "varying vec2 bottomRightTextureCoordinate;\n" +
40 | "\n" +
41 | "uniform sampler2D inputImageTexture;\n" +
42 | "\n" +
43 | "void main()\n" +
44 | "{\n" +
45 | " float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n" +
46 | " float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n" +
47 | " float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n" +
48 | " float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n" +
49 | " float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n" +
50 | " float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n" +
51 | " float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n" +
52 | " float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n" +
53 | " float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n" +
54 | " float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n" +
55 | "\n" +
56 | " float mag = length(vec2(h, v));\n" +
57 | "\n" +
58 | " gl_FragColor = vec4(vec3(mag), 1.0);\n" +
59 | "}";
60 |
61 | public GPUImageSobelEdgeDetection() {
62 | super();
63 | addFilter(new GPUImageGrayscaleFilter());
64 | addFilter(new GPUImage3x3TextureSamplingFilter(SOBEL_EDGE_DETECTION));
65 | }
66 |
67 | public void setLineSize(final float size) {
68 | ((GPUImage3x3TextureSamplingFilter) getFilters().get(1)).setLineSize(size);
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSobelThresholdFilter.java:
--------------------------------------------------------------------------------
1 | package jp.co.cyberagent.android.gpuimage;
2 |
3 | import android.opengl.GLES20;
4 |
5 | public class GPUImageSobelThresholdFilter extends
6 | GPUImage3x3TextureSamplingFilter {
7 | public static final String SOBEL_THRESHOLD_EDGE_DETECTION = "" +
8 | "precision mediump float;\n" +
9 | "\n" +
10 | "varying vec2 textureCoordinate;\n" +
11 | "varying vec2 leftTextureCoordinate;\n" +
12 | "varying vec2 rightTextureCoordinate;\n" +
13 | "\n" +
14 | "varying vec2 topTextureCoordinate;\n" +
15 | "varying vec2 topLeftTextureCoordinate;\n" +
16 | "varying vec2 topRightTextureCoordinate;\n" +
17 | "\n" +
18 | "varying vec2 bottomTextureCoordinate;\n" +
19 | "varying vec2 bottomLeftTextureCoordinate;\n" +
20 | "varying vec2 bottomRightTextureCoordinate;\n" +
21 | "\n" +
22 | "uniform sampler2D inputImageTexture;\n" +
23 | "uniform lowp float threshold;\n" +
24 | "\n" +
25 | "const highp vec3 W = vec3(0.2125, 0.7154, 0.0721);\n" +
26 | "\n" +
27 | "void main()\n" +
28 | "{\n" +
29 | " float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n" +
30 | " float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n" +
31 | " float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n" +
32 | " float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n" +
33 | " float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n" +
34 | " float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n" +
35 | " float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n" +
36 | " float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n" +
37 | " float h = -topLeftIntensity - 2.0 * topIntensity - topRightIntensity + bottomLeftIntensity + 2.0 * bottomIntensity + bottomRightIntensity;\n" +
38 | " float v = -bottomLeftIntensity - 2.0 * leftIntensity - topLeftIntensity + bottomRightIntensity + 2.0 * rightIntensity + topRightIntensity;\n" +
39 | "\n" +
40 | " float mag = 1.0 - length(vec2(h, v));\n" +
41 | " mag = step(threshold, mag);\n" +
42 | "\n" +
43 | " gl_FragColor = vec4(vec3(mag), 1.0);\n" +
44 | "}\n";
45 |
46 | private int mUniformThresholdLocation;
47 | private float mThreshold = 0.9f;
48 |
49 | public GPUImageSobelThresholdFilter() {
50 | this(0.9f);
51 | }
52 |
53 | public GPUImageSobelThresholdFilter(float threshold) {
54 | super(SOBEL_THRESHOLD_EDGE_DETECTION);
55 | mThreshold = threshold;
56 | }
57 |
58 | @Override
59 | public void onInit() {
60 | super.onInit();
61 | mUniformThresholdLocation = GLES20.glGetUniformLocation(getProgram(), "threshold");
62 | }
63 |
64 | @Override
65 | public void onInitialized() {
66 | super.onInitialized();
67 | setThreshold(mThreshold);
68 | }
69 |
70 | public void setThreshold(final float threshold) {
71 | mThreshold = threshold;
72 | setFloat(mUniformThresholdLocation, threshold);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSoftLightBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageSoftLightBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String SOFT_LIGHT_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " mediump vec4 base = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " mediump vec4 overlay = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " gl_FragColor = base * (overlay.a * (base / base.a) + (2.0 * overlay * (1.0 - (base / base.a)))) + overlay * (1.0 - base.a) + base * (1.0 - overlay.a);\n" +
32 | " }";
33 |
34 | public GPUImageSoftLightBlendFilter() {
35 | super(SOFT_LIGHT_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSourceOverBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageSourceOverBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String SOURCE_OVER_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | " \n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | " \n" +
31 | " gl_FragColor = mix(textureColor, textureColor2, textureColor2.a);\n" +
32 | " }";
33 |
34 | public GPUImageSourceOverBlendFilter() {
35 | super(SOURCE_OVER_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSubtractBlendFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageSubtractBlendFilter extends GPUImageTwoInputFilter {
20 | public static final String SUBTRACT_BLEND_FRAGMENT_SHADER = "varying highp vec2 textureCoordinate;\n" +
21 | " varying highp vec2 textureCoordinate2;\n" +
22 | "\n" +
23 | " uniform sampler2D inputImageTexture;\n" +
24 | " uniform sampler2D inputImageTexture2;\n" +
25 | " \n" +
26 | " void main()\n" +
27 | " {\n" +
28 | " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" +
29 | " lowp vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);\n" +
30 | "\n" +
31 | " gl_FragColor = vec4(textureColor.rgb - textureColor2.rgb, textureColor.a);\n" +
32 | " }";
33 |
34 | public GPUImageSubtractBlendFilter() {
35 | super(SUBTRACT_BLEND_FRAGMENT_SHADER);
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageSwirlFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.graphics.PointF;
20 | import android.opengl.GLES20;
21 |
22 | /**
23 | * Creates a swirl distortion on the image.
24 | */
25 | public class GPUImageSwirlFilter extends GPUImageFilter {
26 | public static final String SWIRL_FRAGMENT_SHADER = "" +
27 | "varying highp vec2 textureCoordinate;\n" +
28 | "\n" +
29 | "uniform sampler2D inputImageTexture;\n" +
30 | "\n" +
31 | "uniform highp vec2 center;\n" +
32 | "uniform highp float radius;\n" +
33 | "uniform highp float angle;\n" +
34 | "\n" +
35 | "void main()\n" +
36 | "{\n" +
37 | "highp vec2 textureCoordinateToUse = textureCoordinate;\n" +
38 | "highp float dist = distance(center, textureCoordinate);\n" +
39 | "if (dist < radius)\n" +
40 | "{\n" +
41 | "textureCoordinateToUse -= center;\n" +
42 | "highp float percent = (radius - dist) / radius;\n" +
43 | "highp float theta = percent * percent * angle * 8.0;\n" +
44 | "highp float s = sin(theta);\n" +
45 | "highp float c = cos(theta);\n" +
46 | "textureCoordinateToUse = vec2(dot(textureCoordinateToUse, vec2(c, -s)), dot(textureCoordinateToUse, vec2(s, c)));\n" +
47 | "textureCoordinateToUse += center;\n" +
48 | "}\n" +
49 | "\n" +
50 | "gl_FragColor = texture2D(inputImageTexture, textureCoordinateToUse );\n" +
51 | "\n" +
52 | "}\n";
53 |
54 | private float mAngle;
55 | private int mAngleLocation;
56 | private float mRadius;
57 | private int mRadiusLocation;
58 | private PointF mCenter;
59 | private int mCenterLocation;
60 |
61 | public GPUImageSwirlFilter() {
62 | this(0.5f, 1.0f, new PointF(0.5f, 0.5f));
63 | }
64 |
65 | public GPUImageSwirlFilter(float radius, float angle, PointF center) {
66 | super(NO_FILTER_VERTEX_SHADER, SWIRL_FRAGMENT_SHADER);
67 | mRadius = radius;
68 | mAngle = angle;
69 | mCenter = center;
70 | }
71 |
72 | @Override
73 | public void onInit() {
74 | super.onInit();
75 | mAngleLocation = GLES20.glGetUniformLocation(getProgram(), "angle");
76 | mRadiusLocation = GLES20.glGetUniformLocation(getProgram(), "radius");
77 | mCenterLocation = GLES20.glGetUniformLocation(getProgram(), "center");
78 | }
79 |
80 | @Override
81 | public void onInitialized() {
82 | super.onInitialized();
83 | setRadius(mRadius);
84 | setAngle(mAngle);
85 | setCenter(mCenter);
86 | }
87 |
88 | /**
89 | * The radius of the distortion, ranging from 0.0 to 1.0, with a default of 0.5.
90 | *
91 | * @param radius from 0.0 to 1.0, default 0.5
92 | */
93 | public void setRadius(float radius) {
94 | mRadius = radius;
95 | setFloat(mRadiusLocation, radius);
96 | }
97 |
98 | /**
99 | * The amount of distortion to apply, with a minimum of 0.0 and a default of 1.0.
100 | *
101 | * @param angle minimum 0.0, default 1.0
102 | */
103 | public void setAngle(float angle) {
104 | mAngle = angle;
105 | setFloat(mAngleLocation, angle);
106 | }
107 |
108 | /**
109 | * The center about which to apply the distortion, with a default of (0.5, 0.5).
110 | *
111 | * @param center default (0.5, 0.5)
112 | */
113 | public void setCenter(PointF center) {
114 | mCenter = center;
115 | setPoint(mCenterLocation, center);
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageThresholdEdgeDetection.java:
--------------------------------------------------------------------------------
1 | package jp.co.cyberagent.android.gpuimage;
2 |
3 | /**
4 | * Applies sobel edge detection on the image.
5 | */
6 | public class GPUImageThresholdEdgeDetection extends GPUImageFilterGroup {
7 | public GPUImageThresholdEdgeDetection() {
8 | super();
9 | addFilter(new GPUImageGrayscaleFilter());
10 | addFilter(new GPUImageSobelThresholdFilter());
11 | }
12 |
13 | public void setLineSize(final float size) {
14 | ((GPUImage3x3TextureSamplingFilter) getFilters().get(1)).setLineSize(size);
15 | }
16 |
17 | public void setThreshold(final float threshold) {
18 | ((GPUImageSobelThresholdFilter) getFilters().get(1)).setThreshold(threshold);
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageTwoPassFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageTwoPassFilter extends GPUImageFilterGroup {
20 | public GPUImageTwoPassFilter(String firstVertexShader, String firstFragmentShader,
21 | String secondVertexShader, String secondFragmentShader) {
22 | super(null);
23 | addFilter(new GPUImageFilter(firstVertexShader, firstFragmentShader));
24 | addFilter(new GPUImageFilter(secondVertexShader, secondFragmentShader));
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageTwoPassTextureSamplingFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | public class GPUImageTwoPassTextureSamplingFilter extends GPUImageTwoPassFilter {
22 | public GPUImageTwoPassTextureSamplingFilter(String firstVertexShader, String firstFragmentShader,
23 | String secondVertexShader, String secondFragmentShader) {
24 | super(firstVertexShader, firstFragmentShader,
25 | secondVertexShader, secondFragmentShader);
26 | }
27 |
28 | @Override
29 | public void onInit() {
30 | super.onInit();
31 | initTexelOffsets();
32 | }
33 |
34 | protected void initTexelOffsets() {
35 | float ratio = getHorizontalTexelOffsetRatio();
36 | GPUImageFilter filter = mFilters.get(0);
37 | int texelWidthOffsetLocation = GLES20.glGetUniformLocation(filter.getProgram(), "texelWidthOffset");
38 | int texelHeightOffsetLocation = GLES20.glGetUniformLocation(filter.getProgram(), "texelHeightOffset");
39 | filter.setFloat(texelWidthOffsetLocation, ratio / mOutputWidth);
40 | filter.setFloat(texelHeightOffsetLocation, 0);
41 |
42 | ratio = getVerticalTexelOffsetRatio();
43 | filter = mFilters.get(1);
44 | texelWidthOffsetLocation = GLES20.glGetUniformLocation(filter.getProgram(), "texelWidthOffset");
45 | texelHeightOffsetLocation = GLES20.glGetUniformLocation(filter.getProgram(), "texelHeightOffset");
46 | filter.setFloat(texelWidthOffsetLocation, 0);
47 | filter.setFloat(texelHeightOffsetLocation, ratio / mOutputHeight);
48 | }
49 |
50 | @Override
51 | public void onOutputSizeChanged(int width, int height) {
52 | super.onOutputSizeChanged(width, height);
53 | initTexelOffsets();
54 | }
55 |
56 | public float getVerticalTexelOffsetRatio() {
57 | return 1f;
58 | }
59 |
60 | public float getHorizontalTexelOffsetRatio() {
61 | return 1f;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageVignetteFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.graphics.PointF;
20 | import android.opengl.GLES20;
21 |
22 | /**
23 | * Performs a vignetting effect, fading out the image at the edges
24 | * x:
25 | * y: The directional intensity of the vignetting, with a default of x = 0.75, y = 0.5
26 | */
27 | public class GPUImageVignetteFilter extends GPUImageFilter {
28 | public static final String VIGNETTING_FRAGMENT_SHADER = "" +
29 | " uniform sampler2D inputImageTexture;\n" +
30 | " varying highp vec2 textureCoordinate;\n" +
31 | " \n" +
32 | " uniform lowp vec2 vignetteCenter;\n" +
33 | " uniform lowp vec3 vignetteColor;\n" +
34 | " uniform highp float vignetteStart;\n" +
35 | " uniform highp float vignetteEnd;\n" +
36 | " \n" +
37 | " void main()\n" +
38 | " {\n" +
39 | " /*\n" +
40 | " lowp vec3 rgb = texture2D(inputImageTexture, textureCoordinate).rgb;\n" +
41 | " lowp float d = distance(textureCoordinate, vec2(0.5,0.5));\n" +
42 | " rgb *= (1.0 - smoothstep(vignetteStart, vignetteEnd, d));\n" +
43 | " gl_FragColor = vec4(vec3(rgb),1.0);\n" +
44 | " */\n" +
45 | " \n" +
46 | " lowp vec3 rgb = texture2D(inputImageTexture, textureCoordinate).rgb;\n" +
47 | " lowp float d = distance(textureCoordinate, vec2(vignetteCenter.x, vignetteCenter.y));\n" +
48 | " lowp float percent = smoothstep(vignetteStart, vignetteEnd, d);\n" +
49 | " gl_FragColor = vec4(mix(rgb.x, vignetteColor.x, percent), mix(rgb.y, vignetteColor.y, percent), mix(rgb.z, vignetteColor.z, percent), 1.0);\n" +
50 | " }";
51 |
52 | private int mVignetteCenterLocation;
53 | private PointF mVignetteCenter;
54 | private int mVignetteColorLocation;
55 | private float[] mVignetteColor;
56 | private int mVignetteStartLocation;
57 | private float mVignetteStart;
58 | private int mVignetteEndLocation;
59 | private float mVignetteEnd;
60 |
61 | public GPUImageVignetteFilter() {
62 | this(new PointF(), new float[] {0.0f, 0.0f, 0.0f}, 0.3f, 0.75f);
63 | }
64 |
65 | public GPUImageVignetteFilter(final PointF vignetteCenter, final float[] vignetteColor, final float vignetteStart, final float vignetteEnd) {
66 | super(NO_FILTER_VERTEX_SHADER, VIGNETTING_FRAGMENT_SHADER);
67 | mVignetteCenter = vignetteCenter;
68 | mVignetteColor = vignetteColor;
69 | mVignetteStart = vignetteStart;
70 | mVignetteEnd = vignetteEnd;
71 |
72 | }
73 |
74 | @Override
75 | public void onInit() {
76 | super.onInit();
77 | mVignetteCenterLocation = GLES20.glGetUniformLocation(getProgram(), "vignetteCenter");
78 | mVignetteColorLocation = GLES20.glGetUniformLocation(getProgram(), "vignetteColor");
79 | mVignetteStartLocation = GLES20.glGetUniformLocation(getProgram(), "vignetteStart");
80 | mVignetteEndLocation = GLES20.glGetUniformLocation(getProgram(), "vignetteEnd");
81 |
82 | setVignetteCenter(mVignetteCenter);
83 | setVignetteColor(mVignetteColor);
84 | setVignetteStart(mVignetteStart);
85 | setVignetteEnd(mVignetteEnd);
86 | }
87 |
88 |
89 | public void setVignetteCenter(final PointF vignetteCenter) {
90 | mVignetteCenter = vignetteCenter;
91 | setPoint(mVignetteCenterLocation, mVignetteCenter);
92 | }
93 |
94 | public void setVignetteColor(final float[] vignetteColor) {
95 | mVignetteColor = vignetteColor;
96 | setFloatVec3(mVignetteColorLocation, mVignetteColor);
97 | }
98 |
99 | public void setVignetteStart(final float vignetteStart) {
100 | mVignetteStart = vignetteStart;
101 | setFloat(mVignetteStartLocation, mVignetteStart);
102 | }
103 |
104 | public void setVignetteEnd(final float vignetteEnd) {
105 | mVignetteEnd = vignetteEnd;
106 | setFloat(mVignetteEndLocation, mVignetteEnd);
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageWeakPixelInclusionFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public class GPUImageWeakPixelInclusionFilter extends GPUImage3x3TextureSamplingFilter {
20 | public static final String WEAKPIXEL_FRAGMENT_SHADER = "" +
21 | "precision lowp float;\n" +
22 | "\n" +
23 | "varying vec2 textureCoordinate;\n" +
24 | "varying vec2 leftTextureCoordinate;\n" +
25 | "varying vec2 rightTextureCoordinate;\n" +
26 | "\n" +
27 | "varying vec2 topTextureCoordinate;\n" +
28 | "varying vec2 topLeftTextureCoordinate;\n" +
29 | "varying vec2 topRightTextureCoordinate;\n" +
30 | "\n" +
31 | "varying vec2 bottomTextureCoordinate;\n" +
32 | "varying vec2 bottomLeftTextureCoordinate;\n" +
33 | "varying vec2 bottomRightTextureCoordinate;\n" +
34 | "\n" +
35 | "uniform sampler2D inputImageTexture;\n" +
36 | "\n" +
37 | "void main()\n" +
38 | "{\n" +
39 | "float bottomLeftIntensity = texture2D(inputImageTexture, bottomLeftTextureCoordinate).r;\n" +
40 | "float topRightIntensity = texture2D(inputImageTexture, topRightTextureCoordinate).r;\n" +
41 | "float topLeftIntensity = texture2D(inputImageTexture, topLeftTextureCoordinate).r;\n" +
42 | "float bottomRightIntensity = texture2D(inputImageTexture, bottomRightTextureCoordinate).r;\n" +
43 | "float leftIntensity = texture2D(inputImageTexture, leftTextureCoordinate).r;\n" +
44 | "float rightIntensity = texture2D(inputImageTexture, rightTextureCoordinate).r;\n" +
45 | "float bottomIntensity = texture2D(inputImageTexture, bottomTextureCoordinate).r;\n" +
46 | "float topIntensity = texture2D(inputImageTexture, topTextureCoordinate).r;\n" +
47 | "float centerIntensity = texture2D(inputImageTexture, textureCoordinate).r;\n" +
48 | "\n" +
49 | "float pixelIntensitySum = bottomLeftIntensity + topRightIntensity + topLeftIntensity + bottomRightIntensity + leftIntensity + rightIntensity + bottomIntensity + topIntensity + centerIntensity;\n" +
50 | "float sumTest = step(1.5, pixelIntensitySum);\n" +
51 | "float pixelTest = step(0.01, centerIntensity);\n" +
52 | "\n" +
53 | "gl_FragColor = vec4(vec3(sumTest * pixelTest), 1.0);\n" +
54 | "}\n";
55 |
56 | public GPUImageWeakPixelInclusionFilter() {
57 | super(WEAKPIXEL_FRAGMENT_SHADER);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/GPUImageWhiteBalanceFilter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | import android.opengl.GLES20;
20 |
21 | /**
22 | * Adjusts the white balance of incoming image.
23 | *
24 | * temperature:
25 | * tint:
26 | */
27 | public class GPUImageWhiteBalanceFilter extends GPUImageFilter {
28 | public static final String WHITE_BALANCE_FRAGMENT_SHADER = "" +
29 | "uniform sampler2D inputImageTexture;\n" +
30 | "varying highp vec2 textureCoordinate;\n" +
31 | " \n" +
32 | "uniform lowp float temperature;\n" +
33 | "uniform lowp float tint;\n" +
34 | "\n" +
35 | "const lowp vec3 warmFilter = vec3(0.93, 0.54, 0.0);\n" +
36 | "\n" +
37 | "const mediump mat3 RGBtoYIQ = mat3(0.299, 0.587, 0.114, 0.596, -0.274, -0.322, 0.212, -0.523, 0.311);\n" +
38 | "const mediump mat3 YIQtoRGB = mat3(1.0, 0.956, 0.621, 1.0, -0.272, -0.647, 1.0, -1.105, 1.702);\n" +
39 | "\n" +
40 | "void main()\n" +
41 | "{\n" +
42 | " lowp vec4 source = texture2D(inputImageTexture, textureCoordinate);\n" +
43 | " \n" +
44 | " mediump vec3 yiq = RGBtoYIQ * source.rgb; //adjusting tint\n" +
45 | " yiq.b = clamp(yiq.b + tint*0.5226*0.1, -0.5226, 0.5226);\n" +
46 | " lowp vec3 rgb = YIQtoRGB * yiq;\n" +
47 | "\n" +
48 | " lowp vec3 processed = vec3(\n" +
49 | " (rgb.r < 0.5 ? (2.0 * rgb.r * warmFilter.r) : (1.0 - 2.0 * (1.0 - rgb.r) * (1.0 - warmFilter.r))), //adjusting temperature\n" +
50 | " (rgb.g < 0.5 ? (2.0 * rgb.g * warmFilter.g) : (1.0 - 2.0 * (1.0 - rgb.g) * (1.0 - warmFilter.g))), \n" +
51 | " (rgb.b < 0.5 ? (2.0 * rgb.b * warmFilter.b) : (1.0 - 2.0 * (1.0 - rgb.b) * (1.0 - warmFilter.b))));\n" +
52 | "\n" +
53 | " gl_FragColor = vec4(mix(rgb, processed, temperature), source.a);\n" +
54 | "}";
55 |
56 | private int mTemperatureLocation;
57 | private float mTemperature;
58 | private int mTintLocation;
59 | private float mTint;
60 |
61 | public GPUImageWhiteBalanceFilter() {
62 | this(5000.0f, 0.0f);
63 | }
64 |
65 | public GPUImageWhiteBalanceFilter(final float temperature, final float tint) {
66 | super(NO_FILTER_VERTEX_SHADER, WHITE_BALANCE_FRAGMENT_SHADER);
67 | mTemperature = temperature;
68 | mTint = tint;
69 | }
70 |
71 | @Override
72 | public void onInit() {
73 | super.onInit();
74 | mTemperatureLocation = GLES20.glGetUniformLocation(getProgram(), "temperature");
75 | mTintLocation = GLES20.glGetUniformLocation(getProgram(), "tint");
76 |
77 | setTemperature(mTemperature);
78 | setTint(mTint);
79 | }
80 |
81 |
82 | public void setTemperature(final float temperature) {
83 | mTemperature = temperature;
84 | setFloat(mTemperatureLocation, mTemperature < 5000 ? (float)(0.0004 * (mTemperature-5000.0)) : (float)(0.00006 * (mTemperature-5000.0)));
85 | }
86 |
87 | public void setTint(final float tint) {
88 | mTint = tint;
89 | setFloat(mTintLocation, (float)(mTint/100.0));
90 | }
91 | }
92 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/Rotation.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage;
18 |
19 | public enum Rotation {
20 | NORMAL, ROTATION_90, ROTATION_180, ROTATION_270;
21 |
22 | /**
23 | * Retrieves the int representation of the Rotation.
24 | *
25 | * @return 0, 90, 180 or 270
26 | */
27 | public int asInt() {
28 | switch (this) {
29 | case NORMAL: return 0;
30 | case ROTATION_90: return 90;
31 | case ROTATION_180: return 180;
32 | case ROTATION_270: return 270;
33 | default: throw new IllegalStateException("Unknown Rotation!");
34 | }
35 | }
36 |
37 | /**
38 | * Create a Rotation from an integer. Needs to be either 0, 90, 180 or 270.
39 | *
40 | * @param rotation 0, 90, 180 or 270
41 | * @return Rotation object
42 | */
43 | public static Rotation fromInt(int rotation) {
44 | switch (rotation) {
45 | case 0: return NORMAL;
46 | case 90: return ROTATION_90;
47 | case 180: return ROTATION_180;
48 | case 270: return ROTATION_270;
49 | case 360: return NORMAL;
50 | default: throw new IllegalStateException(
51 | rotation + " is an unknown rotation. Needs to be either 0, 90, 180 or 270!");
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/encoder/WindowSurface.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2013 Google Inc. All rights reserved.
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage.encoder;
18 |
19 | import android.annotation.TargetApi;
20 | import android.graphics.SurfaceTexture;
21 | import android.view.Surface;
22 |
23 | /**
24 | * Recordable EGL window surface.
25 | *
26 | * It's good practice to explicitly release() the surface, preferably from a "finally" block. 27 | */ 28 | @TargetApi(18) 29 | public class WindowSurface extends EglSurfaceBase { 30 | private Surface mSurface; 31 | private boolean mReleaseSurface; 32 | 33 | /** 34 | * Associates an EGL surface with the native window surface. 35 | *
36 | * Set releaseSurface to true if you want the Surface to be released when release() is 37 | * called. This is convenient, but can interfere with framework classes that expect to 38 | * manage the Surface themselves (e.g. if you release a SurfaceView's Surface, the 39 | * surfaceDestroyed() callback won't fire). 40 | */ 41 | public WindowSurface(EglCore eglCore, Surface surface, boolean releaseSurface) { 42 | super(eglCore); 43 | createWindowSurface(surface); 44 | mSurface = surface; 45 | mReleaseSurface = releaseSurface; 46 | } 47 | 48 | /** 49 | * Associates an EGL surface with the SurfaceTexture. 50 | */ 51 | public WindowSurface(EglCore eglCore, SurfaceTexture surfaceTexture) { 52 | super(eglCore); 53 | createWindowSurface(surfaceTexture); 54 | } 55 | 56 | /** 57 | * Releases any resources associated with the EGL surface (and, if configured to do so, 58 | * with the Surface as well). 59 | *
60 | * Does not require that the surface's EGL context be current. 61 | */ 62 | public void release() { 63 | releaseEglSurface(); 64 | if (mSurface != null) { 65 | if (mReleaseSurface) { 66 | mSurface.release(); 67 | } 68 | mSurface = null; 69 | } 70 | } 71 | 72 | /** 73 | * Recreate the EGLSurface, using the new EglBase. The caller should have already 74 | * freed the old EGLSurface with releaseEglSurface(). 75 | *
76 | * This is useful when we want to update the EGLSurface associated with a Surface. 77 | * For example, if we want to share with a different EGLContext, which can only 78 | * be done by tearing down and recreating the context. (That's handled by the caller; 79 | * this just creates a new EGLSurface for the Surface we were handed earlier.) 80 | *
81 | * If the previous EGLSurface isn't fully destroyed, e.g. it's still current on a
82 | * context somewhere, the create call will fail with complaints from the Surface
83 | * about already being connected.
84 | */
85 | public void recreate(EglCore newEglCore) {
86 | if (mSurface == null) {
87 | throw new RuntimeException("not yet implemented for SurfaceTexture");
88 | }
89 | mEglCore = newEglCore; // switch to new context
90 | createWindowSurface(mSurface); // create new surface
91 | }
92 | }
93 |
--------------------------------------------------------------------------------
/library/src/jp/co/cyberagent/android/gpuimage/util/TextureRotationUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (C) 2012 CyberAgent
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 |
17 | package jp.co.cyberagent.android.gpuimage.util;
18 |
19 | import jp.co.cyberagent.android.gpuimage.Rotation;
20 |
21 | public class TextureRotationUtil {
22 |
23 | public static final float TEXTURE_NO_ROTATION[] = {
24 | 0.0f, 1.0f,
25 | 1.0f, 1.0f,
26 | 0.0f, 0.0f,
27 | 1.0f, 0.0f,
28 | };
29 |
30 | public static final float TEXTURE_ROTATED_90[] = {
31 | 1.0f, 1.0f,
32 | 1.0f, 0.0f,
33 | 0.0f, 1.0f,
34 | 0.0f, 0.0f,
35 | };
36 | public static final float TEXTURE_ROTATED_180[] = {
37 | 1.0f, 0.0f,
38 | 0.0f, 0.0f,
39 | 1.0f, 1.0f,
40 | 0.0f, 1.0f,
41 | };
42 | public static final float TEXTURE_ROTATED_270[] = {
43 | 0.0f, 0.0f,
44 | 0.0f, 1.0f,
45 | 1.0f, 0.0f,
46 | 1.0f, 1.0f,
47 | };
48 |
49 | private TextureRotationUtil() {
50 | }
51 |
52 | public static float[] getRotation(final Rotation rotation, final boolean flipHorizontal,
53 | final boolean flipVertical) {
54 | float[] rotatedTex;
55 | switch (rotation) {
56 | case ROTATION_90:
57 | rotatedTex = TEXTURE_ROTATED_90;
58 | break;
59 | case ROTATION_180:
60 | rotatedTex = TEXTURE_ROTATED_180;
61 | break;
62 | case ROTATION_270:
63 | rotatedTex = TEXTURE_ROTATED_270;
64 | break;
65 | case NORMAL:
66 | default:
67 | rotatedTex = TEXTURE_NO_ROTATION;
68 | break;
69 | }
70 | if (flipHorizontal) {
71 | rotatedTex = new float[]{
72 | flip(rotatedTex[0]), rotatedTex[1],
73 | flip(rotatedTex[2]), rotatedTex[3],
74 | flip(rotatedTex[4]), rotatedTex[5],
75 | flip(rotatedTex[6]), rotatedTex[7],
76 | };
77 | }
78 | if (flipVertical) {
79 | rotatedTex = new float[]{
80 | rotatedTex[0], flip(rotatedTex[1]),
81 | rotatedTex[2], flip(rotatedTex[3]),
82 | rotatedTex[4], flip(rotatedTex[5]),
83 | rotatedTex[6], flip(rotatedTex[7]),
84 | };
85 | }
86 | return rotatedTex;
87 | }
88 |
89 |
90 | private static float flip(final float i) {
91 | if (i == 0.0f) {
92 | return 1.0f;
93 | }
94 | return 0.0f;
95 | }
96 | }
97 |
--------------------------------------------------------------------------------
/sample/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |