📄 imgreaderpgx.java
字号:
* * <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.</p> * * @param blk Its coordinates and dimensions specify the area to * return. Some 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 #getCompData * @see JJ2KExceptionHandler * */ public DataBlk getInternCompData(DataBlk blk, int c) { int k,j,i,mi; // counters int levShift = 1<<(bitDepth-1); // 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 int[] barr = (int[]) blk.getData(); if (barr == null || barr.length < blk.w*blk.h*packBytes) { barr = new int[blk.w*blk.h]; blk.setData(barr); } int paddingLength = (32-bitDepth) ; if (buf == null || buf.length < packBytes*blk.w) { buf = new byte[packBytes*blk.w]; } try { switch(packBytes){ // Switch between one of the 3 byte packet type case 1: // Samples packed into 1 byte // Read line by line mi = blk.uly + blk.h; if(isSigned){ 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; k--) barr[k] = (((buf[j--]&0xFF)<<paddingLength) >>paddingLength); } } else{ // Not signed 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; k--) barr[k] = (((buf[j--]&0xFF)<<paddingLength) >>>paddingLength)-levShift; } } break; case 2: // Samples packed into 2 bytes // Read line by line mi = blk.uly + blk.h; if(isSigned){ for (i = blk.uly; i < mi; i++) { // Reposition in input in.seek(offset+2*(i*w+blk.ulx)); in.read(buf,0,blk.w<<1); switch (byteOrder) { case LITTLE_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<1)-1; j>=0; k--) { barr[k] = ((((buf[j--]&0xFF)<<8)|(buf[j--]&0xFF)) <<paddingLength)>>paddingLength; } break; case BIG_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<1)-1; j>=0; k--) { barr[k] = (((buf[j--]&0xFF)|((buf[j--]&0xFF)<<8)) <<paddingLength)>>paddingLength; } break; default: throw new Error("Internal JJ2000 bug"); } } } else{ // If not signed for (i = blk.uly; i < mi; i++) { // Reposition in input in.seek(offset+2*(i*w+blk.ulx)); in.read(buf,0,blk.w<<1); switch (byteOrder) { case LITTLE_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<1)-1; j>=0; k--) { barr[k] = (((((buf[j--]&0xFF)<<8)|(buf[j--]&0xFF)) <<paddingLength)>>>paddingLength)- levShift; } break; case BIG_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<1)-1; j>=0; k--) { barr[k] = ((((buf[j--]&0xFF)|((buf[j--]&0xFF)<<8)) <<paddingLength)>>>paddingLength)- levShift; } break; default: throw new Error("Internal JJ2000 bug"); } } } break; case 4: // Samples packed into 4 bytes // Read line by line mi = blk.uly + blk.h; if(isSigned){ for (i = blk.uly; i < mi; i++) { // Reposition in input in.seek(offset+4*(i*w+blk.ulx)); in.read(buf,0,blk.w<<2); switch (byteOrder) { case LITTLE_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<2)-1; j >= 0; k--) { barr[k] = ((((buf[j--]&0xFF)<<24)| ((buf[j--]&0xFF)<<16)| ((buf[j--]&0xFF)<<8)|(buf[j--]&0xFF)) <<paddingLength)>>paddingLength; } break; case BIG_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<2)-1; j >= 0; k--) { barr[k] = (((buf[j--]&0xFF)|((buf[j--]&0xFF)<<8)| ((buf[j--]&0xFF)<<16)| ((buf[j--]&0xFF)<<24)) <<paddingLength)>>paddingLength; } break; default: throw new Error("Internal JJ2000 bug"); } } } else{ for (i = blk.uly; i < mi; i++) { // Reposition in input in.seek(offset+4*(i*w+blk.ulx)); in.read(buf,0,blk.w<<2); switch (byteOrder) { case LITTLE_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<2)-1; j >= 0; k--) { barr[k] = (((((buf[j--]&0xFF)<<24)| ((buf[j--]&0xFF)<<16)| ((buf[j--]&0xFF)<<8)|(buf[j--]&0xFF)) <<paddingLength)>>>paddingLength)- levShift; } break; case BIG_ENDIAN: for (k = (i-blk.uly)*blk.w+blk.w-1, j=(blk.w<<2)-1; j >= 0; k--) { barr[k] = ((((buf[j--]&0xFF)|((buf[j--]&0xFF)<<8)| ((buf[j--]&0xFF)<<16)| ((buf[j--]&0xFF)<<24)) <<paddingLength)>>>paddingLength)- levShift; } break; default: throw new Error("Internal JJ2000 bug"); } } } break; default: throw new IOException("PGX supports only bit-depth between"+ " 1 and 31"); } } 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> * * <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> * * <p>The returned data has its 'progressive' attribute unset * (i.e. false).</p> * * <p>This method just calls 'getInternCompData(blk,c)'.</p> * * <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 true if the data read was originally signed in the specified * component, false if not. * * @param c The index of the component, from 0 to N-1. * * @return true if the data was originally signed, false if not. * */ public boolean isOrigSigned(int c) { // Check component index if (c != 0) throw new IllegalArgumentException(); return isSigned; } /** * 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 "ImgReaderPGX: WxH = " + w + "x" + h + ", Component = 0" + ", Bit-depth = "+bitDepth+", signed = "+isSigned+ "\nUnderlying RandomAccessIO:\n" + in.toString(); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -