Home | History | Annotate | Download | only in renderscript
      1 /*
      2  * Copyright (C) 2014 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;
     18 
     19 /**
     20  * Intrinsic for performing a resize of a 2D allocation.
     21  */
     22 public final class ScriptIntrinsicResize extends ScriptIntrinsic {
     23     private Allocation mInput;
     24 
     25     private ScriptIntrinsicResize(long id, RenderScript rs) {
     26         super(id, rs);
     27     }
     28 
     29     /**
     30      * Supported elements types are {@link Element#U8}, {@link
     31      * Element#U8_2}, {@link Element#U8_3}, {@link Element#U8_4}
     32      * {@link Element#F32}, {@link Element#F32_2}, {@link
     33      * Element#F32_3}, {@link Element#F32_4}
     34      *
     35      * @param rs The RenderScript context
     36      *
     37      * @return ScriptIntrinsicResize
     38      */
     39     public static ScriptIntrinsicResize create(RenderScript rs) {
     40         long id = rs.nScriptIntrinsicCreate(12, 0);
     41         ScriptIntrinsicResize si = new ScriptIntrinsicResize(id, rs);
     42         return si;
     43 
     44     }
     45 
     46     /**
     47      * Set the input of the resize.
     48      * Must match the element type supplied during create.
     49      *
     50      * @param ain The input allocation.
     51      */
     52     public void setInput(Allocation ain) {
     53         Element e = ain.getElement();
     54         if (!e.isCompatible(Element.U8(mRS)) &&
     55             !e.isCompatible(Element.U8_2(mRS)) &&
     56             !e.isCompatible(Element.U8_3(mRS)) &&
     57             !e.isCompatible(Element.U8_4(mRS)) &&
     58             !e.isCompatible(Element.F32(mRS)) &&
     59             !e.isCompatible(Element.F32_2(mRS)) &&
     60             !e.isCompatible(Element.F32_3(mRS)) &&
     61             !e.isCompatible(Element.F32_4(mRS))) {
     62             throw new RSIllegalArgumentException("Unsupported element type.");
     63         }
     64 
     65         mInput = ain;
     66         setVar(0, ain);
     67     }
     68 
     69     /**
     70      * Get a FieldID for the input field of this intrinsic.
     71      *
     72      * @return Script.FieldID The FieldID object.
     73      */
     74     public Script.FieldID getFieldID_Input() {
     75         return createFieldID(0, null);
     76     }
     77 
     78 
     79     /**
     80      * Resize copy the input allocation to the output specified. The
     81      * Allocation is rescaled if necessary using bi-cubic
     82      * interpolation.
     83      *
     84      * @param aout Output allocation. Element type must match
     85      *             current input.  Must not be same as input.
     86      */
     87     public void forEach_bicubic(Allocation aout) {
     88         if (aout == mInput) {
     89             throw new RSIllegalArgumentException("Output cannot be same as Input.");
     90         }
     91         forEach_bicubic(aout, null);
     92     }
     93 
     94     /**
     95      * Resize copy the input allocation to the output specified. The
     96      * Allocation is rescaled if necessary using bi-cubic
     97      * interpolation.
     98      *
     99      * @param aout Output allocation. Element type must match
    100      *             current input.
    101      * @param opt LaunchOptions for clipping
    102      */
    103     public void forEach_bicubic(Allocation aout, Script.LaunchOptions opt) {
    104         forEach(0, (Allocation) null, aout, null, opt);
    105     }
    106 
    107     /**
    108      * Get a KernelID for this intrinsic kernel.
    109      *
    110      * @return Script.KernelID The KernelID object.
    111      */
    112     public Script.KernelID getKernelID_bicubic() {
    113         return createKernelID(0, 2, null, null);
    114     }
    115 
    116 
    117 }
    118