CSJ2K.j2k.entropy.encoder.StdEntropyCoder.calcSkipMSBP C# (CSharp) Method

calcSkipMSBP() static private method

Calculates the number of magnitude bit-planes that are to be skipped, because they are non-significant. The algorithm looks for the largest magnitude and calculates the most significant bit-plane of it.
static private calcSkipMSBP ( CSJ2K.j2k.wavelet.analysis.CBlkWTData cblk, int lmb ) : int
cblk CSJ2K.j2k.wavelet.analysis.CBlkWTData The code-block of data to scan /// ///
lmb int The least significant magnitude bit in the data /// ///
return int
		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;
		}