blob: aca4e645f10215f37ea4b31b262f7fa2b1ede7a1 [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
Jason Sams25430d02010-02-02 15:26:40 -080019
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070020/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070021 * Class for exposing the native RenderScript byte3 type back to the Android system.
Jason Sams25430d02010-02-02 15:26:40 -080022 *
Xusong Wang8b4548c2021-01-05 10:09:52 -080023 * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
24 * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
25 * guide</a> for the proposed alternatives.
Jason Sams25430d02010-02-02 15:26:40 -080026 **/
Xusong Wang8b4548c2021-01-05 10:09:52 -080027@Deprecated
Jason Samsa70f4162010-03-26 15:33:42 -070028public class Byte3 {
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050029 public byte x;
30 public byte y;
31 public byte z;
32
Jason Samsa70f4162010-03-26 15:33:42 -070033 public Byte3() {
Jason Sams25430d02010-02-02 15:26:40 -080034 }
35
Jason Sams6cc888e2011-04-22 17:05:25 -070036 public Byte3(byte initX, byte initY, byte initZ) {
37 x = initX;
38 y = initY;
39 z = initZ;
40 }
41
Matthieu Delahaye6a5875c2013-09-10 15:11:35 -050042 /** @hide */
43 public Byte3(Byte3 source) {
44 this.x = source.x;
45 this.y = source.y;
46 this.z = source.z;
47 }
48
49 /** @hide
50 * Vector add
51 *
52 * @param a
53 */
54 public void add(Byte3 a) {
55 this.x += a.x;
56 this.y += a.y;
57 this.z += a.z;
58 }
59
60 /** @hide
61 * Vector add
62 *
63 * @param a
64 * @param b
65 * @return
66 */
67 public static Byte3 add(Byte3 a, Byte3 b) {
68 Byte3 result = new Byte3();
69 result.x = (byte)(a.x + b.x);
70 result.y = (byte)(a.y + b.y);
71 result.z = (byte)(a.z + b.z);
72
73 return result;
74 }
75
76 /** @hide
77 * Vector add
78 *
79 * @param value
80 */
81 public void add(byte value) {
82 x += value;
83 y += value;
84 z += value;
85 }
86
87 /** @hide
88 * Vector add
89 *
90 * @param a
91 * @param b
92 * @return
93 */
94 public static Byte3 add(Byte3 a, byte b) {
95 Byte3 result = new Byte3();
96 result.x = (byte)(a.x + b);
97 result.y = (byte)(a.y + b);
98 result.z = (byte)(a.z + b);
99
100 return result;
101 }
102
103 /** @hide
104 * Vector subtraction
105 *
106 * @param a
107 */
108 public void sub(Byte3 a) {
109 this.x -= a.x;
110 this.y -= a.y;
111 this.z -= a.z;
112 }
113
114 /** @hide
115 * Vector subtraction
116 *
117 * @param a
118 * @param b
119 * @return
120 */
121 public static Byte3 sub(Byte3 a, Byte3 b) {
122 Byte3 result = new Byte3();
123 result.x = (byte)(a.x - b.x);
124 result.y = (byte)(a.y - b.y);
125 result.z = (byte)(a.z - b.z);
126
127 return result;
128 }
129
130 /** @hide
131 * Vector subtraction
132 *
133 * @param value
134 */
135 public void sub(byte value) {
136 x -= value;
137 y -= value;
138 z -= value;
139 }
140
141 /** @hide
142 * Vector subtraction
143 *
144 * @param a
145 * @param b
146 * @return
147 */
148 public static Byte3 sub(Byte3 a, byte b) {
149 Byte3 result = new Byte3();
150 result.x = (byte)(a.x - b);
151 result.y = (byte)(a.y - b);
152 result.z = (byte)(a.z - b);
153
154 return result;
155 }
156
157 /** @hide
158 * Vector multiplication
159 *
160 * @param a
161 */
162 public void mul(Byte3 a) {
163 this.x *= a.x;
164 this.y *= a.y;
165 this.z *= a.z;
166 }
167
168 /** @hide
169 * Vector multiplication
170 *
171 * @param a
172 * @param b
173 * @return
174 */
175 public static Byte3 mul(Byte3 a, Byte3 b) {
176 Byte3 result = new Byte3();
177 result.x = (byte)(a.x * b.x);
178 result.y = (byte)(a.y * b.y);
179 result.z = (byte)(a.z * b.z);
180
181 return result;
182 }
183
184 /** @hide
185 * Vector multiplication
186 *
187 * @param value
188 */
189 public void mul(byte value) {
190 x *= value;
191 y *= value;
192 z *= value;
193 }
194
195 /** @hide
196 * Vector multiplication
197 *
198 * @param a
199 * @param b
200 * @return
201 */
202 public static Byte3 mul(Byte3 a, byte b) {
203 Byte3 result = new Byte3();
204 result.x = (byte)(a.x * b);
205 result.y = (byte)(a.y * b);
206 result.z = (byte)(a.z * b);
207
208 return result;
209 }
210
211 /** @hide
212 * Vector division
213 *
214 * @param a
215 */
216 public void div(Byte3 a) {
217 this.x /= a.x;
218 this.y /= a.y;
219 this.z /= a.z;
220 }
221
222 /** @hide
223 * Vector division
224 *
225 * @param a
226 * @param b
227 * @return
228 */
229 public static Byte3 div(Byte3 a, Byte3 b) {
230 Byte3 result = new Byte3();
231 result.x = (byte)(a.x / b.x);
232 result.y = (byte)(a.y / b.y);
233 result.z = (byte)(a.z / b.z);
234
235 return result;
236 }
237
238 /** @hide
239 * Vector division
240 *
241 * @param value
242 */
243 public void div(byte value) {
244 x /= value;
245 y /= value;
246 z /= value;
247 }
248
249 /** @hide
250 * Vector division
251 *
252 * @param a
253 * @param b
254 * @return
255 */
256 public static Byte3 div(Byte3 a, byte b) {
257 Byte3 result = new Byte3();
258 result.x = (byte)(a.x / b);
259 result.y = (byte)(a.y / b);
260 result.z = (byte)(a.z / b);
261
262 return result;
263 }
264
265 /** @hide
266 * get vector length
267 *
268 * @return
269 */
270 public byte length() {
271 return 3;
272 }
273
274 /** @hide
275 * set vector negate
276 */
277 public void negate() {
278 this.x = (byte)(-x);
279 this.y = (byte)(-y);
280 this.z = (byte)(-z);
281 }
282
283 /** @hide
284 * Vector dot Product
285 *
286 * @param a
287 * @return
288 */
289 public byte dotProduct(Byte3 a) {
290 return (byte)((byte)((byte)(x * a.x) + (byte)(y * a.y)) + (byte)(z * a.z));
291 }
292
293 /** @hide
294 * Vector dot Product
295 *
296 * @param a
297 * @param b
298 * @return
299 */
300 public static byte dotProduct(Byte3 a, Byte3 b) {
301 return (byte)((byte)((byte)(b.x * a.x) + (byte)(b.y * a.y)) + (byte)(b.z * a.z));
302 }
303
304 /** @hide
305 * Vector add Multiple
306 *
307 * @param a
308 * @param factor
309 */
310 public void addMultiple(Byte3 a, byte factor) {
311 x += a.x * factor;
312 y += a.y * factor;
313 z += a.z * factor;
314 }
315
316 /** @hide
317 * set vector value by Byte3
318 *
319 * @param a
320 */
321 public void set(Byte3 a) {
322 this.x = a.x;
323 this.y = a.y;
324 this.z = a.z;
325 }
326
327 /** @hide
328 * set the vector field value by Char
329 *
330 * @param a
331 * @param b
332 * @param c
333 */
334 public void setValues(byte a, byte b, byte c) {
335 this.x = a;
336 this.y = b;
337 this.z = c;
338 }
339
340 /** @hide
341 * return the element sum of vector
342 *
343 * @return
344 */
345 public byte elementSum() {
346 return (byte)(x + y + z);
347 }
348
349 /** @hide
350 * get the vector field value by index
351 *
352 * @param i
353 * @return
354 */
355 public byte get(int i) {
356 switch (i) {
357 case 0:
358 return x;
359 case 1:
360 return y;
361 case 2:
362 return z;
363 default:
364 throw new IndexOutOfBoundsException("Index: i");
365 }
366 }
367
368 /** @hide
369 * set the vector field value by index
370 *
371 * @param i
372 * @param value
373 */
374 public void setAt(int i, byte value) {
375 switch (i) {
376 case 0:
377 x = value;
378 return;
379 case 1:
380 y = value;
381 return;
382 case 2:
383 z = value;
384 return;
385 default:
386 throw new IndexOutOfBoundsException("Index: i");
387 }
388 }
389
390 /** @hide
391 * add the vector field value by index
392 *
393 * @param i
394 * @param value
395 */
396 public void addAt(int i, byte value) {
397 switch (i) {
398 case 0:
399 x += value;
400 return;
401 case 1:
402 y += value;
403 return;
404 case 2:
405 z += value;
406 return;
407 default:
408 throw new IndexOutOfBoundsException("Index: i");
409 }
410 }
411
412 /** @hide
413 * copy the vector to Char array
414 *
415 * @param data
416 * @param offset
417 */
418 public void copyTo(byte[] data, int offset) {
419 data[offset] = x;
420 data[offset + 1] = y;
421 data[offset + 2] = z;
422 }
Jason Sams25430d02010-02-02 15:26:40 -0800423}
424
425
426
427