1. /*
  2. * @(#)DataBufferInt.java 1.20 03/12/19
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /* ****************************************************************
  8. ******************************************************************
  9. ******************************************************************
  10. *** COPYRIGHT (c) Eastman Kodak Company, 1997
  11. *** As an unpublished work pursuant to Title 17 of the United
  12. *** States Code. All rights reserved.
  13. ******************************************************************
  14. ******************************************************************
  15. ******************************************************************/
  16. package java.awt.image;
  17. /**
  18. * This class extends <CODE>DataBuffer</CODE> and stores data internally
  19. * as integers.
  20. */
  21. public final class DataBufferInt extends DataBuffer
  22. {
  23. /** The default data bank. */
  24. int data[];
  25. /** All data banks */
  26. int bankdata[][];
  27. /**
  28. * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank
  29. * and the specified size.
  30. *
  31. * @param size The size of the <CODE>DataBuffer</CODE>.
  32. */
  33. public DataBufferInt(int size) {
  34. super(TYPE_INT,size);
  35. data = new int[size];
  36. bankdata = new int[1][];
  37. bankdata[0] = data;
  38. }
  39. /**
  40. * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified number of
  41. * banks, all of which are the specified size.
  42. *
  43. * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  44. * @param numBanks The number of banks in the a<CODE>DataBuffer</CODE>.
  45. */
  46. public DataBufferInt(int size, int numBanks) {
  47. super(TYPE_INT,size,numBanks);
  48. bankdata = new int[numBanks][];
  49. for (int i= 0; i < numBanks; i++) {
  50. bankdata[i] = new int[size];
  51. }
  52. data = bankdata[0];
  53. }
  54. /**
  55. * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank using the
  56. * specified array.
  57. * Only the first <CODE>size</CODE> elements should be used by accessors of
  58. * this <CODE>DataBuffer</CODE>. <CODE>dataArray</CODE> must be large enough to
  59. * hold <CODE>size</CODE> elements.
  60. *
  61. * @param dataArray The integer array for the <CODE>DataBuffer</CODE>.
  62. * @param size The size of the <CODE>DataBuffer</CODE> bank.
  63. */
  64. public DataBufferInt(int dataArray[], int size) {
  65. super(TYPE_INT,size);
  66. data = dataArray;
  67. bankdata = new int[1][];
  68. bankdata[0] = data;
  69. }
  70. /**
  71. * Constructs an integer-based <CODE>DataBuffer</CODE> with a single bank using the
  72. * specified array, size, and offset. <CODE>dataArray</CODE> must have at least
  73. * <CODE>offset</CODE> + <CODE>size</CODE> elements. Only elements <CODE>offset</CODE>
  74. * through <CODE>offset</CODE> + <CODE>size</CODE> - 1
  75. * should be used by accessors of this <CODE>DataBuffer</CODE>.
  76. *
  77. * @param dataArray The integer array for the <CODE>DataBuffer</CODE>.
  78. * @param size The size of the <CODE>DataBuffer</CODE> bank.
  79. * @param offset The offset into the <CODE>dataArray</CODE>.
  80. */
  81. public DataBufferInt(int dataArray[], int size, int offset) {
  82. super(TYPE_INT,size,1,offset);
  83. data = dataArray;
  84. bankdata = new int[1][];
  85. bankdata[0] = data;
  86. }
  87. /**
  88. * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays.
  89. * The number of banks will be equal to <CODE>dataArray.length</CODE>.
  90. * Only the first <CODE>size</CODE> elements of each array should be used by
  91. * accessors of this <CODE>DataBuffer</CODE>.
  92. *
  93. * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
  94. * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  95. */
  96. public DataBufferInt(int dataArray[][], int size) {
  97. super(TYPE_INT, size, dataArray.length);
  98. bankdata = (int [][]) dataArray.clone();
  99. data = bankdata[0];
  100. }
  101. /**
  102. * Constructs an integer-based <CODE>DataBuffer</CODE> with the specified arrays, size,
  103. * and offsets.
  104. * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must
  105. * be at least as large as <CODE>size</CODE> + the corresponding offset. There must
  106. * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each
  107. * bank, only elements <CODE>offset</CODE> through
  108. * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
  109. * used by accessors of this <CODE>DataBuffer</CODE>.
  110. *
  111. * @param dataArray The integer arrays for the <CODE>DataBuffer</CODE>.
  112. * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  113. * @param offsets The offsets into each array.
  114. */
  115. public DataBufferInt(int dataArray[][], int size, int offsets[]) {
  116. super(TYPE_INT,size,dataArray.length,offsets);
  117. bankdata = (int [][]) dataArray.clone();
  118. data = bankdata[0];
  119. }
  120. /**
  121. * Returns the default (first) int data array in <CODE>DataBuffer</CODE>.
  122. *
  123. * @return The first integer data array.
  124. */
  125. public int[] getData() {
  126. return data;
  127. }
  128. /**
  129. * Returns the data array for the specified bank.
  130. *
  131. * @param bank The bank whose data array you want to get.
  132. * @return The data array for the specified bank.
  133. */
  134. public int[] getData(int bank) {
  135. return bankdata[bank];
  136. }
  137. /**
  138. * Returns the data arrays for all banks.
  139. * @return All of the data arrays.
  140. */
  141. public int[][] getBankData() {
  142. return (int [][]) bankdata.clone();
  143. }
  144. /**
  145. * Returns the requested data array element from the first (default) bank.
  146. *
  147. * @param i The data array element you want to get.
  148. * @return The requested data array element as an integer.
  149. * @see #setElem(int, int)
  150. * @see #setElem(int, int, int)
  151. */
  152. public int getElem(int i) {
  153. return data[i+offset];
  154. }
  155. /**
  156. * Returns the requested data array element from the specified bank.
  157. *
  158. * @param bank The bank from which you want to get a data array element.
  159. * @param i The data array element you want to get.
  160. * @return The requested data array element as an integer.
  161. * @see #setElem(int, int)
  162. * @see #setElem(int, int, int)
  163. */
  164. public int getElem(int bank, int i) {
  165. return bankdata[bank][i+offsets[bank]];
  166. }
  167. /**
  168. * Sets the requested data array element in the first (default) bank
  169. * to the specified value.
  170. *
  171. * @param i The data array element you want to set.
  172. * @param val The integer value to which you want to set the data array element.
  173. * @see #getElem(int)
  174. * @see #getElem(int, int)
  175. */
  176. public void setElem(int i, int val) {
  177. data[i+offset] = val;
  178. }
  179. /**
  180. * Sets the requested data array element in the specified bank
  181. * to the integer value <CODE>i</CODE>.
  182. * @param bank The bank in which you want to set the data array element.
  183. * @param i The data array element you want to set.
  184. * @param val The integer value to which you want to set the specified data array element.
  185. * @see #getElem(int)
  186. * @see #getElem(int, int)
  187. */
  188. public void setElem(int bank, int i, int val) {
  189. bankdata[bank][i+offsets[bank]] = (int)val;
  190. }
  191. }