Loading graphics/java/android/renderscript/Script.java +47 −0 Original line number Original line Diff line number Diff line Loading @@ -42,6 +42,10 @@ public class Script extends BaseObj { } } } } protected void invoke(int slot) { mRS.nScriptInvoke(mID, slot); } Script(int id, RenderScript rs) { Script(int id, RenderScript rs) { super(rs); super(rs); mID = id; mID = id; Loading Loading @@ -145,5 +149,48 @@ public class Script extends BaseObj { } } public static class FieldBase { protected Element mElement; protected Type mType; protected Allocation mAllocation; protected void init(RenderScript rs, int dimx) { mAllocation = Allocation.createSized(rs, mElement, dimx); mType = mAllocation.getType(); } protected FieldBase() { } public Element getElement() { return mElement; } public Type getType() { return mType; } public Allocation getAllocation() { return mAllocation; } //@Override public void updateAllocation() { } // /* public class ScriptField_UserField extends android.renderscript.Script.FieldBase { protected } */ } } } graphics/java/android/renderscript/ScriptC.java +41 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,47 @@ public class ScriptC extends Script { super(id, rs); super(id, rs); } } protected ScriptC(RenderScript rs, Resources resources, int resourceID, boolean isRoot) { super(0, rs); mID = internalCreate(rs, resources, resourceID, isRoot); } private static synchronized int internalCreate(RenderScript rs, Resources resources, int resourceID, boolean isRoot) { byte[] pgm; int pgmLength; InputStream is = resources.openRawResource(resourceID); try { try { pgm = new byte[1024]; pgmLength = 0; while(true) { int bytesLeft = pgm.length - pgmLength; if (bytesLeft == 0) { byte[] buf2 = new byte[pgm.length * 2]; System.arraycopy(pgm, 0, buf2, 0, pgm.length); pgm = buf2; bytesLeft = pgm.length - pgmLength; } int bytesRead = is.read(pgm, pgmLength, bytesLeft); if (bytesRead <= 0) { break; } pgmLength += bytesRead; } } finally { is.close(); } } catch(IOException e) { throw new Resources.NotFoundException(); } rs.nScriptCBegin(); rs.nScriptCSetScript(pgm, 0, pgmLength); rs.nScriptSetRoot(isRoot); return rs.nScriptCCreate(); } public static class Builder extends Script.Builder { public static class Builder extends Script.Builder { byte[] mProgram; byte[] mProgram; int mProgramLength; int mProgramLength; Loading libs/rs/java/Fountain/res/raw/fountain2.rs +14 −14 Original line number Original line Diff line number Diff line // Fountain test script // Fountain test script #pragma version(1) #pragma version(1) #include "rs_types.rsh" #include "../../../../scriptc/rs_types.rsh" #include "rs_math.rsh" #include "../../../../scriptc/rs_math.rsh" #include "rs_graphics.rsh" #include "../../../../scriptc/rs_graphics.rsh" static int newPart = 0; static int newPart = 0; Loading @@ -12,15 +12,15 @@ typedef struct Control_s { int rate; int rate; int count; int count; float r, g, b; float r, g, b; rs_allocation partBuffer; rs_mesh partMesh; rs_mesh partMesh; rs_allocation partBuffer; } Control_t; } Control_t; Control_t *Control; Control_t *Control; typedef struct Point_s{ typedef struct Point_s{ float2 delta; float2 delta; float2 position; rs_position2 pos; unsigned int color; rs_color4u color; } Point_t; } Point_t; Point_t *point; Point_t *point; Loading @@ -33,8 +33,6 @@ int main(int launchID) { if (rate) { if (rate) { float rMax = ((float)rate) * 0.005f; float rMax = ((float)rate) * 0.005f; int x = Control->x; int y = Control->y; int color = ((int)(Control->r * 255.f)) | int color = ((int)(Control->r * 255.f)) | ((int)(Control->g * 255.f)) << 8 | ((int)(Control->g * 255.f)) << 8 | ((int)(Control->b * 255.f)) << 16 | ((int)(Control->b * 255.f)) << 16 | Loading @@ -42,9 +40,11 @@ int main(int launchID) { Point_t * np = &p[newPart]; Point_t * np = &p[newPart]; while (rate--) { while (rate--) { np->delta = vec2Rand(rMax); np->delta.x = rand(rMax); np->position.x = x; np->delta.y = rand(rMax); np->position.y = y; //np->delta = vec2Rand(rMax); np->pos.x = Control->x; np->pos.y = Control->y; np->color = color; np->color = color; newPart++; newPart++; np++; np++; Loading @@ -57,13 +57,13 @@ int main(int launchID) { for (ct=0; ct < count; ct++) { for (ct=0; ct < count; ct++) { float dy = p->delta.y + 0.15f; float dy = p->delta.y + 0.15f; float posy = p->position.y + dy; float posy = p->pos.y + dy; if ((posy > height) && (dy > 0)) { if ((posy > height) && (dy > 0)) { dy *= -0.3f; dy *= -0.3f; } } p->delta.y = dy; p->delta.y = dy; p->position.x += p->delta.x; p->pos.x += p->delta.x; p->position.y = posy; p->pos.y = posy; p++; p++; } } Loading libs/rs/java/ImageProcessing/res/raw/threshold2.rs 0 → 100644 +49 −0 Original line number Original line Diff line number Diff line #pragma version(1) #include "../../../../scriptc/rs_types.rsh" #include "../../../../scriptc/rs_math.rsh" #include "../../../../scriptc/rs_graphics.rsh" typedef struct Params_s{ int inHeight; int inWidth; int outHeight; int outWidth; float threshold; } Params_t; Params_t * Params; rs_color4u * InPixel; rs_color4u * OutPixel; int main() { int t = uptimeMillis(); rs_color4u *in = InPixel; rs_color4u *out = OutPixel; int count = Params->inWidth * Params->inHeight; int i; float threshold = Params->threshold * 255.f; for (i = 0; i < count; i++) { float luminance = 0.2125f * in->x + 0.7154f * in->y + 0.0721f * in->z; if (luminance > threshold) { *out = *in; } else { *((int *)out) = *((int *)in) & 0xff000000; } in++; out++; } t= uptimeMillis() - t; debugI32("Filter time", t); sendToClient(&count, 1, 4, 0); return 0; } Loading
graphics/java/android/renderscript/Script.java +47 −0 Original line number Original line Diff line number Diff line Loading @@ -42,6 +42,10 @@ public class Script extends BaseObj { } } } } protected void invoke(int slot) { mRS.nScriptInvoke(mID, slot); } Script(int id, RenderScript rs) { Script(int id, RenderScript rs) { super(rs); super(rs); mID = id; mID = id; Loading Loading @@ -145,5 +149,48 @@ public class Script extends BaseObj { } } public static class FieldBase { protected Element mElement; protected Type mType; protected Allocation mAllocation; protected void init(RenderScript rs, int dimx) { mAllocation = Allocation.createSized(rs, mElement, dimx); mType = mAllocation.getType(); } protected FieldBase() { } public Element getElement() { return mElement; } public Type getType() { return mType; } public Allocation getAllocation() { return mAllocation; } //@Override public void updateAllocation() { } // /* public class ScriptField_UserField extends android.renderscript.Script.FieldBase { protected } */ } } }
graphics/java/android/renderscript/ScriptC.java +41 −0 Original line number Original line Diff line number Diff line Loading @@ -37,6 +37,47 @@ public class ScriptC extends Script { super(id, rs); super(id, rs); } } protected ScriptC(RenderScript rs, Resources resources, int resourceID, boolean isRoot) { super(0, rs); mID = internalCreate(rs, resources, resourceID, isRoot); } private static synchronized int internalCreate(RenderScript rs, Resources resources, int resourceID, boolean isRoot) { byte[] pgm; int pgmLength; InputStream is = resources.openRawResource(resourceID); try { try { pgm = new byte[1024]; pgmLength = 0; while(true) { int bytesLeft = pgm.length - pgmLength; if (bytesLeft == 0) { byte[] buf2 = new byte[pgm.length * 2]; System.arraycopy(pgm, 0, buf2, 0, pgm.length); pgm = buf2; bytesLeft = pgm.length - pgmLength; } int bytesRead = is.read(pgm, pgmLength, bytesLeft); if (bytesRead <= 0) { break; } pgmLength += bytesRead; } } finally { is.close(); } } catch(IOException e) { throw new Resources.NotFoundException(); } rs.nScriptCBegin(); rs.nScriptCSetScript(pgm, 0, pgmLength); rs.nScriptSetRoot(isRoot); return rs.nScriptCCreate(); } public static class Builder extends Script.Builder { public static class Builder extends Script.Builder { byte[] mProgram; byte[] mProgram; int mProgramLength; int mProgramLength; Loading
libs/rs/java/Fountain/res/raw/fountain2.rs +14 −14 Original line number Original line Diff line number Diff line // Fountain test script // Fountain test script #pragma version(1) #pragma version(1) #include "rs_types.rsh" #include "../../../../scriptc/rs_types.rsh" #include "rs_math.rsh" #include "../../../../scriptc/rs_math.rsh" #include "rs_graphics.rsh" #include "../../../../scriptc/rs_graphics.rsh" static int newPart = 0; static int newPart = 0; Loading @@ -12,15 +12,15 @@ typedef struct Control_s { int rate; int rate; int count; int count; float r, g, b; float r, g, b; rs_allocation partBuffer; rs_mesh partMesh; rs_mesh partMesh; rs_allocation partBuffer; } Control_t; } Control_t; Control_t *Control; Control_t *Control; typedef struct Point_s{ typedef struct Point_s{ float2 delta; float2 delta; float2 position; rs_position2 pos; unsigned int color; rs_color4u color; } Point_t; } Point_t; Point_t *point; Point_t *point; Loading @@ -33,8 +33,6 @@ int main(int launchID) { if (rate) { if (rate) { float rMax = ((float)rate) * 0.005f; float rMax = ((float)rate) * 0.005f; int x = Control->x; int y = Control->y; int color = ((int)(Control->r * 255.f)) | int color = ((int)(Control->r * 255.f)) | ((int)(Control->g * 255.f)) << 8 | ((int)(Control->g * 255.f)) << 8 | ((int)(Control->b * 255.f)) << 16 | ((int)(Control->b * 255.f)) << 16 | Loading @@ -42,9 +40,11 @@ int main(int launchID) { Point_t * np = &p[newPart]; Point_t * np = &p[newPart]; while (rate--) { while (rate--) { np->delta = vec2Rand(rMax); np->delta.x = rand(rMax); np->position.x = x; np->delta.y = rand(rMax); np->position.y = y; //np->delta = vec2Rand(rMax); np->pos.x = Control->x; np->pos.y = Control->y; np->color = color; np->color = color; newPart++; newPart++; np++; np++; Loading @@ -57,13 +57,13 @@ int main(int launchID) { for (ct=0; ct < count; ct++) { for (ct=0; ct < count; ct++) { float dy = p->delta.y + 0.15f; float dy = p->delta.y + 0.15f; float posy = p->position.y + dy; float posy = p->pos.y + dy; if ((posy > height) && (dy > 0)) { if ((posy > height) && (dy > 0)) { dy *= -0.3f; dy *= -0.3f; } } p->delta.y = dy; p->delta.y = dy; p->position.x += p->delta.x; p->pos.x += p->delta.x; p->position.y = posy; p->pos.y = posy; p++; p++; } } Loading
libs/rs/java/ImageProcessing/res/raw/threshold2.rs 0 → 100644 +49 −0 Original line number Original line Diff line number Diff line #pragma version(1) #include "../../../../scriptc/rs_types.rsh" #include "../../../../scriptc/rs_math.rsh" #include "../../../../scriptc/rs_graphics.rsh" typedef struct Params_s{ int inHeight; int inWidth; int outHeight; int outWidth; float threshold; } Params_t; Params_t * Params; rs_color4u * InPixel; rs_color4u * OutPixel; int main() { int t = uptimeMillis(); rs_color4u *in = InPixel; rs_color4u *out = OutPixel; int count = Params->inWidth * Params->inHeight; int i; float threshold = Params->threshold * 255.f; for (i = 0; i < count; i++) { float luminance = 0.2125f * in->x + 0.7154f * in->y + 0.0721f * in->z; if (luminance > threshold) { *out = *in; } else { *((int *)out) = *((int *)in) & 0xff000000; } in++; out++; } t= uptimeMillis() - t; debugI32("Filter time", t); sendToClient(&count, 1, 4, 0); return 0; }