1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.renderscript.cts.refocus;
18 
19 import android.graphics.Bitmap;
20 import android.renderscript.Allocation;
21 import android.renderscript.RenderScript;
22 
23 /**
24  * A class that manages the image buffers that interface between Java and Render
25  * Script. This class will be specialized for float in f32 package and for byte
26  * in u8 package.
27  */
28 public class ImageBuffersForRenderScript {
29   /**
30    * Input and output images and their corresponding Allocation to interface
31    * with Render Script. Both input and output images are unpadded images.
32    */
33   public Bitmap inputImage;
34   public Bitmap outputImage;
35   public Allocation inAllocation;
36   public Allocation outAllocation;
37 
38   /**
39    * The following three member variables are used in the subclasses that extend
40    * this class. Therefore, they are protected.
41    */
42   public int imageWidthPadded;
43   public int imageHeightPadded;
44   public int paddedMargin;
45 
ImageBuffersForRenderScript(Bitmap inImage, int margin, RenderScript renderScript)46   public ImageBuffersForRenderScript(Bitmap inImage, int margin,
47                                      RenderScript renderScript) {
48     inputImage = inImage;
49     inAllocation = Allocation.createFromBitmap(renderScript, inputImage);
50 
51     outputImage = Bitmap.createBitmap(inputImage.getWidth(),
52         inputImage.getHeight(), Bitmap.Config.ARGB_8888);
53     outAllocation = Allocation.createFromBitmap(renderScript, outputImage);
54 
55     paddedMargin = margin;
56     imageWidthPadded = inputImage.getWidth() + 2 * margin;
57     imageHeightPadded = inputImage.getHeight() + 2 * margin;
58   }
59 
destroy()60   public void destroy() {
61     inAllocation.destroy();
62     outAllocation.destroy();
63   }
64 }
65