summaryrefslogtreecommitdiffstats
path: root/libs/rs/rsScriptC_Lib.cpp
diff options
context:
space:
mode:
authorRomain Guy <romainguy@android.com>2009-10-09 16:05:25 -0700
committerRomain Guy <romainguy@android.com>2009-10-09 16:05:25 -0700
commitd7fa122dfed376cd9c60eac516e2730acf23f3dd (patch)
tree6648be549b3a01bfaa8dfccb3ae4344ab1b21f65 /libs/rs/rsScriptC_Lib.cpp
parent98e0b146b80670b52805b4b210ef5582dad6bb68 (diff)
downloadframeworks_base-d7fa122dfed376cd9c60eac516e2730acf23f3dd.zip
frameworks_base-d7fa122dfed376cd9c60eac516e2730acf23f3dd.tar.gz
frameworks_base-d7fa122dfed376cd9c60eac516e2730acf23f3dd.tar.bz2
Add new RenderScript sample: ImageProcessing.
Change-Id: I5e482bbc34911c940a3a74258f8f8549b1939bc4
Diffstat (limited to 'libs/rs/rsScriptC_Lib.cpp')
-rw-r--r--libs/rs/rsScriptC_Lib.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 436f48b..5aef56d 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -227,6 +227,53 @@ static void SC_vec3Scale(vec3_t *lhs, float scale)
lhs->z *= scale;
}
+//////////////////////////////////////////////////////////////////////////////
+// Vec4 routines
+//////////////////////////////////////////////////////////////////////////////
+
+static void SC_vec4Norm(vec4_t *v)
+{
+ float len = sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
+ len = 1 / len;
+ v->x *= len;
+ v->y *= len;
+ v->z *= len;
+ v->w *= len;
+}
+
+static float SC_vec4Length(const vec4_t *v)
+{
+ return sqrtf(v->x * v->x + v->y * v->y + v->z * v->z + v->w * v->w);
+}
+
+static void SC_vec4Add(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
+{
+ dest->x = lhs->x + rhs->x;
+ dest->y = lhs->y + rhs->y;
+ dest->z = lhs->z + rhs->z;
+ dest->w = lhs->w + rhs->w;
+}
+
+static void SC_vec4Sub(vec4_t *dest, const vec4_t *lhs, const vec4_t *rhs)
+{
+ dest->x = lhs->x - rhs->x;
+ dest->y = lhs->y - rhs->y;
+ dest->z = lhs->z - rhs->z;
+ dest->w = lhs->w - rhs->w;
+}
+
+static float SC_vec4Dot(const vec4_t *lhs, const vec4_t *rhs)
+{
+ return lhs->x * rhs->x + lhs->y * rhs->y + lhs->z * rhs->z + lhs->w * rhs->w;
+}
+
+static void SC_vec4Scale(vec4_t *lhs, float scale)
+{
+ lhs->x *= scale;
+ lhs->y *= scale;
+ lhs->z *= scale;
+ lhs->w *= scale;
+}
//////////////////////////////////////////////////////////////////////////////
// Math routines
@@ -286,6 +333,16 @@ static float SC_randf2(float min, float max)
return r / RAND_MAX * (max - min) + min;
}
+static int SC_sign(int value)
+{
+ return (value > 0) - (value < 0);
+}
+
+static float SC_signf(float value)
+{
+ return (value > 0) - (value < 0);
+}
+
static float SC_clampf(float amount, float low, float high)
{
return amount < low ? low : (amount > high ? high : amount);
@@ -1103,6 +1160,10 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
"int", "(int)" },
{ "sqrf", (void *)&SC_sqrf,
"float", "(float)" },
+ { "sign", (void *)&SC_sign,
+ "int", "(int)" },
+ { "signf", (void *)&SC_signf,
+ "float", "(float)" },
{ "clamp", (void *)&SC_clamp,
"int", "(int, int, int)" },
{ "clampf", (void *)&SC_clampf,
@@ -1200,6 +1261,20 @@ ScriptCState::SymbolTable_t ScriptCState::gSyms[] = {
{ "vec3Scale", (void *)&SC_vec3Scale,
"void", "(struct vec3_s *lhs, float scale)" },
+ // vec4
+ { "vec4Norm", (void *)&SC_vec4Norm,
+ "void", "(struct vec4_s *)" },
+ { "vec4Length", (void *)&SC_vec4Length,
+ "float", "(struct vec4_s *)" },
+ { "vec4Add", (void *)&SC_vec4Add,
+ "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
+ { "vec4Sub", (void *)&SC_vec4Sub,
+ "void", "(struct vec4_s *dest, struct vec4_s *lhs, struct vec4_s *rhs)" },
+ { "vec4Dot", (void *)&SC_vec4Dot,
+ "float", "(struct vec4_s *lhs, struct vec4_s *rhs)" },
+ { "vec4Scale", (void *)&SC_vec4Scale,
+ "void", "(struct vec4_s *lhs, float scale)" },
+
// context
{ "bindProgramFragment", (void *)&SC_bindProgramFragment,
"void", "(int)" },