/// <summary> Creates a ROIScaler object. The Quantizer is the source of data to
        /// scale.
        ///
        /// <p>The ROI Scaler creates a ROIMaskGenerator depending on what ROI
        /// information is in the ParameterList. If only rectangular ROI are used,
        /// the fast mask generator for rectangular ROI can be used.</p>
        ///
        /// </summary>
        /// <param name="src">The source of data to scale
        ///
        /// </param>
        /// <param name="pl">The parameter list (or options).
        ///
        /// </param>
        /// <param name="encSpec">The encoder specifications for addition of roi specs
        ///
        /// </param>
        /// <exception cref="IllegalArgumentException">If an error occurs while parsing
        /// the options in 'pl'
        ///
        /// </exception>
        public static ROIScaler createInstance(Quantizer src, ParameterList pl, EncoderSpecs encSpec)
        {
            System.Collections.ArrayList roiVector = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            ROIMaskGenerator             maskGen   = null;

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

            // Get parameters and check if there are and ROIs specified
            System.String roiopt = pl.getParameter("Rroi");
            if (roiopt == null)
            {
                // No ROIs specified! Create ROIScaler with no mask generator
                return(new ROIScaler(src, null, false, -1, false, encSpec));
            }

            // Check if the lowest resolution levels should belong to the ROI
            int sLev = pl.getIntParameter("Rstart_level");

            // Check if the ROIs are block-aligned
            bool useBlockAligned = pl.getBooleanParameter("Ralign");

            // Check if generic mask generation is specified
            bool onlyRect = !pl.getBooleanParameter("Rno_rect");

            // Parse the ROIs
            parseROIs(roiopt, src.NumComps, roiVector);
            ROI[] roiArray = new ROI[roiVector.Count];
            roiVector.CopyTo(roiArray);

            // If onlyRect has been forced, check if there are any non-rectangular
            // ROIs specified.  Currently, only the presence of circular ROIs will
            // make this false
            if (onlyRect)
            {
                for (int i = roiArray.Length - 1; i >= 0; i--)
                {
                    if (!roiArray[i].rect)
                    {
                        onlyRect = false;
                        break;
                    }
                }
            }

            if (onlyRect)
            {
                // It's possible to use the fast ROI mask generation when only
                // rectangular ROIs are specified.
                maskGen = new RectROIMaskGenerator(roiArray, src.NumComps);
            }
            else
            {
                // It's necessary to use the generic mask generation
                maskGen = new ArbROIMaskGenerator(roiArray, src.NumComps, src);
            }
            return(new ROIScaler(src, maskGen, true, sLev, useBlockAligned, encSpec));
        }
Ejemplo n.º 2
0
		/// <summary> Creates a ROIScaler object. The Quantizer is the source of data to
		/// scale.
		/// 
		/// <p>The ROI Scaler creates a ROIMaskGenerator depending on what ROI
		/// information is in the ParameterList. If only rectangular ROI are used,
		/// the fast mask generator for rectangular ROI can be used.</p>
		/// 
		/// </summary>
		/// <param name="src">The source of data to scale
		/// 
		/// </param>
		/// <param name="pl">The parameter list (or options).
		/// 
		/// </param>
		/// <param name="encSpec">The encoder specifications for addition of roi specs
		/// 
		/// </param>
		/// <exception cref="IllegalArgumentException">If an error occurs while parsing
		/// the options in 'pl'
		/// 
		/// </exception>
		public static ROIScaler createInstance(Quantizer src, ParameterList pl, EncoderSpecs encSpec)
		{
			System.Collections.ArrayList roiVector = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
			ROIMaskGenerator maskGen = null;
			
			// Check parameters
			pl.checkList(OPT_PREFIX, CSJ2K.j2k.util.ParameterList.toNameArray(pinfo));
			
			// Get parameters and check if there are and ROIs specified 
			System.String roiopt = pl.getParameter("Rroi");
			if (roiopt == null)
			{
				// No ROIs specified! Create ROIScaler with no mask generator
				return new ROIScaler(src, null, false, - 1, false, encSpec);
			}
			
			// Check if the lowest resolution levels should belong to the ROI 
			int sLev = pl.getIntParameter("Rstart_level");
			
			// Check if the ROIs are block-aligned
			bool useBlockAligned = pl.getBooleanParameter("Ralign");
			
			// Check if generic mask generation is specified 
			bool onlyRect = !pl.getBooleanParameter("Rno_rect");
			
			// Parse the ROIs
			parseROIs(roiopt, src.NumComps, roiVector);
			ROI[] roiArray = new ROI[roiVector.Count];
			roiVector.CopyTo(roiArray);
			
			// If onlyRect has been forced, check if there are any non-rectangular
			// ROIs specified.  Currently, only the presence of circular ROIs will
			// make this false
			if (onlyRect)
			{
				for (int i = roiArray.Length - 1; i >= 0; i--)
					if (!roiArray[i].rect)
					{
						onlyRect = false;
						break;
					}
			}
			
			if (onlyRect)
			{
				// It's possible to use the fast ROI mask generation when only
				// rectangular ROIs are specified.
				maskGen = new RectROIMaskGenerator(roiArray, src.NumComps);
			}
			else
			{
				// It's necessary to use the generic mask generation
				maskGen = new ArbROIMaskGenerator(roiArray, src.NumComps, src);
			}
			return new ROIScaler(src, maskGen, true, sLev, useBlockAligned, encSpec);
		}