postcomprateallocator.java

来自「jpeg2000编解码」· Java 代码 · 共 371 行 · 第 1/2 页

JAVA
371
字号
     * */    public abstract void initialize() throws IOException;    /**     * Runs the rate allocation algorithm and writes the data to the     * bit stream. This must be called after the initialize() method.     *     * @see #initialize     * */    public abstract void runAndWrite() throws IOException;    /**     * Returns the number of layers that are actually generated.     *     * @return The number of layers generated.     * */    public int getNumLayers() {        return numLayers;    }    /**     * Returns the parameters that are used in this class and implementing     * classes. It returns a 2D String array. Each of the 1D arrays is for a     * different option, and they have 3 elements. The first element is the     * option name, the second one is the synopsis, the third one is a long     * description of what the parameter is and the fourth is its default     * value. The synopsis or description may be 'null', in which case it is     * assumed that there is no synopsis or description of the option,     * respectively. Null may be returned if no options are supported.     *     * @return the options name, their synopsis and their explanation,      * or null if no options are supported.     * */    public static String[][] getParameterInfo() {        return pinfo;    }    /**     * 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.     *     * @param src The source of entropy coded data.     *     * @param pl The parameter lis (or options).     *     * @param rate The target bitrate for the rate allocation     *     * @param bw The bit stream writer object, where the bit stream data will     * be written.     * */    public static PostCompRateAllocator createInstance(CodedCBlkDataSrcEnc src,                                                       ParameterList pl,                                                       float rate,                                                       CodestreamWriter bw,                                                       EncoderSpecs encSpec){        // Check parameters        pl.checkList(OPT_PREFIX,pl.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.getTotNumLayers();        // 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);    }    /**     * Convenience method that parses the 'Alayers' option.     *     * @param params The parameters of the 'Alayers' option     *     * @param rate The overall target bitrate     *     * @return The layer specification.     * */    private static LayersInfo parseAlayers(String params,float rate) {        LayersInfo lyrs;        StreamTokenizer stok;        boolean islayer,ratepending;        float r;        lyrs = new LayersInfo(rate);        stok = new StreamTokenizer(new StringReader(params));        stok.eolIsSignificant(false);        try {            stok.nextToken();        } catch (IOException e) {            throw new Error("An IOException has ocurred where it "+                            "should never occur");        }        ratepending = false;        islayer = false;        r = 0; // to keep compiler happy        while (stok.ttype != stok.TT_EOF) {            switch(stok.ttype) {            case StreamTokenizer.TT_NUMBER:                if (islayer) { // layer parameter                    try {                        lyrs.addOptPoint(r,(int)stok.nval);                    } catch (IllegalArgumentException e) {                        throw new                            IllegalArgumentException("Error in 'Alayers' "+                                                     "option: "+                                                     e.getMessage());                    }                    ratepending = false;                    islayer = false;                } else { // rate parameter                    if (ratepending) { // Add pending rate parameter                        try {                            lyrs.addOptPoint(r,0);                        } catch (IllegalArgumentException e) {                            throw new                                IllegalArgumentException("Error in 'Alayers' "+                                                         "option: "+                                                         e.getMessage());                        }                    }                    // Now store new rate parameter                    r = (float) stok.nval;                    ratepending = true;                }                break;            case '+':                if (!ratepending || islayer) {                    throw new                        IllegalArgumentException("Layer parameter without "+                                                 "previous rate parameter "+                                                 "in 'Alayers' option");                }                islayer = true; // Next number is layer parameter                break;            case StreamTokenizer.TT_WORD:                try {                    stok.nextToken();                } catch(IOException e) {                    throw new Error("An IOException has ocurred where it "+                                    "should never occur");                }                if (stok.ttype != stok.TT_EOF) {                    throw new                         IllegalArgumentException("'sl' argument of "+                                                 "'-Alayers' option must be "+                                                 "used alone.");                }                break;            default:                throw new IllegalArgumentException("Error parsing 'Alayers' "+                                                   "option");            }            try {                stok.nextToken();            } catch (IOException e) {                throw new Error("An IOException has ocurred where it "+                                "should never occur");            }        }        if (islayer) {            throw new IllegalArgumentException("Error parsing 'Alayers' "+                                               "option");        }        if (ratepending) {            try {                lyrs.addOptPoint(r,0);            } catch (IllegalArgumentException e) {                throw new                    IllegalArgumentException("Error in 'Alayers' "+                                             "option: "+                                             e.getMessage());            }        }        return lyrs;    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?