Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Picture load callback and size access #62

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions library/src/jp/co/cyberagent/android/gpuimage/GPUImage.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,38 +41,39 @@
import java.io.*;
import java.net.URL;
import java.util.List;
import java.util.concurrent.Semaphore;

/**
* The main accessor for GPUImage functionality. This class helps to do common
* tasks through a simple interface.
*/
public class GPUImage {
public class GPUImage {
private final Context mContext;
private final GPUImageRenderer mRenderer;
private GLSurfaceView mGlSurfaceView;
private GPUImageFilter mFilter;
private Bitmap mCurrentBitmap;
private ScaleType mScaleType = ScaleType.CENTER_CROP;

/**
* Instantiates a new GPUImage object.
*
private OnImageLoadedListener listener;

/**
* Instantiates a new GPUImage object.
*
* @param context the context
*/
public GPUImage(final Context context) {
public GPUImage(final Context context) {
if (!supportsOpenGLES2(context)) {
throw new IllegalStateException("OpenGL ES 2.0 is not supported on this phone.");
}
mContext = context;

mContext = context;
mFilter = new GPUImageFilter();
mRenderer = new GPUImageRenderer(mFilter);
}

/**
* Checks if OpenGL ES 2.0 is supported on the current device.
*
*
* @param context the context
* @return true, if successful
*/
Expand All @@ -86,7 +87,7 @@ private boolean supportsOpenGLES2(final Context context) {

/**
* Sets the GLSurfaceView which will display the preview.
*
*
* @param view the GLSurfaceView
*/
public void setGLSurfaceView(final GLSurfaceView view) {
Expand All @@ -108,7 +109,7 @@ public void requestRender() {

/**
* Sets the up camera to be connected to GPUImage to get a filtered preview.
*
*
* @param camera the camera
*/
public void setUpCamera(final Camera camera) {
Expand All @@ -117,7 +118,7 @@ public void setUpCamera(final Camera camera) {

/**
* Sets the up camera to be connected to GPUImage to get a filtered preview.
*
*
* @param camera the camera
* @param degrees by how many degrees the image should be rotated
* @param flipHorizontal if the image should be flipped horizontally
Expand Down Expand Up @@ -155,7 +156,7 @@ private void setUpCameraGingerbread(final Camera camera) {
/**
* Sets the filter which should be applied to the image which was (or will
* be) set by setImage(...).
*
*
* @param filter the new filter
*/
public void setFilter(final GPUImageFilter filter) {
Expand All @@ -166,15 +167,20 @@ public void setFilter(final GPUImageFilter filter) {

/**
* Sets the image on which the filter should be applied.
*
*
* @param bitmap the new image
*/
public void setImage(final Bitmap bitmap) {
mCurrentBitmap = bitmap;
mRenderer.setImageBitmap(bitmap, false);
requestRender();
if(listener != null) listener.onLoad(this);
}

public void setOnImageLoadedListener(OnImageLoadedListener listener){
this.listener = listener;
}

/**
* This sets the scale type of GPUImage. This has to be run before setting the image.
* If image is set and scale type changed, image needs to be reset.
Expand Down Expand Up @@ -209,16 +215,16 @@ public void deleteImage() {

/**
* Sets the image on which the filter should be applied from a Uri.
*
*
* @param uri the uri of the new image
*/
public void setImage(final Uri uri) {
new LoadImageUriTask(this, uri).execute();
}
public void setImage(final Uri uri) {
new LoadImageUriTask(this, uri).execute();
}

/**
* Sets the image on which the filter should be applied from a File.
*
*
* @param file the file of the new image
*/
public void setImage(final File file) {
Expand All @@ -242,7 +248,7 @@ private String getPath(final Uri uri) {

/**
* Gets the current displayed image with applied filter as a Bitmap.
*
*
* @return the current image with filter applied
*/
public Bitmap getBitmapWithFilterApplied() {
Expand All @@ -251,7 +257,7 @@ public Bitmap getBitmapWithFilterApplied() {

/**
* Gets the given bitmap with current filter applied as a Bitmap.
*
*
* @param bitmap the bitmap on which the current filter should be applied
* @return the bitmap with filter applied
*/
Expand Down Expand Up @@ -305,7 +311,7 @@ public void run() {
* Whenever a new Bitmap is ready, the listener will be called with the
* bitmap. The order of the calls to the listener will be the same as the
* filter order.
*
*
* @param bitmap the bitmap on which the filters will be applied
* @param filters the filters which will be applied on the bitmap
* @param listener the listener on which the results will be notified
Expand Down Expand Up @@ -338,7 +344,7 @@ public static void getBitmapForMultipleFilters(final Bitmap bitmap,
* fileName. <br />
* This method is async and will notify when the image was saved through the
* listener.
*
*
* @param folderName the folder name
* @param fileName the file name
* @param listener the listener
Expand All @@ -358,7 +364,7 @@ public void saveToPictures(final String folderName, final String fileName,
* folerName and fileName. <br />
* This method is async and will notify when the image was saved through the
* listener.
*
*
* @param bitmap the bitmap
* @param folderName the folder name
* @param fileName the file name
Expand Down Expand Up @@ -405,6 +411,14 @@ private int getOutputHeight() {
}
}

public int getImageWidth(){
return mCurrentBitmap != null ? mCurrentBitmap.getWidth() : 0;
}

public int getImageHeight(){
return mCurrentBitmap != null ? mCurrentBitmap.getHeight() : 0;
}

@Deprecated
private class SaveTask extends AsyncTask<Void, Void, Void> {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package jp.co.cyberagent.android.gpuimage;

/**
* @author maikvlcek
* @since 9:51 AM - 7/29/13
*/
public interface OnImageLoadedListener {
public void onLoad(GPUImage gpuImage);
}