/rs/java/android/renderscript/Short4.java

https://github.com/aizuzi/platform_frameworks_base · Java · 514 lines · 256 code · 48 blank · 210 comment · 3 complexity · ac4ea3737d2a234bbae423c7484c584d MD5 · raw file

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