📄 decoder.java
字号:
e.printStackTrace(); else { error("Use '-debug' option for more details",2); } return; } } // If 3 (originally) unsigned components with depths less than // 8 bits and a component transformation is used in at least // one tile, ImgWriterPPM is better than ImgWriterPGM (the // image is entirely decoded 3 times). if(imwriter.length==3 && ictransf.getNomRangeBits(0)<=8 && ictransf.getNomRangeBits(1)<=8 && ictransf.getNomRangeBits(2)<=8 && !hd.isOriginalSigned(0) && !hd.isOriginalSigned(1) && !hd.isOriginalSigned(2) && decSpec.cts.isCompTransfUsed()){ warning("JJ2000 is quicker with one PPM output "+ "file than with 3 PGM output files when a"+ " component transformation is applied."); } } // **** Report info **** if(verbose){ if(mrl!=res) FacilityManager.getMsgLogger(). println("Reconstructing resolution "+res+" on "+ mrl+" ("+breader.getImgWidth(res)+"x"+ breader.getImgHeight(res)+")",8,8); FacilityManager.getMsgLogger(). println("Target rate = "+breader.getTargetRate()+" bpp ("+ breader.getTargetNbytes()+" bytes)",8,8); } // **** Decode and write/display result **** if(disp){ // Now create the image and decode. Use a low priority for // this so as not to block other threads. Thread.currentThread().setPriority(Thread.MIN_PRIORITY+1); img = BlkImgDataSrcImageProducer.createImage(ictransf,isp); isp.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); // HACK for JDK 1.1.x under Windows if (win != null) { win.setCursor(Cursor. getPredefinedCursor(Cursor.WAIT_CURSOR)); } // END HACK isp.setImage(img); isp.setCursor(Cursor. getPredefinedCursor(Cursor.DEFAULT_CURSOR)); // HACK for JDK 1.1.x under Windows if (win != null) { win.setCursor(Cursor. getPredefinedCursor(Cursor.DEFAULT_CURSOR)); } // END HACK // Check the image status, every 100ms, until it is finished. if (win != null) { int status; do { status = isp.checkImage(img,null); if ((status & ImageObserver.ERROR) != 0) { FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR, "An unknown error occurred while "+ "producing the image"); return; } else if ((status & ImageObserver.ABORT) != 0) { FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR, "Image production was aborted for "+ "some unknown reason"); } else if ((status & ImageObserver.ALLBITS) != 0) { ImgMouseListener iml = new ImgMouseListener(isp); isp.addMouseListener(iml); isp.addMouseMotionListener(iml); } else { // Check again in 100 ms try { Thread.currentThread().sleep(100); } catch (InterruptedException e) { } } } while ((status & (ImageObserver.ALLBITS| ImageObserver.ABORT| ImageObserver.ERROR)) == 0); } } else{ // Need to optimize! If no component mixer is used and PGM // files are written need to write blocks in parallel // (otherwise decodes 3 times) // Now write the image to the file (decodes as needed) for (i=0; i<imwriter.length; i++) { 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; } FacilityManager.getMsgLogger(). println("Actual bitrate = "+bitrate+ " bpp (i.e. "+numBytes+ " bytes)",8,8); } } 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); } /** * 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(); String[][] str = BitstreamReaderAgent.getParameterInfo(); if(str!=null) for(int i=str.length-1; i>=0; i--) vec.addElement(str[i]); str = EntropyDecoder.getParameterInfo(); if(str!=null) for(int i=str.length-1; i>=0; i--) vec.addElement(str[i]); str = ROIDeScaler.getParameterInfo(); if(str!=null) for(int i=str.length-1; i>=0; i--) vec.addElement(str[i]); str = Dequantizer.getParameterInfo(); if(str!=null) for(int i=str.length-1; i>=0; i--) vec.addElement(str[i]); str = InvCompTransf.getParameterInfo(); if(str!=null) for(int i=str.length-1; i>=0; i--) vec.addElement(str[i]); str = HeaderDecoder.getParameterInfo(); if(str!=null) for(int i=str.length-1; i>=0; i--) vec.addElement(str[i]); str = 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 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -