Prevent context leak for magic filter

Signed-off-by: Leo Ma <begeekmyfriend@gmail.com>
camera2
Leo Ma 9 years ago
parent 766be308ea
commit b02909de66

@ -10,59 +10,59 @@ import com.seu.magicfilter.utils.MagicFilterFactory;
import com.seu.magicfilter.utils.OpenGLUtils; import com.seu.magicfilter.utils.OpenGLUtils;
public class MagicAmaroFilter extends GPUImageFilter{ public class MagicAmaroFilter extends GPUImageFilter{
private int[] inputTextureHandles = {-1,-1,-1}; private int[] inputTextureHandles = {-1,-1,-1};
private int[] inputTextureUniformLocations = {-1,-1,-1}; private int[] inputTextureUniformLocations = {-1,-1,-1};
private int mGLStrengthLocation; private int mGLStrengthLocation;
public MagicAmaroFilter(){ public MagicAmaroFilter(){
super(MagicFilterType.AMARO, R.raw.amaro); super(MagicFilterType.AMARO, R.raw.amaro);
} }
@Override @Override
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0); GLES20.glDeleteTextures(inputTextureHandles.length, inputTextureHandles, 0);
for(int i = 0; i < inputTextureHandles.length; i++) for(int i = 0; i < inputTextureHandles.length; i++)
inputTextureHandles[i] = -1; inputTextureHandles[i] = -1;
} }
@Override @Override
protected void onDrawArraysAfter(){ 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.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3));
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
} }
} }
@Override @Override
protected void onDrawArraysPre(){ 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.glActiveTexture(GLES20.GL_TEXTURE0 + (i+3));
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, inputTextureHandles[i]);
GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3)); GLES20.glUniform1i(inputTextureUniformLocations[i], (i+3));
} }
} }
@Override @Override
protected void onInit(){ protected void onInit(){
super.onInit(); super.onInit();
for (int i = 0; i < inputTextureUniformLocations.length; i++) { for (int i = 0; i < inputTextureUniformLocations.length; i++) {
inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i)); inputTextureUniformLocations[i] = GLES20.glGetUniformLocation(getProgram(), "inputImageTexture" + (2 + i));
} }
mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength"); mGLStrengthLocation = GLES20.glGetUniformLocation(getProgram(), "strength");
} }
@Override @Override
protected void onInitialized(){ protected void onInitialized(){
super.onInitialized(); super.onInitialized();
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_blowout.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/brannan_blowout.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/overlaymap.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaromap.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/amaromap.png");
} }
}); });
} }
} }

