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