Package com.lightcrafts.mediax.jai

Examples of com.lightcrafts.mediax.jai.PixelAccessor


                               WritableRaster dest,
                               Rectangle destRect) {

        Raster source = sources[0];

  PixelAccessor pa = new PixelAccessor(source.getSampleModel(), null);
  PackedImageData srcIm =
            pa.getPackedPixels(source, source.getBounds(), false, false);

  pa = new PixelAccessor(dest.getSampleModel(), null);
  PackedImageData dstIm =
            pa.getPackedPixels(dest, destRect, true, false);

        // src data under kernel, packed in int.
  int[] srcUK = new int [kwPack * kh];

  // sliding the kernel row by row
  // general the packed matrix under the row
  int dheight = destRect.height;
  int dwidth  = destRect.width;

  int sOffset = srcIm.offset;
  int dOffset = dstIm.offset;
  for (int j = 0; j < dheight; j++) {
            int selement, val, dindex, delement;

      // reset srcUK for each row beginning
      // src[sOffset +[-kx:kw-kx, -ky:kh-ky]] placed in srcUK
      //
      for (int m = 0; m < srcUK.length; m++){
          srcUK[m] = 0;
      }
     
      // initial srcUK
      // first shift left the packed bits under the sliding kernel by 1 bit
      // then fill (compute) in the last bit of each row
      for(int i = 0; i < kw -1; i++){
          bitShiftMatrixLeft(srcUK, kh, kwPack); // expand for speedup?
    int lastCol = kwPack - 1;
    int bitLoc  = srcIm.bitOffset + i;
    int byteLoc = bitLoc >> 3;
    bitLoc = 7 - (bitLoc & 7);
    for(int m=0, sOffsetB = sOffset;
        m < kh;
        m++, sOffsetB += srcIm.lineStride){

      selement = (int)srcIm.data[sOffsetB + byteLoc];
      val = (selement >> bitLoc) & 0x1;
      srcUK[lastCol] |= val;
      lastCol += kwPack;
    }
      }

      // same as above
      // also setting dest
      for (int i = 0; i < dwidth; i++){

          bitShiftMatrixLeft(srcUK, kh, kwPack); // expand for speedup?
    int lastCol = kwPack - 1;
    int bitLoc  = srcIm.bitOffset + i + kw -1;
    int byteLoc = bitLoc >> 3;
    bitLoc = 7 - (bitLoc & 7);
    for(int m=0, sOffsetB = sOffset;
        m < kh;
        m++, sOffsetB += srcIm.lineStride){

      selement = (int)srcIm.data[sOffsetB + byteLoc];
      val = (selement >> bitLoc) & 0x1;
      srcUK[lastCol] |= val;
      lastCol += kwPack;
    }

    // set dest bits
    for (int m = 0; m < srcUK.length; m++){
        if ((srcUK[m] & kdataPack[m]) != 0){
              int dBitLoc = dstIm.bitOffset + i;
          int dshift  = 7 - (dBitLoc & 7);
          int dByteLoc= (dBitLoc >> 3) + dOffset;
          delement  = (int)dstIm.data[dByteLoc];
          delement |= (0x1) << dshift;
          dstIm.data[dByteLoc] = (byte)delement;
          break;
        }
    }

      }
            sOffset += srcIm.lineStride;
            dOffset += dstIm.lineStride;
        }
  pa.setPackedPixels(dstIm);
    }
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;

            totalPixelValue = new double[srcPA.numBands];
            totalPixelCount = 0;
