티스토리 뷰
728x90
반응형
FilterScript
- Introduced in Android 4.2 (API Level 17), Filterscript defines a subset of Renderscript that focuses on image processing operations, such as those that you would typically write with an OpenGL ES fragment shader.
- 현재 android developer의 renderscript 항목에는 기본적으로 filterscript를 사용하기를 설명하고 있다.
- http://developer.android.com/guide/topics/renderscript/compute.html
Usage
- Inputs and return values of root functions cannot contain pointers. The default root function signature contains pointers, so you must use the __attribute__((kernel)) attribute to declare a custom root function when using Filterscript.
- Built-in types cannot exceed 32-bits.
- Filterscript must always use relaxed floating point precision by using the rs_fp_relaxed pragma.
- Most applications can use rs_fp_relaxed without any side effects. This may be very beneficial on some architectures due to additional optimizations only available with relaxed precision (such as SIMD CPU instructions).
- Filterscript files must end with an .fs extension, instead of an .rs extension
- Android-18에서는 fs대신에 rs를 써도 된다.
//mono.fs
#pragma version(1)
#pragma rs java_package_name(com.example.renderscriptsample)
#pragma rs_fp_relaxed
// for version 17
// can called by forEach_invert(in, out)
uchar4 __attribute__((kernel)) invert(uchar4 in, uint32_t x, uint32_t y) {
uchar4 out = in;
out.r = 255 - in.r;
out.g = 255 - in.g;
out.b = 255 - in.b;
return out;
}
//MainActivity.java
// renderscript init
mRS = RenderScript.create(this);
mInAllocation = Allocation.createFromBitmap(mRS, bm, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mOutAllocation = Allocation.createFromBitmap(mRS, bm, Allocation.MipmapControl.MIPMAP_NONE, Allocation.USAGE_SCRIPT);
mScript = new ScriptC_mono(mRS, getResources(), R.raw.mono);
// renderscript run
mScript.forEach_invert(mInAllocation, mOutAllocation);
반응형
'모바일 프로그래밍' 카테고리의 다른 글
Android PHP 인앱 구매 영수증 서버 검증 (0) | 2016.07.21 |
---|---|
Android compileReleaseNdk 에러 해결 (0) | 2016.07.21 |
Android pixmaps 특징 (0) | 2016.07.21 |
Android RenderScript mono filter 예제 (0) | 2016.07.21 |
Android ANR 디버깅 방법 (0) | 2016.07.17 |
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday