-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherode_rs.cc
More file actions
66 lines (51 loc) · 1.23 KB
/
erode_rs.cc
File metadata and controls
66 lines (51 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <RenderScript.h>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "erode_rs.h"
#include "ScriptC_erode3x3.h"
using android::RSC::Allocation;
using android::RSC::Element;
using android::RSC::RS;
using android::RSC::Type;
using android::RSC::sp;
static sp<RS> rs;
static sp<ScriptC_erode3x3> sc;
static sp<Allocation> ain;
static sp<Allocation> aout;
int
erode3x3_rs_init(int w, int h)
{
rs = new RS();
// only legitimate because this is a standalone executable
// cache directory, must be writable
rs->init("/data/local/tmp");
sp<const Element> e = Element::U8(rs);
Type::Builder tb(rs, e);
tb.setX(w);
tb.setY(h);
sp<const Type> t = tb.create();
ain = Allocation::createTyped(rs, t);
aout = Allocation::createTyped(rs, t);
sc = new ScriptC_erode3x3(rs);
sc->set_gIn(ain);
sc->set_gWidth(w);
sc->set_gHeight(h);
return 0;
}
void
erode3x3_rs(uint8_t *in_data, uint8_t *out_data, int w, int h)
{
ain->copy2DStridedFrom(in_data, w * sizeof(uint8_t));
sc->forEach_root(aout);
aout->copy2DStridedTo(out_data, w * sizeof(uint8_t));
}
void
erode3x3_rs_destroy()
{
sc.clear();
ain.clear();
aout.clear();
rs.clear();
}