1. /*
  2. * @(#)WritableRaster.java 1.46 03/01/23
  3. *
  4. * Copyright 2003 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. import java.awt.Rectangle;
  18. import java.awt.Point;
  19. /**
  20. * This class extends Raster to provide pixel writing capabilities.
  21. * Refer to the class comment for Raster for descriptions of how
  22. * a Raster stores pixels.
  23. *
  24. * <p> The constructors of this class are protected. To instantiate
  25. * a WritableRaster, use one of the createWritableRaster factory methods
  26. * in the Raster class.
  27. */
  28. public class WritableRaster extends Raster {
  29. /**
  30. * Constructs a WritableRaster with the given SampleModel. The
  31. * WritableRaster's upper left corner is origin and it is the
  32. * same size as the SampleModel. A DataBuffer large enough to
  33. * describe the WritableRaster is automatically created.
  34. * @param sampleModel The SampleModel that specifies the layout.
  35. * @param origin The Point that specifies the origin.
  36. * @throws RasterFormatException if computing either
  37. * <code>origin.x + sampleModel.getWidth()</code> or
  38. * <code>origin.y + sampleModel.getHeight()</code> results
  39. * in integer overflow
  40. */
  41. protected WritableRaster(SampleModel sampleModel,
  42. Point origin) {
  43. this(sampleModel,
  44. sampleModel.createDataBuffer(),
  45. new Rectangle(origin.x,
  46. origin.y,
  47. sampleModel.getWidth(),
  48. sampleModel.getHeight()),
  49. origin,
  50. null);
  51. }
  52. /**
  53. * Constructs a WritableRaster with the given SampleModel and DataBuffer.
  54. * The WritableRaster's upper left corner is origin and it is the same
  55. * size as the SampleModel. The DataBuffer is not initialized and must
  56. * be compatible with SampleModel.
  57. * @param sampleModel The SampleModel that specifies the layout.
  58. * @param dataBuffer The DataBuffer that contains the image data.
  59. * @param origin The Point that specifies the origin.
  60. * @throws RasterFormatException if computing either
  61. * <code>origin.x + sampleModel.getWidth()</code> or
  62. * <code>origin.y + sampleModel.getHeight()</code> results
  63. * in integer overflow
  64. */
  65. protected WritableRaster(SampleModel sampleModel,
  66. DataBuffer dataBuffer,
  67. Point origin) {
  68. this(sampleModel,
  69. dataBuffer,
  70. new Rectangle(origin.x,
  71. origin.y,
  72. sampleModel.getWidth(),
  73. sampleModel.getHeight()),
  74. origin,
  75. null);
  76. }
  77. /**
  78. * Constructs a WritableRaster with the given SampleModel, DataBuffer,
  79. * and parent. aRegion specifies the bounding rectangle of the new
  80. * Raster. When translated into the base Raster's coordinate
  81. * system, aRegion must be contained by the base Raster.
  82. * (The base Raster is the Raster's ancestor which has no parent.)
  83. * sampleModelTranslate specifies the sampleModelTranslateX and
  84. * sampleModelTranslateY values of the new Raster.
  85. *
  86. * Note that this constructor should generally be called by other
  87. * constructors or create methods, it should not be used directly.
  88. * @param sampleModel The SampleModel that specifies the layout.
  89. * @param dataBuffer The DataBuffer that contains the image data.
  90. * @param aRegion The Rectangle that specifies the image area.
  91. * @param sampleModelTranslate The Point that specifies the translation
  92. * from SampleModel to Raster coordinates.
  93. * @param parent The parent (if any) of this raster.
  94. * @throws RasterFormatException if <code>aRegion</code> has width
  95. * or height less than or equal to zero, or computing either
  96. * <code>aRegion.x + aRegion.width</code> or
  97. * <code>aRegion.y + aRegion.height</code> results in integer
  98. * overflow
  99. */
  100. protected WritableRaster(SampleModel sampleModel,
  101. DataBuffer dataBuffer,
  102. Rectangle aRegion,
  103. Point sampleModelTranslate,
  104. WritableRaster parent){
  105. super(sampleModel,dataBuffer,aRegion,sampleModelTranslate,parent);
  106. }
  107. /** Returns the parent WritableRaster (if any) of this WritableRaster,
  108. * or else null.
  109. * @return the parent of this <code>WritableRaster</code>, or
  110. * <code>null</code>.
  111. */
  112. public WritableRaster getWritableParent() {
  113. return (WritableRaster)parent;
  114. }
  115. /**
  116. * Create a WritableRaster with the same size, SampleModel and DataBuffer
  117. * as this one, but with a different location. The new WritableRaster
  118. * will possess a reference to the current WritableRaster, accessible
  119. * through its getParent() and getWritableParent() methods.
  120. *
  121. * @param childMinX X coord of the upper left corner of the new Raster.
  122. * @param childMinY Y coord of the upper left corner of the new Raster.
  123. * @return a <code>WritableRaster</code> the same as this one except
  124. * for the specified location.
  125. * @throws RasterFormatException if computing either
  126. * <code>childMinX + this.getWidth()</code> or
  127. * <code>childMinY + this.getHeight()</code> results in integer
  128. * overflow
  129. */
  130. public WritableRaster createWritableTranslatedChild(int childMinX,
  131. int childMinY) {
  132. return createWritableChild(minX,minY,width,height,
  133. childMinX,childMinY,null);
  134. }
  135. /**
  136. * Returns a new WritableRaster which shares all or part of this
  137. * WritableRaster's DataBuffer. The new WritableRaster will
  138. * possess a reference to the current WritableRaster, accessible
  139. * through its getParent() and getWritableParent() methods.
  140. *
  141. * <p> The parentX, parentY, width and height parameters form a
  142. * Rectangle in this WritableRaster's coordinate space, indicating
  143. * the area of pixels to be shared. An error will be thrown if
  144. * this Rectangle is not contained with the bounds of the current
  145. * WritableRaster.
  146. *
  147. * <p> The new WritableRaster may additionally be translated to a
  148. * different coordinate system for the plane than that used by the current
  149. * WritableRaster. The childMinX and childMinY parameters give
  150. * the new (x, y) coordinate of the upper-left pixel of the
  151. * returned WritableRaster; the coordinate (childMinX, childMinY)
  152. * in the new WritableRaster will map to the same pixel as the
  153. * coordinate (parentX, parentY) in the current WritableRaster.
  154. *
  155. * <p> The new WritableRaster may be defined to contain only a
  156. * subset of the bands of the current WritableRaster, possibly
  157. * reordered, by means of the bandList parameter. If bandList is
  158. * null, it is taken to include all of the bands of the current
  159. * WritableRaster in their current order.
  160. *
  161. * <p> To create a new WritableRaster that contains a subregion of
  162. * the current WritableRaster, but shares its coordinate system
  163. * and bands, this method should be called with childMinX equal to
  164. * parentX, childMinY equal to parentY, and bandList equal to
  165. * null.
  166. *
  167. * @param parentX X coordinate of the upper left corner in this
  168. * WritableRaster's coordinates.
  169. * @param parentY Y coordinate of the upper left corner in this
  170. * WritableRaster's coordinates.
  171. * @param w Width of the region starting at (parentX, parentY).
  172. * @param h Height of the region starting at (parentX, parentY).
  173. * @param childMinX X coordinate of the upper left corner of
  174. * the returned WritableRaster.
  175. * @param childMinY Y coordinate of the upper left corner of
  176. * the returned WritableRaster.
  177. * @param bandList Array of band indices, or null to use all bands.
  178. * @return a <code>WritableRaster</code> sharing all or part of the
  179. * <code>DataBuffer</code> of this <code>WritableRaster</code>.
  180. * @exception RasterFormatException if the subregion is outside of the
  181. * raster bounds.
  182. * @throws RasterFormatException if <code>w</code> or
  183. * <code>h</code>
  184. * is less than or equal to zero, or computing any of
  185. * <code>parentX + w</code>, <code>parentY + h</code>,
  186. * <code>childMinX + w</code>, or
  187. * <code>childMinY + h</code> results in integer
  188. * overflow
  189. */
  190. public WritableRaster createWritableChild(int parentX, int parentY,
  191. int w, int h,
  192. int childMinX, int childMinY,
  193. int bandList[]) {
  194. if (parentX < this.minX) {
  195. throw new RasterFormatException("parentX lies outside raster");
  196. }
  197. if (parentY < this.minY) {
  198. throw new RasterFormatException("parentY lies outside raster");
  199. }
  200. if ((parentX+w < parentX) || (parentX+w > this.width + this.minX)) {
  201. throw new RasterFormatException("(parentX + width) is outside raster");
  202. }
  203. if ((parentY+h < parentY) || (parentY+h > this.height + this.minY)) {
  204. throw new RasterFormatException("(parentY + height) is outside raster");
  205. }
  206. SampleModel sm;
  207. // Note: the SampleModel for the child Raster should have the same
  208. // width and height as that for the parent, since it represents
  209. // the physical layout of the pixel data. The child Raster's width
  210. // and height represent a "virtual" view of the pixel data, so
  211. // they may be different than those of the SampleModel.
  212. if (bandList != null) {
  213. sm = sampleModel.createSubsetSampleModel(bandList);
  214. }
  215. else {
  216. sm = sampleModel;
  217. }
  218. int deltaX = childMinX - parentX;
  219. int deltaY = childMinY - parentY;
  220. return new WritableRaster(sm,
  221. dataBuffer,
  222. new Rectangle(childMinX,childMinY,
  223. w, h),
  224. new Point(sampleModelTranslateX+deltaX,
  225. sampleModelTranslateY+deltaY),
  226. this);
  227. }
  228. /**
  229. * Sets the data for a single pixel from a
  230. * primitive array of type TransferType. For image data supported by
  231. * the Java 2D(tm) API, this will be one of DataBuffer.TYPE_BYTE,
  232. * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  233. * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
  234. * may be in a packed format, thus increasing efficiency for data
  235. * transfers.
  236. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  237. * not in bounds, or if inData is not large enough to hold the pixel data.
  238. * However, explicit bounds checking is not guaranteed.
  239. * A ClassCastException will be thrown if the input object is not null
  240. * and references anything other than an array of TransferType.
  241. * @see java.awt.image.SampleModel#setDataElements(int, int, Object, DataBuffer)
  242. * @param x The X coordinate of the pixel location.
  243. * @param y The Y coordinate of the pixel location.
  244. * @param inData An object reference to an array of type defined by
  245. * getTransferType() and length getNumDataElements()
  246. * containing the pixel data to place at x,y.
  247. *
  248. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  249. * in bounds, or if inData is too small to hold the input.
  250. */
  251. public void setDataElements(int x, int y, Object inData) {
  252. sampleModel.setDataElements(x-sampleModelTranslateX,
  253. y-sampleModelTranslateY,
  254. inData, dataBuffer);
  255. }
  256. /**
  257. * Sets the data for a rectangle of pixels from an input Raster.
  258. * The input Raster must be compatible with this WritableRaster
  259. * in that they must have the same number of bands, corresponding bands
  260. * must have the same number of bits per sample, the TransferTypes
  261. * and NumDataElements must be the same, and the packing used by
  262. * the getDataElements/setDataElements must be identical.
  263. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  264. * not in bounds.
  265. * However, explicit bounds checking is not guaranteed.
  266. * @param x The X coordinate of the pixel location.
  267. * @param y The Y coordinate of the pixel location.
  268. * @param inRaster Raster containing data to place at x,y.
  269. *
  270. * @throws NullPointerException if inRaster is null.
  271. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  272. * in bounds.
  273. */
  274. public void setDataElements(int x, int y, Raster inRaster) {
  275. int dstOffX = x+inRaster.getMinX();
  276. int dstOffY = y+inRaster.getMinY();
  277. int width = inRaster.getWidth();
  278. int height = inRaster.getHeight();
  279. if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
  280. (dstOffX + width > this.minX + this.width) ||
  281. (dstOffY + height > this.minY + this.height)) {
  282. throw new ArrayIndexOutOfBoundsException
  283. ("Coordinate out of bounds!");
  284. }
  285. int srcOffX = inRaster.getMinX();
  286. int srcOffY = inRaster.getMinY();
  287. Object tdata = null;
  288. for (int startY=0; startY < height; startY++) {
  289. tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
  290. width, 1, tdata);
  291. setDataElements(dstOffX, dstOffY+startY,
  292. width, 1, tdata);
  293. }
  294. }
  295. /**
  296. * Sets the data for a rectangle of pixels from a
  297. * primitive array of type TransferType. For image data supported by
  298. * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
  299. * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  300. * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
  301. * may be in a packed format, thus increasing efficiency for data
  302. * transfers.
  303. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  304. * not in bounds, or if inData is not large enough to hold the pixel data.
  305. * However, explicit bounds checking is not guaranteed.
  306. * A ClassCastException will be thrown if the input object is not null
  307. * and references anything other than an array of TransferType.
  308. * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, Object, DataBuffer)
  309. * @param x The X coordinate of the upper left pixel location.
  310. * @param y The Y coordinate of the upper left pixel location.
  311. * @param w Width of the pixel rectangle.
  312. * @param h Height of the pixel rectangle.
  313. * @param inData An object reference to an array of type defined by
  314. * getTransferType() and length w*h*getNumDataElements()
  315. * containing the pixel data to place between x,y and
  316. * x+w-1, y+h-1.
  317. *
  318. * @throws NullPointerException if inData is null.
  319. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  320. * in bounds, or if inData is too small to hold the input.
  321. */
  322. public void setDataElements(int x, int y, int w, int h, Object inData) {
  323. sampleModel.setDataElements(x-sampleModelTranslateX,
  324. y-sampleModelTranslateY,
  325. w,h,inData,dataBuffer);
  326. }
  327. /**
  328. * Copies pixels from Raster srcRaster to this WritableRaster. Each pixel
  329. * in srcRaster is copied to the same x,y address in this raster, unless
  330. * the address falls outside the bounds of this raster. srcRaster
  331. * must have the same number of bands as this WritableRaster. The
  332. * copy is a simple copy of source samples to the corresponding destination
  333. * samples.
  334. * <p>
  335. * If all samples of both source and destination Rasters are of
  336. * integral type and less than or equal to 32 bits in size, then calling
  337. * this method is equivalent to executing the following code for all
  338. * <code>x,y</code> addresses valid in both Rasters.
  339. * <pre>
  340. * Raster srcRaster;
  341. * WritableRaster dstRaster;
  342. * for (int b = 0; b < srcRaster.getNumBands(); b++) {
  343. * dstRaster.setSample(x, y, b, srcRaster.getSample(x, y, b));
  344. * }
  345. * </pre>
  346. * Thus, when copying an integral type source to an integral type
  347. * destination, if the source sample size is greater than the destination
  348. * sample size for a particular band, the high order bits of the source
  349. * sample are truncated. If the source sample size is less than the
  350. * destination size for a particular band, the high order bits of the
  351. * destination are zero-extended or sign-extended depending on whether
  352. * srcRaster's SampleModel treats the sample as a signed or unsigned
  353. * quantity.
  354. * <p>
  355. * When copying a float or double source to an integral type destination,
  356. * each source sample is cast to the destination type. When copying an
  357. * integral type source to a float or double destination, the source
  358. * is first converted to a 32-bit int (if necessary), using the above
  359. * rules for integral types, and then the int is cast to float or
  360. * double.
  361. * <p>
  362. * @param srcRaster The Raster from which to copy pixels.
  363. *
  364. * @throws NullPointerException if srcRaster is null.
  365. */
  366. public void setRect(Raster srcRaster) {
  367. setRect(0,0,srcRaster);
  368. }
  369. /**
  370. * Copies pixels from Raster srcRaster to this WritableRaster.
  371. * For each (x, y) address in srcRaster, the corresponding pixel
  372. * is copied to address (x+dx, y+dy) in this WritableRaster,
  373. * unless (x+dx, y+dy) falls outside the bounds of this raster.
  374. * srcRaster must have the same number of bands as this WritableRaster.
  375. * The copy is a simple copy of source samples to the corresponding
  376. * destination samples. For details, see
  377. * {@link WritableRaster#setRect(Raster)}.
  378. *
  379. * @param dx The X translation factor from src space to dst space
  380. * of the copy.
  381. * @param dy The Y translation factor from src space to dst space
  382. * of the copy.
  383. * @param srcRaster The Raster from which to copy pixels.
  384. *
  385. * @throws NullPointerException if srcRaster is null.
  386. */
  387. public void setRect(int dx, int dy, Raster srcRaster) {
  388. int width = srcRaster.getWidth();
  389. int height = srcRaster.getHeight();
  390. int srcOffX = srcRaster.getMinX();
  391. int srcOffY = srcRaster.getMinY();
  392. int dstOffX = dx+srcOffX;
  393. int dstOffY = dy+srcOffY;
  394. // Clip to this raster
  395. if (dstOffX < this.minX) {
  396. int skipX = this.minX - dstOffX;
  397. width -= skipX;
  398. srcOffX += skipX;
  399. dstOffX = this.minX;
  400. }
  401. if (dstOffY < this.minY) {
  402. int skipY = this.minY - dstOffY;
  403. height -= skipY;
  404. srcOffY += skipY;
  405. dstOffY = this.minY;
  406. }
  407. if (dstOffX+width > this.minX+this.width) {
  408. width = this.minX + this.width - dstOffX;
  409. }
  410. if (dstOffY+height > this.minY+this.height) {
  411. height = this.minY + this.height - dstOffY;
  412. }
  413. if (width <= 0 || height <= 0) {
  414. return;
  415. }
  416. switch (srcRaster.getSampleModel().getDataType()) {
  417. case DataBuffer.TYPE_BYTE:
  418. case DataBuffer.TYPE_SHORT:
  419. case DataBuffer.TYPE_USHORT:
  420. case DataBuffer.TYPE_INT:
  421. int[] iData = null;
  422. for (int startY=0; startY < height; startY++) {
  423. // Grab one scanline at a time
  424. iData =
  425. srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
  426. iData);
  427. setPixels(dstOffX, dstOffY+startY, width, 1, iData);
  428. }
  429. break;
  430. case DataBuffer.TYPE_FLOAT:
  431. float[] fData = null;
  432. for (int startY=0; startY < height; startY++) {
  433. fData =
  434. srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
  435. fData);
  436. setPixels(dstOffX, dstOffY+startY, width, 1, fData);
  437. }
  438. break;
  439. case DataBuffer.TYPE_DOUBLE:
  440. double[] dData = null;
  441. for (int startY=0; startY < height; startY++) {
  442. // Grab one scanline at a time
  443. dData =
  444. srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
  445. dData);
  446. setPixels(dstOffX, dstOffY+startY, width, 1, dData);
  447. }
  448. break;
  449. }
  450. }
  451. /**
  452. * Sets a pixel in the DataBuffer using an int array of samples for input.
  453. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  454. * not in bounds.
  455. * However, explicit bounds checking is not guaranteed.
  456. * @param x The X coordinate of the pixel location.
  457. * @param y The Y coordinate of the pixel location.
  458. * @param iArray The input samples in a int array.
  459. *
  460. * @throws NullPointerException if iArray is null.
  461. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  462. * in bounds, or if iArray is too small to hold the input.
  463. */
  464. public void setPixel(int x, int y, int iArray[]) {
  465. sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
  466. iArray,dataBuffer);
  467. }
  468. /**
  469. * Sets a pixel in the DataBuffer using a float array of samples for input.
  470. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  471. * not in bounds.
  472. * However, explicit bounds checking is not guaranteed.
  473. * @param x The X coordinate of the pixel location.
  474. * @param y The Y coordinate of the pixel location.
  475. * @param fArray The input samples in a float array.
  476. *
  477. * @throws NullPointerException if fArray is null.
  478. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  479. * in bounds, or if fArray is too small to hold the input.
  480. */
  481. public void setPixel(int x, int y, float fArray[]) {
  482. sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
  483. fArray,dataBuffer);
  484. }
  485. /**
  486. * Sets a pixel in the DataBuffer using a double array of samples for input.
  487. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  488. * not in bounds.
  489. * However, explicit bounds checking is not guaranteed.
  490. * @param x The X coordinate of the pixel location.
  491. * @param y The Y coordinate of the pixel location.
  492. * @param dArray The input samples in a double array.
  493. *
  494. * @throws NullPointerException if dArray is null.
  495. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  496. * in bounds, or if dArray is too small to hold the input.
  497. */
  498. public void setPixel(int x, int y, double dArray[]) {
  499. sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
  500. dArray,dataBuffer);
  501. }
  502. /**
  503. * Sets all samples for a rectangle of pixels from an int array containing
  504. * one sample per array element.
  505. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  506. * not in bounds.
  507. * However, explicit bounds checking is not guaranteed.
  508. * @param x The X coordinate of the upper left pixel location.
  509. * @param y The Y coordinate of the upper left pixel location.
  510. * @param w Width of the pixel rectangle.
  511. * @param h Height of the pixel rectangle.
  512. * @param iArray The input int pixel array.
  513. *
  514. * @throws NullPointerException if iArray is null.
  515. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  516. * in bounds, or if iArray is too small to hold the input.
  517. */
  518. public void setPixels(int x, int y, int w, int h, int iArray[]) {
  519. sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
  520. w,h,iArray,dataBuffer);
  521. }
  522. /**
  523. * Sets all samples for a rectangle of pixels from a float array containing
  524. * one sample per array element.
  525. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  526. * not in bounds.
  527. * However, explicit bounds checking is not guaranteed.
  528. * @param x The X coordinate of the upper left pixel location.
  529. * @param y The Y coordinate of the upper left pixel location.
  530. * @param w Width of the pixel rectangle.
  531. * @param h Height of the pixel rectangle.
  532. * @param fArray The input float pixel array.
  533. *
  534. * @throws NullPointerException if fArray is null.
  535. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  536. * in bounds, or if fArray is too small to hold the input.
  537. */
  538. public void setPixels(int x, int y, int w, int h, float fArray[]) {
  539. sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
  540. w,h,fArray,dataBuffer);
  541. }
  542. /**
  543. * Sets all samples for a rectangle of pixels from a double array containing
  544. * one sample per array element.
  545. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  546. * not in bounds.
  547. * However, explicit bounds checking is not guaranteed.
  548. * @param x The X coordinate of the upper left pixel location.
  549. * @param y The Y coordinate of the upper left pixel location.
  550. * @param w Width of the pixel rectangle.
  551. * @param h Height of the pixel rectangle.
  552. * @param dArray The input double pixel array.
  553. *
  554. * @throws NullPointerException if dArray is null.
  555. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  556. * in bounds, or if dArray is too small to hold the input.
  557. */
  558. public void setPixels(int x, int y, int w, int h, double dArray[]) {
  559. sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
  560. w,h,dArray,dataBuffer);
  561. }
  562. /**
  563. * Sets a sample in the specified band for the pixel located at (x,y)
  564. * in the DataBuffer using an int for input.
  565. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  566. * not in bounds.
  567. * However, explicit bounds checking is not guaranteed.
  568. * @param x The X coordinate of the pixel location.
  569. * @param y The Y coordinate of the pixel location.
  570. * @param b The band to set.
  571. * @param s The input sample.
  572. *
  573. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  574. * the band index are not in bounds.
  575. */
  576. public void setSample(int x, int y, int b, int s) {
  577. sampleModel.setSample(x-sampleModelTranslateX,
  578. y-sampleModelTranslateY, b, s,
  579. dataBuffer);
  580. }
  581. /**
  582. * Sets a sample in the specified band for the pixel located at (x,y)
  583. * in the DataBuffer using a float for input.
  584. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  585. * not in bounds.
  586. * However, explicit bounds checking is not guaranteed.
  587. * @param x The X coordinate of the pixel location.
  588. * @param y The Y coordinate of the pixel location.
  589. * @param b The band to set.
  590. * @param s The input sample as a float.
  591. *
  592. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  593. * the band index are not in bounds.
  594. */
  595. public void setSample(int x, int y, int b, float s){
  596. sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
  597. b,s,dataBuffer);
  598. }
  599. /**
  600. * Sets a sample in the specified band for the pixel located at (x,y)
  601. * in the DataBuffer using a double for input.
  602. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  603. * not in bounds.
  604. * However, explicit bounds checking is not guaranteed.
  605. * @param x The X coordinate of the pixel location.
  606. * @param y The Y coordinate of the pixel location.
  607. * @param b The band to set.
  608. * @param s The input sample as a double.
  609. *
  610. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  611. * the band index are not in bounds.
  612. */
  613. public void setSample(int x, int y, int b, double s){
  614. sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
  615. b,s,dataBuffer);
  616. }
  617. /**
  618. * Sets the samples in the specified band for the specified rectangle
  619. * of pixels from an int array containing one sample per array element.
  620. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  621. * not in bounds.
  622. * However, explicit bounds checking is not guaranteed.
  623. * @param x The X coordinate of the upper left pixel location.
  624. * @param y The Y coordinate of the upper left pixel location.
  625. * @param w Width of the pixel rectangle.
  626. * @param h Height of the pixel rectangle.
  627. * @param b The band to set.
  628. * @param iArray The input int sample array.
  629. *
  630. * @throws NullPointerException if iArray is null.
  631. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  632. * the band index are not in bounds, or if iArray is too small to
  633. * hold the input.
  634. */
  635. public void setSamples(int x, int y, int w, int h, int b,
  636. int iArray[]) {
  637. sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
  638. w,h,b,iArray,dataBuffer);
  639. }
  640. /**
  641. * Sets the samples in the specified band for the specified rectangle
  642. * of pixels from a float array containing one sample per array element.
  643. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  644. * not in bounds.
  645. * However, explicit bounds checking is not guaranteed.
  646. * @param x The X coordinate of the upper left pixel location.
  647. * @param y The Y coordinate of the upper left pixel location.
  648. * @param w Width of the pixel rectangle.
  649. * @param h Height of the pixel rectangle.
  650. * @param b The band to set.
  651. * @param fArray The input float sample array.
  652. *
  653. * @throws NullPointerException if fArray is null.
  654. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  655. * the band index are not in bounds, or if fArray is too small to
  656. * hold the input.
  657. */
  658. public void setSamples(int x, int y, int w, int h, int b,
  659. float fArray[]) {
  660. sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
  661. w,h,b,fArray,dataBuffer);
  662. }
  663. /**
  664. * Sets the samples in the specified band for the specified rectangle
  665. * of pixels from a double array containing one sample per array element.
  666. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  667. * not in bounds.
  668. * However, explicit bounds checking is not guaranteed.
  669. * @param x The X coordinate of the upper left pixel location.
  670. * @param y The Y coordinate of the upper left pixel location.
  671. * @param w Width of the pixel rectangle.
  672. * @param h Height of the pixel rectangle.
  673. * @param b The band to set.
  674. * @param dArray The input double sample array.
  675. *
  676. * @throws NullPointerException if dArray is null.
  677. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  678. * the band index are not in bounds, or if dArray is too small to
  679. * hold the input.
  680. */
  681. public void setSamples(int x, int y, int w, int h, int b,
  682. double dArray[]) {
  683. sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
  684. w,h,b,dArray,dataBuffer);
  685. }
  686. }