Пример #1
0
        /// <summary> Creates a PostCompRateAllocator object for the appropriate rate
        /// allocation parameters in the parameter list 'pl', having 'src' as the
        /// source of entropy coded data, 'rate' as the target bitrate and 'bw' as
        /// the bit stream writer object.
        ///
        /// </summary>
        /// <param name="src">The source of entropy coded data.
        ///
        /// </param>
        /// <param name="pl">The parameter lis (or options).
        ///
        /// </param>
        /// <param name="rate">The target bitrate for the rate allocation
        ///
        /// </param>
        /// <param name="bw">The bit stream writer object, where the bit stream data will
        /// be written.
        ///
        /// </param>
        public static PostCompRateAllocator createInstance(CodedCBlkDataSrcEnc src, ParameterList pl, float rate, CodestreamWriter bw, EncoderSpecs encSpec)
        {
            // Check parameters
            pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));

            // Construct the layer specification from the 'Alayers' option
            LayersInfo lyrs = parseAlayers(pl.getParameter("Alayers"), rate);

            int nTiles    = encSpec.nTiles;
            int nComp     = encSpec.nComp;
            int numLayers = lyrs.TotNumLayers;

            // Parse the progressive type
            encSpec.pocs = new ProgressionSpec(nTiles, nComp, numLayers, encSpec.dls, ModuleSpec.SPEC_TYPE_TILE_COMP, pl);

            return(new EBCOTRateAllocator(src, lyrs, bw, encSpec, pl));
        }
Пример #2
0
        /// <summary> Convenience method that parses the 'Alayers' option.
        ///
        /// </summary>
        /// <param name="params">The parameters of the 'Alayers' option
        ///
        /// </param>
        /// <param name="rate">The overall target bitrate
        ///
        /// </param>
        /// <returns> The layer specification.
        ///
        /// </returns>
        private static LayersInfo parseAlayers(System.String params_Renamed, float rate)
        {
            LayersInfo lyrs;

            SupportClass.StreamTokenizerSupport stok;
            bool  islayer, ratepending;
            float r;

            lyrs = new LayersInfo(rate);
            stok = new SupportClass.StreamTokenizerSupport(new System.IO.StringReader(params_Renamed));
            stok.EOLIsSignificant(false);

            try
            {
                stok.NextToken();
            }
            catch (System.IO.IOException e)
            {
                throw new System.InvalidOperationException("An IOException has ocurred where it " + "should never occur");
            }
            ratepending = false;
            islayer     = false;
            r           = 0;   // to keep compiler happy
            while (stok.ttype != SupportClass.StreamTokenizerSupport.TT_EOF)
            {
                switch (stok.ttype)
                {
                case SupportClass.StreamTokenizerSupport.TT_NUMBER:
                    if (islayer)
                    {
                        // layer parameter
                        try
                        {
                            //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'"
                            lyrs.addOptPoint(r, (int)stok.nval);
                        }
                        catch (System.ArgumentException e)
                        {
                            //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                            throw new System.ArgumentException("Error in 'Alayers' " + "option: " + e.Message);
                        }
                        ratepending = false;
                        islayer     = false;
                    }
                    else
                    {
                        // rate parameter
                        if (ratepending)
                        {
                            // Add pending rate parameter
                            try
                            {
                                lyrs.addOptPoint(r, 0);
                            }
                            catch (System.ArgumentException e)
                            {
                                //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                                throw new System.ArgumentException("Error in 'Alayers' " + "option: " + e.Message);
                            }
                        }
                        // Now store new rate parameter
                        //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'"
                        r           = (float)stok.nval;
                        ratepending = true;
                    }
                    break;

                case '+':
                    if (!ratepending || islayer)
                    {
                        throw new System.ArgumentException("Layer parameter without " + "previous rate parameter " + "in 'Alayers' option");
                    }
                    islayer = true;                             // Next number is layer parameter
                    break;

                case SupportClass.StreamTokenizerSupport.TT_WORD:
                    try
                    {
                        stok.NextToken();
                    }
                    catch (System.IO.IOException e)
                    {
                        throw new System.InvalidOperationException("An IOException has ocurred where it " + "should never occur");
                    }
                    if (stok.ttype != SupportClass.StreamTokenizerSupport.TT_EOF)
                    {
                        throw new System.ArgumentException("'sl' argument of " + "'-Alayers' option must be " + "used alone.");
                    }
                    break;

                default:
                    throw new System.ArgumentException("Error parsing 'Alayers' " + "option");
                }
                try
                {
                    stok.NextToken();
                }
                catch (System.IO.IOException e)
                {
                    throw new System.InvalidOperationException("An IOException has ocurred where it " + "should never occur");
                }
            }
            if (islayer)
            {
                throw new System.ArgumentException("Error parsing 'Alayers' " + "option");
            }
            if (ratepending)
            {
                try
                {
                    lyrs.addOptPoint(r, 0);
                }
                catch (System.ArgumentException e)
                {
                    //UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
                    throw new System.ArgumentException("Error in 'Alayers' " + "option: " + e.Message);
                }
            }
            return(lyrs);
        }
