This class holds references to each module specifications used in the decoding chain. This avoid big amount of arguments in method calls. A specification contains values of each tile-component for one module. All members must be instance of ModuleSpec class (or its children).
コード例 #1
0
ファイル: ROIDeScaler.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Creates a ROIDeScaler object. The information needed to create the
		/// object is the Entropy decoder used and the parameters.
		/// 
		/// </summary>
		/// <param name="src">The source of data that is to be descaled
		/// 
		/// </param>
		/// <param name="pl">The parameter list (or options).
		/// 
		/// </param>
		/// <param name="decSpec">The decoding specifications
		/// 
		/// </param>
		/// <exception cref="IllegalArgumentException">If an error occurs while parsing
		/// the options in 'pl'
		/// 
		/// </exception>
		public static ROIDeScaler createInstance(CBlkQuantDataSrcDec src, ParameterList pl, DecoderSpecs decSpec)
		{
			System.String noRoi;
			//int i;
			
			// Check parameters
			pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));
			
			// Check if no_roi specified in command line or no roi signalled
			// in bit stream
			noRoi = pl.getParameter("Rno_roi");
			if (noRoi != null || decSpec.rois == null)
			{
				// no_roi specified in commandline!
				return new ROIDeScaler(src, null);
			}
			
			return new ROIDeScaler(src, decSpec.rois);
		}
コード例 #2
0
ファイル: InvWTAdapter.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Instantiates the 'InvWTAdapter' object using the specified
		/// 'MultiResImgData' source. The reconstruction resolution level is set to
		/// full resolution (i.e. the maximum resolution level).
		/// 
		/// </summary>
		/// <param name="src">From where to obtain the values to return
		/// 
		/// </param>
		/// <param name="decSpec">The decoder specifications
		/// 
		/// </param>
		protected internal InvWTAdapter(MultiResImgData src, DecoderSpecs decSpec)
		{
			mressrc = src;
			this.decSpec = decSpec;
			maxImgRes = decSpec.dls.Min;
		}
コード例 #3
0
ファイル: InvCompTransf.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Constructs a new ForwCompTransf object that operates on the
		/// specified source of image data.
		/// 
		/// </summary>
		/// <param name="imgSrc">The source from where to get the data to be
		/// transformed
		/// 
		/// </param>
		/// <param name="decSpec">The decoder specifications
		/// 
		/// </param>
		/// <param name="utdepth">The bit depth of the un-transformed components 
		/// 
		/// </param>
		/// <param name="pl">The command line optinons of the decoder
		/// 
		/// </param>
		/// <seealso cref="BlkImgDataSrc">
		/// 
		/// </seealso>
		public InvCompTransf(BlkImgDataSrc imgSrc, DecoderSpecs decSpec, int[] utdepth, ParameterList pl):base(imgSrc)
		{
			this.cts = decSpec.cts;
			this.wfs = decSpec.wfs;
			src = imgSrc;
			this.utdepth = utdepth;
			noCompTransf = !(pl.getBooleanParameter("comp_transf"));
		}
コード例 #4
0
ファイル: InvWTFull.cs プロジェクト: cureos/csj2k
 //private bool[][] reversible;
 /// <summary> Initializes this object with the given source of wavelet
 /// coefficients. It initializes the resolution level for full resolutioin
 /// reconstruction.
 /// 
 /// </summary>
 /// <param name="src">from where the wavelet coefficinets should be obtained.
 /// 
 /// </param>
 /// <param name="decSpec">The decoder specifications
 /// 
 /// </param>
 public InvWTFull(CBlkWTDataSrcDec src, DecoderSpecs decSpec)
     : base(src, decSpec)
 {
     this.src = src;
     int nc = src.NumComps;
     reconstructedComps = new DataBlk[nc];
     ndl = new int[nc];
 }
