Esempio n. 1
0
        /// <summary>
        /// Loads the Targa Footer information from the file.
        /// </summary>
        /// <param name="binReader">A BinaryReader that points the loaded file byte stream.</param>
        private void LoadTGAFooterInfo(BinaryReader binReader)
        {
            if (binReader != null && binReader.BaseStream != null && binReader.BaseStream.Length > 0 && binReader.BaseStream.CanSeek == true)
            {

                try
                {
                    // set the cursor at the beginning of the signature string.
                    binReader.BaseStream.Seek((TargaConstants.FooterSignatureOffsetFromEnd * -1), SeekOrigin.End);

                    // read the signature bytes and convert to ascii string
                    string Signature = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.FooterSignatureByteLength)).TrimEnd('\0');

                    // do we have a proper signature
                    if (string.Compare(Signature, TargaConstants.TargaFooterASCIISignature) == 0)
                    {
                        // this is a NEW targa file.
                        // create the footer
                        this.eTGAFormat = TGAFormat.NEW_TGA;

                        // set cursor to beginning of footer info
                        binReader.BaseStream.Seek((TargaConstants.FooterByteLength * -1), SeekOrigin.End);

                        // read the Extension Area Offset value
                        int ExtOffset = binReader.ReadInt32();

                        // read the Developer Directory Offset value
                        int DevDirOff = binReader.ReadInt32();

                        // skip the signature we have already read it.
                        binReader.ReadBytes(TargaConstants.FooterSignatureByteLength);

                        // read the reserved character
                        string ResChar = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.FooterReservedCharByteLength)).TrimEnd('\0');

                        // set all values to our TargaFooter class
                        this.objTargaFooter.SetExtensionAreaOffset(ExtOffset);
                        this.objTargaFooter.SetDeveloperDirectoryOffset(DevDirOff);
                        this.objTargaFooter.SetSignature(Signature);
                        this.objTargaFooter.SetReservedCharacter(ResChar);
                    }
                    else
                    {
                        // this is not an ORIGINAL targa file.
                        this.eTGAFormat = TGAFormat.ORIGINAL_TGA;
                    }
                }
                catch (Exception ex)
                {
                    // clear all
                    this.ClearAll();
                    throw ex;
                }
            }
            else
            {
                this.ClearAll();
                throw new Exception(@"Error loading file, could not read file from disk.");
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Loads the Targa Footer information from the file.
 /// </summary>
 /// <param name="binReader">A BinaryReader that points the loaded file byte stream.</param>
 private void LoadTGAFooterInfo(BinaryReader binReader)
 {
     binReader.BaseStream.Seek((TargaConstants.FooterSignatureOffsetFromEnd * -1), SeekOrigin.End);
     string Signature = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.FooterSignatureByteLength)).TrimEnd('\0');
     if (string.Compare(Signature, TargaConstants.TargaFooterASCIISignature) == 0)
     {
         this.eTGAFormat = TGAFormat.NEW_TGA;
         binReader.BaseStream.Seek((TargaConstants.FooterByteLength * -1), SeekOrigin.End);
         int ExtOffset = binReader.ReadInt32();
         int DevDirOff = binReader.ReadInt32();
         binReader.ReadBytes(TargaConstants.FooterSignatureByteLength);
         string ResChar = System.Text.Encoding.ASCII.GetString(binReader.ReadBytes(TargaConstants.FooterReservedCharByteLength)).TrimEnd('\0');
         this.objTargaFooter.SetExtensionAreaOffset(ExtOffset);
         this.objTargaFooter.SetDeveloperDirectoryOffset(DevDirOff);
         this.objTargaFooter.SetSignature(Signature);
         this.objTargaFooter.SetReservedCharacter(ResChar);
     }
     else
     {
         this.eTGAFormat = TGAFormat.ORIGINAL_TGA;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// Clears out all objects and resources.
        /// </summary>
        private void ClearAll()
        {
            if (this.bmpTargaImage != null)
            {
                this.bmpTargaImage.Dispose();
                this.bmpTargaImage = null;
            }
            if (this.ImageByteHandle.IsAllocated)
                this.ImageByteHandle.Free();

            if (this.ThumbnailByteHandle.IsAllocated)
                this.ThumbnailByteHandle.Free();

            this.objTargaHeader = new TargaHeader();
            this.objTargaExtensionArea = new TargaExtensionArea();
            this.objTargaFooter = new TargaFooter();
            this.eTGAFormat = TGAFormat.UNKNOWN;
            this.intStride = 0;
            this.intPadding = 0;
            this.rows.Clear();
            this.row.Clear();
            this.strFileName = string.Empty;
        }
Esempio n. 4
0
 /// <summary>
 /// Clears out all objects and resources.
 /// </summary>
 private void ClearAll()
 {
     this.objTargaHeader = new TargaHeader();
     this.objTargaExtensionArea = new TargaExtensionArea();
     this.objTargaFooter = new TargaFooter();
     this.eTGAFormat = TGAFormat.UNKNOWN;
     this.intStride = 0;
     this.intPadding = 0;
     this.rows.Clear();
     this.row.Clear();
     this.strFileName = string.Empty;
 }