blob: b8a8a6b1ebfa2425f17167b71bffdc4cdad05e2f [file] [log] [blame]
Jason Sams25430d02010-02-02 15:26:40 -08001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.renderscript;
18
19import java.lang.Math;
20import android.util.Log;
21
22
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070023/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070024 * Class for exposing the native RenderScript byte4 type back to the Android system.
Jason Sams25430d02010-02-02 15:26:40 -080025 *
26 **/
Jason Samsa70f4162010-03-26 15:33:42 -070027public class Byte4 {
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050028 public byte x;
29 public byte y;
30 public byte z;
31 public byte w;
32
Jason Samsa70f4162010-03-26 15:33:42 -070033 public Byte4() {
Jason Sams25430d02010-02-02 15:26:40 -080034 }
35
Jason Sams6cc888e2011-04-22 17:05:25 -070036 public Byte4(byte initX, byte initY, byte initZ, byte initW) {
37 x = initX;
38 y = initY;
39 z = initZ;
40 w = initW;
41 }
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050042 /** @hide */
43 public Byte4(Byte4 source) {
44 this.x = source.x;
45 this.y = source.y;
46 this.z = source.z;
47 this.w = source.w;
48 }
Jason Sams6cc888e2011-04-22 17:05:25 -070049
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050050 /** @hide
51 * Vector add
52 *
53 * @param a
54 */
55 public void add(Byte4 a) {
56 this.x += a.x;
57 this.y += a.y;
58 this.z += a.z;
59 this.w += a.w;
60 }
61
62 /** @hide
63 * Vector add
64 *
65 * @param a
66 * @param b
67 * @return
68 */
69 public static Byte4 add(Byte4 a, Byte4 b) {
70 Byte4 result = new Byte4();
71 result.x = (byte)(a.x + b.x);
72 result.y = (byte)(a.y + b.y);
73 result.z = (byte)(a.z + b.z);
74 result.w = (byte)(a.w + b.w);
75
76 return result;
77 }
78
79 /** @hide
80 * Vector add
81 *
82 * @param value
83 */
84 public void add(byte value) {
85 x += value;
86 y += value;
87 z += value;
88 w += value;
89 }
90
91 /** @hide
92 * Vector add
93 *
94 * @param a
95 * @param b
96 * @return
97 */
98 public static Byte4 add(Byte4 a, byte b) {
99 Byte4 result = new Byte4();
100 result.x = (byte)(a.x + b);
101 result.y = (byte)(a.y + b);
102 result.z = (byte)(a.z + b);
103 result.w = (byte)(a.w + b);
104
105 return result;
106 }
107
108 /** @hide
109 * Vector subtraction
110 *
111 * @param a
112 */
113 public void sub(Byte4 a) {
114 this.x -= a.x;
115 this.y -= a.y;
116 this.z -= a.z;
117 this.w -= a.w;
118 }
119
120 /** @hide
121 * Vector subtraction
122 *
123 * @param a
124 * @param b
125 * @return
126 */
127 public static Byte4 sub(Byte4 a, Byte4 b) {
128 Byte4 result = new Byte4();
129 result.x = (byte)(a.x - b.x);
130 result.y = (byte)(a.y - b.y);
131 result.z = (byte)(a.z - b.z);
132 result.w = (byte)(a.w - b.w);
133
134 return result;
135 }
136
137 /** @hide
138 * Vector subtraction
139 *
140 * @param value
141 */
142 public void sub(byte value) {
143 x -= value;
144 y -= value;
145 z -= value;
146 w -= value;
147 }
148
149 /** @hide
150 * Vector subtraction
151 *
152 * @param a
153 * @param b
154 * @return
155 */
156 public static Byte4 sub(Byte4 a, byte b) {
157 Byte4 result = new Byte4();
158 result.x = (byte)(a.x - b);
159 result.y = (byte)(a.y - b);
160 result.z = (byte)(a.z - b);
161 result.w = (byte)(a.w - b);
162
163 return result;
164 }
165
166 /** @hide
167 * Vector multiplication
168 *
169 * @param a
170 */
171 public void mul(Byte4 a) {
172 this.x *= a.x;
173 this.y *= a.y;
174 this.z *= a.z;
175 this.w *= a.w;
176 }
177
178 /** @hide
179 * Vector multiplication
180 *
181 * @param a
182 * @param b
183 * @return
184 */
185 public static Byte4 mul(Byte4 a, Byte4 b) {
186 Byte4 result = new Byte4();
187 result.x = (byte)(a.x * b.x);
188 result.y = (byte)(a.y * b.y);
189 result.z = (byte)(a.z * b.z);
190 result.w = (byte)(a.w * b.w);
191
192 return result;
193 }
194
195 /** @hide
196 * Vector multiplication
197 *
198 * @param value
199 */
200 public void mul(byte value) {
201 x *= value;
202 y *= value;
203 z *= value;
204 w *= value;
205 }
206
207 /** @hide
208 * Vector multiplication
209 *
210 * @param a
211 * @param b
212 * @return
213 */
214 public static Byte4 mul(Byte4 a, byte b) {
215 Byte4 result = new Byte4();
216 result.x = (byte)(a.x * b);
217 result.y = (byte)(a.y * b);
218 result.z = (byte)(a.z * b);
219 result.w = (byte)(a.w * b);
220
221 return result;
222 }
223
224 /** @hide
225 * Vector division
226 *
227 * @param a
228 */
229 public void div(Byte4 a) {
230 this.x /= a.x;
231 this.y /= a.y;
232 this.z /= a.z;
233 this.w /= a.w;
234 }
235
236 /** @hide
237 * Vector division
238 *
239 * @param a
240 * @param b
241 * @return
242 */
243 public static Byte4 div(Byte4 a, Byte4 b) {
244 Byte4 result = new Byte4();
245 result.x = (byte)(a.x / b.x);
246 result.y = (byte)(a.y / b.y);
247 result.z = (byte)(a.z / b.z);
248 result.w = (byte)(a.w / b.w);
249
250 return result;
251 }
252
253 /** @hide
254 * Vector division
255 *
256 * @param value
257 */
258 public void div(byte value) {
259 x /= value;
260 y /= value;
261 z /= value;
262 w /= value;
263 }
264
265 /** @hide
266 * Vector division
267 *
268 * @param a
269 * @param b
270 * @return
271 */
272 public static Byte4 div(Byte4 a, byte b) {
273 Byte4 result = new Byte4();
274 result.x = (byte)(a.x / b);
275 result.y = (byte)(a.y / b);
276 result.z = (byte)(a.z / b);
277 result.w = (byte)(a.w / b);
278
279 return result;
280 }
281
282 /** @hide
283 * get vector length
284 *
285 * @return
286 */
287 public byte length() {
288 return 4;
289 }
290
291 /** @hide
292 * set vector negate
293 */
294 public void negate() {
295 this.x = (byte)(-x);
296 this.y = (byte)(-y);
297 this.z = (byte)(-z);
298 this.w = (byte)(-w);
299 }
300
301 /** @hide
302 * Vector dot Product
303 *
304 * @param a
305 * @return
306 */
307 public byte dotProduct(Byte4 a) {
308 return (byte)((x * a.x) + (y * a.y) + (z * a.z) + (w * a.w));
309 }
310
311 /** @hide
312 * Vector dot Product
313 *
314 * @param a
315 * @param b
316 * @return
317 */
318 public static byte dotProduct(Byte4 a, Byte4 b) {
319 return (byte)((b.x * a.x) + (b.y * a.y) + (b.z * a.z) + (b.w * a.w));
320 }
321
322 /** @hide
323 * Vector add Multiple
324 *
325 * @param a
326 * @param factor
327 */
328 public void addMultiple(Byte4 a, byte factor) {
329 x += a.x * factor;
330 y += a.y * factor;
331 z += a.z * factor;
332 w += a.w * factor;
333 }
334
335 /** @hide
336 * set vector value by Byte4
337 *
338 * @param a
339 */
340 public void set(Byte4 a) {
341 this.x = a.x;
342 this.y = a.y;
343 this.z = a.z;
344 this.w = a.w;
345 }
346
347 /** @hide
348 * set the vector field values
349 *
350 * @param a
351 * @param b
352 * @param c
353 * @param d
354 */
355 public void setValues(byte a, byte b, byte c, byte d) {
356 this.x = a;
357 this.y = b;
358 this.z = c;
359 this.w = d;
360 }
361
362 /** @hide
363 * return the element sum of vector
364 *
365 * @return
366 */
367 public byte elementSum() {
368 return (byte)(x + y + z + w);
369 }
370
371 /** @hide
372 * get the vector field value by index
373 *
374 * @param i
375 * @return
376 */
377 public byte get(int i) {
378 switch (i) {
379 case 0:
380 return x;
381 case 1:
382 return y;
383 case 2:
384 return z;
385 case 3:
386 return w;
387 default:
388 throw new IndexOutOfBoundsException("Index: i");
389 }
390 }
391
392 /** @hide
393 * set the vector field value by index
394 *
395 * @param i
396 * @param value
397 */
398 public void setAt(int i, byte value) {
399 switch (i) {
400 case 0:
401 x = value;
402 return;
403 case 1:
404 y = value;
405 return;
406 case 2:
407 z = value;
408 return;
409 case 3:
410 w = value;
411 return;
412 default:
413 throw new IndexOutOfBoundsException("Index: i");
414 }
415 }
416
417 /** @hide
418 * add the vector field value by index
419 *
420 * @param i
421 * @param value
422 */
423 public void addAt(int i, byte value) {
424 switch (i) {
425 case 0:
426 x += value;
427 return;
428 case 1:
429 y += value;
430 return;
431 case 2:
432 z += value;
433 return;
434 case 3:
435 w += value;
436 return;
437 default:
438 throw new IndexOutOfBoundsException("Index: i");
439 }
440 }
441
442 /** @hide
443 * copy the vector to Char array
444 *
445 * @param data
446 * @param offset
447 */
448 public void copyTo(byte[] data, int offset) {
449 data[offset] = x;
450 data[offset + 1] = y;
451 data[offset + 2] = z;
452 data[offset + 3] = w;
453 }
Jason Sams25430d02010-02-02 15:26:40 -0800454}
455
456
457