This class holds one of the different progression orders defined in the bit stream. The type(s) of progression order are defined in the ProgressionType interface. A Progression object is totally defined by its component start and end, resolution level start and end and layer start and end indexes. If no progression order change is defined, there is only Progression instance.
        /// <summary> Creates a new ProgressionSpec object for the specified number of tiles,
        /// components and the ParameterList instance.
        ///
        /// </summary>
        /// <param name="nt">The number of tiles
        ///
        /// </param>
        /// <param name="nc">The number of components
        ///
        /// </param>
        /// <param name="nl">The number of layer
        ///
        /// </param>
        /// <param name="dls">The number of decomposition levels specifications
        ///
        /// </param>
        /// <param name="type">the type of the specification module. The ProgressionSpec
        /// class should only be used only with the type ModuleSpec.SPEC_TYPE_TILE.
        ///
        /// </param>
        /// <param name="pl">The ParameterList instance
        ///
        /// </param>
        public ProgressionSpec(int nt, int nc, int nl, IntegerSpec dls, byte type, ParameterList pl) : base(nt, nc, type)
        {
            System.String param = pl.getParameter("Aptype");
            Progression[] prog;
            int           mode = -1;

            if (param == null)
            {
                // No parameter specified
                if (pl.getParameter("Rroi") == null)
                {
                    mode = checkProgMode("res");
                }
                else
                {
                    mode = checkProgMode("layer");
                }

                if (mode == -1)
                {
                    System.String errMsg = "Unknown progression type : '" + param + "'";
                    throw new System.ArgumentException(errMsg);
                }
                prog    = new Progression[1];
                prog[0] = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                setDefault(prog);
                return;
            }

            SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param);
            byte curSpecType           = SPEC_DEF;   // Specification type of the

            // current parameter
            bool[]        tileSpec    = null;  // Tiles concerned by the specification
            System.String word        = null;  // current word
            System.String errMsg2     = null;  // Error message
            bool          needInteger = false; // True if an integer value is expected
            int           intType     = 0;     // Type of read integer value (0=index of first

            // resolution level, 1= index of first component, 2=index of first
            // layer not included, 3= index of first resolution level not
            // included, 4= index of  first component not included
            System.Collections.ArrayList progression = System.Collections.ArrayList.Synchronized(new System.Collections.ArrayList(10));
            int         tmp     = 0;
            Progression curProg = null;

            while (stk.HasMoreTokens())
            {
                word = stk.NextToken();

                switch (word[0])
                {
                case 't':
                    // If progression were previously found, store them
                    if (progression.Count > 0)
                    {
                        // Ensure that all information has been taken
                        curProg.ce  = nc;
                        curProg.lye = nl;
                        curProg.re  = dls.Max + 1;
                        prog        = new Progression[progression.Count];
                        progression.CopyTo(prog);
                        if (curSpecType == SPEC_DEF)
                        {
                            setDefault(prog);
                        }
                        else if (curSpecType == SPEC_TILE_DEF)
                        {
                            for (int i = tileSpec.Length - 1; i >= 0; i--)
                            {
                                if (tileSpec[i])
                                {
                                    setTileDef(i, prog);
                                }
                            }
                        }
                    }
                    progression.Clear();
                    intType     = -1;
                    needInteger = false;

                    // Tiles specification
                    tileSpec    = parseIdx(word, nTiles);
                    curSpecType = SPEC_TILE_DEF;
                    break;

                default:
                    // Here, words is either a Integer (progression bound index)
                    // or a String (progression order type). This is determined by
                    // the value of needInteger.
                    if (needInteger)
                    {
                        // Progression bound info
                        try
                        {
                            tmp = (System.Int32.Parse(word));
                        }
                        catch (System.FormatException)
                        {
                            // Progression has missing parameters
                            throw new System.ArgumentException("Progression " + "order" + " specification " + "has missing " + "parameters: " + param);
                        }

                        switch (intType)
                        {
                        case 0:                                          // cs
                            if (tmp < 0 || tmp > (dls.Max + 1))
                            {
                                throw new System.ArgumentException("Invalid res_start " + "in '-Aptype'" + " option: " + tmp);
                            }
                            curProg.rs = tmp; break;

                        case 1:                                          // rs
                            if (tmp < 0 || tmp > nc)
                            {
                                throw new System.ArgumentException("Invalid comp_start " + "in '-Aptype' " + "option: " + tmp);
                            }
                            curProg.cs = tmp; break;

                        case 2:                                          // lye
                            if (tmp < 0)
                            {
                                throw new System.ArgumentException("Invalid layer_end " + "in '-Aptype'" + " option: " + tmp);
                            }
                            if (tmp > nl)
                            {
                                tmp = nl;
                            }
                            curProg.lye = tmp; break;

                        case 3:                                          // ce
                            if (tmp < 0)
                            {
                                throw new System.ArgumentException("Invalid res_end " + "in '-Aptype'" + " option: " + tmp);
                            }
                            if (tmp > (dls.Max + 1))
                            {
                                tmp = dls.Max + 1;
                            }
                            curProg.re = tmp; break;

                        case 4:                                          // re
                            if (tmp < 0)
                            {
                                throw new System.ArgumentException("Invalid comp_end " + "in '-Aptype'" + " option: " + tmp);
                            }
                            if (tmp > nc)
                            {
                                tmp = nc;
                            }
                            curProg.ce = tmp; break;
                        }

                        if (intType < 4)
                        {
                            intType++;
                            needInteger = true;
                            break;
                        }
                        else if (intType == 4)
                        {
                            intType     = 0;
                            needInteger = false;
                            break;
                        }
                        else
                        {
                            throw new System.ApplicationException("Error in usage of 'Aptype' " + "option: " + param);
                        }
                    }

                    if (!needInteger)
                    {
                        // Progression type info
                        mode = checkProgMode(word);
                        if (mode == -1)
                        {
                            errMsg2 = "Unknown progression type : '" + word + "'";
                            throw new System.ArgumentException(errMsg2);
                        }
                        needInteger = true;
                        intType     = 0;
                        if (progression.Count == 0)
                        {
                            curProg = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                        }
                        else
                        {
                            curProg = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                        }
                        progression.Add(curProg);
                    }
                    break;
                }         // switch
            }             // while

            if (progression.Count == 0)
            {
                // No progression defined
                if (pl.getParameter("Rroi") == null)
                {
                    mode = checkProgMode("res");
                }
                else
                {
                    mode = checkProgMode("layer");
                }
                if (mode == -1)
                {
                    errMsg2 = "Unknown progression type : '" + param + "'";
                    throw new System.ArgumentException(errMsg2);
                }
                prog    = new Progression[1];
                prog[0] = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                setDefault(prog);
                return;
            }

            // Ensure that all information has been taken
            curProg.ce  = nc;
            curProg.lye = nl;
            curProg.re  = dls.Max + 1;

            // Store found progression
            prog = new Progression[progression.Count];
            progression.CopyTo(prog);

            if (curSpecType == SPEC_DEF)
            {
                setDefault(prog);
            }
            else if (curSpecType == SPEC_TILE_DEF)
            {
                for (int i = tileSpec.Length - 1; i >= 0; i--)
                {
                    if (tileSpec[i])
                    {
                        setTileDef(i, prog);
                    }
                }
            }

            // Check that default value has been specified
            if (getDefault() == null)
            {
                int ndefspec = 0;
                for (int t = nt - 1; t >= 0; t--)
                {
                    for (int c = nc - 1; c >= 0; c--)
                    {
                        if (specValType[t][c] == SPEC_DEF)
                        {
                            ndefspec++;
                        }
                    }
                }

                // If some tile-component have received no specification, they
                // receive the default progressiveness.
                if (ndefspec != 0)
                {
                    if (pl.getParameter("Rroi") == null)
                    {
                        mode = checkProgMode("res");
                    }
                    else
                    {
                        mode = checkProgMode("layer");
                    }
                    if (mode == -1)
                    {
                        errMsg2 = "Unknown progression type : '" + param + "'";
                        throw new System.ArgumentException(errMsg2);
                    }
                    prog    = new Progression[1];
                    prog[0] = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                    setDefault(prog);
                }
                else
                {
                    // All tile-component have been specified, takes the first
                    // tile-component value as default.
                    setDefault(getTileCompVal(0, 0));
                    switch (specValType[0][0])
                    {
                    case SPEC_TILE_DEF:
                        for (int c = nc - 1; c >= 0; c--)
                        {
                            if (specValType[0][c] == SPEC_TILE_DEF)
                            {
                                specValType[0][c] = SPEC_DEF;
                            }
                        }
                        tileDef[0] = null;
                        break;

                    case SPEC_COMP_DEF:
                        for (int t = nt - 1; t >= 0; t--)
                        {
                            if (specValType[t][0] == SPEC_COMP_DEF)
                            {
                                specValType[t][0] = SPEC_DEF;
                            }
                        }
                        compDef[0] = null;
                        break;

                    case SPEC_TILE_COMP:
                        specValType[0][0]   = SPEC_DEF;
                        tileCompVal["t0c0"] = null;
                        break;
                    }
                }
            }
        }
