diff --git a/Core/AviRecorder.h b/Core/AviRecorder.h deleted file mode 100644 index 86779911..00000000 --- a/Core/AviRecorder.h +++ /dev/null @@ -1,45 +0,0 @@ -#pragma once -#include "stdafx.h" -#include -#include "../Utilities/AutoResetEvent.h" -#include "../Utilities/AviWriter.h" -#include "../Utilities/SimpleLock.h" - -class Console; - -class AviRecorder -{ -private: - std::thread _aviWriterThread; - - unique_ptr _aviWriter; - shared_ptr _console; - - string _outputFile; - SimpleLock _lock; - AutoResetEvent _waitFrame; - - atomic _stopFlag; - bool _recording; - uint8_t* _frameBuffer; - uint32_t _frameBufferLength; - uint32_t _sampleRate; - - uint32_t _fps; - uint32_t _width; - uint32_t _height; - - uint32_t GetFps(); - -public: - AviRecorder(shared_ptr console); - virtual ~AviRecorder(); - - bool StartRecording(string filename, VideoCodec codec, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, uint32_t compressionLevel); - void StopRecording(); - - void AddFrame(void* frameBuffer, uint32_t width, uint32_t height); - void AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate); - - bool IsRecording(); -}; \ No newline at end of file diff --git a/Core/Console.cpp b/Core/Console.cpp index c2c8d99d..4e8581e4 100644 --- a/Core/Console.cpp +++ b/Core/Console.cpp @@ -1051,6 +1051,15 @@ double Console::GetFrameDelay() return frameDelay; } +double Console::GetFps() +{ + if(_model == NesModel::NTSC) { + return _settings->CheckFlag(EmulationFlags::IntegerFpsMode) ? 60.0 : 60.098812; + } else { + return _settings->CheckFlag(EmulationFlags::IntegerFpsMode) ? 50.0 : 50.006978; + } +} + void Console::SaveState(ostream &saveStream) { if(_initialized) { diff --git a/Core/Console.h b/Core/Console.h index fafe945c..16b0fe79 100644 --- a/Core/Console.h +++ b/Core/Console.h @@ -219,6 +219,8 @@ public: bool IsDebuggerAttached(); + double GetFps(); + void InitializeRam(void* data, uint32_t length); static void InitializeRam(RamPowerOnState powerOnState, void* data, uint32_t length); diff --git a/Core/Core.vcxproj b/Core/Core.vcxproj index c95de683..230e0e16 100644 --- a/Core/Core.vcxproj +++ b/Core/Core.vcxproj @@ -629,7 +629,6 @@ - @@ -1021,7 +1020,6 @@ - diff --git a/Core/Core.vcxproj.filters b/Core/Core.vcxproj.filters index d95ef295..b71eff7d 100644 --- a/Core/Core.vcxproj.filters +++ b/Core/Core.vcxproj.filters @@ -1087,9 +1087,6 @@ VideoDecoder - - Misc - Nes\Mappers @@ -1663,9 +1660,6 @@ VideoDecoder - - Misc - Debugger diff --git a/Core/SaveStateManager.cpp b/Core/SaveStateManager.cpp index 2408f407..31bb0229 100644 --- a/Core/SaveStateManager.cpp +++ b/Core/SaveStateManager.cpp @@ -343,7 +343,7 @@ int32_t SaveStateManager::GetSaveStatePreview(string saveStatePath, uint8_t* png string data = pngStream.str(); memcpy(pngData, data.c_str(), data.size()); - return frameData.size(); + return (int32_t)frameData.size(); } } return -1; diff --git a/Core/VideoRenderer.cpp b/Core/VideoRenderer.cpp index 6ed4e2a9..7390b88a 100644 --- a/Core/VideoRenderer.cpp +++ b/Core/VideoRenderer.cpp @@ -1,9 +1,11 @@ #include "stdafx.h" #include "IRenderingDevice.h" #include "VideoRenderer.h" -#include "AviRecorder.h" #include "VideoDecoder.h" #include "Console.h" +#include "../Utilities/IVideoRecorder.h" +#include "../Utilities/AviRecorder.h" +#include "../Utilities/GifRecorder.h" VideoRenderer::VideoRenderer(shared_ptr console) { @@ -58,9 +60,9 @@ void VideoRenderer::RenderThread() void VideoRenderer::UpdateFrame(void *frameBuffer, uint32_t width, uint32_t height) { - shared_ptr aviRecorder = _aviRecorder; - if(aviRecorder) { - aviRecorder->AddFrame(frameBuffer, width, height); + shared_ptr recorder = _recorder; + if(recorder) { + recorder->AddFrame(frameBuffer, width, height, _console->GetFps()); } if(_renderer) { @@ -85,28 +87,40 @@ void VideoRenderer::UnregisterRenderingDevice(IRenderingDevice *renderer) void VideoRenderer::StartRecording(string filename, VideoCodec codec, uint32_t compressionLevel) { - shared_ptr recorder(new AviRecorder(_console)); - FrameInfo frameInfo = _console->GetVideoDecoder()->GetFrameInfo(); - if(recorder->StartRecording(filename, codec, frameInfo.Width, frameInfo.Height, frameInfo.BitsPerPixel, _console->GetSettings()->GetSampleRate(), compressionLevel)) { - _aviRecorder = recorder; + + shared_ptr recorder; + if(codec == VideoCodec::GIF) { + recorder.reset(new GifRecorder()); + } else { + recorder.reset(new AviRecorder(codec, compressionLevel)); + } + + if(recorder->StartRecording(filename, frameInfo.Width, frameInfo.Height, frameInfo.BitsPerPixel, _console->GetSettings()->GetSampleRate(), _console->GetFps())) { + _recorder = recorder; + MessageManager::DisplayMessage("VideoRecorder", "VideoRecorderStarted", filename); } } void VideoRenderer::AddRecordingSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate) { - shared_ptr aviRecorder = _aviRecorder; - if(aviRecorder) { - aviRecorder->AddSound(soundBuffer, sampleCount, sampleRate); + shared_ptr recorder = _recorder; + if(recorder) { + recorder->AddSound(soundBuffer, sampleCount, sampleRate); } } void VideoRenderer::StopRecording() { - _aviRecorder.reset(); + shared_ptr recorder = _recorder; + if(recorder) { + recorder->StopRecording(); + MessageManager::DisplayMessage("VideoRecorder", "VideoRecorderStopped", recorder->GetOutputFile()); + } + _recorder.reset(); } bool VideoRenderer::IsRecording() { - return _aviRecorder != nullptr && _aviRecorder->IsRecording(); + return _recorder != nullptr && _recorder->IsRecording(); } \ No newline at end of file diff --git a/Core/VideoRenderer.h b/Core/VideoRenderer.h index eb258397..99f5f71f 100644 --- a/Core/VideoRenderer.h +++ b/Core/VideoRenderer.h @@ -2,6 +2,7 @@ #include "stdafx.h" #include #include "../Utilities/AutoResetEvent.h" +#include "../Utilities/IVideoRecorder.h" #include "FrameInfo.h" class IRenderingDevice; @@ -19,7 +20,7 @@ private: IRenderingDevice* _renderer = nullptr; atomic _stopFlag; - shared_ptr _aviRecorder; + shared_ptr _recorder; void RenderThread(); diff --git a/GUI.NET/Dependencies/resources.ca.xml b/GUI.NET/Dependencies/resources.ca.xml index 8fa346e7..7b01390b 100644 --- a/GUI.NET/Dependencies/resources.ca.xml +++ b/GUI.NET/Dependencies/resources.ca.xml @@ -754,6 +754,7 @@ Pel·lícules (*.mmo)|*.mmo|Tots els fitxers (*.*)|*.* Fitxers de so (*.wav)|*.wav|Tots els fitxers(*.*)|*.* Fitxers de vídeo (*.avi)|*.avi|Tots els fitxers (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Fitxers de paleta (*.pal)|*.pal|Tots els fitxers (*.*)|*.* Tots els formats suportats (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms de Famicom Disk System (*.fds)|*.FDS|Fitxers NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Arxius comprimits (*.zip)|*.ZIP|Arxius 7-Zip (*.7z)|*.7z|Tots els fitxers (*.*)|*.* Tots els formats suportats (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES(*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms de Famicom Disk System (*.fds)|*.FDS|Fitxers NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Arxius comprimits (*.zip)|*.ZIP|Arxius 7-Zip (*.7z)|*.7z|Pedaços IPS/UPS/BPS (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|Tots els fitxers (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.en.xml b/GUI.NET/Dependencies/resources.en.xml index 66f6a4ee..6596cc30 100644 --- a/GUI.NET/Dependencies/resources.en.xml +++ b/GUI.NET/Dependencies/resources.en.xml @@ -784,6 +784,7 @@ Movie files (*.mmo)|*.mmo|All Files (*.*)|*.* Wave files (*.wav)|*.wav|All Files (*.*)|*.* Avi files (*.avi)|*.avi|All Files (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Palette Files (*.pal)|*.pal|All Files (*.*)|*.* All supported formats (*.nes, *.zip, *.7z, *.nsf, *.nsfe, *.fds, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|All (*.*)|*.* All supported formats (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|IPS/UPS/BPS Patches (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|All (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.es.xml b/GUI.NET/Dependencies/resources.es.xml index a4e60339..ae43d4a9 100644 --- a/GUI.NET/Dependencies/resources.es.xml +++ b/GUI.NET/Dependencies/resources.es.xml @@ -771,6 +771,7 @@ Videos (*.mmo)|*.mmo|Todos los archivos (*.*)|*.* Archivos wave (*.wav)|*.wav|Todos los archivos (*.*)|*.* Archivos avi (*.avi)|*.avi|Todos los archivos (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Archivos pal (*.pal)|*.pal|Todos los archivos (*.*)|*.* Todos los formatos soportados (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms de Famicom Disk System (*.fds)|*.FDS|Archivos NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Archivos ZIP (*.zip)|*.ZIP|Archivos 7-Zip (*.7z)|*.7z|Todos los archivos (*.*)|*.* Todos los formatos soportados (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES(*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms de Famicom Disk System (*.fds)|*.FDS|Archivos NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Archivos ZIP (*.zip)|*.ZIP|Archivos 7-Zip (*.7z)|*.7z|Archivos IPS/UPS/BPS (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|Todos los archivos (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.fr.xml b/GUI.NET/Dependencies/resources.fr.xml index e247ec7d..0155bd82 100644 --- a/GUI.NET/Dependencies/resources.fr.xml +++ b/GUI.NET/Dependencies/resources.fr.xml @@ -784,6 +784,7 @@ Films (*.mmo)|*.mmo|Tous les fichiers (*.*)|*.* Fichiers wave (*.wav)|*.wav|Tous les fichiers (*.*)|*.* Fichiers avi (*.avi)|*.avi|Tous les fichiers (*.*)|*.* + Fichiers GIF (*.gif)|*.gif|Tous les fichiers (*.*)|*.* Fichier de palette (*.pal)|*.pal|Tous les fichiers (*.*)|*.* Tous les formats supportés (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms du Famicom Disk System (*.fds)|*.FDS|Fichiers NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Fichiers ZIP (*.zip)|*.ZIP|Fichiers 7-Zip (*.7z)|*.7z|Tous les fichiers (*.*)|*.* Tous les formats supportés (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms du Famicom Disk System (*.fds)|*.FDS|Fichiers NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Fichiers ZIP (*.zip)|*.ZIP|Fichiers 7-Zip (*.7z)|*.7z|Fichiers IPS/UPS/BPS (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|Tous les fichiers (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.it.xml b/GUI.NET/Dependencies/resources.it.xml index 40279101..b4bdc94a 100644 --- a/GUI.NET/Dependencies/resources.it.xml +++ b/GUI.NET/Dependencies/resources.it.xml @@ -784,6 +784,7 @@ Video file (*.mmo)|*.mmo|All Files (*.*)|*.* Wave files (*.wav)|*.wav|All Files (*.*)|*.* Avi files (*.avi)|*.avi|All Files (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Palette Files (*.pal)|*.pal|All Files (*.*)|*.* Tutti i formati supportati (*.nes, *.zip, *.7z, *.nsf, *.nsfe, *.fds, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|All (*.*)|*.* Tutti i formati supportati (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *..unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|IPS/UPS/BPS Patches (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|All (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.ja.xml b/GUI.NET/Dependencies/resources.ja.xml index 57e7c10a..9f8d10dd 100644 --- a/GUI.NET/Dependencies/resources.ja.xml +++ b/GUI.NET/Dependencies/resources.ja.xml @@ -772,6 +772,7 @@ 動画 (*.mmo)|*.mmo|すべてのファイル (*.*)|*.* WAVファイル (*.wav)|*.wav|すべてのファイル (*.*)|*.* AVIファイル (*.avi)|*.avi|すべてのファイル (*.*)|*.* + GIFファイル (*.gif)|*.gif|すべてのファイル (*.*)|*.* パレットファイル (*.pal)|*.pal|すべてのファイル (*.*)|*.* 対応するすべてのファイル (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.FDS;*.7z;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|ファミコンゲーム (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|ファミコンディスクシステムのゲーム (*.fds)|*.FDS|NSFファイル (*.nsf, *.nsfe)|*.NSF;*.NSFE|ZIPファイル (*.zip)|*.ZIP|7-Zipファイル (*.7z)|*.7z|すべてのファイル (*.*)|*.* 対応するすべてのファイル (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|ファミコンゲーム (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|ファミコンディスクシステムのゲーム (*.fds)|*.FDS|NSFファイル (*.nsf, *.nsfe)|*.NSF;*.NSFE|ZIPファイル (*.zip)|*.ZIP|7-Zipファイル (*.7z)|*.7z|パッチファイル (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|すべてのファイル (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.pt.xml b/GUI.NET/Dependencies/resources.pt.xml index 1d540832..d3f152d3 100644 --- a/GUI.NET/Dependencies/resources.pt.xml +++ b/GUI.NET/Dependencies/resources.pt.xml @@ -784,6 +784,7 @@ Vídeos (*.mmo)|*.mmo|Todos os arquivos (*.*)|*.* Arquivos wave (*.wav)|*.wav|Todos os arquivos (*.*)|*.* Arquivos avi (*.avi)|*.avi|Todos os arquivos (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Arquivos pal (*.pal)|*.pal|Todos os arquivos (*.*)|*.* Todos os formatos compatíveis (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms de Famicom Disk System (*.fds)|*.FDS|Arquivos NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Arquivos ZIP (*.zip)|*.ZIP|Arquivos 7-Zip (*.7z)|*.7z|Todos os arquivos (*.*)|*.* Todos os formatos compatíveis (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|Roms de NES(*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Roms de Famicom Disk System (*.fds)|*.FDS|Arquivos NSF (*.nsf, *.nsfe)|*.NSF;*.NSFE|Arquivos ZIP (*.zip)|*.ZIP|Arquivos 7-Zip (*.7z)|*.7z|Arquivos IPS/UPS/BPS (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|Todos os arquivos (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.ru.xml b/GUI.NET/Dependencies/resources.ru.xml index 5687bfd1..a752072f 100644 --- a/GUI.NET/Dependencies/resources.ru.xml +++ b/GUI.NET/Dependencies/resources.ru.xml @@ -772,6 +772,7 @@ Записи (*.mmo)|*.mmo|All Files (*.*)|*.* Wave файлы (*.wav)|*.wav|All Files (*.*)|*.* Avi файлы (*.avi)|*.avi|All Files (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Файлы палитры (*.pal)|*.pal|All Files (*.*)|*.* Все поддерживаемые форматы (*.nes, *.zip, *.7z, *.nsf, *.nsfe, *.fds, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|All (*.*)|*.* Все поддерживаемые форматы (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|IPS/UPS/BPS Patches (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|All (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.uk.xml b/GUI.NET/Dependencies/resources.uk.xml index 4df9f794..9d6dec93 100644 --- a/GUI.NET/Dependencies/resources.uk.xml +++ b/GUI.NET/Dependencies/resources.uk.xml @@ -772,6 +772,7 @@ Записи (*.mmo)|*.mmo|All Files (*.*)|*.* Wave файли (*.wav)|*.wav|All Files (*.*)|*.* Avi файли (*.avi)|*.avi|All Files (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* Файли палiтр (*.pal)|*.pal|All Files (*.*)|*.* Всі підтримувані формати (*.nes, *.zip, *.7z, *.nsf, *.nsfe, *.fds, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|All (*.*)|*.* Всі підтримувані формати (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES Roms (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom Disk System Roms (*.fds)|*.FDS|NSF files (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP Archives (*.zip)|*.ZIP|7-Zip Archives (*.7z)|*.7z|IPS/UPS/BPS Patches (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|All (*.*)|*.* diff --git a/GUI.NET/Dependencies/resources.zh.xml b/GUI.NET/Dependencies/resources.zh.xml index 4a8da528..69068960 100644 --- a/GUI.NET/Dependencies/resources.zh.xml +++ b/GUI.NET/Dependencies/resources.zh.xml @@ -797,6 +797,7 @@ 影片文件 (*.mmo)|*.mmo|所有文件 (*.*)|*.* 波形文件 (*.wav)|*.wav|所有文件 (*.*)|*.* AVI 视频 (*.avi)|*.avi|所有文件 (*.*)|*.* + GIF files (*.gif)|*.gif|All Files (*.*)|*.* 调色板 (*.pal)|*.pal|所有文件 (*.*)|*.* 所有支持的格式 (*.nes, *.zip, *.7z, *.nsf, *.nsfe, *.fds, *.unf, *.unif, *.studybox)|*.NES;*.ZIP;*.7z;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES ROM (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom 磁盘 (*.fds)|*.FDS|NSF 音乐 (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP 档案 (*.zip)|*.ZIP|7-Zip 档案 (*.7z)|*.7z|所有文件 (*.*)|*.* 所有支持的格式 (*.nes, *.zip, *.7z, *.fds, *.nsf, *.nsfe, *.unf, *.unif, *.studybox, *.ips, *.bps, *.ups)|*.NES;*.ZIP;*.7z;*.IPS;*.BPS;*.UPS;*.FDS;*.NSF;*.NSFE;*.UNF;*.UNIF;*.STUDYBOX|NES ROM (*.nes, *.unf, *.unif)|*.NES;*.UNF;*.UNIF|Famicom 磁盘 (*.fds)|*.FDS|NSF 音乐 (*.nsf, *.nsfe)|*.nsf;*.nsfe|ZIP 档案 (*.zip)|*.ZIP|7-Zip 档案 (*.7z)|*.7z|IPS/UPS/BPS 补丁 (*.ips, *.bps, *.ups)|*.IPS;*.BPS;*.UPS|所有文件 (*.*)|*.* diff --git a/GUI.NET/Forms/frmRecordAvi.Designer.cs b/GUI.NET/Forms/frmRecordAvi.Designer.cs index 4395f14f..f3f38bbc 100644 --- a/GUI.NET/Forms/frmRecordAvi.Designer.cs +++ b/GUI.NET/Forms/frmRecordAvi.Designer.cs @@ -34,15 +34,15 @@ this.btnBrowse = new System.Windows.Forms.Button(); this.cboVideoCodec = new System.Windows.Forms.ComboBox(); this.lblCompressionLevel = new System.Windows.Forms.Label(); - this.lblLowCompression = new System.Windows.Forms.Label(); + this.tlpCompressionLevel = new System.Windows.Forms.TableLayoutPanel(); + this.lblHighCompression = new System.Windows.Forms.Label(); this.panel1 = new System.Windows.Forms.Panel(); this.trkCompressionLevel = new System.Windows.Forms.TrackBar(); - this.lblHighCompression = new System.Windows.Forms.Label(); - this.tlpCompressionLevel = new System.Windows.Forms.TableLayoutPanel(); + this.lblLowCompression = new System.Windows.Forms.Label(); this.tableLayoutPanel1.SuspendLayout(); + this.tlpCompressionLevel.SuspendLayout(); this.panel1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.trkCompressionLevel)).BeginInit(); - this.tlpCompressionLevel.SuspendLayout(); this.SuspendLayout(); // // baseConfigPanel @@ -134,17 +134,35 @@ this.lblCompressionLevel.TabIndex = 6; this.lblCompressionLevel.Text = "Compression Level:"; // - // lblLowCompression + // tlpCompressionLevel // - this.lblLowCompression.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.lblLowCompression.AutoSize = true; - this.lblLowCompression.Location = new System.Drawing.Point(3, 4); - this.lblLowCompression.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); - this.lblLowCompression.Name = "lblLowCompression"; - this.lblLowCompression.Size = new System.Drawing.Size(30, 26); - this.lblLowCompression.TabIndex = 9; - this.lblLowCompression.Text = "low\r\n(fast)"; - this.lblLowCompression.TextAlign = System.Drawing.ContentAlignment.TopCenter; + this.tlpCompressionLevel.ColumnCount = 3; + this.tlpCompressionLevel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tlpCompressionLevel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tlpCompressionLevel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tlpCompressionLevel.Controls.Add(this.lblHighCompression, 2, 0); + this.tlpCompressionLevel.Controls.Add(this.panel1, 1, 0); + this.tlpCompressionLevel.Controls.Add(this.lblLowCompression, 0, 0); + this.tlpCompressionLevel.Dock = System.Windows.Forms.DockStyle.Fill; + this.tlpCompressionLevel.Location = new System.Drawing.Point(105, 56); + this.tlpCompressionLevel.Margin = new System.Windows.Forms.Padding(0); + this.tlpCompressionLevel.Name = "tlpCompressionLevel"; + this.tlpCompressionLevel.RowCount = 1; + this.tlpCompressionLevel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); + this.tlpCompressionLevel.Size = new System.Drawing.Size(211, 35); + this.tlpCompressionLevel.TabIndex = 9; + // + // lblHighCompression + // + this.lblHighCompression.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblHighCompression.AutoSize = true; + this.lblHighCompression.Location = new System.Drawing.Point(177, 4); + this.lblHighCompression.Margin = new System.Windows.Forms.Padding(0); + this.lblHighCompression.Name = "lblHighCompression"; + this.lblHighCompression.Size = new System.Drawing.Size(34, 26); + this.lblHighCompression.TabIndex = 10; + this.lblHighCompression.Text = "high\r\n(slow)"; + this.lblHighCompression.TextAlign = System.Drawing.ContentAlignment.TopCenter; // // panel1 // @@ -166,35 +184,17 @@ this.trkCompressionLevel.TabIndex = 7; this.trkCompressionLevel.Value = 1; // - // lblHighCompression + // lblLowCompression // - this.lblHighCompression.Anchor = System.Windows.Forms.AnchorStyles.Left; - this.lblHighCompression.AutoSize = true; - this.lblHighCompression.Location = new System.Drawing.Point(177, 4); - this.lblHighCompression.Margin = new System.Windows.Forms.Padding(0); - this.lblHighCompression.Name = "lblHighCompression"; - this.lblHighCompression.Size = new System.Drawing.Size(34, 26); - this.lblHighCompression.TabIndex = 10; - this.lblHighCompression.Text = "high\r\n(slow)"; - this.lblHighCompression.TextAlign = System.Drawing.ContentAlignment.TopCenter; - // - // tlpCompressionLevel - // - this.tlpCompressionLevel.ColumnCount = 3; - this.tlpCompressionLevel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tlpCompressionLevel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tlpCompressionLevel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tlpCompressionLevel.Controls.Add(this.lblHighCompression, 2, 0); - this.tlpCompressionLevel.Controls.Add(this.panel1, 1, 0); - this.tlpCompressionLevel.Controls.Add(this.lblLowCompression, 0, 0); - this.tlpCompressionLevel.Dock = System.Windows.Forms.DockStyle.Fill; - this.tlpCompressionLevel.Location = new System.Drawing.Point(105, 56); - this.tlpCompressionLevel.Margin = new System.Windows.Forms.Padding(0, 0, 0, 0); - this.tlpCompressionLevel.Name = "tlpCompressionLevel"; - this.tlpCompressionLevel.RowCount = 1; - this.tlpCompressionLevel.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tlpCompressionLevel.Size = new System.Drawing.Size(211, 35); - this.tlpCompressionLevel.TabIndex = 9; + this.lblLowCompression.Anchor = System.Windows.Forms.AnchorStyles.Left; + this.lblLowCompression.AutoSize = true; + this.lblLowCompression.Location = new System.Drawing.Point(3, 4); + this.lblLowCompression.Margin = new System.Windows.Forms.Padding(3, 0, 0, 0); + this.lblLowCompression.Name = "lblLowCompression"; + this.lblLowCompression.Size = new System.Drawing.Size(30, 26); + this.lblLowCompression.TabIndex = 9; + this.lblLowCompression.Text = "low\r\n(fast)"; + this.lblLowCompression.TextAlign = System.Drawing.ContentAlignment.TopCenter; // // frmRecordAvi // @@ -212,11 +212,11 @@ this.Controls.SetChildIndex(this.baseConfigPanel, 0); this.tableLayoutPanel1.ResumeLayout(false); this.tableLayoutPanel1.PerformLayout(); + this.tlpCompressionLevel.ResumeLayout(false); + this.tlpCompressionLevel.PerformLayout(); this.panel1.ResumeLayout(false); this.panel1.PerformLayout(); ((System.ComponentModel.ISupportInitialize)(this.trkCompressionLevel)).EndInit(); - this.tlpCompressionLevel.ResumeLayout(false); - this.tlpCompressionLevel.PerformLayout(); this.ResumeLayout(false); } diff --git a/GUI.NET/Forms/frmRecordAvi.cs b/GUI.NET/Forms/frmRecordAvi.cs index 0863862f..e9956bc5 100644 --- a/GUI.NET/Forms/frmRecordAvi.cs +++ b/GUI.NET/Forms/frmRecordAvi.cs @@ -39,18 +39,21 @@ namespace Mesen.GUI.Forms private void btnBrowse_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); - sfd.SetFilter(ResourceHelper.GetMessage("FilterAvi")); + VideoCodec codec = cboVideoCodec.GetEnumValue(); + sfd.SetFilter(ResourceHelper.GetMessage(codec == VideoCodec.GIF ? "FilterGif" : "FilterAvi")); sfd.InitialDirectory = ConfigManager.AviFolder; - sfd.FileName = InteropEmu.GetRomInfo().GetRomName() + ".avi"; - if(sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK) { + sfd.FileName = InteropEmu.GetRomInfo().GetRomName() + (codec == VideoCodec.GIF ? ".gif" : ".avi"); + if(sfd.ShowDialog() == DialogResult.OK) { txtFilename.Text = sfd.FileName; } } private void cboVideoCodec_SelectedIndexChanged(object sender, EventArgs e) { - lblCompressionLevel.Visible = cboVideoCodec.SelectedIndex > 0; - tlpCompressionLevel.Visible = cboVideoCodec.SelectedIndex > 0; + VideoCodec codec = cboVideoCodec.GetEnumValue(); + bool hasCompressionLevel = (codec == VideoCodec.CSCD || codec == VideoCodec.ZMBV); + lblCompressionLevel.Visible = hasCompressionLevel; + tlpCompressionLevel.Visible = hasCompressionLevel; } } } diff --git a/GUI.NET/InteropEmu.cs b/GUI.NET/InteropEmu.cs index 5c1618a4..90a21304 100644 --- a/GUI.NET/InteropEmu.cs +++ b/GUI.NET/InteropEmu.cs @@ -2306,6 +2306,7 @@ namespace Mesen.GUI None = 0, ZMBV = 1, CSCD = 2, + GIF = 3, } public enum ScaleFilterType diff --git a/Libretro/Makefile.common b/Libretro/Makefile.common index 7d45cd14..04767270 100644 --- a/Libretro/Makefile.common +++ b/Libretro/Makefile.common @@ -24,7 +24,6 @@ SOURCES_CXX := $(LIBRETRO_DIR)/libretro.cpp \ $(CORE_DIR)/Assembler.cpp \ $(CORE_DIR)/AutomaticRomTest.cpp \ $(CORE_DIR)/AutoSaveManager.cpp \ - $(CORE_DIR)/AviRecorder.cpp \ $(CORE_DIR)/BaseControlDevice.cpp \ $(CORE_DIR)/BaseExpansionAudio.cpp \ $(CORE_DIR)/BaseMapper.cpp \ @@ -118,12 +117,14 @@ SOURCES_CXX := $(LIBRETRO_DIR)/libretro.cpp \ $(CORE_DIR)/WaveRecorder.cpp \ $(UTIL_DIR)/ArchiveReader.cpp \ $(UTIL_DIR)/AutoResetEvent.cpp \ - $(UTIL_DIR)/AviWriter.cpp \ + $(UTIL_DIR)/AviRecorder.cpp \ + $(UTIL_DIR)/AviWriter.cpp \ $(UTIL_DIR)/blip_buf.cpp \ $(UTIL_DIR)/BpsPatcher.cpp \ $(UTIL_DIR)/CamstudioCodec.cpp \ $(UTIL_DIR)/CRC32.cpp \ $(UTIL_DIR)/FolderUtilities.cpp \ + $(UTIL_DIR)/GifRecorder.cpp \ $(UTIL_DIR)/HexUtilities.cpp \ $(UTIL_DIR)/IpsPatcher.cpp \ $(UTIL_DIR)/md5.cpp \ diff --git a/Core/AviRecorder.cpp b/Utilities/AviRecorder.cpp similarity index 62% rename from Core/AviRecorder.cpp rename to Utilities/AviRecorder.cpp index 2aa34da6..ca0532f1 100644 --- a/Core/AviRecorder.cpp +++ b/Utilities/AviRecorder.cpp @@ -1,17 +1,15 @@ #include "stdafx.h" #include "AviRecorder.h" -#include "MessageManager.h" -#include "Console.h" -#include "EmulationSettings.h" -AviRecorder::AviRecorder(shared_ptr console) +AviRecorder::AviRecorder(VideoCodec codec, uint32_t compressionLevel) { - _console = console; _recording = false; _stopFlag = false; _frameBuffer = nullptr; _frameBufferLength = 0; _sampleRate = 0; + _codec = codec; + _compressionLevel = compressionLevel; } AviRecorder::~AviRecorder() @@ -26,28 +24,19 @@ AviRecorder::~AviRecorder() } } -uint32_t AviRecorder::GetFps() -{ - if(_console->GetModel() == NesModel::NTSC) { - return _console->GetSettings()->CheckFlag(EmulationFlags::IntegerFpsMode) ? 60000000 : 60098812; - } else { - return _console->GetSettings()->CheckFlag(EmulationFlags::IntegerFpsMode) ? 50000000 : 50006978; - } -} - -bool AviRecorder::StartRecording(string filename, VideoCodec codec, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, uint32_t compressionLevel) +bool AviRecorder::StartRecording(string filename, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, double fps) { if(!_recording) { _outputFile = filename; _sampleRate = audioSampleRate; _width = width; _height = height; - _fps = GetFps(); + _fps = fps; _frameBufferLength = height * width * bpp; _frameBuffer = new uint8_t[_frameBufferLength]; _aviWriter.reset(new AviWriter()); - if(!_aviWriter->StartWrite(filename, codec, width, height, bpp, _fps, audioSampleRate, compressionLevel)) { + if(!_aviWriter->StartWrite(filename, _codec, width, height, bpp, (uint32_t)(_fps * 1000000), audioSampleRate, _compressionLevel)) { _aviWriter.reset(); return false; } @@ -64,7 +53,6 @@ bool AviRecorder::StartRecording(string filename, VideoCodec codec, uint32_t wid } }); - MessageManager::DisplayMessage("VideoRecorder", "VideoRecorderStarted", _outputFile); _recording = true; } return true; @@ -81,15 +69,13 @@ void AviRecorder::StopRecording() _aviWriter->EndWrite(); _aviWriter.reset(); - - MessageManager::DisplayMessage("VideoRecorder", "VideoRecorderStopped", _outputFile); } } -void AviRecorder::AddFrame(void* frameBuffer, uint32_t width, uint32_t height) +void AviRecorder::AddFrame(void* frameBuffer, uint32_t width, uint32_t height, double fps) { if(_recording) { - if(_width != width || _height != height || _fps != GetFps()) { + if(_width != width || _height != height || _fps != fps) { StopRecording(); } else { auto lock = _lock.AcquireSafe(); @@ -114,4 +100,9 @@ void AviRecorder::AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t bool AviRecorder::IsRecording() { return _recording; +} + +string AviRecorder::GetOutputFile() +{ + return _outputFile; } \ No newline at end of file diff --git a/Utilities/AviRecorder.h b/Utilities/AviRecorder.h new file mode 100644 index 00000000..f79ecd4c --- /dev/null +++ b/Utilities/AviRecorder.h @@ -0,0 +1,47 @@ +#pragma once +#include "stdafx.h" +#include +#include "AutoResetEvent.h" +#include "AviWriter.h" +#include "SimpleLock.h" +#include "IVideoRecorder.h" + +class Console; + +class AviRecorder : public IVideoRecorder +{ +private: + std::thread _aviWriterThread; + + unique_ptr _aviWriter; + + string _outputFile; + SimpleLock _lock; + AutoResetEvent _waitFrame; + + atomic _stopFlag; + bool _recording; + uint8_t* _frameBuffer; + uint32_t _frameBufferLength; + uint32_t _sampleRate; + + double _fps; + uint32_t _width; + uint32_t _height; + + VideoCodec _codec; + uint32_t _compressionLevel; + +public: + AviRecorder(VideoCodec codec, uint32_t compressionLevel); + virtual ~AviRecorder(); + + bool StartRecording(string filename, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, double fps) override; + void StopRecording() override; + + void AddFrame(void* frameBuffer, uint32_t width, uint32_t height, double fps) override; + void AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate) override; + + bool IsRecording() override; + string GetOutputFile() override; +}; \ No newline at end of file diff --git a/Utilities/AviWriter.h b/Utilities/AviWriter.h index 3941c9c4..0af99ca9 100644 --- a/Utilities/AviWriter.h +++ b/Utilities/AviWriter.h @@ -11,6 +11,7 @@ enum class VideoCodec None = 0, ZMBV = 1, CSCD = 2, + GIF = 3 }; class AviWriter diff --git a/Utilities/GifRecorder.cpp b/Utilities/GifRecorder.cpp new file mode 100644 index 00000000..a1978e27 --- /dev/null +++ b/Utilities/GifRecorder.cpp @@ -0,0 +1,52 @@ +#include "stdafx.h" +#include "GifRecorder.h" +#include "gif.h" + +GifRecorder::GifRecorder() +{ + _gif.reset(new GifWriter()); +} + +GifRecorder::~GifRecorder() +{ + StopRecording(); +} + +bool GifRecorder::StartRecording(string filename, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, double fps) +{ + _outputFile = filename; + _recording = GifBegin(_gif.get(), filename.c_str(), width, height, 2, 8, false); + _frameCounter = 0; + return _recording; +} + +void GifRecorder::StopRecording() +{ + if(_recording) { + GifEnd(_gif.get()); + } +} + +void GifRecorder::AddFrame(void* frameBuffer, uint32_t width, uint32_t height, double fps) +{ + _frameCounter++; + + if(fps < 55 || (_frameCounter % 6) != 0) { + //At 60 FPS, skip 1 of every 6 frames (max FPS for GIFs is 50fps) + GifWriteFrame(_gif.get(), (uint8_t*)frameBuffer, width, height, 2, 8, false); + } +} + +void GifRecorder::AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate) +{ +} + +bool GifRecorder::IsRecording() +{ + return _recording; +} + +string GifRecorder::GetOutputFile() +{ + return _outputFile; +} \ No newline at end of file diff --git a/Utilities/GifRecorder.h b/Utilities/GifRecorder.h new file mode 100644 index 00000000..5d1a800a --- /dev/null +++ b/Utilities/GifRecorder.h @@ -0,0 +1,25 @@ +#pragma once +#include "stdafx.h" +#include "../Utilities/IVideoRecorder.h" + +struct GifWriter; + +class GifRecorder : public IVideoRecorder +{ +private: + std::unique_ptr _gif; + bool _recording = false; + uint32_t _frameCounter = 0; + string _outputFile; + +public: + GifRecorder(); + ~GifRecorder(); + + bool StartRecording(string filename, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, double fps) override; + void StopRecording() override; + void AddFrame(void* frameBuffer, uint32_t width, uint32_t height, double fps) override; + void AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate) override; + bool IsRecording() override; + string GetOutputFile() override; +}; \ No newline at end of file diff --git a/Utilities/IVideoRecorder.h b/Utilities/IVideoRecorder.h new file mode 100644 index 00000000..0d5ccd43 --- /dev/null +++ b/Utilities/IVideoRecorder.h @@ -0,0 +1,15 @@ +#pragma once +#include "stdafx.h" + +class IVideoRecorder +{ +public: + virtual bool StartRecording(string filename, uint32_t width, uint32_t height, uint32_t bpp, uint32_t audioSampleRate, double fps) = 0; + virtual void StopRecording() = 0; + + virtual void AddFrame(void* frameBuffer, uint32_t width, uint32_t height, double fps) = 0; + virtual void AddSound(int16_t* soundBuffer, uint32_t sampleCount, uint32_t sampleRate) = 0; + + virtual bool IsRecording() = 0; + virtual string GetOutputFile() = 0; +}; \ No newline at end of file diff --git a/Utilities/Utilities.vcxproj b/Utilities/Utilities.vcxproj index fa69d116..e774c86f 100644 --- a/Utilities/Utilities.vcxproj +++ b/Utilities/Utilities.vcxproj @@ -420,6 +420,7 @@ + @@ -427,10 +428,12 @@ + + @@ -468,12 +471,14 @@ + + NotUsing diff --git a/Utilities/Utilities.vcxproj.filters b/Utilities/Utilities.vcxproj.filters index 38804867..ab2a7fa9 100644 --- a/Utilities/Utilities.vcxproj.filters +++ b/Utilities/Utilities.vcxproj.filters @@ -1,14 +1,6 @@  - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;xsd - {34df7dd9-5f1b-4aec-9212-1b70f1fada59} @@ -27,67 +19,71 @@ {6d519bc1-7c40-448a-95d2-9ad94cd20644} + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc xBRZ @@ -114,13 +110,13 @@ KreedSaiEagle - Header Files + Misc - Header Files + Misc - Header Files + Misc Avi @@ -138,7 +134,7 @@ Avi - Header Files + Misc Patches @@ -150,73 +146,34 @@ Patches - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc - Header Files + Misc + + + Misc + + + Misc + + + Avi - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - xBRZ @@ -250,18 +207,6 @@ KreedSaiEagle - - Source Files - - - Source Files - - - Source Files - - - Source Files - Avi @@ -280,14 +225,80 @@ Patches + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc + - Source Files + Misc + + + Misc + + + Misc - Source Files + Misc + + + Misc + + + Misc + + + Misc + + + Misc + + + Misc - Source Files + Misc + + + Misc + + + Misc + + + Misc + + + Avi \ No newline at end of file diff --git a/Utilities/gif.h b/Utilities/gif.h new file mode 100644 index 00000000..7d9615e8 --- /dev/null +++ b/Utilities/gif.h @@ -0,0 +1,836 @@ +// +// gif.h +// by Charlie Tangora +// Public domain. +// Email me : ctangora -at- gmail -dot- com +// +// This file offers a simple, very limited way to create animated GIFs directly in code. +// +// Those looking for particular cleverness are likely to be disappointed; it's pretty +// much a straight-ahead implementation of the GIF format with optional Floyd-Steinberg +// dithering. (It does at least use delta encoding - only the changed portions of each +// frame are saved.) +// +// So resulting files are often quite large. The hope is that it will be handy nonetheless +// as a quick and easily-integrated way for programs to spit out animations. +// +// Only RGBA8 is currently supported as an input format. (The alpha is ignored.) +// +// If capturing a buffer with a bottom-left origin (such as OpenGL), define GIF_FLIP_VERT +// to automatically flip the buffer data when writing the image (the buffer itself is +// unchanged. +// +// USAGE: +// Create a GifWriter struct. Pass it to GifBegin() to initialize and write the header. +// Pass subsequent frames to GifWriteFrame(). +// Finally, call GifEnd() to close the file handle and free memory. +// + +#ifndef gif_h +#define gif_h + +#include // for FILE* +#include // for memcpy and bzero +#include // for integer typedefs + +// Define these macros to hook into a custom memory allocator. +// TEMP_MALLOC and TEMP_FREE will only be called in stack fashion - frees in the reverse order of mallocs +// and any temp memory allocated by a function will be freed before it exits. +// MALLOC and FREE are used only by GifBegin and GifEnd respectively (to allocate a buffer the size of the image, which +// is used to find changed pixels for delta-encoding.) + +#ifndef GIF_TEMP_MALLOC +#include +#define GIF_TEMP_MALLOC malloc +#endif + +#ifndef GIF_TEMP_FREE +#include +#define GIF_TEMP_FREE free +#endif + +#ifndef GIF_MALLOC +#include +#define GIF_MALLOC malloc +#endif + +#ifndef GIF_FREE +#include +#define GIF_FREE free +#endif + +const int kGifTransIndex = 0; + +struct GifPalette +{ + int bitDepth; + + uint8_t r[256]; + uint8_t g[256]; + uint8_t b[256]; + + // k-d tree over RGB space, organized in heap fashion + // i.e. left child of node i is node i*2, right child is node i*2+1 + // nodes 256-511 are implicitly the leaves, containing a color + uint8_t treeSplitElt[255]; + uint8_t treeSplit[255]; +}; + +// max, min, and abs functions +int GifIMax(int l, int r) { return l>r?l:r; } +int GifIMin(int l, int r) { return l (1<bitDepth)-1) + { + int ind = treeRoot-(1<bitDepth); + if(ind == kGifTransIndex) return; + + // check whether this color is better than the current winner + int r_err = r - ((int32_t)pPal->r[ind]); + int g_err = g - ((int32_t)pPal->g[ind]); + int b_err = b - ((int32_t)pPal->b[ind]); + int diff = GifIAbs(r_err)+GifIAbs(g_err)+GifIAbs(b_err); + + if(diff < bestDiff) + { + bestInd = ind; + bestDiff = diff; + } + + return; + } + + // take the appropriate color (r, g, or b) for this node of the k-d tree + int comps[3]; comps[0] = r; comps[1] = g; comps[2] = b; + int splitComp = comps[pPal->treeSplitElt[treeRoot]]; + + int splitPos = pPal->treeSplit[treeRoot]; + if(splitPos > splitComp) + { + // check the left subtree + GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); + if( bestDiff > splitPos - splitComp ) + { + // cannot prove there's not a better value in the right subtree, check that too + GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); + } + } + else + { + GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2+1); + if( bestDiff > splitComp - splitPos ) + { + GifGetClosestPaletteColor(pPal, r, g, b, bestInd, bestDiff, treeRoot*2); + } + } +} + +void GifSwapPixels(uint8_t* image, int pixA, int pixB) +{ + uint8_t rA = image[pixA*4]; + uint8_t gA = image[pixA*4+1]; + uint8_t bA = image[pixA*4+2]; + uint8_t aA = image[pixA*4+3]; + + uint8_t rB = image[pixB*4]; + uint8_t gB = image[pixB*4+1]; + uint8_t bB = image[pixB*4+2]; + uint8_t aB = image[pixA*4+3]; + + image[pixA*4] = rB; + image[pixA*4+1] = gB; + image[pixA*4+2] = bB; + image[pixA*4+3] = aB; + + image[pixB*4] = rA; + image[pixB*4+1] = gA; + image[pixB*4+2] = bA; + image[pixB*4+3] = aA; +} + +// just the partition operation from quicksort +int GifPartition(uint8_t* image, const int left, const int right, const int elt, int pivotIndex) +{ + const int pivotValue = image[(pivotIndex)*4+elt]; + GifSwapPixels(image, pivotIndex, right-1); + int storeIndex = left; + bool split = 0; + for(int ii=left; ii neededCenter) + GifPartitionByMedian(image, left, pivotIndex, com, neededCenter); + + if(pivotIndex < neededCenter) + GifPartitionByMedian(image, pivotIndex+1, right, com, neededCenter); + } +} + +// Builds a palette by creating a balanced k-d tree of all pixels in the image +void GifSplitPalette(uint8_t* image, int numPixels, int firstElt, int lastElt, int splitElt, int splitDist, int treeNode, bool buildForDither, GifPalette* pal) +{ + if(lastElt <= firstElt || numPixels == 0) + return; + + // base case, bottom of the tree + if(lastElt == firstElt+1) + { + if(buildForDither) + { + // Dithering needs at least one color as dark as anything + // in the image and at least one brightest color - + // otherwise it builds up error and produces strange artifacts + if( firstElt == 1 ) + { + // special case: the darkest color in the image + uint32_t r=255, g=255, b=255; + for(int ii=0; iir[firstElt] = (uint8_t)r; + pal->g[firstElt] = (uint8_t)g; + pal->b[firstElt] = (uint8_t)b; + + return; + } + + if( firstElt == (1 << pal->bitDepth)-1 ) + { + // special case: the lightest color in the image + uint32_t r=0, g=0, b=0; + for(int ii=0; iir[firstElt] = (uint8_t)r; + pal->g[firstElt] = (uint8_t)g; + pal->b[firstElt] = (uint8_t)b; + + return; + } + } + + // otherwise, take the average of all colors in this subcube + uint64_t r=0, g=0, b=0; + for(int ii=0; iir[firstElt] = (uint8_t)r; + pal->g[firstElt] = (uint8_t)g; + pal->b[firstElt] = (uint8_t)b; + + return; + } + + // Find the axis with the largest range + int minR = 255, maxR = 0; + int minG = 255, maxG = 0; + int minB = 255, maxB = 0; + for(int ii=0; ii maxR) maxR = r; + if(r < minR) minR = r; + + if(g > maxG) maxG = g; + if(g < minG) minG = g; + + if(b > maxB) maxB = b; + if(b < minB) minB = b; + } + + int rRange = maxR - minR; + int gRange = maxG - minG; + int bRange = maxB - minB; + + // and split along that axis. (incidentally, this means this isn't a "proper" k-d tree but I don't know what else to call it) + int splitCom = 1; + if(bRange > gRange) splitCom = 2; + if(rRange > bRange && rRange > gRange) splitCom = 0; + + int subPixelsA = numPixels * (splitElt - firstElt) / (lastElt - firstElt); + int subPixelsB = numPixels-subPixelsA; + + GifPartitionByMedian(image, 0, numPixels, splitCom, subPixelsA); + + pal->treeSplitElt[treeNode] = (uint8_t)splitCom; + pal->treeSplit[treeNode] = image[subPixelsA*4+splitCom]; + + GifSplitPalette(image, subPixelsA, firstElt, splitElt, splitElt-splitDist, splitDist/2, treeNode*2, buildForDither, pal); + GifSplitPalette(image+subPixelsA*4, subPixelsB, splitElt, lastElt, splitElt+splitDist, splitDist/2, treeNode*2+1, buildForDither, pal); +} + +// Finds all pixels that have changed from the previous image and +// moves them to the fromt of th buffer. +// This allows us to build a palette optimized for the colors of the +// changed pixels only. +int GifPickChangedPixels( const uint8_t* lastFrame, uint8_t* frame, int numPixels ) +{ + int numChanged = 0; + uint8_t* writeIter = frame; + + for (int ii=0; iibitDepth = bitDepth; + + // SplitPalette is destructive (it sorts the pixels by color) so + // we must create a copy of the image for it to destroy + size_t imageSize = (size_t)(width * height * 4 * sizeof(uint8_t)); + uint8_t* destroyableImage = (uint8_t*)GIF_TEMP_MALLOC(imageSize); + memcpy(destroyableImage, nextFrame, imageSize); + + int numPixels = (int)(width * height); + if(lastFrame) + numPixels = GifPickChangedPixels(lastFrame, destroyableImage, numPixels); + + const int lastElt = 1 << bitDepth; + const int splitElt = lastElt/2; + const int splitDist = splitElt/2; + + GifSplitPalette(destroyableImage, numPixels, 1, lastElt, splitElt, splitDist, 1, buildForDither, pPal); + + GIF_TEMP_FREE(destroyableImage); + + // add the bottom node for the transparency index + int index = 1 << (bitDepth - 1); + pPal->treeSplit[index] = 0; + pPal->treeSplitElt[index] = 0; + + pPal->r[0] = pPal->g[0] = pPal->b[0] = 0; +} + +// Implements Floyd-Steinberg dithering, writes palette value to alpha +void GifDitherImage( const uint8_t* lastFrame, const uint8_t* nextFrame, uint8_t* outFrame, uint32_t width, uint32_t height, GifPalette* pPal ) +{ + int numPixels = (int)(width * height); + + // quantPixels initially holds color*256 for all pixels + // The extra 8 bits of precision allow for sub-single-color error values + // to be propagated + int32_t *quantPixels = (int32_t *)GIF_TEMP_MALLOC(sizeof(int32_t) * (size_t)numPixels * 4); + + for( int ii=0; iir[bestInd]) * 256; + int32_t g_err = nextPix[1] - int32_t(pPal->g[bestInd]) * 256; + int32_t b_err = nextPix[2] - int32_t(pPal->b[bestInd]) * 256; + + nextPix[0] = pPal->r[bestInd]; + nextPix[1] = pPal->g[bestInd]; + nextPix[2] = pPal->b[bestInd]; + nextPix[3] = bestInd; + + // Propagate the error to the four adjacent locations + // that we haven't touched yet + int quantloc_7 = (int)(yy * width + xx + 1); + int quantloc_3 = (int)(yy * width + width + xx - 1); + int quantloc_5 = (int)(yy * width + width + xx); + int quantloc_1 = (int)(yy * width + width + xx + 1); + + if(quantloc_7 < numPixels) + { + int32_t* pix7 = quantPixels+4*quantloc_7; + pix7[0] += GifIMax( -pix7[0], r_err * 7 / 16 ); + pix7[1] += GifIMax( -pix7[1], g_err * 7 / 16 ); + pix7[2] += GifIMax( -pix7[2], b_err * 7 / 16 ); + } + + if(quantloc_3 < numPixels) + { + int32_t* pix3 = quantPixels+4*quantloc_3; + pix3[0] += GifIMax( -pix3[0], r_err * 3 / 16 ); + pix3[1] += GifIMax( -pix3[1], g_err * 3 / 16 ); + pix3[2] += GifIMax( -pix3[2], b_err * 3 / 16 ); + } + + if(quantloc_5 < numPixels) + { + int32_t* pix5 = quantPixels+4*quantloc_5; + pix5[0] += GifIMax( -pix5[0], r_err * 5 / 16 ); + pix5[1] += GifIMax( -pix5[1], g_err * 5 / 16 ); + pix5[2] += GifIMax( -pix5[2], b_err * 5 / 16 ); + } + + if(quantloc_1 < numPixels) + { + int32_t* pix1 = quantPixels+4*quantloc_1; + pix1[0] += GifIMax( -pix1[0], r_err / 16 ); + pix1[1] += GifIMax( -pix1[1], g_err / 16 ); + pix1[2] += GifIMax( -pix1[2], b_err / 16 ); + } + } + } + + // Copy the palettized result to the output buffer + for( int ii=0; iir[bestInd]; + outFrame[1] = pPal->g[bestInd]; + outFrame[2] = pPal->b[bestInd]; + outFrame[3] = (uint8_t)bestInd; + } + + if(lastFrame) lastFrame += 4; + outFrame += 4; + nextFrame += 4; + } +} + +// Simple structure to write out the LZW-compressed portion of the image +// one bit at a time +struct GifBitStatus +{ + uint8_t bitIndex; // how many bits in the partial byte written so far + uint8_t byte; // current partial byte + + uint32_t chunkIndex; + uint8_t chunk[256]; // bytes are written in here until we have 256 of them, then written to the file +}; + +// insert a single bit +void GifWriteBit( GifBitStatus& stat, uint32_t bit ) +{ + bit = bit & 1; + bit = bit << stat.bitIndex; + stat.byte |= bit; + + ++stat.bitIndex; + if( stat.bitIndex > 7 ) + { + // move the newly-finished byte to the chunk buffer + stat.chunk[stat.chunkIndex++] = stat.byte; + // and start a new byte + stat.bitIndex = 0; + stat.byte = 0; + } +} + +// write all bytes so far to the file +void GifWriteChunk( FILE* f, GifBitStatus& stat ) +{ + fputc((int)stat.chunkIndex, f); + fwrite(stat.chunk, 1, stat.chunkIndex, f); + + stat.bitIndex = 0; + stat.byte = 0; + stat.chunkIndex = 0; +} + +void GifWriteCode( FILE* f, GifBitStatus& stat, uint32_t code, uint32_t length ) +{ + for( uint32_t ii=0; ii> 1; + + if( stat.chunkIndex == 255 ) + { + GifWriteChunk(f, stat); + } + } +} + +// The LZW dictionary is a 256-ary tree constructed as the file is encoded, +// this is one node +struct GifLzwNode +{ + uint16_t m_next[256]; +}; + +// write a 256-color (8-bit) image palette to the file +void GifWritePalette( const GifPalette* pPal, FILE* f ) +{ + fputc(0, f); // first color: transparency + fputc(0, f); + fputc(0, f); + + for(int ii=1; ii<(1 << pPal->bitDepth); ++ii) + { + uint32_t r = pPal->r[ii]; + uint32_t g = pPal->g[ii]; + uint32_t b = pPal->b[ii]; + + fputc((int)b, f); + fputc((int)g, f); + fputc((int)r, f); + } +} + +// write the image header, LZW-compress and write out the image +void GifWriteLzwImage(FILE* f, uint8_t* image, uint32_t left, uint32_t top, uint32_t width, uint32_t height, uint32_t delay, GifPalette* pPal) +{ + // graphics control extension + fputc(0x21, f); + fputc(0xf9, f); + fputc(0x04, f); + fputc(0x05, f); // leave prev frame in place, this frame has transparency + fputc(delay & 0xff, f); + fputc((delay >> 8) & 0xff, f); + fputc(kGifTransIndex, f); // transparent color index + fputc(0, f); + + fputc(0x2c, f); // image descriptor block + + fputc(left & 0xff, f); // corner of image in canvas space + fputc((left >> 8) & 0xff, f); + fputc(top & 0xff, f); + fputc((top >> 8) & 0xff, f); + + fputc(width & 0xff, f); // width and height of image + fputc((width >> 8) & 0xff, f); + fputc(height & 0xff, f); + fputc((height >> 8) & 0xff, f); + + //fputc(0, f); // no local color table, no transparency + //fputc(0x80, f); // no local color table, but transparency + + fputc(0x80 + pPal->bitDepth-1, f); // local color table present, 2 ^ bitDepth entries + GifWritePalette(pPal, f); + + const int minCodeSize = pPal->bitDepth; + const uint32_t clearCode = 1 << pPal->bitDepth; + + fputc(minCodeSize, f); // min code size 8 bits + + GifLzwNode* codetree = (GifLzwNode*)GIF_TEMP_MALLOC(sizeof(GifLzwNode)*4096); + + memset(codetree, 0, sizeof(GifLzwNode)*4096); + int32_t curCode = -1; + uint32_t codeSize = (uint32_t)minCodeSize + 1; + uint32_t maxCode = clearCode+1; + + GifBitStatus stat; + stat.byte = 0; + stat.bitIndex = 0; + stat.chunkIndex = 0; + + GifWriteCode(f, stat, clearCode, codeSize); // start with a fresh LZW dictionary + + for(uint32_t yy=0; yy= (1ul << codeSize) ) + { + // dictionary entry count has broken a size barrier, + // we need more bits for codes + codeSize++; + } + if( maxCode == 4095 ) + { + // the dictionary is full, clear it out and begin anew + GifWriteCode(f, stat, clearCode, codeSize); // clear tree + + memset(codetree, 0, sizeof(GifLzwNode)*4096); + codeSize = (uint32_t)(minCodeSize + 1); + maxCode = clearCode+1; + } + + curCode = nextValue; + } + } + } + + // compression footer + GifWriteCode(f, stat, (uint32_t)curCode, codeSize); + GifWriteCode(f, stat, clearCode, codeSize); + GifWriteCode(f, stat, clearCode + 1, (uint32_t)minCodeSize + 1); + + // write out the last partial chunk + while( stat.bitIndex ) GifWriteBit(stat, 0); + if( stat.chunkIndex ) GifWriteChunk(f, stat); + + fputc(0, f); // image block terminator + + GIF_TEMP_FREE(codetree); +} + +struct GifWriter +{ + FILE* f; + uint8_t* oldImage; + bool firstFrame; +}; + +// Creates a gif file. +// The input GIFWriter is assumed to be uninitialized. +// The delay value is the time between frames in hundredths of a second - note that not all viewers pay much attention to this value. +bool GifBegin( GifWriter* writer, const char* filename, uint32_t width, uint32_t height, uint32_t delay, int32_t bitDepth = 8, bool dither = false ) +{ + (void)bitDepth; (void)dither; // Mute "Unused argument" warnings +#if defined(_MSC_VER) && (_MSC_VER >= 1400) + writer->f = 0; + fopen_s(&writer->f, filename, "wb"); +#else + writer->f = fopen(filename, "wb"); +#endif + if(!writer->f) return false; + + writer->firstFrame = true; + + // allocate + writer->oldImage = (uint8_t*)GIF_MALLOC(width*height*4); + + fputs("GIF89a", writer->f); + + // screen descriptor + fputc(width & 0xff, writer->f); + fputc((width >> 8) & 0xff, writer->f); + fputc(height & 0xff, writer->f); + fputc((height >> 8) & 0xff, writer->f); + + fputc(0xf0, writer->f); // there is an unsorted global color table of 2 entries + fputc(0, writer->f); // background color + fputc(0, writer->f); // pixels are square (we need to specify this because it's 1989) + + // now the "global" palette (really just a dummy palette) + // color 0: black + fputc(0, writer->f); + fputc(0, writer->f); + fputc(0, writer->f); + // color 1: also black + fputc(0, writer->f); + fputc(0, writer->f); + fputc(0, writer->f); + + if( delay != 0 ) + { + // animation header + fputc(0x21, writer->f); // extension + fputc(0xff, writer->f); // application specific + fputc(11, writer->f); // length 11 + fputs("NETSCAPE2.0", writer->f); // yes, really + fputc(3, writer->f); // 3 bytes of NETSCAPE2.0 data + + fputc(1, writer->f); // JUST BECAUSE + fputc(0, writer->f); // loop infinitely (byte 0) + fputc(0, writer->f); // loop infinitely (byte 1) + + fputc(0, writer->f); // block terminator + } + + return true; +} + +// Writes out a new frame to a GIF in progress. +// The GIFWriter should have been created by GIFBegin. +// AFAIK, it is legal to use different bit depths for different frames of an image - +// this may be handy to save bits in animations that don't change much. +bool GifWriteFrame( GifWriter* writer, const uint8_t* image, uint32_t width, uint32_t height, uint32_t delay, int bitDepth = 8, bool dither = false ) +{ + if(!writer->f) return false; + + const uint8_t* oldImage = writer->firstFrame? NULL : writer->oldImage; + writer->firstFrame = false; + + GifPalette pal; + GifMakePalette((dither? NULL : oldImage), image, width, height, bitDepth, dither, &pal); + + if(dither) + GifDitherImage(oldImage, image, writer->oldImage, width, height, &pal); + else + GifThresholdImage(oldImage, image, writer->oldImage, width, height, &pal); + + GifWriteLzwImage(writer->f, writer->oldImage, 0, 0, width, height, delay, &pal); + + return true; +} + +// Writes the EOF code, closes the file handle, and frees temp memory used by a GIF. +// Many if not most viewers will still display a GIF properly if the EOF code is missing, +// but it's still a good idea to write it out. +bool GifEnd( GifWriter* writer ) +{ + if(!writer->f) return false; + + fputc(0x3b, writer->f); // end of file + fclose(writer->f); + GIF_FREE(writer->oldImage); + + writer->f = NULL; + writer->oldImage = NULL; + + return true; +} + +#endif diff --git a/Utilities/stdafx.h b/Utilities/stdafx.h index c33f81bf..18e83c7c 100644 --- a/Utilities/stdafx.h +++ b/Utilities/stdafx.h @@ -12,6 +12,7 @@ #include "UTF8Util.h" using std::shared_ptr; +using std::unique_ptr; using utf8::ifstream; using utf8::ofstream; using std::string;