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