/rs/java/android/renderscript/ScriptIntrinsicResize.java

https://github.com/aizuzi/platform_frameworks_base · Java · 113 lines · 38 code · 15 blank · 60 comment · 3 complexity · 63cf3b77cbe37d925ca5d375e005382b MD5 · raw file

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