예제 #1
0
 /**
  * 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.
  *
  * @param scaleType The new ScaleType
  */
 public void setScaleType(ScaleType scaleType) {
   mScaleType = scaleType;
   mRenderer.setScaleType(scaleType);
   mRenderer.deleteImage();
   mCurrentBitmap = null;
   requestRender();
 }
예제 #2
0
  /**
   * 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
   */
  public Bitmap getBitmapWithFilterApplied(final Bitmap bitmap) {
    if (mGlSurfaceView != null) {
      mRenderer.deleteImage();
      mRenderer.runOnDraw(
          new Runnable() {

            @Override
            public void run() {
              synchronized (mFilter) {
                mFilter.destroy();
                mFilter.notify();
              }
            }
          });
      synchronized (mFilter) {
        requestRender();
        try {
          mFilter.wait();
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }

    GPUImageRenderer renderer = new GPUImageRenderer(mFilter);
    renderer.setRotation(
        Rotation.NORMAL, mRenderer.isFlippedHorizontally(), mRenderer.isFlippedVertically());
    renderer.setScaleType(mScaleType);
    PixelBuffer buffer = new PixelBuffer(bitmap.getWidth(), bitmap.getHeight());
    buffer.setRenderer(renderer);
    renderer.setImageBitmap(bitmap, false);
    Bitmap result = buffer.getBitmap();
    mFilter.destroy();
    renderer.deleteImage();
    buffer.destroy();

    mRenderer.setFilter(mFilter);
    if (mCurrentBitmap != null) {
      mRenderer.setImageBitmap(mCurrentBitmap, false);
    }
    requestRender();

    return result;
  }
예제 #3
0
 /** Deletes the current image. */
 public void deleteImage() {
   mRenderer.deleteImage();
   mCurrentBitmap = null;
   requestRender();
 }
예제 #4
0
 /**
  * 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();
 }
예제 #5
0
 /**
  * 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) {
   mFilter = filter;
   mRenderer.setFilter(mFilter);
   requestRender();
 }
예제 #6
0
 private void setImage(final Bitmap bitmap, final boolean recycle) {
   mRenderer.setImageBitmap(bitmap, recycle);
   requestRender();
 }