summaryrefslogtreecommitdiff
path: root/java/tests/Refocus/src/com/android/rs/test/ImageBuffersForRenderScript.java
blob: f608bcdf417068b23f765e3e7606346fe7b8b2e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package com.android.rs.refocus;

import android.graphics.Bitmap;
import android.support.v8.renderscript.Allocation;
import android.support.v8.renderscript.RenderScript;

/**
 * A class that manages the image buffers that interface between Java and Render
 * Script. This class will be specialized for float in f32 package and for byte
 * in u8 package.
 *
 * @author zhl@google.com (Li Zhang)
 */
public class ImageBuffersForRenderScript {
  /**
   * Input and output images and their corresponding Allocation to interface
   * with Render Script. Both input and output images are unpadded images.
   */
  public Bitmap inputImage;
  public Bitmap outputImage;
  public Allocation inAllocation;
  public Allocation outAllocation;

  /**
   * The following three member variables are used in the subclasses that extend
   * this class. Therefore, they are protected.
   */
  public int imageWidthPadded;
  public int imageHeightPadded;
  public int paddedMargin;

  public ImageBuffersForRenderScript(Bitmap inImage, int margin,
      RenderScript renderScript) {
    inputImage = inImage;
    inAllocation = Allocation.createFromBitmap(renderScript, inputImage);

    outputImage = Bitmap.createBitmap(inputImage.getWidth(),
        inputImage.getHeight(), Bitmap.Config.ARGB_8888);
    outAllocation = Allocation.createFromBitmap(renderScript, outputImage);

    paddedMargin = margin;
    imageWidthPadded = inputImage.getWidth() + 2 * margin;
    imageHeightPadded = inputImage.getHeight() + 2 * margin;
  }
}