Пример #3
0
        /// <summary> Initializes the EBCOT rate allocator of entropy coded data. The layout
        /// of layers, and their bitrate constraints, is specified by the 'lyrs'
        /// parameter.
        /// 
        /// </summary>
        /// <param name="src">The source of entropy coded data.
        /// 
        /// </param>
        /// <param name="lyrs">The layers layout specification.
        /// 
        /// </param>
        /// <param name="writer">The bit stream writer.
        /// 
        /// </param>
        /// <seealso cref="ProgressionType">
        /// 
        /// </seealso>
        public EBCOTRateAllocator(CodedCBlkDataSrcEnc src, LayersInfo lyrs, CodestreamWriter writer, EncoderSpecs encSpec, ParameterList pl)
            : base(src, lyrs.TotNumLayers, writer, encSpec)
        {
            int minsbi, maxsbi;
            int i;
            SubbandAn sb, sb2;
            Coord ncblks = null;

            // If we do timing create necessary structures
            #if DO_TIMING
            // 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);
            // The System.runFinalizersOnExit() method is deprecated in Java
            // 1.2 since it can cause a deadlock in some cases. However, here
            // we use it only for profiling purposes and is disabled in
            // production code.
            initTime = 0L;
            buildTime = 0L;
            writeTime = 0L;
            #endif

            // Save the layer specs
            lyrSpec = lyrs;

            //Initialize the size of the RD slope rates array
            RDSlopesRates = new int[RD_SUMMARY_SIZE];

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

            //Allocate the coded code-blocks and truncation points indexes arrays
            cblks = new CBlkRateDistStats[nt][][][][];
            for (int i2 = 0; i2 < nt; i2++)
            {
                cblks[i2] = new CBlkRateDistStats[nc][][][];
            }
            truncIdxs = new int[nt][][][][][];
            for (int i3 = 0; i3 < nt; i3++)
            {
                truncIdxs[i3] = new int[num_Layers][][][][];
                for (int i4 = 0; i4 < num_Layers; i4++)
                {
                    truncIdxs[i3][i4] = new int[nc][][][];
                }
            }

            int cblkPerSubband; // Number of code-blocks per subband
            int mrl; // Number of resolution levels
            int l; // layer index
            int s; //subband index

            // Used to compute the maximum number of precincts for each resolution
            // level
            int tx0, ty0, tx1, ty1; // Current tile position in the reference grid
            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
            Coord tileI = null;
            Coord nTiles = null;
            int xsiz, ysiz, x0siz, y0siz;
            int xt0siz, yt0siz;
            int xtsiz, ytsiz;

            int cb0x = src.CbULX;
            int cb0y = src.CbULY;

            src.setTile(0, 0);
            for (int t = 0; t < nt; t++)
            {
                // Loop on tiles
                nTiles = src.getNumTiles(nTiles);
                tileI = src.getTile(tileI);
                x0siz = ImgULX;
                y0siz = ImgULY;
                xsiz = x0siz + ImgWidth;
                ysiz = y0siz + ImgHeight;
                xt0siz = src.TilePartULX;
                yt0siz = src.TilePartULY;
                xtsiz = src.NomTileWidth;
                ytsiz = src.NomTileHeight;

                // Tile's coordinates on the reference grid
                tx0 = (tileI.x == 0)?x0siz:xt0siz + tileI.x * xtsiz;
                ty0 = (tileI.y == 0)?y0siz:yt0siz + tileI.y * ytsiz;
                tx1 = (tileI.x != nTiles.x - 1)?xt0siz + (tileI.x + 1) * xtsiz:xsiz;
                ty1 = (tileI.y != nTiles.y - 1)?yt0siz + (tileI.y + 1) * ytsiz:ysiz;

                for (int c = 0; c < nc; c++)
                {
                    // loop on components

                    //Get the number of resolution levels
                    sb = src.getAnSubbandTree(t, c);
                    mrl = sb.resLvl + 1;

                    // Initialize maximum number of precincts per resolution array
                    if (numPrec == null)
                    {
                        Coord[][][] tmpArray = new Coord[nt][][];
                        for (int i5 = 0; i5 < nt; i5++)
                        {
                            tmpArray[i5] = new Coord[nc][];
                        }
                        numPrec = tmpArray;
                    }
                    if (numPrec[t][c] == null)
                    {
                        numPrec[t][c] = new Coord[mrl];
                    }

                    // Subsampling factors
                    xrsiz = src.getCompSubsX(c);
                    yrsiz = src.getCompSubsY(c);

                    // Tile's coordinates in the image component 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'"
                    tcx0 = (int) System.Math.Ceiling(tx0 / (double) (xrsiz));
                    //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'"
                    tcy0 = (int) System.Math.Ceiling(ty0 / (double) (yrsiz));
                    //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'"
                    tcx1 = (int) System.Math.Ceiling(tx1 / (double) (xrsiz));
                    //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'"
                    tcy1 = (int) System.Math.Ceiling(ty1 / (double) (yrsiz));

                    cblks[t][c] = new CBlkRateDistStats[mrl][][];

                    for (l = 0; l < num_Layers; l++)
                    {
                        truncIdxs[t][l][c] = new int[mrl][][];
                    }

                    for (int r = 0; r < mrl; r++)
                    {
                        // loop on resolution levels

                        // 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 << (mrl - 1 - 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 << (mrl - 1 - 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 << (mrl - 1 - 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 << (mrl - 1 - r)));

                        // Calculate the maximum number of precincts for each
                        // resolution level taking into account tile specific
                        // options.
                        double twoppx = (double) encSpec.pss.getPPX(t, c, r);
                        double twoppy = (double) encSpec.pss.getPPY(t, c, r);
                        numPrec[t][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[t][c][r].x = (int) System.Math.Ceiling((trx1 - cb0x) / twoppx) - (int) System.Math.Floor((trx0 - cb0x) / twoppx);
                        }
                        else
                        {
                            numPrec[t][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[t][c][r].y = (int) System.Math.Ceiling((try1 - cb0y) / twoppy) - (int) System.Math.Floor((try0 - cb0y) / (double) twoppy);
                        }
                        else
                        {
                            numPrec[t][c][r].y = 0;
                        }

                        minsbi = (r == 0)?0:1;
                        maxsbi = (r == 0)?1:4;

                        cblks[t][c][r] = new CBlkRateDistStats[maxsbi][];
                        for (l = 0; l < num_Layers; l++)
                        {
                            truncIdxs[t][l][c][r] = new int[maxsbi][];
                        }

                        for (s = minsbi; s < maxsbi; s++)
                        {
                            // loop on subbands
                            //Get the number of blocks in the current subband
                            sb2 = (SubbandAn) sb.getSubbandByIdx(r, s);
                            ncblks = sb2.numCb;
                            cblkPerSubband = ncblks.x * ncblks.y;
                            cblks[t][c][r][s] = new CBlkRateDistStats[cblkPerSubband];

                            for (l = 0; l < num_Layers; l++)
                            {
                                truncIdxs[t][l][c][r][s] = new int[cblkPerSubband];
                                for (i = 0; i < cblkPerSubband; i++)
                                {
                                    truncIdxs[t][l][c][r][s][i] = - 1;
                                }
                            }
                        } // End loop on subbands
                    } // End lopp on resolution levels
                } // End loop on components
                if (t != nt - 1)
                {
                    src.nextTile();
                }
            } // End loop on tiles

            //Initialize the packet encoder
            pktEnc = new PktEncoder(src, encSpec, numPrec, pl);

            // The layers array has to be initialized after the constructor since
            // it is needed that the bit stream header has been entirely written
        }
Пример #4
0
		/// <summary> Convenience method that parses the 'Alayers' option.
		/// 
		/// </summary>
		/// <param name="params">The parameters of the 'Alayers' option
		/// 
		/// </param>
		/// <param name="rate">The overall target bitrate
		/// 
		/// </param>
		/// <returns> The layer specification.
		/// 
		/// </returns>
		private static LayersInfo parseAlayers(System.String params_Renamed, float rate)
		{
			LayersInfo lyrs;
			SupportClass.StreamTokenizerSupport stok;
			bool islayer, ratepending;
			float r;
			
			lyrs = new LayersInfo(rate);
			stok = new SupportClass.StreamTokenizerSupport(new System.IO.StringReader(params_Renamed));
			stok.EOLIsSignificant(false);
			
			try
			{
				stok.NextToken();
			}
			catch (System.IO.IOException)
			{
				throw new System.ApplicationException("An IOException has ocurred where it " + "should never occur");
			}
			ratepending = false;
			islayer = false;
			r = 0; // to keep compiler happy
			while (stok.ttype != SupportClass.StreamTokenizerSupport.TT_EOF)
			{
				switch (stok.ttype)
				{
					
					case SupportClass.StreamTokenizerSupport.TT_NUMBER: 
						if (islayer)
						{
							// layer parameter
							try
							{
								//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'"
								lyrs.addOptPoint(r, (int) stok.nval);
							}
							catch (System.ArgumentException e)
							{
								//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
								throw new System.ArgumentException("Error in 'Alayers' " + "option: " + e.Message);
							}
							ratepending = false;
							islayer = false;
						}
						else
						{
							// rate parameter
							if (ratepending)
							{
								// Add pending rate parameter
								try
								{
									lyrs.addOptPoint(r, 0);
								}
								catch (System.ArgumentException e)
								{
									//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
									throw new System.ArgumentException("Error in 'Alayers' " + "option: " + e.Message);
								}
							}
							// Now store new rate parameter
							//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'"
							r = (float) stok.nval;
							ratepending = true;
						}
						break;
					
					case '+': 
						if (!ratepending || islayer)
						{
							throw new System.ArgumentException("Layer parameter without " + "previous rate parameter " + "in 'Alayers' option");
						}
						islayer = true; // Next number is layer parameter
						break;
					
					case SupportClass.StreamTokenizerSupport.TT_WORD: 
						try
						{
							stok.NextToken();
						}
						catch (System.IO.IOException)
						{
							throw new System.ApplicationException("An IOException has ocurred where it " + "should never occur");
						}
						if (stok.ttype != SupportClass.StreamTokenizerSupport.TT_EOF)
						{
							throw new System.ArgumentException("'sl' argument of " + "'-Alayers' option must be " + "used alone.");
						}
						break;
					
					default: 
						throw new System.ArgumentException("Error parsing 'Alayers' " + "option");
					
				}
				try
				{
					stok.NextToken();
				}
				catch (System.IO.IOException)
				{
					throw new System.ApplicationException("An IOException has ocurred where it " + "should never occur");
				}
			}
			if (islayer)
			{
				throw new System.ArgumentException("Error parsing 'Alayers' " + "option");
			}
			if (ratepending)
			{
				try
				{
					lyrs.addOptPoint(r, 0);
				}
				catch (System.ArgumentException e)
				{
					//UPGRADE_TODO: The equivalent in .NET for method 'java.lang.Throwable.getMessage' may return a different value. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1043'"
					throw new System.ArgumentException("Error in 'Alayers' " + "option: " + e.Message);
				}
			}
			return lyrs;
		}