View Full Code Here

        setProperty("JAI.LookupTable", colorMap);
    }

    private void computeHistogram(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

                               WritableRaster dest,
                               Rectangle destRect) {

        Raster source = sources[0];

  PixelAccessor pa = new PixelAccessor(source.getSampleModel(), null);
  PackedImageData srcIm =
            pa.getPackedPixels(source, source.getBounds(), false, false);

  pa = new PixelAccessor(dest.getSampleModel(), null);
  PackedImageData dstIm =
            pa.getPackedPixels(dest, destRect, true, false);

        // src data under kernel, packed in int.
  int[] srcUK = new int [kwPack * kh];

  // sliding the kernel row by row
  // general the packed matrix under the row
  int dheight = destRect.height;
  int dwidth  = destRect.width;

  int sOffset = srcIm.offset;
  int dOffset = dstIm.offset;
  for (int j = 0; j < dheight; j++) {
            int selement, val, dindex, delement;

      // reset srcUK for each row beginning
      // src[sOffset +[-kx:kw-kx, -ky:kh-ky]] placed in srcUK
      //
      for (int m = 0; m < srcUK.length; m++){
          srcUK[m] = 0;
      }
     
      // initial srcUK
      // first shift left the packed bits under the sliding kernel by 1 bit
      // then fill (compute) in the last bit of each row
      for(int i = 0; i < kw -1; i++){
          bitShiftMatrixLeft(srcUK, kh, kwPack); // expand for speedup?
    int lastCol = kwPack - 1;
    int bitLoc  = srcIm.bitOffset + i;
    int byteLoc = bitLoc >> 3;
    bitLoc = 7 - (bitLoc & 7);
    for(int m=0, sOffsetB = sOffset;
        m < kh;
        m++, sOffsetB += srcIm.lineStride){

      selement = (int)srcIm.data[sOffsetB + byteLoc];
      val = (selement >> bitLoc) & 0x1;
      srcUK[lastCol] |= val;
      lastCol += kwPack;
    }
      }

      // same as above
      // also setting dest
      for (int i = 0; i < dwidth; i++){

          bitShiftMatrixLeft(srcUK, kh, kwPack); // expand for speedup?
    int lastCol = kwPack - 1;
    int bitLoc  = srcIm.bitOffset + i + kw -1;
    int byteLoc = bitLoc >> 3;
    bitLoc = 7 - (bitLoc & 7);
    for(int m=0, sOffsetB = sOffset;
        m < kh;
        m++, sOffsetB += srcIm.lineStride){

      selement = (int)srcIm.data[sOffsetB + byteLoc];
      val = (selement >> bitLoc) & 0x1;
      srcUK[lastCol] |= val;
      lastCol += kwPack;
    }


    int dBitLoc = dstIm.bitOffset + i;
    int dshift  = 7 - (dBitLoc & 7);
    int dByteLoc= (dBitLoc >> 3) + dOffset;
    delement  = (int)dstIm.data[dByteLoc];
    delement |= (0x1) << dshift;

    for (int m = 0; m < srcUK.length; m++){
        if ((srcUK[m] & kdataPack[m]) != kdataPack[m]){
          delement &= ~((0x1) << dshift);
          break;
        }
    }
    dstIm.data[dByteLoc] = (byte)delement;
      }
            sOffset += srcIm.lineStride;
            dOffset += dstIm.lineStride;
        }
  pa.setPackedPixels(dstIm);
    }
View Full Code Here

                            Rectangle destRect) {
        if (colorMap == null)
            train();

        if(!isInitialized) {
            srcPA = new PixelAccessor(getSourceImage(0));
            srcSampleType = srcPA.sampleType == PixelAccessor.TYPE_BIT ?
                DataBuffer.TYPE_BYTE : srcPA.sampleType;
            isInitialized = true;
        }

        UnpackedImageData uid =
            srcPA.getPixels(sources[0], destRect,
                            srcSampleType, false);
        Rectangle rect = uid.rect;
        byte[][] data = uid.getByteData();
        int srcLineStride = uid.lineStride;
        int srcPixelStride = uid.pixelStride;
        byte[] rBand = data[0];
        byte[] gBand = data[1];
        byte[] bBand = data[2];

        int lastLine = rect.height * srcLineStride + uid.bandOffsets[0];

        if (destPA == null)
            destPA = new PixelAccessor(this);

        UnpackedImageData destUid =
            destPA.getPixels(dest, destRect,
                             sampleModel.getDataType(), false);

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.