📄 invcomptransf.java
字号:
return src.getInternCompData(blk,c); switch(transfType){ case NONE: return src.getInternCompData(blk,c); case INV_RCT: return invRCT(blk,c); case INV_ICT: return invICT(blk,c); default: throw new IllegalArgumentException("Non JPEG 2000 part I"+ " component transformation"); } } /** * Apply inverse component transformation to obtain requested component * from specified block of data. Whatever the type of requested DataBlk, * it always returns a DataBlkInt. * * @param blk Determine the rectangular area to return * * @param c The index of the requested component * * @return Data of requested component * */ private DataBlk invRCT(DataBlk blk,int c){ // If the component number is three or greater, return original data if (c>=3 && c < getNumComps()) { // Requesting a component whose index is greater than 3 return src.getInternCompData(blk,c); } // If asking a component for the first time for this block, // do transform for the 3 components else if ((outdata[c] == null)|| (dbi.ulx > blk.ulx) || (dbi.uly > blk.uly) || (dbi.ulx+dbi.w < blk.ulx+blk.w) || (dbi.uly+dbi.h < blk.uly+blk.h)) { int k,k0,k1,k2,mink,i; int w = blk.w; //width of output block int h = blk.h; //height of ouput block //Reference to output block data array outdata[c] = (int[]) blk.getData(); //Create data array of blk if necessary if(outdata[c] == null || outdata[c].length!=h*w){ outdata[c] = new int[h * w]; blk.setData(outdata[c]); } outdata[(c+1)%3] = new int[outdata[c].length]; outdata[(c+2)%3] = new int[outdata[c].length]; if(block0==null || block0.getDataType()!=DataBlk.TYPE_INT) block0 = new DataBlkInt(); if(block1==null || block1.getDataType()!=DataBlk.TYPE_INT) block1 = new DataBlkInt(); if(block2==null || block2.getDataType()!=DataBlk.TYPE_INT) block2 = new DataBlkInt(); block0.w = block1.w = block2.w = blk.w; block0.h = block1.h = block2.h = blk.h; block0.ulx = block1.ulx = block2.ulx = blk.ulx; block0.uly = block1.uly = block2.uly = blk.uly; int data0[],data1[],data2[]; // input data arrays // Fill in buffer blocks (to be read only) // Returned blocks may have different size and position block0 = (DataBlkInt)src.getInternCompData(block0, 0); data0 = (int[]) block0.getData(); block1 = (DataBlkInt)src.getInternCompData(block1, 1); data1 = (int[]) block1.getData(); block2 = (DataBlkInt)src.getInternCompData(block2, 2); data2 = (int[]) block2.getData(); // Set the progressiveness of the output data blk.progressive = block0.progressive || block1.progressive || block2.progressive; blk.offset = 0; blk.scanw = w; // set attributes of the DataBlk used for buffering dbi.progressive = blk.progressive; dbi.ulx = blk.ulx; dbi.uly = blk.uly; dbi.w = blk.w; dbi.h = blk.h; // Perform conversion // Initialize general indexes k = w*h-1; k0 = block0.offset+(h-1)*block0.scanw+w-1; k1 = block1.offset+(h-1)*block1.scanw+w-1; k2 = block2.offset+(h-1)*block2.scanw+w-1; for( i = h-1; i >=0; i--){ for(mink = k-w; k > mink; k--, k0--, k1--, k2--){ outdata[1][k] = (data0[k0] - ((data1[k1]+data2[k2])>>2) ); outdata[0][k] = data2[k2] + outdata[1][k]; outdata[2][k] = data1[k1] + outdata[1][k]; } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k1 -= block1.scanw - w; k2 -= block2.scanw - w; } outdata[c] = null; } else if((c>=0)&&(c<3)){ //Asking for the 2nd or 3rd block component blk.setData(outdata[c]); blk.progressive = dbi.progressive; blk.offset = (blk.uly-dbi.uly)*dbi.w+blk.ulx-dbi.ulx; blk.scanw = dbi.w; outdata[c] = null; } else { // Requesting a non valid component index throw new IllegalArgumentException(); } return blk; } /** * Apply inverse irreversible component transformation to obtain requested * component from specified block of data. Whatever the type of requested * DataBlk, it always returns a DataBlkFloat. * * @param blk Determine the rectangular area to return * * @param c The index of the requested component * * @return Data of requested component * */ private DataBlk invICT(DataBlk blk,int c){ if(c>=3 && c<getNumComps()) { // Requesting a component whose index is greater than 3 int k,k0,k1,k2,mink,i; int w = blk.w; //width of output block int h = blk.h; //height of ouput block int outdata[]; // array of output data //Reference to output block data array outdata = (int[]) blk.getData(); //Create data array of blk if necessary if( outdata == null ) { outdata = new int[h * w]; blk.setData(outdata); } // Variables DataBlkFloat indb = new DataBlkFloat(blk.ulx,blk.uly,w,h); float indata[]; // input data array // Get the input data // (returned block may be larger than requested one) src.getInternCompData(indb,c); indata = (float[]) indb.getData(); // Copy the data converting from int to int k = w*h-1; k0 = indb.offset+(h-1)*indb.scanw+w-1; for (i=h-1; i >=0; i--) { for (mink = k-w; k > mink; k--, k0--) { outdata[k] = (int) (indata[k0]); } // Jump to beggining of previous line in input k0 -= indb.scanw - w; } // Set the progressivity and offset blk.progressive = indb.progressive; blk.offset = 0; blk.scanw = w; } // If asking a component for the first time for this block, // do transform for the 3 components else if ((outdata[c] == null)|| (dbi.ulx > blk.ulx) || (dbi.uly > blk.uly) || (dbi.ulx+dbi.w < blk.ulx+blk.w) || (dbi.uly+dbi.h < blk.uly+blk.h)) { int k,k0,k1,k2,mink,i; int w = blk.w; //width of output block int h = blk.h; //height of ouput block //Reference to output block data array outdata[c] = (int[]) blk.getData(); //Create data array of blk if necessary if(outdata[c] == null || outdata[c].length!=w*h){ outdata[c] = new int[h * w]; blk.setData(outdata[c]); } outdata[(c+1)%3] = new int[outdata[c].length]; outdata[(c+2)%3] = new int[outdata[c].length]; if(block0==null || block0.getDataType()!=DataBlk.TYPE_FLOAT) block0 = new DataBlkFloat(); if(block2==null || block2.getDataType()!=DataBlk.TYPE_FLOAT) block2 = new DataBlkFloat(); if(block1==null || block1.getDataType()!=DataBlk.TYPE_FLOAT) block1 = new DataBlkFloat(); block0.w = block2.w = block1.w = blk.w; block0.h = block2.h = block1.h = blk.h; block0.ulx = block2.ulx = block1.ulx = blk.ulx; block0.uly = block2.uly = block1.uly = blk.uly; float data0[],data1[],data2[]; // input data arrays // Fill in buffer blocks (to be read only) // Returned blocks may have different size and position block0 = (DataBlkFloat)src.getInternCompData(block0, 0); data0 = (float[]) block0.getData(); block2 = (DataBlkFloat)src.getInternCompData(block2, 1); data2 = (float[]) block2.getData(); block1 = (DataBlkFloat)src.getInternCompData(block1, 2); data1 = (float[]) block1.getData(); // Set the progressiveness of the output data blk.progressive = block0.progressive || block1.progressive || block2.progressive; blk.offset = 0; blk.scanw = w; // set attributes of the DataBlk used for buffering dbi.progressive = blk.progressive; dbi.ulx = blk.ulx; dbi.uly = blk.uly; dbi.w = blk.w; dbi.h = blk.h; //Perform conversion // Initialize general indexes k = w*h-1; k0 = block0.offset+(h-1)*block0.scanw+w-1; k2 = block2.offset+(h-1)*block2.scanw+w-1; k1 = block1.offset+(h-1)*block1.scanw+w-1; for( i = h-1; i >=0; i--){ for(mink = k-w; k > mink; k--, k0--, k2--, k1--){ outdata[0][k] = (int)(data0[k0]+1.402f*data1[k1]+0.5f); outdata[1][k] = (int) (data0[k0]-0.34413f*data2[k2]-0.71414f*data1[k1] + 0.5f); outdata[2][k] = (int)(data0[k0]+1.772f*data2[k2]+0.5f); } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k2 -= block2.scanw - w; k1 -= block1.scanw - w; } outdata[c] = null; } else if((c>=0)&&(c<=3)){//Asking for the 2nd or 3rd block component blk.setData(outdata[c]); blk.progressive = dbi.progressive; blk.offset = (blk.uly-dbi.uly)*dbi.w+blk.ulx-dbi.ulx; blk.scanw = dbi.w; outdata[c] = null; } else { // Requesting a non valid component index throw new IllegalArgumentException(); } return blk; } /** * Changes the current tile, given the new indexes. An * IllegalArgumentException is thrown if the indexes do not * correspond to a valid tile. * * <P>This default implementation changes the tile in the source * and re-initializes properly component transformation variables.. * * @param x The horizontal index of the tile. * * @param y The vertical index of the new tile. * * */ public void setTile(int x, int y) { src.setTile(x,y); tIdx = getTileIdx(); // index of the current tile // initializations if( ((Integer)cts.getTileDef(tIdx)).intValue()==NONE ) transfType = NONE; else { int nc = src.getNumComps() > 3 ? 3 : src.getNumComps(); int rev = 0; for(int c=0; c<nc; c++){ rev += (wfs.isReversible(tIdx,c)?1:0); } if(rev==3){ // All WT are reversible transfType = INV_RCT; } else if(rev==0){ // All WT irreversible transfType = INV_ICT; } else{ // Error throw new IllegalArgumentException("Wavelet transformation and "+ "component transformation"+ " not coherent in tile"+tIdx); } } } /** * 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). * * <P>This default implementation just advances to the next tile * in the source and re-initializes properly component * transformation variables. * * */ public void nextTile() { src.nextTile(); tIdx = getTileIdx(); // index of the current tile // initializations if( ((Integer)cts.getTileDef(tIdx)).intValue()==NONE ) transfType = NONE; else { int nc = src.getNumComps() > 3 ? 3 : src.getNumComps(); int rev = 0; for(int c=0; c<nc; c++){ rev += (wfs.isReversible(tIdx,c)?1:0); } if(rev==3){ // All WT are reversible transfType = INV_RCT; } else if(rev==0){ // All WT irreversible transfType = INV_ICT; } else{ // Error throw new IllegalArgumentException("Wavelet transformation and "+ "component transformation"+ " not coherent in tile"+tIdx); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -