Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
RenderScript for Android
Daichi Furiya (Wasabeef)
September 29, 2015
Programming
0
1.7k
RenderScript for Android
RenderScript + Blur
Daichi Furiya (Wasabeef)
September 29, 2015
Tweet
Share
More Decks by Daichi Furiya (Wasabeef)
See All by Daichi Furiya (Wasabeef)
Flutter Hooks を使ったアプリ開発 / App Development with the Flutter Hooks
wasabeef
1
450
Flutter 2021 の振り返りと今後のアプリ開発に向けて / Looking back on Flutter 2021 and for future app development.
wasabeef
4
1.6k
Flutter Hooks, sometimes Jetpack Compose
wasabeef
2
1.3k
Skia and Skija, Skiko [ja]
wasabeef
1
1.1k
Flutter はプロダクション開発に耐えうるのか / Flutter ready for production?
wasabeef
34
10k
モバイル開発におけるクロスプラットフォームの期待と課題 / Cross-platform expectations and challenges in mobile development
wasabeef
0
250
Repository with Store4 [ja]
wasabeef
2
970
来年に備えるために Android の知識を網羅する / Looking back on this Android year in preparation for next year.
wasabeef
17
13k
What's new Android Studio 4.0 [ja]
wasabeef
4
1.4k
Other Decks in Programming
See All in Programming
Meet Swift Regex
usamik26
0
370
[월간 데이터리안 세미나 6월] 스스로 성장하는 분석가 커리어 이야기
datarian
0
250
無限スクロールビューライブラリ 二つの設計思想比較
harumak
0
270
Chart実装が楽になりました。
keisukeyamagishi
0
120
実践エクストリームプログラミング / Extreme Programming in Practice
enk
1
570
Angular‘s Future without NgModules: Architectures with Standalone Components @enterJS
manfredsteyer
PRO
0
250
模組化的Swift架構(二) DDD速成
haifengkao
0
390
OSS貢献を気軽にしたい Let's Go Talk #1
yuyaabo
0
120
【Scrum Fest Osaka 2022】スクラムチームに放り込まれた若手エンジニアの皆さん、どのように技術のキャッチアップをしていくかイメージはついていますか?
miiiki
0
130
AWS Config Custom Rule、ノーコードでできるかな?
watany
0
110
Web API連携でCSRF対策がどう実装されてるか調べた / how to implements csrf-detection on Web API
yasuakiomokawa
2
510
JetPackComposeは宣言型プログラミングパラダイムって実はよくわかってないんですが、別に使ってもいいんですよね、
conigashima
0
190
Featured
See All Featured
In The Pink: A Labor of Love
frogandcode
131
21k
Keith and Marios Guide to Fast Websites
keithpitt
404
21k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
29
4.3k
Happy Clients
brianwarren
89
5.6k
Testing 201, or: Great Expectations
jmmastey
21
5.4k
How New CSS Is Changing Everything About Graphic Design on the Web
jensimmons
213
11k
Why You Should Never Use an ORM
jnunemaker
PRO
47
7.6k
Automating Front-end Workflow
addyosmani
1351
200k
Making the Leap to Tech Lead
cromwellryan
113
7.4k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
655
120k
The Power of CSS Pseudo Elements
geoffreycrofte
47
3.9k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
237
19k
Transcript
RenderScript + Blur Wasabeef
About Me @wasabeef_jp CyberAgent, Inc.
RenderScript?
RenderScript? ɾAPI Level 11 (Support Library v8) ɾUsing C99 lang
(RenderScript Kernel) ɾUsing Java API ɾImage Processing ɾBlur … etc
RenderScript Kernel? blur.rs LLVM RS CC blur.bc ScriptC_blur .java ScriptField_point
.java
RenderScript Intrinsics ɾScriptIntrinsicConvolve3x3 ɾScriptIntrinsicConvolve5x5 ɾScriptIntrinsicBlur ɾScriptIntrinsicYuvToRGB ɾScriptIntrinsicColorMatrix ɾScriptIntrinsicBlend ɾScriptIntrinsicLUT ɾScriptIntrinsic3DLUT
RenderScript Settings
Gradle android { compileSdkVersion 23 buildToolsVersion “23.0.1” defaultConfig { minSdkVersion
23 targetSdkVersion 23 renderscriptTargetApi 23 renderscriptSupportModeEnabled true } }
Gradle android { compileSdkVersion 23 buildToolsVersion “23.0.1” defaultConfig { minSdkVersion
23 targetSdkVersion 23 renderscriptTargetApi 23 renderscriptSupportModeEnabled true } }
Blur?
Blur
Algorithms ɾRS Gaussian Fast (ScriptIntrinsicBlur) ɾRS Box, Gaussian 5x5 (ScriptIntrinsicConvolve5x5)
ɾStack Blur ɾGaussian Fast Blur ɾBox Blur
Gaussian Blur (Java) public static void blur(Bitmap bmp, int radius)
{ int w = bmp.getWidth(); int h = bmp.getHeight(); int[] pix = new int[w * h]; bmp.getPixels(pix, 0, w, 0, 0, w, h); for (int r = radius; r >= 1; r /= 2) { for (int i = r; i < h - r; i++) { for (int j = r; j < w - r; j++) { int tl = pix[(i - r) * w + j - r]; int tr = pix[(i - r) * w + j + r]; int tc = pix[(i - r) * w + j]; int bl = pix[(i + r) * w + j - r]; int br = pix[(i + r) * w + j + r]; int bc = pix[(i + r) * w + j]; int cl = pix[i * w + j - r]; int cr = pix[i * w + j + r]; pix[(i * w) + j] = 0xFF000000 | (((tl & 0xFF) + (tr & 0xFF) + (tc & 0xFF) + (bl & 0xFF) + (br & 0xFF) + (bc & 0xFF) + (cl & 0xFF) + (cr & 0xFF)) >> 3) & 0xFF | (((tl & 0xFF00) + (tr & 0xFF00) + (tc & 0xFF00) + (bl & 0xFF00) + (br & 0xFF00) + (bc & 0xFF00) + (cl & 0xFF00) + (cr & 0xFF00)) >> 3) & 0xFF00 | (((tl & 0xFF0000) + (tr & 0xFF0000) + (tc & 0xFF0000) + (bl & 0xFF0000) + (br & 0xFF0000) + (bc & 0xFF0000) + (cl & 0xFF0000) + (cr & 0xFF0000)) >> 3) & 0xFF0000; } } } bmp.setPixels(pix, 0, w, 0, 0, w, h); }
RS Gaussian Blur (Java) public static void blur(Bitmap src, int
radius) { RenderScript rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
RenderScript public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
Allocation public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
ScriptIntrinsicBlur public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
RenderScript Intrinsics ɾScriptIntrinsicConvolve3x3 ɾScriptIntrinsicConvolve5x5 ɾScriptIntrinsicBlur ɾScriptIntrinsicYuvToRGB ɾScriptIntrinsicColorMatrix ɾScriptIntrinsicBlend ɾScriptIntrinsicLUT ɾScriptIntrinsic3DLUT
Element ɾRoughly equivalent to a C type ɾfloat ɾfloat4 ɾunsigned
32-bit int ɾsigned 8-bit int
ScriptIntrinsicBlur::setRadius public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
ScriptIntrinsicBlur::setInput public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
ScriptIntrinsicBlur::forEach public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
Allocation::copyTo public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
RenderScript::destroy public static void blur(Bitmap src, int radius) { RenderScript
rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
RS Gaussian Blur public static void blur(Bitmap src, int radius)
{ RenderScript rs = RenderScript.create(context); Allocation input = Allocation.createFromBitmap(rs, src); Allocation output = Allocation.createTyped(rs, input.getType()); ScriptIntrinsicBlur script = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs)); script.setRadius(radius); script.setInput(input); script.forEach(output); output.copyTo(src); rs.destroy(); }
github.com/wasabeef Blurry Glide Transformations Picasso Transformations Fresco Processors
Thanks.