/// <summary> /// Clears out all objects and resources. /// </summary> private void ClearAll() { if (this.mBmpTargaImage != null) { this.mBmpTargaImage.Dispose(); this.mBmpTargaImage = null; } if (this.mImageByteHandle.IsAllocated) this.mImageByteHandle.Free(); if (this.mThumbnailByteHandle.IsAllocated) this.mThumbnailByteHandle.Free(); this.mObjTargaHeader = new TargaHeader(); this.mObjTargaExtensionArea = new TargaExtensionArea(); this.mObjTargaFooter = new TargaFooter(); this.mTGAFormat = ETGAFormat.UNKNOWN; this.mStride = 0; this.mPadding = 0; this.rows.Clear(); this.row.Clear(); this.mFileName = string.Empty; }
/// <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.mTGAFormat = ETGAFormat.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.mObjTargaFooter.SetExtensionAreaOffset(ExtOffset); this.mObjTargaFooter.SetDeveloperDirectoryOffset(DevDirOff); this.mObjTargaFooter.SetSignature(Signature); this.mObjTargaFooter.SetReservedCharacter(ResChar); } else { // this is not an ORIGINAL targa file. this.mTGAFormat = ETGAFormat.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."); } }