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

📄 tiler.java

📁 jpeg2000编解码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * new array may have been created. Instead, get the array from     * <tt>blk</tt> after the method has returned.</p>     *     * <p>The returned data may have its 'progressive' attribute set. In this     * case the returned data is only an approximation of the "final"     * data.</p>     *     * @param blk Its coordinates and dimensions specify the area to return,     * relative to the current tile. Some fields in this object are modified     * to return the data.     *     * @param c The index of the component from which to get the data.     *     * @return The requested DataBlk     *     * @see #getCompData     * */    public final DataBlk getInternCompData(DataBlk blk,int c) {        // Check that block is inside tile        if (blk.ulx<0 || blk.uly<0 || blk.w>compW[c] || blk.h>compH[c]) {            throw new IllegalArgumentException("Block is outside the tile");        }        // Translate to the sources coordinates        int incx = (int)Math.ceil(x0siz/(double)src.getCompSubsX(c));        int incy = (int)Math.ceil(y0siz/(double)src.getCompSubsY(c));        blk.ulx -= incx;        blk.uly -= incy;        blk = src.getInternCompData(blk,c);        // Translate back to the tiled coordinates        blk.ulx += incx;        blk.uly += incy;	return blk;    }    /**     * Returns, in the blk argument, a block of image data containing the     * specifed rectangular area, in the specified component. The data is     * returned, as a copy of the internal data, therefore the returned data     * can be modified "in place".     *     * <p>The rectangular area to return is specified by the 'ulx', 'uly', 'w'     * and 'h' members of the 'blk' argument, relative to the current     * tile. These members are not modified by this method. The 'offset' of     * the returned data is 0, and the 'scanw' is the same as the block's     * width. See the 'DataBlk' class.</p>     *     * <p>This method, in general, is less efficient than the     * 'getInternCompData()' method since, in general, it copies the     * data. However if the array of returned data is to be modified by the     * caller then this method is preferable.</p>     *     * <p>If the data array in 'blk' is 'null', then a new one is created. If     * the data array is not 'null' then it is reused, and it must be large     * enough to contain the block's data. Otherwise an 'ArrayStoreException'     * or an 'IndexOutOfBoundsException' is thrown by the Java system.</p>     *     * <p>The returned data may have its 'progressive' attribute set. In this     * case the returned data is only an approximation of the "final"     * data.</p>     *     * @param blk Its coordinates and dimensions specify the area to return,     * relative to the current tile. If it contains a non-null data array,     * then it must be large enough. If it contains a null data array a new     * one is created. Some fields in this object are modified to return the     * data.     *     * @param c The index of the component from which to get the data.     *     * @return The requested DataBlk     *     * @see #getInternCompData     * */    public final DataBlk getCompData(DataBlk blk,int c) {        // Check that block is inside tile        if (blk.ulx<0 || blk.uly<0 || blk.w>compW[c] || blk.h>compH[c]) {            throw new IllegalArgumentException("Block is outside the tile");        }        // Translate to the source's coordinates        int incx = (int)Math.ceil(x0siz/(double)src.getCompSubsX(c));        int incy = (int)Math.ceil(y0siz/(double)src.getCompSubsY(c));        blk.ulx -= incx;        blk.uly -= incy;        blk = src.getCompData(blk,c);        // Translate back to the tiled coordinates        blk.ulx += incx;        blk.uly += incy;	return blk;    }    /**     * Changes the current tile, given the new tile indexes. An     * IllegalArgumentException is thrown if the coordinates do not correspond     * to a valid tile.     *     * @param x The horizontal index of the tile.     *     * @param y The vertical index of the new tile.     * */    public final void setTile(int x,int y) {        // Check tile indexes        if (x<0 || y<0 || x>=ntX || y>=ntY) {            throw new IllegalArgumentException("Tile's indexes out of bounds");        }        // Set new current tile        tx = x;        ty = y;        // Calculate tile origins        int tx0 = (x!=0) ? xt0siz+x*xtsiz : x0siz;        int ty0 = (y!=0) ? yt0siz+y*ytsiz : y0siz;        int tx1 = (x!=ntX-1) ? (xt0siz+(x+1)*xtsiz) :             (x0siz+src.getImgWidth());        int ty1 = (y!=ntY-1) ? (yt0siz+(y+1)*ytsiz) :             (y0siz+src.getImgHeight());        // Set general variables        tileW = tx1 - tx0;        tileH = ty1 - ty0;        // Set component specific variables        int nc = src.getNumComps();        if(compW==null) compW = new int[nc];        if(compH==null) compH = new int[nc];        if(tcx0==null) tcx0 = new int[nc];        if(tcy0==null) tcy0 = new int[nc];        for (int i=0; i<nc ; i++) {            tcx0[i] = (int)Math.ceil(tx0/(double)src.getCompSubsX(i));            tcy0[i] = (int)Math.ceil(ty0/(double)src.getCompSubsY(i));	    compW[i] = (int)Math.ceil(tx1/(double)src.getCompSubsX(i)) -                tcx0[i];	    compH[i] = (int)Math.ceil(ty1/(double)src.getCompSubsY(i)) -                tcy0[i];        }    }    /**     * Advances to the next tile, in standard scan-line order (by rows then     * columns). An NoNextElementException is thrown if the current tile is     * the last one (i.e. there is no next tile).     * */    public final void nextTile() {        if (tx==ntX-1 && ty==ntY-1) { // Already at last tile            throw new NoNextElementException();        } else if (tx<ntX-1) { // If not at end of current tile line            setTile(tx+1,ty);        } else { // First tile at next line            setTile(0,ty+1);        }    }    /**     * Returns the horizontal and vertical indexes of the current tile.     *     * @param co If not null this object is used to return the     * information. If null a new one is created and returned.     *     * @return The current tile's horizontal and vertical indexes..     * */    public final Coord getTile(Coord co) {        if (co != null) {            co.x = tx;            co.y = ty;            return co;        } else {            return new Coord(tx,ty);        }    }    /**     * Returns the index of the current tile, relative to a standard scan-line     * order.     *     * @return The current tile's index (starts at 0).     * */    public final int getTileIdx() {        return ty*ntX+tx;    }    /**     * Returns the horizontal coordinate of the upper-left corner of the     * specified component in the current tile.     *     * @param c The component index.     * */    public final int getCompULX(int c) {        return tcx0[c];    }    /**     * Returns the vertical coordinate of the upper-left corner of the     * specified component in the current tile.     *     * @param c The component index.     * */    public final int getCompULY(int c) {        return tcy0[c];    }    /** Returns the horizontal tile partition offset in the reference grid */    public int getTilePartULX() {        return xt0siz;    }    /** Returns the vertical tile partition offset in the reference grid */    public int getTilePartULY() {        return yt0siz;    }    /**     * Returns the horizontal coordinate of the image origin, the top-left     * corner, in the canvas system, on the reference grid.     *     * @return The horizontal coordinate of the image origin in the canvas     * system, on the reference grid.     * */    public final int getImgULX() {        return x0siz;    }    /**     * Returns the vertical coordinate of the image origin, the top-left     * corner, in the canvas system, on the reference grid.     *     * @return The vertical coordinate of the image origin in the canvas     * system, on the reference grid.     * */    public final int getImgULY() {        return y0siz;    }    /**     * Returns the number of tiles in the horizontal and vertical directions.     *     * @param co If not null this object is used to return the information. If     * null a new one is created and returned.     *     * @return The number of tiles in the horizontal (Coord.x) and vertical     * (Coord.y) directions.     * */    public final Coord getNumTiles(Coord co) {        if (co != null) {            co.x = ntX;            co.y = ntY;            return co;        } else {            return new Coord(ntX,ntY);        }    }    /**     * Returns the total number of tiles in the image.     *     * @return The total number of tiles in the image.     * */    public final int getNumTiles() {        return ntX*ntY;    }    /**     * Returns the nominal width of the tiles in the reference grid.     *     * @return The nominal tile width, in the reference grid.     * */    public final int getNomTileWidth() {        return xtsiz;    }    /**     * Returns the nominal width of the tiles in the reference grid.     *     * @return The nominal tile width, in the reference grid.     * */    public final int getNomTileHeight() {        return ytsiz;    }    /**     * Returns the tiling origin, referred to as '(xt0siz,yt0siz)' in the     * codestream header (SIZ marker segment).     *     * @param co If not null this object is used to return the information. If     * null a new one is created and returned.     *     * @return The coordinate of the tiling origin, in the canvas system, on     * the reference grid.     *     * @see ImgData     * */    public final Coord getTilingOrigin(Coord co) {        if (co != null) {            co.x = xt0siz;            co.y = yt0siz;            return co;        } else {            return new Coord(xt0siz,yt0siz);        }    }    /**     * Returns a String object representing Tiler's informations     *     * @return Tiler's infos in a string     * */    public String toString() {	return "Tiler: source= "+src+	    "\n"+getNumTiles()+" tile(s), nominal width="+xtsiz+	    ", nominal height="+ytsiz;    }}

⌨️ 快捷键说明

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