CSJ2K.j2k.image.input.ImgReaderPGM.getInternCompData C# (CSharp) Method

getInternCompData() public method

Returns, in the blk argument, the block of image data containing the specifed rectangular area, in the specified component. The data is returned, as a reference to the internal data, if any, instead of as a copy, therefore the returned data should not be modified.

After being read the coefficients are level shifted by subtracting 2^(nominal bit range - 1)

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' and 'scanw' of the returned data can be arbitrary. See the 'DataBlk' class.

If the data array in blk is null, then a new one is created if necessary. The implementation of this interface may choose to return the same array or a new one, depending on what is more efficient. Therefore, the data array in blk prior to the method call should not be considered to contain the returned data, a new array may have been created. Instead, get the array from blk after the method has returned.

The returned data always has its 'progressive' attribute unset (i.e. false).

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.

public getInternCompData ( CSJ2K.j2k.image.DataBlk blk, int c ) : CSJ2K.j2k.image.DataBlk
blk CSJ2K.j2k.image.DataBlk Its coordinates and dimensions specify the area to /// return. Some fields in this object are modified to return the data. /// ///
c int The index of the component from which to get the data. Only 0 /// is valid. /// ///
return CSJ2K.j2k.image.DataBlk
        public override DataBlk getInternCompData(DataBlk blk, int c)
        {
            int k, j, i, mi;
            int[] barr;

            // Check component index
            if (c != 0)
                throw new System.ArgumentException();

            // Check type of block provided as an argument
            if (blk.DataType != 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.Data;
            if (barr == null || barr.Length < blk.w * blk.h)
            {
                barr = new int[blk.w * blk.h];
                blk.Data = 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_Renamed.Seek(offset + i * w + blk.ulx, System.IO.SeekOrigin.Begin);
                    in_Renamed.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 (System.IO.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;
        }