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