From 1706a896e766be81c59e3cb7def2ee7d1aa739e0 Mon Sep 17 00:00:00 2001 From: Leo Ma Date: Mon, 31 Oct 2016 19:12:32 +0800 Subject: [PATCH] Simplification Signed-off-by: Leo Ma --- .../advanced/MagicAmaroFilter.java | 14 +- .../advanced/MagicAntiqueFilter.java | 3 +- .../advanced/MagicBeautyFilter.java | 29 +-- .../advanced/MagicBlackCatFilter.java | 145 +++++------ .../advanced/MagicBrannanFilter.java | 94 +++---- .../advanced/MagicBrooklynFilter.java | 92 +++---- .../magicfilter/advanced/MagicCalmFilter.java | 212 +++++++-------- .../magicfilter/advanced/MagicCoolFilter.java | 3 +- .../advanced/MagicCrayonFilter.java | 19 +- .../advanced/MagicEarlyBirdFilter.java | 98 +++---- .../advanced/MagicEmeraldFilter.java | 3 +- .../advanced/MagicEvergreenFilter.java | 3 +- .../advanced/MagicFreudFilter.java | 96 +++---- .../advanced/MagicHealthyFilter.java | 178 ++++++------- .../magicfilter/advanced/MagicHefeFilter.java | 94 +++---- .../advanced/MagicHudsonFilter.java | 94 +++---- .../advanced/MagicImageAdjustFilter.java | 78 +++--- .../advanced/MagicInkwellFilter.java | 90 +++---- .../advanced/MagicKevinFilter.java | 90 +++---- .../advanced/MagicLatteFilter.java | 143 +++++----- .../magicfilter/advanced/MagicLomoFilter.java | 88 +++---- .../advanced/MagicN1977Filter.java | 94 +++---- .../advanced/MagicNashvilleFilter.java | 88 +++---- .../advanced/MagicNostalgiaFilter.java | 229 ++++++++-------- .../advanced/MagicPixarFilter.java | 88 +++---- .../magicfilter/advanced/MagicRiseFilter.java | 92 +++---- .../advanced/MagicRomanceFilter.java | 129 +++++---- .../advanced/MagicSakuraFilter.java | 131 +++++----- .../advanced/MagicSierraFilter.java | 92 +++---- .../advanced/MagicSketchFilter.java | 21 +- .../advanced/MagicSkinWhitenFilter.java | 62 +++-- .../advanced/MagicSunriseFilter.java | 246 +++++++++--------- .../advanced/MagicSunsetFilter.java | 202 +++++++------- .../advanced/MagicSutroFilter.java | 96 +++---- .../advanced/MagicSweetsFilter.java | 152 +++++------ .../advanced/MagicTenderFilter.java | 156 +++++------ .../advanced/MagicToasterFilter.java | 98 +++---- .../advanced/MagicValenciaFilter.java | 96 +++---- .../advanced/MagicWaldenFilter.java | 93 +++---- .../magicfilter/advanced/MagicWarmFilter.java | 204 +++++++-------- .../advanced/MagicWhiteCatFilter.java | 141 +++++----- .../advanced/MagicXproIIFilter.java | 100 +++---- .../base/MagicBaseGroupFilter.java | 11 +- .../magicfilter/base/MagicLookupFilter.java | 45 +--- .../gpuimage/GPUImageBrightnessFilter.java | 16 +- .../base/gpuimage/GPUImageContrastFilter.java | 16 +- .../base/gpuimage/GPUImageExposureFilter.java | 4 +- .../base/gpuimage/GPUImageFilter.java | 37 ++- .../base/gpuimage/GPUImageHueFilter.java | 48 +--- .../gpuimage/GPUImageSaturationFilter.java | 22 +- .../base/gpuimage/GPUImageSharpenFilter.java | 62 +---- .../{OpenGlUtils.java => OpenGLUtils.java} | 2 +- .../java/net/ossrs/yasea/SrsCameraView.java | 26 +- app/src/main/res/raw/beauty.glsl | 172 ++++++------ app/src/main/res/raw/blackcat.glsl | 145 +++++------ app/src/main/res/raw/brightness.glsl | 9 + app/src/main/res/raw/constrast.glsl | 9 + app/src/main/res/raw/exposure.glsl | 9 + ...lt_fragment.glsl => fragment_default.glsl} | 4 +- app/src/main/res/raw/fragment_oes.glsl | 11 + app/src/main/res/raw/hue.glsl | 43 +++ app/src/main/res/raw/lookup.glsl | 33 +++ app/src/main/res/raw/saturation.glsl | 15 ++ app/src/main/res/raw/sharpen.glsl | 22 ++ app/src/main/res/raw/vertex_default.glsl | 9 + .../{default_vertex.glsl => vertex_oes.glsl} | 4 +- app/src/main/res/raw/vertex_sharpen.glsl | 31 +++ 67 files changed, 2538 insertions(+), 2543 deletions(-) rename app/src/main/java/com/seu/magicfilter/utils/{OpenGlUtils.java => OpenGLUtils.java} (99%) create mode 100644 app/src/main/res/raw/brightness.glsl create mode 100644 app/src/main/res/raw/constrast.glsl create mode 100644 app/src/main/res/raw/exposure.glsl rename app/src/main/res/raw/{default_fragment.glsl => fragment_default.glsl} (68%) create mode 100644 app/src/main/res/raw/fragment_oes.glsl create mode 100644 app/src/main/res/raw/hue.glsl create mode 100644 app/src/main/res/raw/lookup.glsl create mode 100644 app/src/main/res/raw/saturation.glsl create mode 100644 app/src/main/res/raw/sharpen.glsl create mode 100644 app/src/main/res/raw/vertex_default.glsl rename app/src/main/res/raw/{default_vertex.glsl => vertex_oes.glsl} (59%) create mode 100644 app/src/main/res/raw/vertex_sharpen.glsl diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicAmaroFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicAmaroFilter.java index 76677a0..de600e8 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicAmaroFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicAmaroFilter.java @@ -7,7 +7,7 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicAmaroFilter extends GPUImageFilter{ private int[] inputTextureHandles = {-1,-1,-1}; @@ -15,7 +15,7 @@ public class MagicAmaroFilter extends GPUImageFilter{ private int mGLStrengthLocation; public MagicAmaroFilter(){ - super(MagicFilterType.AMARO, OpenGlUtils.readShaderFromRawResource(R.raw.amaro)); + super(MagicFilterType.AMARO, R.raw.amaro); } @Override @@ -28,7 +28,7 @@ public class MagicAmaroFilter extends GPUImageFilter{ @Override protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); @@ -37,7 +37,7 @@ public class MagicAmaroFilter extends GPUImageFilter{ @Override protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); @@ -59,9 +59,9 @@ public class MagicAmaroFilter extends GPUImageFilter{ setFloat(mGLStrengthLocation, 1.0f); runOnDraw(new Runnable(){ public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_blowout.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaromap.png"); + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_blowout.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaromap.png"); } }); } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicAntiqueFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicAntiqueFilter.java index cbd5851..e387b3a 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicAntiqueFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicAntiqueFilter.java @@ -8,14 +8,13 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicAntiqueFilter extends GPUImageFilter{ private int[] mToneCurveTexture = {-1}; private int mToneCurveTextureUniformLocation; public MagicAntiqueFilter(){ - super(MagicFilterType.ANTIQUE, OpenGlUtils.readShaderFromRawResource(R.raw.antique)); + super(MagicFilterType.ANTIQUE, R.raw.antique); } @Override diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicBeautyFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicBeautyFilter.java index cf99860..3182762 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicBeautyFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicBeautyFilter.java @@ -6,25 +6,20 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; /** * Created by Administrator on 2016/5/22. */ public class MagicBeautyFilter extends GPUImageFilter{ private int mSingleStepOffsetLocation; - private int mParamsLocation; - private int mBeautyLevel = 3; public MagicBeautyFilter(){ - super(MagicFilterType.BEAUTY, OpenGlUtils.readShaderFromRawResource(R.raw.beauty)); + super(MagicFilterType.BEAUTY, R.raw.beauty); } protected void onInit() { super.onInit(); mSingleStepOffsetLocation = GLES20.glGetUniformLocation(getProgram(), "singleStepOffset"); - mParamsLocation = GLES20.glGetUniformLocation(getProgram(), "params"); - setBeautyLevel(mBeautyLevel); } @Override @@ -32,26 +27,4 @@ public class MagicBeautyFilter extends GPUImageFilter{ super.onInputSizeChanged(width, height); setFloatVec2(mSingleStepOffsetLocation, new float[] {2.0f / width, 2.0f / height}); } - - public void setBeautyLevel(int level){ - switch (level) { - case 1: - setFloat(mParamsLocation, 1.0f); - break; - case 2: - setFloat(mParamsLocation, 0.8f); - break; - case 3: - setFloat(mParamsLocation,0.6f); - break; - case 4: - setFloat(mParamsLocation, 0.4f); - break; - case 5: - setFloat(mParamsLocation,0.33f); - break; - default: - break; - } - } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicBlackCatFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicBlackCatFilter.java index 1f7bc25..1e38ceb 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicBlackCatFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicBlackCatFilter.java @@ -8,84 +8,83 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicBlackCatFilter extends GPUImageFilter{ - - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - - public MagicBlackCatFilter(){ - super(MagicFilterType.BLACKCAT, OpenGlUtils.readShaderFromRawResource(R.raw.blackcat)); - } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + public MagicBlackCatFilter(){ + super(MagicFilterType.BLACKCAT, R.raw.blackcat); + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[2048]; - int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 5, 7, 8, 10, 11, 13, 15, 16, 18, 20, 21, 23, 24, 26, 28, 29, 31, 33, 34, 36, 37, 39, 41, 42, 44, 45, 47, 49, 50, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 129, 131, 132, 134, 135, 136, 138, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 176, 178, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 248, 249, 250, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; - int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 5, 7, 8, 10, 11, 13, 15, 16, 16, 18, 20, 21, 23, 24, 26, 28, 29, 31, 33, 34, 36, 37, 39, 41, 41, 42, 44, 45, 47, 49, 50, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 80, 82, 83, 85, 86, 86, 88, 90, 91, 93, 94, 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 129, 131, 134, 135, 136, 138, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 176, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 199, 200, 201, 203, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 219, 220, 220, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 229, 230, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 242, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 248, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; - int[] arrayOfInt3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 3, 5, 7, 8, 10, 10, 11, 13, 15, 16, 18, 20, 20, 21, 23, 24, 26, 28, 29, 29, 31, 33, 34, 36, 37, 39, 39, 41, 42, 44, 45, 47, 49, 50, 50, 52, 53, 55, 57, 58, 60, 61, 63, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 79, 80, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 97, 99, 100, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 129, 131, 132, 134, 135, 136, 138, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 176, 178, 179, 180, 181, 182, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 215, 216, 218, 219, 220, 220, 221, 222, 223, 224, 225, 226, 227, 227, 228, 229, 229, 230, 232, 232, 233, 234, 234, 235, 236, 236, 238, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 250, 250, 251, 251, 252, 253, 254, 254, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(3 + i * 4)] = -1; - } - int[] arrayOfInt4 = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 16, 17, 18, 18, 19, 19, 20, 21, 21, 23, 24, 25, 26, 26, 26, 27, 28, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, 38, 38, 38, 39, 40, 41, 43, 44, 45, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 62, 63, 64, 65, 65, 66, 67, 68, 69, 70, 70, 71, 72, 74, 75, 76, 76, 77, 78, 79, 80, 81, 82, 82, 83, 85, 86, 87, 88, 89, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 101, 102, 103, 104, 105, 107, 107, 108, 109, 111, 112, 113, 114, 114, 115, 116, 117, 119, 120, 120, 121, 122, 123, 124, 125, 126, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 139, 141, 142, 143, 144, 145, 145, 146, 147, 148, 149, 151, 151, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 189, 189, 190, 191, 192, 193, 194, 195, 195, 196, 198, 199, 201, 202, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 213, 214, 214, 215, 216, 218, 219, 220, 221, 221, 222, 223, 225, 227, 227, 228, 229, 230, 230, 230, 230, 230, 230, 230, 230, 230 }; - int[] arrayOfInt5 = { 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 84, 86, 87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 126, 128, 129, 131, 132, 134, 135, 137, 138, 140, 141, 142, 144, 145, 147, 148, 149, 151, 152, 154, 155, 156, 158, 159, 160, 162, 163, 164, 166, 167, 168, 170, 171, 172, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 225, 225, 226, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 252, 253, 253, 254, 254, 254, 255, 255 }; - int[] arrayOfInt6 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt4[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); - arrayOfByte[(3 + (1024 + j * 4))] = -1; - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - } - }); - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + } + + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + } + + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[2048]; + int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 5, 7, 8, 10, 11, 13, 15, 16, 18, 20, 21, 23, 24, 26, 28, 29, 31, 33, 34, 36, 37, 39, 41, 42, 44, 45, 47, 49, 50, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 129, 131, 132, 134, 135, 136, 138, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 176, 178, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 248, 249, 250, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; + int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 5, 7, 8, 10, 11, 13, 15, 16, 16, 18, 20, 21, 23, 24, 26, 28, 29, 31, 33, 34, 36, 37, 39, 41, 41, 42, 44, 45, 47, 49, 50, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 80, 82, 83, 85, 86, 86, 88, 90, 91, 93, 94, 96, 97, 99, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 129, 131, 134, 135, 136, 138, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 176, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 199, 200, 201, 203, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 219, 220, 220, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 229, 230, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 242, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 248, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; + int[] arrayOfInt3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 3, 5, 7, 8, 10, 10, 11, 13, 15, 16, 18, 20, 20, 21, 23, 24, 26, 28, 29, 29, 31, 33, 34, 36, 37, 39, 39, 41, 42, 44, 45, 47, 49, 50, 50, 52, 53, 55, 57, 58, 60, 61, 63, 63, 65, 66, 68, 69, 71, 72, 74, 76, 77, 79, 79, 80, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 97, 99, 100, 100, 102, 103, 105, 106, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 127, 128, 129, 131, 132, 134, 135, 136, 138, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 176, 178, 179, 180, 181, 182, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 215, 215, 216, 218, 219, 220, 220, 221, 222, 223, 224, 225, 226, 227, 227, 228, 229, 229, 230, 232, 232, 233, 234, 234, 235, 236, 236, 238, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 250, 250, 251, 251, 252, 253, 254, 254, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(3 + i * 4)] = -1; + } + int[] arrayOfInt4 = { 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 12, 13, 13, 14, 14, 15, 16, 17, 18, 18, 19, 19, 20, 21, 21, 23, 24, 25, 26, 26, 26, 27, 28, 29, 30, 31, 32, 32, 33, 34, 35, 36, 37, 38, 38, 38, 39, 40, 41, 43, 44, 45, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 62, 63, 64, 65, 65, 66, 67, 68, 69, 70, 70, 71, 72, 74, 75, 76, 76, 77, 78, 79, 80, 81, 82, 82, 83, 85, 86, 87, 88, 89, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 101, 102, 103, 104, 105, 107, 107, 108, 109, 111, 112, 113, 114, 114, 115, 116, 117, 119, 120, 120, 121, 122, 123, 124, 125, 126, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 139, 141, 142, 143, 144, 145, 145, 146, 147, 148, 149, 151, 151, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 189, 189, 190, 191, 192, 193, 194, 195, 195, 196, 198, 199, 201, 202, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 213, 214, 214, 215, 216, 218, 219, 220, 221, 221, 222, 223, 225, 227, 227, 228, 229, 230, 230, 230, 230, 230, 230, 230, 230, 230 }; + int[] arrayOfInt5 = { 0, 1, 1, 2, 3, 3, 4, 5, 5, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23, 24, 25, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 84, 86, 87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109, 111, 112, 114, 115, 116, 118, 119, 121, 122, 124, 125, 126, 128, 129, 131, 132, 134, 135, 137, 138, 140, 141, 142, 144, 145, 147, 148, 149, 151, 152, 154, 155, 156, 158, 159, 160, 162, 163, 164, 166, 167, 168, 170, 171, 172, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 225, 225, 226, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 252, 253, 253, 254, 254, 254, 255, 255 }; + int[] arrayOfInt6 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt4[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); + arrayOfByte[(3 + (1024 + j * 4))] = -1; + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicBrannanFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicBrannanFilter.java index 9c6d00b..f0b8756 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicBrannanFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicBrannanFilter.java @@ -7,64 +7,64 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicBrannanFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; private int mGLStrengthLocation; - public MagicBrannanFilter(){ - super(MagicFilterType.BRANNAN, OpenGlUtils.readShaderFromRawResource(R.raw.brannan)); - } + public MagicBrannanFilter(){ + super(MagicFilterType.BRANNAN, R.raw.brannan); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for (int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for (int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_process.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_blowout.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_contrast.png"); - inputTextureHandles[3] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_luma.png"); - inputTextureHandles[4] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_screen.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_process.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_blowout.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_contrast.png"); + inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_luma.png"); + inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_screen.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicBrooklynFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicBrooklynFilter.java index da1375d..c50cfc7 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicBrooklynFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicBrooklynFilter.java @@ -7,63 +7,63 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicBrooklynFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1}; private int mGLStrengthLocation; - public MagicBrooklynFilter(){ - super(MagicFilterType.BROOKLYN, OpenGlUtils.readShaderFromRawResource(R.raw.brooklyn)); - } + public MagicBrooklynFilter(){ + super(MagicFilterType.BROOKLYN, R.raw.brooklyn); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for (int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for (int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for (int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brooklynCurves1.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/filter_map_first.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brooklynCurves2.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brooklynCurves1.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/filter_map_first.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brooklynCurves2.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicCalmFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicCalmFilter.java index 423d567..55140ed 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicCalmFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicCalmFilter.java @@ -9,119 +9,119 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicCalmFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - private int mMaskGrey2TextureId = -1; - private int mMaskGrey2UniformLocation; - - public MagicCalmFilter(){ - super(MagicFilterType.CALM, OpenGlUtils.readShaderFromRawResource(R.raw.calm)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + private int mMaskGrey2TextureId = -1; + private int mMaskGrey2UniformLocation; + + public MagicCalmFilter(){ + super(MagicFilterType.CALM, R.raw.calm); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(3, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId, mMaskGrey2TextureId}, 0); - mToneCurveTexture[0] = -1; - mMaskGrey1TextureId = -1; - mMaskGrey2TextureId = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(3, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId, mMaskGrey2TextureId}, 0); + mToneCurveTexture[0] = -1; + mMaskGrey1TextureId = -1; + mMaskGrey2TextureId = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); - GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); - } - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); + GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey1Frame"); mMaskGrey2UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey2Frame"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[3072]; - int[] arrayOfInt1 = { 38, 39, 40, 41, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 52, 53, 54, 55, 56, 57, 58, 58, 59, 60, 61, 62, 63, 64, 64, 65, 66, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 92, 93, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 121, 121, 122, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 132, 133, 134, 135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 149, 150, 151, 152, 153, 154, 155, 155, 156, 157, 158, 159, 160, 161, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 172, 172, 173, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 195, 196, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 217, 218, 218, 219, 220, 221, 222, 223, 224, 224, 225, 226, 227, 228, 229, 229, 230, 231, 232, 233, 234, 235, 235, 236, 237, 238, 239, 240, 241, 241, 242, 243, 244, 245, 246, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(3 + i * 4)] = -1; - } - int[] arrayOfInt2 = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 93, 94, 95, 96, 97, 98, 99, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 131, 132, 133, 134, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 145, 146, 147, 148, 149, 150, 150, 151, 152, 153, 154, 155, 156, 157, 157, 158, 159, 160, 161, 162, 163, 164, 165, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 196, 197, 198, 199, 200, 201, 202, 203, 204, 206, 207, 208, 209, 210, 211, 213, 214, 215, 216, 217, 218, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 232, 233, 234, 235, 237, 238, 239, 240, 241, 243, 244, 245, 246, 248, 249, 250, 251, 253, 254, 255 }; - int[] arrayOfInt3 = { 0, 1, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 42, 43, 44, 46, 47, 48, 50, 51, 53, 54, 56, 57, 59, 60, 62, 64, 65, 67, 69, 70, 72, 74, 75, 77, 79, 80, 82, 84, 85, 87, 89, 91, 92, 94, 96, 97, 99, 101, 102, 104, 106, 107, 109, 111, 112, 114, 115, 117, 118, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 147, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 196, 197, 198, 199, 200, 200, 201, 202, 203, 203, 204, 205, 206, 206, 207, 208, 209, 209, 210, 211, 211, 212, 213, 214, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 222, 223, 224, 224, 225, 226, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 234, 235, 236, 236, 237, 237, 238, 239, 239, 240, 240, 241, 242, 242, 243, 243, 244, 245, 245, 246, 246, 247, 247, 248, 249, 249, 250, 250, 251, 252, 252, 253, 253, 254, 254, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt3[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt3[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt2[j]); - arrayOfByte[(3 + (1024 + j * 4))] = -1; - } - int[] arrayOfInt4 = { 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 45, 46, 47, 49, 50, 51, 53, 54, 55, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 70, 71, 72, 74, 75, 76, 77, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 101, 103, 104, 105, 106, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 202, 203, 204, 205, 205, 206, 207, 208, 208, 209, 210, 211, 211, 212, 213, 214, 214, 215, 216, 216, 217, 218, 218, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, 239, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, 246, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 254, 254, 255 }; - int[] arrayOfInt5 = { 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 33, 33, 34, 34, 35, 35, 36, 37, 37, 38, 38, 39, 40, 40, 41, 42, 42, 43, 44, 44, 45, 46, 47, 47, 48, 49, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 62, 63, 64, 65, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 96, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 137, 138, 140, 142, 143, 145, 147, 148, 150, 152, 153, 155, 157, 159, 161, 162, 164, 166, 168, 170, 172, 174, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 247, 249, 251, 253, 255 }; - int[] arrayOfInt6 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int k = 0; k < 256; k++){ - arrayOfByte[(2048 + k * 4)] = ((byte)arrayOfInt4[k]); - arrayOfByte[(1 + (2048 + k * 4))] = ((byte)arrayOfInt5[k]); - arrayOfByte[(2 + (2048 + k * 4))] = ((byte)arrayOfInt6[k]); - arrayOfByte[(3 + (2048 + k * 4))] = -1; - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 3, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/calm_mask1.jpg"); - mMaskGrey2TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/calm_mask2.jpg"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[3072]; + int[] arrayOfInt1 = { 38, 39, 40, 41, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 52, 53, 54, 55, 56, 57, 58, 58, 59, 60, 61, 62, 63, 64, 64, 65, 66, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 75, 76, 77, 78, 79, 80, 81, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 92, 93, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 121, 121, 122, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 132, 133, 134, 135, 136, 137, 138, 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 149, 150, 151, 152, 153, 154, 155, 155, 156, 157, 158, 159, 160, 161, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 172, 172, 173, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 195, 196, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 217, 218, 218, 219, 220, 221, 222, 223, 224, 224, 225, 226, 227, 228, 229, 229, 230, 231, 232, 233, 234, 235, 235, 236, 237, 238, 239, 240, 241, 241, 242, 243, 244, 245, 246, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(3 + i * 4)] = -1; + } + int[] arrayOfInt2 = { 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, 35, 36, 37, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 93, 94, 95, 96, 97, 98, 99, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 131, 132, 133, 134, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 145, 146, 147, 148, 149, 150, 150, 151, 152, 153, 154, 155, 156, 157, 157, 158, 159, 160, 161, 162, 163, 164, 165, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 196, 197, 198, 199, 200, 201, 202, 203, 204, 206, 207, 208, 209, 210, 211, 213, 214, 215, 216, 217, 218, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 232, 233, 234, 235, 237, 238, 239, 240, 241, 243, 244, 245, 246, 248, 249, 250, 251, 253, 254, 255 }; + int[] arrayOfInt3 = { 0, 1, 1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 12, 13, 14, 15, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 42, 43, 44, 46, 47, 48, 50, 51, 53, 54, 56, 57, 59, 60, 62, 64, 65, 67, 69, 70, 72, 74, 75, 77, 79, 80, 82, 84, 85, 87, 89, 91, 92, 94, 96, 97, 99, 101, 102, 104, 106, 107, 109, 111, 112, 114, 115, 117, 118, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 147, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 196, 197, 198, 199, 200, 200, 201, 202, 203, 203, 204, 205, 206, 206, 207, 208, 209, 209, 210, 211, 211, 212, 213, 214, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 222, 223, 224, 224, 225, 226, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 234, 235, 236, 236, 237, 237, 238, 239, 239, 240, 240, 241, 242, 242, 243, 243, 244, 245, 245, 246, 246, 247, 247, 248, 249, 249, 250, 250, 251, 252, 252, 253, 253, 254, 254, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt3[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt3[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt2[j]); + arrayOfByte[(3 + (1024 + j * 4))] = -1; + } + int[] arrayOfInt4 = { 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, 22, 23, 24, 26, 27, 28, 30, 31, 33, 34, 35, 37, 38, 39, 41, 42, 43, 45, 46, 47, 49, 50, 51, 53, 54, 55, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 70, 71, 72, 74, 75, 76, 77, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 101, 103, 104, 105, 106, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 202, 203, 204, 205, 205, 206, 207, 208, 208, 209, 210, 211, 211, 212, 213, 214, 214, 215, 216, 216, 217, 218, 218, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, 239, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, 246, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 254, 254, 255 }; + int[] arrayOfInt5 = { 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 11, 12, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 21, 21, 21, 22, 22, 23, 23, 24, 24, 24, 25, 25, 26, 26, 27, 27, 28, 28, 29, 29, 30, 30, 31, 31, 32, 33, 33, 34, 34, 35, 35, 36, 37, 37, 38, 38, 39, 40, 40, 41, 42, 42, 43, 44, 44, 45, 46, 47, 47, 48, 49, 49, 50, 51, 52, 53, 53, 54, 55, 56, 57, 57, 58, 59, 60, 61, 62, 63, 64, 65, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 96, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 137, 138, 140, 142, 143, 145, 147, 148, 150, 152, 153, 155, 157, 159, 161, 162, 164, 166, 168, 170, 172, 174, 175, 177, 179, 181, 183, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 224, 226, 228, 230, 232, 234, 236, 238, 240, 242, 244, 247, 249, 251, 253, 255 }; + int[] arrayOfInt6 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int k = 0; k < 256; k++){ + arrayOfByte[(2048 + k * 4)] = ((byte)arrayOfInt4[k]); + arrayOfByte[(1 + (2048 + k * 4))] = ((byte)arrayOfInt5[k]); + arrayOfByte[(2 + (2048 + k * 4))] = ((byte)arrayOfInt6[k]); + arrayOfByte[(3 + (2048 + k * 4))] = -1; + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 3, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/calm_mask1.jpg"); + mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/calm_mask2.jpg"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicCoolFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicCoolFilter.java index 2c5bc84..fe7a577 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicCoolFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicCoolFilter.java @@ -8,14 +8,13 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicCoolFilter extends GPUImageFilter { private int[] mToneCurveTexture = {-1}; private int mToneCurveTextureUniformLocation; public MagicCoolFilter(){ - super(MagicFilterType.COOL, OpenGlUtils.readShaderFromRawResource(R.raw.cool)); + super(MagicFilterType.COOL, R.raw.cool); } @Override diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicCrayonFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicCrayonFilter.java index 7cd8197..cddc5d0 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicCrayonFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicCrayonFilter.java @@ -6,20 +6,19 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicCrayonFilter extends GPUImageFilter{ - - private int mSingleStepOffsetLocation; - //1.0 - 5.0 - private int mStrengthLocation; - - public MagicCrayonFilter(){ - super(MagicFilterType.CRAYON, OpenGlUtils.readShaderFromRawResource(R.raw.crayon)); - } + + private int mSingleStepOffsetLocation; + //1.0 - 5.0 + private int mStrengthLocation; + + public MagicCrayonFilter(){ + super(MagicFilterType.CRAYON, R.raw.crayon); + } @Override - protected void onInit() { + protected void onInit() { super.onInit(); mSingleStepOffsetLocation = GLES20.glGetUniformLocation(getProgram(), "singleStepOffset"); mStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicEarlyBirdFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicEarlyBirdFilter.java index 7784930..2863d7f 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicEarlyBirdFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicEarlyBirdFilter.java @@ -7,65 +7,65 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicEarlyBirdFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; - protected int mGLStrengthLocation; + private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; + protected int mGLStrengthLocation; - public MagicEarlyBirdFilter(){ - super(MagicFilterType.EARLYBIRD, OpenGlUtils.readShaderFromRawResource(R.raw.earlybird)); - } + public MagicEarlyBirdFilter(){ + super(MagicFilterType.EARLYBIRD, R.raw.earlybird); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++) - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++) + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdcurves.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdoverlaymap_new.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignettemap_new.png"); - inputTextureHandles[3] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdblowout.png"); - inputTextureHandles[4] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdmap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdcurves.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdoverlaymap_new.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignettemap_new.png"); + inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdblowout.png"); + inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdmap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicEmeraldFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicEmeraldFilter.java index 7286e59..c3959e6 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicEmeraldFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicEmeraldFilter.java @@ -8,14 +8,13 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicEmeraldFilter extends GPUImageFilter{ private int[] mToneCurveTexture = {-1}; private int mToneCurveTextureUniformLocation; public MagicEmeraldFilter(){ - super(MagicFilterType.EMERALD, OpenGlUtils.readShaderFromRawResource(R.raw.emerald)); + super(MagicFilterType.EMERALD, R.raw.emerald); } @Override diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicEvergreenFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicEvergreenFilter.java index 6163c99..606c4ee 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicEvergreenFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicEvergreenFilter.java @@ -8,14 +8,13 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicEvergreenFilter extends GPUImageFilter{ private int[] mToneCurveTexture = {-1}; private int mToneCurveTextureUniformLocation; public MagicEvergreenFilter(){ - super(MagicFilterType.EVERGREEN, OpenGlUtils.readShaderFromRawResource(R.raw.evergreen)); + super(MagicFilterType.EVERGREEN, R.raw.evergreen); } @Override diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicFreudFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicFreudFilter.java index dec4f0f..72ef6a9 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicFreudFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicFreudFilter.java @@ -7,70 +7,70 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicFreudFilter extends GPUImageFilter { - private int mTexelHeightUniformLocation; + private int mTexelHeightUniformLocation; private int mTexelWidthUniformLocation; - private int[] inputTextureHandles = {-1}; - private int[] inputTextureUniformLocations = {-1}; - private int mGLStrengthLocation; + private int[] inputTextureHandles = {-1}; + private int[] inputTextureUniformLocations = {-1}; + private int mGLStrengthLocation; - public MagicFreudFilter(){ - super(MagicFilterType.FREUD, OpenGlUtils.readShaderFromRawResource(R.raw.freud)); - } + public MagicFreudFilter(){ + super(MagicFilterType.FREUD, R.raw.freud); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(1, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for (int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for (int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for (int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for (int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - inputTextureUniformLocations[0] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture2"); - - mTexelWidthUniformLocation = GLES20.glGetUniformLocation(getProgram(), "inputImageTextureWidth"); + @Override + protected void onInit(){ + super.onInit(); + inputTextureUniformLocations[0] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture2"); + + mTexelWidthUniformLocation = GLES20.glGetUniformLocation(getProgram(), "inputImageTextureWidth"); mTexelHeightUniformLocation = GLES20.glGetUniformLocation(getProgram(), "inputImageTextureHeight"); - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/freud_rand.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/freud_rand.png"); + } + }); + } - @Override - public void onInputSizeChanged(int width, int height) { - super.onInputSizeChanged(width, height); + @Override + public void onInputSizeChanged(int width, int height) { + super.onInputSizeChanged(width, height); GLES20.glUniform1f(mTexelWidthUniformLocation, (float)width); GLES20.glUniform1f(mTexelHeightUniformLocation, (float)height); } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicHealthyFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicHealthyFilter.java index 673e2da..45547ca 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicHealthyFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicHealthyFilter.java @@ -9,105 +9,105 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicHealthyFilter extends GPUImageFilter{ - - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - private int mTexelHeightUniformLocation; - private int mTexelWidthUniformLocation; - public MagicHealthyFilter(){ - super(MagicFilterType.HEALTHY, OpenGlUtils.readShaderFromRawResource(R.raw.healthy)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + private int mTexelHeightUniformLocation; + private int mTexelWidthUniformLocation; - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - int[] texture = new int[1]; - texture[0] = mMaskGrey1TextureId; - GLES20.glDeleteTextures(1, texture, 0); - mMaskGrey1TextureId = -1; - } + public MagicHealthyFilter(){ + super(MagicFilterType.HEALTHY, R.raw.healthy); + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + int[] texture = new int[1]; + texture[0] = mMaskGrey1TextureId; + GLES20.glDeleteTextures(1, texture, 0); + mMaskGrey1TextureId = -1; + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + } + + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "mask"); mTexelWidthUniformLocation = GLES20.glGetUniformLocation(getProgram(), "texelWidthOffset"); mTexelHeightUniformLocation = GLES20.glGetUniformLocation(getProgram(), "texelHeightOffset"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[1024]; - int[] arrayOfInt1 = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 7, 8, 9, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 219, 220, 221, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 234, 235, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 249, 249, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt3 = { 0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 120, 121, 122, 124, 125, 126, 127, 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 249, 250, 251, 252, 253, 254, 255 }; - for (int i = 0; i < 256; i++) - { - arrayOfByte[(i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(3 + i * 4)] = -1; - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/healthy_mask_1.jpg"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[1024]; + int[] arrayOfInt1 = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 4, 5, 7, 8, 9, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 25, 26, 27, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 219, 220, 221, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 234, 235, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 249, 249, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt3 = { 0, 1, 2, 3, 3, 4, 5, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 120, 121, 122, 124, 125, 126, 127, 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 249, 250, 251, 252, 253, 254, 255 }; + for (int i = 0; i < 256; i++) + { + arrayOfByte[(i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(3 + i * 4)] = -1; + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/healthy_mask_1.jpg"); + } + }); + } - @Override - public void onInputSizeChanged(int width, int height){ - super.onInputSizeChanged(width, height); - GLES20.glUniform1f(mTexelWidthUniformLocation, 1.0f / width); - GLES20.glUniform1f(mTexelHeightUniformLocation, 1.0f / height); - } + @Override + public void onInputSizeChanged(int width, int height){ + super.onInputSizeChanged(width, height); + GLES20.glUniform1f(mTexelWidthUniformLocation, 1.0f / width); + GLES20.glUniform1f(mTexelHeightUniformLocation, 1.0f / height); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicHefeFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicHefeFilter.java index 6ab86ae..3e9ecf1 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicHefeFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicHefeFilter.java @@ -7,64 +7,64 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicHefeFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1,-1}; private int mGLStrengthLocation; - public MagicHefeFilter(){ - super(MagicFilterType.HEFE, OpenGlUtils.readShaderFromRawResource(R.raw.hefe)); - } + public MagicHefeFilter(){ + super(MagicFilterType.HEFE, R.raw.hefe); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/edgeburn.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefemap.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefemetal.png"); - inputTextureHandles[3] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefesoftlight.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/edgeburn.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefemap.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefemetal.png"); + inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefesoftlight.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicHudsonFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicHudsonFilter.java index ec193f5..9290151 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicHudsonFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicHudsonFilter.java @@ -7,64 +7,64 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicHudsonFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1}; private int mGLStrengthLocation; - public MagicHudsonFilter(){ - super(MagicFilterType.HUDSON, OpenGlUtils.readShaderFromRawResource(R.raw.hudson)); - } + public MagicHudsonFilter(){ + super(MagicFilterType.HUDSON, R.raw.hudson); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/ohudsonbackground.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hudsonmap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/ohudsonbackground.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hudsonmap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicImageAdjustFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicImageAdjustFilter.java index 732bdad..ecd3701 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicImageAdjustFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicImageAdjustFilter.java @@ -13,43 +13,43 @@ import com.seu.magicfilter.base.gpuimage.GPUImageSaturationFilter; import com.seu.magicfilter.base.gpuimage.GPUImageSharpenFilter; public class MagicImageAdjustFilter extends MagicBaseGroupFilter{ - - public MagicImageAdjustFilter() { - super(initFilters()); - } - - private static List initFilters(){ - List filters = new ArrayList(); - filters.add(new GPUImageContrastFilter()); - filters.add(new GPUImageBrightnessFilter()); - filters.add(new GPUImageExposureFilter()); - filters.add(new GPUImageHueFilter()); - filters.add(new GPUImageSaturationFilter()); - filters.add(new GPUImageSharpenFilter()); - return filters; - } - - public void setSharpness(final float range){ - ((GPUImageSharpenFilter) filters.get(5)).setSharpness(range); - } - - public void setHue(final float range){ - ((GPUImageHueFilter) filters.get(3)).setHue(range); - } - - public void setBrightness(final float range){ - ((GPUImageBrightnessFilter) filters.get(1)).setBrightness(range); - } - - public void setContrast(final float range){ - ((GPUImageContrastFilter) filters.get(0)).setContrast(range); - } - - public void setSaturation(final float range){ - ((GPUImageSaturationFilter) filters.get(4)).setSaturation(range); - } - - public void setExposure(final float range){ - ((GPUImageExposureFilter) filters.get(2)).setExposure(range); - } + + public MagicImageAdjustFilter() { + super(initFilters()); + } + + private static List initFilters(){ + List filters = new ArrayList(); + filters.add(new GPUImageContrastFilter()); + filters.add(new GPUImageBrightnessFilter()); + filters.add(new GPUImageExposureFilter()); + filters.add(new GPUImageHueFilter()); + filters.add(new GPUImageSaturationFilter()); + filters.add(new GPUImageSharpenFilter()); + return filters; + } + + public void setSharpness(final float range){ + ((GPUImageSharpenFilter) filters.get(5)).setSharpness(range); + } + + public void setHue(final float range){ + ((GPUImageHueFilter) filters.get(3)).setHue(range); + } + + public void setBrightness(final float range){ + ((GPUImageBrightnessFilter) filters.get(1)).setBrightness(range); + } + + public void setContrast(final float range){ + ((GPUImageContrastFilter) filters.get(0)).setContrast(range); + } + + public void setSaturation(final float range){ + ((GPUImageSaturationFilter) filters.get(4)).setSaturation(range); + } + + public void setExposure(final float range){ + ((GPUImageExposureFilter) filters.get(2)).setExposure(range); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicInkwellFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicInkwellFilter.java index e16c5f4..7550485 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicInkwellFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicInkwellFilter.java @@ -7,62 +7,62 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicInkwellFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1}; - private int[] inputTextureUniformLocations = {-1}; + private int[] inputTextureHandles = {-1}; + private int[] inputTextureUniformLocations = {-1}; private int mGLStrengthLocation; - public MagicInkwellFilter(){ - super(MagicFilterType.INKWELL, OpenGlUtils.readShaderFromRawResource(R.raw.inkwell)); - } + public MagicInkwellFilter(){ + super(MagicFilterType.INKWELL, R.raw.inkwell); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(1, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/inkwellmap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/inkwellmap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicKevinFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicKevinFilter.java index 4907416..284ed04 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicKevinFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicKevinFilter.java @@ -7,61 +7,61 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicKevinFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1}; - private int[] inputTextureUniformLocations = {-1}; - private int mGLStrengthLocation; + private int[] inputTextureHandles = {-1}; + private int[] inputTextureUniformLocations = {-1}; + private int mGLStrengthLocation; - public MagicKevinFilter(){ - super(MagicFilterType.KEVIN, OpenGlUtils.readShaderFromRawResource(R.raw.kevin_new)); - } + public MagicKevinFilter(){ + super(MagicFilterType.KEVIN, R.raw.kevin_new); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(1, inputTextureHandles, 0); for (int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/kelvinmap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/kelvinmap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicLatteFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicLatteFilter.java index 3d90fae..024cfef 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicLatteFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicLatteFilter.java @@ -8,83 +8,82 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicLatteFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - - public MagicLatteFilter(){ - super(MagicFilterType.LATTE, OpenGlUtils.readShaderFromRawResource(R.raw.latte)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + + public MagicLatteFilter(){ + super(MagicFilterType.LATTE, R.raw.latte); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); - } + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[2048]; - int[] arrayOfInt1 = { 5, 6, 8, 9, 11, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25, 26, 28, 29, 30, 32, 33, 34, 36, 37, 39, 40, 41, 43, 44, 45, 46, 48, 49, 50, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 108, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 120, 121, 122, 123, 124, 125, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; - int[] arrayOfInt2 = { 5, 6, 8, 11, 12, 14, 15, 18, 19, 21, 22, 25, 26, 28, 29, 32, 33, 34, 36, 39, 40, 41, 43, 44, 46, 48, 49, 50, 52, 54, 55, 56, 58, 59, 61, 62, 64, 65, 66, 67, 69, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 108, 108, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 120, 121, 122, 123, 125, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 145, 146, 147, 148, 148, 149, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 165, 166, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 174, 175, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 183, 184, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 192, 193, 194, 195, 196, 197, 198, 198, 199, 199, 200, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 213, 213, 214, 215, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 224, 225, 226, 226, 227, 228, 229, 230, 231, 232, 232, 233, 234, 235, 237, 238, 239, 240, 240, 241, 242, 243, 244, 245, 246, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255 }; - int[] arrayOfInt3 = { 5, 6, 8, 11, 12, 14, 15, 16, 18, 21, 22, 23, 25, 26, 28, 30, 32, 33, 34, 36, 37, 40, 41, 43, 44, 45, 46, 49, 50, 52, 53, 54, 55, 58, 59, 60, 61, 62, 64, 66, 67, 68, 69, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 83, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 108, 109, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 120, 121, 123, 124, 125, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 165, 166, 166, 167, 168, 169, 170, 170, 170, 171, 172, 173, 174, 174, 175, 176, 176, 177, 178, 178, 179, 180, 180, 181, 182, 183, 183, 184, 184, 185, 186, 187, 188, 189, 189, 189, 190, 191, 192, 192, 193, 194, 195, 196, 196, 197, 198, 198, 199, 199, 200, 201, 202, 202, 203, 204, 205, 206, 206, 207, 208, 209, 209, 210, 211, 212, 213, 213, 214, 215, 215, 215, 216, 217, 218, 218, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 233, 233, 234, 235, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(3 + i * 4)] = -1; - } - int[] arrayOfInt4 = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 131, 132, 133, 134, 135, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 161, 162, 163, 164, 165, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 179, 180, 181, 182, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 196, 197, 198, 199, 200, 202, 203, 204, 205, 206, 208, 209, 210, 211, 212, 214, 215, 216, 217, 218, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 232, 233, 234, 235, 236, 238, 239, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240 }; - int[] arrayOfInt5 = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 49, 51, 52, 53, 54, 56, 57, 58, 59, 61, 62, 63, 65, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, 90, 92, 93, 94, 96, 97, 99, 100, 101, 103, 104, 106, 107, 108, 110, 111, 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 136, 138, 139, 140, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 234, 235, 236, 236, 237, 237, 238, 238, 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 244, 245, 245, 246, 246, 247, 247, 247, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 255, 255, 255 }; - int[] arrayOfInt6 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt4[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); - arrayOfByte[(3 + (1024 + j * 4))] = -1; - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[2048]; + int[] arrayOfInt1 = { 5, 6, 8, 9, 11, 12, 14, 15, 16, 18, 19, 21, 22, 23, 25, 26, 28, 29, 30, 32, 33, 34, 36, 37, 39, 40, 41, 43, 44, 45, 46, 48, 49, 50, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 108, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 120, 121, 122, 123, 124, 125, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; + int[] arrayOfInt2 = { 5, 6, 8, 11, 12, 14, 15, 18, 19, 21, 22, 25, 26, 28, 29, 32, 33, 34, 36, 39, 40, 41, 43, 44, 46, 48, 49, 50, 52, 54, 55, 56, 58, 59, 61, 62, 64, 65, 66, 67, 69, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 85, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 108, 108, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 120, 121, 122, 123, 125, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 145, 146, 147, 148, 148, 149, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 165, 166, 166, 167, 168, 169, 170, 170, 171, 172, 173, 174, 174, 175, 175, 176, 177, 178, 178, 179, 180, 181, 182, 183, 183, 184, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 192, 193, 194, 195, 196, 197, 198, 198, 199, 199, 200, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 213, 213, 214, 215, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 224, 225, 226, 226, 227, 228, 229, 230, 231, 232, 232, 233, 234, 235, 237, 238, 239, 240, 240, 241, 242, 243, 244, 245, 246, 246, 247, 248, 249, 250, 251, 252, 252, 253, 254, 255 }; + int[] arrayOfInt3 = { 5, 6, 8, 11, 12, 14, 15, 16, 18, 21, 22, 23, 25, 26, 28, 30, 32, 33, 34, 36, 37, 40, 41, 43, 44, 45, 46, 49, 50, 52, 53, 54, 55, 58, 59, 60, 61, 62, 64, 66, 67, 68, 69, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 83, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 108, 108, 109, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 120, 121, 123, 124, 125, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 134, 135, 136, 137, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 165, 166, 166, 167, 168, 169, 170, 170, 170, 171, 172, 173, 174, 174, 175, 176, 176, 177, 178, 178, 179, 180, 180, 181, 182, 183, 183, 184, 184, 185, 186, 187, 188, 189, 189, 189, 190, 191, 192, 192, 193, 194, 195, 196, 196, 197, 198, 198, 199, 199, 200, 201, 202, 202, 203, 204, 205, 206, 206, 207, 208, 209, 209, 210, 211, 212, 213, 213, 214, 215, 215, 215, 216, 217, 218, 218, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 233, 233, 234, 235, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(3 + i * 4)] = -1; + } + int[] arrayOfInt4 = { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 10, 12, 13, 14, 15, 16, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 131, 132, 133, 134, 135, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 161, 162, 163, 164, 165, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 179, 180, 181, 182, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 196, 197, 198, 199, 200, 202, 203, 204, 205, 206, 208, 209, 210, 211, 212, 214, 215, 216, 217, 218, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 232, 233, 234, 235, 236, 238, 239, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240, 240 }; + int[] arrayOfInt5 = { 0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 49, 51, 52, 53, 54, 56, 57, 58, 59, 61, 62, 63, 65, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, 90, 92, 93, 94, 96, 97, 99, 100, 101, 103, 104, 106, 107, 108, 110, 111, 113, 114, 116, 117, 119, 120, 121, 123, 124, 126, 127, 129, 130, 132, 133, 135, 136, 138, 139, 140, 142, 143, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 234, 235, 236, 236, 237, 237, 238, 238, 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 244, 245, 245, 246, 246, 247, 247, 247, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 255, 255, 255 }; + int[] arrayOfInt6 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt4[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); + arrayOfByte[(3 + (1024 + j * 4))] = -1; + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicLomoFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicLomoFilter.java index a96d3ec..5b043da 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicLomoFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicLomoFilter.java @@ -7,63 +7,63 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicLomoFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1}; + private int[] inputTextureHandles = {-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1}; private int mGLStrengthLocation; - public MagicLomoFilter(){ - super(MagicFilterType.LOMO, OpenGlUtils.readShaderFromRawResource(R.raw.lomo)); - } + public MagicLomoFilter(){ + super(MagicFilterType.LOMO, R.raw.lomo); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); + @Override + protected void onInitialized(){ + super.onInitialized(); setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vlomomap_new.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); - } - }); - } + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vlomomap_new.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicN1977Filter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicN1977Filter.java index f319f95..29b02e4 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicN1977Filter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicN1977Filter.java @@ -7,55 +7,55 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicN1977Filter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1}; + private int[] inputTextureHandles = {-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1}; private int mGLStrengthLocation; - public MagicN1977Filter(){ - super(MagicFilterType.N1977, OpenGlUtils.readShaderFromRawResource(R.raw.n1977)); - } - - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } - - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } - - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } - - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/n1977map.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/n1977blowout.png"); - } - }); - } + public MagicN1977Filter(){ + super(MagicFilterType.N1977, R.raw.n1977); + } + + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } + + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } + + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } + + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/n1977map.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/n1977blowout.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicNashvilleFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicNashvilleFilter.java index ca085cf..6ee9632 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicNashvilleFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicNashvilleFilter.java @@ -7,61 +7,61 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicNashvilleFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1}; - private int[] inputTextureUniformLocations = {-1}; + private int[] inputTextureHandles = {-1}; + private int[] inputTextureUniformLocations = {-1}; private int mGLStrengthLocation; - public MagicNashvilleFilter(){ - super(MagicFilterType.NASHVILLE, OpenGlUtils.readShaderFromRawResource(R.raw.nashville)); - } + public MagicNashvilleFilter(){ + super(MagicFilterType.NASHVILLE, R.raw.nashville); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(1, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/nashvillemap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/nashvillemap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicNostalgiaFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicNostalgiaFilter.java index 380f153..9e65ea5 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicNostalgiaFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicNostalgiaFilter.java @@ -8,133 +8,132 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicNostalgiaFilter extends GPUImageFilter{ - private int mBlurSizeUniformLocation; - private int mTexelWidthUniformLocation; - private int mTexelHeightUniformLocation; - private int[] mToneCurveTexture = { -1 }; - private int[] mToneCurveTexture2 = { -1 }; - private int mToneCurveTextureUniformLocation; - private int mToneCurveTextureUniformLocation2; - - public MagicNostalgiaFilter(){ - super(MagicFilterType.NOSTALGIA, OpenGlUtils.readShaderFromRawResource(R.raw.nostalgia)); - } + private int mBlurSizeUniformLocation; + private int mTexelWidthUniformLocation; + private int mTexelHeightUniformLocation; + private int[] mToneCurveTexture = { -1 }; + private int[] mToneCurveTexture2 = { -1 }; + private int mToneCurveTextureUniformLocation; + private int mToneCurveTextureUniformLocation2; + + public MagicNostalgiaFilter(){ + super(MagicFilterType.NOSTALGIA, R.raw.nostalgia); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - GLES20.glDeleteTextures(1, mToneCurveTexture2, 0); - mToneCurveTexture2[0] = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + GLES20.glDeleteTextures(1, mToneCurveTexture2, 0); + mToneCurveTexture2[0] = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mToneCurveTexture2[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mToneCurveTexture2[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mToneCurveTexture2[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation2, 4); - } - GLES20.glUniform1f(mBlurSizeUniformLocation, 1.0F); - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mToneCurveTexture2[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation2, 4); + } + GLES20.glUniform1f(mBlurSizeUniformLocation, 1.0F); + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mToneCurveTextureUniformLocation2 = GLES20.glGetUniformLocation(getProgram(), "curve2"); mTexelWidthUniformLocation = GLES20.glGetUniformLocation(getProgram(), "texelWidthOffset"); mTexelHeightUniformLocation = GLES20.glGetUniformLocation(getProgram(), "texelHeightOffset"); mBlurSizeUniformLocation = GLES20.glGetUniformLocation(getProgram(), "blurSize"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte1 = new byte[2048]; - int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 6, 8, 9, 11, 13, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 39, 41, 43, 45, 47, 49, 50, 52, 54, 56, 57, 59, 61, 62, 64, 66, 68, 69, 71, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90, 91, 93, 94, 96, 97, 98, 100, 101, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 119, 120, 122, 123, 124, 125, 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 146, 147, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 188, 188, 189, 190, 191, 192, 193, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, 246, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 254, 255 }; - int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 14, 16, 17, 19, 20, 22, 23, 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 39, 40, 42, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 59, 60, 61, 63, 64, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 80, 81, 82, 84, 85, 87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 121, 122, 124, 125, 126, 127, 129, 130, 131, 132, 134, 135, 136, 137, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 244, 245, 246, 246, 247, 248, 248, 249, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; - int[] arrayOfInt3 = { 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 31, 33, 35, 37, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 65, 67, 69, 71, 73, 75, 76, 78, 80, 82, 84, 85, 87, 89, 91, 92, 94, 96, 98, 99, 101, 102, 104, 106, 107, 109, 110, 112, 114, 115, 117, 118, 119, 121, 122, 124, 125, 126, 128, 129, 130, 132, 133, 134, 135, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 177, 178, 178, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 206, 207, 208, 208, 209, 210, 210, 211, 212, 212, 213, 214, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 254, 254, 255 }; - int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte1[(0 + i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte1[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte1[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte1[(3 + i * 4)] = ((byte)arrayOfInt4[i]); - } - int[] arrayOfInt5 = { 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 32, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 74, 75, 76, 77, 79, 80, 81, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 204, 205, 206, 207, 209, 210, 211, 213, 214, 215, 217, 218, 220, 221, 222, 224, 225, 227, 228, 230, 231, 233, 234, 235, 237, 238, 240, 241, 243, 244, 246, 247, 249, 250, 252, 253, 255 }; - int[] arrayOfInt6 = { 0, 3, 6, 8, 11, 14, 16, 18, 21, 24, 26, 29, 30, 33, 35, 37, 39, 41, 43, 45, 47, 49, 50, 52, 53, 54, 56, 58, 59, 61, 62, 63, 65, 65, 66, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 133, 134, 135, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 146, 146, 147, 147, 148, 149, 149, 150, 151, 152, 153, 154, 154, 155, 156, 157, 158, 158, 159, 159, 160, 161, 161, 162, 163, 164, 164, 165, 166, 167, 167, 168, 169, 170, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176, 177, 178, 179, 179, 180, 181, 181, 182, 182, 183, 183, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 194, 194, 195, 196, 197, 197, 198, 199, 199, 200, 201, 201, 202, 203, 203, 204, 205, 205, 206, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 215, 216, 217, 217, 217, 217, 218, 219, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 228, 229, 229, 229, 230, 231, 231, 232, 232, 233, 234, 234, 235 }; - int[] arrayOfInt7 = { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 96, 97, 98, 99, 100, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 115, 116, 118, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 143, 145, 147, 148, 150, 152, 153, 155, 156, 158, 160, 161, 163, 164, 166, 167, 169, 170, 172, 173, 175, 176, 178, 179, 180, 182, 183, 185, 186, 188, 189, 190, 192, 193, 194, 196, 197, 199, 200, 201, 203, 204, 205, 206, 208, 209, 210, 212, 213, 214, 216, 217, 218, 219, 221, 222, 223, 224, 226, 227, 228, 229, 231, 232, 233, 234, 236, 237, 238, 239, 240, 242, 243, 244, 245, 247, 248, 249, 250, 251, 253, 254, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte1[(0 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); - arrayOfByte1[(1 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); - arrayOfByte1[(2 + (1024 + j * 4))] = ((byte)arrayOfInt7[j]); - arrayOfByte1[(3 + (1024 + j * 4))] = ((byte)arrayOfInt4[j]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte1)); - GLES20.glGenTextures(1, mToneCurveTexture2, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture2[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte2 = new byte[1024]; - int[] arrayOfInt8 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - int[] arrayOfInt9 = { 42, 43, 43, 44, 45, 45, 46, 47, 48, 48, 49, 50, 50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 62, 63, 64, 65, 65, 66, 67, 67, 68, 69, 70, 70, 71, 72, 72, 73, 74, 75, 75, 76, 77, 78, 78, 79, 80, 81, 81, 82, 83, 84, 84, 85, 86, 87, 87, 88, 89, 90, 91, 91, 92, 93, 94, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 103, 104, 105, 106, 107, 108, 108, 109, 110, 111, 112, 113, 113, 114, 115, 116, 117, 118, 119, 120, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 207, 207, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 246, 246, 247, 248, 248, 249, 250, 251, 251, 252, 253, 254, 254, 255 }; - int[] arrayOfInt10 = { 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 205, 205, 206, 207, 208, 209, 210, 211, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 246, 247, 248, 248, 249, 250, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; - int[] arrayOfInt11 = { 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 214, 214, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 224, 224, 225, 226, 227, 228, 229, 229, 230, 231, 232, 233, 234, 234, 235, 236, 237, 238, 239, 239, 240, 241, 242, 243, 244, 244, 245, 246, 247, 248, 248, 249, 250, 251, 252, 253, 253, 254, 255 }; - for (int k = 0; k < 256; k++){ - arrayOfByte2[(0 + k * 4)] = ((byte)arrayOfInt9[k]); - arrayOfByte2[(1 + k * 4)] = ((byte)arrayOfInt10[k]); - arrayOfByte2[(2 + k * 4)] = ((byte)arrayOfInt11[k]); - arrayOfByte2[(3 + k * 4)] = ((byte)arrayOfInt8[k]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte2)); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte1 = new byte[2048]; + int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 6, 8, 9, 11, 13, 15, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 39, 41, 43, 45, 47, 49, 50, 52, 54, 56, 57, 59, 61, 62, 64, 66, 68, 69, 71, 72, 74, 76, 77, 79, 80, 82, 84, 85, 87, 88, 90, 91, 93, 94, 96, 97, 98, 100, 101, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 119, 120, 122, 123, 124, 125, 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 140, 141, 142, 143, 144, 145, 146, 147, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 188, 188, 189, 190, 191, 192, 193, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, 246, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 254, 255 }; + int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 14, 16, 17, 19, 20, 22, 23, 24, 26, 27, 29, 30, 32, 33, 34, 36, 37, 39, 40, 42, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 59, 60, 61, 63, 64, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 80, 81, 82, 84, 85, 87, 88, 89, 91, 92, 93, 95, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109, 111, 112, 113, 115, 116, 117, 119, 120, 121, 122, 124, 125, 126, 127, 129, 130, 131, 132, 134, 135, 136, 137, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 235, 235, 236, 237, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 244, 245, 246, 246, 247, 248, 248, 249, 249, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; + int[] arrayOfInt3 = { 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 31, 33, 35, 37, 39, 41, 43, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 65, 67, 69, 71, 73, 75, 76, 78, 80, 82, 84, 85, 87, 89, 91, 92, 94, 96, 98, 99, 101, 102, 104, 106, 107, 109, 110, 112, 114, 115, 117, 118, 119, 121, 122, 124, 125, 126, 128, 129, 130, 132, 133, 134, 135, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 177, 178, 178, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 206, 207, 208, 208, 209, 210, 210, 211, 212, 212, 213, 214, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 231, 232, 233, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 254, 254, 255 }; + int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte1[(0 + i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte1[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte1[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte1[(3 + i * 4)] = ((byte)arrayOfInt4[i]); + } + int[] arrayOfInt5 = { 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 30, 32, 33, 34, 35, 37, 38, 39, 41, 42, 43, 44, 46, 47, 48, 50, 51, 52, 53, 55, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 74, 75, 76, 77, 79, 80, 81, 82, 84, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 204, 205, 206, 207, 209, 210, 211, 213, 214, 215, 217, 218, 220, 221, 222, 224, 225, 227, 228, 230, 231, 233, 234, 235, 237, 238, 240, 241, 243, 244, 246, 247, 249, 250, 252, 253, 255 }; + int[] arrayOfInt6 = { 0, 3, 6, 8, 11, 14, 16, 18, 21, 24, 26, 29, 30, 33, 35, 37, 39, 41, 43, 45, 47, 49, 50, 52, 53, 54, 56, 58, 59, 61, 62, 63, 65, 65, 66, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 133, 134, 135, 135, 135, 136, 137, 138, 139, 140, 140, 141, 142, 143, 144, 145, 146, 146, 147, 147, 148, 149, 149, 150, 151, 152, 153, 154, 154, 155, 156, 157, 158, 158, 159, 159, 160, 161, 161, 162, 163, 164, 164, 165, 166, 167, 167, 168, 169, 170, 170, 170, 171, 172, 173, 173, 174, 175, 176, 176, 177, 178, 179, 179, 180, 181, 181, 182, 182, 183, 183, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 194, 194, 195, 196, 197, 197, 198, 199, 199, 200, 201, 201, 202, 203, 203, 204, 205, 205, 206, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 215, 216, 217, 217, 217, 217, 218, 219, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 228, 229, 229, 229, 230, 231, 231, 232, 232, 233, 234, 234, 235 }; + int[] arrayOfInt7 = { 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 96, 97, 98, 99, 100, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 115, 116, 118, 119, 120, 122, 123, 125, 126, 128, 129, 131, 132, 134, 135, 137, 139, 140, 142, 143, 145, 147, 148, 150, 152, 153, 155, 156, 158, 160, 161, 163, 164, 166, 167, 169, 170, 172, 173, 175, 176, 178, 179, 180, 182, 183, 185, 186, 188, 189, 190, 192, 193, 194, 196, 197, 199, 200, 201, 203, 204, 205, 206, 208, 209, 210, 212, 213, 214, 216, 217, 218, 219, 221, 222, 223, 224, 226, 227, 228, 229, 231, 232, 233, 234, 236, 237, 238, 239, 240, 242, 243, 244, 245, 247, 248, 249, 250, 251, 253, 254, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte1[(0 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); + arrayOfByte1[(1 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); + arrayOfByte1[(2 + (1024 + j * 4))] = ((byte)arrayOfInt7[j]); + arrayOfByte1[(3 + (1024 + j * 4))] = ((byte)arrayOfInt4[j]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte1)); + GLES20.glGenTextures(1, mToneCurveTexture2, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture2[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte2 = new byte[1024]; + int[] arrayOfInt8 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + int[] arrayOfInt9 = { 42, 43, 43, 44, 45, 45, 46, 47, 48, 48, 49, 50, 50, 51, 52, 52, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 62, 63, 64, 65, 65, 66, 67, 67, 68, 69, 70, 70, 71, 72, 72, 73, 74, 75, 75, 76, 77, 78, 78, 79, 80, 81, 81, 82, 83, 84, 84, 85, 86, 87, 87, 88, 89, 90, 91, 91, 92, 93, 94, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 103, 104, 105, 106, 107, 108, 108, 109, 110, 111, 112, 113, 113, 114, 115, 116, 117, 118, 119, 120, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 207, 207, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 221, 222, 223, 224, 224, 225, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 246, 246, 247, 248, 248, 249, 250, 251, 251, 252, 253, 254, 254, 255 }; + int[] arrayOfInt10 = { 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 205, 205, 206, 207, 208, 209, 210, 211, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 246, 247, 248, 248, 249, 250, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; + int[] arrayOfInt11 = { 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 174, 175, 176, 177, 178, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 214, 214, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 224, 224, 225, 226, 227, 228, 229, 229, 230, 231, 232, 233, 234, 234, 235, 236, 237, 238, 239, 239, 240, 241, 242, 243, 244, 244, 245, 246, 247, 248, 248, 249, 250, 251, 252, 253, 253, 254, 255 }; + for (int k = 0; k < 256; k++){ + arrayOfByte2[(0 + k * 4)] = ((byte)arrayOfInt9[k]); + arrayOfByte2[(1 + k * 4)] = ((byte)arrayOfInt10[k]); + arrayOfByte2[(2 + k * 4)] = ((byte)arrayOfInt11[k]); + arrayOfByte2[(3 + k * 4)] = ((byte)arrayOfInt8[k]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte2)); + } + }); + } - @Override - public void onInputSizeChanged(int width, int height) { + @Override + public void onInputSizeChanged(int width, int height) { super.onInputSizeChanged(width, height); GLES20.glUniform1f(mTexelWidthUniformLocation, (1.0f / (float)width)); GLES20.glUniform1f(mTexelHeightUniformLocation, (1.0f / (float)height)); diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicPixarFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicPixarFilter.java index 886b785..e3545cd 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicPixarFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicPixarFilter.java @@ -7,61 +7,61 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicPixarFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1}; - private int[] inputTextureUniformLocations = {-1}; + private int[] inputTextureHandles = {-1}; + private int[] inputTextureUniformLocations = {-1}; private int mGLStrengthLocation; - public MagicPixarFilter(){ - super(MagicFilterType.PIXAR, OpenGlUtils.readShaderFromRawResource(R.raw.pixar)); - } + public MagicPixarFilter(){ + super(MagicFilterType.PIXAR, R.raw.pixar); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(1, inputTextureHandles, 0); for (int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for (int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for (int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for (int i=0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for (int i=0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/pixar_curves.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/pixar_curves.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicRiseFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicRiseFilter.java index 09ec709..071e839 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicRiseFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicRiseFilter.java @@ -7,61 +7,61 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicRiseFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1}; - - public MagicRiseFilter(){ - super(MagicFilterType.RISE, OpenGlUtils.readShaderFromRawResource(R.raw.rise)); - } + private int[] inputTextureHandles = {-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1}; + + public MagicRiseFilter(){ + super(MagicFilterType.RISE, R.raw.rise); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i=0; i < inputTextureUniformLocations.length; i++){ - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); - } - } + @Override + protected void onInit(){ + super.onInit(); + for(int i=0; i < inputTextureUniformLocations.length; i++){ + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); + } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/blackboard1024.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/risemap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/blackboard1024.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/risemap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicRomanceFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicRomanceFilter.java index 3dea9d5..4bda9ac 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicRomanceFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicRomanceFilter.java @@ -8,76 +8,75 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicRomanceFilter extends GPUImageFilter{ - - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - - public MagicRomanceFilter(){ - super(MagicFilterType.ROMANCE, OpenGlUtils.readShaderFromRawResource(R.raw.romance)); - } + + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + + public MagicRomanceFilter(){ + super(MagicFilterType.ROMANCE, R.raw.romance); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); - } + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] romance_arrayOfByte = new byte[1024]; - int[] romance_arrayOfInt1 = { 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 54, 54, 54, 55, 55, 56, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 73, 74, 75, 76, 77, 78, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 127, 128, 129, 130, 131, 133, 134, 135, 136, 138, 139, 140, 141, 143, 144, 145, 146, 148, 149, 150, 151, 153, 154, 155, 156, 158, 159, 160, 161, 162, 164, 165, 166, 167, 169, 170, 171, 172, 173, 175, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 188, 189, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 211, 212, 213, 214, 215, 216, 217, 218, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 226, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 254, 254, 255 }; - int[] romance_arrayOfInt2 = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 23, 24, 25, 26, 26, 27, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 159, 160, 161, 162, 163, 164, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 189, 190, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; - int[] romance_arrayOfInt3 = { 0, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 20, 21, 23, 25, 26, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51, 53, 54, 56, 57, 59, 60, 62, 63, 65, 66, 67, 69, 70, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 84, 86, 87, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 106, 107, 108, 109, 110, 111, 112, 112, 113, 114, 115, 116, 116, 117, 118, 119, 119, 120, 121, 122, 122, 123, 124, 124, 125, 126, 126, 127, 128, 128, 129, 130, 130, 131, 131, 132, 133, 133, 134, 134, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140, 141, 141, 142, 143, 143, 144, 144, 145, 146, 146, 147, 147, 148, 149, 149, 150, 150, 151, 152, 152, 153, 154, 154, 155, 155, 156, 157, 157, 158, 159, 159, 160, 161, 162, 162, 163, 164, 164, 165, 166, 167, 168, 168, 169, 170, 171, 172, 172, 173, 174, 175, 176, 177, 177, 178, 179, 180, 181, 182, 183, 184, 185, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 251, 252, 253, 254, 255 }; - int[] romance_arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int i = 0; i < 256; i++){ - romance_arrayOfByte[(i * 4)] = ((byte)romance_arrayOfInt1[i]); - romance_arrayOfByte[(1 + i * 4)] = ((byte)romance_arrayOfInt2[i]); - romance_arrayOfByte[(2 + i * 4)] = ((byte)romance_arrayOfInt3[i]); - romance_arrayOfByte[(3 + i * 4)] = ((byte)romance_arrayOfInt4[i]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(romance_arrayOfByte)); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] romance_arrayOfByte = new byte[1024]; + int[] romance_arrayOfInt1 = { 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 48, 48, 49, 49, 49, 49, 49, 50, 50, 50, 50, 51, 51, 51, 51, 52, 52, 52, 52, 53, 53, 53, 54, 54, 54, 55, 55, 56, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, 64, 65, 65, 66, 67, 67, 68, 69, 69, 70, 71, 72, 73, 73, 74, 75, 76, 77, 78, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 127, 128, 129, 130, 131, 133, 134, 135, 136, 138, 139, 140, 141, 143, 144, 145, 146, 148, 149, 150, 151, 153, 154, 155, 156, 158, 159, 160, 161, 162, 164, 165, 166, 167, 169, 170, 171, 172, 173, 175, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 188, 189, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 211, 212, 213, 214, 215, 216, 217, 218, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 226, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 254, 254, 255 }; + int[] romance_arrayOfInt2 = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 23, 24, 25, 26, 26, 27, 28, 29, 30, 30, 31, 32, 33, 33, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, 43, 43, 44, 45, 46, 47, 48, 49, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 111, 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 159, 160, 161, 162, 163, 164, 166, 167, 168, 169, 170, 171, 172, 174, 175, 176, 177, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 189, 190, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255 }; + int[] romance_arrayOfInt3 = { 0, 2, 3, 5, 7, 8, 10, 12, 13, 15, 17, 18, 20, 21, 23, 25, 26, 28, 30, 31, 33, 34, 36, 38, 39, 41, 42, 44, 45, 47, 48, 50, 51, 53, 54, 56, 57, 59, 60, 62, 63, 65, 66, 67, 69, 70, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 84, 86, 87, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 106, 107, 108, 109, 110, 111, 112, 112, 113, 114, 115, 116, 116, 117, 118, 119, 119, 120, 121, 122, 122, 123, 124, 124, 125, 126, 126, 127, 128, 128, 129, 130, 130, 131, 131, 132, 133, 133, 134, 134, 135, 136, 136, 137, 137, 138, 139, 139, 140, 140, 141, 141, 142, 143, 143, 144, 144, 145, 146, 146, 147, 147, 148, 149, 149, 150, 150, 151, 152, 152, 153, 154, 154, 155, 155, 156, 157, 157, 158, 159, 159, 160, 161, 162, 162, 163, 164, 164, 165, 166, 167, 168, 168, 169, 170, 171, 172, 172, 173, 174, 175, 176, 177, 177, 178, 179, 180, 181, 182, 183, 184, 185, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 251, 252, 253, 254, 255 }; + int[] romance_arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int i = 0; i < 256; i++){ + romance_arrayOfByte[(i * 4)] = ((byte)romance_arrayOfInt1[i]); + romance_arrayOfByte[(1 + i * 4)] = ((byte)romance_arrayOfInt2[i]); + romance_arrayOfByte[(2 + i * 4)] = ((byte)romance_arrayOfInt3[i]); + romance_arrayOfByte[(3 + i * 4)] = ((byte)romance_arrayOfInt4[i]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(romance_arrayOfByte)); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSakuraFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSakuraFilter.java index ed4438b..339f5b3 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSakuraFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSakuraFilter.java @@ -8,82 +8,81 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicSakuraFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - private int mTexelHeightUniformLocation; - private int mTexelWidthUniformLocation; - - public MagicSakuraFilter(){ - super(MagicFilterType.SAKURA, OpenGlUtils.readShaderFromRawResource(R.raw.romance)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + private int mTexelHeightUniformLocation; + private int mTexelWidthUniformLocation; + + public MagicSakuraFilter(){ + super(MagicFilterType.SAKURA, R.raw.romance); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mTexelWidthUniformLocation = GLES20.glGetUniformLocation(getProgram(), "texelWidthOffset"); mTexelHeightUniformLocation = GLES20.glGetUniformLocation(getProgram(), "texelHeightOffset"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[1024]; - int[] arrayOfInt = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; - for (int i = 0; i < 256; i++) - { - arrayOfByte[(i * 4)] = ((byte)arrayOfInt[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt[i]); - arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt[i]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[1024]; + int[] arrayOfInt = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; + for (int i = 0; i < 256; i++) + { + arrayOfByte[(i * 4)] = ((byte)arrayOfInt[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt[i]); + arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt[i]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + } + }); + } - @Override - public void onInputSizeChanged(int width, int height) { + @Override + public void onInputSizeChanged(int width, int height) { super.onInputSizeChanged(width, height); GLES20.glUniform1f(mTexelWidthUniformLocation, (1.0f / (float)width)); GLES20.glUniform1f(mTexelHeightUniformLocation, (1.0f / (float)height)); diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSierraFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSierraFilter.java index 5f9a1bf..2b3ac81 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSierraFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSierraFilter.java @@ -7,63 +7,63 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicSierraFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1}; private int mGLStrengthLocation; - public MagicSierraFilter(){ - super(MagicFilterType.SIERRA, OpenGlUtils.readShaderFromRawResource(R.raw.sierra)); - } + public MagicSierraFilter(){ + super(MagicFilterType.SIERRA, R.raw.sierra); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit(){ - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit(){ + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sierravignette.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sierramap.png"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sierravignette.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sierramap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSketchFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSketchFilter.java index f0dce6a..5c357d2 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSketchFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSketchFilter.java @@ -6,20 +6,19 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicSketchFilter extends GPUImageFilter{ - - private int mSingleStepOffsetLocation; - //0.0 - 1.0 - private int mStrengthLocation; - - public MagicSketchFilter(){ - super(MagicFilterType.SKETCH, OpenGlUtils.readShaderFromRawResource(R.raw.sketch)); - } + + private int mSingleStepOffsetLocation; + //0.0 - 1.0 + private int mStrengthLocation; + + public MagicSketchFilter(){ + super(MagicFilterType.SKETCH, R.raw.sketch); + } @Override - protected void onInit() { + protected void onInit() { super.onInit(); mSingleStepOffsetLocation = GLES20.glGetUniformLocation(getProgram(), "singleStepOffset"); mStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); @@ -36,7 +35,7 @@ public class MagicSketchFilter extends GPUImageFilter{ setFloat(mStrengthLocation, 0.5f); } - @Override + @Override public void onInputSizeChanged(final int width, final int height) { super.onInputSizeChanged(width, height); setFloatVec2(mSingleStepOffsetLocation, new float[] {1.0f / width, 1.0f / height}); diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSkinWhitenFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSkinWhitenFilter.java index e2db67c..d91f596 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSkinWhitenFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSkinWhitenFilter.java @@ -8,16 +8,15 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicSkinWhitenFilter extends GPUImageFilter { - private int mTexelHeightUniformLocation; - private int mTexelWidthUniformLocation; + private int mTexelHeightUniformLocation; + private int mTexelWidthUniformLocation; private int mToneCurveTextureUniformLocation; private int[] mToneCurveTexture = new int[] {-1}; public MagicSkinWhitenFilter() { - super(MagicFilterType.SKINWHITEN, OpenGlUtils.readShaderFromRawResource(R.raw.skinwhiten)); + super(MagicFilterType.SKINWHITEN, R.raw.skinwhiten); } @Override @@ -40,28 +39,27 @@ public class MagicSkinWhitenFilter extends GPUImageFilter { protected void onInitialized() { super.onInitialized(); runOnDraw(new Runnable() { - - public void run() { - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[1024]; - int[] arrayOfInt1 = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt2 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(3 + i * 4)] = -1; - } + public void run() { + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[1024]; + int[] arrayOfInt1 = { 95, 95, 96, 97, 97, 98, 99, 99, 100, 101, 101, 102, 103, 104, 104, 105, 106, 106, 107, 108, 108, 109, 110, 111, 111, 112, 113, 113, 114, 115, 115, 116, 117, 117, 118, 119, 120, 120, 121, 122, 122, 123, 124, 124, 125, 126, 127, 127, 128, 129, 129, 130, 131, 131, 132, 133, 133, 134, 135, 136, 136, 137, 138, 138, 139, 140, 140, 141, 142, 143, 143, 144, 145, 145, 146, 147, 147, 148, 149, 149, 150, 151, 152, 152, 153, 154, 154, 155, 156, 156, 157, 158, 159, 159, 160, 161, 161, 162, 163, 163, 164, 165, 165, 166, 167, 168, 168, 169, 170, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 182, 183, 184, 184, 185, 186, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 200, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 207, 208, 209, 209, 210, 211, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 229, 229, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 243, 244, 245, 245, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt2 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(3 + i * 4)] = -1; + } GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); } }); @@ -71,9 +69,9 @@ public class MagicSkinWhitenFilter extends GPUImageFilter { protected void onDrawArraysPre() { super.onDrawArraysPre(); if(mToneCurveTexture[0] != -1) { - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(this.mToneCurveTextureUniformLocation, 3); + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(this.mToneCurveTextureUniformLocation, 3); } } @@ -81,9 +79,9 @@ public class MagicSkinWhitenFilter extends GPUImageFilter { protected void onDrawArraysAfter() { super.onDrawArraysAfter(); if (mToneCurveTexture[0] != -1) { - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSunriseFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSunriseFilter.java index d09f18b..088a483 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSunriseFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSunriseFilter.java @@ -9,137 +9,137 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicSunriseFilter extends GPUImageFilter{ - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - private int mMaskGrey2TextureId = -1; - private int mMaskGrey2UniformLocation; - private int mMaskGrey3TextureId = -1; - private int mMaskGrey3UniformLocation; - private int[] mToneCurveTexture = { -1 }; - private int mToneCurveTextureUniformLocation; - - public MagicSunriseFilter(){ - super(MagicFilterType.SUNRISE, OpenGlUtils.readShaderFromRawResource(R.raw.sunrise)); - } + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + private int mMaskGrey2TextureId = -1; + private int mMaskGrey2UniformLocation; + private int mMaskGrey3TextureId = -1; + private int mMaskGrey3UniformLocation; + private int[] mToneCurveTexture = { -1 }; + private int mToneCurveTextureUniformLocation; + + public MagicSunriseFilter(){ + super(MagicFilterType.SUNRISE, R.raw.sunrise); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - GLES20.glDeleteTextures(1, new int[]{mMaskGrey1TextureId}, 0); - mMaskGrey1TextureId = -1; - GLES20.glDeleteTextures(1, new int[]{mMaskGrey2TextureId}, 0); - mMaskGrey2TextureId = -1; - GLES20.glDeleteTextures(1, new int[]{mMaskGrey3TextureId}, 0); - mMaskGrey3TextureId = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + GLES20.glDeleteTextures(1, new int[]{mMaskGrey1TextureId}, 0); + mMaskGrey1TextureId = -1; + GLES20.glDeleteTextures(1, new int[]{mMaskGrey2TextureId}, 0); + mMaskGrey2TextureId = -1; + GLES20.glDeleteTextures(1, new int[]{mMaskGrey3TextureId}, 0); + mMaskGrey3TextureId = -1; + } - @Override - protected void onDrawArraysAfter() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey3TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE6); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey3TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE6); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); - GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); - } - if (mMaskGrey3TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE6); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey3TextureId); - GLES20.glUniform1i(mMaskGrey3UniformLocation, 6); - } - } + @Override + protected void onDrawArraysPre() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); + GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); + } + if (mMaskGrey3TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE6); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey3TextureId); + GLES20.glUniform1i(mMaskGrey3UniformLocation, 6); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey1Frame"); mMaskGrey2UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey2Frame"); mMaskGrey3UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey3Frame"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[2048]; - int[] arrayOfInt1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 41, 42, 44, 45, 47, 49, 50, 52, 54, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 92, 94, 96, 98, 101, 103, 105, 107, 110, 111, 113, 115, 118, 120, 122, 124, 126, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 150, 152, 154, 156, 158, 159, 161, 162, 164, 166, 167, 169, 170, 172, 173, 174, 176, 177, 178, 180, 181, 182, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 200, 201, 202, 203, 203, 204, 205, 205, 207, 208, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 213, 214, 214, 215, 215, 215, 216, 216, 216, 216, 217, 217, 217, 218, 218, 218, 218, 219, 219, 219, 219, 219, 220, 220, 220, 220, 220, 220, 221, 221, 221, 221, 221, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 224, 224, 224, 224, 224, 225, 225, 225, 225, 226, 226, 226, 227, 227, 227, 228, 228, 228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 239, 239, 241, 241, 242, 243, 243, 244, 245, 245, 246, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 254, 255 }; - int[] arrayOfInt2 = { 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 17, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34, 36, 37, 39, 40, 42, 44, 45, 47, 48, 50, 52, 54, 55, 57, 59, 61, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 83, 85, 87, 90, 92, 94, 96, 98, 101, 103, 105, 107, 110, 111, 113, 115, 117, 119, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 143, 145, 147, 149, 150, 152, 154, 155, 157, 158, 160, 161, 163, 164, 165, 167, 168, 169, 171, 172, 173, 174, 175, 176, 177, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 198, 199, 199, 200, 200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 205, 207, 207, 208, 208, 208, 209, 209, 210, 210, 210, 211, 211, 211, 212, 212, 212, 213, 213, 213, 214, 214, 214, 215, 215, 215, 216, 216, 216, 217, 217, 217, 218, 218, 219, 219, 219, 220, 220, 220, 221, 221, 222, 222, 222, 223, 223, 224, 224, 225, 225, 225, 226, 226, 227, 227, 228, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 239, 239, 241, 241, 242, 242, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255 }; - int[] arrayOfInt3 = { 0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 30, 32, 33, 35, 36, 38, 39, 41, 43, 44, 46, 47, 49, 51, 53, 54, 56, 58, 60, 62, 64, 66, 68, 69, 71, 73, 76, 78, 80, 82, 83, 85, 87, 89, 91, 93, 95, 97, 100, 102, 104, 106, 108, 110, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 130, 132, 134, 136, 138, 139, 141, 143, 145, 146, 148, 150, 151, 153, 155, 156, 158, 159, 161, 162, 164, 165, 167, 168, 169, 171, 172, 173, 175, 176, 177, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 200, 201, 202, 203, 204, 204, 205, 207, 207, 208, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214, 214, 215, 215, 215, 216, 216, 217, 217, 217, 218, 218, 218, 219, 219, 219, 220, 220, 220, 220, 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 224, 224, 224, 224, 224, 225, 225, 225, 225, 225, 226, 226, 226, 226, 227, 227, 227, 227, 228, 228, 228, 228, 229, 229, 229, 230, 230, 230, 231, 231, 231, 232, 232, 233, 233, 233, 234, 234, 235, 235, 235, 236, 236, 237, 237, 238, 238, 239, 239, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 252, 252, 253, 253, 254, 254, 255 }; - int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); - } - int[] arrayOfInt5 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 172, 173, 174, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 187, 188, 189, 190, 191, 192, 194, 195, 196, 197, 198, 199, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221, 223, 224, 225, 226, 227, 228, 230, 231, 232, 233, 234, 235, 236, 238, 239, 240, 241, 242, 243, 245, 246, 247, 248, 249, 250, 252, 253, 254, 255 }; - int[] arrayOfInt6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 19, 20, 21, 22, 24, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 41, 42, 44, 45, 46, 47, 49, 50, 51, 52, 53, 55, 56, 57, 58, 60, 61, 62, 63, 65, 66, 67, 68, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81, 82, 83, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 97, 98, 100, 101, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 114, 116, 117, 118, 119, 121, 122, 123, 124, 126, 127, 128, 129, 131, 132, 133, 134, 136, 137, 138, 139, 141, 142, 143, 144, 146, 147, 148, 149, 151, 152, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 177, 178, 179, 180, 182, 183, 184, 185, 187, 188, 189, 190, 192, 193, 194, 195, 197, 198, 199, 200, 202, 203, 204, 205, 206, 208, 209, 210, 211, 213, 214, 215, 216, 218, 219, 220, 221, 223, 224, 225, 226, 228, 229, 230, 231, 233, 234, 235, 236, 238, 239, 240, 241, 243, 244, 245, 246, 248, 249, 250, 251, 253, 254, 255 }; - int[] arrayOfInt7 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 150, 152, 153, 154, 155, 156, 157, 159, 160, 161, 162, 163, 164, 165, 167, 168, 169, 170, 171, 172, 173, 175, 176, 177, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 204, 206, 207, 208, 209, 210, 211, 213, 214, 215, 216, 217, 218, 219, 221, 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 237, 238, 239, 240, 241, 242, 244, 245, 246, 247, 248, 249, 250, 252, 253, 254, 255 }; - int[] arrayOfInt8 = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 14, 15, 15, 16, 17, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 24, 25, 26, 27, 27, 28, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 44, 45, 46, 47, 48, 49, 50, 51, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 126, 127, 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 145, 146, 147, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 162, 163, 164, 165, 166, 168, 169, 170, 171, 173, 174, 175, 176, 177, 179, 180, 181, 182, 184, 185, 186, 187, 189, 190, 191, 192, 194, 195, 196, 197, 199, 200, 201, 202, 204, 205, 206, 208, 209, 210, 211, 213, 214, 215, 217, 218, 219, 221, 222, 223, 224, 226, 227, 228, 230, 231, 232, 234, 235, 236, 238, 239, 240, 242, 243, 244, 246, 247, 248, 250, 251, 252, 254, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt7[j]); - arrayOfByte[(3 + (1024 + j * 4))] = ((byte)arrayOfInt8[j]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaro_mask1.jpg"); - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - mMaskGrey2TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaro_mask2.jpg"); - GLES20.glActiveTexture(GLES20.GL_TEXTURE6); - mMaskGrey3TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toy_mask1.jpg"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[2048]; + int[] arrayOfInt1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 25, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 41, 42, 44, 45, 47, 49, 50, 52, 54, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 92, 94, 96, 98, 101, 103, 105, 107, 110, 111, 113, 115, 118, 120, 122, 124, 126, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 150, 152, 154, 156, 158, 159, 161, 162, 164, 166, 167, 169, 170, 172, 173, 174, 176, 177, 178, 180, 181, 182, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 200, 201, 202, 203, 203, 204, 205, 205, 207, 208, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 213, 214, 214, 215, 215, 215, 216, 216, 216, 216, 217, 217, 217, 218, 218, 218, 218, 219, 219, 219, 219, 219, 220, 220, 220, 220, 220, 220, 221, 221, 221, 221, 221, 222, 222, 222, 222, 222, 223, 223, 223, 223, 223, 224, 224, 224, 224, 224, 225, 225, 225, 225, 226, 226, 226, 227, 227, 227, 228, 228, 228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 239, 239, 241, 241, 242, 243, 243, 244, 245, 245, 246, 246, 247, 248, 248, 249, 250, 250, 251, 252, 252, 253, 254, 254, 255 }; + int[] arrayOfInt2 = { 0, 1, 3, 4, 5, 7, 8, 10, 11, 12, 14, 15, 17, 18, 19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34, 36, 37, 39, 40, 42, 44, 45, 47, 48, 50, 52, 54, 55, 57, 59, 61, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 83, 85, 87, 90, 92, 94, 96, 98, 101, 103, 105, 107, 110, 111, 113, 115, 117, 119, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 143, 145, 147, 149, 150, 152, 154, 155, 157, 158, 160, 161, 163, 164, 165, 167, 168, 169, 171, 172, 173, 174, 175, 176, 177, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 198, 199, 199, 200, 200, 201, 201, 202, 202, 203, 203, 204, 204, 205, 205, 205, 207, 207, 208, 208, 208, 209, 209, 210, 210, 210, 211, 211, 211, 212, 212, 212, 213, 213, 213, 214, 214, 214, 215, 215, 215, 216, 216, 216, 217, 217, 217, 218, 218, 219, 219, 219, 220, 220, 220, 221, 221, 222, 222, 222, 223, 223, 224, 224, 225, 225, 225, 226, 226, 227, 227, 228, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 239, 239, 241, 241, 242, 242, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255 }; + int[] arrayOfInt3 = { 0, 1, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21, 22, 23, 25, 26, 28, 29, 30, 32, 33, 35, 36, 38, 39, 41, 43, 44, 46, 47, 49, 51, 53, 54, 56, 58, 60, 62, 64, 66, 68, 69, 71, 73, 76, 78, 80, 82, 83, 85, 87, 89, 91, 93, 95, 97, 100, 102, 104, 106, 108, 110, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 130, 132, 134, 136, 138, 139, 141, 143, 145, 146, 148, 150, 151, 153, 155, 156, 158, 159, 161, 162, 164, 165, 167, 168, 169, 171, 172, 173, 175, 176, 177, 179, 180, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 200, 201, 202, 203, 204, 204, 205, 207, 207, 208, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214, 214, 215, 215, 215, 216, 216, 217, 217, 217, 218, 218, 218, 219, 219, 219, 220, 220, 220, 220, 221, 221, 221, 221, 222, 222, 222, 222, 223, 223, 223, 223, 224, 224, 224, 224, 224, 225, 225, 225, 225, 225, 226, 226, 226, 226, 227, 227, 227, 227, 228, 228, 228, 228, 229, 229, 229, 230, 230, 230, 231, 231, 231, 232, 232, 233, 233, 233, 234, 234, 235, 235, 235, 236, 236, 237, 237, 238, 238, 239, 239, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 249, 250, 250, 251, 252, 252, 253, 253, 254, 254, 255 }; + int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); + } + int[] arrayOfInt5 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 143, 144, 145, 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 172, 173, 174, 175, 176, 177, 178, 180, 181, 182, 183, 184, 185, 187, 188, 189, 190, 191, 192, 194, 195, 196, 197, 198, 199, 201, 202, 203, 204, 205, 206, 207, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221, 223, 224, 225, 226, 227, 228, 230, 231, 232, 233, 234, 235, 236, 238, 239, 240, 241, 242, 243, 245, 246, 247, 248, 249, 250, 252, 253, 254, 255 }; + int[] arrayOfInt6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 19, 20, 21, 22, 24, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 41, 42, 44, 45, 46, 47, 49, 50, 51, 52, 53, 55, 56, 57, 58, 60, 61, 62, 63, 65, 66, 67, 68, 70, 71, 72, 73, 75, 76, 77, 78, 80, 81, 82, 83, 85, 86, 87, 88, 90, 91, 92, 93, 95, 96, 97, 98, 100, 101, 102, 103, 104, 106, 107, 108, 109, 111, 112, 113, 114, 116, 117, 118, 119, 121, 122, 123, 124, 126, 127, 128, 129, 131, 132, 133, 134, 136, 137, 138, 139, 141, 142, 143, 144, 146, 147, 148, 149, 151, 152, 153, 154, 155, 157, 158, 159, 160, 162, 163, 164, 165, 167, 168, 169, 170, 172, 173, 174, 175, 177, 178, 179, 180, 182, 183, 184, 185, 187, 188, 189, 190, 192, 193, 194, 195, 197, 198, 199, 200, 202, 203, 204, 205, 206, 208, 209, 210, 211, 213, 214, 215, 216, 218, 219, 220, 221, 223, 224, 225, 226, 228, 229, 230, 231, 233, 234, 235, 236, 238, 239, 240, 241, 243, 244, 245, 246, 248, 249, 250, 251, 253, 254, 255 }; + int[] arrayOfInt7 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 59, 60, 61, 62, 63, 64, 65, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 90, 91, 92, 93, 94, 95, 96, 98, 99, 100, 101, 102, 103, 105, 106, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 121, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 150, 152, 153, 154, 155, 156, 157, 159, 160, 161, 162, 163, 164, 165, 167, 168, 169, 170, 171, 172, 173, 175, 176, 177, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 204, 206, 207, 208, 209, 210, 211, 213, 214, 215, 216, 217, 218, 219, 221, 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 237, 238, 239, 240, 241, 242, 244, 245, 246, 247, 248, 249, 250, 252, 253, 254, 255 }; + int[] arrayOfInt8 = { 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 12, 12, 13, 14, 14, 15, 15, 16, 17, 17, 18, 19, 19, 20, 21, 22, 22, 23, 24, 24, 25, 26, 27, 27, 28, 29, 30, 31, 31, 32, 33, 34, 34, 35, 36, 37, 38, 39, 39, 40, 41, 42, 43, 44, 44, 45, 46, 47, 48, 49, 50, 51, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 126, 127, 128, 129, 130, 131, 132, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 145, 146, 147, 149, 150, 151, 152, 153, 155, 156, 157, 158, 159, 160, 162, 163, 164, 165, 166, 168, 169, 170, 171, 173, 174, 175, 176, 177, 179, 180, 181, 182, 184, 185, 186, 187, 189, 190, 191, 192, 194, 195, 196, 197, 199, 200, 201, 202, 204, 205, 206, 208, 209, 210, 211, 213, 214, 215, 217, 218, 219, 221, 222, 223, 224, 226, 227, 228, 230, 231, 232, 234, 235, 236, 238, 239, 240, 242, 243, 244, 246, 247, 248, 250, 251, 252, 254, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt7[j]); + arrayOfByte[(3 + (1024 + j * 4))] = ((byte)arrayOfInt8[j]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaro_mask1.jpg"); + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaro_mask2.jpg"); + GLES20.glActiveTexture(GLES20.GL_TEXTURE6); + mMaskGrey3TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toy_mask1.jpg"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSunsetFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSunsetFilter.java index 5d738ef..a77d50c 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSunsetFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSunsetFilter.java @@ -9,114 +9,114 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicSunsetFilter extends GPUImageFilter{ - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - private int mMaskGrey2TextureId = -1; - private int mMaskGrey2UniformLocation; - private int[] mToneCurveTexture = { -1 }; - private int mToneCurveTextureUniformLocation; - - public MagicSunsetFilter(){ - super(MagicFilterType.SUNSET, OpenGlUtils.readShaderFromRawResource(R.raw.sunset)); - } + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + private int mMaskGrey2TextureId = -1; + private int mMaskGrey2UniformLocation; + private int[] mToneCurveTexture = { -1 }; + private int mToneCurveTextureUniformLocation; + + public MagicSunsetFilter(){ + super(MagicFilterType.SUNSET, R.raw.sunset); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(3, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId, mMaskGrey2TextureId}, 0); - mToneCurveTexture[0] = -1; - mMaskGrey1TextureId = -1; - mMaskGrey2TextureId = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(3, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId, mMaskGrey2TextureId}, 0); + mToneCurveTexture[0] = -1; + mMaskGrey1TextureId = -1; + mMaskGrey2TextureId = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); - GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); - } - } + @Override + protected void onDrawArraysPre() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); + GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); + } + } - @Override - protected void onInit() { - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit() { + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey1Frame"); mMaskGrey2UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey2Frame"); - } + } - @Override - protected void onInitialized() { - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[2048]; - int[] arrayOfInt1 = { 0, 1, 2, 3, 5, 5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 16, 18, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 38, 39, 40, 41, 42, 44, 45, 47, 48, 49, 51, 52, 54, 55, 56, 59, 60, 62, 63, 64, 66, 67, 70, 71, 72, 74, 76, 78, 79, 80, 83, 84, 85, 88, 89, 90, 93, 94, 95, 98, 99, 100, 102, 104, 106, 107, 108, 109, 112, 113, 114, 116, 117, 118, 119, 120, 122, 124, 125, 126, 128, 129, 130, 131, 132, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 142, 143, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 157, 157, 158, 159, 160, 160, 161, 162, 162, 163, 164, 165, 165, 166, 167, 167, 168, 169, 169, 170, 171, 171, 172, 173, 173, 174, 175, 175, 176, 177, 177, 178, 178, 179, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185, 186, 187, 188, 188, 189, 190, 190, 191, 192, 193, 193, 194, 194, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 204, 205, 206, 207, 208, 208, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 217, 218, 218, 219, 220, 221, 222, 222, 223, 224, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 234, 235, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 247, 248, 248, 249, 250, 251, 252, 253, 254, 255 }; - int[] arrayOfInt2 = { 0, 1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 12, 12, 13, 14, 16, 16, 17, 19, 20, 20, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, 41, 42, 43, 44, 46, 47, 49, 50, 51, 53, 54, 56, 57, 59, 61, 62, 64, 65, 66, 69, 70, 72, 73, 76, 77, 78, 80, 82, 84, 85, 87, 89, 90, 93, 94, 95, 98, 99, 100, 103, 104, 106, 108, 109, 111, 112, 114, 116, 117, 118, 120, 122, 123, 124, 125, 126, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 165, 166, 167, 167, 168, 169, 170, 170, 171, 172, 172, 173, 173, 174, 175, 175, 176, 177, 177, 178, 178, 178, 179, 179, 180, 181, 181, 182, 182, 183, 184, 184, 185, 185, 186, 187, 187, 188, 188, 189, 190, 190, 191, 191, 192, 193, 193, 194, 194, 194, 195, 195, 196, 197, 197, 198, 199, 199, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 208, 208, 208, 209, 210, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 221, 222, 222, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 234, 235, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 251, 252, 253, 254, 255 }; - int[] arrayOfInt3 = { 0, 1, 2, 3, 4, 5, 5, 7, 8, 9, 9, 11, 12, 12, 13, 14, 16, 16, 17, 18, 20, 20, 21, 22, 23, 25, 25, 26, 27, 29, 30, 31, 31, 32, 34, 35, 36, 37, 39, 40, 41, 41, 42, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 56, 57, 59, 60, 61, 63, 64, 65, 66, 67, 69, 71, 72, 73, 74, 76, 78, 79, 80, 82, 83, 84, 85, 88, 89, 90, 92, 93, 94, 95, 98, 99, 100, 102, 103, 104, 106, 107, 108, 111, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 147, 148, 149, 150, 151, 152, 153, 154, 154, 155, 156, 157, 158, 159, 159, 160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 169, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 178, 178, 178, 179, 179, 180, 181, 182, 182, 183, 184, 185, 185, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 194, 194, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 208, 209, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 235, 236, 237, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 251, 252, 253, 254, 255 }; - int[] arrayOfInt4 = { 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 14, 16, 17, 19, 20, 21, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 42, 43, 44, 45, 47, 48, 49, 51, 52, 53, 54, 55, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 121, 121, 122, 123, 124, 125, 126, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 135, 135, 136, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 230, 231, 232, 233, 234, 235, 235, 236, 237, 238, 239, 239, 240, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255 }; - for (int i = 0; i < 256; i++) - { - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); - } - int[] arrayOfInt5 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int j = 0; j < 256; j++) - { - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); - arrayOfByte[(3 + (1024 + j * 4))] = -1; - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask1.jpg"); - mMaskGrey2TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask2.jpg"); - } - }); - } + @Override + protected void onInitialized() { + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[2048]; + int[] arrayOfInt1 = { 0, 1, 2, 3, 5, 5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 16, 18, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 38, 39, 40, 41, 42, 44, 45, 47, 48, 49, 51, 52, 54, 55, 56, 59, 60, 62, 63, 64, 66, 67, 70, 71, 72, 74, 76, 78, 79, 80, 83, 84, 85, 88, 89, 90, 93, 94, 95, 98, 99, 100, 102, 104, 106, 107, 108, 109, 112, 113, 114, 116, 117, 118, 119, 120, 122, 124, 125, 126, 128, 129, 130, 131, 132, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 142, 143, 145, 146, 147, 148, 148, 149, 150, 151, 151, 152, 153, 154, 155, 155, 156, 157, 157, 158, 159, 160, 160, 161, 162, 162, 163, 164, 165, 165, 166, 167, 167, 168, 169, 169, 170, 171, 171, 172, 173, 173, 174, 175, 175, 176, 177, 177, 178, 178, 179, 179, 180, 181, 181, 182, 183, 183, 184, 185, 185, 186, 187, 188, 188, 189, 190, 190, 191, 192, 193, 193, 194, 194, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 204, 205, 206, 207, 208, 208, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 217, 218, 218, 219, 220, 221, 222, 222, 223, 224, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 234, 235, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 247, 248, 248, 249, 250, 251, 252, 253, 254, 255 }; + int[] arrayOfInt2 = { 0, 1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 12, 12, 13, 14, 16, 16, 17, 19, 20, 20, 22, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 35, 36, 37, 39, 40, 41, 42, 43, 44, 46, 47, 49, 50, 51, 53, 54, 56, 57, 59, 61, 62, 64, 65, 66, 69, 70, 72, 73, 76, 77, 78, 80, 82, 84, 85, 87, 89, 90, 93, 94, 95, 98, 99, 100, 103, 104, 106, 108, 109, 111, 112, 114, 116, 117, 118, 120, 122, 123, 124, 125, 126, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 162, 163, 164, 165, 165, 166, 167, 167, 168, 169, 170, 170, 171, 172, 172, 173, 173, 174, 175, 175, 176, 177, 177, 178, 178, 178, 179, 179, 180, 181, 181, 182, 182, 183, 184, 184, 185, 185, 186, 187, 187, 188, 188, 189, 190, 190, 191, 191, 192, 193, 193, 194, 194, 194, 195, 195, 196, 197, 197, 198, 199, 199, 200, 201, 202, 202, 203, 204, 204, 205, 206, 207, 208, 208, 208, 209, 210, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 221, 222, 222, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 234, 235, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 251, 252, 253, 254, 255 }; + int[] arrayOfInt3 = { 0, 1, 2, 3, 4, 5, 5, 7, 8, 9, 9, 11, 12, 12, 13, 14, 16, 16, 17, 18, 20, 20, 21, 22, 23, 25, 25, 26, 27, 29, 30, 31, 31, 32, 34, 35, 36, 37, 39, 40, 41, 41, 42, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 56, 57, 59, 60, 61, 63, 64, 65, 66, 67, 69, 71, 72, 73, 74, 76, 78, 79, 80, 82, 83, 84, 85, 88, 89, 90, 92, 93, 94, 95, 98, 99, 100, 102, 103, 104, 106, 107, 108, 111, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 147, 148, 149, 150, 151, 152, 153, 154, 154, 155, 156, 157, 158, 159, 159, 160, 161, 162, 162, 163, 164, 165, 166, 166, 167, 168, 169, 169, 170, 171, 172, 172, 173, 174, 175, 175, 176, 177, 178, 178, 178, 179, 179, 180, 181, 182, 182, 183, 184, 185, 185, 186, 187, 188, 188, 189, 190, 191, 191, 192, 193, 194, 194, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 208, 209, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 235, 236, 237, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 248, 249, 250, 251, 252, 253, 254, 255 }; + int[] arrayOfInt4 = { 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 14, 16, 17, 19, 20, 21, 23, 24, 26, 27, 28, 30, 31, 32, 34, 35, 36, 38, 39, 40, 42, 43, 44, 45, 47, 48, 49, 51, 52, 53, 54, 55, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 115, 116, 117, 118, 119, 120, 121, 121, 122, 123, 124, 125, 126, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 135, 135, 136, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 230, 231, 232, 233, 234, 235, 235, 236, 237, 238, 239, 239, 240, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255 }; + for (int i = 0; i < 256; i++) + { + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); + } + int[] arrayOfInt5 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int j = 0; j < 256; j++) + { + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); + arrayOfByte[(3 + (1024 + j * 4))] = -1; + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask1.jpg"); + mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask2.jpg"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSutroFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSutroFilter.java index 19ef476..4e6c5bd 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSutroFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSutroFilter.java @@ -7,64 +7,64 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicSutroFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; private int mGLStrengthLocation; - public MagicSutroFilter(){ - super(MagicFilterType.SUTRO, OpenGlUtils.readShaderFromRawResource(R.raw.sutro)); - } + public MagicSutroFilter(){ + super(MagicFilterType.SUTRO, R.raw.sutro); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for (int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } + } + + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } } - - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit() { - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit() { + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized() { - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutrometal.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/softlight.png"); - inputTextureHandles[3] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutroedgeburn.png"); - inputTextureHandles[4] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutrocurves.png"); - } - }); - } + @Override + protected void onInitialized() { + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutrometal.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/softlight.png"); + inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutroedgeburn.png"); + inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutrocurves.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicSweetsFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicSweetsFilter.java index de0655b..3b2836c 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicSweetsFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicSweetsFilter.java @@ -9,90 +9,90 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicSweetsFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - private int mLowPerformanceUniformLocation; - - public MagicSweetsFilter(){ - super(MagicFilterType.SWEETS, OpenGlUtils.readShaderFromRawResource(R.raw.sweets)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + private int mLowPerformanceUniformLocation; + + public MagicSweetsFilter(){ + super(MagicFilterType.SWEETS, R.raw.sweets); + } - @Override - protected void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(2, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId}, 0); - mToneCurveTexture[0] = -1; - mMaskGrey1TextureId = -1; - } + @Override + protected void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(2, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId}, 0); + mToneCurveTexture[0] = -1; + mMaskGrey1TextureId = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey1Frame"); mLowPerformanceUniformLocation = GLES20.glGetUniformLocation(getProgram(), "lowPerformance"); setInteger(mLowPerformanceUniformLocation, 1); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[1024]; - int[] arrayOfInt = { 0, 1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23, 24, 24, 25, 26, 27, 28, 29, 30, 30, 31, 32, 33, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 98, 99, 100, 101, 103, 104, 105, 106, 108, 109, 110, 111, 113, 114, 115, 116, 118, 119, 120, 121, 123, 124, 125, 126, 128, 129, 130, 132, 133, 134, 135, 137, 138, 139, 140, 142, 143, 144, 145, 147, 148, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 169, 170, 171, 172, 173, 174, 176, 177, 178, 179, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 246, 246, 247, 248, 248, 249, 250, 251, 251, 252, 253, 254, 254, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt[i]); - arrayOfByte[(3 + i * 4)] = ((byte)i); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask2.jpg"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[1024]; + int[] arrayOfInt = { 0, 1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 14, 15, 16, 17, 18, 19, 19, 20, 21, 22, 23, 24, 24, 25, 26, 27, 28, 29, 30, 30, 31, 32, 33, 34, 35, 36, 37, 38, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 98, 99, 100, 101, 103, 104, 105, 106, 108, 109, 110, 111, 113, 114, 115, 116, 118, 119, 120, 121, 123, 124, 125, 126, 128, 129, 130, 132, 133, 134, 135, 137, 138, 139, 140, 142, 143, 144, 145, 147, 148, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 169, 170, 171, 172, 173, 174, 176, 177, 178, 179, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 209, 210, 211, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 222, 223, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 246, 246, 247, 248, 248, 249, 250, 251, 251, 252, 253, 254, 254, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt[i]); + arrayOfByte[(3 + i * 4)] = ((byte)i); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask2.jpg"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicTenderFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicTenderFilter.java index 3bffcf3..6736b55 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicTenderFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicTenderFilter.java @@ -9,90 +9,90 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicTenderFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - - public MagicTenderFilter(){ - super(MagicFilterType.TENDER, OpenGlUtils.readShaderFromRawResource(R.raw.tender)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + + public MagicTenderFilter(){ + super(MagicFilterType.TENDER, R.raw.tender); + } - @Override - protected void onDestroy() { - super.onDestroy(); - GLES20.glDeleteTextures(2, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId}, 0); - mToneCurveTexture[0] = -1; - mMaskGrey1TextureId = -1; - } + @Override + protected void onDestroy() { + super.onDestroy(); + GLES20.glDeleteTextures(2, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId}, 0); + mToneCurveTexture[0] = -1; + mMaskGrey1TextureId = -1; + } - @Override - protected void onDrawArraysAfter() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - } + @Override + protected void onDrawArraysPre() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + } - @Override - protected void onInit() { - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit() { + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "grey1Frame"); - } + } - @Override - protected void onInitialized() { - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[1024]; - int[] arrayOfInt1 = { 10, 12, 14, 15, 17, 19, 21, 22, 24, 26, 28, 29, 31, 33, 35, 38, 40, 41, 43, 45, 47, 48, 50, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 71, 72, 74, 75, 77, 79, 80, 81, 83, 84, 86, 87, 89, 92, 93, 94, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109, 110, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 196, 197, 198, 198, 199, 200, 200, 201, 201, 202, 202, 203, 204, 204, 205, 205, 206, 206, 207, 207, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215, 215, 216, 216, 216, 217, 217, 218, 218, 219, 219, 219, 220, 220, 221, 221, 222, 222, 223, 223, 224, 224, 224, 225, 225, 226, 226, 227, 227, 227, 228, 228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234, 234, 234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240, 240, 241, 241, 242, 242 }; - int[] arrayOfInt2 = { 10, 12, 14, 15, 17, 19, 19, 21, 22, 24, 26, 28, 29, 31, 33, 35, 36, 36, 38, 40, 41, 43, 45, 47, 48, 50, 52, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 69, 71, 72, 74, 75, 77, 79, 80, 81, 83, 84, 86, 86, 87, 89, 90, 92, 93, 94, 96, 97, 99, 100, 101, 103, 103, 104, 105, 107, 108, 109, 110, 112, 113, 114, 116, 117, 118, 119, 120, 122, 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185, 186, 187, 187, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 196, 197, 198, 198, 199, 200, 200, 201, 201, 202, 202, 204, 204, 205, 205, 206, 206, 207, 207, 208, 209, 209, 210, 210, 211, 211, 212, 213, 213, 214, 214, 215, 215, 216, 216, 217, 217, 218, 218, 219, 219, 220, 220, 221, 221, 222, 222, 223, 223, 224, 224, 224, 225, 226, 226, 227, 227, 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234, 234, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242 }; - int[] arrayOfInt3 = { 10, 12, 12, 14, 15, 15, 17, 17, 19, 21, 21, 22, 24, 24, 26, 28, 28, 29, 31, 31, 33, 33, 35, 36, 36, 38, 40, 40, 41, 43, 43, 45, 47, 47, 48, 50, 52, 52, 53, 55, 55, 57, 58, 58, 60, 61, 63, 63, 65, 66, 68, 68, 69, 71, 71, 72, 74, 75, 77, 77, 79, 80, 81, 81, 83, 84, 86, 87, 87, 89, 90, 92, 93, 94, 94, 96, 97, 99, 100, 101, 103, 103, 104, 105, 107, 108, 109, 110, 112, 113, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 129, 130, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 178, 179, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 187, 188, 189, 190, 191, 191, 192, 193, 193, 195, 195, 196, 196, 197, 198, 199, 200, 200, 201, 201, 202, 203, 204, 204, 205, 206, 206, 207, 207, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214, 215, 215, 216, 217, 217, 218, 218, 219, 219, 220, 220, 221, 222, 222, 223, 223, 224, 224, 225, 225, 226, 227, 227, 227, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 238, 239, 240, 240, 240, 241, 242, 242 }; - int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/bluevintage_mask1.jpg"); - } - }); - } + @Override + protected void onInitialized() { + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[1024]; + int[] arrayOfInt1 = { 10, 12, 14, 15, 17, 19, 21, 22, 24, 26, 28, 29, 31, 33, 35, 38, 40, 41, 43, 45, 47, 48, 50, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 71, 72, 74, 75, 77, 79, 80, 81, 83, 84, 86, 87, 89, 92, 93, 94, 96, 97, 99, 100, 101, 103, 104, 105, 107, 108, 109, 110, 112, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 196, 197, 198, 198, 199, 200, 200, 201, 201, 202, 202, 203, 204, 204, 205, 205, 206, 206, 207, 207, 208, 209, 209, 210, 210, 211, 211, 212, 212, 213, 213, 214, 214, 215, 215, 216, 216, 216, 217, 217, 218, 218, 219, 219, 219, 220, 220, 221, 221, 222, 222, 223, 223, 224, 224, 224, 225, 225, 226, 226, 227, 227, 227, 228, 228, 229, 229, 230, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234, 234, 234, 235, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240, 240, 241, 241, 242, 242 }; + int[] arrayOfInt2 = { 10, 12, 14, 15, 17, 19, 19, 21, 22, 24, 26, 28, 29, 31, 33, 35, 36, 36, 38, 40, 41, 43, 45, 47, 48, 50, 52, 52, 53, 55, 57, 58, 60, 61, 63, 65, 66, 68, 69, 69, 71, 72, 74, 75, 77, 79, 80, 81, 83, 84, 86, 86, 87, 89, 90, 92, 93, 94, 96, 97, 99, 100, 101, 103, 103, 104, 105, 107, 108, 109, 110, 112, 113, 114, 116, 117, 118, 119, 120, 122, 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 168, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 177, 178, 179, 179, 180, 181, 182, 182, 183, 184, 184, 185, 186, 187, 187, 188, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 196, 197, 198, 198, 199, 200, 200, 201, 201, 202, 202, 204, 204, 205, 205, 206, 206, 207, 207, 208, 209, 209, 210, 210, 211, 211, 212, 213, 213, 214, 214, 215, 215, 216, 216, 217, 217, 218, 218, 219, 219, 220, 220, 221, 221, 222, 222, 223, 223, 224, 224, 224, 225, 226, 226, 227, 227, 227, 228, 228, 229, 229, 230, 230, 231, 231, 232, 232, 232, 233, 233, 234, 234, 234, 235, 236, 236, 236, 237, 237, 238, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242 }; + int[] arrayOfInt3 = { 10, 12, 12, 14, 15, 15, 17, 17, 19, 21, 21, 22, 24, 24, 26, 28, 28, 29, 31, 31, 33, 33, 35, 36, 36, 38, 40, 40, 41, 43, 43, 45, 47, 47, 48, 50, 52, 52, 53, 55, 55, 57, 58, 58, 60, 61, 63, 63, 65, 66, 68, 68, 69, 71, 71, 72, 74, 75, 77, 77, 79, 80, 81, 81, 83, 84, 86, 87, 87, 89, 90, 92, 93, 94, 94, 96, 97, 99, 100, 101, 103, 103, 104, 105, 107, 108, 109, 110, 112, 113, 113, 114, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 129, 130, 130, 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 166, 167, 169, 170, 171, 171, 172, 173, 174, 175, 175, 176, 178, 179, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 187, 188, 189, 190, 191, 191, 192, 193, 193, 195, 195, 196, 196, 197, 198, 199, 200, 200, 201, 201, 202, 203, 204, 204, 205, 206, 206, 207, 207, 209, 209, 210, 210, 211, 212, 212, 213, 213, 214, 215, 215, 216, 217, 217, 218, 218, 219, 219, 220, 220, 221, 222, 222, 223, 223, 224, 224, 225, 225, 226, 227, 227, 227, 228, 229, 229, 230, 230, 231, 231, 232, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 238, 239, 240, 240, 240, 241, 242, 242 }; + int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 1, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/bluevintage_mask1.jpg"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicToasterFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicToasterFilter.java index 7988ca0..9f14aab 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicToasterFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicToasterFilter.java @@ -7,66 +7,66 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicToasterFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; + private int[] inputTextureHandles = {-1,-1,-1,-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1,-1,-1,-1}; private int mGLStrengthLocation; - public MagicToasterFilter(){ - super(MagicFilterType.TOASTER2, OpenGlUtils.readShaderFromRawResource(R.raw.toaster2_filter_shader)); - } + public MagicToasterFilter(){ + super(MagicFilterType.TOASTER2, R.raw.toaster2_filter_shader); + } - @Override - protected void onDestroy() { + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter() { - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter() { + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre() { - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre() { + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - protected void onInit() { - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + protected void onInit() { + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - protected void onInitialized() { - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastermetal.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastersoftlight.png"); - inputTextureHandles[2] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastercurves.png"); - inputTextureHandles[3] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toasteroverlaymapwarm.png"); - inputTextureHandles[4] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastercolorshift.png"); - } - }); - } + @Override + protected void onInitialized() { + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastermetal.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastersoftlight.png"); + inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastercurves.png"); + inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toasteroverlaymapwarm.png"); + inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastercolorshift.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicValenciaFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicValenciaFilter.java index 20e7525..f69fd24 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicValenciaFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicValenciaFilter.java @@ -7,64 +7,64 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicValenciaFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1}; - private int mGLStrengthLocation; + private int[] inputTextureHandles = {-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1}; + private int mGLStrengthLocation; - public MagicValenciaFilter(){ - super(MagicFilterType.VALENCIA, OpenGlUtils.readShaderFromRawResource(R.raw.valencia)); - } + public MagicValenciaFilter(){ + super(MagicFilterType.VALENCIA, R.raw.valencia); + } - @Override - protected void onDrawArraysAfter() { - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter() { + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre() { - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre() { + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - public void onInit() { - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) { - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); - } - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + public void onInit() { + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) { + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); + } + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - public void onDestroy() { + @Override + public void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) { - inputTextureHandles[i] = -1; - } + inputTextureHandles[i] = -1; + } } - @Override - public void onInitialized() { - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/valenciamap.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/valenciagradientmap.png"); - } - }); - } + @Override + public void onInitialized() { + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/valenciamap.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/valenciagradientmap.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicWaldenFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicWaldenFilter.java index bbfceae..050a12f 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicWaldenFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicWaldenFilter.java @@ -7,61 +7,62 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; -public class MagicWaldenFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1}; - private int mGLStrengthLocation; +public class MagicWaldenFilter extends GPUImageFilter { - public MagicWaldenFilter(){ - super(MagicFilterType.WALDEN, OpenGlUtils.readShaderFromRawResource(R.raw.walden)); - } + private int[] inputTextureHandles = {-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1}; + private int mGLStrengthLocation; - @Override - protected void onDestroy() { + public MagicWaldenFilter(){ + super(MagicFilterType.WALDEN, R.raw.walden); + } + + @Override + protected void onDestroy() { super.onDestroy(); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; + inputTextureHandles[i] = -1; } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); + } + } - @Override - public void onInit(){ - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + public void onInit(){ + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - public void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/walden_map.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); - } - }); - } + @Override + public void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/walden_map.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicWarmFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicWarmFilter.java index 1e55bb9..e4be996 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicWarmFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicWarmFilter.java @@ -9,115 +9,115 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicWarmFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - private int mMaskGrey1TextureId = -1; - private int mMaskGrey1UniformLocation; - private int mMaskGrey2TextureId = -1; - private int mMaskGrey2UniformLocation; - - public MagicWarmFilter(){ - super(MagicFilterType.WARM, OpenGlUtils.readShaderFromRawResource(R.raw.warm)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + private int mMaskGrey1TextureId = -1; + private int mMaskGrey1UniformLocation; + private int mMaskGrey2TextureId = -1; + private int mMaskGrey2UniformLocation; + + public MagicWarmFilter(){ + super(MagicFilterType.WARM, R.raw.warm); + } - @Override - public void onDestroy(){ - super.onDestroy(); - GLES20.glDeleteTextures(3, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId, mMaskGrey2TextureId}, 0); - mToneCurveTexture[0] = -1; - mMaskGrey1TextureId = -1; - mMaskGrey2TextureId = -1; - } + @Override + public void onDestroy(){ + super.onDestroy(); + GLES20.glDeleteTextures(3, new int[]{mToneCurveTexture[0], mMaskGrey1TextureId, mMaskGrey2TextureId}, 0); + mToneCurveTexture[0] = -1; + mMaskGrey1TextureId = -1; + mMaskGrey2TextureId = -1; + } - @Override - protected void onDrawArraysAfter(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - if (mMaskGrey1TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE4); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); - GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); - } - if (mMaskGrey2TextureId != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE5); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); - GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); - } - } + @Override + protected void onDrawArraysPre(){ + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + if (mMaskGrey1TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE4); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey1TextureId); + GLES20.glUniform1i(mMaskGrey1UniformLocation, 4); + } + if (mMaskGrey2TextureId != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE5); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mMaskGrey2TextureId); + GLES20.glUniform1i(mMaskGrey2UniformLocation, 5); + } + } - @Override - protected void onInit(){ - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + @Override + protected void onInit(){ + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mMaskGrey1UniformLocation = GLES20.glGetUniformLocation(getProgram(), "layerImage"); mMaskGrey2UniformLocation = GLES20.glGetUniformLocation(getProgram(), "greyFrame"); - } + } - @Override - protected void onInitialized(){ - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[2048]; - int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 9, 12, 14, 17, 20, 23, 25, 28, 31, 33, 35, 38, 40, 42, 44, 46, 48, 50, 52, 53, 55, 57, 58, 60, 61, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 83, 84, 85, 85, 86, 87, 87, 88, 88, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 96, 96, 97, 98, 99, 99, 100, 101, 102, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 119, 120, 121, 123, 124, 126, 127, 128, 130, 131, 133, 135, 136, 138, 139, 141, 143, 144, 146, 148, 149, 151, 153, 154, 156, 158, 159, 161, 163, 165, 166, 168, 170, 172, 173, 175, 177, 179, 180, 182, 184, 185, 187, 189, 190, 192, 194, 195, 197, 199, 200, 202, 203, 205, 207, 208, 210, 211, 213, 214, 215, 217, 218, 219, 221, 222, 223, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 238, 239, 240, 241, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt2 = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 93, 94, 95, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 235, 236, 237, 238, 239, 240, 241, 242 }; - int[] arrayOfInt3 = { 9, 10, 11, 11, 12, 13, 14, 15, 16, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 60, 61, 62, 63, 64, 65, 66, 66, 67, 68, 69, 70, 71, 71, 72, 73, 74, 75, 76, 76, 77, 78, 79, 80, 81, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 93, 93, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 110, 110, 111, 112, 113, 114, 115, 116, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 135, 136, 137, 137, 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 160, 161, 162, 163, 164, 165, 166, 167, 168, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 225, 226, 227, 228, 229, 230 }; - int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 33, 34, 35, 37, 38, 40, 41, 42, 44, 45, 47, 48, 50, 51, 53, 54, 56, 58, 59, 61, 62, 64, 65, 67, 69, 70, 72, 73, 75, 77, 78, 80, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 102, 104, 105, 107, 108, 110, 111, 113, 114, 116, 117, 119, 120, 122, 123, 124, 126, 127, 129, 130, 131, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 147, 149, 150, 151, 153, 154, 155, 156, 157, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 228, 229, 230, 230, 231, 231, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 249, 250, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255, 255 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); - arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); - } - int[] arrayOfInt5 = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 11, 12, 13, 13, 14, 15, 15, 16, 17, 18, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 27, 28, 28, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 36, 37, 38, 39, 39, 40, 41, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 63, 64, 65, 66, 68, 69, 70, 71, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 92, 93, 94, 95, 95, 97, 98, 99, 100, 102, 103, 104, 105, 106, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 137, 138, 139, 141, 142, 143, 144, 145, 146, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 219, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 231, 233, 234, 235, 236, 237, 239, 240, 241, 242, 243, 243, 244, 246, 247, 248, 249, 250, 251, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 69, 70, 71, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 139, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 231, 233, 234, 235, 236, 237, 239, 240, 241, 242, 243, 244, 246, 247, 249, 250, 251, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt7 = { 45, 45, 46, 46, 47, 47, 47, 47, 48, 48, 49, 49, 50, 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, 63, 63, 64, 64, 65, 65, 66, 66, 67, 67, 68, 69, 69, 70, 70, 71, 71, 71, 72, 72, 73, 73, 74, 75, 75, 76, 76, 77, 78, 78, 79, 79, 80, 80, 80, 81, 82, 82, 83, 84, 84, 85, 86, 87, 87, 88, 89, 89, 90, 91, 92, 92, 93, 94, 95, 95, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 103, 104, 105, 106, 107, 108, 109, 110, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 141, 142, 143, 144, 146, 147, 148, 149, 150, 151, 152, 154, 156, 157, 158, 159, 160, 161, 162, 165, 166, 167, 168, 169, 170, 171, 173, 175, 176, 177, 178, 179, 180, 182, 183, 184, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 217, 219, 220, 221, 222, 223, 224, 226, 227, 227, 228, 229, 230, 231, 233, 234, 235, 235, 236, 237, 239, 240, 241, 241, 242, 243, 244, 246, 246, 247, 248, 249, 250, 251, 251, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt8 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt7[j]); - arrayOfByte[(3 + (1024 + j * 4))] = ((byte)arrayOfInt8[j]); - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - mMaskGrey1TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/warm_layer1.jpg"); - mMaskGrey2TextureId = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/bluevintage_mask1.jpg"); - } - }); - } + @Override + protected void onInitialized(){ + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[2048]; + int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 9, 12, 14, 17, 20, 23, 25, 28, 31, 33, 35, 38, 40, 42, 44, 46, 48, 50, 52, 53, 55, 57, 58, 60, 61, 63, 64, 65, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 80, 81, 82, 83, 83, 84, 85, 85, 86, 87, 87, 88, 88, 89, 90, 90, 91, 91, 92, 93, 93, 94, 94, 95, 96, 96, 97, 98, 99, 99, 100, 101, 102, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 114, 115, 116, 117, 119, 120, 121, 123, 124, 126, 127, 128, 130, 131, 133, 135, 136, 138, 139, 141, 143, 144, 146, 148, 149, 151, 153, 154, 156, 158, 159, 161, 163, 165, 166, 168, 170, 172, 173, 175, 177, 179, 180, 182, 184, 185, 187, 189, 190, 192, 194, 195, 197, 199, 200, 202, 203, 205, 207, 208, 210, 211, 213, 214, 215, 217, 218, 219, 221, 222, 223, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 238, 239, 240, 241, 241, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 253, 253, 254, 254, 254, 254, 254, 254, 254, 254, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt2 = { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 93, 94, 95, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 235, 236, 237, 238, 239, 240, 241, 242 }; + int[] arrayOfInt3 = { 9, 10, 11, 11, 12, 13, 14, 15, 16, 16, 17, 18, 19, 20, 21, 21, 22, 23, 24, 25, 26, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 36, 37, 38, 39, 40, 40, 41, 42, 43, 44, 45, 45, 46, 47, 48, 49, 50, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 60, 61, 62, 63, 64, 65, 66, 66, 67, 68, 69, 70, 71, 71, 72, 73, 74, 75, 76, 76, 77, 78, 79, 80, 81, 81, 82, 83, 84, 85, 86, 87, 87, 88, 89, 90, 91, 92, 93, 93, 94, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 104, 104, 105, 106, 107, 108, 109, 110, 110, 111, 112, 113, 114, 115, 116, 116, 117, 118, 119, 120, 121, 122, 123, 123, 124, 125, 126, 127, 128, 129, 130, 130, 131, 132, 133, 134, 135, 136, 137, 137, 138, 139, 140, 141, 142, 143, 144, 144, 145, 146, 147, 148, 149, 150, 151, 152, 152, 153, 154, 155, 156, 157, 158, 159, 160, 160, 161, 162, 163, 164, 165, 166, 167, 168, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 225, 226, 227, 228, 229, 230 }; + int[] arrayOfInt4 = { 0, 0, 1, 1, 2, 2, 3, 3, 4, 5, 5, 6, 6, 7, 7, 8, 9, 9, 10, 11, 12, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 29, 30, 31, 33, 34, 35, 37, 38, 40, 41, 42, 44, 45, 47, 48, 50, 51, 53, 54, 56, 58, 59, 61, 62, 64, 65, 67, 69, 70, 72, 73, 75, 77, 78, 80, 82, 83, 85, 86, 88, 90, 91, 93, 94, 96, 98, 99, 101, 102, 104, 105, 107, 108, 110, 111, 113, 114, 116, 117, 119, 120, 122, 123, 124, 126, 127, 129, 130, 131, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 147, 149, 150, 151, 153, 154, 155, 156, 157, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 216, 217, 218, 218, 219, 220, 221, 221, 222, 223, 223, 224, 225, 225, 226, 227, 227, 228, 228, 229, 230, 230, 231, 231, 232, 233, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 246, 246, 247, 247, 248, 248, 249, 249, 249, 250, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255, 255 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); + arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[i]); + } + int[] arrayOfInt5 = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 6, 7, 8, 8, 9, 10, 11, 11, 11, 12, 13, 13, 14, 15, 15, 16, 17, 18, 18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 26, 27, 28, 28, 28, 29, 30, 31, 31, 32, 33, 34, 35, 36, 36, 37, 38, 39, 39, 40, 41, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 59, 60, 61, 62, 63, 63, 64, 65, 66, 68, 69, 70, 71, 71, 72, 73, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 90, 92, 93, 94, 95, 95, 97, 98, 99, 100, 102, 103, 104, 105, 106, 108, 109, 110, 111, 112, 114, 115, 116, 117, 118, 119, 122, 123, 124, 125, 126, 127, 129, 130, 131, 132, 133, 134, 135, 137, 138, 139, 141, 142, 143, 144, 145, 146, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 183, 184, 185, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 219, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 231, 233, 234, 235, 236, 237, 239, 240, 241, 242, 243, 243, 244, 246, 247, 248, 249, 250, 251, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt6 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 39, 40, 41, 42, 43, 44, 45, 46, 47, 47, 48, 49, 50, 51, 52, 53, 54, 55, 55, 56, 57, 58, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 69, 70, 71, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 133, 134, 135, 136, 137, 138, 139, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 173, 174, 175, 176, 177, 178, 179, 180, 182, 183, 184, 185, 186, 187, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 220, 221, 222, 223, 224, 226, 227, 228, 229, 230, 231, 233, 234, 235, 236, 237, 239, 240, 241, 242, 243, 244, 246, 247, 249, 250, 251, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt7 = { 45, 45, 46, 46, 47, 47, 47, 47, 48, 48, 49, 49, 50, 50, 50, 51, 51, 52, 52, 53, 53, 54, 54, 55, 55, 55, 55, 56, 56, 57, 57, 58, 58, 59, 59, 60, 60, 61, 61, 62, 62, 63, 63, 63, 63, 64, 64, 65, 65, 66, 66, 67, 67, 68, 69, 69, 70, 70, 71, 71, 71, 72, 72, 73, 73, 74, 75, 75, 76, 76, 77, 78, 78, 79, 79, 80, 80, 80, 81, 82, 82, 83, 84, 84, 85, 86, 87, 87, 88, 89, 89, 90, 91, 92, 92, 93, 94, 95, 95, 95, 96, 97, 98, 98, 99, 100, 101, 102, 103, 103, 104, 105, 106, 107, 108, 109, 110, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 135, 136, 137, 138, 139, 141, 142, 143, 144, 146, 147, 148, 149, 150, 151, 152, 154, 156, 157, 158, 159, 160, 161, 162, 165, 166, 167, 168, 169, 170, 171, 173, 175, 176, 177, 178, 179, 180, 182, 183, 184, 186, 187, 188, 190, 191, 192, 193, 194, 195, 196, 198, 199, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 212, 213, 214, 215, 216, 217, 217, 219, 220, 221, 222, 223, 224, 226, 227, 227, 228, 229, 230, 231, 233, 234, 235, 235, 236, 237, 239, 240, 241, 241, 242, 243, 244, 246, 246, 247, 248, 249, 250, 251, 251, 253, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt8 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt7[j]); + arrayOfByte[(3 + (1024 + j * 4))] = ((byte)arrayOfInt8[j]); + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/warm_layer1.jpg"); + mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/bluevintage_mask1.jpg"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicWhiteCatFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicWhiteCatFilter.java index 391a294..d097c5e 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicWhiteCatFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicWhiteCatFilter.java @@ -8,83 +8,82 @@ import com.seu.magicfilter.utils.MagicFilterType; import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.OpenGlUtils; public class MagicWhiteCatFilter extends GPUImageFilter{ - private int[] mToneCurveTexture = {-1}; - private int mToneCurveTextureUniformLocation; - - public MagicWhiteCatFilter() { - super(MagicFilterType.WHITECAT, OpenGlUtils.readShaderFromRawResource(R.raw.whitecat)); - } + private int[] mToneCurveTexture = {-1}; + private int mToneCurveTextureUniformLocation; + + public MagicWhiteCatFilter() { + super(MagicFilterType.WHITECAT, R.raw.whitecat); + } - @Override - public void onDestroy() { - super.onDestroy(); - GLES20.glDeleteTextures(1, mToneCurveTexture, 0); - mToneCurveTexture[0] = -1; - } + @Override + public void onDestroy() { + super.onDestroy(); + GLES20.glDeleteTextures(1, mToneCurveTexture, 0); + mToneCurveTexture[0] = -1; + } - @Override - protected void onDrawArraysAfter() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre() { - if (mToneCurveTexture[0] != -1){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE3); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); - } - } + @Override + protected void onDrawArraysPre() { + if (mToneCurveTexture[0] != -1){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE3); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); + } + } - @Override - public void onInit() { - super.onInit(); - mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); - } + @Override + public void onInit() { + super.onInit(); + mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); + } - @Override - public void onInitialized() { - super.onInitialized(); - runOnDraw(new Runnable(){ - public void run(){ - GLES20.glGenTextures(1, mToneCurveTexture, 0); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); - GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, - GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); - byte[] arrayOfByte = new byte[2048]; - int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 249, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 4, 5, 6, 7, 8, 10, 11, 12, 12, 13, 14, 16, 17, 18, 19, 19, 20, 22, 23, 24, 25, 26, 26, 28, 29, 30, 31, 32, 33, 35, 35, 36, 37, 38, 39, 41, 42, 42, 43, 44, 45, 46, 48, 49, 50, 50, 51, 52, 54, 55, 56, 57, 58, 58, 59, 61, 62, 63, 64, 65, 66, 66, 67, 69, 70, 71, 72, 73, 74, 75, 75, 77, 78, 79, 80, 81, 82, 83, 85, 85, 86, 87, 88, 89, 90, 91, 92, 93, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 236, 237, 238, 239, 240, 240 }; - for (int i = 0; i < 256; i++){ - arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]); - arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt2[i]); - arrayOfByte[(3 + i * 4)] = -1; - } - int[] arrayOfInt3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 9, 14, 17, 19, 22, 25, 27, 30, 34, 36, 39, 41, 43, 45, 49, 51, 52, 54, 55, 57, 58, 61, 63, 64, 65, 67, 68, 69, 72, 73, 75, 76, 77, 78, 81, 82, 83, 84, 86, 87, 88, 90, 91, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 105, 106, 108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 138, 138, 139, 140, 141, 142, 144, 145, 146, 146, 147, 148, 149, 151, 152, 153, 153, 154, 155, 156, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 168, 170, 171, 172, 172, 173, 174, 175, 176, 177, 178, 179, 180, 180, 181, 183, 183, 184, 185, 186, 186, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 196, 197, 198, 199, 200, 201, 201, 202, 203, 204, 204, 206, 207, 207, 208, 209, 209, 211, 212, 212, 213, 214, 214, 215, 217, 217, 218, 219, 219, 220, 221, 222, 223, 224, 224, 225, 226, 227, 228, 228, 229, 230, 230, 231, 233, 233, 234, 235, 235, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 244, 245, 245, 246, 247, 248, 249, 249, 250, 250, 251, 252, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; - int[] arrayOfInt4 = { 0, 2, 4, 6, 8, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 32, 34, 36, 38, 40, 42, 44, 46, 47, 49, 51, 53, 54, 56, 58, 60, 61, 63, 65, 66, 68, 70, 71, 73, 74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 89, 91, 92, 93, 95, 96, 98, 99, 100, 101, 103, 104, 105, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 224, 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232, 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 245, 246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 254, 255, 255, 255 }; - int[] arrayOfInt5 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; - for (int j = 0; j < 256; j++){ - arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt4[j]); - arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt3[j]); - arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); - arrayOfByte[(3 + (1024 + j * 4))] = -1; - } - GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); - } - }); - } + @Override + public void onInitialized() { + super.onInitialized(); + runOnDraw(new Runnable(){ + public void run(){ + GLES20.glGenTextures(1, mToneCurveTexture, 0); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); + GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, + GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); + byte[] arrayOfByte = new byte[2048]; + int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 69, 70, 71, 72, 73, 74, 75, 77, 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 249, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 4, 4, 5, 6, 7, 8, 10, 11, 12, 12, 13, 14, 16, 17, 18, 19, 19, 20, 22, 23, 24, 25, 26, 26, 28, 29, 30, 31, 32, 33, 35, 35, 36, 37, 38, 39, 41, 42, 42, 43, 44, 45, 46, 48, 49, 50, 50, 51, 52, 54, 55, 56, 57, 58, 58, 59, 61, 62, 63, 64, 65, 66, 66, 67, 69, 70, 71, 72, 73, 74, 75, 75, 77, 78, 79, 80, 81, 82, 83, 85, 85, 86, 87, 88, 89, 90, 91, 92, 93, 93, 95, 96, 97, 98, 99, 100, 101, 102, 103, 103, 104, 105, 107, 108, 109, 110, 111, 112, 113, 114, 114, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 182, 183, 184, 185, 186, 187, 188, 189, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 236, 237, 238, 239, 240, 240 }; + for (int i = 0; i < 256; i++){ + arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt1[i]); + arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt2[i]); + arrayOfByte[(3 + i * 4)] = -1; + } + int[] arrayOfInt3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 6, 9, 14, 17, 19, 22, 25, 27, 30, 34, 36, 39, 41, 43, 45, 49, 51, 52, 54, 55, 57, 58, 61, 63, 64, 65, 67, 68, 69, 72, 73, 75, 76, 77, 78, 81, 82, 83, 84, 86, 87, 88, 90, 91, 93, 94, 95, 96, 97, 99, 100, 101, 102, 103, 105, 106, 108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 126, 127, 128, 130, 131, 132, 133, 134, 135, 136, 138, 138, 139, 140, 141, 142, 144, 145, 146, 146, 147, 148, 149, 151, 152, 153, 153, 154, 155, 156, 158, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 168, 170, 171, 172, 172, 173, 174, 175, 176, 177, 178, 179, 180, 180, 181, 183, 183, 184, 185, 186, 186, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 196, 197, 198, 199, 200, 201, 201, 202, 203, 204, 204, 206, 207, 207, 208, 209, 209, 211, 212, 212, 213, 214, 214, 215, 217, 217, 218, 219, 219, 220, 221, 222, 223, 224, 224, 225, 226, 227, 228, 228, 229, 230, 230, 231, 233, 233, 234, 235, 235, 236, 237, 238, 239, 239, 240, 241, 241, 242, 243, 244, 245, 245, 246, 247, 248, 249, 249, 250, 250, 251, 252, 253, 254, 254, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255 }; + int[] arrayOfInt4 = { 0, 2, 4, 6, 8, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 32, 34, 36, 38, 40, 42, 44, 46, 47, 49, 51, 53, 54, 56, 58, 60, 61, 63, 65, 66, 68, 70, 71, 73, 74, 76, 77, 79, 80, 82, 83, 85, 86, 88, 89, 91, 92, 93, 95, 96, 98, 99, 100, 101, 103, 104, 105, 107, 108, 109, 110, 111, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 124, 125, 126, 127, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 198, 199, 200, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 211, 212, 212, 213, 214, 215, 216, 216, 217, 218, 219, 219, 220, 221, 222, 222, 223, 224, 224, 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232, 233, 233, 234, 235, 235, 236, 236, 237, 237, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242, 243, 243, 244, 244, 245, 245, 245, 246, 246, 247, 247, 247, 248, 248, 248, 249, 249, 249, 250, 250, 250, 251, 251, 251, 252, 252, 252, 252, 253, 253, 253, 253, 254, 254, 254, 254, 254, 255, 255, 255 }; + int[] arrayOfInt5 = { 0, 0, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 5, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 13, 13, 13, 14, 14, 14, 15, 15, 16, 16, 16, 17, 17, 17, 18, 18, 18, 19, 19, 20, 20, 20, 21, 21, 21, 22, 22, 23, 23, 23, 24, 24, 24, 25, 25, 25, 25, 26, 26, 27, 27, 28, 28, 28, 28, 29, 29, 30, 29, 31, 31, 31, 31, 32, 32, 33, 33, 34, 34, 34, 34, 35, 35, 36, 36, 37, 37, 37, 38, 38, 39, 39, 39, 40, 40, 40, 41, 42, 42, 43, 43, 44, 44, 45, 45, 45, 46, 47, 47, 48, 48, 49, 50, 51, 51, 52, 52, 53, 53, 54, 55, 55, 56, 57, 57, 58, 59, 60, 60, 61, 62, 63, 63, 64, 65, 66, 67, 68, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 96, 97, 98, 100, 101, 103, 104, 105, 107, 108, 110, 111, 113, 115, 116, 118, 119, 120, 122, 123, 125, 127, 128, 130, 132, 134, 135, 137, 139, 141, 143, 144, 146, 148, 150, 152, 154, 156, 158, 160, 163, 165, 167, 169, 171, 173, 175, 178, 180, 182, 185, 187, 189, 192, 194, 197, 199, 201, 204, 206, 209, 211, 214, 216, 219, 221, 224, 226, 229, 232, 234, 236, 239, 241, 245, 247, 250, 252, 255 }; + for (int j = 0; j < 256; j++){ + arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt4[j]); + arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt3[j]); + arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); + arrayOfByte[(3 + (1024 + j * 4))] = -1; + } + GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/advanced/MagicXproIIFilter.java b/app/src/main/java/com/seu/magicfilter/advanced/MagicXproIIFilter.java index 6542309..996c0af 100644 --- a/app/src/main/java/com/seu/magicfilter/advanced/MagicXproIIFilter.java +++ b/app/src/main/java/com/seu/magicfilter/advanced/MagicXproIIFilter.java @@ -7,62 +7,62 @@ import net.ossrs.yasea.R; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; public class MagicXproIIFilter extends GPUImageFilter{ - private int[] inputTextureHandles = {-1,-1}; - private int[] inputTextureUniformLocations = {-1,-1}; - private int mGLStrengthLocation; + private int[] inputTextureHandles = {-1,-1}; + private int[] inputTextureUniformLocations = {-1,-1}; + private int mGLStrengthLocation; - public MagicXproIIFilter(){ - super(MagicFilterType.XPROII, OpenGlUtils.readShaderFromRawResource(R.raw.xproii_filter_shader)); - } + public MagicXproIIFilter(){ + super(MagicFilterType.XPROII, R.raw.xproii_filter_shader); + } - @Override - public void onDestroy() { - super.onDestroy(); - GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); - for(int i = 0; i < inputTextureHandles.length; i++) - inputTextureHandles[i] = -1; - } + @Override + public void onDestroy() { + super.onDestroy(); + GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); + for(int i = 0; i < inputTextureHandles.length; i++) + inputTextureHandles[i] = -1; + } - @Override - protected void onDrawArraysAfter(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); - GLES20.glActiveTexture(GLES20.GL_TEXTURE0); - } - } + @Override + protected void onDrawArraysAfter(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3)); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); + GLES20.glActiveTexture(GLES20.GL_TEXTURE0); + } + } - @Override - protected void onDrawArraysPre(){ - for(int i = 0; i < inputTextureHandles.length - && inputTextureHandles[i] != OpenGlUtils.NO_TEXTURE; i++){ - GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); - GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); - GLES20.glUniform1i(inputTextureUniformLocations[i], (i + 3)); - } - } + @Override + protected void onDrawArraysPre(){ + for(int i = 0; i < inputTextureHandles.length + && inputTextureHandles[i] != OpenGLUtils.NO_TEXTURE; i++){ + GLES20.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3) ); + GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); + GLES20.glUniform1i(inputTextureUniformLocations[i], (i + 3)); + } + } - @Override - public void onInit(){ - super.onInit(); - for(int i = 0; i < inputTextureUniformLocations.length; i++) - inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); - mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); - } + @Override + public void onInit(){ + super.onInit(); + for(int i = 0; i < inputTextureUniformLocations.length; i++) + inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture"+(2+i)); + mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); + } - @Override - public void onInitialized(){ - super.onInitialized(); - setFloat(mGLStrengthLocation, 1.0f); - runOnDraw(new Runnable(){ - public void run(){ - inputTextureHandles[0] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/xpromap.png"); - inputTextureHandles[1] = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignettemap_new.png"); - } - }); - } + @Override + public void onInitialized(){ + super.onInitialized(); + setFloat(mGLStrengthLocation, 1.0f); + runOnDraw(new Runnable(){ + public void run(){ + inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/xpromap.png"); + inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignettemap_new.png"); + } + }); + } } diff --git a/app/src/main/java/com/seu/magicfilter/base/MagicBaseGroupFilter.java b/app/src/main/java/com/seu/magicfilter/base/MagicBaseGroupFilter.java index 4cff56c..b813d0b 100644 --- a/app/src/main/java/com/seu/magicfilter/base/MagicBaseGroupFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/MagicBaseGroupFilter.java @@ -5,8 +5,7 @@ import java.nio.FloatBuffer; import java.util.List; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; -import com.seu.magicfilter.utils.MagicFilterType; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; import android.opengl.GLES20; @@ -83,7 +82,7 @@ public class MagicBaseGroupFilter extends GPUImageFilter { public int onDrawFrame(final int textureId, final FloatBuffer cubeBuffer, final FloatBuffer textureBuffer) { if (frameBuffers == null || frameBufferTextures == null) { - return OpenGlUtils.NOT_INIT; + return OpenGLUtils.NOT_INIT; } int size = filters.size(); int previousTexture = textureId; @@ -102,12 +101,12 @@ public class MagicBaseGroupFilter extends GPUImageFilter { filter.onDrawFrame(previousTexture, cubeBuffer, textureBuffer); } } - return OpenGlUtils.ON_DRAWN; + return OpenGLUtils.ON_DRAWN; } public int onDrawFrame(int textureId) { if (frameBuffers == null || frameBufferTextures == null) { - return OpenGlUtils.NOT_INIT; + return OpenGLUtils.NOT_INIT; } int size = filters.size(); int previousTexture = textureId; @@ -124,7 +123,7 @@ public class MagicBaseGroupFilter extends GPUImageFilter { filter.onDrawFrame(previousTexture, mGLCubeBuffer, mGLTextureBuffer); } } - return OpenGlUtils.ON_DRAWN; + return OpenGLUtils.ON_DRAWN; } private void destroyFramebuffers() { diff --git a/app/src/main/java/com/seu/magicfilter/base/MagicLookupFilter.java b/app/src/main/java/com/seu/magicfilter/base/MagicLookupFilter.java index f62467b..63a7992 100644 --- a/app/src/main/java/com/seu/magicfilter/base/MagicLookupFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/MagicLookupFilter.java @@ -5,54 +5,21 @@ import android.opengl.GLES20; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; import com.seu.magicfilter.utils.MagicFilterType; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; -public class MagicLookupFilter extends GPUImageFilter { +import net.ossrs.yasea.R; - public static final String LOOKUP_FRAGMENT_SHADER = "" + - "varying highp vec2 textureCoordinate;\n" + - " \n" + - " uniform sampler2D inputImageTexture;\n" + - " uniform sampler2D inputImageTexture2; // lookup texture\n" + - " \n" + - " void main()\n" + - " {\n" + - " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + - " \n" + - " mediump float blueColor = textureColor.b * 63.0;\n" + - " \n" + - " mediump vec2 quad1;\n" + - " quad1.y = floor(floor(blueColor) / 8.0);\n" + - " quad1.x = floor(blueColor) - (quad1.y * 8.0);\n" + - " \n" + - " mediump vec2 quad2;\n" + - " quad2.y = floor(ceil(blueColor) / 8.0);\n" + - " quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n" + - " \n" + - " highp vec2 texPos1;\n" + - " texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n" + - " texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n" + - " \n" + - " highp vec2 texPos2;\n" + - " texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r);\n" + - " texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g);\n" + - " \n" + - " lowp vec4 newColor1 = texture2D(inputImageTexture2, texPos1);\n" + - " lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2);\n" + - " \n" + - " lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor));\n" + - " gl_FragColor = vec4(newColor.rgb, textureColor.w);\n" + - " }"; +public class MagicLookupFilter extends GPUImageFilter { protected String table; public MagicLookupFilter(String table) { - super(MagicFilterType.LOCKUP, LOOKUP_FRAGMENT_SHADER); + super(MagicFilterType.LOCKUP, R.raw.lookup); this.table = table; } private int mLookupTextureUniform; - private int mLookupSourceTexture = OpenGlUtils.NO_TEXTURE; + private int mLookupSourceTexture = OpenGLUtils.NO_TEXTURE; protected void onInit() { super.onInit(); @@ -63,7 +30,7 @@ public class MagicLookupFilter extends GPUImageFilter { super.onInitialized(); runOnDraw(new Runnable() { public void run() { - mLookupSourceTexture = OpenGlUtils.loadTexture(MagicFilterFactory.getCurrentContext(), table); + mLookupSourceTexture = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), table); } }); } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageBrightnessFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageBrightnessFilter.java index 59da538..9989c12 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageBrightnessFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageBrightnessFilter.java @@ -20,22 +20,12 @@ import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; +import net.ossrs.yasea.R; + /** * brightness value ranges from -1.0 to 1.0, with 0.0 as the normal level */ public class GPUImageBrightnessFilter extends GPUImageFilter { - public static final String BRIGHTNESS_FRAGMENT_SHADER = "" + - "varying highp vec2 textureCoordinate;\n" + - " \n" + - " uniform sampler2D inputImageTexture;\n" + - " uniform lowp float brightness;\n" + - " \n" + - " void main()\n" + - " {\n" + - " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + - " \n" + - " gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w);\n" + - " }"; private int mBrightnessLocation; private float mBrightness; @@ -45,7 +35,7 @@ public class GPUImageBrightnessFilter extends GPUImageFilter { } public GPUImageBrightnessFilter(final float brightness) { - super(MagicFilterType.BRIGHTNESS, BRIGHTNESS_FRAGMENT_SHADER); + super(MagicFilterType.BRIGHTNESS, R.raw.brightness); mBrightness = brightness; } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageContrastFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageContrastFilter.java index 74d0fc5..6face99 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageContrastFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageContrastFilter.java @@ -20,24 +20,14 @@ import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; +import net.ossrs.yasea.R; + /** * Changes the contrast of the image.
*
* contrast value ranges from 0.0 to 4.0, with 1.0 as the normal level */ public class GPUImageContrastFilter extends GPUImageFilter { - public static final String CONTRAST_FRAGMENT_SHADER = "" + - "varying highp vec2 textureCoordinate;\n" + - " \n" + - " uniform sampler2D inputImageTexture;\n" + - " uniform lowp float contrast;\n" + - " \n" + - " void main()\n" + - " {\n" + - " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + - " \n" + - " gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w);\n" + - " }"; private int mContrastLocation; private float mContrast; @@ -47,7 +37,7 @@ public class GPUImageContrastFilter extends GPUImageFilter { } public GPUImageContrastFilter(float contrast) { - super(MagicFilterType.CONTRAST, CONTRAST_FRAGMENT_SHADER); + super(MagicFilterType.CONTRAST, R.raw.constrast); mContrast = contrast; } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageExposureFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageExposureFilter.java index 4c8efc1..f3fa450 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageExposureFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageExposureFilter.java @@ -20,6 +20,8 @@ import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; +import net.ossrs.yasea.R; + /** * exposure: The adjusted exposure (-10.0 - 10.0, with 0.0 as the default) */ @@ -45,7 +47,7 @@ public class GPUImageExposureFilter extends GPUImageFilter { } public GPUImageExposureFilter(final float exposure) { - super(MagicFilterType.EXPOSURE, EXPOSURE_FRAGMENT_SHADER); + super(MagicFilterType.EXPOSURE, R.raw.exposure); mExposure = exposure; } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageFilter.java index 7c6bc93..e53bb72 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageFilter.java @@ -20,7 +20,7 @@ import android.graphics.PointF; import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; import com.seu.magicfilter.utils.Rotation; import com.seu.magicfilter.utils.TextureRotationUtil; @@ -52,7 +52,7 @@ public class GPUImageFilter { protected int mOutputHeight; protected FloatBuffer mGLCubeBuffer; protected FloatBuffer mGLTextureBuffer; - + private int[] mGLCubeId; private int[] mGLTextureCoordinateId; private float[] mGLTextureTransformMatrix; @@ -66,19 +66,18 @@ public class GPUImageFilter { } public GPUImageFilter(MagicFilterType type) { - this(type, OpenGlUtils.readShaderFromRawResource(R.raw.default_vertex), - OpenGlUtils.readShaderFromRawResource(R.raw.default_fragment)); + this(type, R.raw.vertex_oes, R.raw.fragment_oes); } - public GPUImageFilter(MagicFilterType type, String fragmentShader) { - this(type, OpenGlUtils.readShaderFromRawResource(R.raw.default_vertex), fragmentShader); + public GPUImageFilter(MagicFilterType type, int fragmentShaderId) { + this(type, R.raw.vertex_oes, fragmentShaderId); } - public GPUImageFilter(MagicFilterType type, String vertexShader, String fragmentShader) { + public GPUImageFilter(MagicFilterType type, int vertexShaderId, int fragmentShaderId) { mType = type; mRunOnDraw = new LinkedList<>(); - mVertexShader = vertexShader; - mFragmentShader = fragmentShader; + mVertexShader = OpenGLUtils.readShaderFromRawResource(vertexShaderId); + mFragmentShader = OpenGLUtils.readShaderFromRawResource(fragmentShaderId); mGLCubeBuffer = ByteBuffer.allocateDirect(TextureRotationUtil.CUBE.length * 4) .order(ByteOrder.nativeOrder()) @@ -98,7 +97,7 @@ public class GPUImageFilter { protected void onInit() { initVbo(); - mGLProgId = OpenGlUtils.loadProgram(mVertexShader, mFragmentShader); + mGLProgId = OpenGLUtils.loadProgram(mVertexShader, mFragmentShader); mGLPositionIndex = GLES20.glGetAttribLocation(mGLProgId, "position"); mGLTextureCoordinateIndex = GLES20.glGetAttribLocation(mGLProgId,"inputTextureCoordinate"); mGLTextureTransformIndex = GLES20.glGetUniformLocation(mGLProgId, "textureTransform"); @@ -180,7 +179,7 @@ public class GPUImageFilter { private void destroyFboTexture() { if (mGLFboTexId != null) { - GLES20.glDeleteRenderbuffers(1, mGLFboTexId, 0); + GLES20.glDeleteTextures(1, mGLFboTexId, 0); mGLFboTexId = null; } if (mGLFboId != null) { @@ -191,7 +190,7 @@ public class GPUImageFilter { public int onDrawFrame(final int textureId, final FloatBuffer cubeBuffer, final FloatBuffer textureBuffer) { if (!mIsInitialized) { - return OpenGlUtils.NOT_INIT; + return OpenGLUtils.NOT_INIT; } GLES20.glUseProgram(mGLProgId); @@ -203,7 +202,7 @@ public class GPUImageFilter { GLES20.glEnableVertexAttribArray(mGLTextureCoordinateIndex); GLES20.glVertexAttribPointer(mGLTextureCoordinateIndex, 2, GLES20.GL_FLOAT, false, 4 * 2, textureBuffer); - if (textureId != OpenGlUtils.NO_TEXTURE) { + if (textureId != OpenGLUtils.NO_TEXTURE) { GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mGLFboTexId[0]); GLES20.glUniform1i(mGLInputImageTextureIndex, 0); @@ -218,16 +217,16 @@ public class GPUImageFilter { GLES20.glDisableVertexAttribArray(mGLPositionIndex); GLES20.glDisableVertexAttribArray(mGLTextureCoordinateIndex); - return OpenGlUtils.ON_DRAWN; + return OpenGLUtils.ON_DRAWN; } public int onDrawFrame() { if (!mIsInitialized) { - return OpenGlUtils.NOT_INIT; + return OpenGLUtils.NOT_INIT; } if (mGLFboId == null) { - return OpenGlUtils.NO_TEXTURE; + return OpenGLUtils.NO_TEXTURE; } GLES20.glUseProgram(mGLProgId); @@ -267,14 +266,14 @@ public class GPUImageFilter { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, 0); - return OpenGlUtils.ON_DRAWN; + return OpenGLUtils.ON_DRAWN; } protected void onDrawArraysPre() {} protected void onDrawArraysAfter() {} - protected void runPendingOnDrawTasks() { + private void runPendingOnDrawTasks() { while (!mRunOnDraw.isEmpty()) { mRunOnDraw.removeFirst().run(); } @@ -308,7 +307,7 @@ public class GPUImageFilter { return mGLInputImageTextureIndex; } - public IntBuffer getGlFboBuffer() { + public IntBuffer getGLFboBuffer() { return mGLFboBuffer; } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageHueFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageHueFilter.java index 93bef3a..65014ad 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageHueFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageHueFilter.java @@ -20,51 +20,9 @@ import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; +import net.ossrs.yasea.R; + public class GPUImageHueFilter extends GPUImageFilter { - public static final String HUE_FRAGMENT_SHADER = "" + - "precision highp float;\n" + - "varying highp vec2 textureCoordinate;\n" + - "\n" + - "uniform sampler2D inputImageTexture;\n" + - "uniform mediump float hueAdjust;\n" + - "const highp vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0);\n" + - "const highp vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0);\n" + - "const highp vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0);\n" + - "\n" + - "const highp vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0);\n" + - "const highp vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0);\n" + - "const highp vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0);\n" + - "\n" + - "void main ()\n" + - "{\n" + - " // Sample the input pixel\n" + - " highp vec4 color = texture2D(inputImageTexture, textureCoordinate);\n" + - "\n" + - " // Convert to YIQ\n" + - " highp float YPrime = dot (color, kRGBToYPrime);\n" + - " highp float I = dot (color, kRGBToI);\n" + - " highp float Q = dot (color, kRGBToQ);\n" + - "\n" + - " // Calculate the hue and chroma\n" + - " highp float hue = atan (Q, I);\n" + - " highp float chroma = sqrt (I * I + Q * Q);\n" + - "\n" + - " // Make the user's adjustments\n" + - " hue += (-hueAdjust); //why negative rotation?\n" + - "\n" + - " // Convert back to YIQ\n" + - " Q = chroma * sin (hue);\n" + - " I = chroma * cos (hue);\n" + - "\n" + - " // Convert back to RGB\n" + - " highp vec4 yIQ = vec4 (YPrime, I, Q, 0.0);\n" + - " color.r = dot (yIQ, kYIQToR);\n" + - " color.g = dot (yIQ, kYIQToG);\n" + - " color.b = dot (yIQ, kYIQToB);\n" + - "\n" + - " // Save the result\n" + - " gl_FragColor = color;\n" + - "}\n"; private float mHue; private int mHueLocation; @@ -74,7 +32,7 @@ public class GPUImageHueFilter extends GPUImageFilter { } public GPUImageHueFilter(final float hue) { - super(MagicFilterType.HUE, HUE_FRAGMENT_SHADER); + super(MagicFilterType.HUE, R.raw.hue); mHue = hue; } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSaturationFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSaturationFilter.java index 8fc5832..1486e1a 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSaturationFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSaturationFilter.java @@ -20,28 +20,12 @@ import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; +import net.ossrs.yasea.R; + /** * saturation: The degree of saturation or desaturation to apply to the image (0.0 - 2.0, with 1.0 as the default) */ public class GPUImageSaturationFilter extends GPUImageFilter { - public static final String SATURATION_FRAGMENT_SHADER = "" + - " varying highp vec2 textureCoordinate;\n" + - " \n" + - " uniform sampler2D inputImageTexture;\n" + - " uniform lowp float saturation;\n" + - " \n" + - " // Values from \"Graphics Shaders: Theory and Practice\" by Bailey and Cunningham\n" + - " const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721);\n" + - " \n" + - " void main()\n" + - " {\n" + - " lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + - " lowp float luminance = dot(textureColor.rgb, luminanceWeighting);\n" + - " lowp vec3 greyScaleColor = vec3(luminance);\n" + - " \n" + - " gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w);\n" + - " \n" + - " }"; private int mSaturationLocation; private float mSaturation; @@ -51,7 +35,7 @@ public class GPUImageSaturationFilter extends GPUImageFilter { } public GPUImageSaturationFilter(final float saturation) { - super(MagicFilterType.SATURATION, SATURATION_FRAGMENT_SHADER); + super(MagicFilterType.SATURATION, R.raw.saturation); mSaturation = saturation; } diff --git a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSharpenFilter.java b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSharpenFilter.java index c88eeed..72a510c 100644 --- a/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSharpenFilter.java +++ b/app/src/main/java/com/seu/magicfilter/base/gpuimage/GPUImageSharpenFilter.java @@ -20,70 +20,14 @@ import android.opengl.GLES20; import com.seu.magicfilter.utils.MagicFilterType; +import net.ossrs.yasea.R; + /** * Sharpens the picture.
*
* sharpness: from -4.0 to 4.0, with 0.0 as the normal level */ public class GPUImageSharpenFilter extends GPUImageFilter { - public static final String SHARPEN_VERTEX_SHADER = "" + - "attribute vec4 position;\n" + - "attribute vec4 inputTextureCoordinate;\n" + - "\n" + - "uniform float imageWidthFactor; \n" + - "uniform float imageHeightFactor; \n" + - "uniform float sharpness;\n" + - "\n" + - "varying vec2 textureCoordinate;\n" + - "varying vec2 leftTextureCoordinate;\n" + - "varying vec2 rightTextureCoordinate; \n" + - "varying vec2 topTextureCoordinate;\n" + - "varying vec2 bottomTextureCoordinate;\n" + - "\n" + - "varying float centerMultiplier;\n" + - "varying float edgeMultiplier;\n" + - "\n" + - "void main()\n" + - "{\n" + - " gl_Position = position;\n" + - " \n" + - " mediump vec2 widthStep = vec2(imageWidthFactor, 0.0);\n" + - " mediump vec2 heightStep = vec2(0.0, imageHeightFactor);\n" + - " \n" + - " textureCoordinate = inputTextureCoordinate.xy;\n" + - " leftTextureCoordinate = inputTextureCoordinate.xy - widthStep;\n" + - " rightTextureCoordinate = inputTextureCoordinate.xy + widthStep;\n" + - " topTextureCoordinate = inputTextureCoordinate.xy + heightStep; \n" + - " bottomTextureCoordinate = inputTextureCoordinate.xy - heightStep;\n" + - " \n" + - " centerMultiplier = 1.0 + 4.0 * sharpness;\n" + - " edgeMultiplier = sharpness;\n" + - "}"; - - public static final String SHARPEN_FRAGMENT_SHADER = "" + - "precision highp float;\n" + - "\n" + - "varying highp vec2 textureCoordinate;\n" + - "varying highp vec2 leftTextureCoordinate;\n" + - "varying highp vec2 rightTextureCoordinate; \n" + - "varying highp vec2 topTextureCoordinate;\n" + - "varying highp vec2 bottomTextureCoordinate;\n" + - "\n" + - "varying highp float centerMultiplier;\n" + - "varying highp float edgeMultiplier;\n" + - "\n" + - "uniform sampler2D inputImageTexture;\n" + - "\n" + - "void main()\n" + - "{\n" + - " mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb;\n" + - " mediump vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb;\n" + - " mediump vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb;\n" + - " mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb;\n" + - " mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb;\n" + - "\n" + - " gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w);\n" + - "}"; private int mSharpnessLocation; private float mSharpness; @@ -95,7 +39,7 @@ public class GPUImageSharpenFilter extends GPUImageFilter { } public GPUImageSharpenFilter(final float sharpness) { - super(MagicFilterType.SHARPEN, SHARPEN_VERTEX_SHADER, SHARPEN_FRAGMENT_SHADER); + super(MagicFilterType.SHARPEN, R.raw.vertex_sharpen, R.raw.sharpen); mSharpness = sharpness; } diff --git a/app/src/main/java/com/seu/magicfilter/utils/OpenGlUtils.java b/app/src/main/java/com/seu/magicfilter/utils/OpenGLUtils.java similarity index 99% rename from app/src/main/java/com/seu/magicfilter/utils/OpenGlUtils.java rename to app/src/main/java/com/seu/magicfilter/utils/OpenGLUtils.java index 80d834e..bf33ff8 100644 --- a/app/src/main/java/com/seu/magicfilter/utils/OpenGlUtils.java +++ b/app/src/main/java/com/seu/magicfilter/utils/OpenGLUtils.java @@ -17,7 +17,7 @@ import android.opengl.GLES20; import android.opengl.GLUtils; import android.util.Log; -public class OpenGlUtils { +public class OpenGLUtils { public static final int NO_TEXTURE = -1; public static final int NOT_INIT = -1; public static final int ON_DRAWN = 1; diff --git a/app/src/main/java/net/ossrs/yasea/SrsCameraView.java b/app/src/main/java/net/ossrs/yasea/SrsCameraView.java index 85dc45c..97e2bc5 100644 --- a/app/src/main/java/net/ossrs/yasea/SrsCameraView.java +++ b/app/src/main/java/net/ossrs/yasea/SrsCameraView.java @@ -12,7 +12,7 @@ import android.widget.Toast; import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.utils.MagicFilterFactory; import com.seu.magicfilter.utils.MagicFilterType; -import com.seu.magicfilter.utils.OpenGlUtils; +import com.seu.magicfilter.utils.OpenGLUtils; import java.io.IOException; import java.nio.ByteBuffer; @@ -32,7 +32,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render private SurfaceTexture surfaceTexture; - private int mTextureId = OpenGlUtils.NO_TEXTURE; + private int mOESTextureId = OpenGLUtils.NO_TEXTURE; private int mSurfaceWidth; private int mSurfaceHeight; private int mPreviewWidth; @@ -71,8 +71,8 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render magicFilter.init(); magicFilter.onInputSizeChanged(mPreviewWidth, mPreviewHeight); - mTextureId = OpenGlUtils.getExternalOESTextureID(); - surfaceTexture = new SurfaceTexture(mTextureId); + mOESTextureId = OpenGLUtils.getExternalOESTextureID(); + surfaceTexture = new SurfaceTexture(mOESTextureId); surfaceTexture.setOnFrameAvailableListener(new SurfaceTexture.OnFrameAvailableListener() { @Override public void onFrameAvailable(SurfaceTexture surfaceTexture) { @@ -95,7 +95,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render GLES20.glViewport(0,0,width, height); mSurfaceWidth = width; mSurfaceHeight = height; - magicFilter.onDisplaySizeChanged(mSurfaceWidth, mSurfaceHeight); + magicFilter.onDisplaySizeChanged(width, height); } @Override @@ -108,9 +108,8 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render float[] mtx = new float[16]; surfaceTexture.getTransformMatrix(mtx); magicFilter.setTextureTransformMatrix(mtx); - - magicFilter.onDrawFrame(); - mGLIntBufferCache.add(magicFilter.getGlFboBuffer()); + magicFilter.onDrawFrame(mOESTextureId); + mGLIntBufferCache.add(magicFilter.getGLFboBuffer()); synchronized (writeLock) { writeLock.notifyAll(); } @@ -150,12 +149,12 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render } private void deleteTextures() { - if(mTextureId != OpenGlUtils.NO_TEXTURE){ + if(mOESTextureId != OpenGLUtils.NO_TEXTURE){ queueEvent(new Runnable() { @Override public void run() { - GLES20.glDeleteTextures(1, new int[]{ mTextureId }, 0); - mTextureId = OpenGlUtils.NO_TEXTURE; + GLES20.glDeleteTextures(1, new int[]{ mOESTextureId }, 0); + mOESTextureId = OpenGLUtils.NO_TEXTURE; } }); } @@ -219,9 +218,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render } /***** set parameters *****/ - //params.set("orientation", "portrait"); - //params.set("orientation", "landscape"); - //params.setRotation(90); params.setPictureSize(mPreviewWidth, mPreviewHeight); params.setPreviewSize(mPreviewWidth, mPreviewHeight); int[] range = findClosestFpsRange(SrsEncoder.VFPS, params.getSupportedPreviewFpsRange()); @@ -261,8 +257,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render } if (mCamera != null) { - // need to SET NULL CB before stop preview!!! - mCamera.setPreviewCallback(null); mCamera.stopPreview(); mCamera.release(); mCamera = null; diff --git a/app/src/main/res/raw/beauty.glsl b/app/src/main/res/raw/beauty.glsl index 016b5ba..50b5186 100644 --- a/app/src/main/res/raw/beauty.glsl +++ b/app/src/main/res/raw/beauty.glsl @@ -1,89 +1,109 @@ #extension GL_OES_EGL_image_external : require -precision mediump float; +precision highp float; uniform samplerExternalOES inputImageTexture; uniform vec2 singleStepOffset; -uniform mediump float params; -varying mediump vec2 textureCoordinate; +varying vec2 textureCoordinate; -const highp vec3 W = vec3(0.299,0.587,0.114); -vec2 blurCoordinates[20]; +const vec4 params = vec4(0.33, 0.63, 0.4, 0.35); +const vec3 W = vec3(0.299,0.587,0.114); +const mat3 saturateMatrix = mat3( + 1.1102,-0.0598,-0.061, + -0.0774,1.0826,-0.1186, + -0.0228,-0.0228,1.1772); -float hardLight(float color) -{ - if(color <= 0.5) - color = color * color * 2.0; - else - color = 1.0 - ((1.0 - color)*(1.0 - color) * 2.0); - return color; -} +vec2 blurCoordinates[24]; -void main(){ +float hardLight(float color) { + if(color <= 0.5) { + color = color * color * 2.0; + } else { + color = 1.0 - ((1.0 - color)*(1.0 - color) * 2.0); + } + return color; +} +void main() { vec3 centralColor = texture2D(inputImageTexture, textureCoordinate).rgb; - if(params != 0.0){ - - blurCoordinates[0] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -10.0); - blurCoordinates[1] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 10.0); - blurCoordinates[2] = textureCoordinate.xy + singleStepOffset * vec2(-10.0, 0.0); - blurCoordinates[3] = textureCoordinate.xy + singleStepOffset * vec2(10.0, 0.0); - blurCoordinates[4] = textureCoordinate.xy + singleStepOffset * vec2(5.0, -8.0); - blurCoordinates[5] = textureCoordinate.xy + singleStepOffset * vec2(5.0, 8.0); - blurCoordinates[6] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, 8.0); - blurCoordinates[7] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, -8.0); - blurCoordinates[8] = textureCoordinate.xy + singleStepOffset * vec2(8.0, -5.0); - blurCoordinates[9] = textureCoordinate.xy + singleStepOffset * vec2(8.0, 5.0); - blurCoordinates[10] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, 5.0); - blurCoordinates[11] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, -5.0); - blurCoordinates[12] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -6.0); - blurCoordinates[13] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 6.0); - blurCoordinates[14] = textureCoordinate.xy + singleStepOffset * vec2(6.0, 0.0); - blurCoordinates[15] = textureCoordinate.xy + singleStepOffset * vec2(-6.0, 0.0); - blurCoordinates[16] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, -4.0); - blurCoordinates[17] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, 4.0); - blurCoordinates[18] = textureCoordinate.xy + singleStepOffset * vec2(4.0, -4.0); - blurCoordinates[19] = textureCoordinate.xy + singleStepOffset * vec2(4.0, 4.0); - - float sampleColor = centralColor.g * 20.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[0]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[1]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[2]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[3]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[4]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[5]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[6]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[7]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[8]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[9]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[10]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[11]).g; - sampleColor += texture2D(inputImageTexture, blurCoordinates[12]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[13]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[14]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[15]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[16]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[17]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[18]).g * 2.0; - sampleColor += texture2D(inputImageTexture, blurCoordinates[19]).g * 2.0; - - sampleColor = sampleColor / 48.0; - - float highPass = centralColor.g - sampleColor + 0.5; - - for(int i = 0; i < 5;i++) - { - highPass = hardLight(highPass); - } - float luminance = dot(centralColor, W); - - float alpha = pow(luminance, params); - - vec3 smoothColor = centralColor + (centralColor-vec3(highPass))*alpha*0.1; - - gl_FragColor = vec4(mix(smoothColor.rgb, max(smoothColor, centralColor), alpha), 1.0); - }else{ - gl_FragColor = vec4(centralColor.rgb,1.0);; + + blurCoordinates[0] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -10.0); + blurCoordinates[1] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 10.0); + blurCoordinates[2] = textureCoordinate.xy + singleStepOffset * vec2(-10.0, 0.0); + blurCoordinates[3] = textureCoordinate.xy + singleStepOffset * vec2(10.0, 0.0); + blurCoordinates[4] = textureCoordinate.xy + singleStepOffset * vec2(5.0, -8.0); + blurCoordinates[5] = textureCoordinate.xy + singleStepOffset * vec2(5.0, 8.0); + blurCoordinates[6] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, 8.0); + blurCoordinates[7] = textureCoordinate.xy + singleStepOffset * vec2(-5.0, -8.0); + blurCoordinates[8] = textureCoordinate.xy + singleStepOffset * vec2(8.0, -5.0); + blurCoordinates[9] = textureCoordinate.xy + singleStepOffset * vec2(8.0, 5.0); + blurCoordinates[10] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, 5.0); + blurCoordinates[11] = textureCoordinate.xy + singleStepOffset * vec2(-8.0, -5.0); + blurCoordinates[12] = textureCoordinate.xy + singleStepOffset * vec2(0.0, -6.0); + blurCoordinates[13] = textureCoordinate.xy + singleStepOffset * vec2(0.0, 6.0); + blurCoordinates[14] = textureCoordinate.xy + singleStepOffset * vec2(6.0, 0.0); + blurCoordinates[15] = textureCoordinate.xy + singleStepOffset * vec2(-6.0, 0.0); + blurCoordinates[16] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, -4.0); + blurCoordinates[17] = textureCoordinate.xy + singleStepOffset * vec2(-4.0, 4.0); + blurCoordinates[18] = textureCoordinate.xy + singleStepOffset * vec2(4.0, -4.0); + blurCoordinates[19] = textureCoordinate.xy + singleStepOffset * vec2(4.0, 4.0); + blurCoordinates[20] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, -2.0); + blurCoordinates[21] = textureCoordinate.xy + singleStepOffset * vec2(-2.0, 2.0); + blurCoordinates[22] = textureCoordinate.xy + singleStepOffset * vec2(2.0, -2.0); + blurCoordinates[23] = textureCoordinate.xy + singleStepOffset * vec2(2.0, 2.0); + + float sampleColor = centralColor.g * 22.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[0]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[1]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[2]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[3]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[4]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[5]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[6]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[7]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[8]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[9]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[10]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[11]).g; + sampleColor += texture2D(inputImageTexture, blurCoordinates[12]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[13]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[14]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[15]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[16]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[17]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[18]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[19]).g * 2.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[20]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[21]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[22]).g * 3.0; + sampleColor += texture2D(inputImageTexture, blurCoordinates[23]).g * 3.0; + sampleColor = sampleColor / 62.0; + + float highPass = centralColor.g - sampleColor + 0.5; + + for(int i = 0; i < 5;i++) + { + highPass = hardLight(highPass); } + float luminance = dot(centralColor, W); + float alpha = pow(luminance, params.r); + + vec3 smoothColor = centralColor + (centralColor-vec3(highPass))*alpha*0.1; + + smoothColor.r = clamp(pow(smoothColor.r, params.g),0.0,1.0); + smoothColor.g = clamp(pow(smoothColor.g, params.g),0.0,1.0); + smoothColor.b = clamp(pow(smoothColor.b, params.g),0.0,1.0); + + vec3 screen = vec3(1.0) - (vec3(1.0)-smoothColor) * (vec3(1.0)-centralColor); + vec3 lighten = max(smoothColor, centralColor); + vec3 softLight = 2.0 * centralColor*smoothColor + centralColor*centralColor + - 2.0 * centralColor*centralColor * smoothColor; + + gl_FragColor = vec4(mix(centralColor, screen, alpha), 1.0); + gl_FragColor.rgb = mix(gl_FragColor.rgb, lighten, alpha); + gl_FragColor.rgb = mix(gl_FragColor.rgb, softLight, params.b); + + vec3 satColor = gl_FragColor.rgb * saturateMatrix; + gl_FragColor.rgb = mix(gl_FragColor.rgb, satColor, params.a); } \ No newline at end of file diff --git a/app/src/main/res/raw/blackcat.glsl b/app/src/main/res/raw/blackcat.glsl index e919df4..36697e4 100644 --- a/app/src/main/res/raw/blackcat.glsl +++ b/app/src/main/res/raw/blackcat.glsl @@ -9,85 +9,84 @@ uniform sampler2D curve; vec3 rgb2hsv(vec3 c) { - vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); - vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); - vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); - - float d = q.x - min(q.w, q.y); - float e = 1.0e-10; + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g)); + vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r)); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); } vec3 hsv2rgb(vec3 c) { - vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); - vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); - return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); } -void main() -{ +void main() { float GreyVal; - lowp vec4 textureColor; + lowp vec4 textureColor; lowp vec4 textureColorOri; - float xCoordinate = textureCoordinate.x; - float yCoordinate = textureCoordinate.y; - - highp float redCurveValue; - highp float greenCurveValue; - highp float blueCurveValue; - textureColor = texture2D( inputImageTexture, vec2(xCoordinate, yCoordinate)); - // step1 curve - redCurveValue = texture2D(curve, vec2(textureColor.r, 0.0)).r; - greenCurveValue = texture2D(curve, vec2(textureColor.g, 0.0)).g; - blueCurveValue = texture2D(curve, vec2(textureColor.b, 0.0)).b; - - - //textureColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, 1.0); - vec3 tColor = vec3(redCurveValue, greenCurveValue, blueCurveValue); - tColor = rgb2hsv(tColor); - - tColor.g = tColor.g * 1.2; - - float dStrength = 1.0; - float dSatStrength = 0.3; - - float dGap = 0.0; - - if( tColor.r >= 0.0 && tColor.r < 0.417) - { - tColor.g = tColor.g + (tColor.g * dSatStrength); - } - else if( tColor.r > 0.958 && tColor.r <= 1.0) - { - tColor.g = tColor.g + (tColor.g * dSatStrength); - } - else if( tColor.r >= 0.875 && tColor.r <= 0.958) - { - dGap = abs(tColor.r - 0.875); - dStrength = (dGap / 0.0833); - - tColor.g = tColor.g + (tColor.g * dSatStrength * dStrength); - } - else if( tColor.r >= 0.0417 && tColor.r <= 0.125) - { - dGap = abs(tColor.r - 0.125); - dStrength = (dGap / 0.0833); - - tColor.g = tColor.g + (tColor.g * dSatStrength * dStrength); - } - - tColor = hsv2rgb(tColor); - tColor = clamp(tColor, 0.0, 1.0); - - redCurveValue = texture2D(curve, vec2(tColor.r, 1.0)).r; - greenCurveValue = texture2D(curve, vec2(tColor.g, 1.0)).r; - blueCurveValue = texture2D(curve, vec2(tColor.b, 1.0)).r; - - redCurveValue = texture2D(curve, vec2(redCurveValue, 1.0)).g; - greenCurveValue = texture2D(curve, vec2(greenCurveValue, 1.0)).g; - blueCurveValue = texture2D(curve, vec2(blueCurveValue, 1.0)).g; - - textureColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, 1.0); - - gl_FragColor = vec4(textureColor.r, textureColor.g, textureColor.b, 1.0); + float xCoordinate = textureCoordinate.x; + float yCoordinate = textureCoordinate.y; + + highp float redCurveValue; + highp float greenCurveValue; + highp float blueCurveValue; + textureColor = texture2D( inputImageTexture, vec2(xCoordinate, yCoordinate)); + // step1 curve + redCurveValue = texture2D(curve, vec2(textureColor.r, 0.0)).r; + greenCurveValue = texture2D(curve, vec2(textureColor.g, 0.0)).g; + blueCurveValue = texture2D(curve, vec2(textureColor.b, 0.0)).b; + + + //textureColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, 1.0); + vec3 tColor = vec3(redCurveValue, greenCurveValue, blueCurveValue); + tColor = rgb2hsv(tColor); + + tColor.g = tColor.g * 1.2; + + float dStrength = 1.0; + float dSatStrength = 0.3; + + float dGap = 0.0; + + if( tColor.r >= 0.0 && tColor.r < 0.417) + { + tColor.g = tColor.g + (tColor.g * dSatStrength); + } + else if( tColor.r > 0.958 && tColor.r <= 1.0) + { + tColor.g = tColor.g + (tColor.g * dSatStrength); + } + else if( tColor.r >= 0.875 && tColor.r <= 0.958) + { + dGap = abs(tColor.r - 0.875); + dStrength = (dGap / 0.0833); + + tColor.g = tColor.g + (tColor.g * dSatStrength * dStrength); + } + else if( tColor.r >= 0.0417 && tColor.r <= 0.125) + { + dGap = abs(tColor.r - 0.125); + dStrength = (dGap / 0.0833); + + tColor.g = tColor.g + (tColor.g * dSatStrength * dStrength); + } + + tColor = hsv2rgb(tColor); + tColor = clamp(tColor, 0.0, 1.0); + + redCurveValue = texture2D(curve, vec2(tColor.r, 1.0)).r; + greenCurveValue = texture2D(curve, vec2(tColor.g, 1.0)).r; + blueCurveValue = texture2D(curve, vec2(tColor.b, 1.0)).r; + + redCurveValue = texture2D(curve, vec2(redCurveValue, 1.0)).g; + greenCurveValue = texture2D(curve, vec2(greenCurveValue, 1.0)).g; + blueCurveValue = texture2D(curve, vec2(blueCurveValue, 1.0)).g; + + textureColor = vec4(redCurveValue, greenCurveValue, blueCurveValue, 1.0); + + gl_FragColor = vec4(textureColor.r, textureColor.g, textureColor.b, 1.0); } \ No newline at end of file diff --git a/app/src/main/res/raw/brightness.glsl b/app/src/main/res/raw/brightness.glsl new file mode 100644 index 0000000..82dce92 --- /dev/null +++ b/app/src/main/res/raw/brightness.glsl @@ -0,0 +1,9 @@ +varying highp vec2 textureCoordinate; + +uniform sampler2D inputImageTexture; +uniform lowp float brightness; + +void main() { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + gl_FragColor = vec4((textureColor.rgb + vec3(brightness)), textureColor.w); +} \ No newline at end of file diff --git a/app/src/main/res/raw/constrast.glsl b/app/src/main/res/raw/constrast.glsl new file mode 100644 index 0000000..f40b4a3 --- /dev/null +++ b/app/src/main/res/raw/constrast.glsl @@ -0,0 +1,9 @@ +varying highp vec2 textureCoordinate; + +uniform sampler2D inputImageTexture; +uniform lowp float contrast; + +void main() { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + gl_FragColor = vec4(((textureColor.rgb - vec3(0.5)) * contrast + vec3(0.5)), textureColor.w); +} \ No newline at end of file diff --git a/app/src/main/res/raw/exposure.glsl b/app/src/main/res/raw/exposure.glsl new file mode 100644 index 0000000..1405753 --- /dev/null +++ b/app/src/main/res/raw/exposure.glsl @@ -0,0 +1,9 @@ +varying highp vec2 textureCoordinate; + +uniform sampler2D inputImageTexture; +uniform highp float exposure; + +void main() { + highp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + gl_FragColor = vec4(textureColor.rgb * pow(2.0, exposure), textureColor.w); +} \ No newline at end of file diff --git a/app/src/main/res/raw/default_fragment.glsl b/app/src/main/res/raw/fragment_default.glsl similarity index 68% rename from app/src/main/res/raw/default_fragment.glsl rename to app/src/main/res/raw/fragment_default.glsl index bf43f71..1ddb1f0 100644 --- a/app/src/main/res/raw/default_fragment.glsl +++ b/app/src/main/res/raw/fragment_default.glsl @@ -1,10 +1,8 @@ -#extension GL_OES_EGL_image_external : require - precision mediump float; varying mediump vec2 textureCoordinate; -uniform samplerExternalOES inputImageTexture; +uniform sampler2D inputImageTexture; void main() { vec3 centralColor = texture2D(inputImageTexture, textureCoordinate).rgb; diff --git a/app/src/main/res/raw/fragment_oes.glsl b/app/src/main/res/raw/fragment_oes.glsl new file mode 100644 index 0000000..2c6ed48 --- /dev/null +++ b/app/src/main/res/raw/fragment_oes.glsl @@ -0,0 +1,11 @@ +#extension GL_OES_EGL_image_external : require + +precision mediump float; + +varying mediump vec2 textureCoordinate; + +uniform samplerExternalOES inputImageTexture; + +void main() { + gl_FragColor = texture2D(inputImageTexture, textureCoordinate); +} \ No newline at end of file diff --git a/app/src/main/res/raw/hue.glsl b/app/src/main/res/raw/hue.glsl new file mode 100644 index 0000000..b053e23 --- /dev/null +++ b/app/src/main/res/raw/hue.glsl @@ -0,0 +1,43 @@ +precision highp float; + +varying highp vec2 textureCoordinate; + +uniform sampler2D inputImageTexture; +uniform mediump float hueAdjust; +const highp vec4 kRGBToYPrime = vec4 (0.299, 0.587, 0.114, 0.0); +const highp vec4 kRGBToI = vec4 (0.595716, -0.274453, -0.321263, 0.0); +const highp vec4 kRGBToQ = vec4 (0.211456, -0.522591, 0.31135, 0.0); + +const highp vec4 kYIQToR = vec4 (1.0, 0.9563, 0.6210, 0.0); +const highp vec4 kYIQToG = vec4 (1.0, -0.2721, -0.6474, 0.0); +const highp vec4 kYIQToB = vec4 (1.0, -1.1070, 1.7046, 0.0); + +void main () { + // Sample the input pixel + highp vec4 color = texture2D(inputImageTexture, textureCoordinate); + + // Convert to YIQ + highp float YPrime = dot (color, kRGBToYPrime); + highp float I = dot (color, kRGBToI); + highp float Q = dot (color, kRGBToQ); + + // Calculate the hue and chroma + highp float hue = atan (Q, I); + highp float chroma = sqrt (I * I + Q * Q); + + // Make the user's adjustments + hue += (-hueAdjust); //why negative rotation? + + // Convert back to YIQ + Q = chroma * sin (hue); + I = chroma * cos (hue); + + // Convert back to RGB + highp vec4 yIQ = vec4 (YPrime, I, Q, 0.0); + color.r = dot (yIQ, kYIQToR); + color.g = dot (yIQ, kYIQToG); + color.b = dot (yIQ, kYIQToB); + + // Save the result + gl_FragColor = color; +} \ No newline at end of file diff --git a/app/src/main/res/raw/lookup.glsl b/app/src/main/res/raw/lookup.glsl new file mode 100644 index 0000000..e70e446 --- /dev/null +++ b/app/src/main/res/raw/lookup.glsl @@ -0,0 +1,33 @@ +varying highp vec2 textureCoordinate; + +uniform sampler2D inputImageTexture; +uniform sampler2D inputImageTexture2; // lookup texture\n" + + +void main() { + + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);\n" + + + mediump float blueColor = textureColor.b * 63.0; + + mediump vec2 quad1; + quad1.y = floor(floor(blueColor) / 8.0); + quad1.x = floor(blueColor) - (quad1.y * 8.0); + + mediump vec2 quad2;\n" + + quad2.y = floor(ceil(blueColor) / 8.0);\n" + + quad2.x = ceil(blueColor) - (quad2.y * 8.0);\n" + + + highp vec2 texPos1; + texPos1.x = (quad1.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r); + texPos1.y = (quad1.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g); + + highp vec2 texPos2;\n" + + texPos2.x = (quad2.x * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.r); + texPos2.y = (quad2.y * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.g); + + lowp vec4 newColor1 = texture2D(inputImageTexture2, texPos1); + lowp vec4 newColor2 = texture2D(inputImageTexture2, texPos2); + + lowp vec4 newColor = mix(newColor1, newColor2, fract(blueColor)); + gl_FragColor = vec4(newColor.rgb, textureColor.w); +} \ No newline at end of file diff --git a/app/src/main/res/raw/saturation.glsl b/app/src/main/res/raw/saturation.glsl new file mode 100644 index 0000000..936c032 --- /dev/null +++ b/app/src/main/res/raw/saturation.glsl @@ -0,0 +1,15 @@ +varying highp vec2 textureCoordinate; + +uniform sampler2D inputImageTexture; +uniform lowp float saturation; + +// Values from \"Graphics Shaders: Theory and Practice\" by Bailey and Cunningham +const mediump vec3 luminanceWeighting = vec3(0.2125, 0.7154, 0.0721); + +void main() { + lowp vec4 textureColor = texture2D(inputImageTexture, textureCoordinate); + lowp float luminance = dot(textureColor.rgb, luminanceWeighting); + lowp vec3 greyScaleColor = vec3(luminance); + + gl_FragColor = vec4(mix(greyScaleColor, textureColor.rgb, saturation), textureColor.w); +} \ No newline at end of file diff --git a/app/src/main/res/raw/sharpen.glsl b/app/src/main/res/raw/sharpen.glsl new file mode 100644 index 0000000..642d7b8 --- /dev/null +++ b/app/src/main/res/raw/sharpen.glsl @@ -0,0 +1,22 @@ +precision highp float; + +varying highp vec2 textureCoordinate; +varying highp vec2 leftTextureCoordinate; +varying highp vec2 rightTextureCoordinate; +varying highp vec2 topTextureCoordinate; +varying highp vec2 bottomTextureCoordinate; + +varying highp float centerMultiplier; +varying highp float edgeMultiplier; + +uniform sampler2D inputImageTexture; + +void main() { + mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb; + mediump vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb; + mediump vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb; + mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb; + mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb; + + gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w); +} \ No newline at end of file diff --git a/app/src/main/res/raw/vertex_default.glsl b/app/src/main/res/raw/vertex_default.glsl new file mode 100644 index 0000000..720aa9d --- /dev/null +++ b/app/src/main/res/raw/vertex_default.glsl @@ -0,0 +1,9 @@ +attribute vec4 position; +attribute vec4 inputTextureCoordinate; + +varying vec2 textureCoordinate; + +void main() { + textureCoordinate = inputTextureCoordinate.xy; + gl_Position = position; +} diff --git a/app/src/main/res/raw/default_vertex.glsl b/app/src/main/res/raw/vertex_oes.glsl similarity index 59% rename from app/src/main/res/raw/default_vertex.glsl rename to app/src/main/res/raw/vertex_oes.glsl index f7af466..da85635 100644 --- a/app/src/main/res/raw/default_vertex.glsl +++ b/app/src/main/res/raw/vertex_oes.glsl @@ -6,6 +6,6 @@ varying vec2 textureCoordinate; uniform mat4 textureTransform; void main() { - textureCoordinate = (textureTransform * inputTextureCoordinate).xy; - gl_Position = position; + textureCoordinate = (textureTransform * inputTextureCoordinate).xy; + gl_Position = position; } diff --git a/app/src/main/res/raw/vertex_sharpen.glsl b/app/src/main/res/raw/vertex_sharpen.glsl new file mode 100644 index 0000000..d1050ae --- /dev/null +++ b/app/src/main/res/raw/vertex_sharpen.glsl @@ -0,0 +1,31 @@ +attribute vec4 position; +attribute vec4 inputTextureCoordinate; + +uniform float imageWidthFactor; +uniform float imageHeightFactor; +uniform float sharpness; + +varying vec2 textureCoordinate; +varying vec2 leftTextureCoordinate; +varying vec2 rightTextureCoordinate; +varying vec2 topTextureCoordinate; +varying vec2 bottomTextureCoordinate; + +varying float centerMultiplier; +varying float edgeMultiplier; + +void main() { + gl_Position = position; + + mediump vec2 widthStep = vec2(imageWidthFactor, 0.0); + mediump vec2 heightStep = vec2(0.0, imageHeightFactor); + + textureCoordinate = inputTextureCoordinate.xy; + leftTextureCoordinate = inputTextureCoordinate.xy - widthStep; + rightTextureCoordinate = inputTextureCoordinate.xy + widthStep; + topTextureCoordinate = inputTextureCoordinate.xy + heightStep; + bottomTextureCoordinate = inputTextureCoordinate.xy - heightStep; + + centerMultiplier = 1.0 + 4.0 * sharpness; + edgeMultiplier = sharpness; +} \ No newline at end of file