📄 bitstreamreaderagent.java
字号:
"least, one component in"+ " tile: "+ctX+"x"+ctY); } int ctuly,ntuly; int dl = mindl-rl; // Number of decomposition to obtain this // resolution // Calculate starting Y of current tile at hi-res ctuly = (ctY == 0) ? ay : py+ctY*ntH; // Calculate starting Y of next tile Y-wise at hi-res ntuly = (ctY < ntY-1) ? py+(ctY+1)*ntH : ay+imgH; // The difference at the rl level is the height return (ntuly+(1<<dl)-1)/(1<<dl)-(ctuly+(1<<dl)-1)/(1<<dl); } /** * Returns the overall width of the image in pixels, for the given (image) * resolution level. This is the image's width without accounting for any * component subsampling or tiling. * * <P>Note: Image resolution level indexes may differ from tile-component * resolution index. They are indeed indexed starting from the lowest * number of decomposition levels of each component of each tile. * * <P>Example: For an image (1 tile) with 2 components (component 0 having * 2 decomposition levels and component 1 having 3 decomposition levels), * the first (tile-) component has 3 resolution levels and the second one * has 4 resolution levels, whereas the image has only 3 resolution levels * available. * * @param rl The image resolution level. * * @return The total image's width in pixels. * */ public int getImgWidth(int rl){ // The minimum number of decomposition levels of each // tile-component int mindl = decSpec.dls.getMin(); if(rl>mindl){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "least, one tile-component"); } // Retrieve number of decomposition levels corresponding to // this resolution level int dl = mindl - rl; return (ax+imgW+(1<<dl)-1)/(1<<dl)-(ax+(1<<dl)-1)/(1<<dl); } /** * Returns the overall height of the image in pixels, for the given * resolution level. This is the image's height without accounting for any * component subsampling or tiling. * * <P>Note: Image resolution level indexes may differ from tile-component * resolution index. They are indeed indexed starting from the lowest * number of decomposition levels of each component of each tile. * * <P>Example: For an image (1 tile) with 2 components (component 0 having * 2 decomposition levels and component 1 having 3 decomposition levels), * the first (tile-) component has 3 resolution levels and the second one * has 4 resolution levels, whereas the image has only 3 resolution levels * available. * * @param rl The image resolution level, from 0 to L. * * @return The total image's height in pixels. * */ public int getImgHeight(int rl){ int mindl = decSpec.dls.getMin(); if(rl>mindl){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "least, one tile-component"); } // Retrieve number of decomposition levels corresponding to this // resolution level int dl = mindl - rl; return (ay+imgH+(1<<dl)-1)/(1<<dl)-(ay+(1<<dl)-1)/(1<<dl); } /** * Returns the horizontal coordinate of the image origin, the top-left * corner, in the canvas system, on the reference grid at the specified * resolution level. * * <P>Note: Image resolution level indexes may differ from tile-component * resolution index. They are indeed indexed starting from the lowest * number of decomposition levels of each component of each tile. * * <P>Example: For an image (1 tile) with 2 components (component 0 having * 2 decomposition levels and component 1 having 3 decomposition levels), * the first (tile-) component has 3 resolution levels and the second one * has 4 resolution levels, whereas the image has only 3 resolution levels * available. * * @param rl The resolution level, from 0 to L. * * @return The horizontal coordinate of the image origin in the canvas * system, on the reference grid. * */ public int getImgULX(int rl){ int mindl = decSpec.dls.getMin(); if(rl>mindl){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "least, one tile-component"); } // Retrieve number of decomposition levels corresponding to this // resolution level int dl = mindl - rl; return (ax+(1<<dl)-1)/(1<<dl); } /** * Returns the vertical coordinate of the image origin, the top-left * corner, in the canvas system, on the reference grid at the specified * resolution level. * * <P>Note: Image resolution level indexes may differ from tile-component * resolution index. They are indeed indexed starting from the lowest * number of decomposition levels of each component of each tile. * * <P>Example: For an image (1 tile) with 2 components (component 0 having * 2 decomposition levels and component 1 having 3 decomposition levels), * the first (tile-) component has 3 resolution levels and the second one * has 4 resolution levels, whereas the image has only 3 resolution levels * available. * * @param rl The resolution level, from 0 to L. * * @return The vertical coordinate of the image origin in the canvas * system, on the reference grid. * */ public int getImgULY(int rl){ int mindl = decSpec.dls.getMin(); if(rl>mindl){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "least, one tile-component"); } // Retrieve number of decomposition levels corresponding to this // resolution level int dl = mindl - rl; return (ay+(1<<dl)-1)/(1<<dl); } /** * Returns the width in pixels of the specified component in the current * tile, for the given (tile-component) resolution level. * * @param c The index of the component, from 0 to N-1. * * @param rl The resolution level, from 0 to L. * * @return The width in pixels of component <tt>c</tt> in the current * tile. * */ public final int getCompWidth(int c,int rl) { int ntulx; int dl = mdl[c]-rl; // Calculate starting X of next tile X-wise at reference grid hi-res ntulx = (ctX < ntX-1) ? px+(ctX+1)*ntW : ax+imgW; // Convert reference grid hi-res to component grid hi-res ntulx = (ntulx+hd.getCompSubsX(c)-1)/hd.getCompSubsX(c); // Starting X of current tile at component grid hi-res is culx[c] // The difference at the rl level is the width return (ntulx+(1<<dl)-1)/(1<<dl)-(culx[c]+(1<<dl)-1)/(1<<dl); } /** * Returns the height in pixels of the specified component in the current * tile, for the given (tile-component) resolution level. * * @param c The index of the component, from 0 to N-1. * * @param rl The resolution level, from 0 to L. * * @return The height in pixels of component <tt>c</tt> in the current * tile. * */ public final int getCompHeight(int c, int rl){ int ntuly; int dl = mdl[c]-rl; // Revert level indexation (0 is hi-res) // Calculate starting Y of next tile Y-wise at reference grid hi-res ntuly = (ctY < ntY-1) ? py+(ctY+1)*ntH : ay+imgH; // Convert reference grid hi-res to component grid hi-res ntuly = (ntuly+hd.getCompSubsY(c)-1)/hd.getCompSubsY(c); // Starting Y of current tile at component grid hi-res is culy[c] // The difference at the rl level is the height return (ntuly+(1<<dl)-1)/(1<<dl)-(culy[c]+(1<<dl)-1)/(1<<dl); } /** * Returns the width in pixels of the specified component in the overall * image, for the given (component) resolution level. * * <P>Note: Component resolution level indexes may differ from * tile-component resolution index. They are indeed indexed starting from * the lowest number of decomposition levels of same component of each * tile. * * <P>Example: For an image (2 tiles) with 1 component (tile 0 having 2 * decomposition levels and tile 1 having 3 decomposition levels), the * first tile(-component) has 3 resolution levels and the second one has 4 * resolution levels, whereas the component has only 3 resolution levels * available. * * @param c The index of the component, from 0 to N-1. * * @param rl The resolution level, from 0 to L. * * @return The width in pixels of component <tt>c</tt> in the overall * image. * */ public final int getCompImgWidth(int c,int rl){ int sx,ex; int dl = decSpec.dls.getMinInComp(c)-rl; // indexation (0 is hi-res) // Calculate image starting x at component hi-res grid sx = (ax+hd.getCompSubsX(c)-1)/hd.getCompSubsX(c); // Calculate image ending (excluding) x at component hi-res grid ex = (ax+imgW+hd.getCompSubsX(c)-1)/hd.getCompSubsX(c); // The difference at the rl level is the width return (ex+(1<<dl)-1)/(1<<dl)-(sx+(1<<dl)-1)/(1<<dl); } /** * Returns the height in pixels of the specified component in the overall * image, for the given (component) resolution level. * * <P>Note: Component resolution level indexes may differ from * tile-component resolution index. They are indeed indexed starting from * the lowest number of decomposition levels of same component of each * tile. * * <P>Example: For an image (2 tiles) with 1 component (tile 0 having 2 * decomposition levels and tile 1 having 3 decomposition levels), the * first tile(-component) has 3 resolution levels and the second one has 4 * resolution levels, whereas the component has only 3 resolution levels * available. * * @param c The index of the component, from 0 to N-1. * * @param rl The resolution level, from 0 to L. * * @return The height in pixels of component <tt>c</tt> in the overall * image. * */ public final int getCompImgHeight(int c,int rl){ int sy,ey; int dl = decSpec.dls.getMinInComp(c)-rl; // indexation (0 is hi-res) // Calculate image starting x at component hi-res grid sy = (ay+hd.getCompSubsY(c)-1)/hd.getCompSubsY(c); // Calculate image ending (excluding) x at component hi-res grid ey = (ay+imgH+hd.getCompSubsY(c)-1)/hd.getCompSubsY(c); // The difference at the rl level is the width return (ey+(1<<dl)-1)/(1<<dl)-(sy+(1<<dl)-1)/(1<<dl); } /** * Changes the current tile, given the new indexes. An * IllegalArgumentException is thrown if the indexes do not correspond to * a valid tile. * * @param x The horizontal indexes the tile. * * @param y The vertical indexes of the new tile. * */ public abstract void setTile(int x, int y); /** * 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 abstract void nextTile(); /** * Returns the indexes of the current tile. These are 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 indexes (vertical and horizontal indexes). * */ public final Coord getTile(Coord co) { if (co != null) { co.x = ctX; co.y = ctY; return co; } else { return new Coord(ctX,ctY); } } /** * 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 ctY*ntX+ctX; } /** * Returns the horizontal and vertical offset of the upper-left corner of * the current tile, in the specified component, relative to the canvas * origin, for the specified resolution level. This is returned in the * component coordinates (not in the reference grid coordinates) reduced * to the specified resolution. These are the coordinates of the current * tile's (not active tile) upper-left corner relative to the canvas, in * the specified component, at the specified resolution. * * @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) * * @param rl The resolution level, from 0 to L. * * @return The horizontal and vertical offsets of the upper-left corner of * the current tile, for the specified component and resolution level, * relative to the canvas origin, in the component coordinates. * */ public final Coord getTileOff(Coord co, int c, int rl) { int x,y; int dl = mdl[c]-rl; if(dl<0){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "least, one component in "+ "tile: "+ctX+"x"+ctY); } // Convert coordinates from hi-res component grid to level rl x = (offX[c]+(1<<dl)-1)/(1<<dl); y = (offY[c]+(1<<dl)-1)/(1<<dl); if (co != null) { co.x = x; co.y = y; return co; } else { return new Coord(x,y); } } /** * 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 and resolution level. This is * actually the horizontal coordinate of the top-left corner of the image * data within the current tile. * * @param c The index of the component (between 0 and N-1) * * @param rl The resolution level, from 0 to L. * * @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, at resolution level 'rl'. * */ public final int getULX(int c, int rl) { int dl = mdl[c]-rl; if(dl<0){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "least, one component in "+ "tile: "+ctX+"x"+ctY); } return (culx[c]+(1<<dl)-1)/(1<<dl); } /** * 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 and resolution level. This is actually the * vertical coordinate of the top-left corner of the image data within the * current tile. * * @param c The index of the component (between 0 and N-1) *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -