コード例 #1
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /**
  * 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
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 private int getOutputHeight() {
   if (mRenderer != null && mRenderer.getFrameHeight() != 0) {
     return mRenderer.getFrameHeight();
   } else if (mCurrentBitmap != null) {
     return mCurrentBitmap.getHeight();
   } else {
     WindowManager windowManager =
         (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
     Display display = windowManager.getDefaultDisplay();
     return display.getHeight();
   }
 }
コード例 #3
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
  /**
   * 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();
  }
コード例 #4
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /**
  * 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
  * @param flipVertical if the image should be flipped vertically
  */
 public void setUpCamera(
     final Camera camera,
     boolean userFront,
     final boolean flipHorizontal,
     final boolean flipVertical) {
   try {
     mGlSurfaceView.setRenderMode(GLSurfaceView.RENDERMODE_CONTINUOUSLY);
     Rotation rotation = Rotation.ROTATION_90;
     if (userFront) {
       rotation = Rotation.ROTATION_270;
     } else {
       rotation = Rotation.ROTATION_90;
     }
     mRenderer.setRotationCamera(rotation, flipHorizontal, flipVertical);
     if (Build.VERSION.SDK_INT > Build.VERSION_CODES.GINGERBREAD_MR1) {
       setUpCameraGingerbread(camera);
     } else {
       camera.setPreviewCallback(mRenderer);
       camera.startPreview();
     }
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /**
  * Runs the given Runnable on the OpenGL thread.
  *
  * @param runnable The runnable to be run on the OpenGL thread.
  */
 public void runOnGLThread(Runnable runnable) {
   mRenderer.runOnDrawEnd(runnable);
 }
コード例 #6
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
  /**
   * 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;
  }
コード例 #7
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /** Deletes the current image. */
 public void deleteImage() {
   mRenderer.deleteImage();
   mCurrentBitmap = null;
   requestRender();
 }
コード例 #8
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /**
  * Sets the rotation of the displayed image.
  *
  * @param rotation new rotation
  */
 public void setRotation(Rotation rotation) {
   mRenderer.setRotation(rotation);
 }
コード例 #9
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /**
  * 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();
 }
コード例 #10
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 /**
  * 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();
 }
コード例 #11
0
ファイル: GPUImage.java プロジェクト: qtstsq55/Perspective
 @TargetApi(11)
 private void setUpCameraGingerbread(final Camera camera) {
   mRenderer.setUpSurfaceTexture(camera);
 }