Exemple #2
0
        /// <summary> Creates a new ProgressionSpec object for the specified number of tiles,
        /// components and the ParameterList instance.
        /// 
        /// </summary>
        /// <param name="nt">The number of tiles
        /// 
        /// </param>
        /// <param name="nc">The number of components
        /// 
        /// </param>
        /// <param name="nl">The number of layer
        /// 
        /// </param>
        /// <param name="dls">The number of decomposition levels specifications
        /// 
        /// </param>
        /// <param name="type">the type of the specification module. The ProgressionSpec
        /// class should only be used only with the type ModuleSpec.SPEC_TYPE_TILE.
        /// 
        /// </param>
        /// <param name="pl">The ParameterList instance
        /// 
        /// </param>
        public ProgressionSpec(int nt, int nc, int nl, IntegerSpec dls, byte type, ParameterList pl)
            : base(nt, nc, type)
        {
            System.String param = pl.getParameter("Aptype");
            Progression[] prog;
            int mode = - 1;

            if (param == null)
            {
                // No parameter specified
                if (pl.getParameter("Rroi") == null)
                {
                    mode = checkProgMode("res");
                }
                else
                {
                    mode = checkProgMode("layer");
                }

                if (mode == - 1)
                {
                    System.String errMsg = "Unknown progression type : '" + param + "'";
                    throw new System.ArgumentException(errMsg);
                }
                prog = new Progression[1];
                prog[0] = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                setDefault(prog);
                return ;
            }

            SupportClass.Tokenizer stk = new SupportClass.Tokenizer(param);
            byte curSpecType = SPEC_DEF; // Specification type of the
            // current parameter
            bool[] tileSpec = null; // Tiles concerned by the specification
            System.String word = null; // current word
            System.String errMsg2 = null; // Error message
            bool needInteger = false; // True if an integer value is expected
            int intType = 0; // Type of read integer value (0=index of first
            // resolution level, 1= index of first component, 2=index of first
            // layer not included, 3= index of first resolution level not
            // included, 4= index of  first component not included
            System.Collections.Generic.List<Progression> progression = new List<Progression>(10);
            int tmp = 0;
            Progression curProg = null;

            while (stk.HasMoreTokens())
            {
                word = stk.NextToken();

                switch (word[0])
                {

                    case 't':
                        // If progression were previously found, store them
                        if (progression.Count > 0)
                        {
                            // Ensure that all information has been taken
                            curProg.ce = nc;
                            curProg.lye = nl;
                            curProg.re = dls.Max + 1;
                            prog = new Progression[progression.Count];
                            progression.CopyTo(prog);
                            if (curSpecType == SPEC_DEF)
                            {
                                setDefault(prog);
                            }
                            else if (curSpecType == SPEC_TILE_DEF)
                            {
                                for (int i = tileSpec.Length - 1; i >= 0; i--)
                                    if (tileSpec[i])
                                    {
                                        setTileDef(i, prog);
                                    }
                            }
                        }
                        progression.Clear();
                        intType = - 1;
                        needInteger = false;

                        // Tiles specification
                        tileSpec = parseIdx(word, nTiles);
                        curSpecType = SPEC_TILE_DEF;
                        break;

                    default:
                        // Here, words is either a Integer (progression bound index)
                        // or a String (progression order type). This is determined by
                        // the value of needInteger.
                        if (needInteger)
                        {
                            // Progression bound info
                            try
                            {
                                tmp = (System.Int32.Parse(word));
                            }
                            catch (System.FormatException e)
                            {
                                // Progression has missing parameters
                                throw new System.ArgumentException("Progression " + "order" + " specification " + "has missing " + "parameters: " + param);
                            }

                            switch (intType)
                            {

                                case 0:  // cs
                                    if (tmp < 0 || tmp > (dls.Max + 1))
                                        throw new System.ArgumentException("Invalid res_start " + "in '-Aptype'" + " option: " + tmp);
                                    curProg.rs = tmp; break;

                                case 1:  // rs
                                    if (tmp < 0 || tmp > nc)
                                    {
                                        throw new System.ArgumentException("Invalid comp_start " + "in '-Aptype' " + "option: " + tmp);
                                    }
                                    curProg.cs = tmp; break;

                                case 2:  // lye
                                    if (tmp < 0)
                                        throw new System.ArgumentException("Invalid layer_end " + "in '-Aptype'" + " option: " + tmp);
                                    if (tmp > nl)
                                    {
                                        tmp = nl;
                                    }
                                    curProg.lye = tmp; break;

                                case 3:  // ce
                                    if (tmp < 0)
                                        throw new System.ArgumentException("Invalid res_end " + "in '-Aptype'" + " option: " + tmp);
                                    if (tmp > (dls.Max + 1))
                                    {
                                        tmp = dls.Max + 1;
                                    }
                                    curProg.re = tmp; break;

                                case 4:  // re
                                    if (tmp < 0)
                                        throw new System.ArgumentException("Invalid comp_end " + "in '-Aptype'" + " option: " + tmp);
                                    if (tmp > nc)
                                    {
                                        tmp = nc;
                                    }
                                    curProg.ce = tmp; break;
                                }

                            if (intType < 4)
                            {
                                intType++;
                                needInteger = true;
                                break;
                            }
                            else if (intType == 4)
                            {
                                intType = 0;
                                needInteger = false;
                                break;
                            }
                            else
                            {
                                throw new System.InvalidOperationException("Error in usage of 'Aptype' " + "option: " + param);
                            }
                        }

                        if (!needInteger)
                        {
                            // Progression type info
                            mode = checkProgMode(word);
                            if (mode == - 1)
                            {
                                errMsg2 = "Unknown progression type : '" + word + "'";
                                throw new System.ArgumentException(errMsg2);
                            }
                            needInteger = true;
                            intType = 0;
                            if (progression.Count == 0)
                            {
                                curProg = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                            }
                            else
                            {
                                curProg = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                            }
                            progression.Add(curProg);
                        }
                        break;

                } // switch
            } // while

            if (progression.Count == 0)
            {
                // No progression defined
                if (pl.getParameter("Rroi") == null)
                {
                    mode = checkProgMode("res");
                }
                else
                {
                    mode = checkProgMode("layer");
                }
                if (mode == - 1)
                {
                    errMsg2 = "Unknown progression type : '" + param + "'";
                    throw new System.ArgumentException(errMsg2);
                }
                prog = new Progression[1];
                prog[0] = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                setDefault(prog);
                return ;
            }

            // Ensure that all information has been taken
            curProg.ce = nc;
            curProg.lye = nl;
            curProg.re = dls.Max + 1;

            // Store found progression
            prog = new Progression[progression.Count];
            progression.CopyTo(prog);

            if (curSpecType == SPEC_DEF)
            {
                setDefault(prog);
            }
            else if (curSpecType == SPEC_TILE_DEF)
            {
                for (int i = tileSpec.Length - 1; i >= 0; i--)
                    if (tileSpec[i])
                    {
                        setTileDef(i, prog);
                    }
            }

            // Check that default value has been specified
            if (getDefault() == null)
            {
                int ndefspec = 0;
                for (int t = nt - 1; t >= 0; t--)
                {
                    for (int c = nc - 1; c >= 0; c--)
                    {
                        if (specValType[t][c] == SPEC_DEF)
                        {
                            ndefspec++;
                        }
                    }
                }

                // If some tile-component have received no specification, they
                // receive the default progressiveness.
                if (ndefspec != 0)
                {
                    if (pl.getParameter("Rroi") == null)
                    {
                        mode = checkProgMode("res");
                    }
                    else
                    {
                        mode = checkProgMode("layer");
                    }
                    if (mode == - 1)
                    {
                        errMsg2 = "Unknown progression type : '" + param + "'";
                        throw new System.ArgumentException(errMsg2);
                    }
                    prog = new Progression[1];
                    prog[0] = new Progression(mode, 0, nc, 0, dls.Max + 1, nl);
                    setDefault(prog);
                }
                else
                {
                    // All tile-component have been specified, takes the first
                    // tile-component value as default.
                    setDefault(getTileCompVal(0, 0));
                    switch (specValType[0][0])
                    {

                        case SPEC_TILE_DEF:
                            for (int c = nc - 1; c >= 0; c--)
                            {
                                if (specValType[0][c] == SPEC_TILE_DEF)
                                    specValType[0][c] = SPEC_DEF;
                            }
                            tileDef[0] = null;
                            break;

                        case SPEC_COMP_DEF:
                            for (int t = nt - 1; t >= 0; t--)
                            {
                                if (specValType[t][0] == SPEC_COMP_DEF)
                                    specValType[t][0] = SPEC_DEF;
                            }
                            compDef[0] = null;
                            break;

                        case SPEC_TILE_COMP:
                            specValType[0][0] = SPEC_DEF;
                            tileCompVal["t0c0"] = null;
                            break;
                        }
                }
            }
        }