@ -10,79 +10,79 @@ import net.ossrs.yasea.R;
import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.base.gpuimage.GPUImageFilter;
public class MagicAntiqueFilter extends GPUImageFilter{ public class MagicAntiqueFilter extends GPUImageFilter{
private int[] mToneCurveTexture = {-1}; private int[] mToneCurveTexture = {-1};
private int mToneCurveTextureUniformLocation; private int mToneCurveTextureUniformLocation;
public MagicAntiqueFilter(){ public MagicAntiqueFilter(){
super(MagicFilterType.ANTIQUE, R.raw.antique); super(MagicFilterType.ANTIQUE, R.raw.antique);
} }
@Override @Override
protected void onDestroy(){ protected void onDestroy(){
super.onDestroy(); super.onDestroy();
GLES20.glDeleteTextures(1, mToneCurveTexture, 0); GLES20.glDeleteTextures(1, mToneCurveTexture, 0);
this.mToneCurveTexture[0] = -1; this.mToneCurveTexture[0] = -1;
} }
@Override @Override
protected void onDrawArraysAfter(){ protected void onDrawArraysAfter(){
if (this.mToneCurveTexture[0] != -1){ if (this.mToneCurveTexture[0] != -1){
GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
} }
} }
@Override @Override
protected void onDrawArraysPre(){ protected void onDrawArraysPre(){
if (this.mToneCurveTexture[0] != -1){ if (this.mToneCurveTexture[0] != -1){
GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
GLES20.glUniform1i(this.mToneCurveTextureUniformLocation, 3); GLES20.glUniform1i(this.mToneCurveTextureUniformLocation, 3);
} }
} }
@Override @Override
protected void onInit(){ protected void onInit(){
super.onInit(); super.onInit();
mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve");
} }
@Override @Override
protected void onInitialized(){ protected void onInitialized(){
super.onInitialized(); super.onInitialized();
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
GLES20.glGenTextures(1, mToneCurveTexture, 0); GLES20.glGenTextures(1, mToneCurveTexture, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
byte[] arrayOfByte = new byte[2048]; byte[] arrayOfByte = new byte[2048];
int[] arrayOfInt1 = { 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, 21, 22, 23, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 119, 120, 122, 123, 124, 126, 127, 128, 130, 131, 132, 134, 135, 136, 137, 139, 140, 141, 143, 144, 145, 146, 148, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 164, 165, 166, 168, 169, 170, 171, 172, 173, 175, 176, 177, 178, 179, 180, 181, 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, 211, 211, 212, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 249, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255 }; int[] arrayOfInt1 = { 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, 21, 22, 23, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 55, 56, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 85, 86, 87, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 119, 120, 122, 123, 124, 126, 127, 128, 130, 131, 132, 134, 135, 136, 137, 139, 140, 141, 143, 144, 145, 146, 148, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 164, 165, 166, 168, 169, 170, 171, 172, 173, 175, 176, 177, 178, 179, 180, 181, 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, 211, 211, 212, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 249, 250, 251, 251, 252, 252, 253, 253, 254, 254, 255 };
int[] arrayOfInt2 = { 15, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 55, 56, 57, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 85, 86, 87, 87, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 102, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 118, 119, 120, 122, 123, 124, 126, 127, 128, 130, 131, 132, 134, 134, 135, 136, 137, 139, 140, 141, 143, 144, 145, 146, 148, 149, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 163, 164, 165, 166, 168, 169, 170, 171, 172, 173, 175, 176, 177, 177, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 211, 212, 212, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 245, 246, 247, 247, 248, 248, 249, 249, 250, 251, 251, 252, 252, 252, 253, 253, 254, 254, 255 }; int[] arrayOfInt2 = { 15, 15, 16, 17, 18, 19, 20, 20, 21, 22, 23, 23, 24, 25, 26, 27, 28, 29, 30, 31, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 55, 56, 57, 57, 58, 59, 61, 62, 63, 64, 66, 67, 68, 69, 71, 72, 72, 73, 74, 76, 77, 78, 79, 81, 82, 83, 85, 86, 87, 87, 89, 90, 91, 93, 94, 95, 96, 98, 99, 100, 102, 102, 103, 104, 106, 107, 108, 110, 111, 112, 114, 115, 116, 118, 118, 119, 120, 122, 123, 124, 126, 127, 128, 130, 131, 132, 134, 134, 135, 136, 137, 139, 140, 141, 143, 144, 145, 146, 148, 149, 149, 150, 152, 153, 154, 155, 157, 158, 159, 160, 161, 163, 163, 164, 165, 166, 168, 169, 170, 171, 172, 173, 175, 176, 177, 177, 178, 179, 180, 181, 183, 184, 185, 186, 187, 188, 189, 190, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 211, 212, 212, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 238, 239, 239, 240, 241, 241, 242, 242, 243, 244, 244, 245, 245, 245, 246, 247, 247, 248, 248, 249, 249, 250, 251, 251, 252, 252, 252, 253, 253, 254, 254, 255 };
int[] arrayOfInt3 = { 87, 89, 89, 90, 90, 91, 91, 93, 93, 94, 95, 95, 96, 96, 98, 98, 99, 100, 100, 102, 102, 103, 103, 104, 104, 106, 107, 107, 108, 108, 110, 110, 111, 112, 112, 114, 114, 115, 115, 116, 118, 118, 119, 119, 120, 120, 122, 123, 123, 124, 124, 126, 126, 127, 128, 128, 130, 130, 131, 131, 132, 134, 134, 135, 135, 136, 136, 137, 139, 139, 140, 140, 141, 143, 143, 144, 144, 145, 146, 146, 148, 148, 149, 150, 150, 152, 152, 153, 154, 154, 155, 155, 157, 158, 158, 159, 159, 160, 161, 161, 163, 163, 164, 165, 165, 166, 168, 168, 169, 169, 170, 171, 171, 172, 173, 173, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 183, 183, 184, 185, 185, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 199, 200, 201, 201, 202, 203, 204, 204, 205, 206, 206, 207, 208, 208, 209, 210, 211, 211, 211, 212, 212, 213, 214, 215, 215, 216, 216, 217, 217, 218, 219, 219, 220, 220, 221, 221, 222, 223, 223, 223, 224, 225, 226, 226, 226, 227, 228, 228, 228, 229, 230, 230, 230, 231, 232, 232, 232, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242, 242, 243, 244, 244, 244, 245, 245, 246, 247, 247, 247, 248, 248, 249, 249, 249, 250, 251, 251, 252, 252, 252, 253, 253, 254, 254, 254, 255 }; int[] arrayOfInt3 = { 87, 89, 89, 90, 90, 91, 91, 93, 93, 94, 95, 95, 96, 96, 98, 98, 99, 100, 100, 102, 102, 103, 103, 104, 104, 106, 107, 107, 108, 108, 110, 110, 111, 112, 112, 114, 114, 115, 115, 116, 118, 118, 119, 119, 120, 120, 122, 123, 123, 124, 124, 126, 126, 127, 128, 128, 130, 130, 131, 131, 132, 134, 134, 135, 135, 136, 136, 137, 139, 139, 140, 140, 141, 143, 143, 144, 144, 145, 146, 146, 148, 148, 149, 150, 150, 152, 152, 153, 154, 154, 155, 155, 157, 158, 158, 159, 159, 160, 161, 161, 163, 163, 164, 165, 165, 166, 168, 168, 169, 169, 170, 171, 171, 172, 173, 173, 175, 175, 176, 177, 177, 178, 179, 179, 180, 181, 181, 183, 183, 184, 185, 185, 186, 187, 187, 188, 189, 189, 190, 191, 191, 192, 193, 193, 194, 195, 195, 196, 197, 197, 198, 199, 199, 200, 201, 201, 202, 203, 204, 204, 205, 206, 206, 207, 208, 208, 209, 210, 211, 211, 211, 212, 212, 213, 214, 215, 215, 216, 216, 217, 217, 218, 219, 219, 220, 220, 221, 221, 222, 223, 223, 223, 224, 225, 226, 226, 226, 227, 228, 228, 228, 229, 230, 230, 230, 231, 232, 232, 232, 233, 234, 234, 235, 235, 236, 236, 237, 238, 238, 238, 239, 239, 240, 240, 241, 241, 242, 242, 242, 243, 244, 244, 244, 245, 245, 246, 247, 247, 247, 248, 248, 249, 249, 249, 250, 251, 251, 252, 252, 252, 253, 253, 254, 254, 254, 255 };
int[] arrayOfInt4 = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 24, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33, 34, 35, 36, 36, 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, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 119, 121, 122, 123, 125, 126, 127, 129, 130, 131, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 148, 149, 150, 152, 153, 154, 156, 157, 158, 159, 161, 162, 163, 165, 166, 167, 168, 170, 171, 172, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 192, 193, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 213, 214, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 250, 250, 251, 251, 252, 253, 253, 254, 254, 255 }; int[] arrayOfInt4 = { 0, 1, 1, 2, 3, 4, 4, 5, 6, 7, 7, 8, 9, 10, 10, 11, 12, 13, 13, 14, 15, 16, 17, 17, 18, 19, 20, 20, 21, 22, 23, 24, 24, 25, 26, 27, 28, 29, 29, 30, 31, 32, 33, 34, 35, 36, 36, 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, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 78, 79, 80, 81, 83, 84, 85, 86, 88, 89, 90, 91, 93, 94, 95, 97, 98, 99, 101, 102, 103, 105, 106, 107, 109, 110, 111, 113, 114, 115, 117, 118, 119, 121, 122, 123, 125, 126, 127, 129, 130, 131, 133, 134, 136, 137, 138, 140, 141, 142, 144, 145, 146, 148, 149, 150, 152, 153, 154, 156, 157, 158, 159, 161, 162, 163, 165, 166, 167, 168, 170, 171, 172, 173, 175, 176, 177, 178, 180, 181, 182, 183, 184, 186, 187, 188, 189, 190, 191, 192, 193, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 213, 214, 215, 216, 217, 218, 219, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 227, 228, 229, 230, 230, 231, 232, 232, 233, 234, 234, 235, 236, 236, 237, 238, 238, 239, 240, 240, 241, 242, 242, 243, 244, 244, 245, 245, 246, 247, 247, 248, 248, 249, 250, 250, 251, 251, 252, 253, 253, 254, 254, 255 };
for (int i = 0; i < 256; i++){ for (int i = 0; i < 256; i++){
arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]);
arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]);
arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]);
arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[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 }; 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++){ for (int j = 0; j < 256; j++){
arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]);
arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]);
arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]); arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt5[j]);
arrayOfByte[(3 + (1024 + j * 4))] = -1; 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)); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte));
} }
}); });
} }
} }

