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