コード例 #5
0
ファイル: HeaderDecoder.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Returns the dequantizer parameters. Dequantizer parameters normally are
		/// the quantization step sizes, see DequantizerParams.
		/// 
		/// </summary>
		/// <param name="src">The source of data for the dequantizer.
		/// 
		/// </param>
		/// <param name="rb">The number of range bits for each component. Must be
		/// the number of range bits of the mixed components.
		/// 
		/// </param>
		/// <param name="decSpec2">The DecoderSpecs instance after any image manipulation.
		/// 
		/// </param>
		/// <returns> The dequantizer
		/// 
		/// </returns>
		public Dequantizer createDequantizer(CBlkQuantDataSrcDec src, int[] rb, DecoderSpecs decSpec2)
		{
			return new StdDequantizer(src, rb, decSpec2);
		}
コード例 #6
0
ファイル: HeaderDecoder.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Reads the SIZ marker segment and realigns the codestream at the point
		/// where the next marker segment should be found. 
		/// 
		/// <p>SIZ is a fixed information marker segment containing informations
		/// about image and tile sizes. It is required in the main header
		/// immediately after SOC.</p>
		/// 
		/// </summary>
		/// <param name="ehs">The encoded header stream
		/// 
		/// </param>
		/// <exception cref="IOException">If an I/O error occurs while reading from the
		/// encoded header stream
		/// 
		/// </exception>
		//UPGRADE_TODO: Class 'java.io.DataInputStream' was converted to 'System.IO.BinaryReader' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioDataInputStream'"
		private void  readSIZ(System.IO.BinaryReader ehs)
		{
			HeaderInfo.SIZ ms = hi.NewSIZ;
			hi.sizValue = ms;
			
			// Read the length of SIZ marker segment (Lsiz)
			ms.lsiz = ehs.ReadUInt16();
			
			// Read the capability of the codestream (Rsiz)
			ms.rsiz = ehs.ReadUInt16();
			if (ms.rsiz > 2)
			{
				throw new System.ApplicationException("Codestream capabiities not JPEG 2000 - Part I" + " compliant");
			}
			
			// Read image size
			ms.xsiz = ehs.ReadInt32();
			ms.ysiz = ehs.ReadInt32();
			if (ms.xsiz <= 0 || ms.ysiz <= 0)
			{
				throw new System.IO.IOException("JJ2000 does not support images whose " + "width and/or height not in the " + "range: 1 -- (2^31)-1");
			}
			
			// Read image offset
			ms.x0siz = ehs.ReadInt32();
			ms.y0siz = ehs.ReadInt32();
			if (ms.x0siz < 0 || ms.y0siz < 0)
			{
				throw new System.IO.IOException("JJ2000 does not support images offset " + "not in the range: 0 -- (2^31)-1");
			}
			
			// Read size of tile
			ms.xtsiz = ehs.ReadInt32();
			ms.ytsiz = ehs.ReadInt32();
			if (ms.xtsiz <= 0 || ms.ytsiz <= 0)
			{
				throw new System.IO.IOException("JJ2000 does not support tiles whose " + "width and/or height are not in  " + "the range: 1 -- (2^31)-1");
			}
			
			// Read upper-left tile offset
			ms.xt0siz = ehs.ReadInt32();
			ms.yt0siz = ehs.ReadInt32();
			if (ms.xt0siz < 0 || ms.yt0siz < 0)
			{
				throw new System.IO.IOException("JJ2000 does not support tiles whose " + "offset is not in  " + "the range: 0 -- (2^31)-1");
			}
			
			// Read number of components and initialize related arrays
			nComp = ms.csiz = ehs.ReadUInt16();
			if (nComp < 1 || nComp > 16384)
			{
				throw new System.ArgumentException("Number of component out of " + "range 1--16384: " + nComp);
			}
			
			ms.ssiz = new int[nComp];
			ms.xrsiz = new int[nComp];
			ms.yrsiz = new int[nComp];
			
			// Read bit-depth and down-sampling factors of each component
			for (int i = 0; i < nComp; i++)
			{
				ms.ssiz[i] = ehs.ReadByte();
				ms.xrsiz[i] = ehs.ReadByte();
				ms.yrsiz[i] = ehs.ReadByte();
			}
			
			// Check marker length
			checkMarkerLength(ehs, "SIZ marker");
			
			// Create needed ModuleSpec
			nTiles = ms.NumTiles;
			
			// Finish initialization of decSpec
			decSpec = new DecoderSpecs(nTiles, nComp);
		}
