Beispiel #1
0
		public static SFFHEADERv2 LoadFromStream(Stream stream)
		{
			SFFHEADERv2 ret = new SFFHEADERv2 ();
			if (stream == null)
				return ret;
			var mgr = FilePathMgr.GetInstance ();

			ret.signature = mgr.ReadString (stream, 12, System.Text.Encoding.UTF8);
			ret.verhi = (byte)stream.ReadByte ();
			ret.verlo = (byte)stream.ReadByte ();
			ret.verhi2 = (byte)stream.ReadByte ();
			ret.verlo2 = (byte)stream.ReadByte ();
			ret.reserved1 = (uint)mgr.ReadInt (stream);
			ret.reserved2 = (uint)mgr.ReadInt (stream);
			ret.compatverlo3 = (byte)stream.ReadByte ();
			ret.compatverlo1 = (byte)stream.ReadByte ();
			ret.compatverlo2 = (byte)stream.ReadByte ();
			ret.compatverhi = (byte)stream.ReadByte ();
			ret.reserved3 = (uint)mgr.ReadInt (stream);
			ret.reserved4 = (uint)mgr.ReadInt (stream);
			ret.offsetSubFile = (uint)mgr.ReadInt (stream);
			ret.totalImage = (uint)mgr.ReadInt (stream);
			ret.offsetPaletteFile = (uint)mgr.ReadInt (stream);
			ret.totalPalette = (uint)mgr.ReadInt (stream);
			ret.offsetLData = (uint)mgr.ReadInt (stream);
			ret.sizeLData = (uint)mgr.ReadInt (stream);
			ret.offsetTData = (uint)mgr.ReadInt (stream);
			ret.sizeTData = (uint)mgr.ReadInt (stream);
			ret.reserved5 = (uint)mgr.ReadInt (stream);
			ret.reserved6 = (uint)mgr.ReadInt (stream);
			ret.comments = mgr.ReadString (stream, 436, System.Text.Encoding.UTF8);

			return ret;
		}
Beispiel #2
0
		private bool LoadSubFilesV2(SFFHEADERv2 header, Stream stream)
		{
			if (stream == null || header.offsetSubFile == 0)
				return false;
			int offset = (int)header.offsetSubFile;
			if (offset < 0 || offset >= stream.Length)
				return false;
			int cnt = (int)header.totalImage;
			if (cnt < 0)
				return false;

			if (stream.Seek (offset, SeekOrigin.Begin) != offset)
				return false;
			var filePathMgr = FilePathMgr.GetInstance ();
			for (int i = 0; i < cnt; ++i) {
				SFFSUBHEADERv2 subHeader = SFFSUBHEADERv2.LoadFromStream (stream);
				SubHeadersV2.Add (subHeader);
			}

			if (mSubHeadersV2 != null) {
				for (int i = 0; i < mSubHeadersV2.Count; ++i) {
					var subHeader = mSubHeadersV2 [i];
					KeyValuePair<uint, uint> key = new KeyValuePair<uint, uint> ((uint)subHeader.GroubNumber, (uint)subHeader.ImageNumber);
					if (mPcxDataMap.ContainsKey (key))
						continue;
					// 读取pcx
					if (subHeader.subfileLength == 0 && subHeader.IndexOfPrevious != 0) {
						// LINK模式
					} else {
						if (subHeader.subfileLength == 0)
							continue;
						int off = (int)subHeader.offsetData;
						if (off > 0) {
							stream.Seek (off, SeekOrigin.Begin);

							byte[] buffer = new byte[subHeader.subfileLength];
							stream.Read (buffer, 0, buffer.Length);
							buffer = DeCompressBuffer (buffer, (PcxCompressType)subHeader.fmt);
						}
					}
				}
			}
			return true;
		}
Beispiel #3
0
		private bool Load(byte[] bytes)
		{
			mPcxDataMap.Clear();
			if (mSubHeaders != null)
				mSubHeaders.Clear();
			if ((bytes == null) || (bytes.Length <= 0))
			{
				mIsVaild = false;
				return false;
			}

            // 判断是否是v2的文件
            if (bytes.Length < 16)
            {
                mIsVaild = false;
                return false;
            }

            byte v1 = bytes[15];
            byte v2;
            byte v3;
            byte v4;
            if (v1 == 2)
            {
				
                SFFHEADERv2 header = new SFFHEADERv2();
                int headerSize = Marshal.SizeOf(header);
                IntPtr headerBuffer = Marshal.AllocHGlobal(headerSize);
                try
                {
                    Marshal.Copy(bytes, 0, headerBuffer, headerSize);
                    header = (SFFHEADERv2)Marshal.PtrToStructure(headerBuffer, typeof(SFFHEADERv2));
                }
                finally
                {
                    Marshal.FreeHGlobal(headerBuffer);
                }
				MemoryStream stream = new MemoryStream (bytes);
				try
				{
				//	SFFHEADERv2 header = SFFHEADERv2.LoadFromStream (stream);

					int comp = string.Compare(header.signature, _cElecbyteSpr, true);
					if (comp != 0)
                    	return false;

                	v1 = header.verlo2;
                	v2 = header.verlo;
                	v3 = header.verhi2;
                	v4 = header.verhi;

					if (!LoadSubFilesV2(header, stream))
                    	return false;
				} finally {
					stream.Close ();
					stream.Dispose ();
				}
            }
            else if (v1 == 1)
            {

                SFFHEADER header = new SFFHEADER();
                int headerSize = Marshal.SizeOf(header);
                IntPtr headerBuffer = Marshal.AllocHGlobal(headerSize);
                try
                {
                    Marshal.Copy(bytes, 0, headerBuffer, headerSize);
                    header = (SFFHEADER)Marshal.PtrToStructure(headerBuffer, typeof(SFFHEADER));
                }
                finally
                {
                    Marshal.FreeHGlobal(headerBuffer);
                }

                if (string.Compare(header.signature, _cElecbyteSpr, true) != 0)
                    return false;

                v1 = header.verlo2;
                v2 = header.verlo;
                v3 = header.verhi2;
                v4 = header.verhi;

                if (v1 > 1)
                {
                    Debug.LogErrorFormat("sff file not supoort v{0:D}.{1:D}.{2:D}.{3:D}", v1, v2, v3, v4);
                    return false;
                }

              //  MemoryStream stream = new MemoryStream(bytes);
                try
                {
                    if (!LoadSubFiles(header, bytes))
                        return false;
                   // if (!LoadSubFiles(header, stream))
                  //      return false;

                    if (!LoadPcxs(header, bytes))
                        return false;
                } finally
                {
           //         stream.Close();
           //         stream.Dispose();
                }
            } else
            {
                Debug.LogErrorFormat("sff file not supoort v{0:D}", v1);
                return false;
            }

            if (v1 > 1)
            {
                Debug.LogErrorFormat("sff file not supoort v{0:D}.{1:D}.{2:D}.{3:D}", v1, v2, v3, v4);
                return false;
            }

			mIsVaild = true;
			return true;
		}