decoder.java

来自「jpeg2000编解码」· Java 代码 · 共 1,326 行 · 第 1/4 页

JAVA
1,326
字号
				    new ImgWriterPGX(out[i],decodedImage,i,						     csMap.isOutputSigned(i));			    } else {				imwriter[i] =				    new ImgWriterPGX(out[i],decodedImage,i,						     hd.isOriginalSigned(i));			    }                        } catch (IOException e) {                            error("Cannot write PGX header or open output "+                                  "file for component "                                   + i + ((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;                        }		    }		    try {			imwriter[i].writeAll();		    } catch (IOException e) {			error("I/O error while writing output file" +			      ((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;		    }		    try {			imwriter[i].close();		    } catch (IOException e) {			error("I/O error while closing output file (data may "+                              "be corrupted" + ((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;		    }		}	    }	    // **** Print some resulting info ****	    if(verbose) {		// Print actually read bitrate                // if file format used add the read file format bytes                float bitrate = breader.getActualRate();                int numBytes = breader.getActualNbytes();                if(ff.JP2FFUsed){                    int imageSize =(int)((8.0f*numBytes)/bitrate);                    numBytes +=ff.getFirstCodeStreamPos();                     bitrate = (numBytes*8.0f)/imageSize;                }                 if(pl.getIntParameter("ncb_quit") == -1) {                    FacilityManager.getMsgLogger().                        println("Actual bitrate = "+bitrate+                                " bpp (i.e. "+numBytes+" bytes)",8,8);		} else {                    FacilityManager.getMsgLogger().                        println("Number of packet body bytes read = "+numBytes,                                8,8);		}		FacilityManager.getMsgLogger().flush();	    }		        } catch (IllegalArgumentException e) {	    error(e.getMessage(),2);            if(pl.getParameter("debug").equals("on"))                e.printStackTrace();	    return;	} catch (Error e) {            if(e.getMessage()!=null) {                error(e.getMessage(),2);            } else {                error("An error has occured during decoding.",2);            }            if(pl.getParameter("debug").equals("on")) {                e.printStackTrace();            } else {                error("Use '-debug' option for more details",2);            }            return;        } catch (RuntimeException e) {            if(e.getMessage()!=null) {                error("An uncaught runtime exception has occurred:\n"+                      e.getMessage(),2);            } else {                error("An uncaught runtime exception has occurred.",2);            }            if(pl.getParameter("debug").equals("on")) {                e.printStackTrace();            } else {                error("Use '-debug' option for more details",2);            }            return;        } catch (Throwable e) {            error("An uncaught exception has occurred.",2);            if(pl.getParameter("debug").equals("on")) {                e.printStackTrace();            } else {                error("Use '-debug' option for more details",2);            }            return;        }    }    /**     * 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 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. Either     * the stacktrace or a "details" message is output depending on     * the data of the "debug" parameter.     *     * @param msg The error message     *     * @param code The exit code to set     *     * @param ex The exception associated with the call     * */    private void error(String msg, int code, Throwable ex) {	exitCode = code;	FacilityManager.getMsgLogger().printmsg(MsgLogger.ERROR,msg);	if(pl.getParameter("debug").equals("on")) {	    ex.printStackTrace();	} else {	    error("Use '-debug' option for more details",2); 	}    }     /**      * Return the information found in the COM marker segments encountered in     * the decoded codestream.      * */    public String[] getCOMInfo() {        if(hi==null) { // The codestream has not been read yet            return null;        }        int nCOMMarkers = hi.getNumCOM();        Enumeration com = hi.com.elements();        String[] infoCOM = new String[nCOMMarkers];        for(int i=0; i<nCOMMarkers; i++) {            infoCOM[i] = com.nextElement().toString();        }        return infoCOM;    }    /**      * Returns all the parameters used in the decoding chain. It calls     * parameter from each module and store them in one array (one row per     * parameter and 4 columns).     *     * @return All decoding parameters     *     * @see #getParameterInfo      * */    public static String[][] getAllParameters() {	Vector vec = new Vector();	int i;	String[][] str = BitstreamReaderAgent.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = EntropyDecoder.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = ROIDeScaler.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = Dequantizer.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = InvCompTransf.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = HeaderDecoder.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = Unscrambling.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = ICCProfiler.getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = getParameterInfo();	if(str!=null) for(i=str.length-1; i>=0; i--) vec.addElement(str[i]);	str = new String[vec.size()][4];	if(str!=null) for(i=str.length-1; i>=0; i--)	    str[i] = (String[])vec.elementAt(i);	return str;    }    /**     * 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 the logging facility     * returned by FacilityManager.getMsgLogger()     * */    private void printVersionAndCopyright() {        FacilityManager.getMsgLogger()            .println("JJ2000's JPEG 2000 Decoder\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 decoder.     * */    private void printUsage() {        String opts[][];        int i;        MsgLogger ml = FacilityManager.getMsgLogger();        ml.println("Usage:",0,0);        ml.println("JJ2KDecoder args...\n",10,12);        ml.println("The exit code of the decoder is non-zero "+                   "if an error occurs.",2,4);        ml.println("The following arguments are recongnized:\n",2,4);                // Print decoding options        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 message is printed to the logging facility     * returned by FacilityManager.getMsgLogger(). 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;        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);            }        }    }    /**      * Exit the decoding process according to the isChildProcess variable     **/    public void exit() {        if(isChildProcess) {            if(win!=null)                win.dispose();            if(title!=null)                title.done = true;            return;        } else {            System.exit(0);        }    }    /**      * Set isChildProcess variable.     *     * @param b The boolean value     * */    public void setChildProcess(boolean b) {        isChildProcess = b;    }}

⌨️ 快捷键说明

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