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

📄 encoder.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/* * CVS identifier: * * $Id: Encoder.java,v 1.55 2001/02/26 10:12:54 grosbois Exp $ * * Class:                   Encoder * * Description:             The encoder object * *                          [from CmdLnEncoder, Diego SANTA CRUZ, May-19-1999] * * * 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.encoder;import jj2000.j2k.quantization.quantizer.*;import jj2000.j2k.image.forwcomptransf.*;import jj2000.j2k.codestream.writer.*;import jj2000.j2k.fileformat.writer.*;import jj2000.j2k.wavelet.analysis.*;import jj2000.j2k.entropy.encoder.*;import jj2000.j2k.quantization.*;import jj2000.j2k.image.input.*;import jj2000.j2k.roi.encoder.*;import jj2000.j2k.codestream.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.*;import java.util.*;import java.io.*;/** * This class is the main class of JJ2000's encoder. It instantiates all * objects of the chain and launchs the encoding process. It then writes the * header and the compressed bit stream to the output file. * * <P>First the encoder should be initialized with a ParameterList object * provided through the constructor. Then, the run() method is invoked and the * encoder 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 occurred. * * <P>The modules are inserted in the encoding chain with the following * order: * * <ul> * <li>ImgReader</li> * <li>ImgDataJoiner (if multiple image readers)</li> * <li>ForwCompTransf</li> * <li>Tiler</li> * <li>ImgDataConverter</li> * <li>ForwardWT</li> * <li>Quantizer</li> * <li>ROIScaler</li> * <li>EntropyCoder</li> * <li>PostCompRateAllocator</li> * </ul> * * <P>The encoder uses a pull model. This means that the last module * (PostCompRateAllocator) requests data from its source (EntropyCoder), ... * * <P>Writing of the codestream writing (header+bit stream) is realized by * HeaderEncoder and CodestreamWriter. * * <P>Many modules of the encoder may behave differently depending on the * tile-component. The specifications of their behaviour are kept in * specialized modules extending ModuleSpec class. All these modules are * accessible through an instance of EncoderSpecs class. * * @see ImgReader * @see ImgDataJoiner * @see ForwCompTransf * @see Tiler * @see ImgDataConverter * @see ForwardWT * @see Quantizer * @see ROIScaler * @see EntropyCoder * @see PostCompRateAllocator * @see HeaderEncoder * @see CodestreamWriter * @see ModuleSpec * @see EncoderSpecs * */public class Encoder implements Runnable{    /** 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 */    public final static char vprfxs[] = {	ForwCompTransf.OPT_PREFIX, // Mixer module	AnWTFilter.OPT_PREFIX, // Filters type spec	ForwardWT.OPT_PREFIX, // Wavelets module	Quantizer.OPT_PREFIX, // Quantizer module	ROIScaler.OPT_PREFIX, // ROI module	EntropyCoder.OPT_PREFIX, // Coding modules	PostCompRateAllocator.OPT_PREFIX, // Rate allocator	PktEncoder.OPT_PREFIX, // Packet encoder    };    /** The parameter information for this class */    private final static String[][] pinfo = {        { "debug", null,          "Print debugging messages when an error is encountered.","off"},        { "disable_jp2_extension", "[on|off]",          "JJ2000 automatically adds .jp2 extension when using 'file_format'"+          "option. This option disables it when on.", "off"},        { "file_format", "[on|off]",          "Puts the JPEG 2000 codestream in a JP2 file format wrapper.","off"},        { "pph_tile", "[on|off]",          "Packs the packet headers in the tile headers.","off"},        { "pph_main", "[on|off]",          "Packs the packet headers in the main header.","off"},        { "pfile", "<filename of arguments file>",          "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},        { "tile_parts", "<packets per tile-part>",          "This option specifies the maximum number of packets to have in "+          "one tile-part. 0 means include all packets in first tile-part "+          "of each tile","0"},        { "tiles", "<nominal tile width> <nominal tile height>",          "This option specifies the maximum tile dimensions to use. "+          "If both dimensions are 0 then no tiling is used.","0 0"},        { "ref", "<x> <y>",          "Sets the origin of the image in the canvas system. It sets the "+          "coordinate of the top-left corner of the image reference grid, "+          "with respect to the canvas origin","0 0"},        { "tref", "<x> <y>",          "Sets the origin of the tile partitioning on the reference grid, "+          "with respect to the canvas origin. The value of 'x' ('y') "+          "specified can not be larger than the 'x' one specified in the ref "+          "option.","0 0"},        { "rate", "<output bitrate in bpp>",          "This is the output bitrate in bits per pixel.","100"},        { "lossless", "[on|off]",           "Specifies a lossless compression for the encoder. This options"+          " is equivalent to use reversible quantization ('-Qtype "+          "reversible')"+          " and 5x3 wavelet filters pair ('-Ffilters w5x3'). Note that "+          "this option cannot be used with '-rate'. When this option is "+          "off, the quantization type and the filters pair is defined by "+          "'-Qtype' and '-Ffilters' respectively.","off"},        { "i", "<image file> [<image file> [<image file> ... ]]",          "Mandatory argument. This option specifies the name of the input "+          "image files. Supported formats are PGM (raw), PPM (raw) and PGX, "+          "which is a simple extension of the PGM file format for single "+          "component data supporting arbitrary bitdepths. If the extension "+          "is '.pgm', PGM-raw file format is assumed, if the extension is "+          "'.ppm', PPM-raw file format is assumed, otherwise PGX file "+          "format is assumed. PGM and PPM files are assumed to be 8 bits "+          "deep. A multi-component image can be specified by either "+          "specifying several PPM and/or PGX files, or by specifying one "+          "PPM file.",null},        { "o", "<file name>",          "Mandatory argument. This option specifies the name of the output "+          "file to which the codestream will be written.",null},        { "verbose", null,          "Prints information about the obtained bit stream.","on"},        { "v", "[on|off]",          "Prints version and copyright information.","off"},        { "u", "[on|off]",          "Prints usage information. "+          "If specified all other arguments (except 'v') are ignored","off"},    };    /**     * Instantiates an encoder object, width the ParameterList object     * given as argument. It also retrieves the default ParameterList.     *     * @param pl The ParameterList for this decoder (contains also     * defaults values);     * */    public Encoder(ParameterList pl) {	this.pl = pl;	defpl = pl.getDefaultParameterList();    }    /**     * 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;    }    /**     * Runs the encoder. After completion the exit code is set, a     * non-zero value indicates that an error ocurred.     *     * @see #getExitCode     * */    public void run() {        boolean verbose;        boolean useFileFormat = false;        boolean pphTile = false;        boolean pphMain = false;        boolean tempSop = false;        boolean tempEph = false;        ImgReader imreader[];        String inext,infile;        StreamTokenizer stok;        StringTokenizer sgtok;        int ncomp;        boolean ppminput;        Vector imreadervec;        boolean imsigned[];        BlkImgDataSrc imgsrc;        int i;        int imgcmpidxs[];        int tw,th;        int refx,refy;        int trefx,trefy;        int pktspertp;        Tiler imgtiler;        BlkImgDataSrc cursrc;        ForwCompTransf fctransf;	ImgDataConverter converter;        EncoderSpecs encSpec;        ForwardWT dwt;        Quantizer quant;        ROIScaler rois;        EntropyCoder ecoder;        PostCompRateAllocator ralloc;        HeaderEncoder headenc;        CodestreamWriter bwriter;        FileFormatWriter ffw;        String outname;        float rate;        int fileLength;        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;            }            // **** Get general parameters ****                        // Check that we have the mandatory parameters            if (pl.getParameter("i") == null) {                error("Mandatory input file is missing (-i option)",2);                return;            }            if (pl.getParameter("o") == null) {                error("Mandatory output file is missing (-o option)",2);                return;            }            outname = pl.getParameter("o");            if (pl.getParameter("file_format").equals("on"))                useFileFormat = true;            if(useFileFormat) {                String outext = null;                String outns = outname;                if(outname.lastIndexOf('.')!=-1) {                    outext = outname.substring(outname.lastIndexOf('.'),                                               outname.length());                    outns = outname.substring(0,outname.lastIndexOf('.'));                }                if(outext==null || !outext.equalsIgnoreCase(".jp2")) {                    if(!pl.getBooleanParameter("disable_jp2_extension")) {                        FacilityManager.getMsgLogger().                            printmsg(MsgLogger.INFO,"JPEG 2000 file names"+                                     " end with .jp2 extension when using"+                                     " the file format of part 1. This "+                                     "extension is automatically"+                                     " added by JJ2000. Use "+                                     "'-disable_jp2_extension' to "+                                     "disable it.");                                                outname = outns+".jp2";                    }                }            }            if (pl.getParameter("tiles") == null) {                error("No tiles option specified",2);                return;            }            if (pl.getParameter("pph_tile").equals("on")){                pphTile = true;

⌨️ 快捷键说明

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