• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 using namespace android;
25 using namespace android::renderscript;
26 
27 struct ConvolveParams {
28     ObjectBaseRef<Allocation> lut;
29 };
30 
LUT_Bind(const Context * dc,const Script * script,void * intrinsicData,uint32_t slot,Allocation * data)31 static 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 
LUT_uchar4(const RsForEachStubParamStruct * p,uint32_t xstart,uint32_t xend,uint32_t instep,uint32_t outstep)38 static 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     DrvAllocation *din = (DrvAllocation *)cp->lut->mHal.drv;
48     const uchar *tr = (const uchar *)din->lod[0].mallocPtr;
49     const uchar *tg = &tr[256];
50     const uchar *tb = &tg[256];
51     const uchar *ta = &tb[256];
52 
53     while (x1 < x2) {
54         uchar4 p = *in;
55         uchar4 o = {tr[p.x], tg[p.y], tb[p.z], ta[p.w]};
56         *out = o;
57         in++;
58         out++;
59         x1++;
60     }
61 }
62 
rsdIntrinsic_InitLUT(const android::renderscript::Context * dc,android::renderscript::Script * script,RsdIntriniscFuncs_t * funcs)63 void * rsdIntrinsic_InitLUT(const android::renderscript::Context *dc,
64                                     android::renderscript::Script *script,
65                                     RsdIntriniscFuncs_t *funcs) {
66 
67     script->mHal.info.exportedVariableCount = 1;
68     funcs->setVarObj = LUT_Bind;
69     funcs->root = LUT_uchar4;
70     ConvolveParams *cp = (ConvolveParams *)calloc(1, sizeof(ConvolveParams));
71     return cp;
72 }
73 
74 
75