⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 samplemodel.java

📁 JAVA基本类源代码,大家可以学习学习!
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
	case DataBuffer.TYPE_BYTE:	    byte[] btemp;	    byte[] bdata;	    if (obj == null)		bdata = new byte[numDataElems*w*h];	    else		bdata = (byte[])obj;	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    o = getDataElements(j, i, o, data);		    btemp = (byte[])o;		    for (int k=0; k<numDataElems; k++) {			bdata[cnt++] = btemp[k];		    }		}	    }	    obj = (Object)bdata;	    break;	case DataBuffer.TYPE_USHORT:	case DataBuffer.TYPE_SHORT:	    short[] sdata;	    short[] stemp;	    if (obj == null)		sdata = new short[numDataElems*w*h];	    else		sdata = (short[])obj;	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    o = getDataElements(j, i, o, data);		    stemp = (short[])o;		    for (int k=0; k<numDataElems; k++) {			sdata[cnt++] = stemp[k];		    }		}	    }	    obj = (Object)sdata;	    break;	case DataBuffer.TYPE_INT:	    int[] idata;	    int[] itemp;	    if (obj == null)		idata = new int[numDataElems*w*h];	    else		idata = (int[])obj;	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    o = getDataElements(j, i, o, data);		    itemp = (int[])o;		    for (int k=0; k<numDataElems; k++) {			idata[cnt++] = itemp[k];		    }		}	    }	    obj = (Object)idata;	    break;	case DataBuffer.TYPE_FLOAT:	    float[] fdata;	    float[] ftemp;	    if (obj == null)		fdata = new float[numDataElems*w*h];	    else		fdata = (float[])obj;	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    o = getDataElements(j, i, o, data);		    ftemp = (float[])o;		    for (int k=0; k<numDataElems; k++) {			fdata[cnt++] = ftemp[k];		    }		}	    }	    obj = (Object)fdata;	    break;	case DataBuffer.TYPE_DOUBLE:	    double[] ddata;	    double[] dtemp;	    if (obj == null)		ddata = new double[numDataElems*w*h];	    else		ddata = (double[])obj;	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    o = getDataElements(j, i, o, data);		    dtemp = (double[])o;		    for (int k=0; k<numDataElems; k++) {			ddata[cnt++] = dtemp[k];		    }		}	    }	    obj = (Object)ddata;	    break;	}	return obj;    }    /**      * Sets the data for a single pixel in the specified DataBuffer from a     * primitive array of type TransferType.  For image data supported by     * the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,     * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,     * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.  Data in the array     * may be in a packed format, thus increasing efficiency for data     * transfers.     * <p>     * The following code illustrates transferring data for one pixel from     * DataBuffer <code>db1</code>, whose storage layout is described by     * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose     * storage layout is described by SampleModel <code>sm2</code>.     * The transfer will generally be more efficient than using     * getPixel/setPixel.     * <pre>     * 	     SampleModel sm1, sm2;     *	     DataBuffer db1, db2;     * 	     sm2.setDataElements(x, y, sm1.getDataElements(x, y, null, db1),     *                           db2);     * </pre>     * Using getDataElements/setDataElements to transfer between two     * DataBuffer/SampleModel pairs is legitimate if the SampleModels have     * the same number of bands, corresponding bands have the same number of     * bits per sample, and the TransferTypes are the same.     * <p>     * obj must be a primitive array of type TransferType.  Otherwise,     * a ClassCastException is thrown.  An     * ArrayIndexOutOfBoundsException may be thrown if the coordinates are     * not in bounds, or if obj is not large enough to hold the pixel data.     * @param x 	The X coordinate of the pixel location.     * @param y 	The Y coordinate of the pixel location.     * @param obj       A primitive array containing pixel data.     * @param data      The DataBuffer containing the image data.     * @see #getNumDataElements     * @see #getTransferType     * @see #getDataElements(int, int, Object, DataBuffer)     * @see java.awt.image.DataBuffer     *     * @throws NullPointerException if data is null.     * @throws ArrayIndexOutOfBoundsException if the coordinates are     * not in bounds, or if obj is too small to hold the input.     */    public abstract void setDataElements(int x, int y,                                         Object obj, DataBuffer data);    /**      * Sets the data for a rectangle of pixels in the specified DataBuffer     * from a primitive array of type TransferType.  For image data supported     * by the Java 2D API, this will be one of DataBuffer.TYPE_BYTE,     * DataBuffer.TYPE_USHORT, DataBuffer.TYPE_INT, DataBuffer.TYPE_SHORT,     * DataBuffer.TYPE_FLOAT, or DataBuffer.TYPE_DOUBLE.  Data in the array     * may be in a packed format, thus increasing efficiency for data     * transfers.     * <p>     * The following code illustrates transferring data for a rectangular     * region of pixels from     * DataBuffer <code>db1</code>, whose storage layout is described by     * SampleModel <code>sm1</code>, to DataBuffer <code>db2</code>, whose     * storage layout is described by SampleModel <code>sm2</code>.     * The transfer will generally be more efficient than using     * getPixels/setPixels.     * <pre>     * 	     SampleModel sm1, sm2;     *	     DataBuffer db1, db2;     * 	     sm2.setDataElements(x, y, w, h, sm1.getDataElements(x, y, w, h,     *                           null, db1), db2);     * </pre>     * Using getDataElements/setDataElements to transfer between two     * DataBuffer/SampleModel pairs is legitimate if the SampleModels have     * the same number of bands, corresponding bands have the same number of     * bits per sample, and the TransferTypes are the same.     * <p>     * obj must be a primitive array of type TransferType.  Otherwise,     * a ClassCastException is thrown.  An     * ArrayIndexOutOfBoundsException may be thrown if the coordinates are     * not in bounds, or if obj is not large enough to hold the pixel data.     * @param x 	The minimum X coordinate of the pixel rectangle.     * @param y 	The minimum Y coordinate of the pixel rectangle.     * @param w         The width of the pixel rectangle.     * @param h         The height of the pixel rectangle.     * @param obj       A primitive array containing pixel data.     * @param data      The DataBuffer containing the image data.     * @see #getNumDataElements     * @see #getTransferType     * @see #getDataElements(int, int, int, int, Object, DataBuffer)     * @see java.awt.image.DataBuffer     *     * @throws NullPointerException if data is null.     * @throws ArrayIndexOutOfBoundsException if the coordinates are     * not in bounds, or if obj is too small to hold the input.     */        public void setDataElements(int x, int y, int w, int h,                                Object obj, DataBuffer data) {	int cnt = 0;	Object o = null;	int type = getTransferType();	int numDataElems = getNumDataElements();	switch(type) {	case DataBuffer.TYPE_BYTE:	    byte[] barray = (byte[])obj;	    byte[] btemp = new byte[numDataElems];	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    for (int k=0; k<numDataElems; k++) {			btemp[k] = barray[cnt++];		    }		    setDataElements(j, i, btemp, data);		}	    }	    break;	case DataBuffer.TYPE_USHORT:	case DataBuffer.TYPE_SHORT:	    short[] sarray = (short[])obj;	    short[] stemp = new short[numDataElems];	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    for (int k=0; k<numDataElems; k++) {			stemp[k] = sarray[cnt++];		    }		    setDataElements(j, i, stemp, data);		}	    }	    break;	case DataBuffer.TYPE_INT:	    int[] iArray = (int[])obj;	    int[] itemp = new int[numDataElems];	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    for (int k=0; k<numDataElems; k++) {			itemp[k] = iArray[cnt++];		    }		    setDataElements(j, i, itemp, data);		}	    }	    break;	case DataBuffer.TYPE_FLOAT:	    float[] fArray = (float[])obj;	    float[] ftemp = new float[numDataElems];	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    for (int k=0; k<numDataElems; k++) {			ftemp[k] = fArray[cnt++];		    }		    setDataElements(j, i, ftemp, data);		}	    }	    break;	case DataBuffer.TYPE_DOUBLE:	    double[] dArray = (double[])obj;	    double[] dtemp = new double[numDataElems];	    for (int i=y; i<y+h; i++) {		for (int j=x; j<x+w; j++) {		    for (int k=0; k<numDataElems; k++) {			dtemp[k] = dArray[cnt++];		    }		    setDataElements(j, i, dtemp, data);		}	    }	    break;	}    }    /**     * Returns the samples for the specified pixel in an array of float.     * ArrayIndexOutOfBoundsException may be thrown if the coordinates are     * not in bounds.     * @param x 	The X coordinate of the pixel location.     * @param y 	The Y coordinate of the pixel location.     * @param fArray    If non-null, returns the samples in this array.     * @param data      The DataBuffer containing the image data.     * @return the samples for the specified pixel.     * @see #setPixel(int, int, float[], DataBuffer)     *     * @throws NullPointerException if data is null.     * @throws ArrayIndexOutOfBoundsException if the coordinates are     * not in bounds, or if fArray is too small to hold the output.     */    public float[] getPixel(int x, int y, float fArray[],			    DataBuffer data) {	float pixels[];	if (fArray != null)	    pixels = fArray;	else	    pixels = new float[numBands];	for (int i=0; i<numBands; i++)	    pixels[i] = getSampleFloat(x, y, i, data);	return pixels;    }    /**     * Returns the samples for the specified pixel in an array of double.     * ArrayIndexOutOfBoundsException may be thrown if the coordinates are     * not in bounds.     * @param x 	The X coordinate of the pixel location.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -