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      *
     33      * @param rs The RenderScript context
     34      *
     35      * @return ScriptIntrinsicResize
     36      */
     37     public static ScriptIntrinsicResize create(RenderScript rs) {
     38         long id = rs.nScriptIntrinsicCreate(12, 0);
     39         ScriptIntrinsicResize si = new ScriptIntrinsicResize(id, rs);
     40         return si;
     41 
     42     }
     43 
     44     /**
     45      * Set the input of the resize.
     46      * Must match the element type supplied during create.
     47      *
     48      * @param ain The input allocation.
     49      */
     50     public void setInput(Allocation ain) {
     51         Element e = ain.getElement();
     52         if (!e.isCompatible(Element.U8(mRS)) &&
     53             !e.isCompatible(Element.U8_2(mRS)) &&
     54             !e.isCompatible(Element.U8_3(mRS)) &&
     55             !e.isCompatible(Element.U8_4(mRS))) {
     56             throw new RSIllegalArgumentException("Unsuported element type.");
     57         }
     58 
     59         mInput = ain;
     60         setVar(0, ain);
     61     }
     62 
     63     /**
     64      * Get a FieldID for the input field of this intrinsic.
     65      *
     66      * @return Script.FieldID The FieldID object.
     67      */
     68     public Script.FieldID getFieldID_Input() {
     69         return createFieldID(0, null);
     70     }
     71 
     72 
     73     /**
     74      * Resize copy the input allocation to the output specified. The
     75      * Allocation is rescaled if necessary using bi-cubic
     76      * interpolation.
     77      *
     78      * @param aout Output allocation. Element type must match
     79      *             current input.  Must not be same as input.
     80      */
     81     public void forEach_bicubic(Allocation aout) {
     82         if (aout == mInput) {
     83             throw new RSIllegalArgumentException("Output cannot be same as Input.");
     84         }
     85         forEach_bicubic(aout, null);
     86     }
     87 
     88     /**
     89      * Resize copy the input allocation to the output specified. The
     90      * Allocation is rescaled if necessary using bi-cubic
     91      * interpolation.
     92      *
     93      * @param aout Output allocation. Element type must match
     94      *             current input.
     95      * @param opt LaunchOptions for clipping
     96      */
     97     public void forEach_bicubic(Allocation aout, Script.LaunchOptions opt) {
     98         forEach(0, (Allocation) null, aout, null, opt);
     99     }
    100 
    101     /**
    102      * Get a KernelID for this intrinsic kernel.
    103      *
    104      * @return Script.KernelID The KernelID object.
    105      */
    106     public Script.KernelID getKernelID_bicubic() {
    107         return createKernelID(0, 2, null, null);
    108     }
    109 
    110 
    111 }
    112