public final WritableRaster filter(Raster src,WritableRaster dst){
  int numBands=src.getNumBands();
  int width=src.getWidth();
  int height=src.getHeight();
  int[] srcPix=null;
  int step=0;
  int tidx=0;
  if (dst == null) {
    dst=createCompatibleDestRaster(src);
  }
 else   if (height != dst.getHeight() || width != dst.getWidth()) {
    throw new IllegalArgumentException("Width or height of Rasters do not " + "match");
  }
 else   if (numBands != dst.getNumBands()) {
    throw new IllegalArgumentException("Number of bands in src " + numBands + " does not equal number of bands in dest "+ dst.getNumBands());
  }
  if (length != 1 && length != src.getNumBands()) {
    throw new IllegalArgumentException("Number of scaling constants " + "does not equal the number of" + " of bands in the src raster");
  }
  if (ImagingLib.filter(this,src,dst) != null) {
    return dst;
  }
  if (canUseLookup(src,dst)) {
    int srcNgray=(1 << srcNbits);
    int dstNgray=(1 << dstNbits);
    if (dstNgray == 256) {
      ByteLookupTable lut=createByteLut(scaleFactors,offsets,numBands,srcNgray);
      LookupOp op=new LookupOp(lut,hints);
      op.filter(src,dst);
    }
 else {
      ShortLookupTable lut=createShortLut(scaleFactors,offsets,numBands,srcNgray);
      LookupOp op=new LookupOp(lut,hints);
      op.filter(src,dst);
    }
  }
 else {
    if (length > 1) {
      step=1;
    }
    int sminX=src.getMinX();
    int sY=src.getMinY();
    int dminX=dst.getMinX();
    int dY=dst.getMinY();
    int sX;
    int dX;
    int nbits;
    int dstMax[]=new int[numBands];
    int dstMask[]=new int[numBands];
    SampleModel dstSM=dst.getSampleModel();
    for (int z=0; z < numBands; z++) {
      nbits=dstSM.getSampleSize(z);
      dstMax[z]=(1 << nbits) - 1;
      dstMask[z]=~(dstMax[z]);
    }
    int val;
    for (int y=0; y < height; y++, sY++, dY++) {
      dX=dminX;
      sX=sminX;
      for (int x=0; x < width; x++, sX++, dX++) {
        srcPix=src.getPixel(sX,sY,srcPix);
        tidx=0;
        for (int z=0; z < numBands; z++, tidx+=step) {
          val=(int)(srcPix[z] * scaleFactors[tidx] + offsets[tidx]);
          if ((val & dstMask[z]) != 0) {
            if (val < 0) {
              val=0;
            }
 else {
              val=dstMax[z];
            }
          }
          srcPix[z]=val;
        }
        dst.setPixel(dX,dY,srcPix);
      }
    }
  }
  return dst;
}

public final WritableRaster filter ( Raster src , WritableRaster dst ) { int numBands = src . getNumBands ( ) ; int width = src . getWidth ( ) ; int height = src . getHeight ( ) ; int [ ] srcPix = null ; int step = 0 ; int tidx = 0 ; if ( dst == null ) { dst = createCompatibleDestRaster ( src ) ; } else if ( height != dst . getHeight ( ) || width != dst . getWidth ( ) ) { throw new IllegalArgumentException ( "Width or height of Rasters do not " + "match" ) ; } else if ( numBands != dst . getNumBands ( ) ) { throw new IllegalArgumentException ( "Number of bands in src " + numBands + " does not equal number of bands in dest " + dst . getNumBands ( ) ) ; } if ( length != 1 && length != src . getNumBands ( ) ) { throw new IllegalArgumentException ( "Number of scaling constants " + "does not equal the number of" + " of bands in the src raster" ) ; } if ( ImagingLib . filter ( this , src , dst ) != null ) { return dst ; } if ( canUseLookup ( src , dst ) ) { int srcNgray = ( 1 << srcNbits ) ; int dstNgray = ( 1 << dstNbits ) ; if ( dstNgray == 256 ) { ByteLookupTable lut = createByteLut ( scaleFactors , offsets , numBands , srcNgray ) ; LookupOp op = new LookupOp ( lut , hints ) ; op . filter ( src , dst ) ; } else { ShortLookupTable lut = createShortLut ( scaleFactors , offsets , numBands , srcNgray ) ; LookupOp op = new LookupOp ( lut , hints ) ; op . filter ( src , dst ) ; } } else { if ( length > 1 ) { step = 1 ; } int sminX = src . getMinX ( ) ; int sY = src . getMinY ( ) ; int dminX = dst . getMinX ( ) ; int dY = dst . getMinY ( ) ; int sX ; int dX ; int nbits ; int dstMax [ ] = new int [ numBands ] ; int dstMask [ ] = new int [ numBands ] ; SampleModel dstSM = dst . getSampleModel ( ) ; for ( int z = 0 ; z < numBands ; z ++ ) { nbits = dstSM . getSampleSize ( z ) ; dstMax [ z ] = ( 1 << nbits ) - 1 ; dstMask [ z ] = ~ ( dstMax [ z ] ) ; } int val ; for ( int y = 0 ; y < height ; y ++ , sY ++ , dY ++ ) { dX = dminX ; sX = sminX ; for ( int x = 0 ; x < width ; x ++ , sX ++ , dX ++ ) { srcPix = src . getPixel ( sX , sY , srcPix ) ; tidx = 0 ; for ( int z = 0 ; z < numBands ; z ++ , tidx += step ) { val = ( int ) ( srcPix [ z ] * scaleFactors [ tidx ] + offsets [ tidx ] ) ; if ( ( val & dstMask [ z ] ) != 0 ) { if ( val < 0 ) { val = 0 ; } else { val = dstMax [ z ] ; } } srcPix [ z ] = val ; } dst . setPixel ( dX , dY , srcPix ) ; } } } return dst ; }
rescales the pixel data in the source raster . if the destination raster is null , a new raster will be created . the source and destination must have the same number of bands . otherwise , an illegalargumentexception is thrown . note that the number of scaling factors / offsets in this object must meet the restrictions stated in the class comments above . otherwise , an illegalargumentexception is thrown .
