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

📄 headerencoder.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * CVS identifier: * * $Id: HeaderEncoder.java,v 1.1.1.1 2002/07/22 09:26:47 grosbois Exp $ * * Class:                   HeaderEncoder * * Description:             Write codestream headers. * * * * 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.codestream.writer;import jj2000.j2k.quantization.quantizer.*;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.wavelet.*;import jj2000.j2k.encoder.*;import jj2000.j2k.entropy.*;import jj2000.j2k.image.*;import jj2000.j2k.util.*;import jj2000.j2k.io.*;import jj2000.j2k.*;import java.util.*;import java.io.*;/** * This class writes almost of the markers and marker segments in main header * and in tile-part headers. It is created by the run() method of the Encoder * instance. *  * <p>A marker segment includes a marker and eventually marker segment * parameters. It is designed by the three letter code of the marker * associated with the marker segment. JPEG 2000 part I defines 6 types of * markers: * <ul>  * <li>Delimiting : SOC,SOT,SOD,EOC (written in FileCodestreamWriter).</li> * <li>Fixed information: SIZ.</li>  * <li>Functional: COD,COC,RGN,QCD,QCC,POC.</li> * <li> In bit-stream: SOP,EPH.</li> * <li> Pointer: TLM,PLM,PLT,PPM,PPT.</li>  * <li> Informational: CRG,COM.</li> * </ul></p> * * <p>Main Header is written when Encoder instance calls encodeMainHeader * whereas tile-part headers are written when the EBCOTRateAllocator instance * calls encodeTilePartHeader.</p> * * @see Encoder * @see Markers * @see EBCOTRateAllocator * */public class HeaderEncoder implements Markers, StdEntropyCoderOptions {    /** The prefix for the header encoder options: 'H' */    public final static char OPT_PREFIX = 'H';    /** The list of parameters that are accepted for the header encoder     * module. Options for this modules start with 'H'. */    private final static String[][] pinfo = {        {"Hjj2000_COM", null, "Writes or not the JJ2000 COM marker in the "+         "codestream", "on"},        {"HCOM", "<Comment 1>[#<Comment 2>[#<Comment3...>]]",         "Adds COM marker segments in the codestream. Comments must be "+         "separated with '#' and are written into distinct maker segments.",         null}    };    /** Nominal range bit of the component defining default values in QCD for     * main header */    private int defimgn;    /** Nominal range bit of the component defining default values in QCD for     * tile headers */    private int deftilenr;        /** The number of components in the image */    private int nComp;    /** Whether or not to write the JJ2000 COM marker segment */    private boolean enJJ2KMarkSeg = true;    /** Other COM marker segments specified in the command line */    private String otherCOMMarkSeg = null;    /** The ByteArrayOutputStream to store header data. This handler is kept     * in order to use methods not accessible from a general     * DataOutputStream. For the other methods, it's better to use variable     * hbuf.     *     * @see #hbuf */    protected ByteArrayOutputStream baos;        /** The DataOutputStream to store header data. This kind of object is     * useful to write short, int, .... It's constructor takes baos as     * parameter.     *     * @see #baos     **/    protected DataOutputStream hbuf;    /** The image data reader. Source of original data info */    protected ImgData origSrc;    /** An array specifying, for each component,if the data was signed or not     * */     protected boolean isOrigSig[];    /** Reference to the rate allocator */    protected PostCompRateAllocator ralloc;    /** Reference to the DWT module */    protected ForwardWT dwt;    /** Reference to the tiler module */    protected Tiler tiler;    /** Reference to the ROI module */    protected ROIScaler roiSc;    /** The encoder specifications */    protected EncoderSpecs encSpec;   /**     * Returns the parameters that are used in this class and implementing     * classes. 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, the third one is a long     * description of what the parameter is and the fourth is its default     * value. The synopsis or description may be 'null', in which case it is     * assumed that there is no synopsis or description of the option,     * respectively. Null may be returned if no options are supported.     *     * @return the options name, their synopsis and their explanation, or null     * if no options are supported.     * */    public static String[][] getParameterInfo() {        return pinfo;    }    /**     * Initializes the header writer with the references to the coding chain.     *     * @param origsrc The original image data (before any component mixing,     * tiling, etc.)     *     * @param isorigsig An array specifying for each component if it was     * originally signed or not.     *     * @param dwt The discrete wavelet transform module.     *     * @param tiler The tiler module.     *     * @param encSpec The encoder specifications     *     * @param roiSc The ROI scaler module.     *     * @param ralloc The post compression rate allocator.     *     * @param pl ParameterList instance.     * */    public HeaderEncoder(ImgData origsrc, boolean isorigsig[],                         ForwardWT dwt, Tiler tiler,EncoderSpecs encSpec, 			 ROIScaler roiSc, PostCompRateAllocator ralloc,                         ParameterList pl) {        pl.checkList(OPT_PREFIX,pl.toNameArray(pinfo));        if (origsrc.getNumComps() != isorigsig.length) {            throw new IllegalArgumentException();        }        this.origSrc   = origsrc;        this.isOrigSig = isorigsig;        this.dwt       = dwt;        this.tiler     = tiler;        this.encSpec   = encSpec;        this.roiSc     = roiSc;        this.ralloc    = ralloc;                baos = new ByteArrayOutputStream();        hbuf = new DataOutputStream(baos);        nComp = origsrc.getNumComps();        enJJ2KMarkSeg = pl.getBooleanParameter("Hjj2000_COM");        otherCOMMarkSeg = pl.getParameter("HCOM");    }    /**     * Resets the contents of this HeaderEncoder to its initial state. It     * erases all the data in the header buffer and reactualizes the     * headerLength field of the bit stream writer.     * */    public void reset() {        baos.reset();        hbuf = new DataOutputStream(baos);    }    /**      * Returns the byte-buffer used to store the codestream header.     *     * @return A byte array countaining codestream header     * */    protected byte[] getBuffer() {        return baos.toByteArray();    }    /**     * Returns the length of the header.     *     * @return The length of the header in bytes     * */    public int getLength() {        return hbuf.size();    }    /**     * Writes the header to the specified BinaryDataOutput.     *     * @param out Where to write the header.     * */    public void writeTo(BinaryDataOutput out) throws IOException {        int i,len;        byte buf[];        buf = getBuffer();        len = getLength();        for (i=0; i<len; i++) {            out.writeByte(buf[i]);        }    }    /**     * Returns the number of bytes used in the codestream header's buffer.     *     * @return Header length in buffer (without any header overhead)     * */    protected int getBufferLength() {        return baos.size();    }    /**     * Writes the header to the specified OutputStream.     *     * @param out Where to write the header.     * */    public void writeTo(OutputStream out) throws IOException {        out.write(getBuffer(),0,getBufferLength());    }    /**     * Start Of Codestream marker (SOC) signalling the beginning of a     * codestream.     * */    private void writeSOC() throws IOException {        hbuf.writeShort(SOC);    }    /**     * Writes SIZ marker segment of the codestream header. It is a fixed     * information marker segment containing informations about image and tile     * sizes. It is required in the main header immediately after SOC marker     * segment.     * */    private void writeSIZ() throws IOException {        int tmp;        // SIZ marker        hbuf.writeShort(SIZ);                // Lsiz (Marker length) corresponding to        // Lsiz(2 bytes)+Rsiz(2)+Xsiz(4)+Ysiz(4)+XOsiz(4)+YOsiz(4)+	// XTsiz(4)+YTsiz(4)+XTOsiz(4)+YTOsiz(4)+Csiz(2)+        // (Ssiz(1)+XRsiz(1)+YRsiz(1))*nComp        // markSegLen = 38 + 3*nComp;        int markSegLen = 38 + 3*nComp;        hbuf.writeShort(markSegLen);                // Rsiz (codestream capabilities)	hbuf.writeShort(0); // JPEG 2000 - Part I                // Xsiz (original image width)        hbuf.writeInt(tiler.getImgWidth()+tiler.getImgULX());                // Ysiz (original image height)        hbuf.writeInt(tiler.getImgHeight()+tiler.getImgULY());        	// XOsiz (horizontal offset from the origin of the reference	// grid to the left side of the image area)	hbuf.writeInt(tiler.getImgULX());	// YOsiz (vertical offset from the origin of the reference	// grid to the top side of the image area)	hbuf.writeInt(tiler.getImgULY());        // XTsiz (nominal tile width)        hbuf.writeInt(tiler.getNomTileWidth());                    // YTsiz (nominal tile height)        hbuf.writeInt(tiler.getNomTileHeight());        Coord torig = tiler.getTilingOrigin(null);	// XTOsiz (Horizontal offset from the origin of the reference	// grid to the left side of the first tile)	hbuf.writeInt(torig.x);	// YTOsiz (Vertical offset from the origin of the reference	// grid to the top side of the first tile)	hbuf.writeInt(torig.y);        // Csiz (number of components)        hbuf.writeShort(nComp);                        // Bit-depth and downsampling factors.        for(int c=0; c<nComp; c++) { // Loop on each component                        // Ssiz bit-depth before mixing            tmp = origSrc.getNomRangeBits(c)-1;                        tmp |= ( (isOrigSig[c]?1:0)<<SSIZ_DEPTH_BITS );            hbuf.write(tmp);                        // XRsiz (component sub-sampling value x-wise)            hbuf.write(tiler.getCompSubsX(c));                        // YRsiz (component sub-sampling value y-wise)            hbuf.write(tiler.getCompSubsY(c));                    } // End loop on each component            }    /**     * Writes COD marker segment. COD is a functional marker segment     * containing the code style default (coding style, decomposition,     * layering) used for compressing all the components in an image.     *     * <p>The values can be overriden for an individual component by a COC     * marker in either the main or the tile header.</p>     *     * @param mh Flag indicating whether this marker belongs to the main     * header     *

⌨️ 快捷键说明

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