Example #1
0
		/// <summary> Re-initialize the PktDecoder instance at the beginning of a new tile.
		/// 
		/// </summary>
		/// <param name="nc">The number of components in this tile
		/// 
		/// </param>
		/// <param name="mdl">The maximum number of decomposition level in each component
		/// of this tile
		/// 
		/// </param>
		/// <param name="nl">The number of layers in  this tile
		/// 
		/// </param>
		/// <param name="cbI">The code-blocks array
		/// 
		/// </param>
		/// <param name="pph">Flag indicating whether packed packet headers was used
		/// 
		/// </param>
		/// <param name="pphbais">Stream containing the packed packet headers
		/// 
		/// </param>
		public virtual CBlkInfo[][][][][] restart(int nc, int[] mdl, int nl, CBlkInfo[][][][][] cbI, bool pph, System.IO.MemoryStream pphbais)
		{
			this.nc = nc;
			this.nl = nl;
			this.tIdx = src.TileIdx;
			this.pph = pph;
			this.pphbais = pphbais;
			
			sopUsed = ((System.Boolean) decSpec.sops.getTileDef(tIdx));
			pktIdx = 0;
			ephUsed = ((System.Boolean) decSpec.ephs.getTileDef(tIdx));
			
			cbI = new CBlkInfo[nc][][][][];
			lblock = new int[nc][][][][];
			ttIncl = new TagTreeDecoder[nc][][][];
			ttMaxBP = new TagTreeDecoder[nc][][][];
			numPrec = new Coord[nc][];
			ppinfo = new PrecInfo[nc][][];
			
			// Used to compute the maximum number of precincts for each resolution
			// level
			int tcx0, tcy0, tcx1, tcy1; // Current tile position in the domain of
			// the image component
			int trx0, try0, trx1, try1; // Current tile position in the reduced
			// resolution image domain
			//int xrsiz, yrsiz; // Component sub-sampling factors
			
			SubbandSyn root, sb;
			int mins, maxs;
			Coord nBlk = null;
			int cb0x = src.CbULX;
			int cb0y = src.CbULY;
			
			for (int c = 0; c < nc; c++)
			{
				cbI[c] = new CBlkInfo[mdl[c] + 1][][][];
				lblock[c] = new int[mdl[c] + 1][][][];
				ttIncl[c] = new TagTreeDecoder[mdl[c] + 1][][];
				ttMaxBP[c] = new TagTreeDecoder[mdl[c] + 1][][];
				numPrec[c] = new Coord[mdl[c] + 1];
				ppinfo[c] = new PrecInfo[mdl[c] + 1][];
				
				// Get the tile-component coordinates on the reference grid
				tcx0 = src.getResULX(c, mdl[c]);
				tcy0 = src.getResULY(c, mdl[c]);
				tcx1 = tcx0 + src.getTileCompWidth(tIdx, c, mdl[c]);
				tcy1 = tcy0 + src.getTileCompHeight(tIdx, c, mdl[c]);
				
				for (int r = 0; r <= mdl[c]; r++)
				{
					
					// Tile's coordinates in the reduced resolution image domain
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					trx0 = (int) System.Math.Ceiling(tcx0 / (double) (1 << (mdl[c] - r)));
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					try0 = (int) System.Math.Ceiling(tcy0 / (double) (1 << (mdl[c] - r)));
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					trx1 = (int) System.Math.Ceiling(tcx1 / (double) (1 << (mdl[c] - r)));
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					try1 = (int) System.Math.Ceiling(tcy1 / (double) (1 << (mdl[c] - r)));
					
					// Calculate the maximum number of precincts for each
					// resolution level taking into account tile specific options.
					double twoppx = (double) getPPX(tIdx, c, r);
					double twoppy = (double) getPPY(tIdx, c, r);
					numPrec[c][r] = new Coord();
					if (trx1 > trx0)
					{
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						numPrec[c][r].x = (int) System.Math.Ceiling((trx1 - cb0x) / twoppx) - (int) System.Math.Floor((trx0 - cb0x) / twoppx);
					}
					else
					{
						numPrec[c][r].x = 0;
					}
					if (try1 > try0)
					{
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						numPrec[c][r].y = (int) System.Math.Ceiling((try1 - cb0y) / twoppy) - (int) System.Math.Floor((try0 - cb0y) / twoppy);
					}
					else
					{
						numPrec[c][r].y = 0;
					}
					
					// First and last subbands indexes
					mins = (r == 0)?0:1;
					maxs = (r == 0)?1:4;
					
					int maxPrec = numPrec[c][r].x * numPrec[c][r].y;
					
					ttIncl[c][r] = new TagTreeDecoder[maxPrec][];
					for (int i = 0; i < maxPrec; i++)
					{
						ttIncl[c][r][i] = new TagTreeDecoder[maxs + 1];
					}
					ttMaxBP[c][r] = new TagTreeDecoder[maxPrec][];
					for (int i2 = 0; i2 < maxPrec; i2++)
					{
						ttMaxBP[c][r][i2] = new TagTreeDecoder[maxs + 1];
					}
					cbI[c][r] = new CBlkInfo[maxs + 1][][];
					lblock[c][r] = new int[maxs + 1][][];
					
					ppinfo[c][r] = new PrecInfo[maxPrec];
					fillPrecInfo(c, r, mdl[c]);
					
					root = (SubbandSyn) src.getSynSubbandTree(tIdx, c);
					for (int s = mins; s < maxs; s++)
					{
						sb = (SubbandSyn) root.getSubbandByIdx(r, s);
						nBlk = sb.numCb;
						
						cbI[c][r][s] = new CBlkInfo[nBlk.y][];
						for (int i3 = 0; i3 < nBlk.y; i3++)
						{
							cbI[c][r][s][i3] = new CBlkInfo[nBlk.x];
						}
						lblock[c][r][s] = new int[nBlk.y][];
						for (int i4 = 0; i4 < nBlk.y; i4++)
						{
							lblock[c][r][s][i4] = new int[nBlk.x];
						}
						
						for (int i = nBlk.y - 1; i >= 0; i--)
						{
							ArrayUtil.intArraySet(lblock[c][r][s][i], INIT_LBLOCK);
						}
					} // loop on subbands
				} // End loop on resolution levels
			} // End loop on components
			
			return cbI;
		}
Example #2
0
		/// <summary> Retrives precincts and code-blocks coordinates in the given resolution,
		/// level and component. Finishes TagTreeEncoder initialization as well.
		/// 
		/// </summary>
		/// <param name="c">Component index.
		/// 
		/// </param>
		/// <param name="r">Resolution level index.
		/// 
		/// </param>
		/// <param name="mdl">Number of decomposition level in component <tt>c</tt>.
		/// 
		/// </param>
		private void  fillPrecInfo(int c, int r, int mdl)
		{
			if (ppinfo[c][r].Length == 0)
				return ; // No precinct in this
			// resolution level
			
			Coord tileI = src.getTile(null);
			Coord nTiles = src.getNumTiles(null);
			
			int xsiz, ysiz, x0siz, y0siz;
			int xt0siz, yt0siz;
			int xtsiz, ytsiz;
			
			xt0siz = src.TilePartULX;
			yt0siz = src.TilePartULY;
			xtsiz = src.NomTileWidth;
			ytsiz = src.NomTileHeight;
			x0siz = hd.ImgULX;
			y0siz = hd.ImgULY;
			xsiz = hd.ImgWidth;
			ysiz = hd.ImgHeight;
			
			int tx0 = (tileI.x == 0)?x0siz:xt0siz + tileI.x * xtsiz;
			int ty0 = (tileI.y == 0)?y0siz:yt0siz + tileI.y * ytsiz;
			int tx1 = (tileI.x != nTiles.x - 1)?xt0siz + (tileI.x + 1) * xtsiz:xsiz;
			int ty1 = (tileI.y != nTiles.y - 1)?yt0siz + (tileI.y + 1) * ytsiz:ysiz;
			
			int xrsiz = hd.getCompSubsX(c);
			int yrsiz = hd.getCompSubsY(c);
			
			int tcx0 = src.getResULX(c, mdl);
			int tcy0 = src.getResULY(c, mdl);
			int tcx1 = tcx0 + src.getTileCompWidth(tIdx, c, mdl);
			int tcy1 = tcy0 + src.getTileCompHeight(tIdx, c, mdl);
			
			int ndl = mdl - r;
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int trx0 = (int) System.Math.Ceiling(tcx0 / (double) (1 << ndl));
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int try0 = (int) System.Math.Ceiling(tcy0 / (double) (1 << ndl));
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int trx1 = (int) System.Math.Ceiling(tcx1 / (double) (1 << ndl));
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int try1 = (int) System.Math.Ceiling(tcy1 / (double) (1 << ndl));
			
			int cb0x = src.CbULX;
			int cb0y = src.CbULY;
			
			double twoppx = (double) getPPX(tIdx, c, r);
			double twoppy = (double) getPPY(tIdx, c, r);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int twoppx2 = (int) (twoppx / 2);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int twoppy2 = (int) (twoppy / 2);
			
			// Precincts are located at (cb0x+i*twoppx,cb0y+j*twoppy)
			// Valid precincts are those which intersect with the current
			// resolution level
			int maxPrec = ppinfo[c][r].Length;
			int nPrec = 0;
			
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int istart = (int) System.Math.Floor((try0 - cb0y) / twoppy);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int iend = (int) System.Math.Floor((try1 - 1 - cb0y) / twoppy);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int jstart = (int) System.Math.Floor((trx0 - cb0x) / twoppx);
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int jend = (int) System.Math.Floor((trx1 - 1 - cb0x) / twoppx);
			
			int acb0x, acb0y;
			
			SubbandSyn root = src.getSynSubbandTree(tIdx, c);
			SubbandSyn sb = null;
			
			int p0x, p0y, p1x, p1y; // Precinct projection in subband
			int s0x, s0y, s1x, s1y; // Active subband portion
			int cw, ch;
			int kstart, kend, lstart, lend, k0, l0;
			int prg_ulx, prg_uly;
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int prg_w = (int) twoppx << ndl;
			//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
			int prg_h = (int) twoppy << ndl;
			int tmp1, tmp2;
			
			CBlkCoordInfo cb;
			
			for (int i = istart; i <= iend; i++)
			{
				// Vertical precincts
				for (int j = jstart; j <= jend; j++, nPrec++)
				{
					// Horizontal precincts
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					if (j == jstart && (trx0 - cb0x) % (xrsiz * ((int) twoppx)) != 0)
					{
						prg_ulx = tx0;
					}
					else
					{
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						prg_ulx = cb0x + j * xrsiz * ((int) twoppx << ndl);
					}
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					if (i == istart && (try0 - cb0y) % (yrsiz * ((int) twoppy)) != 0)
					{
						prg_uly = ty0;
					}
					else
					{
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						prg_uly = cb0y + i * yrsiz * ((int) twoppy << ndl);
					}
					
					//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
					ppinfo[c][r][nPrec] = new PrecInfo(r, (int) (cb0x + j * twoppx), (int) (cb0y + i * twoppy), (int) twoppx, (int) twoppy, prg_ulx, prg_uly, prg_w, prg_h);
					
					if (r == 0)
					{
						// LL subband
						acb0x = cb0x;
						acb0y = cb0y;
						
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						p0x = acb0x + j * (int) twoppx;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						p1x = p0x + (int) twoppx;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						p0y = acb0y + i * (int) twoppy;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						p1y = p0y + (int) twoppy;
						
						sb = (SubbandSyn) root.getSubbandByIdx(0, 0);
						s0x = (p0x < sb.ulcx)?sb.ulcx:p0x;
						s1x = (p1x > sb.ulcx + sb.w)?sb.ulcx + sb.w:p1x;
						s0y = (p0y < sb.ulcy)?sb.ulcy:p0y;
						s1y = (p1y > sb.ulcy + sb.h)?sb.ulcy + sb.h:p1y;
						
						// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
						cw = sb.nomCBlkW;
						ch = sb.nomCBlkH;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						k0 = (int) System.Math.Floor((sb.ulcy - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kstart = (int) System.Math.Floor((s0y - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kend = (int) System.Math.Floor((s1y - 1 - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						l0 = (int) System.Math.Floor((sb.ulcx - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lstart = (int) System.Math.Floor((s0x - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lend = (int) System.Math.Floor((s1x - 1 - acb0x) / (double) cw);
						
						if (s1x - s0x <= 0 || s1y - s0y <= 0)
						{
							ppinfo[c][r][nPrec].nblk[0] = 0;
							ttIncl[c][r][nPrec][0] = new TagTreeDecoder(0, 0);
							ttMaxBP[c][r][nPrec][0] = new TagTreeDecoder(0, 0);
						}
						else
						{
							ttIncl[c][r][nPrec][0] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							ttMaxBP[c][r][nPrec][0] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							CBlkCoordInfo[][] tmpArray = new CBlkCoordInfo[kend - kstart + 1][];
							for (int i2 = 0; i2 < kend - kstart + 1; i2++)
							{
								tmpArray[i2] = new CBlkCoordInfo[lend - lstart + 1];
							}
							ppinfo[c][r][nPrec].cblk[0] = tmpArray;
							ppinfo[c][r][nPrec].nblk[0] = (kend - kstart + 1) * (lend - lstart + 1);
							
							for (int k = kstart; k <= kend; k++)
							{
								// Vertical cblks
								for (int l = lstart; l <= lend; l++)
								{
									// Horiz. cblks
									cb = new CBlkCoordInfo(k - k0, l - l0);
									if (l == l0)
									{
										cb.ulx = sb.ulx;
									}
									else
									{
										cb.ulx = sb.ulx + l * cw - (sb.ulcx - acb0x);
									}
									if (k == k0)
									{
										cb.uly = sb.uly;
									}
									else
									{
										cb.uly = sb.uly + k * ch - (sb.ulcy - acb0y);
									}
									tmp1 = acb0x + l * cw;
									tmp1 = (tmp1 > sb.ulcx)?tmp1:sb.ulcx;
									tmp2 = acb0x + (l + 1) * cw;
									tmp2 = (tmp2 > sb.ulcx + sb.w)?sb.ulcx + sb.w:tmp2;
									cb.w = tmp2 - tmp1;
									tmp1 = acb0y + k * ch;
									tmp1 = (tmp1 > sb.ulcy)?tmp1:sb.ulcy;
									tmp2 = acb0y + (k + 1) * ch;
									tmp2 = (tmp2 > sb.ulcy + sb.h)?sb.ulcy + sb.h:tmp2;
									cb.h = tmp2 - tmp1;
									ppinfo[c][r][nPrec].cblk[0][k - kstart][l - lstart] = cb;
								} // Horizontal code-blocks
							} // Vertical code-blocks
						}
					}
					else
					{
						// HL, LH and HH subbands
						// HL subband
						acb0x = 0;
						acb0y = cb0y;
						
						p0x = acb0x + j * twoppx2;
						p1x = p0x + twoppx2;
						p0y = acb0y + i * twoppy2;
						p1y = p0y + twoppy2;
						
						sb = (SubbandSyn) root.getSubbandByIdx(r, 1);
						s0x = (p0x < sb.ulcx)?sb.ulcx:p0x;
						s1x = (p1x > sb.ulcx + sb.w)?sb.ulcx + sb.w:p1x;
						s0y = (p0y < sb.ulcy)?sb.ulcy:p0y;
						s1y = (p1y > sb.ulcy + sb.h)?sb.ulcy + sb.h:p1y;
						
						// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
						cw = sb.nomCBlkW;
						ch = sb.nomCBlkH;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						k0 = (int) System.Math.Floor((sb.ulcy - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kstart = (int) System.Math.Floor((s0y - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kend = (int) System.Math.Floor((s1y - 1 - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						l0 = (int) System.Math.Floor((sb.ulcx - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lstart = (int) System.Math.Floor((s0x - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lend = (int) System.Math.Floor((s1x - 1 - acb0x) / (double) cw);
						
						if (s1x - s0x <= 0 || s1y - s0y <= 0)
						{
							ppinfo[c][r][nPrec].nblk[1] = 0;
							ttIncl[c][r][nPrec][1] = new TagTreeDecoder(0, 0);
							ttMaxBP[c][r][nPrec][1] = new TagTreeDecoder(0, 0);
						}
						else
						{
							ttIncl[c][r][nPrec][1] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							ttMaxBP[c][r][nPrec][1] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							CBlkCoordInfo[][] tmpArray2 = new CBlkCoordInfo[kend - kstart + 1][];
							for (int i3 = 0; i3 < kend - kstart + 1; i3++)
							{
								tmpArray2[i3] = new CBlkCoordInfo[lend - lstart + 1];
							}
							ppinfo[c][r][nPrec].cblk[1] = tmpArray2;
							ppinfo[c][r][nPrec].nblk[1] = (kend - kstart + 1) * (lend - lstart + 1);
							
							for (int k = kstart; k <= kend; k++)
							{
								// Vertical cblks
								for (int l = lstart; l <= lend; l++)
								{
									// Horiz. cblks
									cb = new CBlkCoordInfo(k - k0, l - l0);
									if (l == l0)
									{
										cb.ulx = sb.ulx;
									}
									else
									{
										cb.ulx = sb.ulx + l * cw - (sb.ulcx - acb0x);
									}
									if (k == k0)
									{
										cb.uly = sb.uly;
									}
									else
									{
										cb.uly = sb.uly + k * ch - (sb.ulcy - acb0y);
									}
									tmp1 = acb0x + l * cw;
									tmp1 = (tmp1 > sb.ulcx)?tmp1:sb.ulcx;
									tmp2 = acb0x + (l + 1) * cw;
									tmp2 = (tmp2 > sb.ulcx + sb.w)?sb.ulcx + sb.w:tmp2;
									cb.w = tmp2 - tmp1;
									tmp1 = acb0y + k * ch;
									tmp1 = (tmp1 > sb.ulcy)?tmp1:sb.ulcy;
									tmp2 = acb0y + (k + 1) * ch;
									tmp2 = (tmp2 > sb.ulcy + sb.h)?sb.ulcy + sb.h:tmp2;
									cb.h = tmp2 - tmp1;
									ppinfo[c][r][nPrec].cblk[1][k - kstart][l - lstart] = cb;
								} // Horizontal code-blocks
							} // Vertical code-blocks
						}
						
						// LH subband
						acb0x = cb0x;
						acb0y = 0;
						
						p0x = acb0x + j * twoppx2;
						p1x = p0x + twoppx2;
						p0y = acb0y + i * twoppy2;
						p1y = p0y + twoppy2;
						
						sb = (SubbandSyn) root.getSubbandByIdx(r, 2);
						s0x = (p0x < sb.ulcx)?sb.ulcx:p0x;
						s1x = (p1x > sb.ulcx + sb.w)?sb.ulcx + sb.w:p1x;
						s0y = (p0y < sb.ulcy)?sb.ulcy:p0y;
						s1y = (p1y > sb.ulcy + sb.h)?sb.ulcy + sb.h:p1y;
						
						// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
						cw = sb.nomCBlkW;
						ch = sb.nomCBlkH;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						k0 = (int) System.Math.Floor((sb.ulcy - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kstart = (int) System.Math.Floor((s0y - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kend = (int) System.Math.Floor((s1y - 1 - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						l0 = (int) System.Math.Floor((sb.ulcx - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lstart = (int) System.Math.Floor((s0x - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lend = (int) System.Math.Floor((s1x - 1 - acb0x) / (double) cw);
						
						if (s1x - s0x <= 0 || s1y - s0y <= 0)
						{
							ppinfo[c][r][nPrec].nblk[2] = 0;
							ttIncl[c][r][nPrec][2] = new TagTreeDecoder(0, 0);
							ttMaxBP[c][r][nPrec][2] = new TagTreeDecoder(0, 0);
						}
						else
						{
							ttIncl[c][r][nPrec][2] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							ttMaxBP[c][r][nPrec][2] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							CBlkCoordInfo[][] tmpArray3 = new CBlkCoordInfo[kend - kstart + 1][];
							for (int i4 = 0; i4 < kend - kstart + 1; i4++)
							{
								tmpArray3[i4] = new CBlkCoordInfo[lend - lstart + 1];
							}
							ppinfo[c][r][nPrec].cblk[2] = tmpArray3;
							ppinfo[c][r][nPrec].nblk[2] = (kend - kstart + 1) * (lend - lstart + 1);
							
							for (int k = kstart; k <= kend; k++)
							{
								// Vertical cblks
								for (int l = lstart; l <= lend; l++)
								{
									// Horiz cblks
									cb = new CBlkCoordInfo(k - k0, l - l0);
									if (l == l0)
									{
										cb.ulx = sb.ulx;
									}
									else
									{
										cb.ulx = sb.ulx + l * cw - (sb.ulcx - acb0x);
									}
									if (k == k0)
									{
										cb.uly = sb.uly;
									}
									else
									{
										cb.uly = sb.uly + k * ch - (sb.ulcy - acb0y);
									}
									tmp1 = acb0x + l * cw;
									tmp1 = (tmp1 > sb.ulcx)?tmp1:sb.ulcx;
									tmp2 = acb0x + (l + 1) * cw;
									tmp2 = (tmp2 > sb.ulcx + sb.w)?sb.ulcx + sb.w:tmp2;
									cb.w = tmp2 - tmp1;
									tmp1 = acb0y + k * ch;
									tmp1 = (tmp1 > sb.ulcy)?tmp1:sb.ulcy;
									tmp2 = acb0y + (k + 1) * ch;
									tmp2 = (tmp2 > sb.ulcy + sb.h)?sb.ulcy + sb.h:tmp2;
									cb.h = tmp2 - tmp1;
									ppinfo[c][r][nPrec].cblk[2][k - kstart][l - lstart] = cb;
								} // Horizontal code-blocks
							} // Vertical code-blocks
						}
						
						// HH subband
						acb0x = 0;
						acb0y = 0;
						
						p0x = acb0x + j * twoppx2;
						p1x = p0x + twoppx2;
						p0y = acb0y + i * twoppy2;
						p1y = p0y + twoppy2;
						
						sb = (SubbandSyn) root.getSubbandByIdx(r, 3);
						s0x = (p0x < sb.ulcx)?sb.ulcx:p0x;
						s1x = (p1x > sb.ulcx + sb.w)?sb.ulcx + sb.w:p1x;
						s0y = (p0y < sb.ulcy)?sb.ulcy:p0y;
						s1y = (p1y > sb.ulcy + sb.h)?sb.ulcy + sb.h:p1y;
						
						// Code-blocks are located at (acb0x+k*cw,acb0y+l*ch)
						cw = sb.nomCBlkW;
						ch = sb.nomCBlkH;
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						k0 = (int) System.Math.Floor((sb.ulcy - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kstart = (int) System.Math.Floor((s0y - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						kend = (int) System.Math.Floor((s1y - 1 - acb0y) / (double) ch);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						l0 = (int) System.Math.Floor((sb.ulcx - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lstart = (int) System.Math.Floor((s0x - acb0x) / (double) cw);
						//UPGRADE_WARNING: Data types in Visual C# might be different.  Verify the accuracy of narrowing conversions. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1042'"
						lend = (int) System.Math.Floor((s1x - 1 - acb0x) / (double) cw);
						
						if (s1x - s0x <= 0 || s1y - s0y <= 0)
						{
							ppinfo[c][r][nPrec].nblk[3] = 0;
							ttIncl[c][r][nPrec][3] = new TagTreeDecoder(0, 0);
							ttMaxBP[c][r][nPrec][3] = new TagTreeDecoder(0, 0);
						}
						else
						{
							ttIncl[c][r][nPrec][3] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							ttMaxBP[c][r][nPrec][3] = new TagTreeDecoder(kend - kstart + 1, lend - lstart + 1);
							CBlkCoordInfo[][] tmpArray4 = new CBlkCoordInfo[kend - kstart + 1][];
							for (int i5 = 0; i5 < kend - kstart + 1; i5++)
							{
								tmpArray4[i5] = new CBlkCoordInfo[lend - lstart + 1];
							}
							ppinfo[c][r][nPrec].cblk[3] = tmpArray4;
							ppinfo[c][r][nPrec].nblk[3] = (kend - kstart + 1) * (lend - lstart + 1);
							
							for (int k = kstart; k <= kend; k++)
							{
								// Vertical cblks
								for (int l = lstart; l <= lend; l++)
								{
									// Horiz cblks
									cb = new CBlkCoordInfo(k - k0, l - l0);
									if (l == l0)
									{
										cb.ulx = sb.ulx;
									}
									else
									{
										cb.ulx = sb.ulx + l * cw - (sb.ulcx - acb0x);
									}
									if (k == k0)
									{
										cb.uly = sb.uly;
									}
									else
									{
										cb.uly = sb.uly + k * ch - (sb.ulcy - acb0y);
									}
									tmp1 = acb0x + l * cw;
									tmp1 = (tmp1 > sb.ulcx)?tmp1:sb.ulcx;
									tmp2 = acb0x + (l + 1) * cw;
									tmp2 = (tmp2 > sb.ulcx + sb.w)?sb.ulcx + sb.w:tmp2;
									cb.w = tmp2 - tmp1;
									tmp1 = acb0y + k * ch;
									tmp1 = (tmp1 > sb.ulcy)?tmp1:sb.ulcy;
									tmp2 = acb0y + (k + 1) * ch;
									tmp2 = (tmp2 > sb.ulcy + sb.h)?sb.ulcy + sb.h:tmp2;
									cb.h = tmp2 - tmp1;
									ppinfo[c][r][nPrec].cblk[3][k - kstart][l - lstart] = cb;
								} // Horizontal code-blocks
							} // Vertical code-blocks
						}
					}
				} // Horizontal precincts
			} // Vertical precincts
		}
Example #3
0
        /// <summary> Creates a new packet encoder object, using the information from the
        /// 'infoSrc' object. 
        /// 
        /// </summary>
        /// <param name="infoSrc">The source of information to construct the object.
        /// 
        /// </param>
        /// <param name="encSpec">The encoding parameters.
        /// 
        /// </param>
        /// <param name="numPrec">Maximum number of precincts in each tile, component
        /// and resolution level.
        /// 
        /// </param>
        /// <param name="pl">ParameterList instance that holds command line options
        /// 
        /// </param>
        public PktEncoder(CodedCBlkDataSrcEnc infoSrc, EncoderSpecs encSpec, Coord[][][] numPrec, ParameterList pl)
        {
            this.infoSrc = infoSrc;
            this.encSpec = encSpec;

            // Check parameters
            pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));

            // Get number of components and tiles
            int nc = infoSrc.NumComps;
            int nt = infoSrc.getNumTiles();

            // Do initial allocation
            ttIncl = new TagTreeEncoder[nt][][][][];
            for (int i = 0; i < nt; i++)
            {
                ttIncl[i] = new TagTreeEncoder[nc][][][];
            }
            ttMaxBP = new TagTreeEncoder[nt][][][][];
            for (int i2 = 0; i2 < nt; i2++)
            {
                ttMaxBP[i2] = new TagTreeEncoder[nc][][][];
            }
            lblock = new int[nt][][][][];
            for (int i3 = 0; i3 < nt; i3++)
            {
                lblock[i3] = new int[nc][][][];
            }
            prevtIdxs = new int[nt][][][][];
            for (int i4 = 0; i4 < nt; i4++)
            {
                prevtIdxs[i4] = new int[nc][][][];
            }
            ppinfo = new PrecInfo[nt][][][];
            for (int i5 = 0; i5 < nt; i5++)
            {
                ppinfo[i5] = new PrecInfo[nc][][];
            }

            // Finish allocation
            SubbandAn root, sb;
            int maxs, mins;
            int mrl;
            //Coord tmpCoord = null;
            int numcb; // Number of code-blocks
            //System.Collections.ArrayList cblks = null;
            infoSrc.setTile(0, 0);
            for (int t = 0; t < nt; t++)
            {
                // Loop on tiles
                for (int c = 0; c < nc; c++)
                {
                    // Loop on components
                    // Get number of resolution levels
                    root = infoSrc.getAnSubbandTree(t, c);
                    mrl = root.resLvl;

                    lblock[t][c] = new int[mrl + 1][][];
                    ttIncl[t][c] = new TagTreeEncoder[mrl + 1][][];
                    ttMaxBP[t][c] = new TagTreeEncoder[mrl + 1][][];
                    prevtIdxs[t][c] = new int[mrl + 1][][];
                    ppinfo[t][c] = new PrecInfo[mrl + 1][];

                    for (int r = 0; r <= mrl; r++)
                    {
                        // Loop on resolution levels
                        mins = (r == 0)?0:1;
                        maxs = (r == 0)?1:4;

                        int maxPrec = numPrec[t][c][r].x * numPrec[t][c][r].y;

                        ttIncl[t][c][r] = new TagTreeEncoder[maxPrec][];
                        for (int i6 = 0; i6 < maxPrec; i6++)
                        {
                            ttIncl[t][c][r][i6] = new TagTreeEncoder[maxs];
                        }
                        ttMaxBP[t][c][r] = new TagTreeEncoder[maxPrec][];
                        for (int i7 = 0; i7 < maxPrec; i7++)
                        {
                            ttMaxBP[t][c][r][i7] = new TagTreeEncoder[maxs];
                        }
                        prevtIdxs[t][c][r] = new int[maxs][];
                        lblock[t][c][r] = new int[maxs][];

                        // Precincts and code-blocks
                        ppinfo[t][c][r] = new PrecInfo[maxPrec];
                        fillPrecInfo(t, c, r);

                        for (int s = mins; s < maxs; s++)
                        {
                            // Loop on subbands
                            sb = (SubbandAn) root.getSubbandByIdx(r, s);
                            numcb = sb.numCb.x * sb.numCb.y;

                            lblock[t][c][r][s] = new int[numcb];
                            ArrayUtil.intArraySet(lblock[t][c][r][s], INIT_LBLOCK);

                            prevtIdxs[t][c][r][s] = new int[numcb];
                            ArrayUtil.intArraySet(prevtIdxs[t][c][r][s], - 1);
                        }
                    }
                }
                if (t != nt - 1)
                    infoSrc.nextTile();
            }
        }