Frames | No Frames |
1: /* Copyright (C) 2000, 2001, 2002, 2005, 2006, Free Software Foundation 2: 3: This file is part of GNU Classpath. 4: 5: GNU Classpath is free software; you can redistribute it and/or modify 6: it under the terms of the GNU General Public License as published by 7: the Free Software Foundation; either version 2, or (at your option) 8: any later version. 9: 10: GNU Classpath is distributed in the hope that it will be useful, but 11: WITHOUT ANY WARRANTY; without even the implied warranty of 12: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13: General Public License for more details. 14: 15: You should have received a copy of the GNU General Public License 16: along with GNU Classpath; see the file COPYING. If not, write to the 17: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 18: 02110-1301 USA. 19: 20: Linking this library statically or dynamically with other modules is 21: making a combined work based on this library. Thus, the terms and 22: conditions of the GNU General Public License cover the whole 23: combination. 24: 25: As a special exception, the copyright holders of this library give you 26: permission to link this library with independent modules to produce an 27: executable, regardless of the license terms of these independent 28: modules, and to copy and distribute the resulting executable under 29: terms of your choice, provided that you also meet, for each linked 30: independent module, the terms and conditions of the license of that 31: module. An independent module is a module which is not derived from 32: or based on this library. If you modify this library, you may extend 33: this exception to your version of the library, but you are not 34: obligated to do so. If you do not wish to do so, delete this 35: exception statement from your version. */ 36: 37: package java.awt.image; 38: 39: /** 40: * A <code>SampleModel</code> is used to access pixel data from a 41: * {@link DataBuffer}. This is used by the {@link Raster} class. 42: * 43: * @author Rolf W. Rasmussen (rolfwr@ii.uib.no) 44: */ 45: public abstract class SampleModel 46: { 47: /** Width of image described. */ 48: protected int width; 49: 50: /** Height of image described. */ 51: protected int height; 52: 53: /** Number of bands in the image described. Package-private here, 54: shadowed by ComponentSampleModel. */ 55: protected int numBands; 56: 57: /** 58: * The DataBuffer type that is used to store the data of the image 59: * described. 60: */ 61: protected int dataType; 62: 63: /** 64: * Creates a new sample model with the specified attributes. 65: * 66: * @param dataType the data type (one of {@link DataBuffer#TYPE_BYTE}, 67: * {@link DataBuffer#TYPE_USHORT}, {@link DataBuffer#TYPE_SHORT}, 68: * {@link DataBuffer#TYPE_INT}, {@link DataBuffer#TYPE_FLOAT}, 69: * {@link DataBuffer#TYPE_DOUBLE} or {@link DataBuffer#TYPE_UNDEFINED}). 70: * @param w the width in pixels (must be greater than zero). 71: * @param h the height in pixels (must be greater than zero). 72: * @param numBands the number of bands (must be greater than zero). 73: * 74: * @throws IllegalArgumentException if <code>dataType</code> is not one of 75: * the listed values. 76: * @throws IllegalArgumentException if <code>w</code> is less than or equal 77: * to zero. 78: * @throws IllegalArgumentException if <code>h</code> is less than or equal 79: * to zero. 80: * @throws IllegalArgumentException if <code>w * h</code> is greater than 81: * {@link Integer#MAX_VALUE}. 82: */ 83: public SampleModel(int dataType, int w, int h, int numBands) 84: { 85: if (dataType != DataBuffer.TYPE_UNDEFINED) 86: if (dataType < DataBuffer.TYPE_BYTE || dataType > DataBuffer.TYPE_DOUBLE) 87: throw new IllegalArgumentException("Unrecognised 'dataType' argument."); 88: 89: if ((w <= 0) || (h <= 0)) 90: throw new IllegalArgumentException((w <= 0 ? " width<=0" : " width is ok") 91: + (h <= 0 ? " height<=0" : " height is ok")); 92: 93: long area = (long) w * (long) h; 94: if (area > Integer.MAX_VALUE) 95: throw new IllegalArgumentException("w * h exceeds Integer.MAX_VALUE."); 96: 97: if (numBands <= 0) 98: throw new IllegalArgumentException("Requires numBands > 0."); 99: 100: this.dataType = dataType; 101: this.width = w; 102: this.height = h; 103: this.numBands = numBands; 104: } 105: 106: /** 107: * Returns the width of the pixel data accessible via this 108: * <code>SampleModel</code>. 109: * 110: * @return The width. 111: * 112: * @see #getHeight() 113: */ 114: public final int getWidth() 115: { 116: return width; 117: } 118: 119: /** 120: * Returns the height of the pixel data accessible via this 121: * <code>SampleModel</code>. 122: * 123: * @return The height. 124: * 125: * @see #getWidth() 126: */ 127: public final int getHeight() 128: { 129: return height; 130: } 131: 132: /** 133: * Returns the number of bands for this <code>SampleModel</code>. 134: * 135: * @return The number of bands. 136: */ 137: public final int getNumBands() 138: { 139: return numBands; 140: } 141: 142: public abstract int getNumDataElements(); 143: 144: /** 145: * Returns the type of the {@link DataBuffer} that this 146: * <code>SampleModel</code> accesses. 147: * 148: * @return The data buffer type. 149: */ 150: public final int getDataType() 151: { 152: return dataType; 153: } 154: 155: public int getTransferType() 156: { 157: // FIXME: Is this a reasonable default implementation? 158: return dataType; 159: } 160: 161: /** 162: * Returns an array containing the samples for the pixel at (x, y) in the 163: * specified data buffer. If <code>iArray</code> is not <code>null</code>, 164: * it will be populated with the sample values and returned as the result of 165: * this function (this avoids allocating a new array instance). 166: * 167: * @param x the x-coordinate of the pixel. 168: * @param y the y-coordinate of the pixel. 169: * @param iArray an array to populate with the sample values and return as 170: * the result (if <code>null</code>, a new array will be allocated). 171: * @param data the data buffer (<code>null</code> not permitted). 172: * 173: * @return The pixel sample values. 174: * 175: * @throws NullPointerException if <code>data</code> is <code>null</code>. 176: */ 177: public int[] getPixel(int x, int y, int[] iArray, DataBuffer data) 178: { 179: if (iArray == null) 180: iArray = new int[numBands]; 181: for (int b = 0; b < numBands; b++) 182: iArray[b] = getSample(x, y, b, data); 183: return iArray; 184: } 185: 186: /** 187: * 188: * This method is provided as a faster alternative to getPixel(), 189: * that can be used when there is no need to decode the pixel into 190: * separate sample values. 191: * 192: * @param obj An array to return the pixel data in. If null, an 193: * array of the right type and size will be created. 194: * 195: * @return A single pixel as an array object of a primitive type, 196: * based on the transfer type. Eg. if transfer type is 197: * DataBuffer.TYPE_USHORT, then a short[] object is returned. 198: */ 199: public abstract Object getDataElements(int x, int y, Object obj, 200: DataBuffer data); 201: 202: 203: public Object getDataElements(int x, int y, int w, int h, Object obj, 204: DataBuffer data) 205: { 206: int size = w * h; 207: int numDataElements = getNumDataElements(); 208: int dataSize = numDataElements * size; 209: 210: if (obj == null) 211: { 212: switch (getTransferType()) 213: { 214: case DataBuffer.TYPE_BYTE: 215: obj = new byte[dataSize]; 216: break; 217: case DataBuffer.TYPE_USHORT: 218: obj = new short[dataSize]; 219: break; 220: case DataBuffer.TYPE_INT: 221: obj = new int[dataSize]; 222: break; 223: default: 224: // Seems like the only sensible thing to do. 225: throw new ClassCastException(); 226: } 227: } 228: Object pixelData = null; 229: int outOffset = 0; 230: for (int yy = y; yy < (y + h); yy++) 231: { 232: for (int xx = x; xx < (x + w); xx++) 233: { 234: pixelData = getDataElements(xx, yy, pixelData, data); 235: System.arraycopy(pixelData, 0, obj, outOffset, 236: numDataElements); 237: outOffset += numDataElements; 238: } 239: } 240: return obj; 241: } 242: 243: public abstract void setDataElements(int x, int y, Object obj, 244: DataBuffer data); 245: 246: public void setDataElements(int x, int y, int w, int h, 247: Object obj, DataBuffer data) 248: { 249: int size = w * h; 250: int numDataElements = getNumDataElements(); 251: int dataSize = numDataElements * size; 252: 253: Object pixelData; 254: switch (getTransferType()) 255: { 256: case DataBuffer.TYPE_BYTE: 257: pixelData = new byte[numDataElements]; 258: break; 259: case DataBuffer.TYPE_USHORT: 260: pixelData = new short[numDataElements]; 261: break; 262: case DataBuffer.TYPE_INT: 263: pixelData = new int[numDataElements]; 264: break; 265: default: 266: // Seems like the only sensible thing to do. 267: throw new ClassCastException(); 268: } 269: int inOffset = 0; 270: 271: for (int yy = y; yy < (y + h); yy++) 272: { 273: for (int xx = x; xx < (x + w); xx++) 274: { 275: System.arraycopy(obj, inOffset, pixelData, 0, 276: numDataElements); 277: setDataElements(xx, yy, pixelData, data); 278: inOffset += numDataElements; 279: } 280: } 281: } 282: 283: /** 284: * Returns an array containing the samples for the pixel at (x, y) in the 285: * specified data buffer. If <code>fArray</code> is not <code>null</code>, 286: * it will be populated with the sample values and returned as the result of 287: * this function (this avoids allocating a new array instance). 288: * 289: * @param x the x-coordinate of the pixel. 290: * @param y the y-coordinate of the pixel. 291: * @param fArray an array to populate with the sample values and return as 292: * the result (if <code>null</code>, a new array will be allocated). 293: * @param data the data buffer (<code>null</code> not permitted). 294: * 295: * @return The pixel sample values. 296: * 297: * @throws NullPointerException if <code>data</code> is <code>null</code>. 298: */ 299: public float[] getPixel(int x, int y, float[] fArray, DataBuffer data) 300: { 301: if (fArray == null) 302: fArray = new float[numBands]; 303: 304: for (int b = 0; b < numBands; b++) 305: { 306: fArray[b] = getSampleFloat(x, y, b, data); 307: } 308: return fArray; 309: } 310: 311: /** 312: * Returns an array containing the samples for the pixel at (x, y) in the 313: * specified data buffer. If <code>dArray</code> is not <code>null</code>, 314: * it will be populated with the sample values and returned as the result of 315: * this function (this avoids allocating a new array instance). 316: * 317: * @param x the x-coordinate of the pixel. 318: * @param y the y-coordinate of the pixel. 319: * @param dArray an array to populate with the sample values and return as 320: * the result (if <code>null</code>, a new array will be allocated). 321: * @param data the data buffer (<code>null</code> not permitted). 322: * 323: * @return The pixel sample values. 324: * 325: * @throws NullPointerException if <code>data</code> is <code>null</code>. 326: */ 327: public double[] getPixel(int x, int y, double[] dArray, DataBuffer data) { 328: if (dArray == null) 329: dArray = new double[numBands]; 330: for (int b = 0; b < numBands; b++) 331: { 332: dArray[b] = getSampleDouble(x, y, b, data); 333: } 334: return dArray; 335: } 336: 337: /** 338: * Returns an array containing the samples for the pixels in the region 339: * specified by (x, y, w, h) in the specified data buffer. The array is 340: * ordered by pixels (that is, all the samples for the first pixel are 341: * grouped together, followed by all the samples for the second pixel, and so 342: * on). If <code>iArray</code> is not <code>null</code>, it will be 343: * populated with the sample values and returned as the result of this 344: * function (this avoids allocating a new array instance). 345: * 346: * @param x the x-coordinate of the top-left pixel. 347: * @param y the y-coordinate of the top-left pixel. 348: * @param w the width of the region of pixels. 349: * @param h the height of the region of pixels. 350: * @param iArray an array to populate with the sample values and return as 351: * the result (if <code>null</code>, a new array will be allocated). 352: * @param data the data buffer (<code>null</code> not permitted). 353: * 354: * @return The pixel sample values. 355: * 356: * @throws NullPointerException if <code>data</code> is <code>null</code>. 357: */ 358: public int[] getPixels(int x, int y, int w, int h, int[] iArray, 359: DataBuffer data) 360: { 361: int size = w * h; 362: int outOffset = 0; 363: int[] pixel = null; 364: if (iArray == null) 365: iArray = new int[w * h * numBands]; 366: for (int yy = y; yy < (y + h); yy++) 367: { 368: for (int xx = x; xx < (x + w); xx++) 369: { 370: pixel = getPixel(xx, yy, pixel, data); 371: System.arraycopy(pixel, 0, iArray, outOffset, numBands); 372: outOffset += numBands; 373: } 374: } 375: return iArray; 376: } 377: 378: /** 379: * Returns an array containing the samples for the pixels in the region 380: * specified by (x, y, w, h) in the specified data buffer. The array is 381: * ordered by pixels (that is, all the samples for the first pixel are 382: * grouped together, followed by all the samples for the second pixel, and so 383: * on). If <code>fArray</code> is not <code>null</code>, it will be 384: * populated with the sample values and returned as the result of this 385: * function (this avoids allocating a new array instance). 386: * 387: * @param x the x-coordinate of the top-left pixel. 388: * @param y the y-coordinate of the top-left pixel. 389: * @param w the width of the region of pixels. 390: * @param h the height of the region of pixels. 391: * @param fArray an array to populate with the sample values and return as 392: * the result (if <code>null</code>, a new array will be allocated). 393: * @param data the data buffer (<code>null</code> not permitted). 394: * 395: * @return The pixel sample values. 396: * 397: * @throws NullPointerException if <code>data</code> is <code>null</code>. 398: */ 399: public float[] getPixels(int x, int y, int w, int h, float[] fArray, 400: DataBuffer data) 401: { 402: int size = w * h; 403: int outOffset = 0; 404: float[] pixel = null; 405: if (fArray == null) fArray = new float[w * h * numBands]; 406: for (int yy = y; yy < (y + h); yy++) 407: { 408: for (int xx = x; xx < (x + w); xx++) 409: { 410: pixel = getPixel(xx, yy, pixel, data); 411: System.arraycopy(pixel, 0, fArray, outOffset, numBands); 412: outOffset += numBands; 413: } 414: } 415: return fArray; 416: } 417: 418: /** 419: * Returns an array containing the samples for the pixels in the region 420: * specified by (x, y, w, h) in the specified data buffer. The array is 421: * ordered by pixels (that is, all the samples for the first pixel are 422: * grouped together, followed by all the samples for the second pixel, and so 423: * on). If <code>dArray</code> is not <code>null</code>, it will be 424: * populated with the sample values and returned as the result of this 425: * function (this avoids allocating a new array instance). 426: * 427: * @param x the x-coordinate of the top-left pixel. 428: * @param y the y-coordinate of the top-left pixel. 429: * @param w the width of the region of pixels. 430: * @param h the height of the region of pixels. 431: * @param dArray an array to populate with the sample values and return as 432: * the result (if <code>null</code>, a new array will be allocated). 433: * @param data the data buffer (<code>null</code> not permitted). 434: * 435: * @return The pixel sample values. 436: * 437: * @throws NullPointerException if <code>data</code> is <code>null</code>. 438: */ 439: public double[] getPixels(int x, int y, int w, int h, double[] dArray, 440: DataBuffer data) 441: { 442: int size = w * h; 443: int outOffset = 0; 444: double[] pixel = null; 445: if (dArray == null) 446: dArray = new double[w * h * numBands]; 447: for (int yy = y; yy < (y + h); yy++) 448: { 449: for (int xx = x; xx < (x + w); xx++) 450: { 451: pixel = getPixel(xx, yy, pixel, data); 452: System.arraycopy(pixel, 0, dArray, outOffset, numBands); 453: outOffset += numBands; 454: } 455: } 456: return dArray; 457: } 458: 459: /** 460: * Returns the sample value for the pixel at (x, y) in the specified data 461: * buffer. 462: * 463: * @param x the x-coordinate of the pixel. 464: * @param y the y-coordinate of the pixel. 465: * @param b the band (in the range <code>0</code> to 466: * <code>getNumBands() - 1</code>). 467: * @param data the data buffer (<code>null</code> not permitted). 468: * 469: * @return The sample value. 470: * 471: * @throws NullPointerException if <code>data</code> is <code>null</code>. 472: */ 473: public abstract int getSample(int x, int y, int b, DataBuffer data); 474: 475: /** 476: * Returns the sample value for the pixel at (x, y) in the specified data 477: * buffer. 478: * 479: * @param x the x-coordinate of the pixel. 480: * @param y the y-coordinate of the pixel. 481: * @param b the band (in the range <code>0</code> to 482: * <code>getNumBands() - 1</code>). 483: * @param data the data buffer (<code>null</code> not permitted). 484: * 485: * @return The sample value. 486: * 487: * @throws NullPointerException if <code>data</code> is <code>null</code>. 488: * 489: * @see #getSample(int, int, int, DataBuffer) 490: */ 491: public float getSampleFloat(int x, int y, int b, DataBuffer data) 492: { 493: return getSample(x, y, b, data); 494: } 495: 496: /** 497: * Returns the sample value for the pixel at (x, y) in the specified data 498: * buffer. 499: * 500: * @param x the x-coordinate of the pixel. 501: * @param y the y-coordinate of the pixel. 502: * @param b the band (in the range <code>0</code> to 503: * <code>getNumBands() - 1</code>). 504: * @param data the data buffer (<code>null</code> not permitted). 505: * 506: * @return The sample value. 507: * 508: * @throws NullPointerException if <code>data</code> is <code>null</code>. 509: * 510: * @see #getSample(int, int, int, DataBuffer) 511: */ 512: public double getSampleDouble(int x, int y, int b, DataBuffer data) 513: { 514: return getSampleFloat(x, y, b, data); 515: } 516: 517: /** 518: * Returns an array containing the samples from one band for the pixels in 519: * the region specified by (x, y, w, h) in the specified data buffer. If 520: * <code>iArray</code> is not <code>null</code>, it will be 521: * populated with the sample values and returned as the result of this 522: * function (this avoids allocating a new array instance). 523: * 524: * @param x the x-coordinate of the top-left pixel. 525: * @param y the y-coordinate of the top-left pixel. 526: * @param w the width of the region of pixels. 527: * @param h the height of the region of pixels. 528: * @param b the band (in the range <code>0</code> to 529: * </code>getNumBands() - 1</code>). 530: * @param iArray an array to populate with the sample values and return as 531: * the result (if <code>null</code>, a new array will be allocated). 532: * @param data the data buffer (<code>null</code> not permitted). 533: * 534: * @return The sample values. 535: * 536: * @throws NullPointerException if <code>data</code> is <code>null</code>. 537: */ 538: public int[] getSamples(int x, int y, int w, int h, int b, 539: int[] iArray, DataBuffer data) 540: { 541: int size = w * h; 542: int outOffset = 0; 543: if (iArray == null) 544: iArray = new int[size]; 545: for (int yy = y; yy < (y + h); yy++) 546: { 547: for (int xx = x; xx < (x + w); xx++) 548: { 549: iArray[outOffset++] = getSample(xx, yy, b, data); 550: } 551: } 552: return iArray; 553: } 554: 555: /** 556: * Returns an array containing the samples from one band for the pixels in 557: * the region specified by (x, y, w, h) in the specified data buffer. If 558: * <code>fArray</code> is not <code>null</code>, it will be 559: * populated with the sample values and returned as the result of this 560: * function (this avoids allocating a new array instance). 561: * 562: * @param x the x-coordinate of the top-left pixel. 563: * @param y the y-coordinate of the top-left pixel. 564: * @param w the width of the region of pixels. 565: * @param h the height of the region of pixels. 566: * @param b the band (in the range <code>0</code> to 567: * </code>getNumBands() - 1</code>). 568: * @param fArray an array to populate with the sample values and return as 569: * the result (if <code>null</code>, a new array will be allocated). 570: * @param data the data buffer (<code>null</code> not permitted). 571: * 572: * @return The sample values. 573: * 574: * @throws NullPointerException if <code>data</code> is <code>null</code>. 575: */ 576: public float[] getSamples(int x, int y, int w, int h, int b, 577: float[] fArray, DataBuffer data) 578: { 579: int size = w * h; 580: int outOffset = 0; 581: if (fArray == null) 582: fArray = new float[size]; 583: for (int yy = y; yy < (y + h); yy++) 584: { 585: for (int xx = x; xx < (x + w); xx++) 586: { 587: fArray[outOffset++] = getSampleFloat(xx, yy, b, data); 588: } 589: } 590: return fArray; 591: } 592: 593: /** 594: * Returns an array containing the samples from one band for the pixels in 595: * the region specified by (x, y, w, h) in the specified data buffer. If 596: * <code>dArray</code> is not <code>null</code>, it will be 597: * populated with the sample values and returned as the result of this 598: * function (this avoids allocating a new array instance). 599: * 600: * @param x the x-coordinate of the top-left pixel. 601: * @param y the y-coordinate of the top-left pixel. 602: * @param w the width of the region of pixels. 603: * @param h the height of the region of pixels. 604: * @param b the band (in the range <code>0</code> to 605: * </code>getNumBands() - 1</code>). 606: * @param dArray an array to populate with the sample values and return as 607: * the result (if <code>null</code>, a new array will be allocated). 608: * @param data the data buffer (<code>null</code> not permitted). 609: * 610: * @return The sample values. 611: * 612: * @throws NullPointerException if <code>data</code> is <code>null</code>. 613: */ 614: public double[] getSamples(int x, int y, int w, int h, int b, 615: double[] dArray, DataBuffer data) 616: { 617: int size = w * h; 618: int outOffset = 0; 619: if (dArray == null) 620: dArray = new double[size]; 621: for (int yy = y; yy < (y + h); yy++) 622: { 623: for (int xx = x; xx < (x + w); xx++) 624: { 625: dArray[outOffset++] = getSampleDouble(xx, yy, b, data); 626: } 627: } 628: return dArray; 629: } 630: 631: /** 632: * Sets the samples for the pixel at (x, y) in the specified data buffer to 633: * the specified values. 634: * 635: * @param x the x-coordinate of the pixel. 636: * @param y the y-coordinate of the pixel. 637: * @param iArray the sample values (<code>null</code> not permitted). 638: * @param data the data buffer (<code>null</code> not permitted). 639: * 640: * @throws NullPointerException if either <code>iArray</code> or 641: * <code>data</code> is <code>null</code>. 642: */ 643: public void setPixel(int x, int y, int[] iArray, DataBuffer data) 644: { 645: for (int b = 0; b < numBands; b++) 646: setSample(x, y, b, iArray[b], data); 647: } 648: 649: /** 650: * Sets the samples for the pixel at (x, y) in the specified data buffer to 651: * the specified values. 652: * 653: * @param x the x-coordinate of the pixel. 654: * @param y the y-coordinate of the pixel. 655: * @param fArray the sample values (<code>null</code> not permitted). 656: * @param data the data buffer (<code>null</code> not permitted). 657: * 658: * @throws NullPointerException if either <code>fArray</code> or 659: * <code>data</code> is <code>null</code>. 660: */ 661: public void setPixel(int x, int y, float[] fArray, DataBuffer data) 662: { 663: for (int b = 0; b < numBands; b++) 664: setSample(x, y, b, fArray[b], data); 665: } 666: 667: /** 668: * Sets the samples for the pixel at (x, y) in the specified data buffer to 669: * the specified values. 670: * 671: * @param x the x-coordinate of the pixel. 672: * @param y the y-coordinate of the pixel. 673: * @param dArray the sample values (<code>null</code> not permitted). 674: * @param data the data buffer (<code>null</code> not permitted). 675: * 676: * @throws NullPointerException if either <code>dArray</code> or 677: * <code>data</code> is <code>null</code>. 678: */ 679: public void setPixel(int x, int y, double[] dArray, DataBuffer data) 680: { 681: for (int b = 0; b < numBands; b++) 682: setSample(x, y, b, dArray[b], data); 683: } 684: 685: /** 686: * Sets the sample values for the pixels in the region specified by 687: * (x, y, w, h) in the specified data buffer. The array is 688: * ordered by pixels (that is, all the samples for the first pixel are 689: * grouped together, followed by all the samples for the second pixel, and so 690: * on). 691: * 692: * @param x the x-coordinate of the top-left pixel. 693: * @param y the y-coordinate of the top-left pixel. 694: * @param w the width of the region of pixels. 695: * @param h the height of the region of pixels. 696: * @param iArray the pixel sample values (<code>null</code> not permitted). 697: * @param data the data buffer (<code>null</code> not permitted). 698: * 699: * @throws NullPointerException if either <code>iArray</code> or 700: * <code>data</code> is <code>null</code>. 701: */ 702: public void setPixels(int x, int y, int w, int h, int[] iArray, 703: DataBuffer data) 704: { 705: int inOffset = 0; 706: int[] pixel = new int[numBands]; 707: for (int yy = y; yy < (y + h); yy++) 708: { 709: for (int xx = x; xx < (x + w); xx++) 710: { 711: System.arraycopy(iArray, inOffset, pixel, 0, numBands); 712: setPixel(xx, yy, pixel, data); 713: inOffset += numBands; 714: } 715: } 716: } 717: 718: /** 719: * Sets the sample values for the pixels in the region specified by 720: * (x, y, w, h) in the specified data buffer. The array is 721: * ordered by pixels (that is, all the samples for the first pixel are 722: * grouped together, followed by all the samples for the second pixel, and so 723: * on). 724: * 725: * @param x the x-coordinate of the top-left pixel. 726: * @param y the y-coordinate of the top-left pixel. 727: * @param w the width of the region of pixels. 728: * @param h the height of the region of pixels. 729: * @param fArray the pixel sample values (<code>null</code> not permitted). 730: * @param data the data buffer (<code>null</code> not permitted). 731: * 732: * @throws NullPointerException if either <code>fArray</code> or 733: * <code>data</code> is <code>null</code>. 734: */ 735: public void setPixels(int x, int y, int w, int h, float[] fArray, 736: DataBuffer data) 737: { 738: int inOffset = 0; 739: float[] pixel = new float[numBands]; 740: for (int yy = y; yy < (y + h); yy++) 741: { 742: for (int xx = x; xx < (x + w); xx++) 743: { 744: System.arraycopy(fArray, inOffset, pixel, 0, numBands); 745: setPixel(xx, yy, pixel, data); 746: inOffset += numBands; 747: } 748: } 749: } 750: 751: /** 752: * Sets the sample values for the pixels in the region specified by 753: * (x, y, w, h) in the specified data buffer. The array is 754: * ordered by pixels (that is, all the samples for the first pixel are 755: * grouped together, followed by all the samples for the second pixel, and so 756: * on). 757: * 758: * @param x the x-coordinate of the top-left pixel. 759: * @param y the y-coordinate of the top-left pixel. 760: * @param w the width of the region of pixels. 761: * @param h the height of the region of pixels. 762: * @param dArray the pixel sample values (<code>null</code> not permitted). 763: * @param data the data buffer (<code>null</code> not permitted). 764: * 765: * @throws NullPointerException if either <code>dArray</code> or 766: * <code>data</code> is <code>null</code>. 767: */ 768: public void setPixels(int x, int y, int w, int h, double[] dArray, 769: DataBuffer data) 770: { 771: int inOffset = 0; 772: double[] pixel = new double[numBands]; 773: for (int yy = y; yy < (y + h); yy++) 774: { 775: for (int xx = x; xx < (x + w); xx++) 776: { 777: System.arraycopy(dArray, inOffset, pixel, 0, numBands); 778: setPixel(xx, yy, pixel, data); 779: inOffset += numBands; 780: } 781: } 782: } 783: 784: /** 785: * Sets the sample value for a band for the pixel at (x, y) in the 786: * specified data buffer. 787: * 788: * @param x the x-coordinate of the pixel. 789: * @param y the y-coordinate of the pixel. 790: * @param b the band (in the range <code>0</code> to 791: * <code>getNumBands() - 1</code>). 792: * @param s the sample value. 793: * @param data the data buffer (<code>null</code> not permitted). 794: * 795: * @throws NullPointerException if <code>data</code> is <code>null</code>. 796: */ 797: public abstract void setSample(int x, int y, int b, int s, 798: DataBuffer data); 799: 800: /** 801: * Sets the sample value for a band for the pixel at (x, y) in the 802: * specified data buffer. 803: * 804: * @param x the x-coordinate of the pixel. 805: * @param y the y-coordinate of the pixel. 806: * @param b the band (in the range <code>0</code> to 807: * <code>getNumBands() - 1</code>). 808: * @param s the sample value. 809: * @param data the data buffer (<code>null</code> not permitted). 810: * 811: * @throws NullPointerException if <code>data</code> is <code>null</code>. 812: */ 813: public void setSample(int x, int y, int b, float s, 814: DataBuffer data) 815: { 816: setSample(x, y, b, (int) s, data); 817: } 818: 819: /** 820: * Sets the sample value for a band for the pixel at (x, y) in the 821: * specified data buffer. 822: * 823: * @param x the x-coordinate of the pixel. 824: * @param y the y-coordinate of the pixel. 825: * @param b the band (in the range <code>0</code> to 826: * <code>getNumBands() - 1</code>). 827: * @param s the sample value. 828: * @param data the data buffer (<code>null</code> not permitted). 829: * 830: * @throws NullPointerException if <code>data</code> is <code>null</code>. 831: */ 832: public void setSample(int x, int y, int b, double s, 833: DataBuffer data) 834: { 835: setSample(x, y, b, (float) s, data); 836: } 837: 838: /** 839: * Sets the sample values for one band for the pixels in the region 840: * specified by (x, y, w, h) in the specified data buffer. 841: * 842: * @param x the x-coordinate of the top-left pixel. 843: * @param y the y-coordinate of the top-left pixel. 844: * @param w the width of the region of pixels. 845: * @param h the height of the region of pixels. 846: * @param b the band (in the range <code>0</code> to 847: * </code>getNumBands() - 1</code>). 848: * @param iArray the sample values (<code>null</code> not permitted). 849: * @param data the data buffer (<code>null</code> not permitted). 850: * 851: * @throws NullPointerException if either <code>iArray</code> or 852: * <code>data</code> is <code>null</code>. 853: */ 854: public void setSamples(int x, int y, int w, int h, int b, 855: int[] iArray, DataBuffer data) 856: { 857: int size = w * h; 858: int inOffset = 0; 859: for (int yy = y; yy < (y + h); yy++) 860: for (int xx = x; xx < (x + w); xx++) 861: setSample(xx, yy, b, iArray[inOffset++], data); 862: } 863: 864: /** 865: * Sets the sample values for one band for the pixels in the region 866: * specified by (x, y, w, h) in the specified data buffer. 867: * 868: * @param x the x-coordinate of the top-left pixel. 869: * @param y the y-coordinate of the top-left pixel. 870: * @param w the width of the region of pixels. 871: * @param h the height of the region of pixels. 872: * @param b the band (in the range <code>0</code> to 873: * </code>getNumBands() - 1</code>). 874: * @param fArray the sample values (<code>null</code> not permitted). 875: * @param data the data buffer (<code>null</code> not permitted). 876: * 877: * @throws NullPointerException if either <code>iArray</code> or 878: * <code>data</code> is <code>null</code>. 879: */ 880: public void setSamples(int x, int y, int w, int h, int b, 881: float[] fArray, DataBuffer data) 882: { 883: int size = w * h; 884: int inOffset = 0; 885: for (int yy = y; yy < (y + h); yy++) 886: for (int xx = x; xx < (x + w); xx++) 887: setSample(xx, yy, b, fArray[inOffset++], data); 888: 889: } 890: 891: /** 892: * Sets the sample values for one band for the pixels in the region 893: * specified by (x, y, w, h) in the specified data buffer. 894: * 895: * @param x the x-coordinate of the top-left pixel. 896: * @param y the y-coordinate of the top-left pixel. 897: * @param w the width of the region of pixels. 898: * @param h the height of the region of pixels. 899: * @param b the band (in the range <code>0</code> to 900: * </code>getNumBands() - 1</code>). 901: * @param dArray the sample values (<code>null</code> not permitted). 902: * @param data the data buffer (<code>null</code> not permitted). 903: * 904: * @throws NullPointerException if either <code>iArray</code> or 905: * <code>data</code> is <code>null</code>. 906: */ 907: public void setSamples(int x, int y, int w, int h, int b, 908: double[] dArray, DataBuffer data) { 909: int size = w * h; 910: int inOffset = 0; 911: for (int yy = y; yy < (y + h); yy++) 912: for (int xx = x; xx < (x + w); xx++) 913: setSample(xx, yy, b, dArray[inOffset++], data); 914: } 915: 916: /** 917: * Creates a new <code>SampleModel</code> that is compatible with this 918: * model and has the specified width and height. 919: * 920: * @param w the width (in pixels). 921: * @param h the height (in pixels). 922: * 923: * @return The new sample model. 924: */ 925: public abstract SampleModel createCompatibleSampleModel(int w, int h); 926: 927: /** 928: * Return a SampleModel with a subset of the bands in this model. 929: * 930: * Selects bands.length bands from this sample model. The bands chosen 931: * are specified in the indices of bands[]. This also permits permuting 932: * the bands as well as taking a subset. Thus, giving an array with 933: * 1, 2, 3, ..., numbands, will give an identical sample model. 934: * 935: * @param bands Array with band indices to include. 936: * @return A new sample model 937: */ 938: public abstract SampleModel createSubsetSampleModel(int[] bands); 939: 940: /** 941: * Creates a new {@link DataBuffer} of the correct type and size for this 942: * <code>SampleModel</code>. 943: * 944: * @return The data buffer. 945: */ 946: public abstract DataBuffer createDataBuffer(); 947: 948: /** 949: * Returns an array containing the size (in bits) for each band accessed by 950: * the <code>SampleModel</code>. 951: * 952: * @return An array. 953: * 954: * @see #getSampleSize(int) 955: */ 956: public abstract int[] getSampleSize(); 957: 958: /** 959: * Returns the size (in bits) of the samples for the specified band. 960: * 961: * @param band the band (in the range <code>0</code> to 962: * <code>getNumBands() - 1</code>). 963: * 964: * @return The sample size (in bits). 965: */ 966: public abstract int getSampleSize(int band); 967: }