bitstreamreaderagent.java
来自「jpeg2000编解码」· Java 代码 · 共 1,084 行 · 第 1/3 页
JAVA
1,084 行
* the lowest number of decomposition levels of each component of the * tile.</p> * * <p>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 tile has only 3 resolution levels * available.</p> * * @param rl The (tile) resolution level. * * @return The total current tile's height in pixels. * */ public int getTileHeight(int rl) { // The minumum number of decomposition levels between all the // components int mindl = decSpec.dls.getMinInTile(getTileIdx()); if(rl>mindl){ throw new IllegalArgumentException("Requested resolution level"+ " is not available for, at "+ "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> * * <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.</p> * * @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> * * <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.</p> * * @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> * * <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.</p> * * @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> * * <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.</p> * * @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 tile-component for the * given (tile-component) resolution level. * * @param t The tile index * * @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 tile <tt>t</tt> * for resolution level <tt>rl</tt>. * */ public final int getTileCompWidth(int t,int c,int rl) { int tIdx = getTileIdx(); if(t!=tIdx) { throw new Error("Asking the tile-component width of a tile "+ "different from the current one."); } 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 tile-component for the * given (tile-component) resolution level. * * @param t The tile index. * * @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 getTileCompHeight(int t,int c,int rl) { int tIdx = getTileIdx(); if(t!=tIdx) { throw new Error("Asking the tile-component width of a tile "+ "different from the current one."); } 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> * * <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.</p> * * @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> * * <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.</p> * * @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 coordinate of the upper-left corner of the * specified resolution in the given component of the current tile. * * @param c The component index. * * @param rl The resolution level index. * */ public final int getResULX(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); } int tx0 = (int)Math.max(px+ctX*ntW,ax); int tcx0 = (int)Math.ceil(tx0/(double)getCompSubsX(c));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?