Package com.lightcrafts.mediax.jai

Examples of com.lightcrafts.mediax.jai.PixelAccessor


              Rectangle rect,
              double[] backgroundValues) {
  rect = rect.intersection(raster.getBounds());
  int numBands = raster.getSampleModel().getNumBands();
        SampleModel sm = raster.getSampleModel();
        PixelAccessor accessor = new PixelAccessor(sm, null);

        if (isBinary(sm)) {
            //fill binary data
            byte value = (byte)(((int)backgroundValues[0]) & 1);
            if (value == 0)
                return;
            int rectX = rect.x;
            int rectY = rect.y;
            int rectWidth = rect.width;
            int rectHeight = rect.height;

            int dx = rectX - raster.getSampleModelTranslateX();
            int dy = rectY - raster.getSampleModelTranslateY();

            DataBuffer dataBuffer = raster.getDataBuffer();
            MultiPixelPackedSampleModel mpp = (MultiPixelPackedSampleModel)sm;
            int lineStride = mpp.getScanlineStride();
            int eltOffset = dataBuffer.getOffset() + mpp.getOffset(dx, dy);
            int bitOffset = mpp.getBitOffset(dx);

            switch(sm.getDataType()) {
            case DataBuffer.TYPE_BYTE:
                {
                    byte[] data = ((DataBufferByte)dataBuffer).getData();
                    int bits = bitOffset & 7;
                    int otherBits = (bits == 0) ? 0: 8 - bits;

                    byte mask = (byte)(255 >> bits);
                    int lineLength = (rectWidth - otherBits) / 8;
                    int bits1 = (rectWidth - otherBits) & 7;
                    byte mask1 = (byte)(255 << (8 - bits1));
                    // If operating within a single byte, merge masks into one
                    // and don't apply second mask after while loop
                    if (lineLength == 0) {
                        mask &= mask1;
                        bits1 = 0;
                    }

                    for (int y = 0; y < rectHeight; y++) {
                        int start = eltOffset;
                        int end = start + lineLength;
                        if (bits != 0)
                            data[start++] |= mask;
                        while (start < end)
                            data[start++] = (byte)255;
                        if (bits1 != 0)
                            data[start] |= mask1;
                        eltOffset += lineStride;
                    }
                    break;
                }
            case DataBuffer.TYPE_USHORT:
                {
                    short[] data = ((DataBufferUShort)dataBuffer).getData();
                    int bits = bitOffset & 15;
                    int otherBits = (bits == 0) ? 0: 16 - bits;

                    short mask = (short)(65535 >> bits);
                    int lineLength = (rectWidth - otherBits) / 16;
                    int bits1 = (rectWidth - otherBits) & 15;
                    short mask1 = (short)(65535 << (16 - bits1));
                    // If operating within a single byte, merge masks into one
                    // and don't apply second mask after while loop
                    if (lineLength == 0) {
                        mask &= mask1;
                        bits1 = 0;
                    }

                    for (int y = 0; y < rectHeight; y++) {
                        int start = eltOffset;
                        int end = start + lineLength;
                        if (bits != 0)
                            data[start++] |= mask;
                        while (start < end)
                            data[start++] = (short)0xFFFF;
                        if (bits1 != 0)
                            data[start++] |= mask1;
                        eltOffset += lineStride;
                    }
                    break;
                }
            case DataBuffer.TYPE_INT:
                {
                    int[] data = ((DataBufferInt)dataBuffer).getData();
                    int bits = bitOffset & 31;
                    int otherBits = (bits == 0) ? 0: 32 - bits;

                    int mask = 0xFFFFFFFF >> bits;
                    int lineLength = (rectWidth - otherBits) / 32;
                    int bits1 = (rectWidth - otherBits) & 31;
                    int mask1 = 0xFFFFFFFF << (32 - bits1);
                    // If operating within a single byte, merge masks into one
                    // and don't apply second mask after while loop
                    if (lineLength == 0) {
                        mask &= mask1;
                        bits1 = 0;
                    }

                    for (int y = 0; y < rectHeight; y++) {
                        int start = eltOffset;
                        int end = start + lineLength;
                        if (bits != 0)
                            data[start++] |= mask;
                        while (start < end)
                            data[start++] = 0xFFFFFFFF;
                        if (bits1 != 0)
                            data[start++] |= mask1;
                        eltOffset += lineStride;
                    }
                    break;
                }

            }
        } else {
            int srcSampleType = accessor.sampleType == PixelAccessor.TYPE_BIT ?
                DataBuffer.TYPE_BYTE : accessor.sampleType;
            UnpackedImageData uid = accessor.getPixels(raster, rect,
                                                    srcSampleType, false);
            rect = uid.rect;
            int lineStride = uid.lineStride;
            int pixelStride = uid.pixelStride;
View Full Code Here


         RuntimeException(JaiI18N.getString("SubsampleBinaryToGrayOpImage0"));
        }
    }

    private void byteLoop2x2(Raster source, WritableRaster dest, Rectangle  destRect) {
        PixelAccessor pa = new PixelAccessor(source.getSampleModel(), null);
  PackedImageData pid =
            pa.getPackedPixels(source, source.getBounds(), false, false);
  byte[] sourceData   = pid.data;
        int sourceDBOffset  = pid.offset;
  int dx  = destRect.x;        int dy  = destRect.y;
  int dwi = destRect.width;    int dhi = destRect.height;
        int sourceTransX = pid.rect.x;   // source.getSampleModelTranslateX();
View Full Code Here

        // Checks for source to be Binary and Dest Grayscale
        // to be in the RIF
 
  RenderedImage src = (RenderedImage)args.getSource(0);

  PixelAccessor srcPA = new PixelAccessor(src);
  if (!srcPA.isPacked || !srcPA.isMultiPixelPackedSM){
            msg.append(getName() + " " +
                       JaiI18N.getString("SubsampleBinaryToGray3"));
      return false;   
  }
View Full Code Here

        int nSrcs = sources.length;
        int[] snbands = new int[nSrcs];
        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        for ( int i = 0; i < nSrcs; i++ ) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if ( colorModels[i] instanceof IndexColorModel ) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }       

        int dnbands     = dest.getNumBands();
        int destType    = dest.getTransferType();
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(), null);

        UnpackedImageData dimd = d.getPixels(dest,
                                             destRect,    //liney,
                                             destType,
                                             true);

        byte[][] dstdata = (byte[][])dimd.data;

        for ( int sindex = 0, db = 0; sindex < nSrcs; sindex++ ) {

            UnpackedImageData simd =
                colorModels[sindex] instanceof IndexColorModel ?
                pas[sindex].getComponents(sources[sindex],
                                          destRect,
                                          sources[sindex].getSampleModel().getTransferType()) :
                pas[sindex].getPixels(sources[sindex],
                                      destRect,
                                      sources[sindex].getSampleModel().getTransferType(),
                                      false);

             
            int srcPixelStride = simd.pixelStride;
            int srcLineStride  = simd.lineStride;
            int dstPixelStride = dimd.pixelStride;
            int dstLineStride  = dimd.lineStride;
            int dRectWidth     = destRect.width;

            for ( int sb = 0; sb < snbands[sindex]; sb++, db++ ) {
                if ( db >= dnbands ) {
                     // exceeding destNumBands; should not have happened
                     break;
                }

                byte[]   dstdatabandb = dstdata[db];
                byte[][] srcdata = (byte[][])simd.data;
                byte[]   srcdatabandsb = srcdata[sb];
                int srcstart = simd.bandOffsets[sb];
                int dststart = dimd.bandOffsets[db];

                for(int y = 0;
                    y < destRect.height;
                    y++, srcstart += srcLineStride, dststart += dstLineStride){
                   
                    for(int i=0, srcpos = srcstart, dstpos = dststart;
                        i < dRectWidth;
                        i++, srcpos += srcPixelStride, dstpos += dstPixelStride){
                         
                             dstdatabandb[dstpos] = srcdatabandsb[srcpos];
                    }
                }
            }
        }

        d.setPixels(dimd);
    }
View Full Code Here

        int nSrcs = sources.length;
        int[] snbands = new int[nSrcs];
        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        for ( int i = 0; i < nSrcs; i++ ) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if ( colorModels[i] instanceof IndexColorModel ) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }       

        int dnbands     = dest.getNumBands();
        int destType    = dest.getTransferType();
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(),null);

        UnpackedImageData dimd = d.getPixels(dest,
                                             destRect,    //liney,
                                             destType,
                                             true);

        short[][] dstdata = (short[][])dimd.data;

        for ( int sindex = 0, db = 0; sindex < nSrcs; sindex++ ) {

            UnpackedImageData simd =
                colorModels[sindex] instanceof IndexColorModel ?
                pas[sindex].getComponents(sources[sindex],
                                          destRect,
                                          sources[sindex].getSampleModel().getTransferType()) :
                pas[sindex].getPixels(sources[sindex],
                                      destRect,
                                      sources[sindex].getSampleModel().getTransferType(),
                                      false);
             
            int srcPixelStride = simd.pixelStride;
            int srcLineStride  = simd.lineStride;
            int dstPixelStride = dimd.pixelStride;
            int dstLineStride  = dimd.lineStride;
            int dRectWidth     = destRect.width;

            for ( int sb = 0; sb < snbands[sindex]; sb++, db++ ) {
                if ( db < dnbands ) {
                    short[][] srcdata = (short[][])simd.data;
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    for(int y = 0;
                        y < destRect.height;
                        y++, srcstart += srcLineStride, dststart += dstLineStride){
                       
                        for(int i=0, srcpos = srcstart, dstpos = dststart;
                            i < dRectWidth;
                            i++, srcpos += srcPixelStride, dstpos += dstPixelStride){
                         
                                dstdata[db][dstpos] = srcdata[sb][srcpos];
                        }
                    }
                }
            }
        }

        d.setPixels(dimd);
    }
View Full Code Here

        int nSrcs = sources.length;
        int[] snbands = new int[nSrcs];
        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        for ( int i = 0; i < nSrcs; i++ ) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if ( colorModels[i] instanceof IndexColorModel ) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }       

        int dnbands     = dest.getNumBands();
        int destType    = dest.getTransferType();
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(),null);

        UnpackedImageData dimd = d.getPixels(dest,
                                             destRect,    //liney,
                                             destType,
                                             true);

        int[][] dstdata = (int[][])dimd.data;

        for ( int sindex = 0, db = 0; sindex < nSrcs; sindex++ ) {

            UnpackedImageData simd =
                colorModels[sindex] instanceof IndexColorModel ?
                pas[sindex].getComponents(sources[sindex],
                                          destRect,
                                          sources[sindex].getSampleModel().getTransferType()) :
                pas[sindex].getPixels(sources[sindex],
                                      destRect,
                                      sources[sindex].getSampleModel().getTransferType(),
                                      false);

            int srcPixelStride = simd.pixelStride;
            int srcLineStride  = simd.lineStride;
            int dstPixelStride = dimd.pixelStride;
            int dstLineStride  = dimd.lineStride;
            int dRectWidth     = destRect.width;

            for ( int sb = 0; sb < snbands[sindex]; sb++, db++ ) {
                if ( db < dnbands ) {
                    int[][] srcdata = (int[][])simd.data;
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    for(int y = 0;
                        y < destRect.height;
                        y++, srcstart += srcLineStride, dststart += dstLineStride){
                       
                        for(int i=0, srcpos = srcstart, dstpos = dststart;
                            i < dRectWidth;
                            i++, srcpos += srcPixelStride, dstpos += dstPixelStride){
                          
                                dstdata[db][dstpos] = srcdata[sb][srcpos];
                        }
                    }
                }
            }
        }

        d.setPixels(dimd);
    }
View Full Code Here

        int nSrcs = sources.length;
        int[] snbands = new int[nSrcs];
        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        for ( int i = 0; i < nSrcs; i++ ) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if ( colorModels[i] instanceof IndexColorModel ) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }       

        int dnbands     = dest.getNumBands();
        int destType    = dest.getTransferType();
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(), null);

        UnpackedImageData dimd = d.getPixels(dest,
                                             destRect,    //liney,
                                             destType,
                                             true);

        float[][] dstdata = (float[][])dimd.data;

        for ( int sindex = 0, db = 0; sindex < nSrcs; sindex++ ) {

            UnpackedImageData simd =
                colorModels[sindex] instanceof IndexColorModel ?
                pas[sindex].getComponents(sources[sindex],
                                          destRect,
                                          sources[sindex].getSampleModel().getTransferType()) :
                pas[sindex].getPixels(sources[sindex],
                                      destRect,
                                      sources[sindex].getSampleModel().getTransferType(),
                                      false);

            int srcPixelStride = simd.pixelStride;
            int srcLineStride  = simd.lineStride;
            int dstPixelStride = dimd.pixelStride;
            int dstLineStride  = dimd.lineStride;
            int dRectWidth     = destRect.width;

            for ( int sb = 0; sb < snbands[sindex]; sb++, db++ ) {
                if ( db < dnbands ) {
                    float[][] srcdata = (float[][])simd.data;
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    for(int y = 0;
                        y < destRect.height;
                        y++, srcstart += srcLineStride, dststart += dstLineStride){
                       
                        for(int i=0, srcpos = srcstart, dstpos = dststart;
                            i < dRectWidth;
                            i++, srcpos += srcPixelStride, dstpos += dstPixelStride){
                          
                                dstdata[db][dstpos] = srcdata[sb][srcpos];
                        }
                    }
                }
            }
        }

        d.setPixels(dimd);
    }
View Full Code Here

        int nSrcs = sources.length;
        int[] snbands = new int[nSrcs];
        PixelAccessor[] pas = new PixelAccessor[nSrcs];

        for ( int i = 0; i < nSrcs; i++ ) {
            pas[i] = new PixelAccessor(sources[i].getSampleModel(), colorModels[i]);

            if ( colorModels[i] instanceof IndexColorModel ) {
                snbands[i] = colorModels[i].getNumComponents();
            } else {
                snbands[i] = sources[i].getNumBands();
            }
        }       

        int dnbands     = dest.getNumBands();
        int destType    = dest.getTransferType();
        PixelAccessor d = new PixelAccessor(dest.getSampleModel(), null);

        UnpackedImageData dimd = d.getPixels(dest,
                                             destRect,    //liney,
                                             destType,
                                             true);

        double[][] dstdata = (double[][])dimd.data;

        for ( int sindex = 0, db = 0; sindex < nSrcs; sindex++ ) {

            UnpackedImageData simd =
                colorModels[sindex] instanceof IndexColorModel ?
                pas[sindex].getComponents(sources[sindex],
                                          destRect,
                                          sources[sindex].getSampleModel().getTransferType()) :
                pas[sindex].getPixels(sources[sindex],
                                      destRect,
                                      sources[sindex].getSampleModel().getTransferType(),
                                      false);

            int srcPixelStride = simd.pixelStride;
            int srcLineStride  = simd.lineStride;
            int dstPixelStride = dimd.pixelStride;
            int dstLineStride  = dimd.lineStride;
            int dRectWidth     = destRect.width;

            for ( int sb = 0; sb < snbands[sindex]; sb++, db++ ) {
                if ( db < dnbands ) {
                    double[][] srcdata = (double[][])simd.data;
                    int srcstart = simd.bandOffsets[sb];
                    int dststart = dimd.bandOffsets[db];
                    for(int y = 0;
                        y < destRect.height;
                        y++, srcstart += srcLineStride, dststart += dstLineStride){
                       
                        for(int i=0, srcpos = srcstart, dstpos = dststart;
                            i < dRectWidth;
                            i++, srcpos += srcPixelStride, dstpos += dstPixelStride){
                          
                                dstdata[db][dstpos] = srcdata[sb][srcpos];
                        }
                    }
                }
            }
        }

        d.setPixels(dimd);
    }
View Full Code Here

    protected void accumulateStatistics(String name,
                                        Raster source,
                                        Object stats) {
        if(!isInitialized) {
            srcPA = new PixelAccessor(getSourceImage(0));
            srcSampleType = srcPA.sampleType == PixelAccessor.TYPE_BIT ?
                DataBuffer.TYPE_BYTE : srcPA.sampleType;
            isInitialized = true;
        }
View Full Code Here

            }
        }

        private void constructTree(Raster source) {
            if(!isInitialized) {
                srcPA = new PixelAccessor(getSourceImage(0));
                srcSampleType = srcPA.sampleType == PixelAccessor.TYPE_BIT ?
                    DataBuffer.TYPE_BYTE : srcPA.sampleType;
                isInitialized = true;
            }
View Full Code Here

TOP

Related Classes of com.lightcrafts.mediax.jai.PixelAccessor

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.