CSJ2K.j2k.wavelet.analysis.ForwWTFull.getNextCodeBlock C# (CSharp) Method

getNextCodeBlock() public method

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'.

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.

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.

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.

public getNextCodeBlock ( int c, CSJ2K.j2k.wavelet.analysis.CBlkWTData cblk ) : CSJ2K.j2k.wavelet.analysis.CBlkWTData
c int The component for which to return the next code-block. /// ///
cblk CSJ2K.j2k.wavelet.analysis.CBlkWTData 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 CSJ2K.j2k.wavelet.analysis.CBlkWTData
        public override 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;
            System.Object dst_data; // a int[] or float[] object
            int[] dst_data_int;
            float[] dst_data_float;
            System.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.Data;
            }

            // 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.Data;
            w = cblk.w;
            for (j = w * (cblk.h - 1), k = cblk.offset + (cblk.h - 1) * cblk.scanw; j >= 0; j -= w, k -= cblk.scanw)
            {
                // CONVERSION PROBLEM?
                Array.Copy((System.Array)src_data, k, (System.Array)dst_data, j, w);
            }
            cblk.Data = dst_data;
            cblk.offset = 0;
            cblk.scanw = w;

            return cblk;
        }