diff --git a/Aaru.VideoNow/Color.cs b/Aaru.VideoNow/Color.cs index cec32c5..836be91 100644 --- a/Aaru.VideoNow/Color.cs +++ b/Aaru.VideoNow/Color.cs @@ -13,7 +13,7 @@ namespace Aaru.VideoNow /// endian, so the first appearence is at 9th byte. /// public static readonly byte[] FrameMarker = - { + [ 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, @@ -37,10 +37,10 @@ namespace Aaru.VideoNow 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF - }; + ]; public static readonly byte[] SwappedFrameMarker = - { + [ 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, @@ -64,11 +64,11 @@ namespace Aaru.VideoNow 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 - }; + ]; public static void Decode(string filename, Stream fs, bool swapped, long framePosition) { - char progress = ' '; + var progress = ' '; var aviWriter = new AviWriter(filename + ".avi") { @@ -80,7 +80,7 @@ namespace Aaru.VideoNow IAviAudioStream audioStream = aviWriter.AddAudioStream(2, 17640, 8); fs.Position = framePosition; - byte[] frameBuffer = new byte[19600]; + var frameBuffer = new byte[19600]; fs.Read(frameBuffer, 0, frameBuffer.Length); int audioStart = swapped ? 9 : 8; @@ -91,27 +91,16 @@ namespace Aaru.VideoNow var outFs = new MemoryStream(); - for(int i = 9; i <= frameBuffer.Length; i += 10) + for(var i = 9; i <= frameBuffer.Length; i += 10) { - switch((i / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (i / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingAudio}", progress); outFs.WriteByte(frameBuffer[i]); @@ -121,31 +110,20 @@ namespace Aaru.VideoNow videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length); audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length); - int totalFrames = 1; + var totalFrames = 1; framePosition += 19600; - byte[] buffer = new byte[frameMarkerToUse.Length]; + var buffer = new byte[frameMarkerToUse.Length]; while(framePosition + 19600 < fs.Length) { - switch(totalFrames % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (totalFrames % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.LookingForMoreFrames}", progress); @@ -179,27 +157,16 @@ namespace Aaru.VideoNow outFs = new MemoryStream(); - for(int i = 9; i <= frameBuffer.Length; i += 10) + for(var i = 9; i <= frameBuffer.Length; i += 10) { - switch((i / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (i / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingAudio}", progress); outFs.WriteByte(frameBuffer[i]); @@ -246,27 +213,16 @@ namespace Aaru.VideoNow outFs = new MemoryStream(); - for(int i = 9; i <= frameBuffer.Length; i += 10) + for(var i = 9; i <= frameBuffer.Length; i += 10) { - switch((i / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (i / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingAudio}", progress); outFs.WriteByte(frameBuffer[i]); @@ -291,41 +247,30 @@ namespace Aaru.VideoNow public static byte[] DecodeFrame(byte[] frameBuffer) { - char progress = ' '; + var progress = ' '; var videoFs = new MemoryStream(); Array.Reverse(frameBuffer); byte r, g, b; - int index = 1; + var index = 1; int indexBlock2; - for(int i = 0; i < 19200; i += 240) + for(var i = 0; i < 19200; i += 240) { - for(int k = 0; k < 120; k += 10) + for(var k = 0; k < 120; k += 10) { - for(int j = 1; j < 9; j += 3) + for(var j = 1; j < 9; j += 3) { indexBlock2 = index + 120; - switch((index / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (index / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingVideo}", progress); r = (byte)((frameBuffer[index] & 0xF0) + ((frameBuffer[index] & 0xF0) >> 4)); @@ -377,10 +322,10 @@ namespace Aaru.VideoNow frameBuffer = new byte[videoFs.Length]; byte[] frameBuffer2 = videoFs.ToArray(); - for(int row = 0; row < 80; row++) + for(var row = 0; row < 80; row++) { - for(int p = 0; p < 432; p++) - frameBuffer[(row * 432) + p] = frameBuffer2[(row * 432) + (431 - p)]; + for(var p = 0; p < 432; p++) + frameBuffer[row * 432 + p] = frameBuffer2[row * 432 + (431 - p)]; } return frameBuffer; diff --git a/Aaru.VideoNow/Program.cs b/Aaru.VideoNow/Program.cs index 0cfb6d7..179dd86 100644 --- a/Aaru.VideoNow/Program.cs +++ b/Aaru.VideoNow/Program.cs @@ -42,31 +42,31 @@ namespace Aaru.VideoNow internal static class MainClass { const int MAX_SIZE = 635040000; - static string assemblyCopyright; - static string assemblyTitle; - static AssemblyInformationalVersionAttribute assemblyVersion; + static string _assemblyCopyright; + static string _assemblyTitle; + static AssemblyInformationalVersionAttribute _assemblyVersion; static readonly byte[] FrameStart = - { + [ 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81 - }; + ]; static readonly byte[] SwappedFrameStart = - { + [ 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3 - }; + ]; public static void Main(string[] args) { object[] attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); - assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title; + _assemblyTitle = ((AssemblyTitleAttribute)attributes[0]).Title; attributes = typeof(MainClass).Assembly.GetCustomAttributes(typeof(AssemblyCopyrightAttribute), false); - assemblyVersion = + _assemblyVersion = Attribute.GetCustomAttribute(typeof(MainClass).Assembly, typeof(AssemblyInformationalVersionAttribute)) as AssemblyInformationalVersionAttribute; - assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; + _assemblyCopyright = ((AssemblyCopyrightAttribute)attributes[0]).Copyright; PrintCopyright(); @@ -108,13 +108,13 @@ namespace Aaru.VideoNow Console.WriteLine(Localization.SearchingFirstFrame); long framePosition = 0; - byte[] buffer = new byte[Color.FrameMarker.Length]; - byte[] swappedBuffer = new byte[Color.FrameMarker.Length]; - bool swapped = false; - bool xp = false; - byte[] startBuffer = new byte[FrameStart.Length]; - byte[] xpBuffer = new byte[Xp.FrameMarker.Length]; - byte[] xpSwappedBuffer = new byte[Xp.FrameMarker.Length]; + var buffer = new byte[Color.FrameMarker.Length]; + var swappedBuffer = new byte[Color.FrameMarker.Length]; + var swapped = false; + var xp = false; + var startBuffer = new byte[FrameStart.Length]; + var xpBuffer = new byte[Xp.FrameMarker.Length]; + var xpSwappedBuffer = new byte[Xp.FrameMarker.Length]; while(framePosition < 19760) { @@ -132,7 +132,7 @@ namespace Aaru.VideoNow fs.Position = framePosition; fs.Read(buffer, 0, buffer.Length); - for(int ab = 8; ab < buffer.Length; ab += 10) + for(var ab = 8; ab < buffer.Length; ab += 10) buffer[ab] = 0; if(buffer.SequenceEqual(Color.FrameMarker)) @@ -141,7 +141,7 @@ namespace Aaru.VideoNow fs.Position = framePosition; fs.Read(swappedBuffer, 0, swappedBuffer.Length); - for(int ab = 9; ab < swappedBuffer.Length; ab += 10) + for(var ab = 9; ab < swappedBuffer.Length; ab += 10) swappedBuffer[ab] = 0; if(swappedBuffer.SequenceEqual(Color.SwappedFrameMarker)) @@ -154,7 +154,7 @@ namespace Aaru.VideoNow fs.Position = framePosition; fs.Read(xpBuffer, 0, xpBuffer.Length); - for(int i = 0; i < xpBuffer.Length; i++) + for(var i = 0; i < xpBuffer.Length; i++) xpBuffer[i] &= Xp.FrameMask[i]; if(xpBuffer.SequenceEqual(Xp.FrameMarker)) @@ -167,7 +167,7 @@ namespace Aaru.VideoNow fs.Position = framePosition; fs.Read(xpSwappedBuffer, 0, xpSwappedBuffer.Length); - for(int i = 0; i < xpSwappedBuffer.Length; i++) + for(var i = 0; i < xpSwappedBuffer.Length; i++) xpSwappedBuffer[i] &= Xp.SwappedFrameMask[i]; if(xpSwappedBuffer.SequenceEqual(Xp.SwappedFrameMarker)) @@ -206,8 +206,8 @@ namespace Aaru.VideoNow static void PrintCopyright() { - Console.WriteLine("{0} {1}", assemblyTitle, assemblyVersion?.InformationalVersion); - Console.WriteLine("{0}", assemblyCopyright); + Console.WriteLine("{0} {1}", _assemblyTitle, _assemblyVersion?.InformationalVersion); + Console.WriteLine("{0}", _assemblyCopyright); Console.WriteLine(); } } diff --git a/Aaru.VideoNow/Swapping.cs b/Aaru.VideoNow/Swapping.cs index 6372db1..7e4338a 100644 --- a/Aaru.VideoNow/Swapping.cs +++ b/Aaru.VideoNow/Swapping.cs @@ -4,9 +4,9 @@ namespace Aaru.VideoNow { public static byte[] SwapBuffer(byte[] buffer) { - byte[] tmp = new byte[buffer.Length]; + var tmp = new byte[buffer.Length]; - for(int i = 0; i < buffer.Length; i += 2) + for(var i = 0; i < buffer.Length; i += 2) { tmp[i] = buffer[i + 1]; tmp[i + 1] = buffer[i]; diff --git a/Aaru.VideoNow/Xp.cs b/Aaru.VideoNow/Xp.cs index 8422c78..8c67607 100644 --- a/Aaru.VideoNow/Xp.cs +++ b/Aaru.VideoNow/Xp.cs @@ -9,7 +9,7 @@ namespace Aaru.VideoNow public static class Xp { public static readonly byte[] FrameMask = - { + [ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0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byte[] FrameMarker = - { + [ 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, 0xC7, 0x81, 0x81, 0xE3, 0xC7, 0x00, 0x81, 0xE3, 0xE3, 0xC7, @@ -114,10 +114,10 @@ namespace Aaru.VideoNow 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00 - }; + ]; public static readonly byte[] SwappedFrameMarker = - { + [ 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, 0x81, 0x00, 0xC7, 0xE3, 0x81, 0xC7, 0xE3, @@ -150,11 +150,11 @@ namespace Aaru.VideoNow 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0xFF - }; + ]; public static void Decode(string filename, Stream fs, bool swapped, long framePosition) { - char progress = ' '; + var progress = ' '; var aviWriter = new AviWriter(filename + ".avi") { @@ -166,7 +166,7 @@ namespace Aaru.VideoNow IAviAudioStream audioStream = aviWriter.AddAudioStream(2, 17784, 8); fs.Position = framePosition; - byte[] frameBuffer = new byte[19760]; + var frameBuffer = new byte[19760]; fs.Read(frameBuffer, 0, frameBuffer.Length); int audioStart = swapped ? 9 : 8; @@ -178,27 +178,16 @@ namespace Aaru.VideoNow var outFs = new MemoryStream(); - for(int i = 9; i <= frameBuffer.Length; i += 10) + for(var i = 9; i <= frameBuffer.Length; i += 10) { - switch((i / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (i / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingAudio}", progress); outFs.WriteByte(frameBuffer[i]); @@ -208,35 +197,24 @@ namespace Aaru.VideoNow videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length); audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length); - int totalFrames = 1; + var totalFrames = 1; framePosition += 19760; - byte[] buffer = new byte[frameMarkerToUse.Length]; + var buffer = new byte[frameMarkerToUse.Length]; while(framePosition + 19760 < fs.Length) { - switch(totalFrames % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (totalFrames % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.LookingForMoreFrames}", progress); - for(int i = 0; i < buffer.Length; i++) + for(var i = 0; i < buffer.Length; i++) buffer[i] &= frameMaskToUse[i]; if(!buffer.SequenceEqual(frameMarkerToUse)) @@ -250,7 +228,7 @@ namespace Aaru.VideoNow fs.Position = framePosition; fs.Read(buffer, 0, buffer.Length); - for(int i = 0; i < buffer.Length; i++) + for(var i = 0; i < buffer.Length; i++) buffer[i] &= frameMaskToUse[i]; if(buffer.SequenceEqual(frameMarkerToUse)) @@ -266,27 +244,16 @@ namespace Aaru.VideoNow outFs = new MemoryStream(); - for(int i = 9; i <= frameBuffer.Length; i += 10) + for(var i = 9; i <= frameBuffer.Length; i += 10) { - switch((i / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (i / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingAudio}", progress); outFs.WriteByte(frameBuffer[i]); @@ -333,27 +300,16 @@ namespace Aaru.VideoNow outFs = new MemoryStream(); - for(int i = 9; i <= frameBuffer.Length; i += 10) + for(var i = 9; i <= frameBuffer.Length; i += 10) { - switch((i / 10) % 4) - { - case 0: - progress = '-'; - - break; - case 1: - progress = '\\'; - - break; - case 2: - progress = '|'; - - break; - case 3: - progress = '/'; - - break; - } + progress = (i / 10 % 4) switch + { + 0 => '-', + 1 => '\\', + 2 => '|', + 3 => '/', + _ => progress + }; Console.Write($"\r{Localization.ExtractingAudio}", progress); outFs.WriteByte(frameBuffer[i]);