decoder.java
来自「jpeg2000编解码」· Java 代码 · 共 1,326 行 · 第 1/4 页
JAVA
1,326 行
e.printStackTrace(); } else { error("Use '-debug' option for more details",2); } return; } res = breader.getImgRes(); invWT.setImgResLevel(res); // **** Data converter **** (after inverse transform module) converter = new ImgDataConverter(invWT,0); // **** Inverse component transformation **** ictransf = new InvCompTransf(converter,decSpec,depth,pl); // **** Color space mapping **** if(ff.JP2FFUsed && pl.getParameter("nocolorspace").equals("off")) { try { csMap = new ColorSpace(in,hd,pl); channels = hd. createChannelDefinitionMapper(ictransf,csMap); resampled = hd.createResampler (channels,csMap); palettized = hd. createPalettizedColorSpaceMapper (resampled,csMap); color = hd.createColorSpaceMapper(palettized,csMap); if(csMap.debugging()) { FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR,""+csMap); FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR,""+channels); FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR,""+resampled); FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR,""+palettized); FacilityManager.getMsgLogger(). printmsg(MsgLogger.ERROR,""+color); } } catch (IllegalArgumentException e) { error("Could not instantiate ICC profiler"+ ((e.getMessage() != null) ? (":\n"+e.getMessage()) : ""),1,e); return; } catch (ColorSpaceException e) { error("error processing jp2 colorspace information"+ ((e.getMessage() != null) ? (": "+e.getMessage()) : " "),1,e); return; } } else { // Skip colorspace mapping color = ictransf; } // This is the last image in the decoding chain and should be // assigned by the last transformation: BlkImgDataSrc decodedImage = color; if(color==null) { decodedImage = ictransf; } int nCompImg = decodedImage.getNumComps(); // **** Create image writers/image display **** if(disp) { // No output file has been specified. Display // decoded image // Set up the display elements btitle = "JJ2000: "+(new File(infile)).getName()+" "+ decodedImage.getImgWidth()+"x"+decodedImage.getImgHeight(); if(isp==null) { win = new Frame(btitle+" @ (0,0) : 1"); win.setBackground(Color.white); win.addWindowListener(new ExitHandler(this)); isp = new ImgScrollPane(ImgScrollPane. SCROLLBARS_AS_NEEDED); win.add(isp,BorderLayout.CENTER); isp.addKeyListener(new ImgKeyListener(isp,this)); // HACK to make it work under Windows: for some reason // under JDK 1.1.x the event is delivered to the window // and not to the ImgScrollPane. win.addKeyListener(new ImgKeyListener(isp,this)); // END HACK } else { win = null; } // Get the window dimension to use, do not use more // than 8/10 of the screen size, in either dimension. if(win!=null) { win.addNotify(); // Instantiate peer to get insets ins = win.getInsets(); int subX = decodedImage.getCompSubsX(0); int subY = decodedImage.getCompSubsY(0); int w = (decodedImage.getImgWidth()+subX-1)/subX; int h = (decodedImage.getImgHeight()+subY-1)/subY; winDim = new Dimension(w+ins.left+ins.right, h+ins.top+ins.bottom); scrnDim = win.getToolkit().getScreenSize(); if(winDim.width>scrnDim.width*8/10f) { // Width too large for screen winDim.width = (int)(scrnDim.width*8/10f); } if(winDim.height>scrnDim.height*8/10f) { // Height too large for screen winDim.height = (int)(scrnDim.height*8/10f); } win.setSize(winDim); win.validate(); win.setVisible(true); // Start the title updater Thread tu; title = new TitleUpdater(isp,win,btitle); tu = new Thread(title); tu.start(); } else { title = null; } } else { // Write decoded image to specified output file // Create output file names if(csMap!=null) { if(outext.equalsIgnoreCase(".PPM") && (nCompImg!=3 || decodedImage.getNomRangeBits(0)>8 || decodedImage.getNomRangeBits(1)>8 || decodedImage.getNomRangeBits(2)>8 || csMap.isOutputSigned(0) || csMap.isOutputSigned(1) || csMap.isOutputSigned(2))) { error("Specified PPM output file but compressed image"+ " is not of the correct format for PPM or "+ "limited decoded components to less than 3.",1); return; } } else { if(outext.equalsIgnoreCase(".PPM") && (nCompImg!=3 || decodedImage.getNomRangeBits(0)>8 || decodedImage.getNomRangeBits(1)>8 || decodedImage.getNomRangeBits(2)>8 || hd.isOriginalSigned(0) || hd.isOriginalSigned(1) || hd.isOriginalSigned(2))) { error("Specified PPM output file but compressed image"+ " is not of the correct format for PPM or "+ "limited decoded components to less than 3.",1); return; } } out = new String[nCompImg]; // initiate all strings to keep compiler happy for(i=0; i<nCompImg; i++) { out[i] = ""; } if(nCompImg>1 && !outext.equalsIgnoreCase(".PPM")) { // Multiple file output // files // If PGM verify bitdepth and if signed if(outext.equalsIgnoreCase(".PGM")) { for(i=0;i<nCompImg; i++) { if(csMap!=null) { if(csMap.isOutputSigned(i)) { error("Specified PGM output file but "+ "compressed image is not of the "+ "correct "+ "format for PGM.",1); return; } } else { if(hd.isOriginalSigned(i)) { error("Specified PGM output file but "+ "compressed image is not of the "+ "correct "+ "format for PGM.",1); return; } } } } // Open multiple output files for(i=0; i<nCompImg; i++) { out[i] = outbase + "-" + (i+1) + outext; } } else { // Single output file out[0] = outbase + outext; } // Now get the image writers if(outext.equalsIgnoreCase(".PPM")) { imwriter = new ImgWriter[1]; try { imwriter[0] = new ImgWriterPPM(out[0],decodedImage, 0,1,2); } catch (IOException e) { error("Cannot write PPM header or open output file" + 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; } } else { // PGX or PGM imwriter = new ImgWriter[nCompImg]; } // 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(csMap!=null) { if(imwriter.length==3 && decodedImage.getNomRangeBits(0)<=8 && decodedImage.getNomRangeBits(1)<=8 && decodedImage.getNomRangeBits(2)<=8 && !csMap.isOutputSigned(0) && !csMap.isOutputSigned(1) && !csMap.isOutputSigned(2) && decSpec.cts.isCompTransfUsed()){ warning("JJ2000 is quicker with one PPM output "+ "file than with 3 PGM/PGX output files when a"+ " component transformation is applied."); } } else { if(imwriter.length==3 && decodedImage.getNomRangeBits(0)<=8 && decodedImage.getNomRangeBits(1)<=8 && decodedImage.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/PGX output files when a"+ " component transformation is applied."); } } } // **** Report info **** int mrl = decSpec.dls.getMin(); if(verbose) { if(mrl!=res) { FacilityManager.getMsgLogger(). println("Reconstructing resolution "+res+" on "+ mrl+" ("+breader.getImgWidth(res)+"x"+ breader.getImgHeight(res)+")",8,8); } if(pl.getFloatParameter("rate")!=-1) { 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(decodedImage,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++) { if(outext.equalsIgnoreCase(".PGM")) { try { imwriter[i] = new ImgWriterPGM(out[i],decodedImage, i); } catch (IOException e) { error("Cannot write PGM 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; } } else if(outext.equalsIgnoreCase(".PGX")) { // Not PGM and not PPM means PGX used try { if(csMap!=null) { imwriter[i] =
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?