1. /*
  2. * @(#)DataBufferInt.java 1.14 01/11/29
  3. *
  4. * Copyright 2002 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 = dataArray;
  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 = dataArray;
  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 bankdata;
  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. */
  150. public int getElem(int i) {
  151. return data[i+offset];
  152. }
  153. /**
  154. * Returns the requested data array element from the specified bank
  155. *
  156. * @param bank The bank from which you want to get a data array element.
  157. * @param i The data array element you want to get.
  158. * @return The requested data array element as an integer.
  159. */
  160. public int getElem(int bank, int i) {
  161. return bankdata[bank][i+offsets[bank]];
  162. }
  163. /**
  164. * Sets the requested data array element in the first (default) bank
  165. * to the specified value.
  166. *
  167. * @param i The data array element you want to set.
  168. * @param val The integer value to which you want to set the data array element.
  169. */
  170. public void setElem(int i, int val) {
  171. data[i+offset] = val;
  172. }
  173. /**
  174. * Sets the requested data array element in the specified bank
  175. * to the integer value <CODE>i</CODE>.
  176. * @param bank The bank in which you want to set the data array element.
  177. * @param i The data array element you want to set.
  178. * @param val The integer value to which you want to set the specified data array element.
  179. */
  180. public void setElem(int bank, int i, int val) {
  181. bankdata[bank][i+offsets[bank]] = (int)val;
  182. }
  183. }