コード例 #1
0
ファイル: DDSConversion.cs プロジェクト: t3hm00kz/Assembly
		public static BitmapSource Deswizzle(string FilePath, int resizeWidth = -1, int resizeHeight = -1,
			bool onlyResizeIfGreater = false, bool dontSettingsResize = false)
		{
			//Open the temp dds
			var fs = new FileStream(FilePath, FileMode.Open, FileAccess.ReadWrite);
			var es = new EndianStream(fs, Endian.LittleEndian);

			//Read the dds header
			es.SeekTo(0x0C);
			int height = es.ReadInt32();
			int width = es.ReadInt32();

			//Read our random bytes
			es.SeekTo(0x5C);
			string randomBuf = BitConverter.ToString(es.ReadBlock(12)).Replace("-", "");

			//Read the buffer
			es.SeekTo(0x80);
			int size = width*height*4;
			byte[] buffer = es.ReadBlock(size);
			es.Close();

			Bitmap bitmap = null;

			//A2R10G10B10
			switch (randomBuf)
			{
				case "FF03000000FC0F000000F03F":
					bitmap = DeswizzleA2R10G10B10(buffer, width, height);
					if (App.AssemblyStorage.AssemblySettings.XdkScreenshotGammaCorrect)
					{
						BitmapData imageData = (bitmap).LockBits(
							new Rectangle(0, 0, bitmap.Width, bitmap.Height),
							ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
						GammaCorrect(App.AssemblyStorage.AssemblySettings.XdkScreenshotGammaModifier, imageData);
						bitmap.UnlockBits(imageData);
					}
					break;
				case "0000FF0000FF0000FF000000":
					bitmap = DeswizzleA8R8G8B8(buffer, width, height);
					break;
			}

			if (bitmap == null)
				return null;

			// Resize
			if (App.AssemblyStorage.AssemblySettings.XdkResizeImages && !dontSettingsResize)
				bitmap = ResizeImage(bitmap);

			if (width != -1 && height != -1)
				if (onlyResizeIfGreater && (bitmap.Width > width && bitmap.Height > height))
					bitmap = ResizeImage(bitmap, width, height);
				else
					bitmap = ResizeImage(bitmap, width, height);

			return loadBitmap(bitmap);
		}
コード例 #2
0
ファイル: DDSConversion.cs プロジェクト: Chrisco93/Assembly
        public static BitmapSource Deswizzle(string FilePath)
        {
            //Open the temp dds
            var fs = new FileStream(FilePath, FileMode.Open, FileAccess.Read);
            var es = new EndianStream(fs, Endian.LittleEndian);

            //Read the dds header
            es.SeekTo(0x0C);
            var height = es.ReadInt32();
            var width = es.ReadInt32();

            //Read our random bytes
            es.SeekTo(0x5C);
            var randomBuf = BitConverter.ToString(es.ReadBlock(12)).Replace("-", "");

            //Read the buffer
            es.SeekTo(0x80);
            var size = width * height * 4;
            var buffer = es.ReadBlock(size);
            es.Close();

            Bitmap bitmap = null;

            //A2R10G10B10
            switch (randomBuf)
            {
                case "FF03000000FC0F000000F03F":
                    bitmap = DeswizzleA2R10G10B10(buffer, width, height);
                    if (Settings.XDKScreenshotGammaCorrect)
                    {
                        var imageData = (bitmap).LockBits(
                            new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                            ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
                        GammaCorrect(Settings.XDKScreenshotGammaModifier, imageData);
                        bitmap.UnlockBits(imageData);
                    }
                    break;
                case "0000FF0000FF0000FF000000":
                    bitmap = DeswizzleA8R8G8B8(buffer, width, height);
                    break;
            }

            if (bitmap == null)
                return null;

            // Resize
            if (Settings.XDKResizeImages)
                bitmap = ResizeImage(bitmap);

            return loadBitmap(bitmap);
        }
コード例 #3
0
        private void ProcessMapHeader()
        {
            using (IReader reader = new EndianStream(new MemoryStream(MapHeader), Endian.LittleEndian))
            {
                reader.SeekTo(MapTypeOffset);
                MapType = (CacheFileType) reader.ReadInt32();

                reader.SeekTo(MapNameOffset);
                MapName = reader.ReadAscii();

                reader.SeekTo(ScenarioNameOffset);
                ScenarioName = reader.ReadAscii();
            }
        }