@ -59,11 +59,11 @@ public class MagicBrannanFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_process.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/brannan_process.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_blowout.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/brannan_blowout.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_contrast.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/brannan_contrast.png");
inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_luma.png"); inputTextureHandles[3] = OpenGLUtils.loadTexture(getContext(), "filter/brannan_luma.png");
inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brannan_screen.png"); inputTextureHandles[4] = OpenGLUtils.loadTexture(getContext(), "filter/brannan_screen.png");
} }
}); });
} }

@ -9,7 +9,7 @@ import com.seu.magicfilter.base.gpuimage.GPUImageFilter;
import com.seu.magicfilter.utils.MagicFilterFactory; import com.seu.magicfilter.utils.MagicFilterFactory;
import com.seu.magicfilter.utils.OpenGLUtils; import com.seu.magicfilter.utils.OpenGLUtils;
public class MagicBrooklynFilter extends GPUImageFilter{ public class MagicBrooklynFilter extends GPUImageFilter {
private int[] inputTextureHandles = {-1,-1,-1}; private int[] inputTextureHandles = {-1,-1,-1};
private int[] inputTextureUniformLocations = {-1,-1,-1}; private int[] inputTextureUniformLocations = {-1,-1,-1};
private int mGLStrengthLocation; private int mGLStrengthLocation;
@ -60,9 +60,9 @@ public class MagicBrooklynFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brooklynCurves1.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/brooklynCurves1.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/filter_map_first.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/filter_map_first.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/brooklynCurves2.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/brooklynCurves2.png");
} }
}); });
} }

@ -119,8 +119,8 @@ public class MagicCalmFilter extends GPUImageFilter{
arrayOfByte[(3 + (2048 + k * 4))] = -1; 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)); 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"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/calm_mask1.jpg");
mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/calm_mask2.jpg"); mMaskGrey2TextureId = OpenGLUtils.loadTexture(getContext(), "filter/calm_mask2.jpg");
} }
}); });
} }

@ -60,11 +60,11 @@ public class MagicEarlyBirdFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdcurves.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/earlybirdcurves.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdoverlaymap_new.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/earlybirdoverlaymap_new.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignettemap_new.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/vignettemap_new.png");
inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdblowout.png"); inputTextureHandles[3] = OpenGLUtils.loadTexture(getContext(), "filter/earlybirdblowout.png");
inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/earlybirdmap.png"); inputTextureHandles[4] = OpenGLUtils.loadTexture(getContext(), "filter/earlybirdmap.png");
} }
}); });
} }

