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