我正在开发应用程序,我想在 Seekbar 的进度更改时为我的 GLsurfaceView 提供亮度。进度发生了变化,但不能影响 GLsurfaceView 意味着我不能增加或减少亮度,即使颜色也没有应用于 GLSurfaceview。我已经尝试过了。但什么也没有发生。适合您的帮助 提前致谢!!
我的代码在这里:
EffectActivity.java:
public class EffectsActivity extends FragmentActivity implements
OnTouchListener, OnClickListener, OnSeekBarChangeListener, Renderer {
QuickAction quickAction;
SeekBar progress_seekbar;
String pos, mine;
private FilterAdjuster mFilterAdjuster;
private Matrix matrix = new Matrix();
private Matrix savedMatrix = new Matrix();
private static final int NONE = 0;
private static final int DRAG = 1;
private static final int ZOOM = 2;
private int mode = NONE;
private PointF start = new PointF();
private PointF mid = new PointF();
private float oldDist = 1f;
private float d = 0f;
private float newRot = 0f;
private float[] lastEvent = null;
int count = 0;
Button btnSave, btnEffects, btnWallpaper;
ImageFilters imgFilter;
ProgressDialog pDialog, pd;
Bitmap myBmp, bmp;
MainLayout mainLayout;
FrameLayout fm;
ConnectionDetector cd;
private static ListView lvMenu;
Button btMenu, btnseting;
TextView tvTitle;
ImageView iv;
private static final int ID_SAVE = 1;
private static final int ID_WALLPAPER = 2;
private static final int ID_RATE = 3;
LinearLayout l1, l2, l3, main;
ArrayList<String> mList;
private GLSurfaceView mEffectView;
private int[] mTextures = new int[2];
private EffectContext mEffectContext;
private Effect mEffect;
private TextureRenderer mTexRenderer = new TextureRenderer();
private int mImageWidth;
private int mImageHeight;
private boolean mInitialized = false;
int mCurrentEffect;
private volatile boolean saveFrame;
ArrayList<Bitmap> bimList;
SharedPreferences.Editor editor;
public void setCurrentEffect(int effect) {
mCurrentEffect = effect;
}
Handler h = new Handler() {
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
Toast.makeText(EffectsActivity.this,
"Wallpaper set. Your Image saved.", Toast.LENGTH_LONG)
.show();
SharedPreferences spdata = getSharedPreferences("Image", 0);
String image = spdata.getString("imageshare", "");
Uri uri = Uri.parse(image);
ShareAlertDialog(uri);
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
mainLayout = (MainLayout) this.getLayoutInflater().inflate(
R.layout.myfile, null);
setContentView(mainLayout);
mEffectView = (GLSurfaceView) findViewById(R.id.effectsview);
iv = (ImageView) findViewById(R.id.image);
mEffectView.setEGLContextClientVersion(2);
mEffectView.setRenderer(this);
mEffectView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
mCurrentEffect = 0;
mList = new ArrayList<String>();
bimList = new ArrayList<Bitmap>();
cd = new ConnectionDetector(EffectsActivity.this);
findIDforXML();
Intent n = getIntent();
pos = n.getStringExtra("position");
Log.v("My Position", pos);
if (cd.isConnectingToInternet()) {
GetXMLTask task = new GetXMLTask();
task.execute(pos);
} else {
Toast.makeText(
EffectsActivity.this,
"No Internet Connection available. Please try again later or reconnect to it.",
Toast.LENGTH_SHORT).show();
}
showQucickAction();
showEffectsList();
lvMenu.setAdapter(new ArrayAdapter<String>(this,
R.layout.custom_row_item, R.id.title, mList));
lvMenu.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
setCurrentEffect(position);
mEffectView.requestRender();
mainLayout.toggleMenu();
}
});
}
public void toggleMenu(View v) {
mainLayout.toggleMenu();
}
public void findIDforXML() {
lvMenu = (ListView) findViewById(R.id.activity_main_menu_listview);
tvTitle = (TextView) findViewById(R.id.activity_main_content_title);
progress_seekbar = (SeekBar) findViewById(R.id.seekBar);
progress_seekbar.setOnSeekBarChangeListener(this);
btMenu = (Button) findViewById(R.id.activity_main_content_button_menu);
fm = (FrameLayout) findViewById(R.id.activity_main_content_fragment);
btnseting = (Button) findViewById(R.id.btnsetting);
l1 = (LinearLayout) findViewById(R.id.l1);
l2 = (LinearLayout) findViewById(R.id.l2);
l3 = (LinearLayout) findViewById(R.id.l3);
main = (LinearLayout) findViewById(R.id.main);
// btnseting.setOnClickListener(this);
btMenu.setOnClickListener(this);
}
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// switch (v.getId()) {
switch (v.getId()) {
case R.id.activity_main_content_button_menu:
toggleMenu(v);
break;
case R.id.btnsetting:
// quickAction.show(v);
break;
default:
break;
}
}
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress,
final boolean fromUser) {
if (mFilterAdjuster != null) {
mFilterAdjuster.adjust(progress);
}
mEffectView.requestRender();
}
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
}
private class GetXMLTask extends AsyncTask<String, Void, Bitmap> {
@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
pDialog = new ProgressDialog(EffectsActivity.this);
pDialog.setTitle("Please Wait.");
pDialog.setMessage("Displaying Image");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected Bitmap doInBackground(String... urls) {
Bitmap map = null;
for (String url : urls) {
Log.v("URL", url);
map = downloadImage(url);
mine = encodeTobase64(map);
}
return map;
}
// Sets the Bitmap returned by doInBackground
@Override
protected void onPostExecute(Bitmap result) {
// myBmp = result;
// mGPUImageView.setImage(myBmp);
pDialog.dismiss();
SharedPreferences sp = getSharedPreferences("Bitmap", 0);
editor = sp.edit();
editor.putString("imagePreferance", mine);
editor.commit();
}
// Creates Bitmap from InputStream and returns it
private Bitmap downloadImage(String url) {
Bitmap bitmap = null;
InputStream stream = null;
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
try {
stream = getHttpConnection(url);
Log.v("MyUrl", url);
bitmap = BitmapFactory.decodeStream(stream, null, bmOptions);
stream.close();
} catch (IOException e1) {
e1.printStackTrace();
}
return bitmap;
}
// Makes HttpURLConnection and returns InputStream
private InputStream getHttpConnection(String urlString)
throws IOException {
InputStream stream = null;
URL url = new URL(urlString);
URLConnection connection = url.openConnection();
try {
HttpURLConnection httpConnection = (HttpURLConnection) connection;
httpConnection.setRequestMethod("GET");
httpConnection.connect();
if (httpConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
stream = httpConnection.getInputStream();
}
} catch (Exception ex) {
ex.printStackTrace();
}
return stream;
}
}
public static Bitmap decodeBase64(String input) {
byte[] decodedByte = Base64.decode(input, 0);
return BitmapFactory
.decodeByteArray(decodedByte, 0, decodedByte.length);
}
public void saveBitmap(Bitmap bitmap) {
File imagePath = new File(Environment.getExternalStorageDirectory()
+ "/screenshot.png");
FileOutputStream fos;
try {
fos = new FileOutputStream(imagePath);
bitmap.compress(CompressFormat.JPEG, 100, fos);
fos.flush();
fos.close();
} catch (FileNotFoundException e) {
Log.e("GREC", e.getMessage(), e);
} catch (IOException e) {
Log.e("GREC", e.getMessage(), e);
}
}
public void showEffectsList() {
mList.add("None");
mList.add("Autofix");
mList.add("Bw");
mList.add("Brightness");
mList.add("Contrast");
mList.add("Crossprocess");
mList.add("Documentary");
mList.add("Duotone");
mList.add("Filllight");
mList.add("Fisheye");
mList.add("Fliphor");
mList.add("flipvert");
mList.add("Grain");
mList.add("Grayscale");
mList.add("Lomoish");
mList.add("Negative");
mList.add("Posterize");
mList.add("Rotate");
mList.add("Saturate");
mList.add("Sepia");
mList.add("Sharpen");
mList.add("Temperature");
mList.add("Tint");
mList.add("Vignette");
}
private void loadTextures() {
// Generate textures
GLES20.glGenTextures(2, mTextures, 0);
SharedPreferences sp = getSharedPreferences("Bitmap", 0);
String bmpValue = sp.getString("imagePreferance", "");
Bitmap bitmapObject = decodeBase64(bmpValue);
if (bitmapObject != null) {
mImageWidth = bitmapObject.getWidth();
mImageHeight = bitmapObject.getHeight();
mTexRenderer.updateTextureSize(mImageWidth, mImageHeight);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]);
GLUtils.texImage2D(GLES20.GL_TEXTURE_2D, 0, bitmapObject, 0);
GLToolbox.initTexParams();
}
}
@Override
public void onDrawFrame(GL10 gl) {
// TODO Auto-generated method stub
mInitialized = false;
if (!mInitialized) {
// Only need to do this once
mEffectContext = EffectContext.createWithCurrentGlContext();
mTexRenderer.init();
loadTextures();
mEffectView.requestRender();
mInitialized = true;
}
if (mCurrentEffect != 0) {
// if an effect is chosen initialize it and apply it to the texture
initEffect();
applyEffect();
}
renderResult();
if (saveFrame) {
final Bitmap mp = takeScreenshot(gl);
saveBitmap(mp);
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
final int height = metrics.heightPixels;
final int width = metrics.widthPixels;
final WallpaperManager wallpaperManager = WallpaperManager
.getInstance(EffectsActivity.this);
new Thread(new Runnable() {
public void run() {
// // method stub
try {
try {
Thread.sleep(1000);
Looper.prepare();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
wallpaperManager.setBitmap(mp);
wallpaperManager
.suggestDesiredDimensions(width, height);
h.sendEmptyMessage(0);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();
String path = Images.Media.insertImage(getContentResolver(), mp,
"MyImage", null);
SharedPreferences spdata = getSharedPreferences("Image", 0);
SharedPreferences.Editor edt = spdata.edit();
edt.putString("imageshare", path);
edt.commit();
saveFrame = false;
}
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
// TODO Auto-generated method stub
Log.e("SurfaceView ", "Changed");
if (mTexRenderer != null) {
mTexRenderer.updateViewSize(width, height);
mInitialized = false;
}
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// TODO Auto-generated method stub
Log.e("SurfaceView ", "Created");
}
private void initEffect() {
EffectFactory effectFactory = mEffectContext.getFactory();
if (mEffect != null) {
mEffect.release();
}
/**
* Initialize the correct effect based on the selected menu/action item
*/
switch (mCurrentEffect) {
case 0:
break;
case 1:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_AUTOFIX);
mEffect.setParameter("scale", 0.5f);
break;
case 2:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_BLACKWHITE);
mEffect.setParameter("black", .1f);
mEffect.setParameter("white", .7f);
break;
case 3:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_BRIGHTNESS);
mEffect.setParameter("brightness", 2.0f);
break;
case 4:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_CONTRAST);
mEffect.setParameter("contrast", 1.4f);
break;
case 5:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_CROSSPROCESS);
break;
case 6:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_DOCUMENTARY);
break;
case 7:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_DUOTONE);
mEffect.setParameter("first_color", Color.YELLOW);
mEffect.setParameter("second_color", Color.DKGRAY);
break;
case 8:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_FILLLIGHT);
mEffect.setParameter("strength", .8f);
break;
case 9:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FISHEYE);
mEffect.setParameter("scale", .5f);
break;
case 10:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
mEffect.setParameter("vertical", true);
break;
case 11:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_FLIP);
mEffect.setParameter("horizontal", true);
break;
case 12:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAIN);
mEffect.setParameter("strength", 1.0f);
break;
case 13:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_GRAYSCALE);
break;
case 14:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_LOMOISH);
break;
case 15:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_NEGATIVE);
break;
case 16:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_POSTERIZE);
break;
case 17:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_ROTATE);
mEffect.setParameter("angle", 180);
break;
case 18:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SATURATE);
mEffect.setParameter("scale", .5f);
break;
case 19:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SEPIA);
break;
case 20:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_SHARPEN);
break;
case 21:
mEffect = effectFactory
.createEffect(EffectFactory.EFFECT_TEMPERATURE);
mEffect.setParameter("scale", .9f);
break;
case 22:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_TINT);
mEffect.setParameter("tint", Color.MAGENTA);
break;
case 23:
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_VIGNETTE);
mEffect.setParameter("scale", .5f);
break;
default:
break;
}
}
private void applyEffect() {
mEffect.apply(mTextures[0], mImageWidth, mImageHeight, mTextures[1]);
}
private void renderResult() {
if (mCurrentEffect != 0) {
// if no effect is chosen, just render the original bitmap
mTexRenderer.renderTexture(mTextures[1]);
} else {
// render the result of applyEffect()
mTexRenderer.renderTexture(mTextures[0]);
}
}
public Bitmap takeScreenshot(GL10 mGL) {
final int mWidth = mEffectView.getWidth();
final int mHeight = mEffectView.getHeight();
IntBuffer ib = IntBuffer.allocate(mWidth * mHeight);
IntBuffer ibt = IntBuffer.allocate(mWidth * mHeight);
mGL.glReadPixels(0, 0, mWidth, mHeight, GL10.GL_RGBA,
GL10.GL_UNSIGNED_BYTE, ib);
// Convert upside down mirror-reversed image to right-side up normal
// image.
for (int i = 0; i < mHeight; i++) {
for (int j = 0; j < mWidth; j++) {
ibt.put((mHeight - i - 1) * mWidth + j, ib.get(i * mWidth + j));
}
}
Bitmap mBitmap = Bitmap.createBitmap(mWidth, mHeight,
Bitmap.Config.ARGB_8888);
mBitmap.copyPixelsFromBuffer(ibt);
return mBitmap;
}
public static String encodeTobase64(Bitmap image) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
image.compress(Bitmap.CompressFormat.PNG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
Log.d("Image Log:", imageEncoded);
return imageEncoded;
}
public void MyClick(View v) {
saveFrame = true;
mEffectView.requestRender();
}
@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
if (mEffectView != null) {
mEffectView.onResume();
}
}
}
GLTool.java:
public class GLToolbox {
final LinkedList<Runnable> mRunOnDraw;
private final String mVertexShader;
private final String mFragmentShader;
protected int mGLProgId;
protected int mGLAttribPosition;
protected int mGLUniformTexture;
protected int mGLAttribTextureCoordinate;
int mOutputWidth;
int mOutputHeight;
boolean mIsInitialized;
public static final String NO_FILTER_VERTEX_SHADER = ""
+ "attribute vec4 position;\n"
+ "attribute vec4 inputTextureCoordinate;\n" + " \n"
+ "varying vec2 textureCoordinate;\n" + " \n" + "void main()\n"
+ "{\n" + " gl_Position = position;\n"
+ " textureCoordinate = inputTextureCoordinate.xy;\n" + "}";
public static final String NO_FILTER_FRAGMENT_SHADER = ""
+ "varying highp vec2 textureCoordinate;\n"
+ " \n"
+ "uniform sampler2D inputImageTexture;\n"
+ " \n"
+ "void main()\n"
+ "{\n"
+ " gl_FragColor = texture2D(inputImageTexture, textureCoordinate);\n"
+ "}";
public GLToolbox() {
this(NO_FILTER_VERTEX_SHADER, NO_FILTER_FRAGMENT_SHADER);
}
public GLToolbox(final String vertexShader, final String fragmentShader) {
mRunOnDraw = new LinkedList<Runnable>();
mVertexShader = vertexShader;
mFragmentShader = fragmentShader;
}
public static int loadShader(int shaderType, String source) {
int shader = GLES20.glCreateShader(shaderType);
if (shader != 0) {
GLES20.glShaderSource(shader, source);
GLES20.glCompileShader(shader);
int[] compiled = new int[1];
GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
if (compiled[0] == 0) {
String info = GLES20.glGetShaderInfoLog(shader);
GLES20.glDeleteShader(shader);
shader = 0;
throw new RuntimeException("Could not compile shader "
+ shaderType + ":" + info);
}
}
return shader;
}
public static int createProgram(String vertexSource, String fragmentSource) {
int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
if (vertexShader == 0) {
return 0;
}
int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
if (pixelShader == 0) {
return 0;
}
int program = GLES20.glCreateProgram();
if (program != 0) {
GLES20.glAttachShader(program, vertexShader);
checkGlError("glAttachShader");
GLES20.glAttachShader(program, pixelShader);
checkGlError("glAttachShader");
GLES20.glLinkProgram(program);
int[] linkStatus = new int[1];
GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
if (linkStatus[0] != GLES20.GL_TRUE) {
String info = GLES20.glGetProgramInfoLog(program);
GLES20.glDeleteProgram(program);
program = 0;
throw new RuntimeException("Could not link program: " + info);
}
}
return program;
}
public static void checkGlError(String op) {
int error;
while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
throw new RuntimeException(op + ": glError " + error);
}
}
public static void initTexParams() {
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S,
GLES20.GL_CLAMP_TO_EDGE);
GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T,
GLES20.GL_CLAMP_TO_EDGE);
}
public static class FilterAdjuster {
private final Adjuster<? extends GLToolbox> adjuster;
public FilterAdjuster(final GLToolbox filter) {
if (filter instanceof GPUImageSharpenFilter) {
adjuster = new SharpnessAdjuster().filter(filter);
} else {
adjuster = null;
}
}
public void adjust(final int percentage) {
if (adjuster != null) {
adjuster.adjust(percentage);
}
}
private abstract class Adjuster<T extends GLToolbox> {
private T filter;
@SuppressWarnings("unchecked")
public Adjuster<T> filter(final GLToolbox filter) {
this.filter = (T) filter;
return this;
}
public T getFilter() {
return filter;
}
public abstract void adjust(int percentage);
protected float range(final int percentage, final float start,
final float end) {
return (end - start) * percentage / 100.0f + start;
}
@SuppressWarnings("unused")
protected int range(final int percentage, final int start,
final int end) {
return (end - start) * percentage / 100 + start;
}
}
private class SharpnessAdjuster extends Adjuster<GPUImageSharpenFilter> {
@Override
public void adjust(final int percentage) {
getFilter().setSharpness(range(percentage, -4.0f, 4.0f));
}
}
}
public void onOutputSizeChanged(final int width, final int height) {
mOutputWidth = width;
mOutputHeight = height;
}
public void onInit() {
mGLProgId = com.example.photoeffects.extra.OpenGlUtils.loadProgram(
mVertexShader, mFragmentShader);
mGLAttribPosition = GLES20.glGetAttribLocation(mGLProgId, "position");
mGLUniformTexture = GLES20.glGetUniformLocation(mGLProgId,
"inputImageTexture");
mGLAttribTextureCoordinate = GLES20.glGetAttribLocation(mGLProgId,
"inputTextureCoordinate");
mIsInitialized = true;
}
public void onInitialized() {
}
public final void destroy() {
mIsInitialized = false;
GLES20.glDeleteProgram(mGLProgId);
onDestroy();
}
public void onDestroy() {
}
protected void setFloat(final int location, final float floatValue) {
GLES20.glUniform1f(location, floatValue);
}
GPUImageSharpenFilter.java:
public class GPUImageSharpenFilter extends GLToolbox {
public static final String SHARPEN_VERTEX_SHADER = ""
+ "attribute vec4 position;\n"
+ "attribute vec4 inputTextureCoordinate;\n"
+ "\n"
+ "uniform float imageWidthFactor; \n"
+ "uniform float imageHeightFactor; \n"
+ "uniform float sharpness;\n"
+ "\n"
+ "varying vec2 textureCoordinate;\n"
+ "varying vec2 leftTextureCoordinate;\n"
+ "varying vec2 rightTextureCoordinate; \n"
+ "varying vec2 topTextureCoordinate;\n"
+ "varying vec2 bottomTextureCoordinate;\n"
+ "\n"
+ "varying float centerMultiplier;\n"
+ "varying float edgeMultiplier;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " gl_Position = position;\n"
+ " \n"
+ " mediump vec2 widthStep = vec2(imageWidthFactor, 0.0);\n"
+ " mediump vec2 heightStep = vec2(0.0, imageHeightFactor);\n"
+ " \n"
+ " textureCoordinate = inputTextureCoordinate.xy;\n"
+ " leftTextureCoordinate = inputTextureCoordinate.xy - widthStep;\n"
+ " rightTextureCoordinate = inputTextureCoordinate.xy + widthStep;\n"
+ " topTextureCoordinate = inputTextureCoordinate.xy + heightStep; \n"
+ " bottomTextureCoordinate = inputTextureCoordinate.xy - heightStep;\n"
+ " \n" + " centerMultiplier = 1.0 + 4.0 * sharpness;\n"
+ " edgeMultiplier = sharpness;\n" + "}";
public static final String SHARPEN_FRAGMENT_SHADER = ""
+ "precision highp float;\n"
+ "\n"
+ "varying highp vec2 textureCoordinate;\n"
+ "varying highp vec2 leftTextureCoordinate;\n"
+ "varying highp vec2 rightTextureCoordinate; \n"
+ "varying highp vec2 topTextureCoordinate;\n"
+ "varying highp vec2 bottomTextureCoordinate;\n"
+ "\n"
+ "varying highp float centerMultiplier;\n"
+ "varying highp float edgeMultiplier;\n"
+ "\n"
+ "uniform sampler2D inputImageTexture;\n"
+ "\n"
+ "void main()\n"
+ "{\n"
+ " mediump vec3 textureColor = texture2D(inputImageTexture, textureCoordinate).rgb;\n"
+ " mediump vec3 leftTextureColor = texture2D(inputImageTexture, leftTextureCoordinate).rgb;\n"
+ " mediump vec3 rightTextureColor = texture2D(inputImageTexture, rightTextureCoordinate).rgb;\n"
+ " mediump vec3 topTextureColor = texture2D(inputImageTexture, topTextureCoordinate).rgb;\n"
+ " mediump vec3 bottomTextureColor = texture2D(inputImageTexture, bottomTextureCoordinate).rgb;\n"
+ "\n"
+ " gl_FragColor = vec4((textureColor * centerMultiplier - (leftTextureColor * edgeMultiplier + rightTextureColor * edgeMultiplier + topTextureColor * edgeMultiplier + bottomTextureColor * edgeMultiplier)), texture2D(inputImageTexture, bottomTextureCoordinate).w);\n"
+ "}";
private int mSharpnessLocation;
private float mSharpness;
private int mImageWidthFactorLocation;
private int mImageHeightFactorLocation;
public GPUImageSharpenFilter() {
this(0.0f);
}
public GPUImageSharpenFilter(final float sharpness) {
super(SHARPEN_VERTEX_SHADER, SHARPEN_FRAGMENT_SHADER);
mSharpness = sharpness;
}
@Override
public void onInit() {
super.onInit();
mSharpnessLocation = GLES20.glGetUniformLocation(createProgram("", "sharpness"),
"sharpness");
mImageWidthFactorLocation = GLES20.glGetUniformLocation(createProgram("", "imageWidthFactor"),
"imageWidthFactor");
mImageHeightFactorLocation = GLES20.glGetUniformLocation(createProgram("", "imageHeightFactor"),
"imageHeightFactor");
setSharpness(mSharpness);
}
@Override
public void onOutputSizeChanged(final int width, final int height) {
super.onOutputSizeChanged(width, height);
setFloat(mImageWidthFactorLocation, 1.0f / width);
setFloat(mImageHeightFactorLocation, 1.0f / height);
}
public void setSharpness(final float sharpness) {
mSharpness = sharpness;
setFloat(mSharpnessLocation, mSharpness);
}
}