@ -10,80 +10,80 @@ import net.ossrs.yasea.R;
import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.base.gpuimage.GPUImageFilter;
public class MagicEmeraldFilter extends GPUImageFilter{ public class MagicEmeraldFilter extends GPUImageFilter{
private int[] mToneCurveTexture = {-1}; private int[] mToneCurveTexture = {-1};
private int mToneCurveTextureUniformLocation; private int mToneCurveTextureUniformLocation;
public MagicEmeraldFilter(){ public MagicEmeraldFilter(){
super(MagicFilterType.EMERALD, R.raw.emerald); super(MagicFilterType.EMERALD, R.raw.emerald);
} }
@Override @Override
protected void onDestroy(){ protected void onDestroy(){
super.onDestroy(); super.onDestroy();
GLES20.glDeleteTextures(1, mToneCurveTexture, 0); GLES20.glDeleteTextures(1, mToneCurveTexture, 0);
mToneCurveTexture[0] = -1; mToneCurveTexture[0] = -1;
} }
@Override @Override
protected void onDrawArraysAfter(){ protected void onDrawArraysAfter(){
if (mToneCurveTexture[0] != -1){ if (mToneCurveTexture[0] != -1){
GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, 0);
GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
} }
} }
@Override @Override
protected void onDrawArraysPre(){ protected void onDrawArraysPre(){
if (mToneCurveTexture[0] != -1){ if (mToneCurveTexture[0] != -1){
GLES20.glActiveTexture(GLES20.GL_TEXTURE3); GLES20.glActiveTexture(GLES20.GL_TEXTURE3);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3); GLES20.glUniform1i(mToneCurveTextureUniformLocation, 3);
} }
} }
@Override @Override
protected void onInit(){ protected void onInit(){
super.onInit(); super.onInit();
mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve"); mToneCurveTextureUniformLocation = GLES20.glGetUniformLocation(getProgram(), "curve");
} }
@Override @Override
protected void onInitialized(){ protected void onInitialized(){
super.onInitialized(); super.onInitialized();
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
GLES20.glGenTextures(1, mToneCurveTexture, 0); GLES20.glGenTextures(1, mToneCurveTexture, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mToneCurveTexture[0]);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR); GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR); GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE); GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D, GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE); GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
byte[] arrayOfByte = new byte[2048]; byte[] arrayOfByte = new byte[2048];
int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 4, 7, 8, 9, 10, 12, 13, 14, 17, 18, 19, 21, 22, 23, 25, 26, 29, 30, 31, 32, 34, 35, 36, 39, 40, 41, 43, 44, 45, 46, 48, 50, 51, 53, 54, 55, 56, 58, 60, 61, 62, 64, 65, 66, 67, 69, 70, 72, 73, 75, 76, 77, 78, 79, 81, 82, 84, 85, 87, 88, 89, 90, 91, 92, 94, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 110, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 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, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 236, 237, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 254, 254, 255 }; int[] arrayOfInt1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 3, 4, 7, 8, 9, 10, 12, 13, 14, 17, 18, 19, 21, 22, 23, 25, 26, 29, 30, 31, 32, 34, 35, 36, 39, 40, 41, 43, 44, 45, 46, 48, 50, 51, 53, 54, 55, 56, 58, 60, 61, 62, 64, 65, 66, 67, 69, 70, 72, 73, 75, 76, 77, 78, 79, 81, 82, 84, 85, 87, 88, 89, 90, 91, 92, 94, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 110, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 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, 173, 174, 175, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 236, 237, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 254, 254, 255 };
int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 1, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 41, 43, 44, 45, 46, 48, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 109, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 131, 132, 133, 134, 135, 136, 137, 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, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 254, 254, 255, 255, 255, 255, 255, 255 }; int[] arrayOfInt2 = { 0, 0, 0, 0, 0, 0, 1, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 41, 43, 44, 45, 46, 48, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 109, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 131, 132, 133, 134, 135, 136, 137, 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, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 254, 254, 255, 255, 255, 255, 255, 255 };
int[] arrayOfInt3 = { 0, 1, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 41, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 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, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 254, 254, 255 }; int[] arrayOfInt3 = { 0, 1, 3, 4, 5, 7, 8, 9, 10, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 25, 26, 27, 29, 30, 31, 32, 34, 35, 36, 37, 39, 40, 41, 43, 44, 45, 46, 48, 49, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 87, 88, 89, 90, 91, 92, 94, 95, 96, 97, 98, 99, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111, 112, 113, 114, 115, 116, 117, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 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, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 184, 185, 186, 187, 188, 189, 190, 191, 191, 192, 193, 194, 195, 196, 197, 197, 198, 199, 200, 201, 201, 202, 203, 204, 205, 206, 206, 207, 208, 209, 210, 210, 211, 212, 213, 213, 214, 215, 216, 216, 217, 218, 219, 220, 220, 221, 222, 223, 223, 224, 225, 226, 226, 227, 228, 228, 229, 230, 231, 231, 232, 233, 234, 234, 235, 236, 237, 237, 238, 239, 239, 240, 241, 242, 242, 243, 244, 244, 245, 246, 247, 247, 248, 249, 249, 250, 251, 251, 252, 253, 254, 254, 255 };
for (int i = 0; i < 256; i++){ for (int i = 0; i < 256; i++){
arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]); arrayOfByte[(i * 4)] = ((byte)arrayOfInt1[i]);
arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]); arrayOfByte[(1 + i * 4)] = ((byte)arrayOfInt2[i]);
arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]); arrayOfByte[(2 + i * 4)] = ((byte)arrayOfInt3[i]);
arrayOfByte[(3 + i * 4)] = -1; arrayOfByte[(3 + i * 4)] = -1;
} }
int[] arrayOfInt4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 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, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 224, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255 }; int[] arrayOfInt4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 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, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 123, 124, 125, 126, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 164, 165, 166, 167, 168, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 200, 201, 202, 203, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 224, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 255, 255, 255, 255, 255 };
int[] arrayOfInt5 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 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, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 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, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 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, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 229, 230, 231, 232, 233, 233, 234, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 250, 251, 252, 252, 253, 253, 254, 254, 255 }; int[] arrayOfInt5 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 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, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 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, 133, 135, 136, 137, 138, 139, 140, 141, 142, 143, 145, 146, 147, 148, 149, 150, 151, 152, 154, 155, 156, 157, 158, 159, 160, 161, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 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, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 223, 224, 225, 226, 227, 228, 229, 229, 230, 231, 232, 233, 233, 234, 235, 236, 237, 237, 238, 239, 240, 240, 241, 242, 243, 243, 244, 245, 245, 246, 247, 247, 248, 249, 249, 250, 250, 251, 252, 252, 253, 253, 254, 254, 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 }; 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++){ for (int j = 0; j < 256; j++){
arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]); arrayOfByte[(1024 + j * 4)] = ((byte)arrayOfInt5[j]);
arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt4[j]); arrayOfByte[(1 + (1024 + j * 4))] = ((byte)arrayOfInt4[j]);
arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]); arrayOfByte[(2 + (1024 + j * 4))] = ((byte)arrayOfInt6[j]);
arrayOfByte[(3 + (1024 + j * 4))] = -1; 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)); GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte));
} }
}); });
} }
} }

@ -63,7 +63,7 @@ public class MagicFreudFilter extends GPUImageFilter {
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/freud_rand.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/freud_rand.png");
} }
}); });
} }

@ -99,7 +99,7 @@ public class MagicHealthyFilter extends GPUImageFilter{
arrayOfByte[(3 + i * 4)] = -1; 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)); 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"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/healthy_mask_1.jpg");
} }
}); });
} }

@ -60,10 +60,10 @@ public class MagicHefeFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/edgeburn.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/edgeburn.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefemap.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/hefemap.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefemetal.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/hefemetal.png");
inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hefesoftlight.png"); inputTextureHandles[3] = OpenGLUtils.loadTexture(getContext(), "filter/hefesoftlight.png");
} }
}); });
} }

@ -61,9 +61,9 @@ public class MagicHudsonFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/ohudsonbackground.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/ohudsonbackground.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/overlaymap.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/hudsonmap.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/hudsonmap.png");
} }
}); });
} }

@ -61,7 +61,7 @@ public class MagicInkwellFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/inkwellmap.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/inkwellmap.png");
} }
}); });
} }

@ -60,7 +60,7 @@ public class MagicKevinFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/kelvinmap.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/kelvinmap.png");
} }
}); });
} }

@ -61,8 +61,8 @@ public class MagicLomoFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vlomomap_new.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/vlomomap_new.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/vignette_map.png");
} }
}); });
} }

@ -53,8 +53,8 @@ public class MagicN1977Filter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/n1977map.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/n1977map.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/n1977blowout.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/n1977blowout.png");
} }
}); });
} }

