rsCpuIntrinsicLUT.cpp 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include "rsCpuIntrinsic.h"
  17. #include "rsCpuIntrinsicInlines.h"
  18. namespace android {
  19. namespace renderscript {
  20. class RsdCpuScriptIntrinsicLUT : public RsdCpuScriptIntrinsic {
  21. public:
  22. void populateScript(Script *) override;
  23. void invokeFreeChildren() override;
  24. void setGlobalObj(uint32_t slot, ObjectBase *data) override;
  25. ~RsdCpuScriptIntrinsicLUT() override;
  26. RsdCpuScriptIntrinsicLUT(RsdCpuReferenceImpl *ctx, const Script *s, const Element *e);
  27. protected:
  28. ObjectBaseRef<Allocation> lut;
  29. static void kernel(const RsExpandKernelDriverInfo *info,
  30. uint32_t xstart, uint32_t xend,
  31. uint32_t outstep);
  32. };
  33. void RsdCpuScriptIntrinsicLUT::setGlobalObj(uint32_t slot, ObjectBase *data) {
  34. rsAssert(slot == 0);
  35. lut.set(static_cast<Allocation *>(data));
  36. }
  37. void RsdCpuScriptIntrinsicLUT::kernel(const RsExpandKernelDriverInfo *info,
  38. uint32_t xstart, uint32_t xend,
  39. uint32_t outstep) {
  40. RsdCpuScriptIntrinsicLUT *cp = (RsdCpuScriptIntrinsicLUT *)info->usr;
  41. uchar *out = (uchar *)info->outPtr[0];
  42. const uchar *in = (uchar *)info->inPtr[0];
  43. uint32_t x1 = xstart;
  44. uint32_t x2 = xend;
  45. const uchar *tr = (const uchar *)cp->lut->mHal.drvState.lod[0].mallocPtr;
  46. const uchar *tg = &tr[256];
  47. const uchar *tb = &tg[256];
  48. const uchar *ta = &tb[256];
  49. while (x1 < x2) {
  50. out[0] = tr[in[0]];
  51. out[1] = tg[in[1]];
  52. out[2] = tb[in[2]];
  53. out[3] = ta[in[3]];
  54. in += 4;
  55. out += 4;
  56. x1++;
  57. }
  58. }
  59. RsdCpuScriptIntrinsicLUT::RsdCpuScriptIntrinsicLUT(RsdCpuReferenceImpl *ctx,
  60. const Script *s, const Element *e)
  61. : RsdCpuScriptIntrinsic(ctx, s, e, RS_SCRIPT_INTRINSIC_ID_LUT) {
  62. mRootPtr = &kernel;
  63. }
  64. RsdCpuScriptIntrinsicLUT::~RsdCpuScriptIntrinsicLUT() {
  65. }
  66. void RsdCpuScriptIntrinsicLUT::populateScript(Script *s) {
  67. s->mHal.info.exportedVariableCount = 1;
  68. }
  69. void RsdCpuScriptIntrinsicLUT::invokeFreeChildren() {
  70. lut.clear();
  71. }
  72. RsdCpuScriptImpl * rsdIntrinsic_LUT(RsdCpuReferenceImpl *ctx,
  73. const Script *s, const Element *e) {
  74. return new RsdCpuScriptIntrinsicLUT(ctx, s, e);
  75. }
  76. } // namespace renderscript
  77. } // namespace android