1. /*
  2. * @(#)WritableRaster.java 1.48 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. 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. // we use getDataBuffer() here, which will ensure that notifyStolen()
  221. // is invoked if this is a SunWritableRaster, thus disabling future
  222. // acceleration of this WritableRaster
  223. return new WritableRaster(sm,
  224. getDataBuffer(),
  225. new Rectangle(childMinX,childMinY,
  226. w, h),
  227. new Point(sampleModelTranslateX+deltaX,
  228. sampleModelTranslateY+deltaY),
  229. this);
  230. }
  231. /**
  232. * Sets the data for a single pixel from a
  233. * primitive array of type TransferType. For image data supported by
  234. * the Java 2D(tm) API, this will be one of DataBuffer.TYPE_BYTE,
  235. * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  236. * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
  237. * may be in a packed format, thus increasing efficiency for data
  238. * transfers.
  239. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  240. * not in bounds, or if inData is not large enough to hold the pixel data.
  241. * However, explicit bounds checking is not guaranteed.
  242. * A ClassCastException will be thrown if the input object is not null
  243. * and references anything other than an array of TransferType.
  244. * @see java.awt.image.SampleModel#setDataElements(int, int, Object, DataBuffer)
  245. * @param x The X coordinate of the pixel location.
  246. * @param y The Y coordinate of the pixel location.
  247. * @param inData An object reference to an array of type defined by
  248. * getTransferType() and length getNumDataElements()
  249. * containing the pixel data to place at x,y.
  250. *
  251. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  252. * in bounds, or if inData is too small to hold the input.
  253. */
  254. public void setDataElements(int x, int y, Object inData) {
  255. sampleModel.setDataElements(x-sampleModelTranslateX,
  256. y-sampleModelTranslateY,
  257. inData, dataBuffer);
  258. }
  259. /**
  260. * Sets the data for a rectangle of pixels from an input Raster.
  261. * The input Raster must be compatible with this WritableRaster
  262. * in that they must have the same number of bands, corresponding bands
  263. * must have the same number of bits per sample, the TransferTypes
  264. * and NumDataElements must be the same, and the packing used by
  265. * the getDataElements/setDataElements must be identical.
  266. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  267. * not in bounds.
  268. * However, explicit bounds checking is not guaranteed.
  269. * @param x The X coordinate of the pixel location.
  270. * @param y The Y coordinate of the pixel location.
  271. * @param inRaster Raster containing data to place at x,y.
  272. *
  273. * @throws NullPointerException if inRaster is null.
  274. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  275. * in bounds.
  276. */
  277. public void setDataElements(int x, int y, Raster inRaster) {
  278. int dstOffX = x+inRaster.getMinX();
  279. int dstOffY = y+inRaster.getMinY();
  280. int width = inRaster.getWidth();
  281. int height = inRaster.getHeight();
  282. if ((dstOffX < this.minX) || (dstOffY < this.minY) ||
  283. (dstOffX + width > this.minX + this.width) ||
  284. (dstOffY + height > this.minY + this.height)) {
  285. throw new ArrayIndexOutOfBoundsException
  286. ("Coordinate out of bounds!");
  287. }
  288. int srcOffX = inRaster.getMinX();
  289. int srcOffY = inRaster.getMinY();
  290. Object tdata = null;
  291. for (int startY=0; startY < height; startY++) {
  292. tdata = inRaster.getDataElements(srcOffX, srcOffY+startY,
  293. width, 1, tdata);
  294. setDataElements(dstOffX, dstOffY+startY,
  295. width, 1, tdata);
  296. }
  297. }
  298. /**
  299. * Sets the data for a rectangle of pixels from a
  300. * primitive array of type TransferType. For image data supported by
  301. * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,
  302. * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,
  303. * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE. Data in the array
  304. * may be in a packed format, thus increasing efficiency for data
  305. * transfers.
  306. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  307. * not in bounds, or if inData is not large enough to hold the pixel data.
  308. * However, explicit bounds checking is not guaranteed.
  309. * A ClassCastException will be thrown if the input object is not null
  310. * and references anything other than an array of TransferType.
  311. * @see java.awt.image.SampleModel#setDataElements(int, int, int, int, Object, DataBuffer)
  312. * @param x The X coordinate of the upper left pixel location.
  313. * @param y The Y coordinate of the upper left pixel location.
  314. * @param w Width of the pixel rectangle.
  315. * @param h Height of the pixel rectangle.
  316. * @param inData An object reference to an array of type defined by
  317. * getTransferType() and length w*h*getNumDataElements()
  318. * containing the pixel data to place between x,y and
  319. * x+w-1, y+h-1.
  320. *
  321. * @throws NullPointerException if inData is null.
  322. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  323. * in bounds, or if inData is too small to hold the input.
  324. */
  325. public void setDataElements(int x, int y, int w, int h, Object inData) {
  326. sampleModel.setDataElements(x-sampleModelTranslateX,
  327. y-sampleModelTranslateY,
  328. w,h,inData,dataBuffer);
  329. }
  330. /**
  331. * Copies pixels from Raster srcRaster to this WritableRaster. Each pixel
  332. * in srcRaster is copied to the same x,y address in this raster, unless
  333. * the address falls outside the bounds of this raster. srcRaster
  334. * must have the same number of bands as this WritableRaster. The
  335. * copy is a simple copy of source samples to the corresponding destination
  336. * samples.
  337. * <p>
  338. * If all samples of both source and destination Rasters are of
  339. * integral type and less than or equal to 32 bits in size, then calling
  340. * this method is equivalent to executing the following code for all
  341. * <code>x,y</code> addresses valid in both Rasters.
  342. * <pre>
  343. * Raster srcRaster;
  344. * WritableRaster dstRaster;
  345. * for (int b = 0; b < srcRaster.getNumBands(); b++) {
  346. * dstRaster.setSample(x, y, b, srcRaster.getSample(x, y, b));
  347. * }
  348. * </pre>
  349. * Thus, when copying an integral type source to an integral type
  350. * destination, if the source sample size is greater than the destination
  351. * sample size for a particular band, the high order bits of the source
  352. * sample are truncated. If the source sample size is less than the
  353. * destination size for a particular band, the high order bits of the
  354. * destination are zero-extended or sign-extended depending on whether
  355. * srcRaster's SampleModel treats the sample as a signed or unsigned
  356. * quantity.
  357. * <p>
  358. * When copying a float or double source to an integral type destination,
  359. * each source sample is cast to the destination type. When copying an
  360. * integral type source to a float or double destination, the source
  361. * is first converted to a 32-bit int (if necessary), using the above
  362. * rules for integral types, and then the int is cast to float or
  363. * double.
  364. * <p>
  365. * @param srcRaster The Raster from which to copy pixels.
  366. *
  367. * @throws NullPointerException if srcRaster is null.
  368. */
  369. public void setRect(Raster srcRaster) {
  370. setRect(0,0,srcRaster);
  371. }
  372. /**
  373. * Copies pixels from Raster srcRaster to this WritableRaster.
  374. * For each (x, y) address in srcRaster, the corresponding pixel
  375. * is copied to address (x+dx, y+dy) in this WritableRaster,
  376. * unless (x+dx, y+dy) falls outside the bounds of this raster.
  377. * srcRaster must have the same number of bands as this WritableRaster.
  378. * The copy is a simple copy of source samples to the corresponding
  379. * destination samples. For details, see
  380. * {@link WritableRaster#setRect(Raster)}.
  381. *
  382. * @param dx The X translation factor from src space to dst space
  383. * of the copy.
  384. * @param dy The Y translation factor from src space to dst space
  385. * of the copy.
  386. * @param srcRaster The Raster from which to copy pixels.
  387. *
  388. * @throws NullPointerException if srcRaster is null.
  389. */
  390. public void setRect(int dx, int dy, Raster srcRaster) {
  391. int width = srcRaster.getWidth();
  392. int height = srcRaster.getHeight();
  393. int srcOffX = srcRaster.getMinX();
  394. int srcOffY = srcRaster.getMinY();
  395. int dstOffX = dx+srcOffX;
  396. int dstOffY = dy+srcOffY;
  397. // Clip to this raster
  398. if (dstOffX < this.minX) {
  399. int skipX = this.minX - dstOffX;
  400. width -= skipX;
  401. srcOffX += skipX;
  402. dstOffX = this.minX;
  403. }
  404. if (dstOffY < this.minY) {
  405. int skipY = this.minY - dstOffY;
  406. height -= skipY;
  407. srcOffY += skipY;
  408. dstOffY = this.minY;
  409. }
  410. if (dstOffX+width > this.minX+this.width) {
  411. width = this.minX + this.width - dstOffX;
  412. }
  413. if (dstOffY+height > this.minY+this.height) {
  414. height = this.minY + this.height - dstOffY;
  415. }
  416. if (width <= 0 || height <= 0) {
  417. return;
  418. }
  419. switch (srcRaster.getSampleModel().getDataType()) {
  420. case DataBuffer.TYPE_BYTE:
  421. case DataBuffer.TYPE_SHORT:
  422. case DataBuffer.TYPE_USHORT:
  423. case DataBuffer.TYPE_INT:
  424. int[] iData = null;
  425. for (int startY=0; startY < height; startY++) {
  426. // Grab one scanline at a time
  427. iData =
  428. srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
  429. iData);
  430. setPixels(dstOffX, dstOffY+startY, width, 1, iData);
  431. }
  432. break;
  433. case DataBuffer.TYPE_FLOAT:
  434. float[] fData = null;
  435. for (int startY=0; startY < height; startY++) {
  436. fData =
  437. srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
  438. fData);
  439. setPixels(dstOffX, dstOffY+startY, width, 1, fData);
  440. }
  441. break;
  442. case DataBuffer.TYPE_DOUBLE:
  443. double[] dData = null;
  444. for (int startY=0; startY < height; startY++) {
  445. // Grab one scanline at a time
  446. dData =
  447. srcRaster.getPixels(srcOffX, srcOffY+startY, width, 1,
  448. dData);
  449. setPixels(dstOffX, dstOffY+startY, width, 1, dData);
  450. }
  451. break;
  452. }
  453. }
  454. /**
  455. * Sets a pixel in the DataBuffer using an int array of samples for input.
  456. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  457. * not in bounds.
  458. * However, explicit bounds checking is not guaranteed.
  459. * @param x The X coordinate of the pixel location.
  460. * @param y The Y coordinate of the pixel location.
  461. * @param iArray The input samples in a int array.
  462. *
  463. * @throws NullPointerException if iArray is null.
  464. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  465. * in bounds, or if iArray is too small to hold the input.
  466. */
  467. public void setPixel(int x, int y, int iArray[]) {
  468. sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
  469. iArray,dataBuffer);
  470. }
  471. /**
  472. * Sets a pixel in the DataBuffer using a float array of samples for input.
  473. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  474. * not in bounds.
  475. * However, explicit bounds checking is not guaranteed.
  476. * @param x The X coordinate of the pixel location.
  477. * @param y The Y coordinate of the pixel location.
  478. * @param fArray The input samples in a float array.
  479. *
  480. * @throws NullPointerException if fArray is null.
  481. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  482. * in bounds, or if fArray is too small to hold the input.
  483. */
  484. public void setPixel(int x, int y, float fArray[]) {
  485. sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
  486. fArray,dataBuffer);
  487. }
  488. /**
  489. * Sets a pixel in the DataBuffer using a double array of samples for input.
  490. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  491. * not in bounds.
  492. * However, explicit bounds checking is not guaranteed.
  493. * @param x The X coordinate of the pixel location.
  494. * @param y The Y coordinate of the pixel location.
  495. * @param dArray The input samples in a double array.
  496. *
  497. * @throws NullPointerException if dArray is null.
  498. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  499. * in bounds, or if dArray is too small to hold the input.
  500. */
  501. public void setPixel(int x, int y, double dArray[]) {
  502. sampleModel.setPixel(x-sampleModelTranslateX,y-sampleModelTranslateY,
  503. dArray,dataBuffer);
  504. }
  505. /**
  506. * Sets all samples for a rectangle of pixels from an int array containing
  507. * one sample per array element.
  508. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  509. * not in bounds.
  510. * However, explicit bounds checking is not guaranteed.
  511. * @param x The X coordinate of the upper left pixel location.
  512. * @param y The Y coordinate of the upper left pixel location.
  513. * @param w Width of the pixel rectangle.
  514. * @param h Height of the pixel rectangle.
  515. * @param iArray The input int pixel array.
  516. *
  517. * @throws NullPointerException if iArray is null.
  518. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  519. * in bounds, or if iArray is too small to hold the input.
  520. */
  521. public void setPixels(int x, int y, int w, int h, int iArray[]) {
  522. sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
  523. w,h,iArray,dataBuffer);
  524. }
  525. /**
  526. * Sets all samples for a rectangle of pixels from a float array containing
  527. * one sample per array element.
  528. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  529. * not in bounds.
  530. * However, explicit bounds checking is not guaranteed.
  531. * @param x The X coordinate of the upper left pixel location.
  532. * @param y The Y coordinate of the upper left pixel location.
  533. * @param w Width of the pixel rectangle.
  534. * @param h Height of the pixel rectangle.
  535. * @param fArray The input float pixel array.
  536. *
  537. * @throws NullPointerException if fArray is null.
  538. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  539. * in bounds, or if fArray is too small to hold the input.
  540. */
  541. public void setPixels(int x, int y, int w, int h, float fArray[]) {
  542. sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
  543. w,h,fArray,dataBuffer);
  544. }
  545. /**
  546. * Sets all samples for a rectangle of pixels from a double array containing
  547. * one sample per array element.
  548. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  549. * not in bounds.
  550. * However, explicit bounds checking is not guaranteed.
  551. * @param x The X coordinate of the upper left pixel location.
  552. * @param y The Y coordinate of the upper left pixel location.
  553. * @param w Width of the pixel rectangle.
  554. * @param h Height of the pixel rectangle.
  555. * @param dArray The input double pixel array.
  556. *
  557. * @throws NullPointerException if dArray is null.
  558. * @throws ArrayIndexOutOfBoundsException if the coordinates are not
  559. * in bounds, or if dArray is too small to hold the input.
  560. */
  561. public void setPixels(int x, int y, int w, int h, double dArray[]) {
  562. sampleModel.setPixels(x-sampleModelTranslateX,y-sampleModelTranslateY,
  563. w,h,dArray,dataBuffer);
  564. }
  565. /**
  566. * Sets a sample in the specified band for the pixel located at (x,y)
  567. * in the DataBuffer using an int for input.
  568. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  569. * not in bounds.
  570. * However, explicit bounds checking is not guaranteed.
  571. * @param x The X coordinate of the pixel location.
  572. * @param y The Y coordinate of the pixel location.
  573. * @param b The band to set.
  574. * @param s The input sample.
  575. *
  576. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  577. * the band index are not in bounds.
  578. */
  579. public void setSample(int x, int y, int b, int s) {
  580. sampleModel.setSample(x-sampleModelTranslateX,
  581. y-sampleModelTranslateY, b, s,
  582. dataBuffer);
  583. }
  584. /**
  585. * Sets a sample in the specified band for the pixel located at (x,y)
  586. * in the DataBuffer using a float for input.
  587. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  588. * not in bounds.
  589. * However, explicit bounds checking is not guaranteed.
  590. * @param x The X coordinate of the pixel location.
  591. * @param y The Y coordinate of the pixel location.
  592. * @param b The band to set.
  593. * @param s The input sample as a float.
  594. *
  595. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  596. * the band index are not in bounds.
  597. */
  598. public void setSample(int x, int y, int b, float s){
  599. sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
  600. b,s,dataBuffer);
  601. }
  602. /**
  603. * Sets a sample in the specified band for the pixel located at (x,y)
  604. * in the DataBuffer using a double for input.
  605. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  606. * not in bounds.
  607. * However, explicit bounds checking is not guaranteed.
  608. * @param x The X coordinate of the pixel location.
  609. * @param y The Y coordinate of the pixel location.
  610. * @param b The band to set.
  611. * @param s The input sample as a double.
  612. *
  613. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  614. * the band index are not in bounds.
  615. */
  616. public void setSample(int x, int y, int b, double s){
  617. sampleModel.setSample(x-sampleModelTranslateX,y-sampleModelTranslateY,
  618. b,s,dataBuffer);
  619. }
  620. /**
  621. * Sets the samples in the specified band for the specified rectangle
  622. * of pixels from an int array containing one sample per array element.
  623. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  624. * not in bounds.
  625. * However, explicit bounds checking is not guaranteed.
  626. * @param x The X coordinate of the upper left pixel location.
  627. * @param y The Y coordinate of the upper left pixel location.
  628. * @param w Width of the pixel rectangle.
  629. * @param h Height of the pixel rectangle.
  630. * @param b The band to set.
  631. * @param iArray The input int sample array.
  632. *
  633. * @throws NullPointerException if iArray is null.
  634. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  635. * the band index are not in bounds, or if iArray is too small to
  636. * hold the input.
  637. */
  638. public void setSamples(int x, int y, int w, int h, int b,
  639. int iArray[]) {
  640. sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
  641. w,h,b,iArray,dataBuffer);
  642. }
  643. /**
  644. * Sets the samples in the specified band for the specified rectangle
  645. * of pixels from a float array containing one sample per array element.
  646. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  647. * not in bounds.
  648. * However, explicit bounds checking is not guaranteed.
  649. * @param x The X coordinate of the upper left pixel location.
  650. * @param y The Y coordinate of the upper left pixel location.
  651. * @param w Width of the pixel rectangle.
  652. * @param h Height of the pixel rectangle.
  653. * @param b The band to set.
  654. * @param fArray The input float sample array.
  655. *
  656. * @throws NullPointerException if fArray is null.
  657. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  658. * the band index are not in bounds, or if fArray is too small to
  659. * hold the input.
  660. */
  661. public void setSamples(int x, int y, int w, int h, int b,
  662. float fArray[]) {
  663. sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
  664. w,h,b,fArray,dataBuffer);
  665. }
  666. /**
  667. * Sets the samples in the specified band for the specified rectangle
  668. * of pixels from a double array containing one sample per array element.
  669. * An ArrayIndexOutOfBoundsException may be thrown if the coordinates are
  670. * not in bounds.
  671. * However, explicit bounds checking is not guaranteed.
  672. * @param x The X coordinate of the upper left pixel location.
  673. * @param y The Y coordinate of the upper left pixel location.
  674. * @param w Width of the pixel rectangle.
  675. * @param h Height of the pixel rectangle.
  676. * @param b The band to set.
  677. * @param dArray The input double sample array.
  678. *
  679. * @throws NullPointerException if dArray is null.
  680. * @throws ArrayIndexOutOfBoundsException if the coordinates or
  681. * the band index are not in bounds, or if dArray is too small to
  682. * hold the input.
  683. */
  684. public void setSamples(int x, int y, int w, int h, int b,
  685. double dArray[]) {
  686. sampleModel.setSamples(x-sampleModelTranslateX,y-sampleModelTranslateY,
  687. w,h,b,dArray,dataBuffer);
  688. }
  689. }