@ -60,7 +60,7 @@ public class MagicNashvilleFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/nashvillemap.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/nashvillemap.png");
} }
}); });
} }

@ -60,7 +60,7 @@ public class MagicPixarFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/pixar_curves.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/pixar_curves.png");
} }
}); });
} }

@ -58,9 +58,9 @@ public class MagicRiseFilter extends GPUImageFilter{
super.onInitialized(); super.onInitialized();
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/blackboard1024.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/blackboard1024.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/overlaymap.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/risemap.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/risemap.png");
} }
}); });
} }

@ -60,9 +60,9 @@ public class MagicSierraFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sierravignette.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/sierravignette.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/overlaymap.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/overlaymap.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sierramap.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/sierramap.png");
} }
}); });
} }

@ -134,11 +134,11 @@ public class MagicSunriseFilter extends GPUImageFilter{
} }
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, 256, 2, 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ByteBuffer.wrap(arrayOfByte)); 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); GLES20.glActiveTexture(GLES20.GL_TEXTURE4);
mMaskGrey1TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaro_mask1.jpg"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/amaro_mask1.jpg");
GLES20.glActiveTexture(GLES20.GL_TEXTURE5); GLES20.glActiveTexture(GLES20.GL_TEXTURE5);
mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/amaro_mask2.jpg"); mMaskGrey2TextureId = OpenGLUtils.loadTexture(getContext(), "filter/amaro_mask2.jpg");
GLES20.glActiveTexture(GLES20.GL_TEXTURE6); GLES20.glActiveTexture(GLES20.GL_TEXTURE6);
mMaskGrey3TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toy_mask1.jpg"); mMaskGrey3TextureId = OpenGLUtils.loadTexture(getContext(), "filter/toy_mask1.jpg");
} }
}); });
} }

@ -114,8 +114,8 @@ public class MagicSunsetFilter extends GPUImageFilter{
arrayOfByte[(3 + (1024 + j * 4))] = -1; 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)); 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"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/rise_mask1.jpg");
mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/rise_mask2.jpg"); mMaskGrey2TextureId = OpenGLUtils.loadTexture(getContext(), "filter/rise_mask2.jpg");
} }
}); });
} }

@ -59,11 +59,11 @@ public class MagicSutroFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/vignette_map.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutrometal.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/sutrometal.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/softlight.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/softlight.png");
inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutroedgeburn.png"); inputTextureHandles[3] = OpenGLUtils.loadTexture(getContext(), "filter/sutroedgeburn.png");
inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/sutrocurves.png"); inputTextureHandles[4] = OpenGLUtils.loadTexture(getContext(), "filter/sutrocurves.png");
} }
}); });
} }

@ -91,7 +91,7 @@ public class MagicSweetsFilter extends GPUImageFilter{
arrayOfByte[(3 + i * 4)] = ((byte)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)); 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"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/rise_mask2.jpg");
} }
}); });
} }

@ -91,7 +91,7 @@ public class MagicTenderFilter extends GPUImageFilter{
arrayOfByte[(3 + i * 4)] = ((byte)arrayOfInt4[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)); 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"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/bluevintage_mask1.jpg");
} }
}); });
} }

@ -61,11 +61,11 @@ public class MagicToasterFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastermetal.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/toastermetal.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastersoftlight.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/toastersoftlight.png");
inputTextureHandles[2] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastercurves.png"); inputTextureHandles[2] = OpenGLUtils.loadTexture(getContext(), "filter/toastercurves.png");
inputTextureHandles[3] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toasteroverlaymapwarm.png"); inputTextureHandles[3] = OpenGLUtils.loadTexture(getContext(), "filter/toasteroverlaymapwarm.png");
inputTextureHandles[4] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/toastercolorshift.png"); inputTextureHandles[4] = OpenGLUtils.loadTexture(getContext(), "filter/toastercolorshift.png");
} }
}); });
} }

@ -62,8 +62,8 @@ public class MagicValenciaFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/valenciamap.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/valenciamap.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/valenciagradientmap.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/valenciagradientmap.png");
} }
}); });
} }

@ -60,8 +60,8 @@ public class MagicWaldenFilter extends GPUImageFilter {
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/walden_map.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/walden_map.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignette_map.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/vignette_map.png");
} }
}); });
} }

@ -115,8 +115,8 @@ public class MagicWarmFilter extends GPUImageFilter{
arrayOfByte[(3 + (1024 + j * 4))] = ((byte)arrayOfInt8[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.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"); mMaskGrey1TextureId = OpenGLUtils.loadTexture(getContext(), "filter/warm_layer1.jpg");
mMaskGrey2TextureId = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/bluevintage_mask1.jpg"); mMaskGrey2TextureId = OpenGLUtils.loadTexture(getContext(), "filter/bluevintage_mask1.jpg");
} }
}); });
} }

@ -60,8 +60,8 @@ public class MagicXproIIFilter extends GPUImageFilter{
setFloat(mGLStrengthLocation, 1.0f); setFloat(mGLStrengthLocation, 1.0f);
runOnDraw(new Runnable(){ runOnDraw(new Runnable(){
public void run(){ public void run(){
inputTextureHandles[0] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/xpromap.png"); inputTextureHandles[0] = OpenGLUtils.loadTexture(getContext(), "filter/xpromap.png");
inputTextureHandles[1] = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), "filter/vignettemap_new.png"); inputTextureHandles[1] = OpenGLUtils.loadTexture(getContext(), "filter/vignettemap_new.png");
} }
}); });
} }

@ -7,6 +7,7 @@ import java.util.List;
import com.seu.magicfilter.base.gpuimage.GPUImageFilter; import com.seu.magicfilter.base.gpuimage.GPUImageFilter;
import com.seu.magicfilter.utils.OpenGLUtils; import com.seu.magicfilter.utils.OpenGLUtils;
import android.content.Context;
import android.opengl.GLES20; import android.opengl.GLES20;
@ -30,9 +31,9 @@ public class MagicBaseGroupFilter extends GPUImageFilter {
} }
@Override @Override
public void init() { public void init(Context context) {
for (GPUImageFilter filter : filters) { for (GPUImageFilter filter : filters) {
filter.init(); filter.init(context);
} }
} }

