/rs/java/android/renderscript/ScriptIntrinsic3DLUT.java

https://github.com/aizuzi/platform_frameworks_base · Java · 101 lines · 34 code · 16 blank · 51 comment · 4 complexity · bc13c8ae1692a2d1ad2b63d0b86ae44d MD5 · raw file

  1. /*
  2. * Copyright (C) 2012 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. import android.util.Log;
  18. /**
  19. *
  20. * Intrinsic for converting RGB to RGBA by using a 3D lookup table. The
  21. * incoming r,g,b values are use as normalized x,y,z coordinates into a 3D
  22. * allocation. The 8 nearest values are sampled and linearly interpolated. The
  23. * result is placed in the output.
  24. *
  25. **/
  26. public final class ScriptIntrinsic3DLUT extends ScriptIntrinsic {
  27. private Allocation mLUT;
  28. private Element mElement;
  29. private ScriptIntrinsic3DLUT(long id, RenderScript rs, Element e) {
  30. super(id, rs);
  31. mElement = e;
  32. }
  33. /**
  34. * Supported elements types are {@link Element#U8_4}
  35. *
  36. * The defaults tables are identity.
  37. *
  38. * @param rs The RenderScript context
  39. * @param e Element type for intputs and outputs
  40. *
  41. * @return ScriptIntrinsic3DLUT
  42. */
  43. public static ScriptIntrinsic3DLUT create(RenderScript rs, Element e) {
  44. long id = rs.nScriptIntrinsicCreate(8, e.getID(rs));
  45. if (!e.isCompatible(Element.U8_4(rs))) {
  46. throw new RSIllegalArgumentException("Element must be compatible with uchar4.");
  47. }
  48. return new ScriptIntrinsic3DLUT(id, rs, e);
  49. }
  50. /**
  51. * Sets the {@link android.renderscript.Allocation} to be used as the lookup table.
  52. *
  53. * The lookup table must use the same {@link android.renderscript.Element} as the intrinsic.
  54. *
  55. */
  56. public void setLUT(Allocation lut) {
  57. final Type t = lut.getType();
  58. if (t.getZ() == 0) {
  59. throw new RSIllegalArgumentException("LUT must be 3d.");
  60. }
  61. if (!t.getElement().isCompatible(mElement)) {
  62. throw new RSIllegalArgumentException("LUT element type must match.");
  63. }
  64. mLUT = lut;
  65. setVar(0, mLUT);
  66. }
  67. /**
  68. * Invoke the kernel and apply the lookup to each cell of ain
  69. * and copy to aout.
  70. *
  71. * @param ain Input allocation
  72. * @param aout Output allocation
  73. */
  74. public void forEach(Allocation ain, Allocation aout) {
  75. forEach(0, ain, aout, null);
  76. }
  77. /**
  78. * Get a KernelID for this intrinsic kernel.
  79. *
  80. * @return Script.KernelID The KernelID object.
  81. */
  82. public Script.KernelID getKernelID() {
  83. return createKernelID(0, 3, null, null);
  84. }
  85. }