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

📄 tiler.java

📁 jpeg2000算法实现
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * is created if necessary. The implementation of this interface may     * choose to return the same array or a new one, depending on what is more     * efficient. Therefore, the data array in <tt>blk</tt> prior to the     * method call should not be considered to contain the returned data, a     * new array may have been created. Instead, get the array from     * <tt>blk</tt> after the method has returned.     *     * <P>The returned data may have its 'progressive' attribute set. In this     * case the returned data is only an approximation of the "final" data.     *     * @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.ulx+blk.w > bw[c] || blk.uly+blk.h > bh[c]) {            throw new IllegalArgumentException("Block is outside the tile");        }        // Translate to the sources coordinates        blk.ulx += iulx[c];        blk.uly += iuly[c];        blk = src.getInternCompData(blk,c);        // Translate back to the tiled coordinates        blk.ulx -= iulx[c];        blk.uly -= iuly[c];	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>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>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>The returned data may have its 'progressive' attribute set. In this     * case the returned data is only an approximation of the "final" data.     *     * @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 n The index of the component from which to get the data.     *     * @return The requested DataBlk     *     * @see #getInternCompData     * */    public final DataBlk getCompData(DataBlk blk, int n) {        // Check that block is inside tile        if (blk.ulx < 0 || blk.uly < 0 ||             blk.ulx+blk.w > bw[n] || blk.uly+blk.h > bh[n]) {            throw new IllegalArgumentException("Block is outside the tile");        }        // Translate to the source's coordinates        blk.ulx += iulx[n];        blk.uly += iuly[n];        blk = src.getCompData(blk,n);        // Translate back to the tiled coordinates        blk.ulx -= iulx[n];        blk.uly -= iuly[n];	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) {        int i;          // counter        int ctox,ctoy;  // new current tile origin in the reference grid        int tonx;       // x of the origin of the next tile in the X direction        int tony;       // y of the origin of the next tile in the Y direction        // Check tile indexes        if (x < 0 || y < 0 || x >= nht || y >= nvt) {            throw new IllegalArgumentException("Tile's indexes out of bounds");        }        // Set new current tile        tx = x;        ty = y;        // Calculate tile origins        ctox = (x != 0) ? px+x*nw : ax;        ctoy = (y != 0) ? py+y*nh : ay;        tonx = (x != nht-1) ? px+(x+1)*nw : ax+src.getImgWidth();        tony = (y != nvt-1) ? py+(y+1)*nh : ay+src.getImgHeight();        // Set general variables        cw = tonx - ctox;        ch = tony - ctoy;        // Set component specific variables        for (i = src.getNumComps()-1; i >= 0 ; i--) {	    bw[i] = (tonx+src.getCompSubsX(i)-1)/src.getCompSubsX(i) -                (ctox+src.getCompSubsX(i)-1)/src.getCompSubsX(i);	    bh[i] = (tony+src.getCompSubsY(i)-1)/src.getCompSubsY(i) -                (ctoy+src.getCompSubsY(i)-1)/src.getCompSubsY(i);            offX[i] = (px+x*nw+src.getCompSubsX(i)-1)/src.getCompSubsX(i);            offY[i] = (py+y*nh+src.getCompSubsY(i)-1)/src.getCompSubsY(i);            iulx[i] = (ctox+src.getCompSubsX(i)-1)/src.getCompSubsX(i)-                (ax+src.getCompSubsX(i)-1)/src.getCompSubsX(i);            iuly[i] = (ctoy+src.getCompSubsY(i)-1)/src.getCompSubsY(i)-                (ay+src.getCompSubsY(i)-1)/src.getCompSubsY(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 == nht-1 && ty == nvt-1) { // Already at last tile            throw new NoNextElementException();        }        else if (tx < nht-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*nht+tx;    }    /**     * Returns the horizontal and vertical offset of the upper-left corner of     * the current tile, in the specified component, relative to the canvas     * origin, in the component coordinates (not in the reference grid     * coordinates). These are the coordinates of the current tile's (not     * active tile) upper-left corner relative to the canvas.     *     * @param co If not null the object is used to return the values,     * if null a new one is created and returned.     *     * @param c The index of the component (between 0 and N-1).     *     * @return The horizontal and vertical offsets of the upper-left corner of     * the current tile, for the specified component, relative to the canvas     * origin, in the component coordinates.     * */    public final Coord getTileOff(Coord co, int c) {        if (co != null) {            co.x = offX[c];            co.y = offY[c];            return co;        }        else {            return new Coord(offX[c],offY[c]);        }    }    /**     * Returns the horizontal coordinate of the upper-left corner of the     * active tile, with respect to the canvas origin, in the component     * coordinates, for the specified component.     *     * @param c The index of the component (between 0 and N-1)     *     * @return The horizontal coordinate of the upper-left corner of the     * active tile, with respect to the canvas origin, for component 'c', in     * the component coordinates.     * */    public final int getULX(int c) {        return iulx[c]+(ax+src.getCompSubsX(c)-1)/src.getCompSubsX(c);    }    /**     * Returns the vertical coordinate of the upper-left corner of the active     * tile, with respect to the canvas origin, in the component coordinates,     * for the specified component.     *     * @param c The index of the component (between 0 and N-1)     *     * @return The vertical coordinate of the upper-left corner of the active     * tile, with respect to the canvas origin, for component 'c', in the     * component coordinates.     * */    public final int getULY(int c) {        return iuly[c]+(ay+src.getCompSubsY(c)-1)/src.getCompSubsY(c);    }    /**     * 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 ax;    }    /**     * 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 ay;    }    /**     * 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 = nht;            co.y = nvt;            return co;        }        else {            return new Coord(nht,nvt);        }    }    /**     * Returns the total number of tiles in the image.     *     * @return The total number of tiles in the image.     * */    public final int getNumTiles() {        return nht*nvt;    }    /**     * 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 nw;    }    /**     * 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 nh;    }    /**     * Returns the tiling origin, refferred to as '(Px,Py)' in the 'ImgData'     * interface.     *     * @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 = px;            co.y = py;            return co;        }        else {            return new Coord(px,py);        }    }    /**     * 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= "+nw+	    ", nominal height= "+nh;    }}

⌨️ 快捷键说明

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