@ -30,7 +30,7 @@ public class MagicLookupFilter extends GPUImageFilter {
super.onInitialized(); super.onInitialized();
runOnDraw(new Runnable() { runOnDraw(new Runnable() {
public void run() { public void run() {
mLookupSourceTexture = OpenGLUtils.loadTexture(MagicFilterFactory.getCurrentContext(), table); mLookupSourceTexture = OpenGLUtils.loadTexture(getContext(), table);
} }
}); });
} }

@ -16,6 +16,7 @@
package com.seu.magicfilter.base.gpuimage; package com.seu.magicfilter.base.gpuimage;
import android.content.Context;
import android.graphics.PointF; import android.graphics.PointF;
import android.opengl.GLES11Ext; import android.opengl.GLES11Ext;
import android.opengl.GLES20; import android.opengl.GLES20;
@ -36,10 +37,11 @@ import java.util.LinkedList;
public class GPUImageFilter { public class GPUImageFilter {
private boolean mIsInitialized; private boolean mIsInitialized;
private Context mContext;
private MagicFilterType mType = MagicFilterType.NONE; private MagicFilterType mType = MagicFilterType.NONE;
private final LinkedList<Runnable> mRunOnDraw; private final LinkedList<Runnable> mRunOnDraw;
private final String mVertexShader; private final int mVertexShaderId;
private final String mFragmentShader; private final int mFragmentShaderId;
private int mGLProgId; private int mGLProgId;
private int mGLPositionIndex; private int mGLPositionIndex;
@ -82,8 +84,8 @@ public class GPUImageFilter {
public GPUImageFilter(MagicFilterType type, int vertexShaderId, int fragmentShaderId) { public GPUImageFilter(MagicFilterType type, int vertexShaderId, int fragmentShaderId) {
mType = type; mType = type;
mRunOnDraw = new LinkedList<>(); mRunOnDraw = new LinkedList<>();
mVertexShader = OpenGLUtils.readShaderFromRawResource(vertexShaderId); mVertexShaderId = vertexShaderId;
mFragmentShader = OpenGLUtils.readShaderFromRawResource(fragmentShaderId); mFragmentShaderId = fragmentShaderId;
mGLCubeBuffer = ByteBuffer.allocateDirect(TextureRotationUtil.CUBE.length * 4) mGLCubeBuffer = ByteBuffer.allocateDirect(TextureRotationUtil.CUBE.length * 4)
.order(ByteOrder.nativeOrder()) .order(ByteOrder.nativeOrder())
@ -96,7 +98,8 @@ public class GPUImageFilter {
mGLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.NORMAL, false, true)).position(0); mGLTextureBuffer.put(TextureRotationUtil.getRotation(Rotation.NORMAL, false, true)).position(0);
} }
public void init() { public void init(Context context) {
mContext = context;
onInit(); onInit();
onInitialized(); onInitialized();
} }
@ -135,7 +138,8 @@ public class GPUImageFilter {
} }
private void loadExternalSamplerShader() { private void loadExternalSamplerShader() {
mGLProgId = OpenGLUtils.loadProgram(mVertexShader, mFragmentShader); mGLProgId = OpenGLUtils.loadProgram(OpenGLUtils.readShaderFromRawResource(getContext(), mVertexShaderId),
OpenGLUtils.readShaderFromRawResource(getContext(), mFragmentShaderId));
mGLPositionIndex = GLES20.glGetAttribLocation(mGLProgId, "position"); mGLPositionIndex = GLES20.glGetAttribLocation(mGLProgId, "position");
mGLTextureCoordinateIndex = GLES20.glGetAttribLocation(mGLProgId,"inputTextureCoordinate"); mGLTextureCoordinateIndex = GLES20.glGetAttribLocation(mGLProgId,"inputTextureCoordinate");
mGLTextureTransformIndex = GLES20.glGetUniformLocation(mGLProgId, "textureTransform"); mGLTextureTransformIndex = GLES20.glGetUniformLocation(mGLProgId, "textureTransform");
@ -143,8 +147,8 @@ public class GPUImageFilter {
} }
private void loadInternalSamplerShader() { private void loadInternalSamplerShader() {
mGLScreenProgId = OpenGLUtils.loadProgram(OpenGLUtils.readShaderFromRawResource(R.raw.vertex_default), mGLScreenProgId = OpenGLUtils.loadProgram(OpenGLUtils.readShaderFromRawResource(getContext(), R.raw.vertex_default),
OpenGLUtils.readShaderFromRawResource(R.raw.fragment_default)); OpenGLUtils.readShaderFromRawResource(getContext(), R.raw.fragment_default));
mGLScreenPositionIndex = GLES20.glGetAttribLocation(mGLScreenProgId, "position"); mGLScreenPositionIndex = GLES20.glGetAttribLocation(mGLScreenProgId, "position");
mGLScreenTextureCoordinateIndex = GLES20.glGetAttribLocation(mGLScreenProgId,"inputTextureCoordinate"); mGLScreenTextureCoordinateIndex = GLES20.glGetAttribLocation(mGLScreenProgId,"inputTextureCoordinate");
mGLScreenInputImageTextureIndex = GLES20.glGetUniformLocation(mGLScreenProgId, "inputImageTexture"); mGLScreenInputImageTextureIndex = GLES20.glGetUniformLocation(mGLScreenProgId, "inputImageTexture");
@ -336,11 +340,7 @@ public class GPUImageFilter {
mRunOnDraw.removeFirst().run(); mRunOnDraw.removeFirst().run();
} }
} }
public MagicFilterType getFilterType() {
return mType;
}
public int getProgram() { public int getProgram() {
return mGLProgId; return mGLProgId;
} }
@ -349,6 +349,14 @@ public class GPUImageFilter {
return mGLFboBuffer; return mGLFboBuffer;
} }
protected Context getContext() {
return mContext;
}
protected MagicFilterType getFilterType() {
return mType;
}
public void setTextureTransformMatrix(float[] mtx){ public void setTextureTransformMatrix(float[] mtx){
mGLTextureTransformMatrix = mtx; mGLTextureTransformMatrix = mtx;
} }

