1 #include "RenderScript.h"
2 #include "ScriptC_detectAt.h"
3 #include "../../objdetect/src/HaarStructs.h"
4
5 using namespace android;
6 using namespace RSC;
7 using namespace std;
8
9 static sp<RS> rs;
10 static sp<ScriptC_detectAt> sc;
11
initInnerLoop(HaarVars hf,int origWidth,int origHeight)12 void initInnerLoop(HaarVars hf, int origWidth, int origHeight) {
13 rs = new RS();
14 bool r = rs->init("/data/data/com.example.noahp.facialrecogrs/cache");
15
16 sc = new ScriptC_detectAt(rs);
17
18 sc->set_origWidth(origWidth);
19 sc->set_origHeight(origHeight);
20 sc->set_sqofs(hf.sqofs);
21 sc->set_normRectArea(hf.normRectArea);
22 sc->set_stagesSize(hf.stagesSize);
23
24 sc->invoke_initCurr();
25
26 const HaarStump* cascadeStumps = &hf.stumps[0];
27 const HaarStage* cascadeStages = &hf.stages[0];
28
29 for( int i = 0; i < hf.nStumps; i++ )
30 {
31 const HaarStump stump = cascadeStumps[i];
32 sc->invoke_addStump(i, stump.threshold, stump.left, stump.right);
33 }
34
35 for(int stageIdx = 0; stageIdx < hf.stagesSize; stageIdx++) {
36 const HaarStage stage = cascadeStages[stageIdx];
37 sc->invoke_addStage(stage.first, stage.ntrees, stage.threshold);
38 int ntrees = stage.ntrees;
39 }
40
41 for( int i = 0; i < hf.nFeatures; i++ )
42 {
43 const HaarFeature f = hf.haarFeatures[i];
44 sc->invoke_addHF(f.x[0],f.y[0],f.width[0],f.height[0],
45 f.x[1],f.y[1],f.width[1],f.height[1],
46 f.x[2],f.y[2],f.width[2],f.height[2],
47 f.weight0, f.weight1, f.weight2);
48 }
49
50 sc->set_nrect(UInt4(hf.nrect.x, hf.nrect.y, hf.nrect.width, hf.nrect.height));
51 }
52
innerloops(const int height,const int width,const int * inArr,const int * inArrSq,const int yStep,bool * outData)53 void innerloops(const int height, const int width, const int* inArr, const int* inArrSq, const int yStep, bool* outData) {
54 sp<Allocation> outAllocation;
55 sp<const Element> e2 = Element::BOOLEAN(rs);
56 Type::Builder tb2(rs, e2);
57 tb2.setX(width*height);
58 sp<const Type> t2 = tb2.create();
59 outAllocation = Allocation::createTyped(rs,t2);
60
61 sp<Allocation> inAllocation;
62 sp<const Element> e = Element::I32(rs);
63 Type::Builder tb(rs, e);
64 tb.setX(width*height);
65 sp<const Type> t = tb.create();
66 inAllocation = Allocation::createTyped(rs,t);
67 inAllocation->copy1DRangeFrom(0,width*height,inArr);
68 sc->set_inAlloc(inAllocation);
69
70 sp<Allocation> inAllocationSq;
71 sp<const Element> e3 = Element::I32(rs);
72 inAllocationSq = Allocation::createTyped(rs,t);
73 inAllocationSq->copy1DRangeFrom(0,width*height,inArrSq);
74 sc->set_inAllocSq(inAllocationSq);
75
76 sc->set_width(width);
77 sc->set_height(height);
78 sc->set_yStep(yStep);
79
80 sc->forEach_runAtHaarKernel(inAllocation, outAllocation);
81 outAllocation->copy1DRangeTo(0,width*height,outData);
82 }
83
cleanUpInnerLoops()84 void cleanUpInnerLoops() {
85 rs->finish();
86 }