/** * Returns the next code-block in the current tile for the specified component, as a copy (see * below). The order in which code-blocks are returned is not specified. However each code-block * is returned only once and all code-blocks will be returned if the method is called 'N' times, * where 'N' is the number of code-blocks in the tile. After all the code-blocks have been * returned for the current tile calls to this method will return 'null'. * * <p>When changing the current tile (through 'setTile()' or 'nextTile()') this method will always * return the first code-block, as if this method was never called before for the new current * tile. * * <p>The data returned by this method is always a copy of the internal data of this object, and * it can be modified "in place" without any problems after being returned. The 'offset' of the * returned data is 0, and the 'scanw' is the same as the code-block width. The 'magbits' of the * returned data is not set by this method and should be ignored. See the 'CBlkWTData' class. * * <p>The 'ulx' and 'uly' members of the returned 'CBlkWTData' object contain the coordinates of * the top-left corner of the block, with respect to the tile, not the subband. * * @param c The component for which to return the next code-block. * @param cblk If non-null this object will be used to return the new code-block. If null a new * one will be allocated and returned. If the "data" array of the object is non-null it will * be reused, if possible, to return the data. * @return The next code-block in the current tile for component 'c', or null if all code-blocks * for the current tile have been returned. * @see CBlkWTData */ public CBlkWTData getNextCodeBlock(int c, CBlkWTData cblk) { // We can not directly use getNextInternCodeBlock() since that returns // a reference to the internal buffer, we have to copy that data int j, k; int w; Object dst_data; // a int[] or float[] object int[] dst_data_int; float[] dst_data_float; Object src_data; // a int[] or float[] object intData = (filters.getWTDataType(tIdx, c) == DataBlk.TYPE_INT); dst_data = null; // Cache the data array, if any if (cblk != null) { dst_data = cblk.getData(); } // Get the next code-block cblk = getNextInternCodeBlock(c, cblk); if (cblk == null) { return null; // No more code-blocks in current tile for component // c } // Ensure size of output buffer if (intData) { // int data dst_data_int = (int[]) dst_data; if (dst_data_int == null || dst_data_int.length < cblk.w * cblk.h) { dst_data = new int[cblk.w * cblk.h]; } } else { // float data dst_data_float = (float[]) dst_data; if (dst_data_float == null || dst_data_float.length < cblk.w * cblk.h) { dst_data = new float[cblk.w * cblk.h]; } } // Copy data line by line src_data = cblk.getData(); w = cblk.w; for (j = w * (cblk.h - 1), k = cblk.offset + (cblk.h - 1) * cblk.scanw; j >= 0; j -= w, k -= cblk.scanw) { System.arraycopy(src_data, k, dst_data, j, w); } cblk.setData(dst_data); cblk.offset = 0; cblk.scanw = w; return cblk; }