コード例 #7
0
ファイル: PktDecoder.cs プロジェクト: RavenB/gridsearch
		/// <summary> Creates an empty PktDecoder object associated with given decoder
		/// specifications and HeaderDecoder. This object must be initialized
		/// thanks to the restart method before being used.
		/// 
		/// </summary>
		/// <param name="decSpec">The decoder specifications.
		/// 
		/// </param>
		/// <param name="hd">The HeaderDecoder instance.
		/// 
		/// </param>
		/// <param name="ehs">The stream where to read data from.
		/// 
		/// </param>
		/// <param name="src">The bit stream reader agent.
		/// 
		/// </param>
		/// <param name="isTruncMode">Whether or not truncation mode is required.
		/// 
		/// </param>
		/// <param name="maxCB">The maximum number of code-blocks to read before ncbquit
		/// 
		/// 
		/// </param>
		public PktDecoder(DecoderSpecs decSpec, HeaderDecoder hd, RandomAccessIO ehs, BitstreamReaderAgent src, bool isTruncMode, int maxCB)
		{
			this.decSpec = decSpec;
			this.hd = hd;
			this.ehs = ehs;
			this.isTruncMode = isTruncMode;
			bin = new PktHeaderBitReader(ehs);
			this.src = src;
			ncb = 0;
			ncbQuit = false;
			this.maxCB = maxCB;
		}
コード例 #8
0
		/// <summary> Initializes the source of compressed data. And sets the number of range
		/// bits and fraction bits and receives the parameters for the dequantizer.
		/// 
		/// </summary>
		/// <param name="src">From where to obtain the quantized data.
		/// 
		/// </param>
		/// <param name="rb">The number of "range bits" (bitdepth) for each component
		/// (must be the "range bits" of the un-transformed components). For a
		/// definition of "range bits" see the getNomRangeBits() method.
		/// 
		/// </param>
		/// <param name="qts">The quantizer type spec
		/// 
		/// </param>
		/// <param name="qsss">The dequantizer step sizes spec
		/// 
		/// </param>
		/// <seealso cref="Dequantizer.getNomRangeBits">
		/// 
		/// </seealso>
		/// <exception cref="IllegalArgumentException">Thrown if 'outdt' is neither
		/// TYPE_FLOAT nor TYPE_INT, or if 'param' specify reversible quantization
		/// and 'outdt' is not TYPE_INT or 'fp' has non-zero values, or if 'outdt'
		/// is TYPE_FLOAT and 'fp' has non-zero values.
		/// 
		/// </exception>
		public StdDequantizer(CBlkQuantDataSrcDec src, int[] utrb, DecoderSpecs decSpec):base(src, utrb, decSpec)
		{
			
			if (utrb.Length != src.NumComps)
			{
				throw new System.ArgumentException("Invalid rb argument");
			}
			this.qsss = decSpec.qsss;
			this.qts = decSpec.qts;
			this.gbs = decSpec.gbs;
		}
コード例 #9
0
		/// <summary> Initializes members of this class. This constructor takes a
		/// HeaderDecoder object. This object must be initialized by the
		/// constructor of the implementing class from the header of the bit
		/// stream.
		/// 
		/// </summary>
		/// <param name="hd">The decoded header of the bit stream from where to initialize
		/// the values.
		/// 
		/// </param>
		/// <param name="decSpec">The decoder specifications
		/// 
		/// </param>
		protected internal BitstreamReaderAgent(HeaderDecoder hd, DecoderSpecs decSpec)
		{
			Coord co;
			//int i, j, max;
			
			this.decSpec = decSpec;
			this.hd = hd;
			
			// Number of components
			nc = hd.NumComps;
			offX = new int[nc];
			offY = new int[nc];
			culx = new int[nc];
			culy = new int[nc];
			
			// Image size and origin
			imgW = hd.ImgWidth;
			imgH = hd.ImgHeight;
			ax = hd.ImgULX;
			ay = hd.ImgULY;
			
			// Tiles
			co = hd.getTilingOrigin(null);
			px = co.x;
			py = co.y;
			ntW = hd.NomTileWidth;
			ntH = hd.NomTileHeight;
			ntX = (ax + imgW - px + ntW - 1) / ntW;
			ntY = (ay + imgH - py + ntH - 1) / ntH;
			nt = ntX * ntY;
		}
コード例 #10
0
		/// <summary> Instantiates a new entropy decoder engine, with the specified source of
		/// data, nominal block width and height.
		/// 
		/// </summary>
		/// <param name="src">The source of data
		/// 
		/// </param>
		/// <param name="opt">The options to use for this encoder. It is a mix of the
		/// 'OPT_TERM_PASS', 'OPT_RESET_MQ', 'OPT_VERT_STR_CAUSAL', 'OPT_BYPASS'
		/// and 'OPT_SEG_SYMBOLS' option flags.
		/// 
		/// </param>
		/// <param name="doer">If true error detection will be performed, if any error
		/// detection features have been enabled.
		/// 
		/// </param>
		/// <param name="verber">This flag indicates if the entropy decoder should be
		/// verbose about bit stream errors that are detected and concealed.
		/// 
		/// </param>
		/// <param name="mQuit">the maximum number of bit planes to decode according to
		/// the m quit condition
		/// 
		/// </param>
		public StdEntropyDecoder(CodedCBlkDataSrcDec src, DecoderSpecs decSpec, bool doer, bool verber, int mQuit):base(src)
		{
			
			this.decSpec = decSpec;
			this.doer = doer;
			this.verber = verber;
			this.mQuit = mQuit;
			
			// If we do timing create necessary structures
#if DO_TIMING
			time = new long[src.NumComps];
			// If we are timing make sure that 'finalize' gets called.
			//UPGRADE_ISSUE: Method 'java.lang.System.runFinalizersOnExit' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javalangSystem'"
            // CONVERSION PROBLEM?
			//System_Renamed.runFinalizersOnExit(true);
#endif
			
			// Initialize internal variables
			state = new int[(decSpec.cblks.MaxCBlkWidth + 2) * ((decSpec.cblks.MaxCBlkHeight + 1) / 2 + 2)];
		}
コード例 #11
0
		/// <summary> Creates a bit stream reader of the correct type that works on the
		/// provided RandomAccessIO, with the special parameters from the parameter
		/// list.
		/// 
		/// </summary>
		/// <param name="in">The RandomAccessIO source from which to read the bit stream.
		/// 
		/// </param>
		/// <param name="hd">Header of the codestream.
		/// 
		/// </param>
		/// <param name="pl">The parameter list containing parameters applicable to the
		/// bit stream read (other parameters may also be present).
		/// 
		/// </param>
		/// <param name="decSpec">The decoder specifications
		/// 
		/// </param>
		/// <param name="cdstrInfo">Whether or not to print information found in
		/// codestream. 
		/// 
		/// </param>
		/// <param name="hi">Reference to the HeaderInfo instance.
		/// 
		/// </param>
		/// <exception cref="IOException">If an I/O error occurs while reading initial
		/// data from the bit stream.
		/// </exception>
		/// <exception cref="IllegalArgumentException">If an unrecognised bit stream
		/// reader option is present.
		/// 
		/// </exception>
		public static BitstreamReaderAgent createInstance(RandomAccessIO in_Renamed, HeaderDecoder hd, ParameterList pl, DecoderSpecs decSpec, bool cdstrInfo, HeaderInfo hi)
		{
			
			// Check parameters
			pl.checkList(BitstreamReaderAgent.OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(BitstreamReaderAgent.ParameterInfo));
			
			return new FileBitstreamReaderAgent(hd, in_Renamed, decSpec, pl, cdstrInfo, hi);
		}
コード例 #12
0
ファイル: InverseWT.cs プロジェクト: cureos/csj2k
 /// <summary> Initializes this object with the given source of wavelet
 /// coefficients. It initializes the resolution level for full resolutioin
 /// reconstruction (i.e. the maximum resolution available from the 'src'
 /// source).
 /// 
 /// <p>It is assumed here that all tiles and components have the same
 /// reconstruction resolution level. If that was not the case it should be
 /// the value for the current tile of the source.</p>
 /// 
 /// </summary>
 /// <param name="src">from where the wavelet coefficinets should be obtained.
 /// 
 /// </param>
 /// <param name="decSpec">The decoder specifications
 /// 
 /// </param>
 public InverseWT(MultiResImgData src, DecoderSpecs decSpec)
     : base(src, decSpec)
 {
 }
コード例 #13
0
ファイル: InverseWT.cs プロジェクト: cureos/csj2k
 /// <summary> Creates an InverseWT object that works on the data type of the source,
 /// with the special additional parameters from the parameter
 /// list. Currently the parameter list is ignored since no special
 /// parameters can be specified for the inverse wavelet transform yet.
 /// 
 /// </summary>
 /// <param name="src">The source of data for the inverse wavelet
 /// transform.
 /// 
 /// </param>
 /// <param name="pl">The parameter list containing parameters applicable to the
 /// inverse wavelet transform (other parameters can also be present).
 /// 
 /// </param>
 public static InverseWT createInstance(CBlkWTDataSrcDec src, DecoderSpecs decSpec)
 {
     // full page wavelet transform
     return new InvWTFull(src, decSpec);
 }
コード例 #14
0
ファイル: Dequantizer.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Initializes the source of compressed data.
		/// 
		/// </summary>
		/// <param name="src">From where to obtain the quantized data.
		/// 
		/// </param>
		/// <param name="rb">The number of "range bits" for each component (must be the
		/// "range bits" of the un-transformed components. For a definition of
		/// "range bits" see the getNomRangeBits() method.
		/// 
		/// </param>
		/// <seealso cref="getNomRangeBits">
		/// 
		/// </seealso>
		public Dequantizer(CBlkQuantDataSrcDec src, int[] utrb, DecoderSpecs decSpec):base(src)
		{
			if (utrb.Length != src.NumComps)
			{
				throw new System.ArgumentException();
			}
			this.src = src;
			this.utrb = utrb;
			this.cts = decSpec.cts;
			this.wfs = decSpec.wfs;
		}
コード例 #15
0
ファイル: HeaderDecoder.cs プロジェクト: KSLcom/Aurora-LibOMV
		/// <summary> Creates and returns the ROIDeScaler corresponding to the information
		/// read from the codestream header and with the special additional
		/// parameters from the parameter list.
		/// 
		/// </summary>
		/// <param name="src">The bit stream reader agent where to get code-block data
		/// from.
		/// 
		/// </param>
		/// <param name="pl">The parameter list containing parameters applicable to the
		/// entropy decoder (other parameters can also be present).
		/// 
		/// </param>
		/// <param name="decSpec2">The DecoderSpecs instance after any image manipulation.
		/// 
		/// </param>
		/// <returns> The ROI descaler.
		/// 
		/// </returns>
		public virtual ROIDeScaler createROIDeScaler(CBlkQuantDataSrcDec src, ParameterList pl, DecoderSpecs decSpec2)
		{
			return ROIDeScaler.createInstance(src, pl, decSpec2);
		}
