Mandelbrot.java revision 572a5031a5d8602db0bec0b253428a034bd4dd59
1f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat/* 2f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * Copyright (C) 2012 The Android Open Source Project 3f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * 4f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * Licensed under the Apache License, Version 2.0 (the "License"); 5f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * you may not use this file except in compliance with the License. 6f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * You may obtain a copy of the License at 7f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * 8f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * http://www.apache.org/licenses/LICENSE-2.0 9f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * 10f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * Unless required by applicable law or agreed to in writing, software 11f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * distributed under the License is distributed on an "AS IS" BASIS, 12f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * See the License for the specific language governing permissions and 14f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat * limitations under the License. 15f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat */ 16f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat 17f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehatpackage com.android.rs.imagejb; 18fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat 19fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehatimport java.lang.Math; 20f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat 21a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehatimport android.renderscript.Allocation; 22344ca10856f3d3087a3288ce8f91ad83665d93fbKenny Rootimport android.renderscript.Element; 23344ca10856f3d3087a3288ce8f91ad83665d93fbKenny Rootimport android.renderscript.RenderScript; 24a19b250bd273455933ca3502cf2c2e0a803aff77San Mehatimport android.renderscript.Script; 25a19b250bd273455933ca3502cf2c2e0a803aff77San Mehatimport android.renderscript.ScriptC; 26a19b250bd273455933ca3502cf2c2e0a803aff77San Mehatimport android.renderscript.Type; 27fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenbergimport android.util.Log; 28425524dba1552ab3d2ad39e205e65d0a2af997f2Ken Sumrallimport android.widget.SeekBar; 29a19b250bd273455933ca3502cf2c2e0a803aff77San Mehatimport android.widget.TextView; 30a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat 31f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehatpublic class Mandelbrot extends TestBase { 32f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat private ScriptC_mandelbrot mScript; 33f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat 347b18a7b36f61574c0f0bdde0a7409dc36676fa12Kenny Root public boolean onBar1Setup(SeekBar b, TextView t) { 357b18a7b36f61574c0f0bdde0a7409dc36676fa12Kenny Root t.setText("Iterations"); 3671ebe154a5fbbb4b394a439ff0b6b9c84fbd04f5Jeff Sharkey b.setProgress(0); 37f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat return true; 38f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat } 39b9e3ba56cb4075f894a73b02ee70571456494ac1Robert Craig 40b9e3ba56cb4075f894a73b02ee70571456494ac1Robert Craig public void onBar1Changed(int progress) { 41fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat int iters = progress * 3 + 50; 42fd7f5875129adfe2845f4f3fffb17db3a89eea25San Mehat mScript.set_gMaxIteration(iters); 43344ca10856f3d3087a3288ce8f91ad83665d93fbKenny Root } 44344ca10856f3d3087a3288ce8f91ad83665d93fbKenny Root 45f1b736bc5605e92e917ab27f5abf3ba839be2270San Mehat public boolean onBar2Setup(SeekBar b, TextView t) { 46ae10b91044bf76b40b77d81c169e48e0bbdf6d75San Mehat t.setText("Lower Bound: X"); 47a2677e4ad01f250b0765f04adf0acfa6627efc98San Mehat b.setProgress(0); 48a19b250bd273455933ca3502cf2c2e0a803aff77San Mehat return true; 49344ca10856f3d3087a3288ce8f91ad83665d93fbKenny Root } 50a19b250bd273455933ca3502cf2c2e0a803aff77San Mehat 51b78a32c1d5eeb243bdac0eaf18effb1897f1ee67San Mehat public void onBar2Changed(int progress) { 52586536c60b773e3517531ad8a6cb0de6722c67fcSan Mehat float scaleFactor = mScript.get_scaleFactor(); 53fcf24fe62f98c5d44431aa575555569c2c7a29b0San Mehat // allow viewport to be moved by 2x scale factor 5429d8da8cefa99e436c13295d4c9bad060ca18a6dKen Sumrall float lowerBoundX = -2.f + ((progress / scaleFactor) / 50.f); 5523969931fad6e993832208f099f6eea0f6f76eb5San Mehat mScript.set_lowerBoundX(lowerBoundX); 5697f2fc110b2ace7914671c2f5852379bd78922e4Mike Lockwood } 5797f2fc110b2ace7914671c2f5852379bd78922e4Mike Lockwood 586a74dcaa6e646fea8e00b7c04332fc60fe7e017cDaniel Rosenberg public boolean onBar3Setup(SeekBar b, TextView t) { 596a74dcaa6e646fea8e00b7c04332fc60fe7e017cDaniel Rosenberg t.setText("Lower Bound: Y"); 606a74dcaa6e646fea8e00b7c04332fc60fe7e017cDaniel Rosenberg b.setProgress(0); 61fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg return true; 62fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg } 63fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 64fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg public void onBar3Changed(int progress) { 65fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg float scaleFactor = mScript.get_scaleFactor(); 66fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg // allow viewport to be moved by 2x scale factor 67fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg float lowerBoundY = -2.f + ((progress / scaleFactor) / 50.f); 68fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg mScript.set_lowerBoundY(lowerBoundY); 69fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg } 70fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 71fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg public boolean onBar4Setup(SeekBar b, TextView t) { 72fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg t.setText("Scale Factor"); 73fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg b.setProgress(0); 74fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg return true; 75fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg } 76fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 77fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg public void onBar4Changed(int progress) { 78fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg float scaleFactor = 4.f - (3.96f * (progress / 100.f)); 79fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg mScript.set_scaleFactor(scaleFactor); 80fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg } 81fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 82fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg public void createTest(android.content.res.Resources res) { 83fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg int width = mOutPixelsAllocation.getType().getX(); 84fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg int height = mOutPixelsAllocation.getType().getY(); 85e9196fecbb08ead0b5dcdf1b38b81a0419c24bf4Daniel Rosenberg 86e9196fecbb08ead0b5dcdf1b38b81a0419c24bf4Daniel Rosenberg mScript = new ScriptC_mandelbrot(mRS, res, R.raw.mandelbrot); 87e9196fecbb08ead0b5dcdf1b38b81a0419c24bf4Daniel Rosenberg mScript.set_gDimX(width); 88e9196fecbb08ead0b5dcdf1b38b81a0419c24bf4Daniel Rosenberg mScript.set_gDimY(height); 89e9196fecbb08ead0b5dcdf1b38b81a0419c24bf4Daniel Rosenberg mScript.set_gMaxIteration(50); 90e9196fecbb08ead0b5dcdf1b38b81a0419c24bf4Daniel Rosenberg } 91fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 92fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg public void runTest() { 93fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg mScript.forEach_root(mOutPixelsAllocation); 94fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg mRS.finish(); 95fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg } 96fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 97fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg} 98fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg 99fcd34a0ddd45db83b7bc71ff47cba9b789089fddDaniel Rosenberg