static private int calcSkipMSBP(CBlkWTData cblk, int lmb)
{
int k, kmax, mask;
int[] data;
int maxmag;
int mag;
int w, h;
int msbp;
int l;
data = (int[]) cblk.Data;
w = cblk.w;
h = cblk.h;
// First look for the maximum magnitude in the code-block
maxmag = 0;
// Consider only magnitude bits that are in non-fractional bit-planes.
mask = 0x7FFFFFFF & (~ ((1 << lmb) - 1));
for (l = h - 1, k = cblk.offset; l >= 0; l--)
{
for (kmax = k + w; k < kmax; k++)
{
mag = data[k] & mask;
if (mag > maxmag)
maxmag = mag;
}
k += cblk.scanw - w;
}
// Now calculate the number of all zero most significant
// bit-planes for the maximum magnitude.
msbp = 30;
do
{
if (((1 << msbp) & maxmag) != 0)
break;
msbp--;
}
while (msbp >= lmb);
// Return the number of non-significant bit-planes to skip
return 30 - msbp;
}