From deade2f47d86d0a5467215c727e0487ab07dc4cd Mon Sep 17 00:00:00 2001 From: Brett Sanderson Date: Sun, 6 Mar 2016 10:37:29 -0500 Subject: [PATCH] refactor --- CdgLib/Graphic.cs | 9 +++++++-- CdgLib/GraphicFileStream.cs | 7 +++++-- KaraokePlayer/KaraokeVideoPlayer.cs | 6 +++--- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/CdgLib/Graphic.cs b/CdgLib/Graphic.cs index f64c26e..df1dad9 100644 --- a/CdgLib/Graphic.cs +++ b/CdgLib/Graphic.cs @@ -16,12 +16,14 @@ namespace CdgLib public const int FullWidth = 300; public const int FullHeight = 216; + private int _borderColourIndex; + private int _horizonalOffset; private int _verticalOffset; private readonly int[] _colourTable = new int[ColourTableSize]; private readonly byte[,] _pixelColours = new byte[FullHeight, FullWidth]; - private int[,] _graphicData; + private int[,] _graphicData = new int[FullHeight, FullWidth]; public Graphic(IEnumerable packets) { @@ -33,6 +35,7 @@ namespace CdgLib public Bitmap ToBitmap() { + RenderSurface(); Bitmap myBitmap; using (var bitmapStream = new MemoryStream()) { @@ -104,6 +107,7 @@ namespace CdgLib private void MemoryPreset(Packet packet) { var colour = packet.Data[0] & 0xf; + _borderColourIndex = colour; var repeat = packet.Data[1] & 0xf; //we have a reliable packet stream, so the repeat command @@ -133,6 +137,7 @@ namespace CdgLib int columnIndex; var colour = packet.Data[0] & 0xf; + _borderColourIndex = colour; //The border area is the area contained with a rectangle //defined by (0,0,300,216) minus the interior pixels which are contained @@ -379,7 +384,7 @@ namespace CdgLib if (rowIndex < TileHeight || rowIndex >= FullHeight - TileHeight || columnIndex < TileWidth || columnIndex >= FullWidth - TileWidth) { - _graphicData[rowIndex, columnIndex] = _colourTable[_mBorderColourIndex]; + _graphicData[rowIndex, columnIndex] = _colourTable[_borderColourIndex]; } else { diff --git a/CdgLib/GraphicFileStream.cs b/CdgLib/GraphicFileStream.cs index c7e3e6d..e4aae78 100644 --- a/CdgLib/GraphicFileStream.cs +++ b/CdgLib/GraphicFileStream.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.Linq; using System.Threading.Tasks; @@ -23,7 +24,9 @@ namespace CdgLib for (var i = 0; i < bytesRead/PacketSize; i++) { - var subCodePacket = new Packet(buffer.Skip(i*PacketSize).Take(PacketSize).ToArray()); + var cdgPacket = new byte[PacketSize]; + Array.Copy(buffer,i*PacketSize,cdgPacket,0,PacketSize); + var subCodePacket = new Packet(cdgPacket); subCodePackets.Add(subCodePacket); } return subCodePackets; diff --git a/KaraokePlayer/KaraokeVideoPlayer.cs b/KaraokePlayer/KaraokeVideoPlayer.cs index 03acc8c..e09dc83 100644 --- a/KaraokePlayer/KaraokeVideoPlayer.cs +++ b/KaraokePlayer/KaraokeVideoPlayer.cs @@ -36,10 +36,10 @@ namespace KaraokePlayer } - public void Play(Uri file) + public async void Play(Uri file) { vlcPlayer.SetMedia(file); - _cdgFile = new GraphicsFile(Path.ChangeExtension(file.LocalPath, "cdg"), FileMode.Open, FileAccess.Read); + _cdgFile = await GraphicsFile.LoadAsync(Path.ChangeExtension(file.LocalPath, "cdg")); vlcPlayer.Play(); } @@ -52,7 +52,7 @@ namespace KaraokePlayer { var stopwatch = new Stopwatch(); stopwatch.Start(); - var picture = await _cdgFile.RenderAtTime((long) (DateTime.Now - _startTime).TotalMilliseconds); + var picture = _cdgFile.RenderAtTime((long) (DateTime.Now - _startTime).TotalMilliseconds); stopwatch.Reset(); Debug.Print(stopwatch.ElapsedMilliseconds.ToString());