Prevent context leak for magic filter

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

@ -59,9 +59,9 @@ public class MagicAmaroFilter 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_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");
} }
}); });
} }

@ -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");
} }
}); });
} }

@ -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");
} }
}); });
} }

@ -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");
@ -337,10 +341,6 @@ public class GPUImageFilter {
} }
} }
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;
} }

@ -55,12 +55,6 @@ import com.seu.magicfilter.base.gpuimage.GPUImageSharpenFilter;
public class MagicFilterFactory{ public class MagicFilterFactory{
private static Context mContext;
public static void initContext(Context context) {
mContext = context;
}
public static GPUImageFilter initFilters(MagicFilterType type) { public static GPUImageFilter initFilters(MagicFilterType type) {
switch (type) { switch (type) {
case NONE: case NONE:
@ -168,8 +162,4 @@ public class MagicFilterFactory{
return null; 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);
}
}
} }

@ -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