コード例 #16
0
		/// <summary> Reads all tiles headers and keep offset of their first
		/// packet. Finally it calls the rate allocation method.
		/// 
		/// </summary>
		/// <param name="hd">HeaderDecoder of the codestream.
		/// 
		/// </param>
		/// <param name="ehs">The input stream where to read bit-stream.
		/// 
		/// </param>
		/// <param name="decSpec">The decoder specifications 
		/// 
		/// </param>
		/// <param name="pl">The ParameterList instance created from the
		/// command-line arguments.
		/// 
		/// </param>
		/// <param name="cdstrInfo">Whether or not to print information found in
		/// codestream. 
		/// 
		/// </param>
		/// <seealso cref="allocateRate">
		/// 
		/// </seealso>
		public FileBitstreamReaderAgent(HeaderDecoder hd, RandomAccessIO ehs, DecoderSpecs decSpec, ParameterList pl, bool cdstrInfo, HeaderInfo hi):base(hd, decSpec)
		{
			
			this.pl = pl;
			this.printInfo = cdstrInfo;
			this.hi = hi;
			
			// Check whether quit conditiosn used
			usePOCQuit = pl.getBooleanParameter("poc_quit");
			
			// Get decoding rate
			bool rateInBytes;
			bool parsing = pl.getBooleanParameter("parsing");
			try
			{
				trate = pl.getFloatParameter("rate");
				if (trate == - 1)
				{
					trate = System.Single.MaxValue;
				}
			}
			catch (System.FormatException)
			{
				throw new System.ApplicationException("Invalid value in 'rate' option: " + pl.getParameter("rate"));
			}
			catch (System.ArgumentException)
			{
				throw new System.ApplicationException("'rate' option is missing");
			}
			
			try
			{
				tnbytes = pl.getIntParameter("nbytes");
			}
			catch (System.FormatException)
			{
				throw new System.ApplicationException("Invalid value in 'nbytes' option: " + pl.getParameter("nbytes"));
			}
			catch (System.ArgumentException)
			{
				throw new System.ApplicationException("'nbytes' option is missing");
			}
			
			// Check that '-rate' and '-nbytes' are not used at the same time
			ParameterList defaults = pl.DefaultParameterList;
			if (tnbytes != defaults.getFloatParameter("nbytes"))
			{
				rateInBytes = true;
			}
			else
			{
				rateInBytes = false;
			}
			
			if (rateInBytes)
			{
				trate = tnbytes * 8f / hd.MaxCompImgWidth / hd.MaxCompImgHeight;
			}
			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'"
				tnbytes = (int) (trate * hd.MaxCompImgWidth * hd.MaxCompImgHeight) / 8;
                if (tnbytes < 0) tnbytes = int.MaxValue;
			}
			isTruncMode = !pl.getBooleanParameter("parsing");
			
			// Check if quit conditions are being used
			int ncbQuit;
			try
			{
				ncbQuit = pl.getIntParameter("ncb_quit");
			}
			catch (System.FormatException)
			{
				throw new System.ApplicationException("Invalid value in 'ncb_quit' option: " + pl.getParameter("ncb_quit"));
			}
			catch (System.ArgumentException)
			{
				throw new System.ApplicationException("'ncb_quit' option is missing");
			}
			if (ncbQuit != - 1 && !isTruncMode)
			{
				throw new System.ApplicationException("Cannot use -parsing and -ncb_quit condition at " + "the same time.");
			}
			
			try
			{
				lQuit = pl.getIntParameter("l_quit");
			}
			catch (System.FormatException)
			{
				throw new System.ApplicationException("Invalid value in 'l_quit' option: " + pl.getParameter("l_quit"));
			}
			catch (System.ArgumentException)
			{
				throw new System.ApplicationException("'l_quit' option is missing");
			}
			
			// initializations
			in_Renamed = ehs;
			pktDec = new PktDecoder(decSpec, hd, ehs, this, isTruncMode, ncbQuit);
			
			tileParts = new int[nt];
			totTileLen = new int[nt];
			tilePartLen = new int[nt][];
			tilePartNum = new int[nt][];
			firstPackOff = new int[nt][];
			tilePartsRead = new int[nt];
			totTileHeadLen = new int[nt];
			tilePartHeadLen = new int[nt][];
			nBytes = new int[nt];
			baknBytes = new int[nt];
			hd.nTileParts = new int[nt];
			
            // CONVERSION PROBLEM?
			//this.isTruncMode = isTruncMode;
			int t = 0, pos, tp = 0, tptot = 0;
			
			// Keeps main header's length, takes file format overhead into account
			int cdstreamStart = hd.mainHeadOff; // Codestream offset in the file
			mainHeadLen = in_Renamed.Pos - cdstreamStart;
			headLen = mainHeadLen;
			
			// If ncb and lbody quit conditions are used, headers are not counted
			if (ncbQuit == - 1)
			{
				anbytes = mainHeadLen;
			}
			else
			{
				anbytes = 0;
			}
			
			// If cannot even read the first tile-part
			if (anbytes > tnbytes)
			{
				throw new System.ApplicationException("Requested bitrate is too small.");
			}
			
			// Read all tile-part headers from all tiles.
			int tilePartStart;
			bool rateReached = false;
			int mdl;
			//int numtp = 0;
			totAllTileLen = 0;
			remainingTileParts = nt; // at least as many tile-parts as tiles
			int maxTP = nt; // If maximum 1 tile part per tile specified
			
			try
			{
				while (remainingTileParts != 0)
				{
					
					tilePartStart = in_Renamed.Pos;
					// Read tile-part header
					try
					{
						t = readTilePartHeader();
						if (isEOCFound)
						{
							// Some tiles are missing but the
							// codestream is OK
							break;
						}
						tp = tilePartsRead[t];
						if (isPsotEqualsZero)
						{
							// Psot may equals zero for the
							// last tile-part: it is assumed that this tile-part
							// contain all data until EOC
							tilePartLen[t][tp] = in_Renamed.length() - 2 - tilePartStart;
						}
					}
					catch (System.IO.EndOfStreamException e)
					{
						firstPackOff[t][tp] = in_Renamed.length();
						throw e;
					}
					
					pos = in_Renamed.Pos;
					
					// In truncation mode, if target decoding rate is reached in
					// tile-part header, skips the tile-part and stop reading
					// unless the ncb and lbody quit condition is in use
					if (isTruncMode && ncbQuit == - 1)
					{
						if ((pos - cdstreamStart) > tnbytes)
						{
							firstPackOff[t][tp] = in_Renamed.length();
							rateReached = true;
							break;
						}
					}
					
					// Set tile part position and header length
					firstPackOff[t][tp] = pos;
					tilePartHeadLen[t][tp] = (pos - tilePartStart);
					
					// Update length counters
					totTileLen[t] += tilePartLen[t][tp];
					totTileHeadLen[t] += tilePartHeadLen[t][tp];
					totAllTileLen += tilePartLen[t][tp];
					if (isTruncMode)
					{
						if (anbytes + tilePartLen[t][tp] > tnbytes)
						{
							anbytes += tilePartHeadLen[t][tp];
							headLen += tilePartHeadLen[t][tp];
							rateReached = true;
							nBytes[t] += (tnbytes - anbytes);
							break;
						}
						else
						{
							anbytes += tilePartHeadLen[t][tp];
							headLen += tilePartHeadLen[t][tp];
							nBytes[t] += (tilePartLen[t][tp] - tilePartHeadLen[t][tp]);
						}
					}
					else
					{
						if (anbytes + tilePartHeadLen[t][tp] > tnbytes)
						{
							break;
						}
						else
						{
							anbytes += tilePartHeadLen[t][tp];
							headLen += tilePartHeadLen[t][tp];
						}
					}
					
					// If this is first tile-part, remember header length
					if (tptot == 0)
						firstTilePartHeadLen = tilePartHeadLen[t][tp];
					
					// Go to the beginning of next tile part
					tilePartsRead[t]++;
					in_Renamed.seek(tilePartStart + tilePartLen[t][tp]);
					remainingTileParts--;
					maxTP--;
					tptot++;
					
					// If Psot of the current tile-part was equal to zero, it is
					// assumed that it contains all data until the EOC marker
					if (isPsotEqualsZero)
					{
						if (remainingTileParts != 0)
						{
							FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Some tile-parts have not " + "been found. The codestream may be corrupted.");
						}
						break;
					}
				}
			}
			catch (System.IO.EndOfStreamException)
			{
				if (printInfo)
				{
				}
				FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Codestream truncated in tile " + t);
				
				// Set specified rate to end of file if valid
				int fileLen = in_Renamed.length();
				if (fileLen < tnbytes)
				{
					tnbytes = fileLen;
					trate = tnbytes * 8f / hd.MaxCompImgWidth / hd.MaxCompImgHeight;
				}
				
				// Bit-rate allocation
				if (!isTruncMode)
				{
					allocateRate();
				}
				
				// Update 'res' value once all tile-part headers are read
				if (pl.getParameter("res") == null)
				{
					targetRes = decSpec.dls.Min;
				}
				else
				{
					try
					{
						targetRes = pl.getIntParameter("res");
						if (targetRes < 0)
						{
							throw new System.ArgumentException("Specified negative " + "resolution level " + "index: " + targetRes);
						}
					}
					catch (System.FormatException)
					{
						throw new System.ArgumentException("Invalid resolution level " + "index ('-res' option) " + pl.getParameter("res"));
					}
				}
				
				// Verify reduction in resolution level
				mdl = decSpec.dls.Min;
				if (targetRes > mdl)
				{
					FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Specified resolution level (" + targetRes + ") is larger" + " than the maximum value. Setting it to " + mdl + " (maximum value)");
					targetRes = mdl;
				}
				
				// Backup nBytes
				for (int tIdx = 0; tIdx < nt; tIdx++)
				{
					baknBytes[tIdx] = nBytes[tIdx];
				}
				
				return ;
			}
			remainingTileParts = 0;
			
			// Update 'res' value once all tile-part headers are read
			if (pl.getParameter("res") == null)
			{
				targetRes = decSpec.dls.Min;
			}
			else
			{
				try
				{
					targetRes = pl.getIntParameter("res");
					if (targetRes < 0)
					{
						throw new System.ArgumentException("Specified negative " + "resolution level index: " + targetRes);
					}
				}
				catch (System.FormatException)
				{
					throw new System.ArgumentException("Invalid resolution level " + "index ('-res' option) " + pl.getParameter("res"));
				}
			}
			
			// Verify reduction in resolution level
			mdl = decSpec.dls.Min;
			if (targetRes > mdl)
			{
				FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "Specified resolution level (" + targetRes + ") is larger" + " than the maximum possible. Setting it to " + mdl + " (maximum possible)");
				targetRes = mdl;
			}
			
			if (printInfo)
			{
			}
			
			// Check presence of EOC marker is decoding rate not reached or if
			// this marker has not been found yet
			if (!isEOCFound && !isPsotEqualsZero)
			{
				try
				{
                    short eocCheck = 0;
                    if (in_Renamed.Pos + sizeof(short) <= in_Renamed.length())
                        eocCheck = in_Renamed.readShort();

					if (!rateReached && !isPsotEqualsZero && eocCheck != CSJ2K.j2k.codestream.Markers.EOC)
					{
						FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "EOC marker not found. " + "Codestream is corrupted.");
					}
				}
				catch (System.IO.EndOfStreamException)
				{
					FacilityManager.getMsgLogger().printmsg(CSJ2K.j2k.util.MsgLogger_Fields.WARNING, "EOC marker is missing");
				}
			}
			
			// Bit-rate allocation
			if (!isTruncMode)
			{
				allocateRate();
			}
			else
			{
				// Take EOC into account if rate is not reached
				if (in_Renamed.Pos >= tnbytes)
					anbytes += 2;
			}
			
			// Backup nBytes
			for (int tIdx = 0; tIdx < nt; tIdx++)
			{
				baknBytes[tIdx] = nBytes[tIdx];
				if (printInfo)
				{
					FacilityManager.getMsgLogger().println("" + hi.toStringTileHeader(tIdx, tilePartLen[tIdx].Length), 2, 2);
				}
			}
		}
コード例 #17
0
ファイル: InvWTFull.cs プロジェクト: KSLcom/Aurora-LibOMV
		//private bool[][] reversible;
		
		/// <summary> Initializes this object with the given source of wavelet
		/// coefficients. It initializes the resolution level for full resolutioin
		/// reconstruction.
		/// 
		/// </summary>
		/// <param name="src">from where the wavelet coefficinets should be obtained.
		/// 
		/// </param>
		/// <param name="decSpec">The decoder specifications
		/// 
		/// </param>
		public InvWTFull(CBlkWTDataSrcDec src, DecoderSpecs decSpec):base(src, decSpec)
		{
			this.src = src;
			int nc = src.NumComps;
			reconstructedComps = new DataBlk[nc];
			ndl = new int[nc];
			pw = FacilityManager.ProgressWatch;
		}