public void computeMinMax(int samplesPerPixel,float missing){
  minimum=new double[samplesPerPixel];
  maximum=new double[samplesPerPixel];
  Arrays.fill(minimum,Double.MAX_VALUE);
  Arrays.fill(maximum,-Double.MAX_VALUE);
  byte[] bArray=new byte[width * numBytes];
  ByteBuffer bBuf=ByteBuffer.wrap(bArray);
  bBuf.rewind();
switch (dataType) {
case Float:
    for (int r=0; r < length; ++r) {
      mmbBuf.get(r,bArray);
      bBuf.rewind();
      for (int c=0; c < width; ++c) {
        float val=bBuf.getFloat();
        for (int i=0; i < samplesPerPixel; ++i) {
          if (!Float.isNaN(val) && (val != missing)) {
            minimum[i]=Math.min(minimum[i],val);
            maximum[i]=Math.max(maximum[i],val);
          }
        }
      }
      bBuf.rewind();
    }
  break;
case Integer:
for (int r=0; r < length; ++r) {
  mmbBuf.get(r,bArray);
  bBuf.rewind();
  for (int c=0; c < width; ++c) {
    int val=bBuf.getInt();
    for (int i=0; i < samplesPerPixel; ++i) {
      if (val != missing) {
        minimum[i]=Math.min(minimum[i],val);
        maximum[i]=Math.max(maximum[i],val);
      }
    }
  }
  bBuf.rewind();
}
break;
case UnsignedInteger:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
long val=MathUtil.unsignedInt(bBuf.getInt());
for (int i=0; i < samplesPerPixel; ++i) {
  if (val != missing) {
    minimum[i]=Math.min(minimum[i],val);
    maximum[i]=Math.max(maximum[i],val);
  }
}
}
bBuf.rewind();
}
break;
case Short:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
short val=bBuf.getShort();
for (int i=0; i < samplesPerPixel; ++i) {
if (val != missing) {
minimum[i]=Math.min(minimum[i],val);
maximum[i]=Math.max(maximum[i],val);
}
}
}
bBuf.rewind();
}
break;
case UnsignedShort:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
int val=MathUtil.unsignedShort(bBuf.getShort());
for (int i=0; i < samplesPerPixel; ++i) {
if (val != missing) {
minimum[i]=Math.min(minimum[i],val);
maximum[i]=Math.max(maximum[i],val);
}
}
}
bBuf.rewind();
}
break;
case Byte:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
byte val=bBuf.get();
for (int i=0; i < samplesPerPixel; ++i) {
if (val != missing) {
minimum[i]=Math.min(minimum[i],val);
maximum[i]=Math.max(maximum[i],val);
}
}
}
bBuf.rewind();
}
break;
case UnsignedByte:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
int val=MathUtil.unsignedByte(bBuf.get());
for (int i=0; i < samplesPerPixel; ++i) {
if (val != missing) {
minimum[i]=Math.min(minimum[i],val);
maximum[i]=Math.max(maximum[i],val);
}
}
}
bBuf.rewind();
}
break;
case Double:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
double val=bBuf.getDouble();
for (int i=0; i < samplesPerPixel; ++i) {
if (!Double.isNaN(val) && (val != missing)) {
minimum[i]=Math.min(minimum[i],val);
maximum[i]=Math.max(maximum[i],val);
}
}
}
bBuf.rewind();
}
break;
case Long:
for (int r=0; r < length; ++r) {
mmbBuf.get(r,bArray);
bBuf.rewind();
for (int c=0; c < width; ++c) {
long val=bBuf.getLong();
for (int i=0; i < samplesPerPixel; ++i) {
if (val != missing) {
minimum[i]=Math.min(minimum[i],val);
maximum[i]=Math.max(maximum[i],val);
}
}
}
bBuf.rewind();
}
break;
case Unknown:
break;
}
}

public void computeMinMax ( int samplesPerPixel , float missing ) { minimum = new double [ samplesPerPixel ] ; maximum = new double [ samplesPerPixel ] ; Arrays . fill ( minimum , Double . MAX_VALUE ) ; Arrays . fill ( maximum , - Double . MAX_VALUE ) ; byte [ ] bArray = new byte [ width * numBytes ] ; ByteBuffer bBuf = ByteBuffer . wrap ( bArray ) ; bBuf . rewind ( ) ; switch ( dataType ) { case Float : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { float val = bBuf . getFloat ( ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( ! Float . isNaN ( val ) && ( val != missing ) ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case Integer : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { int val = bBuf . getInt ( ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case UnsignedInteger : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { long val = MathUtil . unsignedInt ( bBuf . getInt ( ) ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case Short : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { short val = bBuf . getShort ( ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case UnsignedShort : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { int val = MathUtil . unsignedShort ( bBuf . getShort ( ) ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case Byte : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { byte val = bBuf . get ( ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case UnsignedByte : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { int val = MathUtil . unsignedByte ( bBuf . get ( ) ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case Double : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { double val = bBuf . getDouble ( ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( ! Double . isNaN ( val ) && ( val != missing ) ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case Long : for ( int r = 0 ; r < length ; ++ r ) { mmbBuf . get ( r , bArray ) ; bBuf . rewind ( ) ; for ( int c = 0 ; c < width ; ++ c ) { long val = bBuf . getLong ( ) ; for ( int i = 0 ; i < samplesPerPixel ; ++ i ) { if ( val != missing ) { minimum [ i ] = Math . min ( minimum [ i ] , val ) ; maximum [ i ] = Math . max ( maximum [ i ] , val ) ; } } } bBuf . rewind ( ) ; } break ; case Unknown : break ; } }
compute the minimum and maximum
