Package java.awt.image

Examples of java.awt.image.ComponentSampleModel


            this.highValue[i] = (int)Math.ceil(this.highValueFP[i]);
        }

        // Set up the band re-index map if needed.
        if(numBands > 1) {
            ComponentSampleModel csm = (ComponentSampleModel)sampleModel;

            TreeMap indexMap = new TreeMap();

            // Determine whether there is more than one bank.
            int[] indices = csm.getBankIndices();
            boolean checkBanks = false;
            for(int i = 1; i < numBands; i++) {
                if(indices[i] != indices[i-1]) {
                    checkBanks = true;
                    break;
                }
            }

            // Check the banks for ordering.
            if(checkBanks) {
                for(int i = 0; i < numBands; i++) {
                    indexMap.put(new Integer(indices[i]), new Integer(i));
                }

                bandIndexMap = new int[numBands];
                Iterator bankIter = indexMap.keySet().iterator();
                int k = 0;
                while(bankIter.hasNext()) {
                    int idx =
                        ((Integer)indexMap.get(bankIter.next())).intValue();
                    if(idx != k) {
                        reorderBands = true;
                    }
                    bandIndexMap[k++] = idx;
                }
            }

            // If band re-ordering not needed on basis of bank indices
            // then check ordering of band offsets.
            if(!reorderBands) {
                indexMap.clear();

                if(bandIndexMap == null) {
                    bandIndexMap = new int[numBands];
                }

                int[] offsets = csm.getBandOffsets();
                for(int i = 0; i < numBands; i++) {
                    indexMap.put(new Integer(offsets[i]), new Integer(i));
                }

                Iterator offsetIter = indexMap.keySet().iterator();
View Full Code Here


        if ((formatTagID & COPY_MASK) == UNCOPIED) {

            this.numBands = rft.getNumBands();
            this.pixelStride = rft.getPixelStride();

            ComponentSampleModel csm =
                (ComponentSampleModel)raster.getSampleModel();
            this.scanlineStride = csm.getScanlineStride();

            int bankIndices[] = null;

            // if the rft isPixelSequential we can rely on it's
            // version of bandOffsets and bankIndicies.  If it's
            // not the SampleModel passed in might not completely
            // match the one that was passed to the the
            // RasterFormatTag constructor so we have to get them
            // from the passed in Raster/SampleModel
            if (rft.isPixelSequential()) {
                this.bandOffsets = rft.getBandOffsets();
                bankIndices = rft.getBankIndices();
            } else {
                this.bandOffsets = csm.getBandOffsets();
                bankIndices = csm.getBankIndices();
            }

            this.bandDataOffsets = new int[numBands];

      int dataBufferOffsets[] = raster.getDataBuffer().getOffsets();
View Full Code Here

    public static boolean isAcceptableSampleModel(SampleModel sm) {
        if(!(sm instanceof ComponentSampleModel)) {
            return true;
        }

        ComponentSampleModel csm = (ComponentSampleModel)sm;

        int[] bandOffsets = csm.getBandOffsets();

        if(bandOffsets.length == 2 &&
           bandOffsets[1] == bandOffsets[0] + 1) {
            return true;
        }
View Full Code Here

      * @param out The <code>ObjectOutputStream</code>.
      */
    private void writeObject(ObjectOutputStream out) throws IOException {
        SampleModel sampleModel = (SampleModel)theObject;
        if(sampleModel instanceof ComponentSampleModel) {
            ComponentSampleModel sm = (ComponentSampleModel)sampleModel;
            int sampleModelType = TYPE_COMPONENT;
            int transferType = sm.getTransferType();
            if(sampleModel instanceof PixelInterleavedSampleModel) {
                sampleModelType = TYPE_PIXEL_INTERLEAVED;
            } else if(sampleModel instanceof BandedSampleModel) {
                sampleModelType = TYPE_BANDED;
            } else if(sampleModel instanceof ComponentSampleModelJAI ||
                      transferType == DataBuffer.TYPE_FLOAT ||
                      transferType == DataBuffer.TYPE_DOUBLE) {
                sampleModelType = TYPE_COMPONENT_JAI;
            }
            out.writeInt(sampleModelType);
            out.writeInt(transferType);
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            if(sampleModelType != TYPE_BANDED) {
                out.writeInt(sm.getPixelStride());
            }
            out.writeInt(sm.getScanlineStride());
            if(sampleModelType != TYPE_PIXEL_INTERLEAVED) {
                out.writeObject(sm.getBankIndices());
            }
            out.writeObject(sm.getBandOffsets());
        } else if(sampleModel instanceof
                  SinglePixelPackedSampleModel) {
            SinglePixelPackedSampleModel sm =
                (SinglePixelPackedSampleModel)sampleModel;
            out.writeInt(TYPE_SINGLE_PIXEL_PACKED);
            out.writeInt(sm.getTransferType());
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            out.writeInt(sm.getScanlineStride());
            out.writeObject(sm.getBitMasks());
        } else if(sampleModel instanceof MultiPixelPackedSampleModel) {
            MultiPixelPackedSampleModel sm =
                (MultiPixelPackedSampleModel)sampleModel;
            out.writeInt(TYPE_MULTI_PIXEL_PACKED);
            out.writeInt(sm.getTransferType());
            out.writeInt(sm.getWidth());
            out.writeInt(sm.getHeight());
            out.writeInt(sm.getPixelBitStride());
            out.writeInt(sm.getScanlineStride());
            out.writeInt(sm.getDataBitOffset());
        } else {
            throw new RuntimeException(JaiI18N.getString("SampleModelState0"));
        }
    }
View Full Code Here

                                            (int[])in.readObject(),
                                            (int[])in.readObject());
            break;
        case TYPE_COMPONENT:
            sampleModel =
                new ComponentSampleModel(in.readInt(),
                                         in.readInt(),
                                         in.readInt(),
                                         in.readInt(),
                                         in.readInt(),
                                         (int[])in.readObject(),
View Full Code Here

        boolean set;

        //ComponentSampleModel sm = (ComponentSampleModel)sampleModel;
        // For bug 4696966: when the raster bounds is not coincide with a
        // tile bounds.
        ComponentSampleModel sm = (ComponentSampleModel)raster.getSampleModel();

        if (type == sampleType) {
            // Data are stored in the requested array type; no need to copy.

            DataBuffer db = raster.getDataBuffer();
            int[] bankIndices = sm.getBankIndices();

            switch (sampleType) {
            case DataBuffer.TYPE_BYTE:
                byte[][] bbd = ((DataBufferByte)db).getBankData();
                byte[][] bd = new byte[numBands][];

                for (int b = 0; b < numBands; b++) {
                    bd[b] = bbd[bankIndices[b]];
                }
                data = bd;
                break;

            case DataBuffer.TYPE_USHORT:
            case DataBuffer.TYPE_SHORT:
                short[][] sbd = sampleType == DataBuffer.TYPE_USHORT ?
                                ((DataBufferUShort)db).getBankData() :
                                ((DataBufferShort)db).getBankData();
                short[][] sd = new short[numBands][];

                for (int b = 0; b < numBands; b++) {
                    sd[b] = sbd[bankIndices[b]];
                }
                data = sd;
                break;

            case DataBuffer.TYPE_INT:
                int[][] ibd = ((DataBufferInt)db).getBankData();
                int[][] id = new int[numBands][];

                for (int b = 0; b < numBands; b++) {
                    id[b] = ibd[bankIndices[b]];
                }
                data = id;
                break;

            case DataBuffer.TYPE_FLOAT:
                float[][] fbd = DataBufferUtils.getBankDataFloat(db);
                float[][] fd = new float[numBands][];

                for (int b = 0; b < numBands; b++) {
                    fd[b] = fbd[bankIndices[b]];
                }
                data = fd;
                break;

            case DataBuffer.TYPE_DOUBLE:
                double[][] dbd = DataBufferUtils.getBankDataDouble(db);
                double[][] dd = new double[numBands][];

                for (int b = 0; b < numBands; b++) {
                    dd[b] = dbd[bankIndices[b]];
                }
                data = dd;
                break;
            }

            pixelStride = sm.getPixelStride();
            lineStride = sm.getScanlineStride();

            // Determine offsets.
            int[] dbOffsets = db.getOffsets()// DataBuffer offsets
            int x = rect.x - raster.getSampleModelTranslateX();
            int y = rect.y - raster.getSampleModelTranslateY();

            offsets = new int[numBands];
            for (int b = 0; b < numBands; b++) {
                offsets[b] = sm.getOffset(x, y, b) + dbOffsets[bankIndices[b]];
            }

            set = false;      // no need to copy

        } else // need to reformat data
View Full Code Here

            srcSM.getNumBands() == numBands &&
            srcSM.getClass().equals(sampleModel.getClass());

        if (isCompatible) {
            if (sampleModel instanceof ComponentSampleModel) {
                ComponentSampleModel smSrc = (ComponentSampleModel)srcSM;
                ComponentSampleModel smDst = (ComponentSampleModel)sampleModel;
                isCompatible = isCompatible &&
                    smSrc.getPixelStride() == smDst.getPixelStride() &&
                    smSrc.getScanlineStride() == smDst.getScanlineStride();
                int[] biSrc = smSrc.getBankIndices();
                int[] biDst = smDst.getBankIndices();
                int[] boSrc = smSrc.getBandOffsets();
                int[] boDst = smDst.getBandOffsets();
                for(int b = 0; b < numBands && isCompatible; b++) {
                    isCompatible = isCompatible &&
                        biSrc[b] == biDst[b] &&
                        boSrc[b] == boDst[b];
                }
            } else if (sampleModel instanceof
                      SinglePixelPackedSampleModel) {
                SinglePixelPackedSampleModel smSrc =
                    (SinglePixelPackedSampleModel)srcSM;
                SinglePixelPackedSampleModel smDst =
                    (SinglePixelPackedSampleModel)sampleModel;
                isCompatible = isCompatible &&
                    smSrc.getScanlineStride() == smDst.getScanlineStride();
                int[] bmSrc = smSrc.getBitMasks();
                int[] bmDst = smDst.getBitMasks();
                for(int b = 0; b < numBands && isCompatible; b++) {
                    isCompatible = isCompatible &&
                        bmSrc[b] == bmDst[b];
                }
            } else if (sampleModel instanceof MultiPixelPackedSampleModel) {
                MultiPixelPackedSampleModel smSrc =
                    (MultiPixelPackedSampleModel)srcSM;
                MultiPixelPackedSampleModel smDst =
                    (MultiPixelPackedSampleModel)sampleModel;
                isCompatible = isCompatible &&
                    smSrc.getPixelBitStride() == smDst.getPixelBitStride() &&
                    smSrc.getScanlineStride() == smDst.getScanlineStride() &&
                    smSrc.getDataBitOffset() == smDst.getDataBitOffset();
            } else {
                isCompatible = false;
            }
        }
View Full Code Here

    /**
     *  Determines if the SampleModel stores data in a way that can
     *  be represented by a mediaLibImage without copying
     */
    public static boolean isPixelSequential(SampleModel sm) {
        ComponentSampleModel csm = null;
        if (sm instanceof ComponentSampleModel) {
            csm = (ComponentSampleModel)sm;
        } else {
            return false;
        }
        int pixelStride = csm.getPixelStride();
        int bandOffsets[] = csm.getBandOffsets();
        int bankIndices[] = csm.getBankIndices();
        if (pixelStride != bandOffsets.length) {
            return false;
        }
        for (int i = 0; i < bandOffsets.length; i++) {
            if (bandOffsets[i] >= pixelStride ||
View Full Code Here

            return;
        }

        if ((formatTag & COPY_MASK) == UNCOPIED) {
            ComponentSampleModel csm =
                (ComponentSampleModel)raster.getSampleModel();

            numBands = csm.getNumBands();
            bandOffsets = csm.getBandOffsets();
            int dataOffset = raster.getDataBuffer().getOffset();
            dataOffset +=
             (rect.y-raster.getSampleModelTranslateY())*csm.getScanlineStride()+
             (rect.x-raster.getSampleModelTranslateX())*csm.getPixelStride();

            // dataoffset should and is in terms of dataElements

            // scanline stride should be in terms of dataElements
            int scanlineStride = csm.getScanlineStride();

            switch (formatTag & DATATYPE_MASK) {
            case DataBuffer.TYPE_BYTE:
                DataBufferByte dbb = (DataBufferByte)raster.getDataBuffer();
                mlimages = new mediaLibImage[1];
View Full Code Here

    private void copyDataFromRaster() {
        // Writeback should only be necessary on destRasters which
        // should be writable so this cast should succeed.

        if (raster.getSampleModel() instanceof ComponentSampleModel) {
            ComponentSampleModel csm =
               (ComponentSampleModel)raster.getSampleModel();
            int rasScanlineStride = csm.getScanlineStride();
            int rasPixelStride = csm.getPixelStride();

            int subRasterOffset =
             (rect.y-raster.getSampleModelTranslateY())*rasScanlineStride+
             (rect.x-raster.getSampleModelTranslateX())*rasPixelStride;

            int rasBankIndices[] = csm.getBankIndices();
            int rasBandOffsets[] = csm.getBandOffsets();
            int rasDataOffsets[] = raster.getDataBuffer().getOffsets();

            if (rasDataOffsets.length == 1) {
                for (int i = 0; i < numBands; i++) {
                    rasBandOffsets[i] += rasDataOffsets[0] +
                       subRasterOffset;
                }
            } else if (rasDataOffsets.length == rasBandOffsets.length) {
                for (int i = 0; i < numBands; i++) {
                    rasBandOffsets[i] += rasDataOffsets[i] +
                        subRasterOffset;
                }
            }

            Object mlibDataArray = null;
            switch (getDataType()) {
            case DataBuffer.TYPE_BYTE:
                byte bArray[][] = new byte[numBands][];
                for (int i = 0; i < numBands; i++) {
                    bArray[i] = mlimages[0].getByteData();
                }
                mlibDataArray = bArray;
                break;
            case DataBuffer.TYPE_USHORT:
                short usArray[][] = new short[numBands][];
                for (int i = 0; i < numBands; i++) {
                    usArray[i] = mlimages[0].getUShortData();
                }
                mlibDataArray = usArray;
                break;
            case DataBuffer.TYPE_SHORT:
                short sArray[][] = new short[numBands][];
                for (int i = 0; i < numBands; i++) {
                    sArray[i] = mlimages[0].getShortData();
                }
                mlibDataArray = sArray;
                break;
            case DataBuffer.TYPE_INT:
                int iArray[][] = new int[numBands][];
                for (int i = 0; i < numBands; i++) {
                    iArray[i] = mlimages[0].getIntData();
                }
                mlibDataArray = iArray;
                break;
            case DataBuffer.TYPE_FLOAT:
                float fArray[][] = new float[numBands][];
                for (int i = 0; i < numBands; i++) {
                    fArray[i] = mlimages[0].getFloatData();
                }
                mlibDataArray = fArray;
                break;
            case DataBuffer.TYPE_DOUBLE:
                double dArray[][] = new double[numBands][];
                for (int i = 0; i < numBands; i++) {
                    dArray[i] = mlimages[0].getDoubleData();
                }
                mlibDataArray = dArray;
                break;
            }



            Object rasDataArray = null;
            switch (csm.getDataType()) {
                case DataBuffer.TYPE_BYTE: {
                    DataBufferByte dbb =
                        (DataBufferByte)raster.getDataBuffer();
                    byte rasByteDataArray[][] = new byte[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        rasByteDataArray[i] =
                            dbb.getData(rasBankIndices[i]);
                    }
                    rasDataArray = rasByteDataArray;
                    }
                    break;
                case DataBuffer.TYPE_USHORT: {
                    DataBufferUShort dbus =
                        (DataBufferUShort)raster.getDataBuffer();
                    short rasUShortDataArray[][] = new short[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        rasUShortDataArray[i] =
                            dbus.getData(rasBankIndices[i]);
                    }
                    rasDataArray = rasUShortDataArray;
                    }
                    break;
                case DataBuffer.TYPE_SHORT: {
                    DataBufferShort dbs =
                        (DataBufferShort)raster.getDataBuffer();
                    short rasShortDataArray[][] = new short[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        rasShortDataArray[i] =
                            dbs.getData(rasBankIndices[i]);
                    }
                    rasDataArray = rasShortDataArray;
                    }
                    break;
                case DataBuffer.TYPE_INT: {
                    DataBufferInt dbi =
                        (DataBufferInt)raster.getDataBuffer();
                    int rasIntDataArray[][] = new int[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        rasIntDataArray[i] =
                            dbi.getData(rasBankIndices[i]);
                    }
                    rasDataArray = rasIntDataArray;
                    }
                    break;
                case DataBuffer.TYPE_FLOAT: {
                    DataBuffer dbf =
                        raster.getDataBuffer();
                    float rasFloatDataArray[][] = new float[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        rasFloatDataArray[i] =
                            DataBufferUtils.getDataFloat(dbf, rasBankIndices[i]);
                    }
                    rasDataArray = rasFloatDataArray;
                    }
                    break;
                case DataBuffer.TYPE_DOUBLE: {
                    DataBuffer dbd =
                        raster.getDataBuffer();
                    double rasDoubleDataArray[][] = new double[numBands][];
                    for (int i = 0; i < numBands; i++) {
                        rasDoubleDataArray[i] =
                            DataBufferUtils.getDataDouble(dbd, rasBankIndices[i]);
                    }
                    rasDataArray = rasDoubleDataArray;
                    }
                    break;
            }


            // dst = mlib && src = ras
            Image.Reformat(
                    mlibDataArray,
                    rasDataArray,
                    numBands,
                    rect.width,rect.height,
                    getMediaLibDataType(this.getDataType()),
                    bandOffsets,
                    rect.width*numBands,
                    numBands,
                    getMediaLibDataType(csm.getDataType()),
                    rasBandOffsets,
                    rasScanlineStride,
                    rasPixelStride);
        } else {
            // If COPIED and the raster doesn't have ComponentSampleModel
View Full Code Here

TOP

Related Classes of java.awt.image.ComponentSampleModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.