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 "rsdCore.h" 19#include "rsdIntrinsics.h" 20#include "rsdAllocation.h" 21 22#include "rsdIntrinsicInlines.h" 23 24using namespace android; 25using namespace android::renderscript; 26 27struct ConvolveParams { 28 ObjectBaseRef<Allocation> lut; 29}; 30 31static void LUT_Bind(const Context *dc, const Script *script, 32 void * intrinsicData, uint32_t slot, Allocation *data) { 33 ConvolveParams *cp = (ConvolveParams *)intrinsicData; 34 rsAssert(slot == 0); 35 cp->lut.set(data); 36} 37 38static void LUT_uchar4(const RsForEachStubParamStruct *p, 39 uint32_t xstart, uint32_t xend, 40 uint32_t instep, uint32_t outstep) { 41 ConvolveParams *cp = (ConvolveParams *)p->usr; 42 uchar4 *out = (uchar4 *)p->out; 43 uchar4 *in = (uchar4 *)p->in; 44 uint32_t x1 = xstart; 45 uint32_t x2 = xend; 46 47 in += xstart; 48 out += xstart; 49 50 DrvAllocation *din = (DrvAllocation *)cp->lut->mHal.drv; 51 const uchar *tr = (const uchar *)din->lod[0].mallocPtr; 52 const uchar *tg = &tr[256]; 53 const uchar *tb = &tg[256]; 54 const uchar *ta = &tb[256]; 55 56 while (x1 < x2) { 57 uchar4 p = *in; 58 uchar4 o = {tr[p.x], tg[p.y], tb[p.z], ta[p.w]}; 59 *out = o; 60 in++; 61 out++; 62 x1++; 63 } 64} 65 66void * rsdIntrinsic_InitLUT(const android::renderscript::Context *dc, 67 android::renderscript::Script *script, 68 RsdIntriniscFuncs_t *funcs) { 69 70 script->mHal.info.exportedVariableCount = 1; 71 funcs->setVarObj = LUT_Bind; 72 funcs->root = LUT_uchar4; 73 ConvolveParams *cp = (ConvolveParams *)calloc(1, sizeof(ConvolveParams)); 74 return cp; 75} 76 77 78