@ -54,122 +54,112 @@ import com.seu.magicfilter.base.gpuimage.GPUImageSaturationFilter;
import com.seu.magicfilter.base.gpuimage.GPUImageSharpenFilter; import com.seu.magicfilter.base.gpuimage.GPUImageSharpenFilter;
public class MagicFilterFactory{ public class MagicFilterFactory{
private static Context mContext;
public static void initContext(Context context) { public static GPUImageFilter initFilters(MagicFilterType type) {
mContext = context; switch (type) {
} case NONE:
return new GPUImageFilter();
public static GPUImageFilter initFilters(MagicFilterType type) { case WHITECAT:
switch (type) { return new MagicWhiteCatFilter();
case NONE: case BLACKCAT:
return new GPUImageFilter(); return new MagicBlackCatFilter();
case WHITECAT: case SKINWHITEN:
return new MagicWhiteCatFilter(); return new MagicSkinWhitenFilter();
case BLACKCAT: case BEAUTY:
return new MagicBlackCatFilter(); return new MagicBeautyFilter();
case SKINWHITEN: case ROMANCE:
return new MagicSkinWhitenFilter(); return new MagicRomanceFilter();
case BEAUTY: case SAKURA:
return new MagicBeautyFilter(); return new MagicSakuraFilter();
case ROMANCE: case AMARO:
return new MagicRomanceFilter(); return new MagicAmaroFilter();
case SAKURA: case WALDEN:
return new MagicSakuraFilter(); return new MagicWaldenFilter();
case AMARO: case ANTIQUE:
return new MagicAmaroFilter(); return new MagicAntiqueFilter();
case WALDEN: case CALM:
return new MagicWaldenFilter(); return new MagicCalmFilter();
case ANTIQUE: case BRANNAN:
return new MagicAntiqueFilter(); return new MagicBrannanFilter();
case CALM: case BROOKLYN:
return new MagicCalmFilter(); return new MagicBrooklynFilter();
case BRANNAN: case EARLYBIRD:
return new MagicBrannanFilter(); return new MagicEarlyBirdFilter();
case BROOKLYN: case FREUD:
return new MagicBrooklynFilter(); return new MagicFreudFilter();
case EARLYBIRD: case HEFE:
return new MagicEarlyBirdFilter(); return new MagicHefeFilter();
case FREUD: case HUDSON:
return new MagicFreudFilter(); return new MagicHudsonFilter();
case HEFE: case INKWELL:
return new MagicHefeFilter(); return new MagicInkwellFilter();
case HUDSON: case KEVIN:
return new MagicHudsonFilter(); return new MagicKevinFilter();
case INKWELL: case LOCKUP:
return new MagicInkwellFilter(); return new MagicLookupFilter("");
case KEVIN: case LOMO:
return new MagicKevinFilter(); return new MagicLomoFilter();
case LOCKUP: case N1977:
return new MagicLookupFilter(""); return new MagicN1977Filter();
case LOMO: case NASHVILLE:
return new MagicLomoFilter(); return new MagicNashvilleFilter();
case N1977: case PIXAR:
return new MagicN1977Filter(); return new MagicPixarFilter();
case NASHVILLE: case RISE:
return new MagicNashvilleFilter(); return new MagicRiseFilter();
case PIXAR: case SIERRA:
return new MagicPixarFilter(); return new MagicSierraFilter();
case RISE: case SUTRO:
return new MagicRiseFilter(); return new MagicSutroFilter();
case SIERRA: case TOASTER2:
return new MagicSierraFilter(); return new MagicToasterFilter();
case SUTRO: case VALENCIA:
return new MagicSutroFilter(); return new MagicValenciaFilter();
case TOASTER2: case XPROII:
return new MagicToasterFilter(); return new MagicXproIIFilter();
case VALENCIA: case EVERGREEN:
return new MagicValenciaFilter(); return new MagicEvergreenFilter();
case XPROII: case HEALTHY:
return new MagicXproIIFilter(); return new MagicHealthyFilter();
case EVERGREEN: case COOL:
return new MagicEvergreenFilter(); return new MagicCoolFilter();
case HEALTHY: case EMERALD:
return new MagicHealthyFilter(); return new MagicEmeraldFilter();
case COOL: case LATTE:
return new MagicCoolFilter(); return new MagicLatteFilter();
case EMERALD: case WARM:
return new MagicEmeraldFilter(); return new MagicWarmFilter();
case LATTE: case TENDER:
return new MagicLatteFilter(); return new MagicTenderFilter();
case WARM: case SWEETS:
return new MagicWarmFilter(); return new MagicSweetsFilter();
case TENDER: case NOSTALGIA:
return new MagicTenderFilter(); return new MagicNostalgiaFilter();
case SWEETS: case SUNRISE:
return new MagicSweetsFilter(); return new MagicSunriseFilter();
case NOSTALGIA: case SUNSET:
return new MagicNostalgiaFilter(); return new MagicSunsetFilter();
case SUNRISE: case CRAYON:
return new MagicSunriseFilter(); return new MagicCrayonFilter();
case SUNSET: case SKETCH:
return new MagicSunsetFilter(); return new MagicSketchFilter();
case CRAYON: //image adjust
return new MagicCrayonFilter(); case BRIGHTNESS:
case SKETCH: return new GPUImageBrightnessFilter();
return new MagicSketchFilter(); case CONTRAST:
//image adjust return new GPUImageContrastFilter();
case BRIGHTNESS: case EXPOSURE:
return new GPUImageBrightnessFilter(); return new GPUImageExposureFilter();
case CONTRAST: case HUE:
return new GPUImageContrastFilter(); return new GPUImageHueFilter();
case EXPOSURE: case SATURATION:
return new GPUImageExposureFilter(); return new GPUImageSaturationFilter();
case HUE: case SHARPEN:
return new GPUImageHueFilter(); return new GPUImageSharpenFilter();
case SATURATION: case IMAGE_ADJUST:
return new GPUImageSaturationFilter(); return new MagicImageAdjustFilter();
case SHARPEN: default:
return new GPUImageSharpenFilter(); return null;
case IMAGE_ADJUST: }
return new MagicImageAdjustFilter(); }
default:
return null;
}
}
public static Context getCurrentContext(){
return mContext;
}
} }

