?? forwcomptransf.java
字號:
/** * Apply the component transformation associated with the current tile. If * no component transformation has been requested by the user, data are * not modified. Else, appropriate method is called (forwRCT or forwICT). * * @see #forwRCT * * @see #forwICT * * @param blk Determines the rectangular area to return. * * @param c Index of the output component. * * @return The requested DataBlk * */ public DataBlk getInternCompData(DataBlk blk, int c){ switch(transfType){ case NONE: return src.getInternCompData(blk,c); case FORW_RCT: return forwRCT(blk,c); case FORW_ICT: return forwICT(blk,c); default: throw new IllegalArgumentException("Non JPEG 2000 part I component"+ " transformation for tile: "+ tIdx); } } /** * Apply forward 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 forwRCT(DataBlk blk,int c){ 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 //If asking for Yr, Ur or Vr do transform if(c >= 0 && c <= 2) { // Check that request data type is int if(blk.getDataType()!=DataBlk.TYPE_INT){ if(outBlk==null || outBlk.getDataType() != DataBlk.TYPE_INT){ outBlk = new DataBlkInt(); } outBlk.w = w; outBlk.h = h; outBlk.ulx = blk.ulx; outBlk.uly = blk.uly; blk = outBlk; } //Reference to output block data array outdata = (int[]) blk.getData(); //Create data array of blk if necessary if(outdata == null || outdata.length<h*w) { outdata = new int[h*w]; blk.setData(outdata); } // Block buffers for input RGB data int data0[],data1[],bdata[]; // input data arrays if(block0==null) block0 = new DataBlkInt(); if(block1==null) block1 = new DataBlkInt(); if(block2==null) 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; //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); bdata = (int[]) block2.getData(); // Set the progressiveness of the output data blk.progressive = block0.progressive || block1.progressive || block2.progressive; blk.offset = 0; blk.scanw = w; //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; switch(c) { case 0: //RGB to Yr conversion for (i = h-1; i >= 0; i--) { for (mink = k-w; k > mink; k--, k0--, k1--, k2--) { // Use int arithmetic with 12 fractional bits // and rounding outdata[k] = ( data0[k] + 2 * data1[k] + bdata[k] ) >> 2; // Same as / 4 } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k1 -= block1.scanw - w; k2 -= block2.scanw - w; } break; case 1: //RGB to Ur conversion for (i = h-1; i >= 0; i--) { for (mink = k-w; k > mink; k--, k1--, k2--) { // Use int arithmetic with 12 fractional bits // and rounding outdata[k] = bdata[k2] - data1[k1]; } // Jump to beggining of previous line in input k1 -= block1.scanw - w; k2 -= block2.scanw - w; } break; case 2: //RGB to Vr conversion for (i = h-1; i >= 0; i--) { for (mink = k-w; k > mink; k--, k0--, k1--) { // Use int arithmetic with 12 fractional bits // and rounding outdata[k] = data0[k0] - data1[k1]; } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k1 -= block1.scanw - w; } break; } } else if (c >= 3) { // Requesting a component which is not Y, Ur or Vr => // just pass the data return src.getInternCompData(blk,c); } else { // Requesting a non valid component index throw new IllegalArgumentException(); } return blk; } /** * Apply forward 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 forwICT(DataBlk blk,int c){ int k,k0,k1,k2,mink,i; int w = blk.w; //width of output block int h = blk.h; //height of ouput block float outdata[]; //array of output data if(blk.getDataType()!=DataBlk.TYPE_FLOAT){ if(outBlk==null || outBlk.getDataType() != DataBlk.TYPE_FLOAT){ outBlk = new DataBlkFloat(); } outBlk.w = w; outBlk.h = h; outBlk.ulx = blk.ulx; outBlk.uly = blk.uly; blk = outBlk; } //Reference to output block data array outdata = (float[]) blk.getData(); //Create data array of blk if necessary if(outdata == null) { outdata = new float[h * w]; blk.setData(outdata); } //If asking for Y, Cb or Cr do transform if(c>=0 && c<=2) { int data0[],data1[],data2[]; // input data arrays if(block0==null) block0 = new DataBlkInt(); if(block1==null) block1 = new DataBlkInt(); if(block2==null) 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; // 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; //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; switch(c) { case 0: //RGB to Y conversion for (i = h-1; i >= 0; i--) { for (mink = k-w; k > mink; k--, k0--, k1--, k2--) { outdata[k] = 0.299f * data0[k0] + 0.587f * data1[k1] + 0.114f * data2[k2]; } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k1 -= block1.scanw - w; k2 -= block2.scanw - w; } break; case 1: //RGB to Cb conversion for (i = h-1; i >= 0; i--) { for (mink = k-w; k > mink; k--, k0--, k1--, k2--) { outdata[k] = - 0.16875f * data0[k0] - 0.33126f * data1[k1] + 0.5f * data2[k2]; } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k1 -= block1.scanw - w; k2 -= block2.scanw - w; } break; case 2: //RGB to Cr conversion for (i = h-1; i >= 0; i--) { for (mink = k-w; k > mink; k--, k0--, k1--, k2--) { outdata[k] = 0.5f * data0[k0] - 0.41869f * data1[k1] - 0.08131f * data2[k2]; } // Jump to beggining of previous line in input k0 -= block0.scanw - w; k1 -= block1.scanw - w; k2 -= block2.scanw - w; } break; } } else if(c>=3) { // Requesting a component which is not Y, Cb or Cr => // just pass the data // Variables DataBlkInt indb = new DataBlkInt(blk.ulx,blk.uly,w,h); int indata[]; // input data array // Get the input data // (returned block may be larger than requested one) src.getInternCompData(indb,c); indata = (int[]) indb.getData(); // Copy the data converting from int to float 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] = (float) indata[k0]; } // Jump to beggining of next line in input k0 += indb.w - w; } // Set the progressivity blk.progressive = indb.progressive; blk.offset = 0; blk.scanw = w; return blk; } 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 String str = (String)cts.getTileDef(tIdx); if(str.equals("none")){ transfType = NONE; } else if(str.equals("rct")){ transfType = FORW_RCT; initForwRCT(); } else if(str.equals("ict")){ transfType = FORW_ICT; initForwICT(); } else{ throw new IllegalArgumentException("Component transformation"+ " not recognized"); } } /** * 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 String str = (String)cts.getTileDef(tIdx); if(str.equals("none")){ transfType = NONE; } else if(str.equals("rct")){ transfType = FORW_RCT; initForwRCT(); } else if(str.equals("ict")){ transfType = FORW_ICT; initForwICT(); } else{ throw new IllegalArgumentException("Component transformation"+ " not recognized"); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -