?? imgreaderpgm.java
字號:
public final DataBlk getInternCompData(DataBlk blk, int c) { int k,j,i,mi; int barr[]; // Check component index if (c != 0) throw new IllegalArgumentException(); // Check type of block provided as an argument if(blk.getDataType()!=DataBlk.TYPE_INT){ if(intBlk==null) intBlk = new DataBlkInt(blk.ulx,blk.uly,blk.w,blk.h); else{ intBlk.ulx = blk.ulx; intBlk.uly = blk.uly; intBlk.w = blk.w; intBlk.h = blk.h; } blk = intBlk; } // Get data array barr = (int[]) blk.getData(); if (barr == null || barr.length < blk.w*blk.h) { barr = new int[blk.w*blk.h]; blk.setData(barr); } // Check line buffer if (buf == null || buf.length < blk.w) { buf = new byte[blk.w]; } try { // Read line by line mi = blk.uly + blk.h; for (i = blk.uly; i < mi; i++) { // Reposition in input in.seek(offset+i*w+blk.ulx); in.read(buf,0,blk.w); for (k = (i-blk.uly)*blk.w+blk.w-1, j = blk.w-1; j >= 0; j--, k--) { barr[k] = (((int)buf[j])&0xFF)-DC_OFFSET; } } } catch (IOException e) { JJ2KExceptionHandler.handleException(e); } // Turn off the progressive attribute blk.progressive = false; // Set buffer attributes blk.offset = 0; blk.scanw = blk.w; 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> After being read the coefficients are level shifted by subtracting * 2^(nominal bit range - 1) * * <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>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 has its 'progressive' attribute unset * (i.e. false). * * <P>This method just calls 'getInternCompData(blk, n)'. * * <P>When an I/O exception is encountered the JJ2KExceptionHandler is * used. The exception is passed to its handleException method. The action * that is taken depends on the action that has been registered in * JJ2KExceptionHandler. See JJ2KExceptionHandler for details. * * @param blk Its coordinates and dimensions specify the area to * return. If it contains a non-null data array, then it must have the * correct dimensions. If it contains a null data array a new one is * created. The fields in this object are modified to return the data. * * @param c The index of the component from which to get the data. Only 0 * is valid. * * @return The requested DataBlk * * @see #getInternCompData * * @see JJ2KExceptionHandler * */ public DataBlk getCompData(DataBlk blk, int c) { return getInternCompData(blk,c); } /** * Returns a byte read from the RandomAccessIO. The number of read byted * are counted to keep track of the offset of the pixel data in the PGM * file * * @return One byte read from the header of the PGM file. * * @exception IOException If an I/O error occurs. * * @exception EOFException If an EOF is read * */ private byte countedByteRead() throws IOException, EOFException{ offset++; return in.readByte(); } /** * Checks that the RandomAccessIO begins with 'P5' * * @exception IOException If an I/O error occurs. * @exception EOFException If an EOF is read * */ private void confirmFileType() throws IOException, EOFException{ byte[] type={80,53}; // 'P5' int i; byte b; for(i=0;i<2;i++){ b = countedByteRead(); if(b!=type[i]){ if( i==1 && b==50 ) { //i.e 'P2' throw new IllegalArgumentException("JJ2000 does not support"+ " ascii-PGM files. Use "+ " raw-PGM file instead. "); } else { throw new IllegalArgumentException("Not a raw-PGM file"); } } } } /** * Skips any line in the header starting with '#' and any space, tab, line * feed or carriage return. * * @exception IOException If an I/O error occurs. * @exception EOFException if an EOF is read * */ private void skipCommentAndWhiteSpace() throws IOException, EOFException { boolean done=false; byte b; while(!done){ b=countedByteRead(); if(b==35){ // Comment start while(b!=10 && b!=13){ // Comment ends in end of line b=countedByteRead(); } }else if(!(b==9||b==10||b==13||b==32)){ // If not whitespace done=true; } } // Put last valid byte in offset--; in.seek(offset); } /** * Returns an int read from the header of the PGM file. * * @return One int read from the header of the PGM file. * * @exception IOException If an I/O error occurs. * @exception EOFException If an EOF is read * */ private int readHeaderInt() throws IOException, EOFException{ int res=0; byte b=0; b=countedByteRead(); while(b!=32&&b!=10&&b!=9&&b!=13){ // While not whitespace res=res*10+b-48; // Covert ASCII to numerical value b=countedByteRead(); } return res; } /** * Returns true if the data read was originally signed in the specified * component, false if not. This method returns always false since PGM * data is always unsigned. * * @param c The index of the component, from 0 to N-1. * * @return always false, since PGM data is always unsigned. * */ public boolean isOrigSigned(int c) { // Check component index if (c != 0) throw new IllegalArgumentException(); return false; } /** * Returns a string of information about the object, more than 1 line * long. The information string includes information from the underlying * RandomAccessIO (its toString() method is called in turn). * * @return A string of information about the object. * */ public String toString() { return "ImgReaderPGM: WxH = " + w + "x" + h + ", Component = 0" + "\nUnderlying RandomAccessIO:\n" + in.toString(); }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -