This commit is contained in:
Brett Sanderson 2016-03-06 10:37:29 -05:00
parent 4fe924ae6a
commit deade2f47d
3 changed files with 15 additions and 7 deletions

View File

@ -16,12 +16,14 @@ namespace CdgLib
public const int FullWidth = 300; public const int FullWidth = 300;
public const int FullHeight = 216; public const int FullHeight = 216;
private int _borderColourIndex;
private int _horizonalOffset; private int _horizonalOffset;
private int _verticalOffset; private int _verticalOffset;
private readonly int[] _colourTable = new int[ColourTableSize]; private readonly int[] _colourTable = new int[ColourTableSize];
private readonly byte[,] _pixelColours = new byte[FullHeight, FullWidth]; private readonly byte[,] _pixelColours = new byte[FullHeight, FullWidth];
private int[,] _graphicData; private int[,] _graphicData = new int[FullHeight, FullWidth];
public Graphic(IEnumerable<Packet> packets) public Graphic(IEnumerable<Packet> packets)
{ {
@ -33,6 +35,7 @@ namespace CdgLib
public Bitmap ToBitmap() public Bitmap ToBitmap()
{ {
RenderSurface();
Bitmap myBitmap; Bitmap myBitmap;
using (var bitmapStream = new MemoryStream()) using (var bitmapStream = new MemoryStream())
{ {
@ -104,6 +107,7 @@ namespace CdgLib
private void MemoryPreset(Packet packet) private void MemoryPreset(Packet packet)
{ {
var colour = packet.Data[0] & 0xf; var colour = packet.Data[0] & 0xf;
_borderColourIndex = colour;
var repeat = packet.Data[1] & 0xf; var repeat = packet.Data[1] & 0xf;
//we have a reliable packet stream, so the repeat command //we have a reliable packet stream, so the repeat command
@ -133,6 +137,7 @@ namespace CdgLib
int columnIndex; int columnIndex;
var colour = packet.Data[0] & 0xf; var colour = packet.Data[0] & 0xf;
_borderColourIndex = colour;
//The border area is the area contained with a rectangle //The border area is the area contained with a rectangle
//defined by (0,0,300,216) minus the interior pixels which are contained //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 || if (rowIndex < TileHeight || rowIndex >= FullHeight - TileHeight || columnIndex < TileWidth ||
columnIndex >= FullWidth - TileWidth) columnIndex >= FullWidth - TileWidth)
{ {
_graphicData[rowIndex, columnIndex] = _colourTable[_mBorderColourIndex]; _graphicData[rowIndex, columnIndex] = _colourTable[_borderColourIndex];
} }
else else
{ {

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -23,7 +24,9 @@ namespace CdgLib
for (var i = 0; i < bytesRead/PacketSize; i++) 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); subCodePackets.Add(subCodePacket);
} }
return subCodePackets; return subCodePackets;

View File

@ -36,10 +36,10 @@ namespace KaraokePlayer
} }
public void Play(Uri file) public async void Play(Uri file)
{ {
vlcPlayer.SetMedia(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(); vlcPlayer.Play();
} }
@ -52,7 +52,7 @@ namespace KaraokePlayer
{ {
var stopwatch = new Stopwatch(); var stopwatch = new Stopwatch();
stopwatch.Start(); stopwatch.Start();
var picture = await _cdgFile.RenderAtTime((long) (DateTime.Now - _startTime).TotalMilliseconds); var picture = _cdgFile.RenderAtTime((long) (DateTime.Now - _startTime).TotalMilliseconds);
stopwatch.Reset(); stopwatch.Reset();
Debug.Print(stopwatch.ElapsedMilliseconds.ToString()); Debug.Print(stopwatch.ElapsedMilliseconds.ToString());