Home | History | Annotate | Download | only in test
      1 package com.android.rs.refocus;
      2 
      3 import android.graphics.Bitmap;
      4 import android.support.v8.renderscript.Allocation;
      5 import android.support.v8.renderscript.RenderScript;
      6 
      7 /**
      8  * A class that manages the image buffers that interface between Java and Render
      9  * Script. This class will be specialized for float in f32 package and for byte
     10  * in u8 package.
     11  *
     12  * @author zhl (at) google.com (Li Zhang)
     13  */
     14 public class ImageBuffersForRenderScript {
     15   /**
     16    * Input and output images and their corresponding Allocation to interface
     17    * with Render Script. Both input and output images are unpadded images.
     18    */
     19   public Bitmap inputImage;
     20   public Bitmap outputImage;
     21   public Allocation inAllocation;
     22   public Allocation outAllocation;
     23 
     24   /**
     25    * The following three member variables are used in the subclasses that extend
     26    * this class. Therefore, they are protected.
     27    */
     28   public int imageWidthPadded;
     29   public int imageHeightPadded;
     30   public int paddedMargin;
     31 
     32   public ImageBuffersForRenderScript(Bitmap inImage, int margin,
     33       RenderScript renderScript) {
     34     inputImage = inImage;
     35     inAllocation = Allocation.createFromBitmap(renderScript, inputImage);
     36 
     37     outputImage = Bitmap.createBitmap(inputImage.getWidth(),
     38         inputImage.getHeight(), Bitmap.Config.ARGB_8888);
     39     outAllocation = Allocation.createFromBitmap(renderScript, outputImage);
     40 
     41     paddedMargin = margin;
     42     imageWidthPadded = inputImage.getWidth() + 2 * margin;
     43     imageHeightPadded = inputImage.getHeight() + 2 * margin;
     44   }
     45 }
     46