summaryrefslogtreecommitdiffstats
path: root/docs/html/reference/renderscript/rs__math_8rsh_source.html
blob: 513ce48dddd6b57a6815c9bf166915ba812f1744 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>

<title>/usr/local/google/home/srhines/android_trees/jb-mr2-dev/frameworks/rs/scriptc/rs_math.rsh Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="top"><!-- do not remove this div! -->


<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Overview</span></a></li>
      <li class="current"><a href="globals.html"><span>Globals</span></a></li>
      <li><a href="annotated.html"><span>Structs</span></a></li>
    </ul>
  </div>
<div class="header">
  <div class="headertitle">
<div class="title">/usr/local/google/home/srhines/android_trees/jb-mr2-dev/frameworks/rs/scriptc/rs_math.rsh</div>  </div>
</div>
<div class="contents">
<a href="rs__math_8rsh.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2011 The Android Open Source Project</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<a name="l00005"></a>00005 <span class="comment"> * you may not use this file except in compliance with the License.</span>
<a name="l00006"></a>00006 <span class="comment"> * You may obtain a copy of the License at</span>
<a name="l00007"></a>00007 <span class="comment"> *</span>
<a name="l00008"></a>00008 <span class="comment"> *      http://www.apache.org/licenses/LICENSE-2.0</span>
<a name="l00009"></a>00009 <span class="comment"> *</span>
<a name="l00010"></a>00010 <span class="comment"> * Unless required by applicable law or agreed to in writing, software</span>
<a name="l00011"></a>00011 <span class="comment"> * distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<a name="l00012"></a>00012 <span class="comment"> * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<a name="l00013"></a>00013 <span class="comment"> * See the License for the specific language governing permissions and</span>
<a name="l00014"></a>00014 <span class="comment"> * limitations under the License.</span>
<a name="l00015"></a>00015 <span class="comment"> */</span>
<a name="l00016"></a>00016 
<a name="l00024"></a>00024 <span class="preprocessor">#ifndef __RS_MATH_RSH__</span>
<a name="l00025"></a>00025 <span class="preprocessor"></span><span class="preprocessor">#define __RS_MATH_RSH__</span>
<a name="l00026"></a>00026 <span class="preprocessor"></span>
<a name="l00027"></a>00027 
<a name="l00031"></a>00031 <span class="keyword">extern</span> <span class="keywordtype">int</span> __attribute__((overloadable))
<a name="l00032"></a>00032     <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">int</span> max_value);
<a name="l00036"></a>00036 extern <span class="keywordtype">int</span> __attribute__((overloadable))
<a name="l00037"></a>00037     <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">int</span> min_value, <span class="keywordtype">int</span> max_value);
<a name="l00041"></a>00041 extern <span class="keywordtype">float</span> __attribute__((overloadable))
<a name="l00042"></a>00042     <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">float</span> max_value);
<a name="l00046"></a>00046 extern <span class="keywordtype">float</span> __attribute__((overloadable))
<a name="l00047"></a>00047     <a class="code" href="rs__math_8rsh.html#ad9106e5aae5b1248870f21061f36a1c9">rsRand</a>(<span class="keywordtype">float</span> min_value, <span class="keywordtype">float</span> max_value);
<a name="l00048"></a>00048 
<a name="l00052"></a>00052 extern <span class="keywordtype">float</span> __attribute__((overloadable))
<a name="l00053"></a>00053     <a class="code" href="rs__math_8rsh.html#ac4f127e78da0849321c7f6db14f9e989">rsFrac</a>(<span class="keywordtype">float</span>);
<a name="l00054"></a>00054 
<a name="l00055"></a>00055 
<a name="l00057"></a>00057 <span class="comment">// int ops</span>
<a name="l00059"></a>00059 <span class="comment"></span>
<a name="l00067"></a>00067 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> amount, <a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> low, <a class="code" href="rs__types_8rsh.html#a4f5fce8c1ef282264f9214809524d836">uint</a> high);
<a name="l00068"></a>00068 
<a name="l00072"></a>00072 _RS_RUNTIME <span class="keywordtype">int</span> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<span class="keywordtype">int</span> amount, <span class="keywordtype">int</span> low, <span class="keywordtype">int</span> high);
<a name="l00076"></a>00076 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> amount, <a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> low, <a class="code" href="rs__types_8rsh.html#a9e58a7bf060b7a5fbf6a401d3020adca">ushort</a> high);
<a name="l00080"></a>00080 _RS_RUNTIME <span class="keywordtype">short</span> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<span class="keywordtype">short</span> amount, <span class="keywordtype">short</span> low, <span class="keywordtype">short</span> high);
<a name="l00084"></a>00084 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> amount, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> low, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> high);
<a name="l00088"></a>00088 _RS_RUNTIME <span class="keywordtype">char</span> __attribute__((overloadable, always_inline)) <a class="code" href="rs__math_8rsh.html#a5de277f7518a61646c3d74f3a0b9e893">rsClamp</a>(<span class="keywordtype">char</span> amount, <span class="keywordtype">char</span> low, <span class="keywordtype">char</span> high);
<a name="l00089"></a>00089 
<a name="l00090"></a>00090 
<a name="l00101"></a>00101 __inline__ static <span class="keywordtype">void</span> __attribute__((overloadable, always_inline))
<a name="l00102"></a><a class="code" href="rs__math_8rsh.html#a191f9c687c56322c18b7d71491602122">00102</a> <a class="code" href="rs__math_8rsh.html#a191f9c687c56322c18b7d71491602122">rsExtractFrustumPlanes</a>(const <a class="code" href="structrs__matrix4x4.html" title="4x4 float matrix">rs_matrix4x4</a> *viewProj,
<a name="l00103"></a>00103                          <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *left, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *right,
<a name="l00104"></a>00104                          <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *top, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *bottom,
<a name="l00105"></a>00105                          <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *near, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *far) {
<a name="l00106"></a>00106     <span class="comment">// x y z w = a b c d in the plane equation</span>
<a name="l00107"></a>00107     left-&gt;x = viewProj-&gt;m[3] + viewProj-&gt;m[0];
<a name="l00108"></a>00108     left-&gt;y = viewProj-&gt;m[7] + viewProj-&gt;m[4];
<a name="l00109"></a>00109     left-&gt;z = viewProj-&gt;m[11] + viewProj-&gt;m[8];
<a name="l00110"></a>00110     left-&gt;w = viewProj-&gt;m[15] + viewProj-&gt;m[12];
<a name="l00111"></a>00111 
<a name="l00112"></a>00112     right-&gt;x = viewProj-&gt;m[3] - viewProj-&gt;m[0];
<a name="l00113"></a>00113     right-&gt;y = viewProj-&gt;m[7] - viewProj-&gt;m[4];
<a name="l00114"></a>00114     right-&gt;z = viewProj-&gt;m[11] - viewProj-&gt;m[8];
<a name="l00115"></a>00115     right-&gt;w = viewProj-&gt;m[15] - viewProj-&gt;m[12];
<a name="l00116"></a>00116 
<a name="l00117"></a>00117     top-&gt;x = viewProj-&gt;m[3] - viewProj-&gt;m[1];
<a name="l00118"></a>00118     top-&gt;y = viewProj-&gt;m[7] - viewProj-&gt;m[5];
<a name="l00119"></a>00119     top-&gt;z = viewProj-&gt;m[11] - viewProj-&gt;m[9];
<a name="l00120"></a>00120     top-&gt;w = viewProj-&gt;m[15] - viewProj-&gt;m[13];
<a name="l00121"></a>00121 
<a name="l00122"></a>00122     bottom-&gt;x = viewProj-&gt;m[3] + viewProj-&gt;m[1];
<a name="l00123"></a>00123     bottom-&gt;y = viewProj-&gt;m[7] + viewProj-&gt;m[5];
<a name="l00124"></a>00124     bottom-&gt;z = viewProj-&gt;m[11] + viewProj-&gt;m[9];
<a name="l00125"></a>00125     bottom-&gt;w = viewProj-&gt;m[15] + viewProj-&gt;m[13];
<a name="l00126"></a>00126 
<a name="l00127"></a>00127     near-&gt;x = viewProj-&gt;m[3] + viewProj-&gt;m[2];
<a name="l00128"></a>00128     near-&gt;y = viewProj-&gt;m[7] + viewProj-&gt;m[6];
<a name="l00129"></a>00129     near-&gt;z = viewProj-&gt;m[11] + viewProj-&gt;m[10];
<a name="l00130"></a>00130     near-&gt;w = viewProj-&gt;m[15] + viewProj-&gt;m[14];
<a name="l00131"></a>00131 
<a name="l00132"></a>00132     far-&gt;x = viewProj-&gt;m[3] - viewProj-&gt;m[2];
<a name="l00133"></a>00133     far-&gt;y = viewProj-&gt;m[7] - viewProj-&gt;m[6];
<a name="l00134"></a>00134     far-&gt;z = viewProj-&gt;m[11] - viewProj-&gt;m[10];
<a name="l00135"></a>00135     far-&gt;w = viewProj-&gt;m[15] - viewProj-&gt;m[14];
<a name="l00136"></a>00136 
<a name="l00137"></a>00137     <span class="keywordtype">float</span> len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(left-&gt;xyz);
<a name="l00138"></a>00138     *left /= len;
<a name="l00139"></a>00139     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(right-&gt;xyz);
<a name="l00140"></a>00140     *right /= len;
<a name="l00141"></a>00141     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(top-&gt;xyz);
<a name="l00142"></a>00142     *top /= len;
<a name="l00143"></a>00143     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(bottom-&gt;xyz);
<a name="l00144"></a>00144     *bottom /= len;
<a name="l00145"></a>00145     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(near-&gt;xyz);
<a name="l00146"></a>00146     *near /= len;
<a name="l00147"></a>00147     len = <a class="code" href="rs__cl_8rsh.html#a902d4d2fab31ba8f9631b1f681e99baa">length</a>(far-&gt;xyz);
<a name="l00148"></a>00148     *far /= len;
<a name="l00149"></a>00149 }
<a name="l00150"></a>00150 
<a name="l00161"></a>00161 __inline__ <span class="keyword">static</span> <span class="keywordtype">bool</span> __attribute__((overloadable, always_inline))
<a name="l00162"></a><a class="code" href="rs__math_8rsh.html#a7bbeaf44838e08e68d5cf3e3d7b0818c">00162</a> <a class="code" href="rs__math_8rsh.html#a7bbeaf44838e08e68d5cf3e3d7b0818c">rsIsSphereInFrustum</a>(<a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *sphere,
<a name="l00163"></a>00163                       <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *left, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *right,
<a name="l00164"></a>00164                       <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *top, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *bottom,
<a name="l00165"></a>00165                       <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *near, <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> *far) {
<a name="l00166"></a>00166 
<a name="l00167"></a>00167     <span class="keywordtype">float</span> distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(left-&gt;xyz, sphere-&gt;xyz) + left-&gt;w;
<a name="l00168"></a>00168     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
<a name="l00169"></a>00169         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00170"></a>00170     }
<a name="l00171"></a>00171     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(right-&gt;xyz, sphere-&gt;xyz) + right-&gt;w;
<a name="l00172"></a>00172     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
<a name="l00173"></a>00173         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00174"></a>00174     }
<a name="l00175"></a>00175     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(top-&gt;xyz, sphere-&gt;xyz) + top-&gt;w;
<a name="l00176"></a>00176     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
<a name="l00177"></a>00177         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00178"></a>00178     }
<a name="l00179"></a>00179     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(bottom-&gt;xyz, sphere-&gt;xyz) + bottom-&gt;w;
<a name="l00180"></a>00180     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
<a name="l00181"></a>00181         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00182"></a>00182     }
<a name="l00183"></a>00183     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(near-&gt;xyz, sphere-&gt;xyz) + near-&gt;w;
<a name="l00184"></a>00184     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
<a name="l00185"></a>00185         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00186"></a>00186     }
<a name="l00187"></a>00187     distToCenter = <a class="code" href="rs__cl_8rsh.html#aa26d85eac3067e9769b33b6914b180f2">dot</a>(far-&gt;xyz, sphere-&gt;xyz) + far-&gt;w;
<a name="l00188"></a>00188     <span class="keywordflow">if</span> (distToCenter &lt; -sphere-&gt;w) {
<a name="l00189"></a>00189         <span class="keywordflow">return</span> <span class="keyword">false</span>;
<a name="l00190"></a>00190     }
<a name="l00191"></a>00191     <span class="keywordflow">return</span> <span class="keyword">true</span>;
<a name="l00192"></a>00192 }
<a name="l00193"></a>00193 
<a name="l00194"></a>00194 
<a name="l00205"></a>00205 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<span class="keywordtype">float</span> r, <span class="keywordtype">float</span> g, <span class="keywordtype">float</span> b);
<a name="l00206"></a>00206 
<a name="l00217"></a>00217 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<span class="keywordtype">float</span> r, <span class="keywordtype">float</span> g, <span class="keywordtype">float</span> b, <span class="keywordtype">float</span> a);
<a name="l00218"></a>00218 
<a name="l00227"></a>00227 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<a class="code" href="rs__types_8rsh.html#a0046fa0f208d0899adbcf1f8b5aafadd">float3</a> color);
<a name="l00228"></a>00228 
<a name="l00236"></a>00236 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) <a class="code" href="rs__math_8rsh.html#a5e20d326a6e2532d19a493b01f948c17">rsPackColorTo8888</a>(<a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> color);
<a name="l00237"></a>00237 
<a name="l00245"></a>00245 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> <a class="code" href="rs__math_8rsh.html#a48bb0c2e7b1f2b62b2a8970c7d709eca">rsUnpackColor8888</a>(<a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> c);
<a name="l00246"></a>00246 
<a name="l00247"></a>00247 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#ae6ed52a87d4ff920c303b13b00f7396d">uchar4</a> __attribute__((overloadable)) rsYuvToRGBA_uchar4(<a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> y, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> u, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> v);
<a name="l00248"></a>00248 _RS_RUNTIME <a class="code" href="rs__types_8rsh.html#adb5162dc168ddd471d948faa60b37c5e">float4</a> __attribute__((overloadable)) rsYuvToRGBA_float4(<a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> y, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> u, <a class="code" href="rs__types_8rsh.html#a27c902d5ca78afa82d5ed75554d5cedc">uchar</a> v);
<a name="l00249"></a>00249 
<a name="l00250"></a>00250 
<a name="l00251"></a>00251 <span class="preprocessor">#endif</span>
</pre></div></div>
</div>

</body>
</html>