1 /* 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 17 package android.renderscript; 18 19 20 /** 21 * Class for exposing the native RenderScript byte2 type back to the Android system. 22 * 23 * @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. 26 **/ 27 @Deprecated 28 public class Byte2 { 29 public byte x; 30 public byte y; 31 Byte2()32 public Byte2() { 33 } 34 Byte2(byte initX, byte initY)35 public Byte2(byte initX, byte initY) { 36 x = initX; 37 y = initY; 38 } 39 40 /** @hide */ Byte2(Byte2 source)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 */ add(Byte2 a)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 */ add(Byte2 a, Byte2 b)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 */ add(byte value)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 */ add(Byte2 a, byte b)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 */ sub(Byte2 a)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 */ sub(Byte2 a, Byte2 b)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 */ sub(byte value)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 */ sub(Byte2 a, byte b)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 */ mul(Byte2 a)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 */ mul(Byte2 a, Byte2 b)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 */ mul(byte value)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 */ mul(Byte2 a, byte b)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 */ div(Byte2 a)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 */ div(Byte2 a, Byte2 b)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 */ div(byte value)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 */ div(Byte2 a, byte b)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 */ length()251 public byte length() { 252 return 2; 253 } 254 255 /** @hide 256 * set vector negate 257 */ negate()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 */ dotProduct(Byte2 a)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 */ dotProduct(Byte2 a, Byte2 b)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 */ addMultiple(Byte2 a, byte factor)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 */ set(Byte2 a)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 */ setValues(byte a, byte b)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 */ elementSum()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 */ get(int i)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 */ setAt(int i, byte value)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 */ addAt(int i, byte value)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 */ copyTo(byte[] data, int offset)386 public void copyTo(byte[] data, int offset) { 387 data[offset] = x; 388 data[offset + 1] = y; 389 } 390 391 } 392 393 394 395 396