CSJ2K.j2k.image.output.ImgWriterPGX.ImgWriterPGX C# (CSharp) Method

ImgWriterPGX() public method

Creates a new writer to the specified File object, to write data from the specified component.

The size of the image that is written to the file is the size of the component from which to get the data, specified by b, not the size of the source image (they differ if there is some sub-sampling).

All the header informations are given by the BlkImgDataSrc source (component width, component height, bit-depth) and sign flag, which are provided to the constructor. The endianness is always big-endian (MSB first).

public ImgWriterPGX ( IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int c, bool isSigned ) : System
out_Renamed IFileInfo
imgSrc BlkImgDataSrc The source from where to get the image data to write. /// ///
c int The index of the component from where to get the data. /// ///
isSigned bool Whether the datas are signed or not (needed only when /// writing header). /// ///
return System
        public ImgWriterPGX(IFileInfo out_Renamed, BlkImgDataSrc imgSrc, int c, bool isSigned)
        {
            //Initialize
            this.c = c;
            if (out_Renamed.Exists && !out_Renamed.Delete())
            {
                throw new System.IO.IOException("Could not reset file");
            }
            this.out_Renamed = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(out_Renamed, "rw");
            this.isSigned = isSigned;
            src = imgSrc;
            w = src.ImgWidth;
            h = src.ImgHeight;
            fb = imgSrc.getFixedPoint(c);

            bitDepth = src.getNomRangeBits(this.c);
            if ((bitDepth <= 0) || (bitDepth > 31))
            {
                throw new System.IO.IOException("PGX supports only bit-depth between " + "1 and 31");
            }
            if (bitDepth <= 8)
            {
                packBytes = 1;
            }
            else if (bitDepth <= 16)
            {
                packBytes = 2;
            }
            else
            {
                // <= 31
                packBytes = 4;
            }

            // Writes PGX header
            System.String tmpString = "PG " + "ML " + ((this.isSigned)?"- ":"+ ") + bitDepth + " " + w + " " + h + "\n"; // component height

            byte[] tmpByte = System.Text.Encoding.UTF8.GetBytes(tmpString);
            for (int i = 0; i < tmpByte.Length; i++)
            {
                this.out_Renamed.WriteByte((byte) tmpByte[i]);
            }

            offset = tmpByte.Length;
            maxVal = this.isSigned?((1 << (src.getNomRangeBits(c) - 1)) - 1):((1 << src.getNomRangeBits(c)) - 1);
            minVal = this.isSigned?((- 1) * (1 << (src.getNomRangeBits(c) - 1))):0;

            levShift = (this.isSigned)?0:1 << (src.getNomRangeBits(c) - 1);
        }

Same methods

ImgWriterPGX::ImgWriterPGX ( System fname, BlkImgDataSrc imgSrc, int c, bool isSigned ) : System