BizHawk/BizHawk.Client.EmuHawk/AVOut/ImageSequenceWriter.cs

109 lines
2.2 KiB
C#
Raw Normal View History

2015-01-27 04:04:53 +00:00
using System;
using System.IO;
2017-04-18 17:27:44 +00:00
using System.Windows.Forms;
2015-01-27 04:04:53 +00:00
2017-04-18 17:27:44 +00:00
using BizHawk.Bizware.BizwareGL;
2015-01-27 04:04:53 +00:00
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// Writes a sequence of 24bpp PNG or JPG files
/// </summary>
[VideoWriter("imagesequence", "Image sequence writer", "Writes a sequence of 24bpp PNG or JPG files (default compression quality)")]
public class ImageSequenceWriter : IDisposable, IVideoWriter
{
2017-04-18 17:27:44 +00:00
private string _baseName;
private int _frame;
2015-01-27 04:04:53 +00:00
public void SetVideoCodecToken(IDisposable token)
{
}
public void SetDefaultVideoCodecToken()
{
}
2017-04-18 17:27:44 +00:00
public bool UsesAudio => false;
public bool UsesVideo => true;
2015-01-27 04:04:53 +00:00
public void OpenFile(string baseName)
{
2017-04-18 17:27:44 +00:00
_baseName = baseName;
2015-01-27 04:04:53 +00:00
}
public void CloseFile()
{
}
public void SetFrame(int frame)
{
2017-04-18 17:27:44 +00:00
// eh? this gets ditched somehow
2015-01-27 04:04:53 +00:00
}
public void AddFrame(IVideoProvider source)
{
2017-04-18 17:27:44 +00:00
string ext = Path.GetExtension(_baseName);
string name = Path.GetFileNameWithoutExtension(_baseName) + "_" + _frame;
2015-01-27 04:04:53 +00:00
name += ext;
2017-04-18 17:27:44 +00:00
name = Path.Combine(Path.GetDirectoryName(_baseName), name);
BitmapBuffer bb = new BitmapBuffer(source.BufferWidth, source.BufferHeight, source.GetVideoBuffer());
2015-01-27 04:04:53 +00:00
using (var bmp = bb.ToSysdrawingBitmap())
{
if (ext.ToUpper() == ".PNG")
2017-04-18 17:27:44 +00:00
{
2015-01-27 04:04:53 +00:00
bmp.Save(name, System.Drawing.Imaging.ImageFormat.Png);
2017-04-18 17:27:44 +00:00
}
2015-01-27 04:04:53 +00:00
else if (ext.ToUpper() == ".JPG")
2017-04-18 17:27:44 +00:00
{
2015-01-27 04:04:53 +00:00
bmp.Save(name, System.Drawing.Imaging.ImageFormat.Jpeg);
2017-04-18 17:27:44 +00:00
}
2015-01-27 04:04:53 +00:00
}
2017-04-18 17:27:44 +00:00
_frame++;
2015-01-27 04:04:53 +00:00
}
public void AddSamples(short[] samples)
{
}
2017-04-18 17:27:44 +00:00
private class CodecToken : IDisposable
2015-01-27 04:04:53 +00:00
{
2017-04-18 17:27:44 +00:00
public void Dispose()
{
}
2015-01-27 04:04:53 +00:00
}
2017-04-18 17:27:44 +00:00
public IDisposable AcquireVideoCodecToken(IWin32Window hwnd)
2015-01-27 04:04:53 +00:00
{
return new CodecToken();
}
public void SetMovieParameters(int fpsnum, int fpsden)
{
}
public void SetVideoParameters(int width, int height)
{
}
public void SetAudioParameters(int sampleRate, int channels, int bits)
{
}
public void SetMetaData(string gameName, string authors, ulong lengthMS, ulong rerecords)
{
}
public string DesiredExtension()
{
return "png";
}
public void Dispose()
{
}
}
}