1. /*
  2. * @(#)DataBufferShort.java 1.14 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 as shorts.
  22. */
  23. public final class DataBufferShort extends DataBuffer
  24. {
  25. /** The default data bank. */
  26. short data[];
  27. /** All data banks */
  28. short bankdata[][];
  29. /**
  30. * Constructs a short-based <CODE>DataBuffer</CODE> with a single bank and the
  31. * specified size.
  32. *
  33. * @param size The size of the <CODE>DataBuffer</CODE>.
  34. */
  35. public DataBufferShort(int size) {
  36. super(TYPE_SHORT,size);
  37. data = new short[size];
  38. bankdata = new short[1][];
  39. bankdata[0] = data;
  40. }
  41. /**
  42. * Constructs a short-based <CODE>DataBuffer</CODE> with the specified number of
  43. * banks all of which are the specified size.
  44. *
  45. * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  46. * @param numBanks The number of banks in the a<CODE>DataBuffer</CODE>.
  47. */
  48. public DataBufferShort(int size, int numBanks) {
  49. super(TYPE_SHORT,size,numBanks);
  50. bankdata = new short[numBanks][];
  51. for (int i= 0; i < numBanks; i++) {
  52. bankdata[i] = new short[size];
  53. }
  54. data = bankdata[0];
  55. }
  56. /**
  57. * Constructs a short-based <CODE>DataBuffer</CODE> with a single bank using the
  58. * specified array.
  59. * Only the first <CODE>size</CODE> elements should be used by accessors of
  60. * this <CODE>DataBuffer</CODE>. <CODE>dataArray</CODE> must be large enough to
  61. * hold <CODE>size</CODE> elements.
  62. *
  63. * @param dataArray The short array for the <CODE>DataBuffer</CODE>.
  64. * @param size The size of the <CODE>DataBuffer</CODE> bank.
  65. */
  66. public DataBufferShort(short dataArray[], int size) {
  67. super(TYPE_SHORT,size);
  68. data = dataArray;
  69. bankdata = new short[1][];
  70. bankdata[0] = data;
  71. }
  72. /**
  73. * Constructs a short-based <CODE>DataBuffer</CODE> with a single bank using the
  74. * specified array, size, and offset. <CODE>dataArray</CODE> must have at least
  75. * <CODE>offset</CODE> + <CODE>size</CODE> elements. Only elements <CODE>offset</CODE>
  76. * through <CODE>offset</CODE> + <CODE>size</CODE> - 1
  77. * should be used by accessors of this <CODE>DataBuffer</CODE>.
  78. *
  79. * @param dataArray The short array for the <CODE>DataBuffer</CODE>.
  80. * @param size The size of the <CODE>DataBuffer</CODE> bank.
  81. * @param offset The offset into the <CODE>dataArray</CODE>.
  82. */
  83. public DataBufferShort(short dataArray[], int size, int offset) {
  84. super(TYPE_SHORT,size,1,offset);
  85. data = dataArray;
  86. bankdata = new short[1][];
  87. bankdata[0] = data;
  88. }
  89. /**
  90. * Constructs a short-based <CODE>DataBuffer</CODE> with the specified arrays.
  91. * The number of banks will be equal to <CODE>dataArray.length</CODE>.
  92. * Only the first <CODE>size</CODE> elements of each array should be used by
  93. * accessors of this <CODE>DataBuffer</CODE>.
  94. *
  95. * @param dataArray The short arrays for the <CODE>DataBuffer</CODE>.
  96. * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  97. */
  98. public DataBufferShort(short dataArray[][], int size) {
  99. super(TYPE_SHORT,size,dataArray.length);
  100. bankdata = dataArray;
  101. data = bankdata[0];
  102. }
  103. /**
  104. * Constructs a short-based <CODE>DataBuffer</CODE> with the specified arrays, size,
  105. * and offsets.
  106. * The number of banks is equal to <CODE>dataArray.length</CODE>. Each array must
  107. * be at least as large as <CODE>size</CODE> + the corresponding offset. There must
  108. * be an entry in the offset array for each <CODE>dataArray</CODE> entry. For each
  109. * bank, only elements <CODE>offset</CODE> through
  110. * <CODE>offset</CODE> + <CODE>size</CODE> - 1 should be
  111. * used by accessors of this <CODE>DataBuffer</CODE>.
  112. *
  113. * @param dataArray The short arrays for the <CODE>DataBuffer</CODE>.
  114. * @param size The size of the banks in the <CODE>DataBuffer</CODE>.
  115. * @param offsets The offsets into each array.
  116. */
  117. public DataBufferShort(short dataArray[][], int size, int offsets[]) {
  118. super(TYPE_SHORT,size,dataArray.length,offsets);
  119. bankdata = dataArray;
  120. data = bankdata[0];
  121. }
  122. /**
  123. * Returns the default (first) byte data array.
  124. *
  125. * @return The first short data array.
  126. */
  127. public short[] getData() {
  128. return data;
  129. }
  130. /**
  131. * Returns the data array for the specified bank.
  132. *
  133. * @param bank The bank whose data array you want to get.
  134. * @return The data array for the specified bank.
  135. */
  136. public short[] getData(int bank) {
  137. return bankdata[bank];
  138. }
  139. /**
  140. * Returns the data arrays for all banks.
  141. * @return All of the data arrays.
  142. */
  143. public short[][] getBankData() {
  144. return bankdata;
  145. }
  146. /**
  147. * Returns the requested data array element from the first (default) bank.
  148. *
  149. * @param i The data array element you want to get.
  150. * @return The requested data array element as an integer.
  151. */
  152. public int getElem(int i) {
  153. return (int)(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. */
  162. public int getElem(int bank, int i) {
  163. return (int)(bankdata[bank][i+offsets[bank]]);
  164. }
  165. /**
  166. * Sets the requested data array element in the first (default) bank
  167. * to the specified value.
  168. *
  169. * @param i The data array element you want to set.
  170. * @param val The integer value to which you want to set the data array element.
  171. */
  172. public void setElem(int i, int val) {
  173. data[i+offset] = (short)val;
  174. }
  175. /**
  176. * Sets the requested data array element in the specified bank
  177. * from the given integer.
  178. * @param bank The bank in which you want to set the data array element.
  179. * @param i The data array element you want to set.
  180. * @param val The integer value to which you want to set the specified data array element.
  181. */
  182. public void setElem(int bank, int i, int val) {
  183. bankdata[bank][i+offsets[bank]] = (short)val;
  184. }
  185. }