diff --git a/OpenRA.FileFormats/Graphics/VqaReader.cs b/OpenRA.FileFormats/Graphics/VqaReader.cs index 34c44b75f9..d130dfe294 100644 --- a/OpenRA.FileFormats/Graphics/VqaReader.cs +++ b/OpenRA.FileFormats/Graphics/VqaReader.cs @@ -22,9 +22,10 @@ namespace OpenRA.FileFormats Stream stream; ushort flags; public readonly ushort numFrames; + public readonly byte framerate; ushort numColors; - ushort width; - ushort height; + public readonly ushort width; + public readonly ushort height; ushort blockWidth; ushort blockHeight; byte cbParts; @@ -51,12 +52,12 @@ namespace OpenRA.FileFormats if (new String(reader.ReadChars(4)) != "FORM") throw new InvalidDataException("Invalid vqa (invalid FORM section)"); - /*var formlength = */ reader.ReadUInt32(); + /*var length = */ reader.ReadUInt32(); if (new String(reader.ReadChars(8)) != "WVQAVQHD") throw new InvalidDataException("Invalid vqa (not WVQAVQHD)"); - /* var len = */reader.ReadUInt32(); + /* var length = */reader.ReadUInt32(); var version = reader.ReadUInt16(); flags = reader.ReadUInt16(); numFrames = reader.ReadUInt16(); @@ -65,7 +66,7 @@ namespace OpenRA.FileFormats blockWidth = reader.ReadByte(); blockHeight = reader.ReadByte(); - var framerate = reader.ReadByte(); + framerate = reader.ReadByte(); cbParts = reader.ReadByte(); blocks = new int2(width / blockWidth, height / blockHeight); @@ -74,7 +75,7 @@ namespace OpenRA.FileFormats /*var unknown1 = */reader.ReadUInt16(); /*var unknown2 = */reader.ReadUInt32(); - cbf = new byte[8*blocks.X*blocks.Y]; + cbf = new byte[width*height]; palette = new Color[numColors]; framedata = new byte[2*blocks.X*blocks.Y]; @@ -86,15 +87,6 @@ namespace OpenRA.FileFormats /*var unknown3 = */reader.ReadChars(14); - Console.WriteLine("FORM Info"); - Console.WriteLine("\tVersion: {0}",version); - Console.WriteLine("\tFlags: {0}",flags); - Console.WriteLine("\tFrames: {0}",numFrames); - Console.WriteLine("\tFramerate: {0}",framerate); - Console.WriteLine("\tSize: {0}x{1}",width,height); - Console.WriteLine("\tBlocksize: {0}x{1}",blockWidth,blockHeight); - Console.WriteLine("\tAudio: {0}hz, {1} channel(s), {2} bit",freq, channels, bits); - // Decode FINF chunk if (new String(reader.ReadChars(4)) != "FINF") throw new InvalidDataException("Invalid vqa (invalid FINF section)"); @@ -117,7 +109,7 @@ namespace OpenRA.FileFormats } public void AdvanceFrame() - { + { // Seek to the start of the frame stream.Seek(frames[currentFrame], SeekOrigin.Begin); BinaryReader reader = new BinaryReader(stream); @@ -144,15 +136,14 @@ namespace OpenRA.FileFormats // Chunks are aligned on even bytes; advance by a byte if the next one is null if (reader.PeekChar() == 0) reader.ReadByte(); } - currentFrame++; + if (++currentFrame == numFrames) + currentFrame = 0; } - public Bitmap FrameData() + public void FrameData(ref Bitmap frame) { - Bitmap frame = new Bitmap(width, height); var bitmapData = frame.LockBits(new Rectangle(0, 0, width, height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); - unsafe { int* c = (int*)bitmapData.Scan0; @@ -172,7 +163,6 @@ namespace OpenRA.FileFormats } } frame.UnlockBits(bitmapData); - return frame; } // VQA Frame diff --git a/OpenRA.Game/Game.cs b/OpenRA.Game/Game.cs index db47cb000e..99c9a6b70c 100644 --- a/OpenRA.Game/Game.cs +++ b/OpenRA.Game/Game.cs @@ -503,15 +503,7 @@ namespace OpenRA // Load the default mod to access required files LoadModPackages(); - - var video = new VqaReader(FileSystem.Open("crontest.vqa")); - video.FrameData().Save("test-0.bmp"); - for (int i = 1; i < video.numFrames; i++) - { - video.AdvanceFrame(); - video.FrameData().Save("test-{0}.bmp".F(i)); - } - + Renderer.SheetSize = Settings.SheetSize; var resolution = GetResolution(settings, Game.Settings.WindowMode); diff --git a/OpenRA.Game/OpenRA.Game.csproj b/OpenRA.Game/OpenRA.Game.csproj index 801c8486b9..6efa3bbf6b 100755 --- a/OpenRA.Game/OpenRA.Game.csproj +++ b/OpenRA.Game/OpenRA.Game.csproj @@ -1,4 +1,4 @@ - + Debug @@ -221,6 +221,7 @@ + diff --git a/OpenRA.Game/Widgets/VqaPlayerWidget.cs b/OpenRA.Game/Widgets/VqaPlayerWidget.cs new file mode 100644 index 0000000000..6b9ac8795a --- /dev/null +++ b/OpenRA.Game/Widgets/VqaPlayerWidget.cs @@ -0,0 +1,62 @@ +#region Copyright & License Information +/* + * Copyright 2007-2010 The OpenRA Developers (see AUTHORS) + * This file is part of OpenRA, which is free software. It is made + * available to you under the terms of the GNU General Public License + * as published by the Free Software Foundation. For more information, + * see LICENSE. + */ +#endregion +using System; +using System.Drawing; +using System.Linq; +using OpenRA.Graphics; +using OpenRA.Traits; +using OpenRA.Widgets; +using OpenRA.FileFormats; + +namespace OpenRA.Widgets +{ + public class VqaPlayerWidget : Widget + { + public string Video = ""; + + float timestep; + Sprite videoSprite; + Bitmap videoFrame; + VqaReader video = null; + + public void LoadVideo(string filename) + { + video = new VqaReader(FileSystem.Open(filename)); + timestep = 1e3f/video.framerate; + + var size = OpenRA.Graphics.Util.NextPowerOf2(Math.Max(video.width, video.height)); + videoFrame = new Bitmap(size,size); + video.FrameData(ref videoFrame); + + videoSprite = new Sprite(new Sheet(new Size(size,size)), new Rectangle( 0, 0, video.width, video.height ), TextureChannel.Alpha); + videoSprite.sheet.Texture.SetData(videoFrame); + } + + int lastTime; + public override void DrawInner(World world) + { + if (video == null) + LoadVideo(Video); + + int t = Environment.TickCount; + int dt = t - lastTime; + + if (dt > timestep) + { + lastTime = t; + video.AdvanceFrame(); + video.FrameData(ref videoFrame); + videoSprite.sheet.Texture.SetData(videoFrame); + } + + Game.Renderer.RgbaSpriteRenderer.DrawSprite(videoSprite, new int2(RenderBounds.X,RenderBounds.Y), "chrome"); + } + } +} diff --git a/mods/cnc/chrome/mainmenu.yaml b/mods/cnc/chrome/mainmenu.yaml index ed751256b7..c3531614ca 100644 --- a/mods/cnc/chrome/mainmenu.yaml +++ b/mods/cnc/chrome/mainmenu.yaml @@ -1,5 +1,11 @@ Container@ROOT: Children: + VqaPlayer: + X:WINDOW_RIGHT - 400 + Y:WINDOW_BOTTOM - 200 + Width:200 + Height:200 + Video:obel.vqa Background@MAINMENU_BG: Id:MAINMENU_BG X:(WINDOW_RIGHT - WIDTH)/2 diff --git a/mods/ra/chrome/mainmenu.yaml b/mods/ra/chrome/mainmenu.yaml index 42c70bef00..ed6ebb71ca 100644 --- a/mods/ra/chrome/mainmenu.yaml +++ b/mods/ra/chrome/mainmenu.yaml @@ -1,3 +1,9 @@ +VqaPlayer: + X:WINDOW_RIGHT - 400 + Y:WINDOW_BOTTOM - 200 + Width:200 + Height:200 + Video:aagun.vqa Background@MAINMENU_BG: Id:MAINMENU_BG X:(WINDOW_RIGHT - WIDTH)/2