⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 encoder.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                      ((e.getMessage() != null) ?                       (":\n"+e.getMessage()) : ""),2);                if(pl.getParameter("debug").equals("on"))                    e.printStackTrace();                else {                    error("Use '-debug' option for more details",2);                }                return;            }            // Instantiate the HeaderEncoder            headenc = new HeaderEncoder(imgsrc,imsigned,dwt,imgtiler,encSpec,                                        rois,ralloc);	    ralloc.setHeaderEncoder(headenc);            // **** Write header to be able to estimate header overhead ****            headenc.encodeMainHeader();            // **** Initialize rate allocator, with proper header            // overhead. This will also encode all the data ****            ralloc.initialize();            // **** Write header (final) ****            headenc.reset();            headenc.encodeMainHeader();            // Insert header into the codestream            bwriter.commitBitstreamHeader(headenc);            // **** Report info ****            if (verbose) {                // Print target rate info                FacilityManager.getMsgLogger().                    println("Target bitrate = "+rate+" bpp (i.e. "+                            (int)(rate*imgsrc.getImgWidth()                                  *imgsrc.getImgHeight()/8)+ " bytes)",4,6);            }            // **** Now do the rate-allocation and write result ****            ralloc.runAndWrite();            // **** Done ****            bwriter.close();            // **** Calculate file length ****            fileLength = bwriter.getLength();            // **** Tile-parts and packed packet headers ****            if(pktspertp>0 || pphTile || pphMain){                int headInc;                try{                    CodestreamManipulator cm = new                         CodestreamManipulator(outname, ntiles, pktspertp,                                              pphMain, pphTile, tempSop,                                              tempEph);                    fileLength += cm.doCodestreamManipulation();                    String res="";                    if(pktspertp>0)                        FacilityManager.                            getMsgLogger().println("Created tile-parts "+                                                   "containing at most "+                                                   pktspertp+                                                   " packets per tile.",4,6);                    if(pphTile)                        FacilityManager.getMsgLogger().                            println("Moved packet headers "+                                    "to tile headers",4,6);                    if(pphMain)                        FacilityManager.getMsgLogger().                            println("Moved packet headers "+                                    "to main header",4,6);                }                catch(IOException e){                    error("Error while creating tileparts or packed packet"+                          " headers"+                          ((e.getMessage() != null) ?                           (":\n"+e.getMessage()) : ""),2);                    if(pl.getParameter("debug").equals("on"))                        e.printStackTrace();                    else {                        error("Use '-debug' option for more details",2);                    }                    return;                }            }                            // **** File Format ****            if(useFileFormat){                try{                    int nc= imgsrc.getNumComps() ;                    int[] bpc=new int[nc];                    for(int comp = 0; comp<nc; comp++)                        bpc[comp]=imgsrc.getNomRangeBits(comp);                                        ffw = new FileFormatWriter(outname,                                                imgsrc.getImgHeight(),                                               imgsrc.getImgWidth(), nc, bpc,                                               fileLength);                    fileLength += ffw.writeFileFormat();                }                catch(IOException e){                    throw new Error("Error while writing JP2 file format");                }            }            // **** Report results ****            if (verbose) {                // Print achieved rate                FacilityManager.getMsgLogger().                    println("Achieved bitrate = "+                             (8f*fileLength/                             (imgsrc.getImgWidth()*imgsrc.getImgHeight())) +                            " bpp (i.e. "+fileLength+" bytes)",4,6);                // Display ROI information if needed                if(pl.getParameter("Rroi")!=null && !useFileFormat &&                    pl.getIntParameter("tile_parts")==0 ) {                    int roiLen = bwriter.getOffLastROIPkt();                    FacilityManager.getMsgLogger().                        printmsg(MsgLogger.INFO,"The Region Of Interest is"+                                 " encoded in the first "+                                 roiLen+" bytes of the codestream (i.e "+                                 (8f*roiLen/(imgsrc.getImgWidth()*                                             imgsrc.getImgHeight()))+" bpp)");                                    }            }        }	catch(IllegalArgumentException e){	    error(e.getMessage(),2);            if(pl.getParameter("debug").equals("on"))                e.printStackTrace();	    return;	}        catch (Error e) {            error("An uncaught error has occurred: "+e.getMessage(),2);            if(pl.getParameter("debug").equals("on"))                e.printStackTrace();            else {                error("Use '-debug' option for more details",2);            }        }        catch (RuntimeException e) {            error("An uncaught runtime exception has occurred: "+                  e.getMessage(),2);            if(pl.getParameter("debug").equals("on"))                e.printStackTrace();            else {                error("Use '-debug' option for more details",2);            }        }        catch (Throwable e) {            error("An unchecked exception has occurred: "+                  e.getMessage(),2);            if(pl.getParameter("debug").equals("on"))                e.printStackTrace();            else {                error("Use '-debug' option for more details",2);            }            return;        }    }    /**     * 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 4     * 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;    }    /**      * Returns all the parameters used in the encoding chain. It calls     * parameter from each module and store them in one array (one row     * per parameter and 4 columns).     *     * @return All encoding parameters     *     * @see #getParameterInfo     * */    public static String[][] getAllParameters(){        Vector vec = new Vector();                String[][] str = getParameterInfo();        if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);                str = ForwCompTransf.getParameterInfo();        if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);                str = AnWTFilter.getParameterInfo();        if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);                str = ForwardWT.getParameterInfo();        if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);                str = Quantizer.getParameterInfo();        if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);                str = ROIScaler.getParameterInfo();        if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);                str = EntropyCoder.getParameterInfo();	if(str!=null)	    for(int i=str.length-1; i>=0; i--)		vec.addElement(str[i]);        	str = PostCompRateAllocator.getParameterInfo();	if(str!=null)	    for(int i=str.length-1; i>=0; i--)		vec.addElement(str[i]);                str = PktEncoder.getParameterInfo();	if(str!=null)            for(int i=str.length-1; i>=0; i--)                vec.addElement(str[i]);        	str = new String[vec.size()][4];	if(str!=null)	    for(int i=str.length-1; i>=0; i--)		str[i] = (String[])vec.elementAt(i);        	return str;    }        /**     * Prints the error message 'msg' to standard err, prepending "ERROR" to     * it, and sets the exitCode to 'code'. An exit code different than 0     * indicates that there where problems.     *     * @param msg The error message     *     * @param code The exit code to set     * */    private void error(String msg, int code) {        exitCode = code;        FacilityManager.getMsgLogger().printmsg(MsgLogger.ERROR,msg);    }    /**     * Prints the warning message 'msg' to standard err, prepending "WARNING"     * to it.     *     * @param msg The error message     * */    private void warning(String msg) {        FacilityManager.getMsgLogger().printmsg(MsgLogger.WARNING,msg);    }    /**     * Prints version and copyright information to stdout, using the     * MsgPrinter.     * */    private void printVersionAndCopyright() {        FacilityManager.getMsgLogger()            .println("JJ2000's JPEG 2000 Encoder\n",2,4);        FacilityManager.getMsgLogger()            .println("Version: "+JJ2KInfo.version+"\n",2,4);        FacilityManager.getMsgLogger()            .println("Copyright:\n\n"+JJ2KInfo.copyright+"\n",2,4);        FacilityManager.getMsgLogger()            .println("Send bug reports to: "+JJ2KInfo.bugaddr+"\n",2,4);    }    /**     * Prints the usage information to stdout. The usage information     * is written for all modules in the encoder.     * */    private void printUsage() {        String opts[][];        int i;        MsgLogger ml = FacilityManager.getMsgLogger();        ml.println("Usage:",0,0);        ml.println("JJ2KEncoder args...\n",10,12);        ml.println("The exit code of the encoder is non-zero "+                   "if an error occurs.\n",2,4);        ml.println("Note: Many encoder modules accept tile-component "+                   "specific parameters. These parameters must be provided "+                   "according to the pattern:\n \"[<tile-component idx>] "+                   "<param>\" (repeated as many time as needed). ",2,4);        ml.println("\n"+                   "<tile-component idx> respect the following policy"+                   " according to the degree of priority: \n"+                   "  (1) t<idx> c<idx> : Tile-component specification.\n"+                   "  (2) t<idx> : Tile specification.\n"+                   "  (3) c<idx> : Component specification\n"+                   "  (4) <void> : Default specification.\n\n"+                   "Where the priorities of the specifications are:\n"+                   "(1) > (2) > (3) > (4), (\'>\' means \"overrides\")\n",2,4);        ml.println("  <idx>: ',' separates indexes, '-' separates bounds of "+                   "indexes list. (ex: 0,2-4 means indexes 0,2,3 and "+                   " 4).\n",2,4);        ml.println("The following arguments are recognized:",2,4);                // Info of each encoder parameter        printParamInfo(ml,getAllParameters());        // Print bug-report address        FacilityManager.getMsgLogger().println("\n\n",0,0);        FacilityManager.getMsgLogger().            println("Send bug reports to: "+JJ2KInfo.bugaddr+"\n",2,4);    }            /**     * Prints the parameters in 'pinfo' to the provided output, 'out', showing     * the existing defaults. The 'pinfo' argument is a 2D String array. The     * first dimension contains String arrays, 1 for each parameter. Each of     * these arrays has 3 elements, the first element is the parameter name,     * the second element is the synopsis for the parameter and the third one     * is a long description of the parameter. If the synopsis or description     * is 'null' then no synopsis or description is printed, respectively. If     * there is a default value for a parameter it is also printed.     *     * @param out Where to print.     *     * @param pinfo The parameter information to write.     * */    private void printParamInfo(MsgLogger out, String pinfo[][]) {        String defval;        if (pinfo == null) {            return;        }        for (int i=0; i<pinfo.length; i++) {            defval = defpl.getParameter(pinfo[i][0]);            if (defval != null) { // There is a default value                out.println("-" + pinfo[i][0] +                         ((pinfo[i][1] != null) ? " "+pinfo[i][1]+" " : " ") +                         "(default = "+defval+")",4,8);            }            else { // There is no default value                out.println("-" + pinfo[i][0] +                         ((pinfo[i][1] != null) ? " "+pinfo[i][1] : ""),4,8);            }            // Is there an explanatory message?            if (pinfo[i][2] != null) {                out.println(pinfo[i][2],6,6);            }        }    }}

⌨️ 快捷键说明

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