|
16 | 16 |
|
17 | 17 | package android.renderscript; |
18 | 18 |
|
19 | | -import android.content.Context; |
20 | | -import android.content.res.Resources; |
21 | | -import android.util.Log; |
22 | | - |
23 | | -import java.io.File; |
24 | | -import java.io.IOException; |
25 | | -import java.io.InputStream; |
26 | | -import java.util.Map.Entry; |
27 | | -import java.util.HashMap; |
28 | | - |
29 | | -import java.lang.reflect.Field; |
30 | | -import java.lang.reflect.Modifier; |
31 | 19 |
|
32 | 20 | /** |
33 | | - * @hide |
34 | | - **/ |
35 | | -public class ScriptIntrinsicYuvToRGB extends ScriptIntrinsic { |
| 21 | + * Intrinsic for converting an Android YUV buffer to RGB. |
| 22 | + * |
| 23 | + * The input allocation is supplied in NV21 format as a U8 |
| 24 | + * element type. The output is RGBA, the alpha channel will be |
| 25 | + * set to 255. |
| 26 | + */ |
| 27 | +public final class ScriptIntrinsicYuvToRGB extends ScriptIntrinsic { |
| 28 | + private Allocation mInput; |
| 29 | + |
36 | 30 | ScriptIntrinsicYuvToRGB(int id, RenderScript rs) { |
37 | 31 | super(id, rs); |
38 | 32 | } |
39 | 33 |
|
| 34 | + /** |
| 35 | + * Create an intrinsic for converting YUV to RGB. |
| 36 | + * |
| 37 | + * Supported elements types are {@link Element#U8_4} |
| 38 | + * |
| 39 | + * @param rs The Renderscript context |
| 40 | + * @param e Element type for output |
| 41 | + * |
| 42 | + * @return ScriptIntrinsicYuvToRGB |
| 43 | + */ |
| 44 | + public static ScriptIntrinsicYuvToRGB create(RenderScript rs, Element e) { |
| 45 | + // 6 comes from RS_SCRIPT_INTRINSIC_YUV_TO_RGB in rsDefines.h |
| 46 | + int id = rs.nScriptIntrinsicCreate(6, e.getID(rs)); |
| 47 | + ScriptIntrinsicYuvToRGB si = new ScriptIntrinsicYuvToRGB(id, rs); |
| 48 | + return si; |
| 49 | + } |
40 | 50 |
|
41 | 51 |
|
42 | | - public static class Builder { |
43 | | - RenderScript mRS; |
44 | | - |
45 | | - public Builder(RenderScript rs) { |
46 | | - mRS = rs; |
47 | | - } |
48 | | - |
49 | | - public void setInputFormat(int inputFormat) { |
50 | | - |
51 | | - } |
52 | | - |
53 | | - public void setOutputFormat(Element e) { |
54 | | - |
55 | | - } |
56 | | - |
57 | | - public ScriptIntrinsicYuvToRGB create() { |
58 | | - return null; |
| 52 | + /** |
| 53 | + * Set the input yuv allocation, must be {@link Element#U8}. |
| 54 | + * |
| 55 | + * @param ain The input allocation. |
| 56 | + */ |
| 57 | + public void setInput(Allocation ain) { |
| 58 | + mInput = ain; |
| 59 | + bindAllocation(ain, 0); |
| 60 | + } |
59 | 61 |
|
60 | | - } |
| 62 | + /** |
| 63 | + * Convert the image to RGB. |
| 64 | + * |
| 65 | + * @param aout Output allocation. Must match creation element |
| 66 | + * type. |
| 67 | + */ |
| 68 | + public void forEach(Allocation aout) { |
| 69 | + forEach(0, null, aout, null); |
| 70 | + } |
61 | 71 |
|
| 72 | + /** |
| 73 | + * Get a KernelID for this intrinsic kernel. |
| 74 | + * |
| 75 | + * @return Script.KernelID The KernelID object. |
| 76 | + */ |
| 77 | + public Script.KernelID getKernelID() { |
| 78 | + return createKernelID(0, 2, null, null); |
62 | 79 | } |
63 | 80 |
|
| 81 | + /** |
| 82 | + * Get a FieldID for the input field of this intrinsic. |
| 83 | + * |
| 84 | + * @return Script.FieldID The FieldID object. |
| 85 | + */ |
| 86 | + public Script.FieldID getFieldID_Input() { |
| 87 | + return createFieldID(0, null); |
| 88 | + } |
64 | 89 | } |
0 commit comments