@ -22,11 +22,11 @@ public class OpenGLUtils {
public static final int NOT_INIT = -1; public static final int NOT_INIT = -1;
public static final int ON_DRAWN = 1; public static final int ON_DRAWN = 1;
public static int loadTexture(final Bitmap img, final int usedTexId) { public static int loadTexture(Bitmap img, int usedTexId) {
return loadTexture(img, usedTexId, false); return loadTexture(img, usedTexId, false);
} }
public static int loadTexture(final Bitmap img, final int usedTexId, boolean recyled) { public static int loadTexture(Bitmap img, int usedTexId, boolean recyled) {
if(img == null) if(img == null)
return NO_TEXTURE; return NO_TEXTURE;
int textures[] = new int[1]; int textures[] = new int[1];
@ -53,7 +53,7 @@ public class OpenGLUtils {
return textures[0]; return textures[0];
} }
public static int loadTexture(final Buffer data, final int width,final int height, final int usedTexId) { public static int loadTexture(Buffer data, int width, int height, int usedTexId) {
if(data == null) if(data == null)
return NO_TEXTURE; return NO_TEXTURE;
int textures[] = new int[1]; int textures[] = new int[1];
@ -79,7 +79,7 @@ public class OpenGLUtils {
return textures[0]; return textures[0];
} }
public static int loadTexture(final Buffer data, final int width,final int height, final int usedTexId,final int type) { public static int loadTexture(Buffer data, int width, int height, int usedTexId, int type) {
if(data == null) if(data == null)
return NO_TEXTURE; return NO_TEXTURE;
int textures[] = new int[1]; int textures[] = new int[1];
@ -150,7 +150,7 @@ public class OpenGLUtils {
return image; return image;
} }
public static int loadProgram(final String strVSource, final String strFSource) { public static int loadProgram(String strVSource, String strFSource) {
int iVShader; int iVShader;
int iFShader; int iFShader;
int iProgId; int iProgId;
@ -180,7 +180,7 @@ public class OpenGLUtils {
return iProgId; return iProgId;
} }
private static int loadShader(final String strSource, final int iType) { private static int loadShader(String strSource, int iType) {
int[] compiled = new int[1]; int[] compiled = new int[1];
int iShader = GLES20.glCreateShader(iType); int iShader = GLES20.glCreateShader(iType);
GLES20.glShaderSource(iShader, strSource); GLES20.glShaderSource(iShader, strSource);
@ -208,8 +208,8 @@ public class OpenGLUtils {
return texture[0]; return texture[0];
} }
public static String readShaderFromRawResource(final int resourceId){ public static String readShaderFromRawResource(Context context, int resourceId){
final InputStream inputStream = MagicFilterFactory.getCurrentContext().getResources().openRawResource(resourceId); final InputStream inputStream = context.getResources().openRawResource(resourceId);
final InputStreamReader inputStreamReader = new InputStreamReader(inputStream); final InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
final BufferedReader bufferedReader = new BufferedReader(inputStreamReader); final BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
@ -227,15 +227,4 @@ public class OpenGLUtils {
} }
return body.toString(); return body.toString();
} }
/**
* Checks to see if a GLES error has been raised.
*/
public static void checkGlError(String op) {
int error = GLES20.glGetError();
if (error != GLES20.GL_NO_ERROR) {
String msg = op + ": glError 0x" + Integer.toHexString(error);
Log.e("OpenGlUtils", msg);
}
}
} }

@ -32,7 +32,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
private GPUImageFilter magicFilter; private GPUImageFilter magicFilter;
private SurfaceTexture surfaceTexture; private SurfaceTexture surfaceTexture;
private int mOESTextureId = OpenGLUtils.NO_TEXTURE; private int mOESTextureId = OpenGLUtils.NO_TEXTURE;
private int mSurfaceWidth; private int mSurfaceWidth;
private int mSurfaceHeight; private int mSurfaceHeight;
@ -64,8 +64,6 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
setEGLContextClientVersion(2); setEGLContextClientVersion(2);
setRenderer(this); setRenderer(this);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY); setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
MagicFilterFactory.initContext(context.getApplicationContext());
} }
@Override @Override
@ -74,7 +72,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
GLES20.glClearColor(0, 0, 0, 0); GLES20.glClearColor(0, 0, 0, 0);
magicFilter = new GPUImageFilter(MagicFilterType.NONE); magicFilter = new GPUImageFilter(MagicFilterType.NONE);
magicFilter.init(); magicFilter.init(getContext().getApplicationContext());
magicFilter.onInputSizeChanged(mPreviewWidth, mPreviewHeight); magicFilter.onInputSizeChanged(mPreviewWidth, mPreviewHeight);
mOESTextureId = OpenGLUtils.getExternalOESTextureID(); mOESTextureId = OpenGLUtils.getExternalOESTextureID();
@ -137,7 +135,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
public void setPreviewResolution(int width, int height) { public void setPreviewResolution(int width, int height) {
mPreviewWidth = width; mPreviewWidth = width;
mPreviewHeight = height; mPreviewHeight = height;
mGlPreviewBuffer = ByteBuffer.allocate(mPreviewWidth * mPreviewHeight * 4); mGlPreviewBuffer = ByteBuffer.allocate(width * height * 4);
mInputAspectRatio = width > height ? (float) width / height : (float) height / width; mInputAspectRatio = width > height ? (float) width / height : (float) height / width;
} }
@ -154,7 +152,7 @@ public class SrsCameraView extends GLSurfaceView implements GLSurfaceView.Render
} }
magicFilter = MagicFilterFactory.initFilters(type); magicFilter = MagicFilterFactory.initFilters(type);
if (magicFilter != null) { if (magicFilter != null) {
magicFilter.init(); magicFilter.init(getContext().getApplicationContext());
magicFilter.onInputSizeChanged(mPreviewWidth, mPreviewHeight); magicFilter.onInputSizeChanged(mPreviewWidth, mPreviewHeight);
magicFilter.onDisplaySizeChanged(mSurfaceWidth, mSurfaceHeight); magicFilter.onDisplaySizeChanged(mSurfaceWidth, mSurfaceHeight);
} }

Loading…
Cancel
Save