Exemple #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();
 }
Exemple #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;
  }
Exemple #3
0
  /**
   * Gets the images for multiple filters on a image. This can be used to quickly get thumbnail
   * images for filters. <br>
   * 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
   */
  public static void getBitmapForMultipleFilters(
      final Bitmap bitmap,
      final List<GPUImageFilter> filters,
      final ResponseListener<Bitmap> listener) {
    if (filters.isEmpty()) {
      return;
    }
    GPUImageRenderer renderer = new GPUImageRenderer(filters.get(0));
    renderer.setImageBitmap(bitmap, false);
    PixelBuffer buffer = new PixelBuffer(bitmap.getWidth(), bitmap.getHeight());
    buffer.setRenderer(renderer);

    for (GPUImageFilter filter : filters) {
      renderer.setFilter(filter);
      listener.response(buffer.getBitmap());
      filter.destroy();
    }
    renderer.deleteImage();
    buffer.destroy();
  }
Exemple #4
0
 /** Deletes the current image. */
 public void deleteImage() {
   mRenderer.deleteImage();
   mCurrentBitmap = null;
   requestRender();
 }