📄 decoder.java
字号:
/* * CVS identifier: * * $Id: Decoder.java,v 1.49 2001/02/16 14:54:39 qtxjoas Exp $ * * Class: Decoder * * Description: The decoder object * * * * COPYRIGHT: * * This software module was originally developed by Rapha雔 Grosbois and * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel * Askel鰂 (Ericsson Radio Systems AB); and Bertrand Berthelot, David * Bouchard, F閘ix Henry, Gerard Mozelle and Patrice Onno (Canon Research * Centre France S.A) in the course of development of the JPEG2000 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This * software module is an implementation of a part of the JPEG 2000 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio * Systems AB and Canon Research Centre France S.A (collectively JJ2000 * Partners) agree not to assert against ISO/IEC and users of the JPEG * 2000 Standard (Users) any of their rights under the copyright, not * including other intellectual property rights, for this software module * with respect to the usage by ISO/IEC and Users of this software module * or modifications thereof for use in hardware or software products * claiming conformance to the JPEG 2000 Standard. Those intending to use * this software module in hardware or software products are advised that * their use may infringe existing patents. The original developers of * this software module, JJ2000 Partners and ISO/IEC assume no liability * for use of this software module or modifications thereof. No license * or right to this software module is granted for non JPEG 2000 Standard * conforming products. JJ2000 Partners have full right to use this * software module for his/her own purpose, assign or donate this * software module to any third party and to inhibit third parties from * using this software module for non JPEG 2000 Standard conforming * products. This copyright notice must be included in all copies or * derivative works of this software module. * * Copyright (c) 1999/2000 JJ2000 Partners. * */package jj2000.j2k.decoder;import jj2000.j2k.quantization.dequantizer.*;import jj2000.j2k.wavelet.synthesis.*;import jj2000.j2k.image.invcomptransf.*;import jj2000.j2k.fileformat.reader.*;import jj2000.j2k.codestream.reader.*;import jj2000.j2k.entropy.decoder.*;import jj2000.j2k.image.output.*;import jj2000.j2k.codestream.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.roi.*;import jj2000.j2k.io.*;import jj2000.disp.*;import jj2000.j2k.*;import java.awt.image.*;import java.awt.event.*;import java.util.*;import java.awt.*;import java.net.*;import java.io.*;/** * This class is the main class of JJ2000's decoder. It instantiates all * objects and performs the decoding operations. It then writes the image to * the output file or displays it. * * <P>First the decoder should be initialized with a ParameterList object * given through the constructor. The when the run() method is invoked and the * decoder executes. The exit code of the class can be obtained with the * getExitCode() method, after the constructor and after the run method. A * non-zero value indicates that an error has ocurred. * * <P>The decoding chain corresponds to the following sequence of * modules: * * <ul> * <li>BitstreamReaderAgent</li> * <li>EntropyDecoder</li> * <li>ROIDeScaler</li> * <li>Dequantizer</li> * <li>InverseWT</li> * <li>ImgDataConverter</li> * <li>ComponentDemixer (if needed)</li> * <li>ImgDataAdapter (if ComponentDemixer is needed)</li> * <li>ImgWriter</li> * <li>BlkImgDataSrcImageProducer</li> * </ul> * * <P>The 2 last modules cannot be used at the same time and corresponds * respectively to the writing of decoded image into a file or the graphical * display of this same image. * * The behaviour of each module may be modified according to the current * tile-component. All the specifications are kept in modules extending * ModuleSpec and accessible through an instance of DecoderSpecs class. * * @see BitstreamReaderAgent * @see EntropyDecoder * @see ROIDeScaler * @see Dequantizer * @see InverseWT * @see ImgDataConverter * @see InvCompTransf * @see ImgWriter * @see BlkImgDataSrcImageProducer * @see ModuleSpec * @see DecoderSpecs * */public class Decoder implements Runnable { /** Reference to the TitleUpdater instance. Only used when decoded image * is displayed */ TitleUpdater title = null; /** False if the Decoder instance is self-contained process, false if * thrown by another process (i.e by a GUI)*/ private boolean isChildProcess = false; /** The exit code of the run method */ private int exitCode; /** The parameter list (arguments) */ private ParameterList pl; /** The default parameter list (arguments) */ private ParameterList defpl; /** The valid list of options prefixes */ private final static char vprfxs[] = {BitstreamReaderAgent.OPT_PREFIX, EntropyDecoder.OPT_PREFIX, ROIDeScaler.OPT_PREFIX, Dequantizer.OPT_PREFIX, InvCompTransf.OPT_PREFIX, HeaderDecoder.OPT_PREFIX}; /** Frame used to display decoded image */ private Frame win = null; /** The component where the image is to be displayed */ private ImgScrollPane isp; /** The parameter information for this class */ private final static String[][] pinfo = { { "u", "[on|off]", "Prints usage information. "+ "If specified all other arguments (except 'v') are ignored","off"}, { "v", "[on|off]", "Prints version and copyright information","off"}, { "verbose", "[on|off]", "Prints information about the decoded codestream","on"}, { "pfile", "<filename>", "Loads the arguments from the specified file. Arguments that are "+ "specified on the command line override the ones from the file.\n"+ "The arguments file is a simple text file with one argument per "+ "line of the following form:\n" + " <argument name>=<argument value>\n"+ "If the argument is of boolean type (i.e. its presence turns a "+ "feature on), then the 'on' value turns it on, while the 'off' "+ "value turns it off. The argument name does not include the '-' "+ "or '+' character. Long lines can be broken into several lines "+ "by terminating them with '\\'. Lines starting with '#' are "+ "considered as comments. This option is not recursive: any 'pfile' "+ "argument appearing in the file is ignored.",null}, { "res", "<resolution level index>", "Specifies the resolution level wanted for the decoded image"+ " (0 means the lowest available resolution, the last resolution "+ " level gives an image with original dimension). If given index"+ " is greater than the number of available resolution levels of the "+ "compressed image, the decoded image has the lowest available "+ "resolution (among all tile-components). Note that this option"+ " affects only the inverse wavelet transform and not the number "+ " of bytes read by the codestream parser: this number of bytes "+ "depends only on options '-nbytes' or '-rate'.",null}, { "i", "<filename or url>", "The file containing the JPEG 2000 compressed data. This can be "+ "either a JPEG 2000 codestream or a JP2 file containing a "+ "JPEG 2000 "+ "codestream. In the latter case the first codestream in the file "+ "will be decoded. If an URL is specified (e.g., http://...) "+ "the data will be downloaded and cached in memory before decoding. "+ "This is intended for easy use in applets, but it is not a very "+ "efficient way of decoding network served data.", null}, { "o", "<filename>", "This is the name of the file to which the decompressed image "+ "is written. If no output filename is given, the image is "+ "displayed on the screen. "+ "Output file format is PGX by default. If the extension"+ " is '.pgm' then a PGM file is written as output, however this is "+ "only permitted if the component bitdepth does not exceed 8. If "+ "the extension is '.ppm' then a PPM file is written, however this "+ "is only permitted if there are 3 components and none of them has "+ "a bitdepth of more than 8. If there is more than 1 component, "+ "suffices '-1', '-2', '-3', ... are added to the file name, just "+ "before the extension, except for PPM files where all three "+ "components are written to the same file.",null}, { "rate","<decoding rate in bpp>", "Specifies the decoding rate in bits per pixel (bpp) where the "+ "number of pixels is related to the image's original size (Note:"+ " this number is not affected by the '-res' option). "+ "The codestream is either parsed (default) or truncated depending "+ "the command line option '-parsing'. To specify the decoding "+ "rate in bytes, use '-nbytes' options instead.","100"}, { "nbytes","<decoding rate in bytes>", "Specifies the decoding rate in bytes. "+ "The codestream is either parsed (default) or truncated depending "+ "the command line option '-parsing'. To specify the decoding "+ "rate in bits per pixel, use '-rate' options instead.","-1"}, { "parsing", null, "Enable or not the parsing mode when decoding rate is specified "+ "('-nbytes' or '-rate' options). If it is false, the codestream "+ "is decoded as if it were truncated to the given rate. If it is "+ "true, the decoder creates, truncates and decodes a virtual layer"+ " progressive codestream with the same truncation points in each "+ "code-block.","on"}, { "debug", null, "Print debugging messages when an error is encountered.","off"}, { "cdstr_info", null, "Display information about the codestream. This information is: "+ "\n- Marker segments value in main and tile-part headers,"+ "\n- Tile-part length and position within the code-stream.", "off"} }; /** * Instantiates a decoder object, with the ParameterList object given as * argument and a component where to display the image if no output file * is specified. It also retrieves the default ParameterList. * * @param pl The ParameterList for this decoder (contains also defaults * values). * * @param isp The component where the image is to be displayed if not * output file is specified. If null a new frame will be created to * display the image. * */ public Decoder(ParameterList pl, ImgScrollPane isp) { this.pl = pl; defpl = pl.getDefaultParameterList(); this.isp = isp; } /** * Instantiates a decoder object, with the ParameterList object given as * argument. It also retrieves the default ParameterList. * * @param pl The ParameterList for this decoder (contains also defaults * values). * */ public Decoder(ParameterList pl) { this(pl,null); } /** * Returns the exit code of the class. This is only initialized after the * constructor and when the run method returns. * * @return The exit code of the constructor and the run() method. * */ public int getExitCode() { return exitCode; } /** * Returns the parameters that are used in this class. 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 and the third one is a long description of what the * parameter is. The synopsis or description may be 'null', in which case * it is assumed that there is no synopsis or description of the option, * respectively. * * @return the options name, their synopsis and their explanation. * */ public static String[][] getParameterInfo() { return pinfo; } /** * Runs the decoder. After completion the exit code is set, a non-zero * value indicates that an error ocurred. * * @see #getExitCode * */ public void run() { boolean verbose; int res; // resolution level to reconstruct int nComp; // number of components in the image String infile; RandomAccessIO in; FileFormatReader ff; String outfile="", outbase="", outext=""; String out[]; BitstreamReaderAgent breader; HeaderDecoder hd; EntropyDecoder entdec; ROIDeScaler roids; Dequantizer deq; InverseWT invWT; InvCompTransf ictransf; ImgWriter imwriter[] = null; ImgDataConverter converter,converter2; DecoderSpecs decSpec = null; int i; int depth[]; float rate; int nbytes; boolean disp = false; Image img = null; Dimension winDim,scrnDim; Insets ins = null; String btitle = ""; try { // **** Usage and version **** try { // Do we print version information? if (pl.getBooleanParameter("v")) { printVersionAndCopyright(); } // Do we print usage information? if (pl.getParameter("u").equals("on")) { printUsage(); return; // When printing usage => exit } // Do we print info ? verbose = pl.getBooleanParameter("verbose"); } catch (StringFormatException e) { error("An error occured while parsing the arguments:\n"+ e.getMessage(),1); if(pl.getParameter("debug").equals("on")) e.printStackTrace(); else { error("Use '-debug' option for more details",2); } return; } catch (NumberFormatException e) { error("An error occured while parsing the arguments:\n"+ e.getMessage(),1); if(pl.getParameter("debug").equals("on")) e.printStackTrace(); else { error("Use '-debug' option for more details",2); } return; } // **** Check parameters **** try { pl.checkList(vprfxs,pl.toNameArray(pinfo)); } catch (IllegalArgumentException e) { error(e.getMessage(),2); if(pl.getParameter("debug").equals("on")) e.printStackTrace(); else { error("Use '-debug' option for more details",2); } return; } // Get input file infile = pl.getParameter("i"); if (infile == null) { error("Input file ('-i' option) has not been specified",1); return; } // Get output files outfile = pl.getParameter("o"); if (outfile == null) { disp = true; } else if (outfile.lastIndexOf('.') != -1) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -