1. /*
  2. * @(#)SampleModel.java 1.36 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 abstract class defines an interface for extracting samples of pixels
  19. * in an image. All image data is expressed as a collection of pixels.
  20. * Each pixel consists of a number of samples. A sample is a datum
  21. * for one band of an image and a band consists of all samples of a
  22. * particular type in an image. For example, a pixel might contain
  23. * three samples representing its red, green and blue components.
  24. * There are three bands in the image containing this pixel. One band
  25. * consists of all the red samples from all pixels in the
  26. * image. The second band consists of all the green samples and
  27. * the remaining band consists of all of the blue samples. The pixel
  28. * can be stored in various formats. For example, all samples from
  29. * a particular band can be stored contiguously or all samples from a
  30. * single pixel can be stored contiguously.
  31. * <p>
  32. * Subclasses of SampleModel specify the types of samples they can
  33. * represent (e.g. unsigned 8-bit byte, signed 16-bit short, etc.)
  34. * and may specify how the samples are organized in memory.
  35. * In the Java 2D(tm) API, built-in image processing operators may
  36. * not operate on all possible sample types, but generally will work
  37. * for unsigned integral samples of 16 bits or less. Some operators
  38. * support a wider variety of sample types.
  39. * <p>
  40. * A collection of pixels is represented as a Raster, which consists of
  41. * a DataBuffer and a SampleModel. The SampleModel allows access to
  42. * samples in the DataBuffer and may provide low-level information that
  43. * a programmer can use to directly manipulate samples and pixels in the
  44. * DataBuffer.
  45. * <p>
  46. * This class is generally a fall back method for dealing with
  47. * images. More efficient code will cast the SampleModel to the
  48. * appropriate subclass and extract the information needed to directly
  49. * manipulate pixels in the DataBuffer.
  50. *
  51. * @see java.awt.image.DataBuffer
  52. * @see java.awt.image.Raster
  53. * @see java.awt.image.ComponentSampleModel
  54. * @see java.awt.image.PixelInterleavedSampleModel
  55. * @see java.awt.image.BandedSampleModel
  56. * @see java.awt.image.MultiPixelPackedSampleModel
  57. * @see java.awt.image.SinglePixelPackedSampleModel
  58. */
  59. public abstract class SampleModel
  60. {
  61. /** Width in pixels of the region of image data that this SampleModel
  62. * describes.
  63. */
  64. protected int width;
  65. /** Height in pixels of the region of image data that this SampleModel
  66. * describes.
  67. */
  68. protected int height;
  69. /** Number of bands of the image data that this SampleModel describes. */
  70. protected int numBands;
  71. /** Data type of the DataBuffer storing the pixel data.
  72. * @see java.awt.image.DataBuffer
  73. */
  74. protected int dataType;
  75. static private native void initIDs();
  76. static {
  77. ColorModel.loadLibraries();
  78. initIDs();
  79. }
  80. /**
  81. * Constructs a SampleModel with the specified parameters.
  82. * @param dataType The data type of the DataBuffer storing the pixel data.
  83. * @param w The width (in pixels) of the region of image data.
  84. * @param h The height (in pixels) of the region of image data.
  85. * @param numBands The number of bands of the image data.
  86. * @throws IllegalArgumentException if <code>w</code> or <code>h</code>
  87. * is not greater than 0
  88. * @throws IllegalArgumentException if the product of <code>w</code>
  89. * and <code>h</code> is greater than
  90. * <code>Integer.MAX_VALUE</code>
  91. * @throws IllegalArgumentException if <code>dataType</code> is not
  92. * one of the supported data types
  93. */
  94. public SampleModel(int dataType, int w, int h, int numBands)
  95. {
  96. float size = (float)w*h;
  97. if (w <= 0 || h <= 0) {
  98. throw new IllegalArgumentException("Width ("+w+") and height ("+
  99. h+") must be > 0");
  100. }
  101. if (size >= Integer.MAX_VALUE) {
  102. throw new IllegalArgumentException("Dimensions (width="+w+
  103. " height="+h+") are too large");
  104. }
  105. if (dataType < DataBuffer.TYPE_BYTE ||
  106. (dataType > DataBuffer.TYPE_DOUBLE &&
  107. dataType != DataBuffer.TYPE_UNDEFINED))
  108. {
  109. throw new IllegalArgumentException("Unsupported dataType: "+
  110. dataType);
  111. }
  112. if (numBands <= 0) {
  113. throw new IllegalArgumentException("Number of bands must be > 0");
  114. }
  115. this.dataType = dataType;
  116. this.width = w;
  117. this.height = h;
  118. this.numBands = numBands;
  119. }
  120. /** Returns the width in pixels.
  121. * @return the width in pixels of the region of image data
  122. * that this <code>SampleModel</code> describes.
  123. */
  124. final public int getWidth() {
  125. return width;
  126. }
  127. /** Returns the height in pixels.
  128. * @return the height in pixels of the region of image data
  129. * that this <code>SampleModel</code> describes.
  130. */
  131. final public int getHeight() {
  132. return height;
  133. }
  134. /** Returns the total number of bands of image data.
  135. * @return the number of bands of image data that this
  136. * <code>SampleModel</code> describes.
  137. */
  138. final public int getNumBands() {
  139. return numBands;
  140. }
  141. /** Returns the number of data elements needed to transfer a pixel
  142. * via the getDataElements and setDataElements methods. When pixels
  143. * are transferred via these methods, they may be transferred in a
  144. * packed or unpacked format, depending on the implementation of the
  145. * SampleModel. Using these methods, pixels are transferred as an
  146. * array of getNumDataElements() elements of a primitive type given
  147. * by getTransferType(). The TransferType may or may not be the same
  148. * as the storage DataType.
  149. * @return the number of data elements.
  150. * @see #getDataElements(int, int, Object, DataBuffer)
  151. * @see #getDataElements(int, int, int, int, Object, DataBuffer)
  152. * @see #setDataElements(int, int, Object, DataBuffer)
  153. * @see #setDataElements(int, int, int, int, Object, DataBuffer)
  154. * @see #getTransferType
  155. */
  156. public abstract int getNumDataElements();
  157. /** Returns the data type of the DataBuffer storing the pixel data.
  158. * @return the data type.
  159. */
  160. final public int getDataType() {
  161. return dataType;
  162. }
  163. /** Returns the TransferType used to transfer pixels via the
  164. * getDataElements and setDataElements methods. When pixels
  165. * are transferred via these methods, they may be transferred in a
  166. * packed or unpacked format, depending on the implementation of the
  167. * SampleModel. Using these methods, pixels are transferred as an
  168. * array of getNumDataElements() elements of a primitive type given
  169. * by getTransferType(). The TransferType may or may not be the same
  170. * as the storage DataType. The TransferType will be one of the types
  171. * defined in DataBuffer.
  172. * @return the transfer type.
  173. * @see #getDataElements(int, int, Object, DataBuffer)
  174. * @see #getDataElements(int, int, int, int, Object, DataBuffer)
  175. * @see #setDataElements(int, int, Object, DataBuffer)
  176. * @see #setDataElements(int, int, int, int, Object, DataBuffer)
  177. * @see #getNumDataElements
  178. * @see java.awt.image.DataBuffer
  179. */
  180. public int getTransferType() {
  181. return dataType;
  182. }
  183. /**
  184. * Returns the samples for a specified pixel in an int array,
  185. * one sample per array element.
  186. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  187. * not in bounds.
  188. * @param x, y The coordinates of the pixel location
  189. * @param iArray If non-null, returns the samples in this array
  190. * @param data The DataBuffer containing the image data
  191. * @return the samples for the specified pixel.
  192. * @see #setPixel(int, int, int[], DataBuffer)
  193. *
  194. * @throws NullPointerException if data is null.
  195. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  196. * not in bounds, or if iArray is too small to hold the output.
  197. */
  198. public int[] getPixel(int x, int y, int iArray[], DataBuffer data) {
  199. int pixels[];
  200. if (iArray != null)
  201. pixels = iArray;
  202. else
  203. pixels = new int[numBands];
  204. for (int i=0; i<numBands; i++) {
  205. pixels[i] = getSample(x, y, i, data);
  206. }
  207. return pixels;
  208. }
  209. /**
  210. * Returns data for a single pixel in a primitive array of type
  211. * TransferType. For image data supported by the Java 2D API, this
  212. * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
  213. * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
  214. * or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
  215. * thus increasing efficiency for data transfers. Generally, obj
  216. * should be passed in as null, so that the Object will be created
  217. * automatically and will be of the right primitive data type.
  218. * <p>
  219. * The following code illustrates transferring data for one pixel from
  220. * DataBuffer <code>db1</code>, whose storage layout is described by
  221. * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  222. * storage layout is described by SampleModel <code>sm2</code>.
  223. * The transfer will generally be more efficient than using
  224. * getPixel/setPixel.
  225. * <pre>
  226. * SampleModel sm1, sm2;
  227. * DataBuffer db1, db2;
  228. * sm2.setDataElements(x, y, sm1.getDataElements(x, y, null, db1), db2);
  229. * </pre>
  230. * Using getDataElements/setDataElements to transfer between two
  231. * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  232. * the same number of bands, corresponding bands have the same number of
  233. * bits per sample, and the TransferTypes are the same.
  234. * <p>
  235. * If obj is non-null, it should be a primitive array of type TransferType.
  236. * Otherwise, a ClassCastException is thrown. An
  237. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  238. * not in bounds, or if obj is non-null and is not large enough to hold
  239. * the pixel data.
  240. * @param x The X coordinate of the pixel location.
  241. * @param y The Y coordinate of the pixel location.
  242. * @param obj If non-null, a primitive array in which to return
  243. * the pixel data.
  244. * @param data The DataBuffer containing the image data.
  245. * @return the data elements for the specified pixel.
  246. * @see #getNumDataElements
  247. * @see #getTransferType
  248. * @see java.awt.image.DataBuffer
  249. * @see #setDataElements(int, int, Object, DataBuffer)
  250. *
  251. * @throws NullPointerException if data is null.
  252. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  253. * not in bounds, or if obj is too small to hold the output.
  254. */
  255. public abstract Object getDataElements(int x, int y,
  256. Object obj, DataBuffer data);
  257. /**
  258. * Returns the pixel data for the specified rectangle of pixels in a
  259. * primitive array of type TransferType.
  260. * For image data supported by the Java 2D API, this
  261. * will be one of DataBuffer.TYPE_BYTE, DataBuffer.TYPE_USHORT,
  262. * DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT, DataBuffer.TYPE_FLOAT,
  263. * or DataBuffer.TYPE_DOUBLE. Data may be returned in a packed format,
  264. * thus increasing efficiency for data transfers. Generally, obj
  265. * should be passed in as null, so that the Object will be created
  266. * automatically and will be of the right primitive data type.
  267. * <p>
  268. * The following code illustrates transferring data for a rectangular
  269. * region of pixels from
  270. * DataBuffer <code>db1</code>, whose storage layout is described by
  271. * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  272. * storage layout is described by SampleModel <code>sm2</code>.
  273. * The transfer will generally be more efficient than using
  274. * getPixels/setPixels.
  275. * <pre>
  276. * SampleModel sm1, sm2;
  277. * DataBuffer db1, db2;
  278. * sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w,
  279. * h, null, db1), db2);
  280. * </pre>
  281. * Using getDataElements/setDataElements to transfer between two
  282. * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  283. * the same number of bands, corresponding bands have the same number of
  284. * bits per sample, and the TransferTypes are the same.
  285. * <p>
  286. * If obj is non-null, it should be a primitive array of type TransferType.
  287. * Otherwise, a ClassCastException is thrown. An
  288. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  289. * not in bounds, or if obj is non-null and is not large enough to hold
  290. * the pixel data.
  291. * @param x The minimum X coordinate of the pixel rectangle.
  292. * @param y The minimum Y coordinate of the pixel rectangle.
  293. * @param w The width of the pixel rectangle.
  294. * @param h The height of the pixel rectangle.
  295. * @param obj If non-null, a primitive array in which to return
  296. * the pixel data.
  297. * @param data The DataBuffer containing the image data.
  298. * @return the data elements for the specified region of pixels.
  299. * @see #getNumDataElements
  300. * @see #getTransferType
  301. * @see #setDataElements(int, int, int, int, Object, DataBuffer)
  302. * @see java.awt.image.DataBuffer
  303. *
  304. * @throws NullPointerException if data is null.
  305. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  306. * not in bounds, or if obj is too small to hold the output.
  307. */
  308. public Object getDataElements(int x, int y, int w, int h,
  309. Object obj, DataBuffer data) {
  310. int type = getTransferType();
  311. int numDataElems = getNumDataElements();
  312. int cnt = 0;
  313. Object o = null;
  314. switch(type) {
  315. case DataBuffer.TYPE_BYTE:
  316. byte[] btemp;
  317. byte[] bdata;
  318. if (obj == null)
  319. bdata = new byte[numDataElems*w*h];
  320. else
  321. bdata = (byte[])obj;
  322. for (int i=y; i<y+h; i++) {
  323. for (int j=x; j<x+w; j++) {
  324. o = getDataElements(j, i, o, data);
  325. btemp = (byte[])o;
  326. for (int k=0; k<numDataElems; k++) {
  327. bdata[cnt++] = btemp[k];
  328. }
  329. }
  330. }
  331. obj = (Object)bdata;
  332. break;
  333. case DataBuffer.TYPE_USHORT:
  334. case DataBuffer.TYPE_SHORT:
  335. short[] sdata;
  336. short[] stemp;
  337. if (obj == null)
  338. sdata = new short[numDataElems*w*h];
  339. else
  340. sdata = (short[])obj;
  341. for (int i=y; i<y+h; i++) {
  342. for (int j=x; j<x+w; j++) {
  343. o = getDataElements(j, i, o, data);
  344. stemp = (short[])o;
  345. for (int k=0; k<numDataElems; k++) {
  346. sdata[cnt++] = stemp[k];
  347. }
  348. }
  349. }
  350. obj = (Object)sdata;
  351. break;
  352. case DataBuffer.TYPE_INT:
  353. int[] idata;
  354. int[] itemp;
  355. if (obj == null)
  356. idata = new int[numDataElems*w*h];
  357. else
  358. idata = (int[])obj;
  359. for (int i=y; i<y+h; i++) {
  360. for (int j=x; j<x+w; j++) {
  361. o = getDataElements(j, i, o, data);
  362. itemp = (int[])o;
  363. for (int k=0; k<numDataElems; k++) {
  364. idata[cnt++] = itemp[k];
  365. }
  366. }
  367. }
  368. obj = (Object)idata;
  369. break;
  370. case DataBuffer.TYPE_FLOAT:
  371. float[] fdata;
  372. float[] ftemp;
  373. if (obj == null)
  374. fdata = new float[numDataElems*w*h];
  375. else
  376. fdata = (float[])obj;
  377. for (int i=y; i<y+h; i++) {
  378. for (int j=x; j<x+w; j++) {
  379. o = getDataElements(j, i, o, data);
  380. ftemp = (float[])o;
  381. for (int k=0; k<numDataElems; k++) {
  382. fdata[cnt++] = ftemp[k];
  383. }
  384. }
  385. }
  386. obj = (Object)fdata;
  387. break;
  388. case DataBuffer.TYPE_DOUBLE:
  389. double[] ddata;
  390. double[] dtemp;
  391. if (obj == null)
  392. ddata = new double[numDataElems*w*h];
  393. else
  394. ddata = (double[])obj;
  395. for (int i=y; i<y+h; i++) {
  396. for (int j=x; j<x+w; j++) {
  397. o = getDataElements(j, i, o, data);
  398. dtemp = (double[])o;
  399. for (int k=0; k<numDataElems; k++) {
  400. ddata[cnt++] = dtemp[k];
  401. }
  402. }
  403. }
  404. obj = (Object)ddata;
  405. break;
  406. }
  407. return obj;
  408. }
  409. /**
  410. * Sets the data for a single pixel in the specified DataBuffer from a
  411. * primitive array of type TransferType. For image data supported by
  412. * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
  413. * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  414. * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
  415. * may be in a packed format, thus increasing efficiency for data
  416. * transfers.
  417. * <p>
  418. * The following code illustrates transferring data for one pixel from
  419. * DataBuffer <code>db1</code>, whose storage layout is described by
  420. * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  421. * storage layout is described by SampleModel <code>sm2</code>.
  422. * The transfer will generally be more efficient than using
  423. * getPixel/setPixel.
  424. * <pre>
  425. * SampleModel sm1, sm2;
  426. * DataBuffer db1, db2;
  427. * sm2.setDataElements(x, y, sm1.getDataElements(x, y, null, db1),
  428. * db2);
  429. * </pre>
  430. * Using getDataElements/setDataElements to transfer between two
  431. * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  432. * the same number of bands, corresponding bands have the same number of
  433. * bits per sample, and the TransferTypes are the same.
  434. * <p>
  435. * obj must be a primitive array of type TransferType. Otherwise,
  436. * a ClassCastException is thrown. An
  437. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  438. * not in bounds, or if obj is not large enough to hold the pixel data.
  439. * @param x The X coordinate of the pixel location.
  440. * @param y The Y coordinate of the pixel location.
  441. * @param obj A primitive array containing pixel data.
  442. * @param data The DataBuffer containing the image data.
  443. * @see #getNumDataElements
  444. * @see #getTransferType
  445. * @see #getDataElements(int, int, Object, DataBuffer)
  446. * @see java.awt.image.DataBuffer
  447. *
  448. * @throws NullPointerException if data is null.
  449. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  450. * not in bounds, or if obj is too small to hold the input.
  451. */
  452. public abstract void setDataElements(int x, int y,
  453. Object obj, DataBuffer data);
  454. /**
  455. * Sets the data for a rectangle of pixels in the specified DataBuffer
  456. * from a primitive array of type TransferType. For image data supported
  457. * by the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
  458. * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  459. * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
  460. * may be in a packed format, thus increasing efficiency for data
  461. * transfers.
  462. * <p>
  463. * The following code illustrates transferring data for a rectangular
  464. * region of pixels from
  465. * DataBuffer <code>db1</code>, whose storage layout is described by
  466. * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose
  467. * storage layout is described by SampleModel <code>sm2</code>.
  468. * The transfer will generally be more efficient than using
  469. * getPixels/setPixels.
  470. * <pre>
  471. * SampleModel sm1, sm2;
  472. * DataBuffer db1, db2;
  473. * sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w, h,
  474. * null, db1), db2);
  475. * </pre>
  476. * Using getDataElements/setDataElements to transfer between two
  477. * DataBuffer/SampleModel pairs is legitimate if the SampleModels have
  478. * the same number of bands, corresponding bands have the same number of
  479. * bits per sample, and the TransferTypes are the same.
  480. * <p>
  481. * obj must be a primitive array of type TransferType. Otherwise,
  482. * a ClassCastException is thrown. An
  483. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  484. * not in bounds, or if obj is not large enough to hold the pixel data.
  485. * @param x The minimum X coordinate of the pixel rectangle.
  486. * @param y The minimum Y coordinate of the pixel rectangle.
  487. * @param w The width of the pixel rectangle.
  488. * @param h The height of the pixel rectangle.
  489. * @param obj A primitive array containing pixel data.
  490. * @param data The DataBuffer containing the image data.
  491. * @see #getNumDataElements
  492. * @see #getTransferType
  493. * @see #getDataElements(int, int, int, int, Object, DataBuffer)
  494. * @see java.awt.image.DataBuffer
  495. *
  496. * @throws NullPointerException if data is null.
  497. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  498. * not in bounds, or if obj is too small to hold the input.
  499. */
  500. public void setDataElements(int x, int y, int w, int h,
  501. Object obj, DataBuffer data) {
  502. int cnt = 0;
  503. Object o = null;
  504. int type = getTransferType();
  505. int numDataElems = getNumDataElements();
  506. switch(type) {
  507. case DataBuffer.TYPE_BYTE:
  508. byte[] barray = (byte[])obj;
  509. byte[] btemp = new byte[numDataElems];
  510. for (int i=y; i<y+h; i++) {
  511. for (int j=x; j<x+w; j++) {
  512. for (int k=0; k<numDataElems; k++) {
  513. btemp[k] = barray[cnt++];
  514. }
  515. setDataElements(j, i, btemp, data);
  516. }
  517. }
  518. break;
  519. case DataBuffer.TYPE_USHORT:
  520. case DataBuffer.TYPE_SHORT:
  521. short[] sarray = (short[])obj;
  522. short[] stemp = new short[numDataElems];
  523. for (int i=y; i<y+h; i++) {
  524. for (int j=x; j<x+w; j++) {
  525. for (int k=0; k<numDataElems; k++) {
  526. stemp[k] = sarray[cnt++];
  527. }
  528. setDataElements(j, i, stemp, data);
  529. }
  530. }
  531. break;
  532. case DataBuffer.TYPE_INT:
  533. int[] iArray = (int[])obj;
  534. int[] itemp = new int[numDataElems];
  535. for (int i=y; i<y+h; i++) {
  536. for (int j=x; j<x+w; j++) {
  537. for (int k=0; k<numDataElems; k++) {
  538. itemp[k] = iArray[cnt++];
  539. }
  540. setDataElements(j, i, itemp, data);
  541. }
  542. }
  543. break;
  544. case DataBuffer.TYPE_FLOAT:
  545. float[] fArray = (float[])obj;
  546. float[] ftemp = new float[numDataElems];
  547. for (int i=y; i<y+h; i++) {
  548. for (int j=x; j<x+w; j++) {
  549. for (int k=0; k<numDataElems; k++) {
  550. ftemp[k] = fArray[cnt++];
  551. }
  552. setDataElements(j, i, ftemp, data);
  553. }
  554. }
  555. break;
  556. case DataBuffer.TYPE_DOUBLE:
  557. double[] dArray = (double[])obj;
  558. double[] dtemp = new double[numDataElems];
  559. for (int i=y; i<y+h; i++) {
  560. for (int j=x; j<x+w; j++) {
  561. for (int k=0; k<numDataElems; k++) {
  562. dtemp[k] = dArray[cnt++];
  563. }
  564. setDataElements(j, i, dtemp, data);
  565. }
  566. }
  567. break;
  568. }
  569. }
  570. /**
  571. * Returns the samples for the specified pixel in an array of float.
  572. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  573. * not in bounds.
  574. * @param x The X coordinate of the pixel location.
  575. * @param y The Y coordinate of the pixel location.
  576. * @param fArray If non-null, returns the samples in this array.
  577. * @param data The DataBuffer containing the image data.
  578. * @return the samples for the specified pixel.
  579. * @see #setPixel(int, int, float[], DataBuffer)
  580. *
  581. * @throws NullPointerException if data is null.
  582. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  583. * not in bounds, or if fArray is too small to hold the output.
  584. */
  585. public float[] getPixel(int x, int y, float fArray[],
  586. DataBuffer data) {
  587. float pixels[];
  588. if (fArray != null)
  589. pixels = fArray;
  590. else
  591. pixels = new float[numBands];
  592. for (int i=0; i<numBands; i++)
  593. pixels[i] = getSampleFloat(x, y, i, data);
  594. return pixels;
  595. }
  596. /**
  597. * Returns the samples for the specified pixel in an array of double.
  598. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  599. * not in bounds.
  600. * @param x The X coordinate of the pixel location.
  601. * @param y The Y coordinate of the pixel location.
  602. * @param dArray If non-null, returns the samples in this array.
  603. * @param data The DataBuffer containing the image data.
  604. * @return the samples for the specified pixel.
  605. * @see #setPixel(int, int, double[], DataBuffer)
  606. *
  607. * @throws NullPointerException if data is null.
  608. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  609. * not in bounds, or if dArray is too small to hold the output.
  610. */
  611. public double[] getPixel(int x, int y, double dArray[],
  612. DataBuffer data) {
  613. double pixels[];
  614. if(dArray != null)
  615. pixels = dArray;
  616. else
  617. pixels = new double[numBands];
  618. for (int i=0; i<numBands; i++)
  619. pixels[i] = getSampleDouble(x, y, i, data);
  620. return pixels;
  621. }
  622. /**
  623. * Returns all samples for a rectangle of pixels in an
  624. * int array, one sample per array element.
  625. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  626. * not in bounds.
  627. * @param x The X coordinate of the upper left pixel location.
  628. * @param y The Y coordinate of the upper left pixel location.
  629. * @param w The width of the pixel rectangle.
  630. * @param h The height of the pixel rectangle.
  631. * @param iArray If non-null, returns the samples in this array.
  632. * @param data The DataBuffer containing the image data.
  633. * @return the samples for the specified region of pixels.
  634. * @see #setPixels(int, int, int, int, int[], DataBuffer)
  635. *
  636. * @throws NullPointerException if data is null.
  637. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  638. * not in bounds, or if iArray is too small to hold the output.
  639. */
  640. public int[] getPixels(int x, int y, int w, int h,
  641. int iArray[], DataBuffer data) {
  642. int pixels[];
  643. int Offset=0;
  644. if (iArray != null)
  645. pixels = iArray;
  646. else
  647. pixels = new int[numBands * w * h];
  648. for (int i=y; i<(h+y); i++) {
  649. for (int j=x; j<(w+x); j++) {
  650. for(int k=0; k<numBands; k++) {
  651. pixels[Offset++] = getSample(j, i, k, data);
  652. }
  653. }
  654. }
  655. return pixels;
  656. }
  657. /**
  658. * Returns all samples for a rectangle of pixels in a float
  659. * array, one sample per array element.
  660. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  661. * not in bounds.
  662. * @param x The X coordinate of the upper left pixel location.
  663. * @param y The Y coordinate of the upper left pixel location.
  664. * @param w The width of the pixel rectangle.
  665. * @param h The height of the pixel rectangle.
  666. * @param fArray If non-null, returns the samples in this array.
  667. * @param data The DataBuffer containing the image data.
  668. * @return the samples for the specified region of pixels.
  669. * @see #setPixels(int, int, int, int, float[], DataBuffer)
  670. *
  671. * @throws NullPointerException if data is null.
  672. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  673. * not in bounds, or if fArray is too small to hold the output.
  674. */
  675. public float[] getPixels(int x, int y, int w, int h,
  676. float fArray[], DataBuffer data) {
  677. float pixels[];
  678. int Offset = 0;
  679. if (fArray != null)
  680. pixels = fArray;
  681. else
  682. pixels = new float[numBands * w * h];
  683. for (int i=y; i<(h+y); i++) {
  684. for(int j=x; j<(w+x); j++) {
  685. for(int k=0; k<numBands; k++) {
  686. pixels[Offset++] = getSampleFloat(j, i, k, data);
  687. }
  688. }
  689. }
  690. return pixels;
  691. }
  692. /**
  693. * Returns all samples for a rectangle of pixels in a double
  694. * array, one sample per array element.
  695. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  696. * not in bounds.
  697. * @param x The X coordinate of the upper left pixel location.
  698. * @param y The Y coordinate of the upper left pixel location.
  699. * @param w The width of the pixel rectangle.
  700. * @param h The height of the pixel rectangle.
  701. * @param dArray If non-null, returns the samples in this array.
  702. * @param data The DataBuffer containing the image data.
  703. * @return the samples for the specified region of pixels.
  704. * @see #setPixels(int, int, int, int, double[], DataBuffer)
  705. *
  706. * @throws NullPointerException if data is null.
  707. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  708. * not in bounds, or if dArray is too small to hold the output.
  709. */
  710. public double[] getPixels(int x, int y, int w, int h,
  711. double dArray[], DataBuffer data) {
  712. double pixels[];
  713. int Offset = 0;
  714. if (dArray != null)
  715. pixels = dArray;
  716. else
  717. pixels = new double[numBands * w * h];
  718. // Fix 4217412
  719. for (int i=y; i<(h+y); i++) {
  720. for (int j=x; j<(w+x); j++) {
  721. for (int k=0; k<numBands; k++) {
  722. pixels[Offset++] = getSampleDouble(j, i, k, data);
  723. }
  724. }
  725. }
  726. return pixels;
  727. }
  728. /**
  729. * Returns the sample in a specified band for the pixel located
  730. * at (x,y) as an int.
  731. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  732. * not in bounds.
  733. * @param x The X coordinate of the pixel location.
  734. * @param y The Y coordinate of the pixel location.
  735. * @param b The band to return.
  736. * @param data The DataBuffer containing the image data.
  737. * @return the sample in a specified band for the specified pixel.
  738. * @see #setSample(int, int, int, int, DataBuffer)
  739. *
  740. * @throws NullPointerException if data is null.
  741. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  742. * the band index are not in bounds.
  743. */
  744. public abstract int getSample(int x, int y, int b, DataBuffer data);
  745. /**
  746. * Returns the sample in a specified band
  747. * for the pixel located at (x,y) as a float.
  748. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  749. * not in bounds.
  750. * @param x The X coordinate of the pixel location.
  751. * @param y The Y coordinate of the pixel location.
  752. * @param b The band to return.
  753. * @param data The DataBuffer containing the image data.
  754. * @return the sample in a specified band for the specified pixel.
  755. *
  756. * @throws NullPointerException if data is null.
  757. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  758. * the band index are not in bounds.
  759. */
  760. public float getSampleFloat(int x, int y, int b, DataBuffer data) {
  761. float sample;
  762. sample = (float) getSample(x, y, b, data);
  763. return sample;
  764. }
  765. /**
  766. * Returns the sample in a specified band
  767. * for a pixel located at (x,y) as a double.
  768. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  769. * not in bounds.
  770. * @param x The X coordinate of the pixel location.
  771. * @param y The Y coordinate of the pixel location.
  772. * @param b The band to return.
  773. * @param data The DataBuffer containing the image data.
  774. * @return the sample in a specified band for the specified pixel.
  775. *
  776. * @throws NullPointerException if data is null.
  777. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  778. * the band index are not in bounds.
  779. */
  780. public double getSampleDouble(int x, int y, int b, DataBuffer data) {
  781. double sample;
  782. sample = (double) getSample(x, y, b, data);
  783. return sample;
  784. }
  785. /**
  786. * Returns the samples for a specified band for the specified rectangle
  787. * of pixels in an int array, one sample per array element.
  788. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  789. * not in bounds.
  790. * @param x The X coordinate of the upper left pixel location.
  791. * @param y The Y coordinate of the upper left pixel location.
  792. * @param w The width of the pixel rectangle.
  793. * @param h The height of the pixel rectangle.
  794. * @param b The band to return.
  795. * @param iArray If non-null, returns the samples in this array.
  796. * @param data The DataBuffer containing the image data.
  797. * @return the samples for the specified band for the specified region
  798. * of pixels.
  799. * @see #setSamples(int, int, int, int, int, int[], DataBuffer)
  800. *
  801. * @throws NullPointerException if data is null.
  802. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  803. * the band index are not in bounds, or if iArray is too small to
  804. * hold the output.
  805. */
  806. public int[] getSamples(int x, int y, int w, int h, int b,
  807. int iArray[], DataBuffer data) {
  808. int pixels[];
  809. int Offset=0;
  810. if (iArray != null)
  811. pixels = iArray;
  812. else
  813. pixels = new int[w * h];
  814. for(int i=y; i<(h+y); i++) {
  815. for (int j=x; j<(w+x); j++) {
  816. pixels[Offset++] = getSample(j, i, b, data);
  817. }
  818. }
  819. return pixels;
  820. }
  821. /**
  822. * Returns the samples for a specified band for the specified rectangle
  823. * of pixels in a float array, one sample per array element.
  824. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  825. * not in bounds.
  826. * @param x The X coordinate of the upper left pixel location.
  827. * @param y The Y coordinate of the upper left pixel location.
  828. * @param w The width of the pixel rectangle.
  829. * @param h The height of the pixel rectangle.
  830. * @param b The band to return.
  831. * @param fArray If non-null, returns the samples in this array.
  832. * @param data The DataBuffer containing the image data.
  833. * @return the samples for the specified band for the specified region
  834. * of pixels.
  835. * @see #setSamples(int, int, int, int, int, float[], DataBuffer)
  836. *
  837. * @throws NullPointerException if data is null.
  838. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  839. * the band index are not in bounds, or if fArray is too small to
  840. * hold the output.
  841. */
  842. public float[] getSamples(int x, int y, int w, int h,
  843. int b, float fArray[],
  844. DataBuffer data) {
  845. float pixels[];
  846. int Offset=0;
  847. if (fArray != null)
  848. pixels = fArray;
  849. else
  850. pixels = new float[w * h];
  851. for (int i=y; i<(h+y); i++) {
  852. for (int j=x; j<(w+x); j++) {
  853. pixels[Offset++] = getSampleFloat(j, i, b, data);
  854. }
  855. }
  856. return pixels;
  857. }
  858. /**
  859. * Returns the samples for a specified band for a specified rectangle
  860. * of pixels in a double array, one sample per array element.
  861. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  862. * not in bounds.
  863. * @param x The X coordinate of the upper left pixel location.
  864. * @param y The Y coordinate of the upper left pixel location.
  865. * @param w The width of the pixel rectangle.
  866. * @param h The height of the pixel rectangle.
  867. * @param b The band to return.
  868. * @param dArray If non-null, returns the samples in this array.
  869. * @param data The DataBuffer containing the image data.
  870. * @return the samples for the specified band for the specified region
  871. * of pixels.
  872. * @see #setSamples(int, int, int, int, int, double[], DataBuffer)
  873. *
  874. * @throws NullPointerException if data is null.
  875. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  876. * the band index are not in bounds, or if dArray is too small to
  877. * hold the output.
  878. */
  879. public double[] getSamples(int x, int y, int w, int h,
  880. int b, double dArray[],
  881. DataBuffer data) {
  882. double pixels[];
  883. int Offset=0;
  884. if (dArray != null)
  885. pixels = dArray;
  886. else
  887. pixels = new double[w * h];
  888. for (int i=y; i<(y+h); i++) {
  889. for (int j=x; j<(x+w); j++) {
  890. pixels[Offset++] = getSampleDouble(j, i, b, data);
  891. }
  892. }
  893. return pixels;
  894. }
  895. /**
  896. * Sets a pixel in the DataBuffer using an int array of samples for input.
  897. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  898. * not in bounds.
  899. * @param x The X coordinate of the pixel location.
  900. * @param y The Y coordinate of the pixel location.
  901. * @param iArray The input samples in an int array.
  902. * @param data The DataBuffer containing the image data.
  903. * @see #getPixel(int, int, int[], DataBuffer)
  904. *
  905. * @throws NullPointerException if iArray or data is null.
  906. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  907. * not in bounds, or if iArray is too small to hold the input.
  908. */
  909. public void setPixel(int x, int y, int iArray[], DataBuffer data) {
  910. for (int i=0; i<numBands; i++)
  911. setSample(x, y, i, iArray[i], data);
  912. }
  913. /**
  914. * Sets a pixel in the DataBuffer using a float array of samples for input.
  915. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  916. * not in bounds.
  917. * @param x The X coordinate of the pixel location.
  918. * @param y The Y coordinate of the pixel location.
  919. * @param fArray The input samples in a float array.
  920. * @param data The DataBuffer containing the image data.
  921. * @see #getPixel(int, int, float[], DataBuffer)
  922. *
  923. * @throws NullPointerException if fArray or data is null.
  924. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  925. * not in bounds, or if fArray is too small to hold the input.
  926. */
  927. public void setPixel(int x, int y, float fArray[], DataBuffer data) {
  928. for (int i=0; i<numBands; i++)
  929. setSample(x, y, i, fArray[i], data);
  930. }
  931. /**
  932. * Sets a pixel in the DataBuffer using a double array of samples
  933. * for input.
  934. * @param x The X coordinate of the pixel location.
  935. * @param y The Y coordinate of the pixel location.
  936. * @param dArray The input samples in a double array.
  937. * @param data The DataBuffer containing the image data.
  938. * @see #getPixel(int, int, double[], DataBuffer)
  939. *
  940. * @throws NullPointerException if dArray or data is null.
  941. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  942. * not in bounds, or if fArray is too small to hold the input.
  943. */
  944. public void setPixel(int x, int y, double dArray[], DataBuffer data) {
  945. for (int i=0; i<numBands; i++)
  946. setSample(x, y, i, dArray[i], data);
  947. }
  948. /**
  949. * Sets all samples for a rectangle of pixels from an int array containing
  950. * one sample per array element.
  951. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  952. * not in bounds.
  953. * @param x The X coordinate of the upper left pixel location.
  954. * @param y The Y coordinate of the upper left pixel location.
  955. * @param w The width of the pixel rectangle.
  956. * @param h The height of the pixel rectangle.
  957. * @param iArray The input samples in an int array.
  958. * @param data The DataBuffer containing the image data.
  959. * @see #getPixels(int, int, int, int, int[], DataBuffer)
  960. *
  961. * @throws NullPointerException if iArray or data is null.
  962. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  963. * not in bounds, or if iArray is too small to hold the input.
  964. */
  965. public void setPixels(int x, int y, int w, int h,
  966. int iArray[], DataBuffer data) {
  967. int Offset=0;
  968. for (int i=y; i<(y+h); i++) {
  969. for (int j=x; j<(x+w); j++) {
  970. for (int k=0; k<numBands; k++) {
  971. setSample(j, i, k, iArray[Offset++], data);
  972. }
  973. }
  974. }
  975. }
  976. /**
  977. * Sets all samples for a rectangle of pixels from a float array containing
  978. * one sample per array element.
  979. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  980. * not in bounds.
  981. * @param x The X coordinate of the upper left pixel location.
  982. * @param y The Y coordinate of the upper left pixel location.
  983. * @param w The width of the pixel rectangle.
  984. * @param h The height of the pixel rectangle.
  985. * @param fArray The input samples in a float array.
  986. * @param data The DataBuffer containing the image data.
  987. * @see #getPixels(int, int, int, int, float[], DataBuffer)
  988. *
  989. * @throws NullPointerException if fArray or data is null.
  990. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  991. * not in bounds, or if fArray is too small to hold the input.
  992. */
  993. public void setPixels(int x, int y, int w, int h,
  994. float fArray[], DataBuffer data) {
  995. int Offset=0;
  996. for (int i=y; i<(y+h); i++) {
  997. for (int j=x; j<(x+w); j++) {
  998. for(int k=0; k<numBands; k++) {
  999. setSample(j, i, k, fArray[Offset++], data);
  1000. }
  1001. }
  1002. }
  1003. }
  1004. /**
  1005. * Sets all samples for a rectangle of pixels from a double array
  1006. * containing one sample per array element.
  1007. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1008. * not in bounds.
  1009. * @param x The X coordinate of the upper left pixel location.
  1010. * @param y The Y coordinate of the upper left pixel location.
  1011. * @param w The width of the pixel rectangle.
  1012. * @param h The height of the pixel rectangle.
  1013. * @param dArray The input samples in a double array.
  1014. * @param data The DataBuffer containing the image data.
  1015. * @see #getPixels(int, int, int, int, double[], DataBuffer)
  1016. *
  1017. * @throws NullPointerException if dArray or data is null.
  1018. * @throws ArrayIndexOutOfBoundsException if the coordinates are
  1019. * not in bounds, or if dArray is too small to hold the input.
  1020. */
  1021. public void setPixels(int x, int y, int w, int h,
  1022. double dArray[], DataBuffer data) {
  1023. int Offset=0;
  1024. for (int i=y; i<(y+h); i++) {
  1025. for (int j=x; j<(x+w); j++) {
  1026. for (int k=0; k<numBands; k++) {
  1027. setSample(j, i, k, dArray[Offset++], data);
  1028. }
  1029. }
  1030. }
  1031. }
  1032. /**
  1033. * Sets a sample in the specified band for the pixel located at (x,y)
  1034. * in the DataBuffer using an int for input.
  1035. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1036. * not in bounds.
  1037. * @param x The X coordinate of the pixel location.
  1038. * @param y The Y coordinate of the pixel location.
  1039. * @param b The band to set.
  1040. * @param s The input sample as an int.
  1041. * @param data The DataBuffer containing the image data.
  1042. * @see #getSample(int, int, int, DataBuffer)
  1043. *
  1044. * @throws NullPointerException if data is null.
  1045. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  1046. * the band index are not in bounds.
  1047. */
  1048. public abstract void setSample(int x, int y, int b,
  1049. int s,
  1050. DataBuffer data);
  1051. /**
  1052. * Sets a sample in the specified band for the pixel located at (x,y)
  1053. * in the DataBuffer using a float for input.
  1054. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1055. * not in bounds.
  1056. * @param x The X coordinate of the pixel location.
  1057. * @param y The Y coordinate of the pixel location.
  1058. * @param b The band to set.
  1059. * @param s The input sample as a float.
  1060. * @param data The DataBuffer containing the image data.
  1061. * @see #getSample(int, int, int, DataBuffer)
  1062. *
  1063. * @throws NullPointerException if data is null.
  1064. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  1065. * the band index are not in bounds.
  1066. */
  1067. public void setSample(int x, int y, int b,
  1068. float s ,
  1069. DataBuffer data) {
  1070. int sample = (int)s;
  1071. setSample(x, y, b, sample, data);
  1072. }
  1073. /**
  1074. * Sets a sample in the specified band for the pixel located at (x,y)
  1075. * in the DataBuffer using a double for input.
  1076. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1077. * not in bounds.
  1078. * @param x The X coordinate of the pixel location.
  1079. * @param y The Y coordinate of the pixel location.
  1080. * @param b The band to set.
  1081. * @param s The input sample as a double.
  1082. * @param data The DataBuffer containing the image data.
  1083. * @see #getSample(int, int, int, DataBuffer)
  1084. *
  1085. * @throws NullPointerException if data is null.
  1086. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  1087. * the band index are not in bounds.
  1088. */
  1089. public void setSample(int x, int y, int b,
  1090. double s,
  1091. DataBuffer data) {
  1092. int sample = (int)s;
  1093. setSample(x, y, b, sample, data);
  1094. }
  1095. /**
  1096. * Sets the samples in the specified band for the specified rectangle
  1097. * of pixels from an int array containing one sample per array element.
  1098. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1099. * not in bounds.
  1100. * @param x The X coordinate of the upper left pixel location.
  1101. * @param y The Y coordinate of the upper left pixel location.
  1102. * @param w The width of the pixel rectangle.
  1103. * @param h The height of the pixel rectangle.
  1104. * @param b The band to set.
  1105. * @param iArray The input samples in an int array.
  1106. * @param data The DataBuffer containing the image data.
  1107. * @see #getSamples(int, int, int, int, int, int[], DataBuffer)
  1108. *
  1109. * @throws NullPointerException if iArray or data is null.
  1110. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  1111. * the band index are not in bounds, or if iArray is too small to
  1112. * hold the input.
  1113. */
  1114. public void setSamples(int x, int y, int w, int h, int b,
  1115. int iArray[], DataBuffer data) {
  1116. int Offset=0;
  1117. for (int i=y; i<(y+h); i++) {
  1118. for (int j=x; j<(x+w); j++) {
  1119. setSample(j, i, b, iArray[Offset++], data);
  1120. }
  1121. }
  1122. }
  1123. /**
  1124. * Sets the samples in the specified band for the specified rectangle
  1125. * of pixels from a float array containing one sample per array element.
  1126. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1127. * not in bounds.
  1128. * @param x The X coordinate of the upper left pixel location.
  1129. * @param y The Y coordinate of the upper left pixel location.
  1130. * @param w The width of the pixel rectangle.
  1131. * @param h The height of the pixel rectangle.
  1132. * @param b The band to set.
  1133. * @param fArray The input samples in a float array.
  1134. * @param data The DataBuffer containing the image data.
  1135. * @see #getSamples(int, int, int, int, int, float[], DataBuffer)
  1136. *
  1137. * @throws NullPointerException if fArray or data is null.
  1138. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  1139. * the band index are not in bounds, or if fArray is too small to
  1140. * hold the input.
  1141. */
  1142. public void setSamples(int x, int y, int w, int h, int b,
  1143. float fArray[], DataBuffer data) {
  1144. int Offset=0;
  1145. for (int i=y; i<(y+h); i++) {
  1146. for (int j=x; j<(x+w); j++) {
  1147. setSample(j, i, b, fArray[Offset++], data);
  1148. }
  1149. }
  1150. }
  1151. /**
  1152. * Sets the samples in the specified band for the specified rectangle
  1153. * of pixels from a double array containing one sample per array element.
  1154. * ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  1155. * not in bounds.
  1156. * @param x The X coordinate of the upper left pixel location.
  1157. * @param y The Y coordinate of the upper left pixel location.
  1158. * @param w The width of the pixel rectangle.
  1159. * @param h The height of the pixel rectangle.
  1160. * @param b The band to set.
  1161. * @param dArray The input samples in a double array.
  1162. * @param data The DataBuffer containing the image data.
  1163. * @see #getSamples(int, int, int, int, int, double[], DataBuffer)
  1164. *
  1165. * @throws NullPointerException if dArray or data is null.
  1166. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  1167. * the band index are not in bounds, or if dArray is too small to
  1168. * hold the input.
  1169. */
  1170. public void setSamples(int x, int y, int w, int h, int b,
  1171. double dArray[], DataBuffer data) {
  1172. int Offset=0;
  1173. for (int i=y; i<(y+h); i++) {
  1174. for (int j=x; j<(x+w); j++) {
  1175. setSample(j, i, b, dArray[Offset++], data);
  1176. }
  1177. }
  1178. }
  1179. /**
  1180. * Creates a SampleModel which describes data in this SampleModel's
  1181. * format, but with a different width and height.
  1182. * @param w the width of the image data
  1183. * @param h the height of the image data
  1184. * @return a <code>SampleModel</code> describing the same image
  1185. * data as this <code>SampleModel</code>, but with a
  1186. * different size.
  1187. */
  1188. public abstract SampleModel createCompatibleSampleModel(int w, int h);
  1189. /**
  1190. * Creates a new SampleModel
  1191. * with a subset of the bands of this
  1192. * SampleModel.
  1193. * @param bands the subset of bands of this <code>SampleModel</code>
  1194. * @return a <code>SampleModel</code> with a subset of bands of this
  1195. * <code>SampleModel</code>.
  1196. */
  1197. public abstract SampleModel createSubsetSampleModel(int bands[]);
  1198. /**
  1199. * Creates a DataBuffer that corresponds to this SampleModel.
  1200. * The DataBuffer's width and height will match this SampleModel's.
  1201. * @return a <code>DataBuffer</code> corresponding to this
  1202. * <code>SampleModel</code>.
  1203. */
  1204. public abstract DataBuffer createDataBuffer();
  1205. /** Returns the size in bits of samples for all bands.
  1206. * @return the size of samples for all bands.
  1207. */
  1208. public abstract int[] getSampleSize();
  1209. /** Returns the size in bits of samples for the specified band.
  1210. * @param band the specified band
  1211. * @return the size of the samples of the specified band.
  1212. */
  1213. public abstract int getSampleSize(int band);
  1214. }