From a683a420a9e43705c972b5e74d55e319729e1a81 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 Jul 2010 19:53:02 +0000 Subject: SWORD25: Importing original sources svn-id: r53171 --- engines/sword25/fmv/movieplayer.cpp | 36 ++ engines/sword25/fmv/movieplayer.h | 138 +++++ engines/sword25/fmv/movieplayer_script.cpp | 187 ++++++ engines/sword25/fmv/oggtheora/audiobuffer.cpp | 93 +++ engines/sword25/fmv/oggtheora/audiobuffer.h | 53 ++ engines/sword25/fmv/oggtheora/moviefile.cpp | 90 +++ engines/sword25/fmv/oggtheora/moviefile.h | 57 ++ engines/sword25/fmv/oggtheora/oggstate.cpp | 59 ++ engines/sword25/fmv/oggtheora/oggstate.h | 63 ++ engines/sword25/fmv/oggtheora/oggstreamstate.cpp | 118 ++++ engines/sword25/fmv/oggtheora/oggstreamstate.h | 74 +++ engines/sword25/fmv/oggtheora/oggtheora.cpp | 709 +++++++++++++++++++++++ engines/sword25/fmv/oggtheora/oggtheora.h | 109 ++++ engines/sword25/fmv/oggtheora/theorastate.cpp | 79 +++ engines/sword25/fmv/oggtheora/theorastate.h | 55 ++ engines/sword25/fmv/oggtheora/vorbisstate.cpp | 97 ++++ engines/sword25/fmv/oggtheora/vorbisstate.h | 59 ++ engines/sword25/fmv/oggtheora/yuvtorgba.cpp | 416 +++++++++++++ engines/sword25/fmv/oggtheora/yuvtorgba.h | 44 ++ 19 files changed, 2536 insertions(+) create mode 100755 engines/sword25/fmv/movieplayer.cpp create mode 100755 engines/sword25/fmv/movieplayer.h create mode 100755 engines/sword25/fmv/movieplayer_script.cpp create mode 100755 engines/sword25/fmv/oggtheora/audiobuffer.cpp create mode 100755 engines/sword25/fmv/oggtheora/audiobuffer.h create mode 100755 engines/sword25/fmv/oggtheora/moviefile.cpp create mode 100755 engines/sword25/fmv/oggtheora/moviefile.h create mode 100755 engines/sword25/fmv/oggtheora/oggstate.cpp create mode 100755 engines/sword25/fmv/oggtheora/oggstate.h create mode 100755 engines/sword25/fmv/oggtheora/oggstreamstate.cpp create mode 100755 engines/sword25/fmv/oggtheora/oggstreamstate.h create mode 100755 engines/sword25/fmv/oggtheora/oggtheora.cpp create mode 100755 engines/sword25/fmv/oggtheora/oggtheora.h create mode 100755 engines/sword25/fmv/oggtheora/theorastate.cpp create mode 100755 engines/sword25/fmv/oggtheora/theorastate.h create mode 100755 engines/sword25/fmv/oggtheora/vorbisstate.cpp create mode 100755 engines/sword25/fmv/oggtheora/vorbisstate.h create mode 100755 engines/sword25/fmv/oggtheora/yuvtorgba.cpp create mode 100755 engines/sword25/fmv/oggtheora/yuvtorgba.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp new file mode 100755 index 0000000000..f7df544a48 --- /dev/null +++ b/engines/sword25/fmv/movieplayer.cpp @@ -0,0 +1,36 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "movieplayer.h" + +#define BS_LOG_PREFIX "MOVIEPLAYER" + +// ----------------------------------------------------------------------------- + +BS_MoviePlayer::BS_MoviePlayer(BS_Kernel * pKernel) : BS_Service(pKernel) +{ + if (!_RegisterScriptBindings()) + BS_LOG_ERRORLN("Script bindings could not be registered."); + else + BS_LOGLN("Script bindings registered."); +} diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h new file mode 100755 index 0000000000..ed9e94edad --- /dev/null +++ b/engines/sword25/fmv/movieplayer.h @@ -0,0 +1,138 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_MOVIEPLAYER_H +#define BS_MOVIEPLAYER_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" +#include "kernel/service.h" + +#include "kernel/memlog_off.h" +#include +#include "kernel/memlog_on.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_MoviePlayer : public BS_Service +{ +public: + // ----------------------------------------------------------------------------- + // Konstruktion / Destruktion + // ----------------------------------------------------------------------------- + + BS_MoviePlayer(BS_Kernel * pKernel); + virtual ~BS_MoviePlayer() {}; + + // ----------------------------------------------------------------------------- + // Abstraktes Interface, muss von jedem MoviePlayer implementiert werden + // ----------------------------------------------------------------------------- + + /** + @brief Lädt eine Filmdatei + + Diese Methode lädt eine Filmdatei und bereitet sie zur Wiedergabe vor. + Es kann immer nur eine Filmdatei zur Zeit geladen sein. Falls bereits eine Filmdatei geladen + ist, wird diese entladen und nötigenfalls die Wiedergabe gestoppt. + + @param Filename der Dateiname der zu ladenden Filmdatei + @param Z gibt die Z Position des Films auf dem Graphik-Hauptlayer an + @return Gibt false zurück, wenn beim Laden ein Fehler aufgetreten ist, ansonsten true. + */ + virtual bool LoadMovie(const std::string & Filename, unsigned int Z) = 0; + + /** + @brief Entlädt die gerade geladene Filmdatei + + @return Gibt false zurück, wenn beim Entladen ein Fehler aufgetreten ist, ansonsten true. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual bool UnloadMovie() = 0; + + /** + @brief Spielt den Film ab. + + Der Film wird unter Beibehaltung der Seitenverhältnisse auf Bildschirmgröße skaliert.
+ Falls der Film mit einem Aufruf von Pause() pausiert wurde, fährt der Film an dieser Stelle fort. + + @return Gibt false zurück, wenn ein Fehler aufgetreten ist, ansonsten true. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual bool Play() = 0; + + /** + @brief Pausiert die Filmwiedergabe. + + Bei einem späteren Aufruf von Play() fährt die Wiedergabe an der Stelle fort an der der Film Pausiert wurde. + + @return Gibt false zurück, wenn ein Fehler aufgetreten ist, ansonsten true. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual bool Pause() = 0; + + /** + @brief Diese Funktion muss ein mal pro Frame aufgerufen werden. + */ + virtual void Update() = 0; + + /** + @brief Gibt zurück, ob ein Film zur Wiedergabe geladen wurde. + */ + virtual bool IsMovieLoaded() = 0; + + /** + @brief Gibt zurück, ob die Filmwiedergabe pausiert wurde. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual bool IsPaused() = 0; + + /** + @brief Gibt den Faktor zurück um den der geladene Film skaliert wird. + + Beim Laden wird der Skalierungsfaktor automatisch so gewählt, dass der Film die maximal mögliche Bildschirmfläche einnimmt, ohne dass der + Film verzerrt wird. + + @return Gibt den Skalierungsfaktor des Filmes zurück. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual float GetScaleFactor() = 0; + + /** + @brief Legt den Faktor fest um den der geladene Film skaliert werden soll. + @param ScaleFactor der gewünschte Skalierungsfaktor. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual void SetScaleFactor(float ScaleFactor) = 0; + + /** + @brief Gibt die aktuelle Abspielposition in Sekunden zurück. + @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + */ + virtual double GetTime() = 0; + +private: + bool _RegisterScriptBindings(); +}; + +#endif diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp new file mode 100755 index 0000000000..c5160122d0 --- /dev/null +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -0,0 +1,187 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" +#include "kernel/kernel.h" +#include "script/script.h" +#include "script/luabindhelper.h" + +#include "movieplayer.h" + +namespace +{ + // ------------------------------------------------------------------------- + + int LoadMovie(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); + + return 1; + } + + // ------------------------------------------------------------------------- + + int UnloadMovie(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushbooleancpp(L, FMVPtr->UnloadMovie()); + + return 1; + } + + // ------------------------------------------------------------------------- + + int Play(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushbooleancpp(L, FMVPtr->Play()); + + return 1; + } + + // ------------------------------------------------------------------------- + + int Pause(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushbooleancpp(L, FMVPtr->Pause()); + + return 1; + } + + // ------------------------------------------------------------------------- + + int Update(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + FMVPtr->Update(); + + return 0; + } + + // ------------------------------------------------------------------------- + + int IsMovieLoaded(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushbooleancpp(L, FMVPtr->IsMovieLoaded()); + + return 1; + } + + // ------------------------------------------------------------------------- + + int IsPaused(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushbooleancpp(L, FMVPtr->IsPaused()); + + return 1; + } + + // ------------------------------------------------------------------------- + + int GetScaleFactor(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushnumber(L, FMVPtr->GetScaleFactor()); + + return 1; + } + + // ------------------------------------------------------------------------- + + int SetScaleFactor(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + FMVPtr->SetScaleFactor(static_cast(luaL_checknumber(L, 1))); + + return 0; + } + + // ------------------------------------------------------------------------- + + int GetTime(lua_State * L) + { + BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); + + lua_pushnumber(L, FMVPtr->GetTime()); + + return 1; + } + + // ------------------------------------------------------------------------- + + const char * LIBRARY_NAME = "Movieplayer"; + + const luaL_reg LIBRARY_FUNCTIONS[] = + { + "LoadMovie", LoadMovie, + "UnloadMovie", UnloadMovie, + "Play", Play, + "Pause", Pause, + "Update", Update, + "IsMovieLoaded", IsMovieLoaded, + "IsPaused", IsPaused, + "GetScaleFactor", GetScaleFactor, + "SetScaleFactor", SetScaleFactor, + "GetTime", GetTime, + 0, 0, + }; +} + +// ----------------------------------------------------------------------------- + +bool BS_MoviePlayer::_RegisterScriptBindings() +{ + BS_Kernel * pKernel = BS_Kernel::GetInstance(); + BS_ASSERT(pKernel); + BS_ScriptEngine * pScript = static_cast(pKernel->GetService("script")); + BS_ASSERT(pScript); + lua_State * L = static_cast(pScript->GetScriptObject()); + BS_ASSERT(L); + + if (!BS_LuaBindhelper::AddFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false; + + return true; +} diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.cpp b/engines/sword25/fmv/oggtheora/audiobuffer.cpp new file mode 100755 index 0000000000..9161c18fa8 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/audiobuffer.cpp @@ -0,0 +1,93 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "audiobuffer.h" +#include +#include + +using namespace std; + +// ----------------------------------------------------------------------------- + +struct BS_AudioBuffer::Impl +{ + CRITICAL_SECTION CS; + queue Buffer; +}; + +// ----------------------------------------------------------------------------- + +BS_AudioBuffer::BS_AudioBuffer() : t(new Impl()) +{ + InitializeCriticalSection(&t->CS); +} + +// ----------------------------------------------------------------------------- + +BS_AudioBuffer::~BS_AudioBuffer() +{ + DeleteCriticalSection(&t->CS); + + delete t; +} + +// ----------------------------------------------------------------------------- + +void BS_AudioBuffer::Push(signed short * SamplePtr, unsigned int SampleCount) +{ + EnterCriticalSection(&t->CS); + + signed short * SampleEndPtr = SamplePtr + SampleCount; + while (SamplePtr != SampleEndPtr) t->Buffer.push(*SamplePtr++); + + LeaveCriticalSection(&t->CS); +} + +// ----------------------------------------------------------------------------- + +unsigned int BS_AudioBuffer::Pop(signed short * SamplePtr, unsigned int SampleCount) +{ + EnterCriticalSection(&t->CS); + + unsigned int i = 0; + for (; i < SampleCount && !t->Buffer.empty(); ++i) + { + SamplePtr[i] = t->Buffer.front(); + t->Buffer.pop(); + } + + LeaveCriticalSection(&t->CS); + + return i; +} + +// ----------------------------------------------------------------------------- + +unsigned int BS_AudioBuffer::Size() const +{ + EnterCriticalSection(&t->CS); + unsigned int result = t->Buffer.size(); + LeaveCriticalSection(&t->CS); + + return result; +} diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.h b/engines/sword25/fmv/oggtheora/audiobuffer.h new file mode 100755 index 0000000000..c0c19811be --- /dev/null +++ b/engines/sword25/fmv/oggtheora/audiobuffer.h @@ -0,0 +1,53 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_AUDIOBUFFER_H +#define BS_AUDIOBUFFER_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_AudioBuffer +{ +public: + BS_AudioBuffer(); + virtual ~BS_AudioBuffer(); + + void Push(signed short * SamplePtr, unsigned int SampleCount); + unsigned int Pop(signed short * SamplePtr, unsigned int SampleCount); + unsigned int Size() const; + +private: + // PIMPL Pattern + struct Impl; + Impl * t; + + // Kopie verbieten + BS_AudioBuffer(const BS_AudioBuffer &); + const BS_AudioBuffer & operator=(const BS_AudioBuffer &); +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/moviefile.cpp b/engines/sword25/fmv/oggtheora/moviefile.cpp new file mode 100755 index 0000000000..92cbdad844 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/moviefile.cpp @@ -0,0 +1,90 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Logging +// ----------------------------------------------------------------------------- + +#define BS_LOG_PREFIX "MOVIEFILE" + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/kernel.h" +#include "package/packagemanager.h" +#include "oggstate.h" +#include "moviefile.h" + +// ----------------------------------------------------------------------------- + +BS_MovieFile::BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success) : + m_Data(0), m_Size(0), m_ReadPos(0), m_ReadBlockSize(ReadBlockSize) +{ + m_Data = reinterpret_cast(BS_Kernel::GetInstance()->GetPackage()->GetFile(Filename, &m_Size)); + if (!m_Data) + { + BS_LOG_ERRORLN("Could not load movie file \"%s\".", Filename.c_str()); + Success = false; + } + else + Success = true; +} + +// ----------------------------------------------------------------------------- + +BS_MovieFile::~BS_MovieFile() +{ + if (m_Data) delete [] m_Data; +} + +// ----------------------------------------------------------------------------- + +int BS_MovieFile::BufferData(BS_OggState & OggState) +{ + if (!m_Data || !m_Size || m_ReadPos >= m_Size) + { + BS_LOG_ERRORLN("Tried to read past the movie buffer's end."); + return 0; + } + + // just grab some more compressed bitstream and sync it for page extraction + char * Buffer = OggState.SyncBuffer(m_ReadBlockSize); + if (!Buffer) + { + BS_LOG_ERRORLN("ogg_sync_buffer() failed."); + return 0; + } + + // Feststellen wie viele Bytes kopiert werden sollen, maximal READ_BLOCK_SIZE, weniger falls das Ende der Daten erreicht ist. + int Bytes = (m_Size - m_ReadPos) > m_ReadBlockSize ? m_ReadBlockSize : m_Size - m_ReadPos; + memcpy(Buffer, &m_Data[m_ReadPos], Bytes); + m_ReadPos += Bytes; + + OggState.SyncWrote(Bytes); + + return Bytes; +} + +// ----------------------------------------------------------------------------- + +bool BS_MovieFile::IsEOF() const +{ + return m_ReadPos >= m_Size; +} diff --git a/engines/sword25/fmv/oggtheora/moviefile.h b/engines/sword25/fmv/oggtheora/moviefile.h new file mode 100755 index 0000000000..17935789b7 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/moviefile.h @@ -0,0 +1,57 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_MOVIEFILE_H +#define BS_MOVIEFILE_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" + +#include "kernel/memlog_off.h" +#include +#include "kernel/memlog_on.h" + +// ----------------------------------------------------------------------------- + +class BS_OggState; + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_MovieFile +{ +public: + BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success); + virtual ~BS_MovieFile(); + + int BufferData(BS_OggState & OggState); + bool IsEOF() const; + +private: + char * m_Data; + unsigned int m_Size; + unsigned int m_ReadPos; + unsigned int m_ReadBlockSize; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/oggstate.cpp b/engines/sword25/fmv/oggtheora/oggstate.cpp new file mode 100755 index 0000000000..d8300693c9 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggstate.cpp @@ -0,0 +1,59 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "oggstate.h" + +// ----------------------------------------------------------------------------- + +BS_OggState::BS_OggState() +{ + ogg_sync_init(&m_SyncState); +} + +// ----------------------------------------------------------------------------- + +BS_OggState::~BS_OggState() +{ + ogg_sync_clear(&m_SyncState); +} + +// ----------------------------------------------------------------------------- + +int BS_OggState::SyncPageout(ogg_page * OggPage) +{ + return ogg_sync_pageout(&m_SyncState, OggPage); +} + +// ----------------------------------------------------------------------------- + +char * BS_OggState::SyncBuffer(long Size) +{ + return ogg_sync_buffer(&m_SyncState, Size); +} + +// ----------------------------------------------------------------------------- + +int BS_OggState::SyncWrote(long Bytes) +{ + return ogg_sync_wrote(&m_SyncState, Bytes); +} diff --git a/engines/sword25/fmv/oggtheora/oggstate.h b/engines/sword25/fmv/oggtheora/oggstate.h new file mode 100755 index 0000000000..18b44e375f --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggstate.h @@ -0,0 +1,63 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_OGGSTATE_H +#define BS_OGGSTATE_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" +#include "ogg/ogg.h" +// XXX +#include +// XXX + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_OggState +{ +public: + BS_OggState(); + virtual ~BS_OggState(); + + int SyncPageout(ogg_page * OggPage); + char * SyncBuffer(long Size); + int SyncWrote(long Bytes); + + // XXX + void DumpInternals() + { + std::cout << "bodybytes: " << m_SyncState.bodybytes << std::endl; + std::cout << "fill: " << m_SyncState.fill << std::endl; + std::cout << "headerbytes: " << m_SyncState.headerbytes << std::endl; + std::cout << "returned: " << m_SyncState.returned << std::endl; + std::cout << "storage: " << m_SyncState.storage << std::endl; + std::cout << "unsynched: " << m_SyncState.unsynced << std::endl; + std::cout << std::endl; + } + // XXX +private: + ogg_sync_state m_SyncState; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp new file mode 100755 index 0000000000..da4dc317b5 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp @@ -0,0 +1,118 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "oggstreamstate.h" + +// ----------------------------------------------------------------------------- + +BS_OggStreamState::BS_OggStreamState(int SerialNo) +{ + ogg_stream_init(&m_State, SerialNo); +} + +// ----------------------------------------------------------------------------- + +BS_OggStreamState::~BS_OggStreamState() +{ + ogg_stream_clear(&m_State); + + // Alle gepufferten Pages löschen. + while (!m_PageBuffer.empty()) + { + delete [] m_PageBuffer.front().header; + delete [] m_PageBuffer.front().body; + m_PageBuffer.pop(); + } +} + +// ----------------------------------------------------------------------------- + +int BS_OggStreamState::PageIn(ogg_page * PagePtr) +{ + return ogg_stream_pagein(&m_State, PagePtr); +} + +// ----------------------------------------------------------------------------- + +int BS_OggStreamState::PacketOut(ogg_packet * PacketPtr) +{ + return ogg_stream_packetout(&m_State, PacketPtr); +} + +// ----------------------------------------------------------------------------- + +void BS_OggStreamState::BufferPage(ogg_page * PagePtr) +{ + if (PageBelongsToStream(PagePtr)) + { + // Pages können nicht direkt gespeichert werden, da die Pointer im Laufe der Zeit ungültig werden. + // Daher wird an dieser Stelle eine tiefe Kopie der Page im erzeugt und im Pagebuffer angelegt. + ogg_page PageCopy; + PageCopy.header_len = PagePtr->header_len; + PageCopy.header = new unsigned char[PageCopy.header_len]; + memcpy(PageCopy.header, PagePtr->header, PageCopy.header_len); + PageCopy.body_len = PagePtr->body_len; + PageCopy.body = new unsigned char[PageCopy.body_len]; + memcpy(PageCopy.body, PagePtr->body, PageCopy.body_len); + + m_PageBuffer.push(PageCopy); + } +} + +// ----------------------------------------------------------------------------- + +int BS_OggStreamState::PageInBufferedPage() +{ + if (GetPageBufferSize() > 0) + { + // Page in den Stream einfügen, löschen und aus dem Puffer entfernen. + int Result = PageIn(&m_PageBuffer.front()); + delete [] m_PageBuffer.front().header; + delete [] m_PageBuffer.front().body; + m_PageBuffer.pop(); + return Result; + } + + return -1; +} + +// ----------------------------------------------------------------------------- + +unsigned int BS_OggStreamState::GetPageBufferSize() const +{ + return m_PageBuffer.size(); +} + +// ----------------------------------------------------------------------------- + +unsigned int BS_OggStreamState::GetUnprocessedBytes() const +{ + return m_State.body_fill - m_State.body_returned; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggStreamState::PageBelongsToStream(ogg_page * PagePtr) const +{ + return m_State.serialno == ogg_page_serialno(PagePtr); +} diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.h b/engines/sword25/fmv/oggtheora/oggstreamstate.h new file mode 100755 index 0000000000..9460c7286f --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.h @@ -0,0 +1,74 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_OGGSTREAMSTATE_H +#define BS_OGGSTREAMSTATE_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" +#include "ogg/ogg.h" +#include +// XXX +#include +// XXX + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_OggStreamState +{ +public: + BS_OggStreamState(int SerialNo); + virtual ~BS_OggStreamState(); + + int PageIn(ogg_page * PagePtr); + int PacketOut(ogg_packet * PacketPtr); + + void BufferPage(ogg_page * PagePtr); + int PageInBufferedPage(); + unsigned int GetPageBufferSize() const; + + unsigned int GetUnprocessedBytes() const; + bool PageBelongsToStream(ogg_page * PagePtr) const; + + // XXX + void DumpInternals() + { + using namespace std; + + cout << "body_storage: " << m_State.body_storage << endl; + cout << "body_fill: " << m_State.body_fill << endl; + cout << "body_returned: " << m_State.body_returned << endl; + cout << "lacing_storage: " << m_State.lacing_storage << endl; + cout << "lacing_fill: " << m_State.lacing_fill << endl; + cout << "lacing_returned: " << m_State.lacing_returned << endl; + cout << endl; + } + // XXX + +private: + ogg_stream_state m_State; + std::queue m_PageBuffer; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp new file mode 100755 index 0000000000..c5436dcc8f --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggtheora.cpp @@ -0,0 +1,709 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// The code in this file is based in part on code from the OggTheora Software +// codec source released under the following terms: +// +// Copyright (C) 2002-2007 Xiph.org Foundation +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the Xiph.org Foundation nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// ----------------------------------------------------------------------------- +// Logging +// ----------------------------------------------------------------------------- + +#define BS_LOG_PREFIX "OGGTHEORA" + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/memlog_off.h" +#include +#include "kernel/memlog_on.h" +#include + +#include "package/packagemanager.h" +#include "kernel/cpuinfo.h" +#include "sfx/soundengine.h" +#include "gfx/graphicengine.h" +#include "gfx/panel.h" +#include "oggtheora.h" +#include "yuvtorgba.h" + +using namespace std; + +// ----------------------------------------------------------------------------- +// Konstanten und Hilfsfunktionen +// ----------------------------------------------------------------------------- + +namespace +{ + // -------------------------------------------------------------------------- + + const int MAX_FRAMES_PER_TICK = 10; + const int READ_BLOCK_SIZE = 1024 * 40; + const float MAX_AUDIO_BUFFER_LENGTH = 1.0f; + + // -------------------------------------------------------------------------- + + template + inline T Clamp(T x, T low, T high) + { + return ((x > high) ? high : (( x < low) ? low : x)); + } +}; + +// ----------------------------------------------------------------------------- +// Konstruktion / Destruktion +// ----------------------------------------------------------------------------- + +BS_OggTheora::BS_OggTheora(BS_Kernel * pKernel) : BS_MoviePlayer(pKernel), m_SoundHandle(0) +{ + UnloadMovie(); +} + +// ----------------------------------------------------------------------------- + +BS_OggTheora::~BS_OggTheora() +{ + UnloadMovie(); +} + +// ----------------------------------------------------------------------------- + +BS_Service * BS_OggTheora_CreateObject(BS_Kernel* pKernel) { return new BS_OggTheora(pKernel); } + +// ----------------------------------------------------------------------------- +// BS_MoviePlayer Interface +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// LoadMovie() mit Hilfsfunktionen +// ----------------------------------------------------------------------------- + +namespace +{ + inline bool VerifyRequiredServiceAvailability() + { + char * RequiredServices[] = { "gfx", "sfx", "package" }; + for (size_t i = 0; i < sizeof(RequiredServices) / sizeof(RequiredServices[0]); ++i) + { + if (!BS_Kernel::GetInstance()->GetService(RequiredServices[i])) + { + BS_LOG_ERRORLN("Required service \"%s\" is not active.", RequiredServices[i]); + return false; + } + } + + return true; + } + + // ------------------------------------------------------------------------- + + bool ParseStreamHeaders(auto_ptr & File, + auto_ptr & OggState, + auto_ptr & TheoraStreamState, + auto_ptr & VorbisStreamState, + auto_ptr & TheoraState, + auto_ptr & VorbisState, + bool & TheoraPresent, + bool & VorbisPresent, + const std::string & Filename) + { + TheoraPresent = false; + VorbisPresent = false; + + // Ogg file open; parse the headers + // Only interested in Vorbis/Theora streams + bool FinishedHeaderParsing = false; + while (!FinishedHeaderParsing) + { + if (File->BufferData(*OggState.get()) == 0) return false; + + ogg_page Page; + while(OggState->SyncPageout(&Page) > 0) + { + // is this a mandated initial header? If not, stop parsing + if(!ogg_page_bos(&Page)) + { + // don't leak the page; get it into the appropriate stream + if (TheoraPresent) TheoraStreamState->PageIn(&Page); + if (VorbisPresent) VorbisStreamState->PageIn(&Page); + + FinishedHeaderParsing = true; + break; + } + + auto_ptr streamState(new BS_OggStreamState(ogg_page_serialno(&Page))); + + streamState->PageIn(&Page); + + ogg_packet Packet; + streamState->PacketOut(&Packet); + + // identify the codec: try theora + if(!TheoraPresent && TheoraState->DecodeHeader(&Packet) >= 0) + { + // it is theora + TheoraStreamState = streamState; + TheoraPresent = true; + } + else if(!VorbisPresent && VorbisState->SynthesisHeaderIn(&Packet) >=0) + { + // it is vorbis + VorbisStreamState = streamState; + VorbisPresent = true; + } + } + // fall through to non-bos page parsing + } + + // we're expecting more header packets. + unsigned int TheoraPacketsRead = TheoraPresent ? 1 : 0; + unsigned int VorbisPacketsRead = VorbisPresent ? 1 : 0; + while((TheoraPresent && TheoraPacketsRead < 3) || (VorbisPresent && VorbisPacketsRead < 3)) + { + int ret; + ogg_packet Packet; + + // look for further theora headers + while(TheoraPresent && (TheoraPacketsRead < 3) && (ret = TheoraStreamState->PacketOut(&Packet))) + { + if(ret < 0 || TheoraState->DecodeHeader(&Packet)) + { + BS_LOG_ERRORLN("Error parsing Theora stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); + return false; + } + + ++TheoraPacketsRead; + if (TheoraPacketsRead == 3) break; + } + + // look for more vorbis header packets + while(VorbisPresent && (VorbisPacketsRead < 3) && (ret = VorbisStreamState->PacketOut(&Packet))) + { + if(ret < 0 || VorbisState->SynthesisHeaderIn(&Packet)) + { + BS_LOG_ERRORLN("Error parsing Vorbis stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); + return false; + } + + ++VorbisPacketsRead; + if (VorbisPacketsRead == 3) break; + } + + // The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec + ogg_page Page; + if(OggState->SyncPageout(&Page) > 0) + { + // demux into the appropriate stream + if(TheoraPresent) TheoraStreamState->PageIn(&Page); + if(VorbisPresent) VorbisStreamState->PageIn(&Page); + } + else + { + if(File->BufferData(*OggState.get()) == 0) + { + BS_LOG_ERRORLN("End of file while searching for codec headers. (%s)", Filename.c_str()); + return false; + } + } + } + + return true; + } +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::LoadMovie(const std::string & Filename, unsigned int Z) +{ + if (!VerifyRequiredServiceAvailability()) return false; + + UnloadMovie(); + + // Alle Objekte die in dieser Funktion erzeugt werden, werden in zunächst lokalen Auto-Pointern gehalten. + // Bei erfolgreicher Beendigung dieser Funktion werden sie den objektlokalen Auto-Pointern zugewiesen. + // So wird sichergestellt, dass sie korrekt deinitialisiert werden, wenn in dieser Funktion ein Fehler auftritt, denn beim Zerstören der + // lokalen Auto-Pointer werden die entsprechenden Destruktoren aufgerufen. + + // Film laden + // Für Filmdateien wird das Cachingsystem nicht benutzt, da Filme in der Regel nur ein Mal abgespielt werden. + bool Success; + auto_ptr File(new BS_MovieFile(Filename, READ_BLOCK_SIZE, Success)); + if (!Success) return false; + + // States erzeugen für Ogg, Vorbis und Theora, sowie die Ogg und Theora Streams + auto_ptr OggState(new BS_OggState()); + auto_ptr VorbisState(new BS_VorbisState()); + auto_ptr TheoraState(new BS_TheoraState()); + + auto_ptr TheoraStreamState; + auto_ptr VorbisStreamState; + + if (!ParseStreamHeaders(File, OggState, TheoraStreamState, VorbisStreamState, TheoraState, VorbisState, m_TheoraPresent, m_VorbisPresent, Filename)) return false; + + // Theora-Decoder Initialisieren + if(m_TheoraPresent) + { + TheoraState->DecodeInit(); + + const theora_info & TheoraInfo = TheoraState->GetInfo(); + + if (TheoraInfo.pixelformat != OC_PF_444 && + TheoraInfo.pixelformat != OC_PF_422 && + TheoraInfo.pixelformat != OC_PF_420) + { + BS_LOG_ERRORLN("Unknown chroma sampling. (%s)", Filename.c_str()); + return false; + } + + // Ausgabebitmap erstellen + BS_GraphicEngine * pGfx = BS_Kernel::GetInstance()->GetGfx(); + m_OutputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(TheoraInfo.frame_width, TheoraInfo.frame_height); + if (!m_OutputBitmap.IsValid()) + { + BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); + return false; + } + + // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. + float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); + float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); + float ScaleFactor = std::min(ScreenToVideoWidth, ScreenToVideoHeight); + if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; + m_OutputBitmap->SetScaleFactor(ScaleFactor); + + // Z-Wert setzen + m_OutputBitmap->SetZ(Z); + + // Ausgabebitmap auf dem Bildschirm zentrieren + m_OutputBitmap->SetX((pGfx->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); + m_OutputBitmap->SetY((pGfx->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); + + // Buffer für die Pixeldaten erstellen + m_Pixels.resize(TheoraInfo.width * TheoraInfo.height * 4); + + m_VideoEnded = false; + } + + // Vorbis-Decoder initialisieren + if(m_VorbisPresent) + { + VorbisState->SynthesisInit(); + VorbisState->BlockInit(); + m_AudioBuffer.reset(new BS_AudioBuffer()); + + m_AudioEnded = false; + } + + // Keine Kopie, überträgt Besitz der erzeugten Objekte von der Funktion auf das Objekt. + m_File = File; + m_OggState = OggState; + m_TheoraState = TheoraState; + m_TheoraStreamState = TheoraStreamState; + m_VorbisState = VorbisState; + m_VorbisStreamState = VorbisStreamState; + m_MovieLoaded = true; + m_Timer = 0; + + return true; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::UnloadMovie() +{ + m_MovieLoaded = false; + m_Paused = true; + + m_VorbisStreamState.reset(); + m_VorbisPresent = false; + m_VorbisState.reset(); + if (m_SoundHandle) + { + BS_Kernel::GetInstance()->GetSfx()->StopSound(m_SoundHandle); + m_SoundHandle = 0; + } + m_AudioEnded = true; + m_AudioBuffer.reset(); + + m_TheoraStreamState.reset(); + m_TheoraPresent = false; + m_TheoraState.reset(); + m_VideoEnded = true; + + m_OggState.reset(); + + m_File.reset(); + + m_StartTime = 0; + m_LastFrameTime = 0; + m_Timer = 0.0f; + + vector().swap(m_Pixels); + m_OutputBitmap.Erase(); + + return true; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::Play() +{ + if (m_MovieLoaded) + { + if (m_Paused) + { + if (m_SoundHandle) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + SfxPtr->ResumeSound(m_SoundHandle); + } + m_Paused = false; + } + + return true; + } + else + { + BS_LOG_WARNINGLN("Cannot play movie, when no movie is loaded."); + return false; + } +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::Pause() +{ + if (m_MovieLoaded) + { + if (m_SoundHandle) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + SfxPtr->PauseSound(m_SoundHandle); + } + + m_Paused = true; + return true; + } + else + { + BS_LOG_WARNINGLN("Cannot pause movie, when no movie is loaded."); + return false; + } +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::ReadData() +{ + if (!m_File->IsEOF()) m_File->BufferData(*m_OggState.get()); + + ogg_page Page; + while(m_OggState->SyncPageout(&Page) > 0) + { + if(m_TheoraPresent) m_TheoraStreamState->BufferPage(&Page); + if(m_VorbisPresent) m_VorbisStreamState->BufferPage(&Page); + } +} + +void BS_OggTheora::Update() +{ + if (m_AudioEnded && m_VideoEnded) + { + m_Paused = true; + + // Falls der Sound noch läuft, muss er jetzt beendet werden. + if (m_SoundHandle) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + SfxPtr->StopSound(m_SoundHandle); + m_SoundHandle = 0; + } + } + + if (m_Paused) return; + + // Timer aktualisieren. + // Wird nur genutzt, wenn keine Audiodaten vorhanden sind. + m_Timer += BS_Kernel::GetInstance()->GetGfx()->GetSecondaryFrameDuration(); + + // Audiodaten dekodieren + if (m_VorbisPresent && !m_AudioEnded) DecodeVorbis(); + + + // Videodaten dekodieren + if (m_TheoraPresent && !m_VideoEnded) + { + bool Result = DecodeTheora(); + + if (Result) + { + // YUV Framebuffer holen + yuv_buffer YUVBuffer; + m_TheoraState->DecodeYUVOut(&YUVBuffer); + + // YUV Bilddaten nach RGBA konvertieren + BS_YUVtoRGBA::YUVtoRGBA(YUVBuffer, m_TheoraState->GetInfo(), m_Pixels); + + // RGBA Bilddaten auf das Ausgabebild kopieren, dabei die Postion des Theoraframes innerhalb des dekodierten Frames beachten. + const theora_info & TheoraInfo = m_TheoraState->GetInfo(); + m_OutputBitmap->SetContent(m_Pixels, (TheoraInfo.offset_x + TheoraInfo.width * TheoraInfo.offset_y) * 4, (TheoraInfo.width - TheoraInfo.frame_width) * 4); + } + } +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::DecodeTheora() +{ + double MovieTime = GetTime(); + + // Check if this frame time has not passed yet. If the frame is late we need + // to decode additonal ones and keep looping, since theora at this stage + // needs to decode all frames (due to keyframing) + // Getting the current time once at the beginning of the function rather than + // every time at the beginning of the loop produces the smoothest framerate + + unsigned int FramesDecoded = 0; + bool FrameReady = false; + while (m_TheoraState->GranuleTime() < MovieTime) + { + // theora is one in, one out... + ogg_packet Packet; + if(m_TheoraStreamState->PacketOut(&Packet) > 0) + { + if (FramesDecoded < MAX_FRAMES_PER_TICK || Packet.granulepos >= MovieTime) + { + m_TheoraState->DecodePacketIn(&Packet); + FrameReady = true; + ++FramesDecoded; + } + } + else + { + if (m_TheoraStreamState->GetPageBufferSize() > 0) + m_TheoraStreamState->PageInBufferedPage(); + else + { + if(m_File->IsEOF()) + { + m_VideoEnded = true; + break; + } + else + ReadData(); + } + } + } + m_LastFrameTime = MovieTime; + + return FrameReady; +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength) +{ + BS_OggTheora & t = *reinterpret_cast(UserData); + + signed short * Buffer = reinterpret_cast(Data); + + // Audiodaten in den Soundbuffer schreiben. + DataLength -= t.m_AudioBuffer->Pop(Buffer, DataLength / 2) * 2; + + // Falls nicht genug Audiodaten vorhanden waren, wird der Rest mit Stille überschrieben. + if (DataLength) + { + char * ByteBuffer = reinterpret_cast(Buffer); + while (DataLength--) + { + *ByteBuffer++ = 0; + } + } +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::DecodeVorbis() +{ + // Vorbis-Stream Infos holen. + const vorbis_info & Info = m_VorbisState->GetInfo(); + + // Maximalgröße des Audiobuffers berechnen. + size_t MaxAudioBufferSamples = static_cast(Info.channels * Info.rate * MAX_AUDIO_BUFFER_LENGTH); + + // Zwischenspeicher für die Samples. + vector Samples; + + // Audiobuffer bis zur Maximalgröße füllen, wenn möglich. + while (m_AudioBuffer->Size() < MaxAudioBufferSamples) + { + // Vorhandene Audiodaten auslesen + float ** PCM; + int SampleCount = m_VorbisState->SynthesisPCMout(&PCM); + + // Wenn Audiodaten gelesen werden konnten, werden diese in 16-Bit Sample umgewandelt und in den Audiobuffer geschrieben. + if(SampleCount > 0) + { + // Im Samplezwischenspeicher leeren und genügend Platz für die kommenden Samples reservieren. + Samples.reserve(SampleCount); + Samples.clear(); + + // Samples konvertieren und in die Samplezwischenspeicher schreiben. + for (int i = 0; i < SampleCount; ++i) + { + for(int j = 0; j < Info.channels; ++j) + { + int SampleValue = static_cast(PCM[j][i] * 32767.0f); + Samples.push_back(Clamp(SampleValue, -32700, 32700)); + } + } + + // Daten aus dem Samplezwischenspeicher in den Audiobuffer schreiben. + m_AudioBuffer->Push(&Samples[0], Samples.size()); + + // Vorbis mitteilen, dass wir alle Samples gelesen haben. + m_VorbisState->SynthesisRead(SampleCount); + } + else + { + // Wir konnten, keine Audiodaten auslesen, versuchen ein neues Paket zu dekodieren. + ogg_packet Packet; + if(m_VorbisStreamState->PacketOut(&Packet) > 0) + { + if (m_VorbisState->Synthesis(&Packet) == 0) m_VorbisState->SynthesisBlockIn(); + } + else + { + // Gepufferte Daten in den Stream einfügen. + if (m_VorbisStreamState->GetPageBufferSize() > 0) + m_VorbisStreamState->PageInBufferedPage(); + else + { + // Nicht genug Daten vorhanden. Wenn die Datei leer ist und bereits alle Audiodaten gelesen wurden, ist der Audiostream am Ende. + // Ansonsten Daten nachladen. + if(m_File->IsEOF()) + { + if (m_AudioBuffer->Size() == 0) + { + m_AudioEnded = true; + } + + break; + } + else + ReadData(); + } + } + } + } + + // Soundkanal abspielen, wenn er noch nicht spielt und Audiodaten vorhanden sind. + if (m_SoundHandle == 0 && m_AudioBuffer->Size()) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + m_SoundHandle = SfxPtr->PlayDynamicSoundEx(&DynamicSoundCallBack, this, BS_SoundEngine::SFX, Info.rate, 16, Info.channels); + } +} + +// ----------------------------------------------------------------------------- + +double BS_OggTheora::GetTime() +{ + if(m_VorbisPresent) + { + if (m_SoundHandle) + { + float time = BS_Kernel::GetInstance()->GetSfx()->GetSoundTime(m_SoundHandle); + return time; + } + else + return 0.0f; + } + else + return m_Timer; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::IsMovieLoaded() +{ + return m_MovieLoaded; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::IsPaused() +{ + return m_Paused; +} + +// ----------------------------------------------------------------------------- + +float BS_OggTheora::GetScaleFactor() +{ + if (m_MovieLoaded) + return m_OutputBitmap->GetScaleFactorX(); + else + return 0; +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::SetScaleFactor(float ScaleFactor) +{ + if (m_MovieLoaded) + { + m_OutputBitmap->SetScaleFactor(ScaleFactor); + + // Ausgabebitmap auf dem Bildschirm zentrieren + BS_GraphicEngine * GfxPtr = BS_Kernel::GetInstance()->GetGfx(); + m_OutputBitmap->SetX((GfxPtr->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); + m_OutputBitmap->SetY((GfxPtr->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); + } +} diff --git a/engines/sword25/fmv/oggtheora/oggtheora.h b/engines/sword25/fmv/oggtheora/oggtheora.h new file mode 100755 index 0000000000..0b43ba698d --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggtheora.h @@ -0,0 +1,109 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_OGGTHEORA_H +#define BS_OGGTHEORA_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/memlog_off.h" +#include +#include +#include +#include "kernel/memlog_on.h" + +#include "kernel/common.h" +#include "kernel/bs_stdint.h" +#include "gfx/bitmap.h" +#include "gfx/renderobjectptr.h" +#include "fmv/movieplayer.h" +#include "vorbisstate.h" +#include "theorastate.h" +#include "oggstate.h" +#include "oggstreamstate.h" +#include "moviefile.h" +#include "audiobuffer.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_OggTheora : public BS_MoviePlayer +{ +public: + // ----------------------------------------------------------------------------- + // Konstruktion / Destruktion + // ----------------------------------------------------------------------------- + + BS_OggTheora(BS_Kernel * pKernel); + virtual ~BS_OggTheora(); + + // ----------------------------------------------------------------------------- + // BS_MoviePlayer Interface + // ----------------------------------------------------------------------------- + + virtual bool LoadMovie(const std::string & Filename, unsigned int Z); + virtual bool UnloadMovie(); + virtual bool Play(); + virtual bool Pause(); + virtual void Update(); + virtual bool IsMovieLoaded(); + virtual bool IsPaused(); + virtual float GetScaleFactor(); + virtual void SetScaleFactor(float ScaleFactor); + virtual double GetTime(); + +private: + bool DecodeTheora(); + void DecodeVorbis(); + void RefillOggBuffer(); + void ReadData(); + static void DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength); + + bool m_MovieLoaded; + bool m_Paused; + + std::auto_ptr m_VorbisStreamState; + bool m_VorbisPresent; + std::auto_ptr m_VorbisState; + unsigned int m_SoundHandle; + bool m_AudioEnded; + std::auto_ptr m_AudioBuffer; + + std::auto_ptr m_TheoraStreamState; + bool m_TheoraPresent; + std::auto_ptr m_TheoraState; + bool m_VideoEnded; + + std::auto_ptr m_OggState; + + std::auto_ptr m_File; + + uint64_t m_StartTime; + double m_LastFrameTime; + + float m_Timer; + + std::vector m_Pixels; + BS_RenderObjectPtr m_OutputBitmap; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/theorastate.cpp b/engines/sword25/fmv/oggtheora/theorastate.cpp new file mode 100755 index 0000000000..853ef911ba --- /dev/null +++ b/engines/sword25/fmv/oggtheora/theorastate.cpp @@ -0,0 +1,79 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "theorastate.h" + +// ----------------------------------------------------------------------------- + +BS_TheoraState::BS_TheoraState() : + m_StateInitialized(false) +{ + theora_comment_init(&m_Comment); + theora_info_init(&m_Info); +} + +// ----------------------------------------------------------------------------- + +BS_TheoraState::~BS_TheoraState() +{ + if (m_StateInitialized) theora_clear(&m_State); + theora_info_clear(&m_Info); + theora_comment_clear(&m_Comment); +} + +// ----------------------------------------------------------------------------- + +int BS_TheoraState::DecodeHeader(ogg_packet * OggPacketPtr) +{ + return theora_decode_header(&m_Info, &m_Comment, OggPacketPtr); +} + +// ----------------------------------------------------------------------------- + +int BS_TheoraState::DecodeInit() +{ + int Result = theora_decode_init(&m_State, &m_Info); + m_StateInitialized = (Result == 0); + return Result; +} + +// ----------------------------------------------------------------------------- + +double BS_TheoraState::GranuleTime() +{ + return theora_granule_time(&m_State, m_State.granulepos); +} + +// ----------------------------------------------------------------------------- + +int BS_TheoraState::DecodePacketIn(ogg_packet * OggPacketPtr) +{ + return theora_decode_packetin(&m_State, OggPacketPtr); +} + +// ----------------------------------------------------------------------------- + +int BS_TheoraState::DecodeYUVOut(yuv_buffer * YUV) +{ + return theora_decode_YUVout(&m_State, YUV); +} diff --git a/engines/sword25/fmv/oggtheora/theorastate.h b/engines/sword25/fmv/oggtheora/theorastate.h new file mode 100755 index 0000000000..582215bad9 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/theorastate.h @@ -0,0 +1,55 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_THEORASTATE_H +#define BS_THEORASTATE_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" +#include "theora/theora.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_TheoraState +{ +public: + BS_TheoraState(); + virtual ~BS_TheoraState(); + + int DecodeHeader(ogg_packet * OggPacketPtr); + int DecodeInit(); + int DecodePacketIn(ogg_packet * OggPacketPtr); + int DecodeYUVOut(yuv_buffer * YUV); + double GranuleTime(); + + const theora_info & GetInfo() const { return m_Info; } + +private: + theora_info m_Info; + theora_comment m_Comment; + bool m_StateInitialized; + theora_state m_State; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.cpp b/engines/sword25/fmv/oggtheora/vorbisstate.cpp new file mode 100755 index 0000000000..683b6fd0d7 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/vorbisstate.cpp @@ -0,0 +1,97 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "vorbisstate.h" + +// ----------------------------------------------------------------------------- + +BS_VorbisState::BS_VorbisState() : + m_DSPStateInitialized(false), + m_BlockInitialized(false) +{ + vorbis_info_init(&m_Info); + vorbis_comment_init(&m_Comment); +} + +// ----------------------------------------------------------------------------- + +BS_VorbisState::~BS_VorbisState() +{ + if (m_BlockInitialized) vorbis_block_clear(&m_Block); + if (m_DSPStateInitialized) vorbis_dsp_clear(&m_DSPState); + vorbis_comment_clear(&m_Comment); + vorbis_info_clear(&m_Info); +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::SynthesisHeaderIn(ogg_packet * OggPacketPtr) +{ + return vorbis_synthesis_headerin(&m_Info, &m_Comment, OggPacketPtr); +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::SynthesisInit() +{ + int Result = vorbis_synthesis_init(&m_DSPState, &m_Info); + m_DSPStateInitialized = (Result == 0); + return Result; +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::BlockInit() +{ + int Result = vorbis_block_init(&m_DSPState, &m_Block); + m_BlockInitialized = (Result == 0); + return Result; +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::SynthesisPCMout(float *** PCM) +{ + return vorbis_synthesis_pcmout(&m_DSPState, PCM); +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::SynthesisRead(int Samples) +{ + return vorbis_synthesis_read(&m_DSPState, Samples); +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::Synthesis(ogg_packet * OggPacketPtr) +{ + return vorbis_synthesis(&m_Block, OggPacketPtr); +} + +// ----------------------------------------------------------------------------- + +int BS_VorbisState::SynthesisBlockIn() +{ + return vorbis_synthesis_blockin(&m_DSPState, &m_Block); +} diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.h b/engines/sword25/fmv/oggtheora/vorbisstate.h new file mode 100755 index 0000000000..193e115637 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/vorbisstate.h @@ -0,0 +1,59 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_VORBISSTATE_H +#define BS_VORBISSTATE_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/common.h" +#include "vorbis/codec.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_VorbisState +{ +public: + BS_VorbisState(); + virtual ~BS_VorbisState(); + + int SynthesisHeaderIn(ogg_packet * OggPacketPtr); + int SynthesisInit(); + int BlockInit(); + int SynthesisPCMout(float *** PCM); + int SynthesisRead(int Samples); + int Synthesis(ogg_packet * OggPacketPtr); + int SynthesisBlockIn(); + + const vorbis_info & GetInfo() const { return m_Info; } + +private: + vorbis_info m_Info; + bool m_DSPStateInitialized; + vorbis_dsp_state m_DSPState; + bool m_BlockInitialized; + vorbis_block m_Block; + vorbis_comment m_Comment; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp new file mode 100755 index 0000000000..0e709b12e0 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp @@ -0,0 +1,416 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/cpuinfo.h" +#include "yuvtorgba.h" + +#include + +using namespace std; + +// ----------------------------------------------------------------------------- + +namespace +{ + + static const int PRECISION = 32768; + static const int COEFFS_Y[256] = { + -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, + 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, + 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, + 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, + 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, + 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, + 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, + 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, + 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, + 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, + 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, + 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, + 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, + 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, + 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, + 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, + }; + static const int COEFFS_RV[256] = { + -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, + -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, + -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, + -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, + -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, + -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, + -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, + -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, + 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, + 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, + 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, + 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, + 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, + 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, + 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, + 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, + }; + static const int COEFFS_GU[256] = { + 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, + 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, + 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, + 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, + 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, + 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, + 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, + 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, + 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, + -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, + -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, + -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, + -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, + -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, + -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, + -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, + }; + static const int COEFFS_GV[256] = { + 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, + 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, + 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, + 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, + 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, + 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, + 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, + 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, + 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, + -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, + -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, + -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, + -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, + -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, + -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, + -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, + }; + static const int COEFFS_BU[256] = { + -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, + -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, + -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, + -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, + -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, + -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, + -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, + -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, + 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, + 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, + 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, + 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, + 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, + 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, + 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, + 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, + }; + static const int CLAMP_TAB[1024] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + }; + + void YUVtoRGBA_c(const yuv_buffer & YUVBuffer, std::vector & PixelData) + { + // Width and height of all buffers have to be divisible by 2. + BS_ASSERT((YUVBuffer.y_width & 1) == 0); + BS_ASSERT((YUVBuffer.y_height & 1) == 0); + BS_ASSERT((YUVBuffer.uv_width & 1) == 0); + BS_ASSERT((YUVBuffer.uv_height & 1) == 0); + // UV images have to have a quarter of the Y image resolution + BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); + BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); + + const int *cl = &CLAMP_TAB[320]; + + const unsigned char * ySrc0 = YUVBuffer.y; + const unsigned char * ySrc1 = YUVBuffer.y + YUVBuffer.y_stride; + const unsigned char * uSrc = YUVBuffer.u; + const unsigned char * vSrc = YUVBuffer.v; + unsigned char * dst0 = &PixelData[0]; + unsigned char * dst1 = &PixelData[0] + YUVBuffer.y_width * 4; + + for (int h = 0; h < YUVBuffer.y_height / 2; ++h) + { + for (int w = 0; w < YUVBuffer.y_width / 2; ++w) + { + int u = *uSrc++; + int v = *vSrc++; + + int rUV = COEFFS_RV[v]; + int gUV = COEFFS_GU[u] + COEFFS_GV[v]; + int bUV = COEFFS_BU[u]; + + int y = *ySrc0++; + int r = COEFFS_Y[y] + rUV; + int g = COEFFS_Y[y] + gUV; + int b = COEFFS_Y[y] + bUV; + *dst0++ = cl[r / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[b / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[r / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[b / PRECISION]; + *dst1++ = 255; + + y = *ySrc0++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst0++ = cl[r / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[b / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[r / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[b / PRECISION]; + *dst1++ = 255; + } + + dst0 += YUVBuffer.y_width * 4; + dst1 += YUVBuffer.y_width * 4; + ySrc0 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; + ySrc1 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; + uSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; + vSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; + } + } + + // ----------------------------------------------------------------------------- + + static const __m64 COEFF_Y_MMX[256] = { + 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, + 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, + 0x1fff000000000000, 0x1fff004a004a004a, 0x1fff009500950095, 0x1fff00df00df00df, 0x1fff012a012a012a, 0x1fff017401740174, 0x1fff01bf01bf01bf, 0x1fff020902090209, + 0x1fff025402540254, 0x1fff029e029e029e, 0x1fff02e902e902e9, 0x1fff033303330333, 0x1fff037e037e037e, 0x1fff03c803c803c8, 0x1fff041304130413, 0x1fff045d045d045d, + 0x1fff04a804a804a8, 0x1fff04f204f204f2, 0x1fff053d053d053d, 0x1fff058705870587, 0x1fff05d205d205d2, 0x1fff061c061c061c, 0x1fff066706670667, 0x1fff06b106b106b1, + 0x1fff06fc06fc06fc, 0x1fff074607460746, 0x1fff079107910791, 0x1fff07db07db07db, 0x1fff082608260826, 0x1fff087008700870, 0x1fff08bb08bb08bb, 0x1fff090509050905, + 0x1fff095009500950, 0x1fff099a099a099a, 0x1fff09e509e509e5, 0x1fff0a2f0a2f0a2f, 0x1fff0a7a0a7a0a7a, 0x1fff0ac40ac40ac4, 0x1fff0b0f0b0f0b0f, 0x1fff0b590b590b59, + 0x1fff0ba40ba40ba4, 0x1fff0bee0bee0bee, 0x1fff0c390c390c39, 0x1fff0c830c830c83, 0x1fff0cce0cce0cce, 0x1fff0d180d180d18, 0x1fff0d630d630d63, 0x1fff0dad0dad0dad, + 0x1fff0df80df80df8, 0x1fff0e420e420e42, 0x1fff0e8d0e8d0e8d, 0x1fff0ed70ed70ed7, 0x1fff0f220f220f22, 0x1fff0f6c0f6c0f6c, 0x1fff0fb70fb70fb7, 0x1fff100110011001, + 0x1fff104c104c104c, 0x1fff109610961096, 0x1fff10e110e110e1, 0x1fff112b112b112b, 0x1fff117611761176, 0x1fff11c011c011c0, 0x1fff120b120b120b, 0x1fff125512551255, + 0x1fff12a012a012a0, 0x1fff12ea12ea12ea, 0x1fff133513351335, 0x1fff137f137f137f, 0x1fff13ca13ca13ca, 0x1fff141414141414, 0x1fff145f145f145f, 0x1fff14a914a914a9, + 0x1fff14f414f414f4, 0x1fff153e153e153e, 0x1fff158915891589, 0x1fff15d315d315d3, 0x1fff161e161e161e, 0x1fff166816681668, 0x1fff16b316b316b3, 0x1fff16fd16fd16fd, + 0x1fff174817481748, 0x1fff179217921792, 0x1fff17dd17dd17dd, 0x1fff182718271827, 0x1fff187218721872, 0x1fff18bc18bc18bc, 0x1fff190719071907, 0x1fff195119511951, + 0x1fff199c199c199c, 0x1fff19e619e619e6, 0x1fff1a311a311a31, 0x1fff1a7b1a7b1a7b, 0x1fff1ac61ac61ac6, 0x1fff1b101b101b10, 0x1fff1b5b1b5b1b5b, 0x1fff1ba51ba51ba5, + 0x1fff1bf01bf01bf0, 0x1fff1c3a1c3a1c3a, 0x1fff1c851c851c85, 0x1fff1ccf1ccf1ccf, 0x1fff1d1a1d1a1d1a, 0x1fff1d641d641d64, 0x1fff1daf1daf1daf, 0x1fff1df91df91df9, + 0x1fff1e441e441e44, 0x1fff1e8e1e8e1e8e, 0x1fff1ed91ed91ed9, 0x1fff1f231f231f23, 0x1fff1f6e1f6e1f6e, 0x1fff1fb81fb81fb8, 0x1fff200320032003, 0x1fff204d204d204d, + 0x1fff209820982098, 0x1fff20e220e220e2, 0x1fff212d212d212d, 0x1fff217721772177, 0x1fff21c221c221c2, 0x1fff220c220c220c, 0x1fff225722572257, 0x1fff22a122a122a1, + 0x1fff22ec22ec22ec, 0x1fff233623362336, 0x1fff238123812381, 0x1fff23cb23cb23cb, 0x1fff241624162416, 0x1fff246024602460, 0x1fff24aa24aa24aa, 0x1fff24f524f524f5, + 0x1fff253f253f253f, 0x1fff258a258a258a, 0x1fff25d425d425d4, 0x1fff261f261f261f, 0x1fff266926692669, 0x1fff26b426b426b4, 0x1fff26fe26fe26fe, 0x1fff274927492749, + 0x1fff279327932793, 0x1fff27de27de27de, 0x1fff282828282828, 0x1fff287328732873, 0x1fff28bd28bd28bd, 0x1fff290829082908, 0x1fff295229522952, 0x1fff299d299d299d, + 0x1fff29e729e729e7, 0x1fff2a322a322a32, 0x1fff2a7c2a7c2a7c, 0x1fff2ac72ac72ac7, 0x1fff2b112b112b11, 0x1fff2b5c2b5c2b5c, 0x1fff2ba62ba62ba6, 0x1fff2bf12bf12bf1, + 0x1fff2c3b2c3b2c3b, 0x1fff2c862c862c86, 0x1fff2cd02cd02cd0, 0x1fff2d1b2d1b2d1b, 0x1fff2d652d652d65, 0x1fff2db02db02db0, 0x1fff2dfa2dfa2dfa, 0x1fff2e452e452e45, + 0x1fff2e8f2e8f2e8f, 0x1fff2eda2eda2eda, 0x1fff2f242f242f24, 0x1fff2f6f2f6f2f6f, 0x1fff2fb92fb92fb9, 0x1fff300430043004, 0x1fff304e304e304e, 0x1fff309930993099, + 0x1fff30e330e330e3, 0x1fff312e312e312e, 0x1fff317831783178, 0x1fff31c331c331c3, 0x1fff320d320d320d, 0x1fff325832583258, 0x1fff32a232a232a2, 0x1fff32ed32ed32ed, + 0x1fff333733373337, 0x1fff338233823382, 0x1fff33cc33cc33cc, 0x1fff341734173417, 0x1fff346134613461, 0x1fff34ac34ac34ac, 0x1fff34f634f634f6, 0x1fff354135413541, + 0x1fff358b358b358b, 0x1fff35d635d635d6, 0x1fff362036203620, 0x1fff366b366b366b, 0x1fff36b536b536b5, 0x1fff370037003700, 0x1fff374a374a374a, 0x1fff379537953795, + 0x1fff37df37df37df, 0x1fff382a382a382a, 0x1fff387438743874, 0x1fff38bf38bf38bf, 0x1fff390939093909, 0x1fff395439543954, 0x1fff399e399e399e, 0x1fff39e939e939e9, + 0x1fff3a333a333a33, 0x1fff3a7e3a7e3a7e, 0x1fff3ac83ac83ac8, 0x1fff3b133b133b13, 0x1fff3b5d3b5d3b5d, 0x1fff3ba83ba83ba8, 0x1fff3bf23bf23bf2, 0x1fff3c3d3c3d3c3d, + 0x1fff3c873c873c87, 0x1fff3cd23cd23cd2, 0x1fff3d1c3d1c3d1c, 0x1fff3d673d673d67, 0x1fff3db13db13db1, 0x1fff3dfc3dfc3dfc, 0x1fff3e463e463e46, 0x1fff3e913e913e91, + 0x1fff3edb3edb3edb, 0x1fff3f263f263f26, 0x1fff3f703f703f70, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, + 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, + 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, + }; + static const __m64 COEFF_U_MMX[256] = { + 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, + 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, + 0x1fffc7800af30000, 0x1fffc8010ada0000, 0x1fffc8820ac10000, 0x1fffc9030aa80000, 0x1fffc9850a8f0000, 0x1fffca060a760000, 0x1fffca870a5d0000, 0x1fffcb080a440000, + 0x1fffcb890a2a0000, 0x1fffcc0a0a110000, 0x1fffcc8b09f80000, 0x1fffcd0d09df0000, 0x1fffcd8e09c60000, 0x1fffce0f09ad0000, 0x1fffce9009940000, 0x1fffcf11097b0000, + 0x1fffcf9209620000, 0x1fffd01409490000, 0x1fffd09509300000, 0x1fffd11609170000, 0x1fffd19708fe0000, 0x1fffd21808e50000, 0x1fffd29908cc0000, 0x1fffd31a08b30000, + 0x1fffd39c089a0000, 0x1fffd41d08810000, 0x1fffd49e08680000, 0x1fffd51f084f0000, 0x1fffd5a008360000, 0x1fffd621081d0000, 0x1fffd6a308040000, 0x1fffd72407eb0000, + 0x1fffd7a507d20000, 0x1fffd82607b90000, 0x1fffd8a707a00000, 0x1fffd92807870000, 0x1fffd9a9076e0000, 0x1fffda2b07550000, 0x1fffdaac073c0000, 0x1fffdb2d07230000, + 0x1fffdbae070a0000, 0x1fffdc2f06f10000, 0x1fffdcb006d80000, 0x1fffdd3206bf0000, 0x1fffddb306a60000, 0x1fffde34068d0000, 0x1fffdeb506740000, 0x1fffdf36065b0000, + 0x1fffdfb706420000, 0x1fffe03806290000, 0x1fffe0ba060f0000, 0x1fffe13b05f60000, 0x1fffe1bc05dd0000, 0x1fffe23d05c40000, 0x1fffe2be05ab0000, 0x1fffe33f05920000, + 0x1fffe3c005790000, 0x1fffe44205600000, 0x1fffe4c305470000, 0x1fffe544052e0000, 0x1fffe5c505150000, 0x1fffe64604fc0000, 0x1fffe6c704e30000, 0x1fffe74904ca0000, + 0x1fffe7ca04b10000, 0x1fffe84b04980000, 0x1fffe8cc047f0000, 0x1fffe94d04660000, 0x1fffe9ce044d0000, 0x1fffea4f04340000, 0x1fffead1041b0000, 0x1fffeb5204020000, + 0x1fffebd303e90000, 0x1fffec5403d00000, 0x1fffecd503b70000, 0x1fffed56039e0000, 0x1fffedd803850000, 0x1fffee59036c0000, 0x1fffeeda03530000, 0x1fffef5b033a0000, + 0x1fffefdc03210000, 0x1ffff05d03080000, 0x1ffff0de02ef0000, 0x1ffff16002d60000, 0x1ffff1e102bd0000, 0x1ffff26202a40000, 0x1ffff2e3028b0000, 0x1ffff36402720000, + 0x1ffff3e502590000, 0x1ffff46702400000, 0x1ffff4e802270000, 0x1ffff569020e0000, 0x1ffff5ea01f40000, 0x1ffff66b01db0000, 0x1ffff6ec01c20000, 0x1ffff76d01a90000, + 0x1ffff7ef01900000, 0x1ffff87001770000, 0x1ffff8f1015e0000, 0x1ffff97201450000, 0x1ffff9f3012c0000, 0x1ffffa7401130000, 0x1ffffaf500fa0000, 0x1ffffb7700e10000, + 0x1ffffbf800c80000, 0x1ffffc7900af0000, 0x1ffffcfa00960000, 0x1ffffd7b007d0000, 0x1ffffdfc00640000, 0x1ffffe7e004b0000, 0x1ffffeff00320000, 0x1fffff8000190000, + 0x1fff000000000000, 0x1fff0081ffe80000, 0x1fff0102ffcf0000, 0x1fff0183ffb60000, 0x1fff0205ff9d0000, 0x1fff0286ff840000, 0x1fff0307ff6b0000, 0x1fff0388ff520000, + 0x1fff0409ff390000, 0x1fff048aff200000, 0x1fff050cff070000, 0x1fff058dfeee0000, 0x1fff060efed50000, 0x1fff068ffebc0000, 0x1fff0710fea30000, 0x1fff0791fe8a0000, + 0x1fff0812fe710000, 0x1fff0894fe580000, 0x1fff0915fe3f0000, 0x1fff0996fe260000, 0x1fff0a17fe0d0000, 0x1fff0a98fdf30000, 0x1fff0b19fdda0000, 0x1fff0b9afdc10000, + 0x1fff0c1cfda80000, 0x1fff0c9dfd8f0000, 0x1fff0d1efd760000, 0x1fff0d9ffd5d0000, 0x1fff0e20fd440000, 0x1fff0ea1fd2b0000, 0x1fff0f23fd120000, 0x1fff0fa4fcf90000, + 0x1fff1025fce00000, 0x1fff10a6fcc70000, 0x1fff1127fcae0000, 0x1fff11a8fc950000, 0x1fff1229fc7c0000, 0x1fff12abfc630000, 0x1fff132cfc4a0000, 0x1fff13adfc310000, + 0x1fff142efc180000, 0x1fff14affbff0000, 0x1fff1530fbe60000, 0x1fff15b2fbcd0000, 0x1fff1633fbb40000, 0x1fff16b4fb9b0000, 0x1fff1735fb820000, 0x1fff17b6fb690000, + 0x1fff1837fb500000, 0x1fff18b8fb370000, 0x1fff193afb1e0000, 0x1fff19bbfb050000, 0x1fff1a3cfaec0000, 0x1fff1abdfad30000, 0x1fff1b3efaba0000, 0x1fff1bbffaa10000, + 0x1fff1c41fa880000, 0x1fff1cc2fa6f0000, 0x1fff1d43fa560000, 0x1fff1dc4fa3d0000, 0x1fff1e45fa240000, 0x1fff1ec6fa0b0000, 0x1fff1f47f9f20000, 0x1fff1fc9f9d80000, + 0x1fff204af9bf0000, 0x1fff20cbf9a60000, 0x1fff214cf98d0000, 0x1fff21cdf9740000, 0x1fff224ef95b0000, 0x1fff22cff9420000, 0x1fff2351f9290000, 0x1fff23d2f9100000, + 0x1fff2453f8f70000, 0x1fff24d4f8de0000, 0x1fff2555f8c50000, 0x1fff25d6f8ac0000, 0x1fff2658f8930000, 0x1fff26d9f87a0000, 0x1fff275af8610000, 0x1fff27dbf8480000, + 0x1fff285cf82f0000, 0x1fff28ddf8160000, 0x1fff295ef7fd0000, 0x1fff29e0f7e40000, 0x1fff2a61f7cb0000, 0x1fff2ae2f7b20000, 0x1fff2b63f7990000, 0x1fff2be4f7800000, + 0x1fff2c65f7670000, 0x1fff2ce7f74e0000, 0x1fff2d68f7350000, 0x1fff2de9f71c0000, 0x1fff2e6af7030000, 0x1fff2eebf6ea0000, 0x1fff2f6cf6d10000, 0x1fff2fedf6b80000, + 0x1fff306ff69f0000, 0x1fff30f0f6860000, 0x1fff3171f66d0000, 0x1fff31f2f6540000, 0x1fff3273f63b0000, 0x1fff32f4f6220000, 0x1fff3376f6090000, 0x1fff33f7f5f00000, + 0x1fff3478f5d70000, 0x1fff34f9f5bd0000, 0x1fff357af5a40000, 0x1fff35fbf58b0000, 0x1fff367cf5720000, 0x1fff36fef5590000, 0x1fff377ff5400000, 0x1fff3800f5270000, + 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, + 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, + }; + static const __m64 COEFF_V_MMX[256] = { + 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, + 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, + 0x1fff000016c4d351, 0x1fff00001690d3b7, 0x1fff0000165cd41d, 0x1fff00001627d483, 0x1fff000015f3d4e9, 0x1fff000015bfd550, 0x1fff0000158bd5b6, 0x1fff00001557d61c, + 0x1fff00001523d682, 0x1fff000014efd6e8, 0x1fff000014bbd74e, 0x1fff00001487d7b4, 0x1fff00001453d81b, 0x1fff0000141fd881, 0x1fff000013ebd8e7, 0x1fff000013b7d94d, + 0x1fff00001383d9b3, 0x1fff0000134fda19, 0x1fff0000131bda7f, 0x1fff000012e7dae6, 0x1fff000012b3db4c, 0x1fff0000127fdbb2, 0x1fff0000124bdc18, 0x1fff00001217dc7e, + 0x1fff000011e3dce4, 0x1fff000011afdd4a, 0x1fff0000117bddb1, 0x1fff00001147de17, 0x1fff00001113de7d, 0x1fff000010dfdee3, 0x1fff000010abdf49, 0x1fff00001077dfaf, + 0x1fff00001043e015, 0x1fff0000100fe07c, 0x1fff00000fdae0e2, 0x1fff00000fa6e148, 0x1fff00000f72e1ae, 0x1fff00000f3ee214, 0x1fff00000f0ae27a, 0x1fff00000ed6e2e0, + 0x1fff00000ea2e347, 0x1fff00000e6ee3ad, 0x1fff00000e3ae413, 0x1fff00000e06e479, 0x1fff00000dd2e4df, 0x1fff00000d9ee545, 0x1fff00000d6ae5ab, 0x1fff00000d36e612, + 0x1fff00000d02e678, 0x1fff00000ccee6de, 0x1fff00000c9ae744, 0x1fff00000c66e7aa, 0x1fff00000c32e810, 0x1fff00000bfee877, 0x1fff00000bcae8dd, 0x1fff00000b96e943, + 0x1fff00000b62e9a9, 0x1fff00000b2eea0f, 0x1fff00000afaea75, 0x1fff00000ac6eadb, 0x1fff00000a92eb42, 0x1fff00000a5eeba8, 0x1fff00000a2aec0e, 0x1fff000009f6ec74, + 0x1fff000009c2ecda, 0x1fff0000098eed40, 0x1fff00000959eda6, 0x1fff00000925ee0d, 0x1fff000008f1ee73, 0x1fff000008bdeed9, 0x1fff00000889ef3f, 0x1fff00000855efa5, + 0x1fff00000821f00b, 0x1fff000007edf071, 0x1fff000007b9f0d8, 0x1fff00000785f13e, 0x1fff00000751f1a4, 0x1fff0000071df20a, 0x1fff000006e9f270, 0x1fff000006b5f2d6, + 0x1fff00000681f33c, 0x1fff0000064df3a3, 0x1fff00000619f409, 0x1fff000005e5f46f, 0x1fff000005b1f4d5, 0x1fff0000057df53b, 0x1fff00000549f5a1, 0x1fff00000515f607, + 0x1fff000004e1f66e, 0x1fff000004adf6d4, 0x1fff00000479f73a, 0x1fff00000445f7a0, 0x1fff00000411f806, 0x1fff000003ddf86c, 0x1fff000003a9f8d2, 0x1fff00000375f939, + 0x1fff00000341f99f, 0x1fff0000030cfa05, 0x1fff000002d8fa6b, 0x1fff000002a4fad1, 0x1fff00000270fb37, 0x1fff0000023cfb9d, 0x1fff00000208fc04, 0x1fff000001d4fc6a, + 0x1fff000001a0fcd0, 0x1fff0000016cfd36, 0x1fff00000138fd9c, 0x1fff00000104fe02, 0x1fff000000d0fe68, 0x1fff0000009cfecf, 0x1fff00000068ff35, 0x1fff00000034ff9b, + 0x1fff000000000000, 0x1fff0000ffcd0066, 0x1fff0000ff9900cc, 0x1fff0000ff650132, 0x1fff0000ff310199, 0x1fff0000fefd01ff, 0x1fff0000fec90265, 0x1fff0000fe9502cb, + 0x1fff0000fe610331, 0x1fff0000fe2d0397, 0x1fff0000fdf903fd, 0x1fff0000fdc50464, 0x1fff0000fd9104ca, 0x1fff0000fd5d0530, 0x1fff0000fd290596, 0x1fff0000fcf505fc, + 0x1fff0000fcc00662, 0x1fff0000fc8c06c8, 0x1fff0000fc58072f, 0x1fff0000fc240795, 0x1fff0000fbf007fb, 0x1fff0000fbbc0861, 0x1fff0000fb8808c7, 0x1fff0000fb54092d, + 0x1fff0000fb200993, 0x1fff0000faec09fa, 0x1fff0000fab80a60, 0x1fff0000fa840ac6, 0x1fff0000fa500b2c, 0x1fff0000fa1c0b92, 0x1fff0000f9e80bf8, 0x1fff0000f9b40c5e, + 0x1fff0000f9800cc5, 0x1fff0000f94c0d2b, 0x1fff0000f9180d91, 0x1fff0000f8e40df7, 0x1fff0000f8b00e5d, 0x1fff0000f87c0ec3, 0x1fff0000f8480f29, 0x1fff0000f8140f90, + 0x1fff0000f7e00ff6, 0x1fff0000f7ac105c, 0x1fff0000f77810c2, 0x1fff0000f7441128, 0x1fff0000f710118e, 0x1fff0000f6dc11f4, 0x1fff0000f6a8125b, 0x1fff0000f67312c1, + 0x1fff0000f63f1327, 0x1fff0000f60b138d, 0x1fff0000f5d713f3, 0x1fff0000f5a31459, 0x1fff0000f56f14bf, 0x1fff0000f53b1526, 0x1fff0000f507158c, 0x1fff0000f4d315f2, + 0x1fff0000f49f1658, 0x1fff0000f46b16be, 0x1fff0000f4371724, 0x1fff0000f403178a, 0x1fff0000f3cf17f1, 0x1fff0000f39b1857, 0x1fff0000f36718bd, 0x1fff0000f3331923, + 0x1fff0000f2ff1989, 0x1fff0000f2cb19ef, 0x1fff0000f2971a56, 0x1fff0000f2631abc, 0x1fff0000f22f1b22, 0x1fff0000f1fb1b88, 0x1fff0000f1c71bee, 0x1fff0000f1931c54, + 0x1fff0000f15f1cba, 0x1fff0000f12b1d21, 0x1fff0000f0f71d87, 0x1fff0000f0c31ded, 0x1fff0000f08f1e53, 0x1fff0000f05b1eb9, 0x1fff0000f0271f1f, 0x1fff0000eff21f85, + 0x1fff0000efbe1fec, 0x1fff0000ef8a2052, 0x1fff0000ef5620b8, 0x1fff0000ef22211e, 0x1fff0000eeee2184, 0x1fff0000eeba21ea, 0x1fff0000ee862250, 0x1fff0000ee5222b7, + 0x1fff0000ee1e231d, 0x1fff0000edea2383, 0x1fff0000edb623e9, 0x1fff0000ed82244f, 0x1fff0000ed4e24b5, 0x1fff0000ed1a251b, 0x1fff0000ece62582, 0x1fff0000ecb225e8, + 0x1fff0000ec7e264e, 0x1fff0000ec4a26b4, 0x1fff0000ec16271a, 0x1fff0000ebe22780, 0x1fff0000ebae27e6, 0x1fff0000eb7a284d, 0x1fff0000eb4628b3, 0x1fff0000eb122919, + 0x1fff0000eade297f, 0x1fff0000eaaa29e5, 0x1fff0000ea762a4b, 0x1fff0000ea422ab1, 0x1fff0000ea0e2b18, 0x1fff0000e9da2b7e, 0x1fff0000e9a52be4, 0x1fff0000e9712c4a, + 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, + 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, + }; + + // ----------------------------------------------------------------------------- + + void YUVtoRGBA_MMX(yuv_buffer & YUVBuffer, std::vector & PixelData) + { + // Width and height of all buffers have to be divisible by 4. + BS_ASSERT((YUVBuffer.y_width & 3) == 0); + BS_ASSERT((YUVBuffer.y_height & 3) == 0); + BS_ASSERT((YUVBuffer.uv_width & 3) == 0); + BS_ASSERT((YUVBuffer.uv_height & 3) == 0); + // UV images have to have a quarter of the Y image resolution + BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); + BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); + + const unsigned char * ySrc = YUVBuffer.y; + const unsigned char * uSrc = YUVBuffer.u; + const unsigned char * vSrc = YUVBuffer.v; + unsigned char * dst = &PixelData[0]; + + const int yPadding = YUVBuffer.y_stride - YUVBuffer.y_width; + int uvStride = YUVBuffer.uv_stride; + + for (int h = 0; h < YUVBuffer.y_height; ++h) + { + uvStride ^= YUVBuffer.uv_stride; + for (int w = 0; w < YUVBuffer.y_width / 4; ++w) + { + __m64 uvCoeff0 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); + __m64 uvCoeff1 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); + + __m64 px01 = COEFF_Y_MMX[*ySrc++]; + __m64 px23 = COEFF_Y_MMX[*ySrc++]; + __m64 px45 = COEFF_Y_MMX[*ySrc++]; + __m64 px67 = COEFF_Y_MMX[*ySrc++]; + + px01 = _m_paddw(px01, uvCoeff0); + px23 = _m_paddw(px23, uvCoeff0); + px45 = _m_paddw(px45, uvCoeff1); + px67 = _m_paddw(px67, uvCoeff1); + + px01 = _m_psrawi(px01, 6); + px23 = _m_psrawi(px23, 6); + px45 = _m_psrawi(px45, 6); + px67 = _m_psrawi(px67, 6); + + ((__m64*)dst)[0] = _m_packuswb(px01, px23); + ((__m64*)dst)[1] = _m_packuswb(px45, px67); + dst += 16; + } + + ySrc += yPadding; + uSrc += uvStride - YUVBuffer.uv_width; + vSrc += uvStride - YUVBuffer.uv_width; + } + + _m_empty(); + } + +} + +// ----------------------------------------------------------------------------- + +void BS_YUVtoRGBA::YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, vector & Pixels) +{ + BS_ASSERT(TheoraInfo.pixelformat == OC_PF_420); + BS_ASSERT(int(Pixels.size()) >= YUVBuffer.y_width * YUVBuffer.y_height); + + return YUVtoRGBA_c(YUVBuffer, Pixels); + + if (BS_CPUInfo::GetInstance().IsMMXSupported()) + return YUVtoRGBA_MMX(YUVBuffer, Pixels); + else + return YUVtoRGBA_c(YUVBuffer, Pixels); +} diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.h b/engines/sword25/fmv/oggtheora/yuvtorgba.h new file mode 100755 index 0000000000..0bd74e5a18 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.h @@ -0,0 +1,44 @@ +// ----------------------------------------------------------------------------- +// This file is part of Broken Sword 2.5 +// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer +// +// Broken Sword 2.5 is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// Broken Sword 2.5 is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Broken Sword 2.5; if not, write to the Free Software +// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +// ----------------------------------------------------------------------------- + +#ifndef BS_YUVTORGBA_H +#define BS_YUVTORGBA_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "kernel/memlog_off.h" +#include +#include "kernel/memlog_on.h" + +#include "kernel/common.h" +#include "theora/theora.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_YUVtoRGBA +{ +public: + static void YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, std::vector & Pixels); +}; + +#endif -- cgit v1.2.3 From 7b964a2823406721ec1200938948c0cfcdb3f1b1 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 Jul 2010 19:55:03 +0000 Subject: SWORD25: Make couple file compilable svn-id: r53179 --- engines/sword25/fmv/movieplayer.cpp | 2 +- engines/sword25/fmv/movieplayer.h | 12 ++++++------ engines/sword25/fmv/movieplayer_script.cpp | 10 +++++----- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index f7df544a48..a9aacc48fc 100755 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -21,7 +21,7 @@ // Includes // ----------------------------------------------------------------------------- -#include "movieplayer.h" +#include "sword25/fmv/movieplayer.h" #define BS_LOG_PREFIX "MOVIEPLAYER" diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index ed9e94edad..c08969a5a2 100755 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -17,19 +17,19 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_MOVIEPLAYER_H -#define BS_MOVIEPLAYER_H +#ifndef SWORD25_MOVIEPLAYER_H +#define SWORD25_MOVIEPLAYER_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" -#include "kernel/service.h" +#include "sword25/kernel/common.h" +#include "sword25/kernel/service.h" -#include "kernel/memlog_off.h" +#include "sword25/kernel/memlog_off.h" #include -#include "kernel/memlog_on.h" +#include "sword25/kernel/memlog_on.h" // ----------------------------------------------------------------------------- // Klassendefinition diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index c5160122d0..43ec6506b4 100755 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -21,12 +21,12 @@ // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" -#include "kernel/kernel.h" -#include "script/script.h" -#include "script/luabindhelper.h" +#include "sword25/kernel/common.h" +#include "sword25/kernel/kernel.h" +#include "sword25/script/script.h" +#include "sword25/script/luabindhelper.h" -#include "movieplayer.h" +#include "sword25/fmv/movieplayer.h" namespace { -- cgit v1.2.3 From 65da804f583460739aec3bfe35b70310af1ee5a9 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 29 Jul 2010 19:55:28 +0000 Subject: SWORD25: Path fixes for includes svn-id: r53180 --- engines/sword25/fmv/oggtheora/audiobuffer.cpp | 2 +- engines/sword25/fmv/oggtheora/audiobuffer.h | 6 ++--- engines/sword25/fmv/oggtheora/moviefile.cpp | 8 +++--- engines/sword25/fmv/oggtheora/moviefile.h | 10 ++++---- engines/sword25/fmv/oggtheora/oggstate.cpp | 2 +- engines/sword25/fmv/oggtheora/oggstate.h | 6 ++--- engines/sword25/fmv/oggtheora/oggstreamstate.cpp | 2 +- engines/sword25/fmv/oggtheora/oggstreamstate.h | 6 ++--- engines/sword25/fmv/oggtheora/oggtheora.cpp | 17 ++++++------- engines/sword25/fmv/oggtheora/oggtheora.h | 32 ++++++++++++------------ engines/sword25/fmv/oggtheora/theorastate.cpp | 2 +- engines/sword25/fmv/oggtheora/theorastate.h | 8 +++--- engines/sword25/fmv/oggtheora/vorbisstate.cpp | 2 +- engines/sword25/fmv/oggtheora/vorbisstate.h | 8 +++--- engines/sword25/fmv/oggtheora/yuvtorgba.cpp | 4 +-- engines/sword25/fmv/oggtheora/yuvtorgba.h | 10 ++++---- 16 files changed, 62 insertions(+), 63 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.cpp b/engines/sword25/fmv/oggtheora/audiobuffer.cpp index 9161c18fa8..1ad9620134 100755 --- a/engines/sword25/fmv/oggtheora/audiobuffer.cpp +++ b/engines/sword25/fmv/oggtheora/audiobuffer.cpp @@ -21,7 +21,7 @@ // Includes // ----------------------------------------------------------------------------- -#include "audiobuffer.h" +#include "sword25/fmv/oggtheora/audiobuffer.h" #include #include diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.h b/engines/sword25/fmv/oggtheora/audiobuffer.h index c0c19811be..a040caf5ab 100755 --- a/engines/sword25/fmv/oggtheora/audiobuffer.h +++ b/engines/sword25/fmv/oggtheora/audiobuffer.h @@ -17,14 +17,14 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_AUDIOBUFFER_H -#define BS_AUDIOBUFFER_H +#ifndef SWORD25_AUDIOBUFFER_H +#define SWORD25_AUDIOBUFFER_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" +#include "sword25/kernel/common.h" // ----------------------------------------------------------------------------- // Klassendefinition diff --git a/engines/sword25/fmv/oggtheora/moviefile.cpp b/engines/sword25/fmv/oggtheora/moviefile.cpp index 92cbdad844..3b68a96c5c 100755 --- a/engines/sword25/fmv/oggtheora/moviefile.cpp +++ b/engines/sword25/fmv/oggtheora/moviefile.cpp @@ -27,10 +27,10 @@ // Includes // ----------------------------------------------------------------------------- -#include "kernel/kernel.h" -#include "package/packagemanager.h" -#include "oggstate.h" -#include "moviefile.h" +#include "sword25/kernel/kernel.h" +#include "sword25/package/packagemanager.h" +#include "sword25/fmv/oggtheora/oggstate.h" +#include "sword25/fmv/oggtheora/moviefile.h" // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/oggtheora/moviefile.h b/engines/sword25/fmv/oggtheora/moviefile.h index 17935789b7..35566a56ca 100755 --- a/engines/sword25/fmv/oggtheora/moviefile.h +++ b/engines/sword25/fmv/oggtheora/moviefile.h @@ -17,18 +17,18 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_MOVIEFILE_H -#define BS_MOVIEFILE_H +#ifndef SWORD25_MOVIEFILE_H +#define SWORD25_MOVIEFILE_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" +#include "sword25/kernel/common.h" -#include "kernel/memlog_off.h" +#include "sword25/kernel/memlog_off.h" #include -#include "kernel/memlog_on.h" +#include "sword25/kernel/memlog_on.h" // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/oggtheora/oggstate.cpp b/engines/sword25/fmv/oggtheora/oggstate.cpp index d8300693c9..d6da995d0c 100755 --- a/engines/sword25/fmv/oggtheora/oggstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstate.cpp @@ -21,7 +21,7 @@ // Includes // ----------------------------------------------------------------------------- -#include "oggstate.h" +#include "sword25/fmv/oggtheora/oggstate.h" // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/oggtheora/oggstate.h b/engines/sword25/fmv/oggtheora/oggstate.h index 18b44e375f..2196e41b7c 100755 --- a/engines/sword25/fmv/oggtheora/oggstate.h +++ b/engines/sword25/fmv/oggtheora/oggstate.h @@ -17,14 +17,14 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_OGGSTATE_H -#define BS_OGGSTATE_H +#ifndef SWORD25_OGGSTATE_H +#define SWORD25_OGGSTATE_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" +#include "sword25/kernel/common.h" #include "ogg/ogg.h" // XXX #include diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp index da4dc317b5..05629be82b 100755 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp @@ -21,7 +21,7 @@ // Includes // ----------------------------------------------------------------------------- -#include "oggstreamstate.h" +#include "sword25/fmv/oggtheora/oggstreamstate.h" // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.h b/engines/sword25/fmv/oggtheora/oggstreamstate.h index 9460c7286f..7b296b82aa 100755 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.h +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.h @@ -17,14 +17,14 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_OGGSTREAMSTATE_H -#define BS_OGGSTREAMSTATE_H +#ifndef SWORD25_OGGSTREAMSTATE_H +#define SWORD25_OGGSTREAMSTATE_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" +#include "sword25/kernel/common.h" #include "ogg/ogg.h" #include // XXX diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp index c5436dcc8f..dcff5e025b 100755 --- a/engines/sword25/fmv/oggtheora/oggtheora.cpp +++ b/engines/sword25/fmv/oggtheora/oggtheora.cpp @@ -59,18 +59,17 @@ // Includes // ----------------------------------------------------------------------------- -#include "kernel/memlog_off.h" +#include "sword25/kernel/memlog_off.h" #include -#include "kernel/memlog_on.h" +#include "sword25/kernel/memlog_on.h" #include -#include "package/packagemanager.h" -#include "kernel/cpuinfo.h" -#include "sfx/soundengine.h" -#include "gfx/graphicengine.h" -#include "gfx/panel.h" -#include "oggtheora.h" -#include "yuvtorgba.h" +#include "sword25/package/packagemanager.h" +#include "sword25/sfx/soundengine.h" +#include "sword25/gfx/graphicengine.h" +#include "sword25/gfx/panel.h" +#include "sword25/fmv/oggtheora/oggtheora.h" +#include "sword25/fmv/oggtheora/yuvtorgba.h" using namespace std; diff --git a/engines/sword25/fmv/oggtheora/oggtheora.h b/engines/sword25/fmv/oggtheora/oggtheora.h index 0b43ba698d..516f5cc072 100755 --- a/engines/sword25/fmv/oggtheora/oggtheora.h +++ b/engines/sword25/fmv/oggtheora/oggtheora.h @@ -17,30 +17,30 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_OGGTHEORA_H -#define BS_OGGTHEORA_H +#ifndef SWORD25_OGGTHEORA_H +#define SWORD25_OGGTHEORA_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/memlog_off.h" +#include "sword25/kernel/memlog_off.h" #include #include #include -#include "kernel/memlog_on.h" - -#include "kernel/common.h" -#include "kernel/bs_stdint.h" -#include "gfx/bitmap.h" -#include "gfx/renderobjectptr.h" -#include "fmv/movieplayer.h" -#include "vorbisstate.h" -#include "theorastate.h" -#include "oggstate.h" -#include "oggstreamstate.h" -#include "moviefile.h" -#include "audiobuffer.h" +#include "sword25/kernel/memlog_on.h" + +#include "sword25/kernel/common.h" +#include "sword25/kernel/bs_stdint.h" +#include "sword25/gfx/bitmap.h" +#include "sword25/gfx/renderobjectptr.h" +#include "sword25/fmv/movieplayer.h" +#include "sword25/fmv/oggtheora/vorbisstate.h" +#include "sword25/fmv/oggtheora/theorastate.h" +#include "sword25/fmv/oggtheora/oggstate.h" +#include "sword25/fmv/oggtheora/oggstreamstate.h" +#include "sword25/fmv/oggtheora/moviefile.h" +#include "sword25/fmv/oggtheora/audiobuffer.h" // ----------------------------------------------------------------------------- // Klassendefinition diff --git a/engines/sword25/fmv/oggtheora/theorastate.cpp b/engines/sword25/fmv/oggtheora/theorastate.cpp index 853ef911ba..3d3c4018e4 100755 --- a/engines/sword25/fmv/oggtheora/theorastate.cpp +++ b/engines/sword25/fmv/oggtheora/theorastate.cpp @@ -21,7 +21,7 @@ // Includes // ----------------------------------------------------------------------------- -#include "theorastate.h" +#include "sword25/fmv/oggtheora/theorastate.h" // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/oggtheora/theorastate.h b/engines/sword25/fmv/oggtheora/theorastate.h index 582215bad9..3a88b6fdab 100755 --- a/engines/sword25/fmv/oggtheora/theorastate.h +++ b/engines/sword25/fmv/oggtheora/theorastate.h @@ -17,15 +17,15 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_THEORASTATE_H -#define BS_THEORASTATE_H +#ifndef SWORD25_THEORASTATE_H +#define SWORD25_THEORASTATE_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" -#include "theora/theora.h" +#include "sword25/kernel/common.h" +#include // ----------------------------------------------------------------------------- // Klassendefinition diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.cpp b/engines/sword25/fmv/oggtheora/vorbisstate.cpp index 683b6fd0d7..a2df701ba2 100755 --- a/engines/sword25/fmv/oggtheora/vorbisstate.cpp +++ b/engines/sword25/fmv/oggtheora/vorbisstate.cpp @@ -21,7 +21,7 @@ // Includes // ----------------------------------------------------------------------------- -#include "vorbisstate.h" +#include "sword25/fmv/oggtheora/vorbisstate.h" // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.h b/engines/sword25/fmv/oggtheora/vorbisstate.h index 193e115637..87e027e175 100755 --- a/engines/sword25/fmv/oggtheora/vorbisstate.h +++ b/engines/sword25/fmv/oggtheora/vorbisstate.h @@ -17,15 +17,15 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_VORBISSTATE_H -#define BS_VORBISSTATE_H +#ifndef SWORD25_VORBISSTATE_H +#define SWORD25_VORBISSTATE_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/common.h" -#include "vorbis/codec.h" +#include "sword25/kernel/common.h" +#include // ----------------------------------------------------------------------------- // Klassendefinition diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp index 0e709b12e0..9fc2c0ae58 100755 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp @@ -21,8 +21,8 @@ // Includes // ----------------------------------------------------------------------------- -#include "kernel/cpuinfo.h" -#include "yuvtorgba.h" +#include "sword25/kernel/cpuinfo.h" +#include "sword25/fmv/ogghteora/yuvtorgba.h" #include diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.h b/engines/sword25/fmv/oggtheora/yuvtorgba.h index 0bd74e5a18..116e854494 100755 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.h +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.h @@ -17,18 +17,18 @@ // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA // ----------------------------------------------------------------------------- -#ifndef BS_YUVTORGBA_H -#define BS_YUVTORGBA_H +#ifndef SWORD25_YUVTORGBA_H +#define SWORD25_YUVTORGBA_H // ----------------------------------------------------------------------------- // Includes // ----------------------------------------------------------------------------- -#include "kernel/memlog_off.h" +#include "sword25/kernel/memlog_off.h" #include -#include "kernel/memlog_on.h" +#include "sword25/kernel/memlog_on.h" -#include "kernel/common.h" +#include "sword25/kernel/common.h" #include "theora/theora.h" // ----------------------------------------------------------------------------- -- cgit v1.2.3 From 69b618a8f5517c609a5e94d9609dc27aea2ad573 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 30 Jul 2010 12:19:13 +0000 Subject: SWORD25: Compilation fixes Majority of files now compile under Windoze. svn-id: r53182 --- engines/sword25/fmv/oggtheora/oggtheora.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp index dcff5e025b..9ad2712128 100755 --- a/engines/sword25/fmv/oggtheora/oggtheora.cpp +++ b/engines/sword25/fmv/oggtheora/oggtheora.cpp @@ -92,7 +92,7 @@ namespace { return ((x > high) ? high : (( x < low) ? low : x)); } -}; +} // ----------------------------------------------------------------------------- // Konstruktion / Destruktion @@ -313,7 +313,7 @@ bool BS_OggTheora::LoadMovie(const std::string & Filename, unsigned int Z) float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); float ScaleFactor = std::min(ScreenToVideoWidth, ScreenToVideoHeight); - if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; + if (ABS(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; m_OutputBitmap->SetScaleFactor(ScaleFactor); // Z-Wert setzen -- cgit v1.2.3 From e78b19a650e27fe9a24d0e4c9c938294c7b08650 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sat, 31 Jul 2010 06:23:38 +0000 Subject: SWORD25: Converted kernel/kernel.cpp to compile under ScummVM This commit creates a skeleton detection and engine class, as well as code necessary to call the kernel initiation. The kernel/kernel.cpp has been converted to compile under ScummVM, along with all dependant header files. svn-id: r53184 --- engines/sword25/fmv/movieplayer.h | 154 +++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 77 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index c08969a5a2..5255e0b8e5 100755 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -1,21 +1,27 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ #ifndef SWORD25_MOVIEPLAYER_H #define SWORD25_MOVIEPLAYER_H @@ -27,112 +33,106 @@ #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" +namespace Sword25 { // ----------------------------------------------------------------------------- -// Klassendefinition +// Class definitions // ----------------------------------------------------------------------------- -class BS_MoviePlayer : public BS_Service -{ +class BS_MoviePlayer : public BS_Service { public: // ----------------------------------------------------------------------------- - // Konstruktion / Destruktion + // Constructor / Destructor // ----------------------------------------------------------------------------- - BS_MoviePlayer(BS_Kernel * pKernel); + BS_MoviePlayer(BS_Kernel *pKernel); virtual ~BS_MoviePlayer() {}; // ----------------------------------------------------------------------------- - // Abstraktes Interface, muss von jedem MoviePlayer implementiert werden + // Abstract interface must be implemented by each Movie Player // ----------------------------------------------------------------------------- /** - @brief Lädt eine Filmdatei - - Diese Methode lädt eine Filmdatei und bereitet sie zur Wiedergabe vor. - Es kann immer nur eine Filmdatei zur Zeit geladen sein. Falls bereits eine Filmdatei geladen - ist, wird diese entladen und nötigenfalls die Wiedergabe gestoppt. - - @param Filename der Dateiname der zu ladenden Filmdatei - @param Z gibt die Z Position des Films auf dem Graphik-Hauptlayer an - @return Gibt false zurück, wenn beim Laden ein Fehler aufgetreten ist, ansonsten true. + * Loads a movie file + * + * This method loads a movie file and prepares it for playback. + * There can be oly one movie file loaded at a time. If you already have loaded a + * movie file, it will be unloaded and, if necessary, stopped playing. + * @param Filename The filename of the movie file to be loaded + * @param Z Z indicates the position of the film on the main graphics layer + * @return Returns false if an error occured while loading, otherwise true. */ virtual bool LoadMovie(const std::string & Filename, unsigned int Z) = 0; /** - @brief Entlädt die gerade geladene Filmdatei - - @return Gibt false zurück, wenn beim Entladen ein Fehler aufgetreten ist, ansonsten true. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. - */ + * Unloads the currently loaded movie file. + * @return Returns false if an error occurred while unloading, otherwise true. + * @remark This method can only be called when IsMovieLoaded() returns true. + */ virtual bool UnloadMovie() = 0; /** - @brief Spielt den Film ab. - - Der Film wird unter Beibehaltung der Seitenverhältnisse auf Bildschirmgröße skaliert.
- Falls der Film mit einem Aufruf von Pause() pausiert wurde, fährt der Film an dieser Stelle fort. - - @return Gibt false zurück, wenn ein Fehler aufgetreten ist, ansonsten true. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. - */ + * Plays the loaded movie. + * + * The film will be keeping the aspect ratio of the screen. + * If the film was previously paused with Pause(), then the film will resume playing. + * @return Returns false if an error occurred while starting, otherwise true. + * @remark This method can only be called when IsMovieLoaded() returns true. + */ virtual bool Play() = 0; /** - @brief Pausiert die Filmwiedergabe. - - Bei einem späteren Aufruf von Play() fährt die Wiedergabe an der Stelle fort an der der Film Pausiert wurde. - - @return Gibt false zurück, wenn ein Fehler aufgetreten ist, ansonsten true. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. - */ + * Pauses movie playback. + * + * A paused movie can later be resumed by calling the Play() method again. + * @return Returns false if an error occurred while pausing, otherwise true. + * @remark This method can only be called when IsMovieLoaded() returns true. + */ virtual bool Pause() = 0; /** - @brief Diese Funktion muss ein mal pro Frame aufgerufen werden. - */ + * This function must be called once per frame. + */ virtual void Update() = 0; /** - @brief Gibt zurück, ob ein Film zur Wiedergabe geladen wurde. - */ + * Returns whether a film is loaded for playback. + */ virtual bool IsMovieLoaded() = 0; /** - @brief Gibt zurück, ob die Filmwiedergabe pausiert wurde. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. + * Returns whether the movie playback is paused. + * @remark This method can only be called when IsMovieLoaded() returns true. */ virtual bool IsPaused() = 0; /** - @brief Gibt den Faktor zurück um den der geladene Film skaliert wird. - - Beim Laden wird der Skalierungsfaktor automatisch so gewählt, dass der Film die maximal mögliche Bildschirmfläche einnimmt, ohne dass der - Film verzerrt wird. - - @return Gibt den Skalierungsfaktor des Filmes zurück. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. - */ + * Returns the scaling factor for the loaded film. + * + * When a movie is loaded, the scaling factor is automatically selected so that the film + * takes the maximum screen space, without the film being distorted. + * @return Returns the scaling factor of the film. + * @remark This method can only be called when IsMovieLoaded() returns true. + */ virtual float GetScaleFactor() = 0; /** - @brief Legt den Faktor fest um den der geladene Film skaliert werden soll. - @param ScaleFactor der gewünschte Skalierungsfaktor. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. - */ + * Sets the factor by which the loaded film is to be scaled. + * @param ScaleFactor The desired scale factor. + * @remark This method can only be called when IsMovieLoaded() returns true. + */ virtual void SetScaleFactor(float ScaleFactor) = 0; /** - @brief Gibt die aktuelle Abspielposition in Sekunden zurück. - @remark Diese Methode darf nur aufgerufen werden, wenn IsMovieLoaded() true zurückgibt. - */ + * Returns the current playing position in seconds. + * @remark This method can only be called when IsMovieLoaded() returns true. + */ virtual double GetTime() = 0; private: bool _RegisterScriptBindings(); }; +} // End of namespace Sword25 + #endif -- cgit v1.2.3 From 293bf95c01f76c8d812a300eb038854f1246ab3d Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 31 Jul 2010 09:53:02 +0000 Subject: SWORD25: Replacing headers with ScummVM ones plus original (C) svn-id: r53188 --- engines/sword25/fmv/movieplayer.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/movieplayer.h | 9 +++++ engines/sword25/fmv/movieplayer_script.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/audiobuffer.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/audiobuffer.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/moviefile.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/moviefile.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/oggstate.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/oggstate.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/oggstreamstate.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/oggstreamstate.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/oggtheora.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/oggtheora.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/theorastate.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/theorastate.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/vorbisstate.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/vorbisstate.h | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/yuvtorgba.cpp | 51 +++++++++++++++--------- engines/sword25/fmv/oggtheora/yuvtorgba.h | 51 +++++++++++++++--------- 19 files changed, 603 insertions(+), 324 deletions(-) mode change 100755 => 100644 engines/sword25/fmv/movieplayer.cpp mode change 100755 => 100644 engines/sword25/fmv/movieplayer.h mode change 100755 => 100644 engines/sword25/fmv/movieplayer_script.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/audiobuffer.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/audiobuffer.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/moviefile.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/moviefile.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/oggstate.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/oggstate.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/oggstreamstate.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/oggstreamstate.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/oggtheora.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/oggtheora.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/theorastate.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/theorastate.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/vorbisstate.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/vorbisstate.h mode change 100755 => 100644 engines/sword25/fmv/oggtheora/yuvtorgba.cpp mode change 100755 => 100644 engines/sword25/fmv/oggtheora/yuvtorgba.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp old mode 100755 new mode 100644 index a9aacc48fc..20a780f201 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h old mode 100755 new mode 100644 index 5255e0b8e5..365ec99af5 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -23,6 +23,15 @@ * */ +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ + #ifndef SWORD25_MOVIEPLAYER_H #define SWORD25_MOVIEPLAYER_H diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp old mode 100755 new mode 100644 index 43ec6506b4..b04cff35f7 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.cpp b/engines/sword25/fmv/oggtheora/audiobuffer.cpp old mode 100755 new mode 100644 index 1ad9620134..f9e6667ce5 --- a/engines/sword25/fmv/oggtheora/audiobuffer.cpp +++ b/engines/sword25/fmv/oggtheora/audiobuffer.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.h b/engines/sword25/fmv/oggtheora/audiobuffer.h old mode 100755 new mode 100644 index a040caf5ab..0b4233bc4e --- a/engines/sword25/fmv/oggtheora/audiobuffer.h +++ b/engines/sword25/fmv/oggtheora/audiobuffer.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_AUDIOBUFFER_H #define SWORD25_AUDIOBUFFER_H diff --git a/engines/sword25/fmv/oggtheora/moviefile.cpp b/engines/sword25/fmv/oggtheora/moviefile.cpp old mode 100755 new mode 100644 index 3b68a96c5c..b764ab2d22 --- a/engines/sword25/fmv/oggtheora/moviefile.cpp +++ b/engines/sword25/fmv/oggtheora/moviefile.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Logging diff --git a/engines/sword25/fmv/oggtheora/moviefile.h b/engines/sword25/fmv/oggtheora/moviefile.h old mode 100755 new mode 100644 index 35566a56ca..5aa0ef5617 --- a/engines/sword25/fmv/oggtheora/moviefile.h +++ b/engines/sword25/fmv/oggtheora/moviefile.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_MOVIEFILE_H #define SWORD25_MOVIEFILE_H diff --git a/engines/sword25/fmv/oggtheora/oggstate.cpp b/engines/sword25/fmv/oggtheora/oggstate.cpp old mode 100755 new mode 100644 index d6da995d0c..11788ce53b --- a/engines/sword25/fmv/oggtheora/oggstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstate.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/oggstate.h b/engines/sword25/fmv/oggtheora/oggstate.h old mode 100755 new mode 100644 index 2196e41b7c..1c25ca5e3a --- a/engines/sword25/fmv/oggtheora/oggstate.h +++ b/engines/sword25/fmv/oggtheora/oggstate.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_OGGSTATE_H #define SWORD25_OGGSTATE_H diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp old mode 100755 new mode 100644 index 05629be82b..d787a96af2 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.h b/engines/sword25/fmv/oggtheora/oggstreamstate.h old mode 100755 new mode 100644 index 7b296b82aa..7e291bd107 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.h +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_OGGSTREAMSTATE_H #define SWORD25_OGGSTREAMSTATE_H diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp old mode 100755 new mode 100644 index 9ad2712128..9d6eaa0baf --- a/engines/sword25/fmv/oggtheora/oggtheora.cpp +++ b/engines/sword25/fmv/oggtheora/oggtheora.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // The code in this file is based in part on code from the OggTheora Software // codec source released under the following terms: diff --git a/engines/sword25/fmv/oggtheora/oggtheora.h b/engines/sword25/fmv/oggtheora/oggtheora.h old mode 100755 new mode 100644 index 516f5cc072..62fa607935 --- a/engines/sword25/fmv/oggtheora/oggtheora.h +++ b/engines/sword25/fmv/oggtheora/oggtheora.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_OGGTHEORA_H #define SWORD25_OGGTHEORA_H diff --git a/engines/sword25/fmv/oggtheora/theorastate.cpp b/engines/sword25/fmv/oggtheora/theorastate.cpp old mode 100755 new mode 100644 index 3d3c4018e4..a270bab80c --- a/engines/sword25/fmv/oggtheora/theorastate.cpp +++ b/engines/sword25/fmv/oggtheora/theorastate.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/theorastate.h b/engines/sword25/fmv/oggtheora/theorastate.h old mode 100755 new mode 100644 index 3a88b6fdab..07934c26ea --- a/engines/sword25/fmv/oggtheora/theorastate.h +++ b/engines/sword25/fmv/oggtheora/theorastate.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_THEORASTATE_H #define SWORD25_THEORASTATE_H diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.cpp b/engines/sword25/fmv/oggtheora/vorbisstate.cpp old mode 100755 new mode 100644 index a2df701ba2..e9f6b7dc4f --- a/engines/sword25/fmv/oggtheora/vorbisstate.cpp +++ b/engines/sword25/fmv/oggtheora/vorbisstate.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.h b/engines/sword25/fmv/oggtheora/vorbisstate.h old mode 100755 new mode 100644 index 87e027e175..126e59d0aa --- a/engines/sword25/fmv/oggtheora/vorbisstate.h +++ b/engines/sword25/fmv/oggtheora/vorbisstate.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_VORBISSTATE_H #define SWORD25_VORBISSTATE_H diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp old mode 100755 new mode 100644 index 9fc2c0ae58..d835d2ba0b --- a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ // ----------------------------------------------------------------------------- // Includes diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.h b/engines/sword25/fmv/oggtheora/yuvtorgba.h old mode 100755 new mode 100644 index 116e854494..6593254ff9 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.h +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.h @@ -1,21 +1,36 @@ -// ----------------------------------------------------------------------------- -// This file is part of Broken Sword 2.5 -// Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdörfer -// -// Broken Sword 2.5 is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// Broken Sword 2.5 is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Broken Sword 2.5; if not, write to the Free Software -// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -// ----------------------------------------------------------------------------- +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ #ifndef SWORD25_YUVTORGBA_H #define SWORD25_YUVTORGBA_H -- cgit v1.2.3 From bed623b11ef007bb46b26f1f995b6073914383c5 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 31 Jul 2010 11:49:39 +0000 Subject: SWORD25: Fix compilation svn-id: r53193 --- engines/sword25/fmv/movieplayer.cpp | 13 +++++-------- engines/sword25/fmv/movieplayer.h | 2 +- engines/sword25/fmv/movieplayer_script.cpp | 31 ++++++++++++++---------------- 3 files changed, 20 insertions(+), 26 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 20a780f201..bfba6d1b7a 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -32,20 +32,17 @@ * */ -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "sword25/fmv/movieplayer.h" -#define BS_LOG_PREFIX "MOVIEPLAYER" +namespace Sword25 { -// ----------------------------------------------------------------------------- +#define BS_LOG_PREFIX "MOVIEPLAYER" -BS_MoviePlayer::BS_MoviePlayer(BS_Kernel * pKernel) : BS_Service(pKernel) -{ +BS_MoviePlayer::BS_MoviePlayer(BS_Kernel * pKernel) : BS_Service(pKernel) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 365ec99af5..9988b5e182 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -71,7 +71,7 @@ public: * @param Z Z indicates the position of the film on the main graphics layer * @return Returns false if an error occured while loading, otherwise true. */ - virtual bool LoadMovie(const std::string & Filename, unsigned int Z) = 0; + virtual bool LoadMovie(const Common::String &Filename, unsigned int Z) = 0; /** * Unloads the currently loaded movie file. diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index b04cff35f7..f95dc90b1d 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -43,9 +43,7 @@ #include "sword25/fmv/movieplayer.h" -namespace -{ - // ------------------------------------------------------------------------- +namespace Sword25 { int LoadMovie(lua_State * L) { @@ -171,21 +169,18 @@ namespace const luaL_reg LIBRARY_FUNCTIONS[] = { - "LoadMovie", LoadMovie, - "UnloadMovie", UnloadMovie, - "Play", Play, - "Pause", Pause, - "Update", Update, - "IsMovieLoaded", IsMovieLoaded, - "IsPaused", IsPaused, - "GetScaleFactor", GetScaleFactor, - "SetScaleFactor", SetScaleFactor, - "GetTime", GetTime, - 0, 0, + { "LoadMovie", LoadMovie }, + { "UnloadMovie", UnloadMovie }, + { "Play", Play }, + { "Pause", Pause }, + { "Update", Update }, + { "IsMovieLoaded", IsMovieLoaded }, + { "IsPaused", IsPaused }, + { "GetScaleFactor", GetScaleFactor }, + { "SetScaleFactor", SetScaleFactor }, + { "GetTime", GetTime }, + { 0, 0 } }; -} - -// ----------------------------------------------------------------------------- bool BS_MoviePlayer::_RegisterScriptBindings() { @@ -200,3 +195,5 @@ bool BS_MoviePlayer::_RegisterScriptBindings() return true; } + +} // End of namespace Sword25 -- cgit v1.2.3 From 9b3e26e7a29756848395d7a12928efdb60b8ff21 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 4 Aug 2010 14:53:07 +0000 Subject: SWORD25: Start for VideoDecoder-compatible Theora player. svn-id: r53206 --- engines/sword25/fmv/movieplayer.cpp | 43 ++- engines/sword25/fmv/movieplayer.h | 22 +- engines/sword25/fmv/movieplayer_script.cpp | 196 ++++++------- engines/sword25/fmv/theora_decoder.cpp | 434 +++++++++++++++++++++++++++++ engines/sword25/fmv/theora_decoder.h | 120 ++++++++ 5 files changed, 699 insertions(+), 116 deletions(-) create mode 100644 engines/sword25/fmv/theora_decoder.cpp create mode 100755 engines/sword25/fmv/theora_decoder.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index bfba6d1b7a..a031fc8283 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -38,11 +38,52 @@ namespace Sword25 { #define BS_LOG_PREFIX "MOVIEPLAYER" -BS_MoviePlayer::BS_MoviePlayer(BS_Kernel * pKernel) : BS_Service(pKernel) { +BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { return new BS_MoviePlayer(pKernel); } + +BS_MoviePlayer::BS_MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); } +bool BS_MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { + return true; +} + +bool BS_MoviePlayer::UnloadMovie() { + return true; +} + +bool BS_MoviePlayer::Play() { + return true; +} + +bool BS_MoviePlayer::Pause() { + return true; +} + +void BS_MoviePlayer::Update() { +} + +bool BS_MoviePlayer::IsMovieLoaded() { + return true; +} + +bool BS_MoviePlayer::IsPaused() { + return true; +} + +float BS_MoviePlayer::GetScaleFactor() { + return 1.0f; +} + +void BS_MoviePlayer::SetScaleFactor(float ScaleFactor) { +} + +double BS_MoviePlayer::GetTime() { + return 1.0; +} + + } // End of namespace Sword25 diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 9988b5e182..be841c51a9 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -55,7 +55,7 @@ public: // ----------------------------------------------------------------------------- BS_MoviePlayer(BS_Kernel *pKernel); - virtual ~BS_MoviePlayer() {}; + ~BS_MoviePlayer() {}; // ----------------------------------------------------------------------------- // Abstract interface must be implemented by each Movie Player @@ -71,14 +71,14 @@ public: * @param Z Z indicates the position of the film on the main graphics layer * @return Returns false if an error occured while loading, otherwise true. */ - virtual bool LoadMovie(const Common::String &Filename, unsigned int Z) = 0; + bool LoadMovie(const Common::String &Filename, unsigned int Z); /** * Unloads the currently loaded movie file. * @return Returns false if an error occurred while unloading, otherwise true. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual bool UnloadMovie() = 0; + bool UnloadMovie(); /** * Plays the loaded movie. @@ -88,7 +88,7 @@ public: * @return Returns false if an error occurred while starting, otherwise true. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual bool Play() = 0; + bool Play(); /** * Pauses movie playback. @@ -97,23 +97,23 @@ public: * @return Returns false if an error occurred while pausing, otherwise true. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual bool Pause() = 0; + bool Pause(); /** * This function must be called once per frame. */ - virtual void Update() = 0; + void Update(); /** * Returns whether a film is loaded for playback. */ - virtual bool IsMovieLoaded() = 0; + bool IsMovieLoaded(); /** * Returns whether the movie playback is paused. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual bool IsPaused() = 0; + bool IsPaused(); /** * Returns the scaling factor for the loaded film. @@ -123,20 +123,20 @@ public: * @return Returns the scaling factor of the film. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual float GetScaleFactor() = 0; + float GetScaleFactor(); /** * Sets the factor by which the loaded film is to be scaled. * @param ScaleFactor The desired scale factor. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual void SetScaleFactor(float ScaleFactor) = 0; + void SetScaleFactor(float ScaleFactor); /** * Returns the current playing position in seconds. * @remark This method can only be called when IsMovieLoaded() returns true. */ - virtual double GetTime() = 0; + double GetTime(); private: bool _RegisterScriptBindings(); diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index f95dc90b1d..523cc2d4f3 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -45,150 +45,138 @@ namespace Sword25 { - int LoadMovie(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); +int LoadMovie(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); + lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); - return 1; - } - - // ------------------------------------------------------------------------- - - int UnloadMovie(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); - - lua_pushbooleancpp(L, FMVPtr->UnloadMovie()); + return 1; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int UnloadMovie(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int Play(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + lua_pushbooleancpp(L, FMVPtr->UnloadMovie()); - lua_pushbooleancpp(L, FMVPtr->Play()); + return 1; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int Play(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int Pause(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + lua_pushbooleancpp(L, FMVPtr->Play()); - lua_pushbooleancpp(L, FMVPtr->Pause()); + return 1; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int Pause(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int Update(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + lua_pushbooleancpp(L, FMVPtr->Pause()); - FMVPtr->Update(); + return 1; +} - return 0; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int Update(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int IsMovieLoaded(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + FMVPtr->Update(); - lua_pushbooleancpp(L, FMVPtr->IsMovieLoaded()); + return 0; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int IsMovieLoaded(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int IsPaused(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + lua_pushbooleancpp(L, FMVPtr->IsMovieLoaded()); - lua_pushbooleancpp(L, FMVPtr->IsPaused()); + return 1; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int IsPaused(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int GetScaleFactor(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + lua_pushbooleancpp(L, FMVPtr->IsPaused()); - lua_pushnumber(L, FMVPtr->GetScaleFactor()); + return 1; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int GetScaleFactor(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int SetScaleFactor(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + lua_pushnumber(L, FMVPtr->GetScaleFactor()); - FMVPtr->SetScaleFactor(static_cast(luaL_checknumber(L, 1))); + return 1; +} - return 0; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int SetScaleFactor(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - int GetTime(lua_State * L) - { - BS_MoviePlayer * FMVPtr = BS_Kernel::GetInstance()->GetFMV(); - BS_ASSERT(FMVPtr); + FMVPtr->SetScaleFactor(static_cast(luaL_checknumber(L, 1))); - lua_pushnumber(L, FMVPtr->GetTime()); + return 0; +} - return 1; - } +// ------------------------------------------------------------------------- - // ------------------------------------------------------------------------- +int GetTime(lua_State *L) { + BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + BS_ASSERT(FMVPtr); - const char * LIBRARY_NAME = "Movieplayer"; + lua_pushnumber(L, FMVPtr->GetTime()); - const luaL_reg LIBRARY_FUNCTIONS[] = - { - { "LoadMovie", LoadMovie }, - { "UnloadMovie", UnloadMovie }, - { "Play", Play }, - { "Pause", Pause }, - { "Update", Update }, - { "IsMovieLoaded", IsMovieLoaded }, - { "IsPaused", IsPaused }, - { "GetScaleFactor", GetScaleFactor }, - { "SetScaleFactor", SetScaleFactor }, - { "GetTime", GetTime }, - { 0, 0 } - }; + return 1; +} -bool BS_MoviePlayer::_RegisterScriptBindings() -{ - BS_Kernel * pKernel = BS_Kernel::GetInstance(); +// ------------------------------------------------------------------------- + +const char *LIBRARY_NAME = "Movieplayer"; + +const luaL_reg LIBRARY_FUNCTIONS[] = { + { "LoadMovie", LoadMovie }, + { "UnloadMovie", UnloadMovie }, + { "Play", Play }, + { "Pause", Pause }, + { "Update", Update }, + { "IsMovieLoaded", IsMovieLoaded }, + { "IsPaused", IsPaused }, + { "GetScaleFactor", GetScaleFactor }, + { "SetScaleFactor", SetScaleFactor }, + { "GetTime", GetTime }, + { 0, 0 } +}; + +bool BS_MoviePlayer::_RegisterScriptBindings() { + BS_Kernel *pKernel = BS_Kernel::GetInstance(); BS_ASSERT(pKernel); - BS_ScriptEngine * pScript = static_cast(pKernel->GetService("script")); + BS_ScriptEngine *pScript = static_cast(pKernel->GetService("script")); BS_ASSERT(pScript); - lua_State * L = static_cast(pScript->GetScriptObject()); + lua_State *L = static_cast(pScript->GetScriptObject()); BS_ASSERT(L); if (!BS_LuaBindhelper::AddFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false; diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp new file mode 100644 index 0000000000..0a4de4e649 --- /dev/null +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -0,0 +1,434 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * Source is based on the player example from libvorbis package + * + * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. + * + * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 + * by the Xiph.Org Foundation and contributors http://www.xiph.org/ + * + */ + +#include "sword25/fmv/theora_decoder.h" +#include "common/system.h" + +namespace Sword25 { + +TheoraDecoder::TheoraDecoder() { + _fileStream = 0; + _surface = 0; + + _theoraPacket = 0; + _vorbisPacket = 0; + _stateFlag = 0; +} + +TheoraDecoder::~TheoraDecoder() { + close(); +} + +void TheoraDecoder::queuePage(ogg_page *page) { + if (_theoraPacket) + ogg_stream_pagein(&_theoraOut, page); + + if (_vorbisPacket) + ogg_stream_pagein(&_vorbisOut, page); +} + +int TheoraDecoder::bufferData() { + char *buffer = ogg_sync_buffer(&_oggSync, 4096); + int bytes = _fileStream->read(buffer, 4096); + + ogg_sync_wrote(&_oggSync, bytes); + + return(bytes); +} + +bool TheoraDecoder::load(Common::SeekableReadStream &stream) { + close(); + + _fileStream = &stream; + + // start up Ogg stream synchronization layer + ogg_sync_init(&_oggSync); + + // init supporting Vorbis structures needed in header parsing + vorbis_info_init(&_vorbisInfo); + vorbis_comment_init(&_vorbisComment); + + // init supporting Theora structures needed in header parsing + th_comment_init(&_theoraComment); + th_info_init(&_theoraInfo); + + // Ogg file open; parse the headers + // Only interested in Vorbis/Theora streams + while (!_stateFlag) { + int ret = bufferData(); + + if (ret == 0) + break; + + while (ogg_sync_pageout(&_oggSync, &_oggPage) > 0) { + ogg_stream_state test; + + // is this a mandated initial header? If not, stop parsing + if (!ogg_page_bos(&_oggPage)) { + // don't leak the page; get it into the appropriate stream + queuePage(&_oggPage); + _stateFlag = 1; + break; + } + + ogg_stream_init(&test, ogg_page_serialno(&_oggPage)); + ogg_stream_pagein(&test, &_oggPage); + ogg_stream_packetout(&test, &_oggPacket); + + // identify the codec: try theora + if (!_theoraPacket && th_decode_headerin(&_theoraInfo, &_theoraComment, &_theoraSetup, &_oggPacket) >= 0) { + // it is theora + memcpy(&_theoraOut, &test, sizeof(test)); + _theoraPacket = 1; + } else if (!_vorbisPacket && vorbis_synthesis_headerin(&_vorbisInfo, &_vorbisComment, &_oggPacket) >= 0) { + // it is vorbis + memcpy(&_vorbisOut, &test, sizeof(test)); + _vorbisPacket = 1; + } else { + // whatever it is, we don't care about it + ogg_stream_clear(&test); + } + } + // fall through to non-bos page parsing + } + + // we're expecting more header packets. + while ((_theoraPacket && _theoraPacket < 3) || (_vorbisPacket && _vorbisPacket < 3)) { + int ret; + + // look for further theora headers + while (_theoraPacket && (_theoraPacket < 3) && (ret = ogg_stream_packetout(&_theoraOut, &_oggPacket))) { + if (ret < 0) + error("Error parsing Theora stream headers; corrupt stream?"); + + if (!th_decode_headerin(&_theoraInfo, &_theoraComment, &_theoraSetup, &_oggPacket)) + error("Error parsing Theora stream headers; corrupt stream?"); + + _theoraPacket++; + } + + // look for more vorbis header packets + while (_vorbisPacket && (_vorbisPacket < 3) && (ret = ogg_stream_packetout(&_vorbisOut, &_oggPacket))) { + if (ret < 0) + error("Error parsing Vorbis stream headers; corrupt stream?"); + + if (vorbis_synthesis_headerin(&_vorbisInfo, &_vorbisComment, &_oggPacket)) + error("Error parsing Vorbis stream headers; corrupt stream?"); + + _vorbisPacket++; + + if (_vorbisPacket == 3) + break; + } + + // The header pages/packets will arrive before anything else we + // care about, or the stream is not obeying spec + + if (ogg_sync_pageout(&_oggSync, &_oggPage) > 0) { + queuePage(&_oggPage); // demux into the appropriate stream + } else { + ret = bufferData(); // someone needs more data + + if (ret == 0) + error("End of file while searching for codec headers."); + } + } + + // and now we have it all. initialize decoders + if (_theoraPacket) { + _theoraDecode = th_decode_alloc(&_theoraInfo, _theoraSetup); + debugN(1, "Ogg logical stream %lx is Theora %dx%d %.02f fps", + _theoraOut.serialno, _theoraInfo.pic_width, _theoraInfo.pic_height, + (double)_theoraInfo.fps_numerator / _theoraInfo.fps_denominator); + switch (_theoraInfo.pixel_fmt) { + case TH_PF_420: + debug(1, " 4:2:0 video"); + break; + case TH_PF_422: + debug(1, " 4:2:2 video"); + break; + case TH_PF_444: + debug(1, " 4:4:4 video"); + break; + case TH_PF_RSVD: + default: + debug(1, " video\n (UNKNOWN Chroma sampling!)"); + break; + } + + if (_theoraInfo.pic_width != _theoraInfo.frame_width || _theoraInfo.pic_height != _theoraInfo.frame_height) + debug(1, " Frame content is %dx%d with offset (%d,%d).", + _theoraInfo.frame_width, _theoraInfo.frame_height, _theoraInfo.pic_x, _theoraInfo.pic_y); + + th_decode_ctl(_theoraDecode, TH_DECCTL_GET_PPLEVEL_MAX, &_ppLevelMax, sizeof(_ppLevelMax)); + _ppLevel = _ppLevelMax; + th_decode_ctl(_theoraDecode, TH_DECCTL_SET_PPLEVEL, &_ppLevel, sizeof(_ppLevel)); + _ppInc = 0; + + } else { + // tear down the partial theora setup + th_info_clear(&_theoraInfo); + th_comment_clear(&_theoraComment); + } + + th_setup_free(_theoraSetup); + + if (_vorbisPacket) { + vorbis_synthesis_init(&_vorbisDSP, &_vorbisInfo); + vorbis_block_init(&_vorbisDSP, &_vorbisBlock); + debug(3, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.", + _vorbisOut.serialno, _vorbisInfo.channels, _vorbisInfo.rate); + } else { + // tear down the partial vorbis setup + vorbis_info_clear(&_vorbisInfo); + vorbis_comment_clear(&_vorbisComment); + } + + // open audio + if (_vorbisPacket) + open_audio(); + + return true; +} + +void TheoraDecoder::close() { + if (_vorbisPacket) { + ogg_stream_clear(&_vorbisOut); + vorbis_block_clear(&_vorbisBlock); + vorbis_dsp_clear(&_vorbisDSP); + vorbis_comment_clear(&_vorbisComment); + vorbis_info_clear(&_vorbisInfo); + } + if (_theoraPacket) { + ogg_stream_clear(&_theoraOut); + th_decode_free(_theoraDecode); + th_comment_clear(&_theoraComment); + th_info_clear(&_theoraInfo); + } + ogg_sync_clear(&_oggSync); + + if (!_fileStream) + return; + + delete _fileStream; + _fileStream = 0; + + _surface->free(); + delete _surface; + _surface = 0; + + reset(); +} + +Graphics::Surface *TheoraDecoder::decodeNextFrame() { + int i, j; + + _stateFlag = 0; // playback has not begun + + // we want a video and audio frame ready to go at all times. If + // we have to buffer incoming, buffer the compressed data (ie, let + // ogg do the buffering) + while (_vorbisPacket && !_audiobufReady) { + int ret; + float **pcm; + + // if there's pending, decoded audio, grab it + if ((ret = vorbis_synthesis_pcmout(&_vorbisDSP, &pcm)) > 0) { + int count = _audiobufFill / 2; + int maxsamples = (audiofd_fragsize - _audiobufFill) / 2 / _vorbisInfo.channels; + for (i = 0; i < ret && i < maxsamples; i++) + for (j = 0; j < _vorbisInfo.channels; j++) { + int val = CLIP(rint(pcm[j][i] * 32767.f), -32768, 32768); + _audiobuf[count++] = val; + } + + vorbis_synthesis_read(&_vorbisDSP, i); + _audiobufFill += i * _vorbisInfo.channels * 2; + + if (_audiobufFill == audiofd_fragsize) + _audiobufReady = 1; + + if (_vorbisDSP.granulepos >= 0) + _audiobufGranulePos = _vorbisDSP.granulepos - ret + i; + else + _audiobufGranulePos += i; + } else { + + // no pending audio; is there a pending packet to decode? + if (ogg_stream_packetout(&_vorbisOut, &_oggPacket) > 0) { + if (vorbis_synthesis(&_vorbisBlock, &_oggPacket) == 0) // test for success! + vorbis_synthesis_blockin(&_vorbisDSP, &_vorbisBlock); + } else // we need more data; break out to suck in another page + break; + } + } + + while (_theoraPacket && !_videobufReady) { + // theora is one in, one out... + if (ogg_stream_packetout(&_theoraOut, &_oggPacket) > 0) { + + if (_ppInc) { + _ppLevel += _ppInc; + th_decode_ctl(_theoraDecode, TH_DECCTL_SET_PPLEVEL, &_ppLevel, sizeof(_ppLevel)); + _ppInc = 0; + } + // HACK: This should be set after a seek or a gap, but we might not have + // a granulepos for the first packet (we only have them for the last + // packet on a page), so we just set it as often as we get it. + // To do this right, we should back-track from the last packet on the + // page and compute the correct granulepos for the first packet after + // a seek or a gap. + if (_oggPacket.granulepos >= 0) { + th_decode_ctl(_theoraDecode, TH_DECCTL_SET_GRANPOS, &_oggPacket.granulepos, sizeof(_oggPacket.granulepos)); + } + if (th_decode_packetin(_theoraDecode, &_oggPacket, &_videobufGranulePos) == 0) { + _videobufTime = th_granule_time(_theoraDecode, _videobufGranulePos); + _curFrame++; + + // is it already too old to be useful? This is only actually + // useful cosmetically after a SIGSTOP. Note that we have to + // decode the frame even if we don't show it (for now) due to + // keyframing. Soon enough libtheora will be able to deal + // with non-keyframe seeks. + + if (_videobufTime >= get_time()) + _videobufReady = 1; + else { + // If we are too slow, reduce the pp level. + _ppInc = _ppLevel > 0 ? -1 : 0; + dropped++; + } + } + } else + break; + } + + if (!_videobufReady && !_audiobufReady && _fileStream->eos()) + break; + + if (!_videobufReady || !_audiobufReady) { + // no data yet for somebody. Grab another page + bufferData(); + while (ogg_sync_pageout(&_oggSync, &_oggPage) > 0) { + queuePage(&_oggPage); + } + } + + // If playback has begun, top audio buffer off immediately. + if (_stateFlag) audio_write_nonblocking(); + + // are we at or past time for this video frame? + if (_stateFlag && _videobufReady && _videobufTime <= get_time()) { + video_write(); + _videobufReady = 0; + } + + if (_stateFlag && + (_audiobufReady || !_vorbisPacket) && + (_videobufReady || !_theoraPacket) && + !got_sigint) { + // we have an audio frame ready (which means the audio buffer is + // full), it's not time to play video, so wait until one of the + // audio buffer is ready or it's near time to play video + + // set up select wait on the audiobuffer and a timeout for video + struct timeval timeout; + fd_set writefs; + fd_set empty; + int n = 0; + + FD_ZERO(&writefs); + FD_ZERO(&empty); + if (audiofd >= 0) { + FD_SET(audiofd, &writefs); + n = audiofd + 1; + } + + if (_theoraPacket) { + double tdiff; + long milliseconds; + tdiff = _videobufTime - get_time(); + + // If we have lots of extra time, increase the post-processing level. + if (tdiff > _theoraInfo.fps_denominator * 0.25 / _theoraInfo.fps_numerator) { + _ppInc = _ppLevel < _ppLevelMax ? 1 : 0; + } else if (tdiff < _theoraInfo.fps_denominator * 0.05 / _theoraInfo.fps_numerator) { + _ppInc = _ppLevel > 0 ? -1 : 0; + } + milliseconds = tdiff * 1000 - 5; + if (milliseconds > 500) + milliseconds = 500; + if (milliseconds > 0) { + timeout.tv_sec = milliseconds / 1000; + timeout.tv_usec = (milliseconds % 1000) * 1000; + + n = select(n, &empty, &writefs, &empty, &timeout); + if (n) + audio_calibrate_timer(0); + } + } else { + select(n, &empty, &writefs, &empty, NULL); + } + } + + // if our buffers either don't exist or are ready to go, + // we can begin playback + if ((!_theoraPacket || _videobufReady) && + (!_vorbisPacket || _audiobufReady)) + _stateFlag = 1; + + // same if we've run out of input + if (_fileStream->eos()) + _stateFlag = 1; +} + +void TheoraDecoder::reset() { + VideoDecoder::reset(); + if (_fileStream) + _fileStream->seek(0); + + _videobufReady = 0; + _videobufGranulePos = -1; + _videobufTime = 0; + + _audiobufFill = 0; + _audiobufReady = 0; + _audiobufGranulePos = 0; +} + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h new file mode 100755 index 0000000000..cda1c8a6cb --- /dev/null +++ b/engines/sword25/fmv/theora_decoder.h @@ -0,0 +1,120 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef SWORD25_THEORADECODER_H +#define SWORD25_THEORADECODER_H + +#include "graphics/video/video_decoder.h" + +#include +#include + +namespace Common { + class SeekableReadStream; +} + +namespace Sword25 { + +/** + * + * Decoder for Theora videos. + * Video decoder used in engines: + * - sword25 + */ +class TheoraDecoder : public Graphics::FixedRateVideoDecoder { +public: + TheoraDecoder(); + virtual ~TheoraDecoder(); + + /** + * Load a video file + * @param stream the stream to load + */ + bool load(Common::SeekableReadStream &stream); + void close(); + + /** + * Decode the next frame and return the frame's surface + * @note the return surface should *not* be freed + * @note this may return 0, in which case the last frame should be kept on screen + */ + Graphics::Surface *decodeNextFrame(); + + bool isVideoLoaded() const { return _fileStream != 0; } + uint16 getWidth() const { return _surface->w; } + uint16 getHeight() const { return _surface->h; } + uint32 getFrameCount() const { return _frameCount; } + Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); } + +protected: + Common::Rational getFrameRate() const { return _frameRate; } + +private: + void queuePage(ogg_page *page); + int bufferData(); + +private: + Common::SeekableReadStream *_fileStream; + Graphics::Surface *_surface; + Common::Rational _frameRate; + uint32 _frameCount; + + ogg_sync_state _oggSync; + ogg_page _oggPage; + ogg_packet _oggPacket; + ogg_stream_state _vorbisOut; + ogg_stream_state _theoraOut; + th_info _theoraInfo; + th_comment _theoraComment; + th_dec_ctx *_theoraDecode; + th_setup_info *_theoraSetup; + vorbis_info _vorbisInfo; + vorbis_dsp_state _vorbisDSP; + vorbis_block _vorbisBlock; + vorbis_comment _vorbisComment; + + int _theoraPacket; + int _vorbisPacket; + int _stateFlag; + + int _ppLevelMax; + int _ppLevel; + int _ppInc; + + // single frame video buffering + int _videobufReady; + ogg_int64_t _videobufGranulePos; + double _videobufTime; + + // single audio fragment audio buffering + int _audiobufFill; + int _audiobufReady; + ogg_int16_t *_audiobuf; + ogg_int64_t _audiobufGranulePos; // time position of last sample +}; + +} // End of namespace Sword25 + +#endif -- cgit v1.2.3 From 1e3b3af5c09ef5b9168436b2276bce612f74c0d2 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 4 Aug 2010 21:13:43 +0000 Subject: SWORD25: Start of plugging audio to Theora decoder svn-id: r53207 --- engines/sword25/fmv/theora_decoder.cpp | 51 ++++++++++++++++++++++++---------- engines/sword25/fmv/theora_decoder.h | 18 +++++++++--- 2 files changed, 51 insertions(+), 18 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index 0a4de4e649..f0a4fd7eab 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -41,17 +41,22 @@ namespace Sword25 { -TheoraDecoder::TheoraDecoder() { +TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : _mixer(mixer) { _fileStream = 0; _surface = 0; _theoraPacket = 0; _vorbisPacket = 0; - _stateFlag = 0; + _stateFlag = false; + + _soundType = soundType; + _audStream = 0; + _audHandle = new Audio::SoundHandle(); } TheoraDecoder::~TheoraDecoder() { close(); + delete _audHandle; } void TheoraDecoder::queuePage(ogg_page *page) { @@ -102,7 +107,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { if (!ogg_page_bos(&_oggPage)) { // don't leak the page; get it into the appropriate stream queuePage(&_oggPage); - _stateFlag = 1; + _stateFlag = true; break; } @@ -220,8 +225,11 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { } // open audio - if (_vorbisPacket) - open_audio(); + if (_vorbisPacket) { + _audStream = createAudioStream(); + if (_audStream) + _mixer->playStream(_soundType, _audHandle, _audStream); + } return true; } @@ -233,6 +241,9 @@ void TheoraDecoder::close() { vorbis_dsp_clear(&_vorbisDSP); vorbis_comment_clear(&_vorbisComment); vorbis_info_clear(&_vorbisInfo); + + _mixer->stopHandle(*_audHandle); + _audStream = 0; } if (_theoraPacket) { ogg_stream_clear(&_theoraOut); @@ -258,7 +269,7 @@ void TheoraDecoder::close() { Graphics::Surface *TheoraDecoder::decodeNextFrame() { int i, j; - _stateFlag = 0; // playback has not begun + _stateFlag = false; // playback has not begun // we want a video and audio frame ready to go at all times. If // we have to buffer incoming, buffer the compressed data (ie, let @@ -281,7 +292,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { _audiobufFill += i * _vorbisInfo.channels * 2; if (_audiobufFill == audiofd_fragsize) - _audiobufReady = 1; + _audiobufReady = true; if (_vorbisDSP.granulepos >= 0) _audiobufGranulePos = _vorbisDSP.granulepos - ret + i; @@ -327,7 +338,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { // with non-keyframe seeks. if (_videobufTime >= get_time()) - _videobufReady = 1; + _videobufReady = true; else { // If we are too slow, reduce the pp level. _ppInc = _ppLevel > 0 ? -1 : 0; @@ -350,12 +361,13 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { } // If playback has begun, top audio buffer off immediately. - if (_stateFlag) audio_write_nonblocking(); + if (_stateFlag) + audio_write_nonblocking(); // are we at or past time for this video frame? if (_stateFlag && _videobufReady && _videobufTime <= get_time()) { video_write(); - _videobufReady = 0; + _videobufReady = false; } if (_stateFlag && @@ -410,11 +422,11 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { // we can begin playback if ((!_theoraPacket || _videobufReady) && (!_vorbisPacket || _audiobufReady)) - _stateFlag = 1; + _stateFlag = true; // same if we've run out of input if (_fileStream->eos()) - _stateFlag = 1; + _stateFlag = true; } void TheoraDecoder::reset() { @@ -422,13 +434,24 @@ void TheoraDecoder::reset() { if (_fileStream) _fileStream->seek(0); - _videobufReady = 0; + _videobufReady = false; _videobufGranulePos = -1; _videobufTime = 0; _audiobufFill = 0; - _audiobufReady = 0; + _audiobufReady = false; _audiobufGranulePos = 0; } +uint32 TheoraDecoder::getElapsedTime() const { + if (_audStream) + return _mixer->getSoundElapsedTime(*_audHandle); + + return VideoDecoder::getElapsedTime(); +} + +Audio::QueuingAudioStream *AviDecoder::createAudioStream() { + return Audio::makeQueuingAudioStream(_vorbisInfo.rate, _vorbisInfo.channels); +} + } // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index cda1c8a6cb..cd526b6ba0 100755 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -27,6 +27,8 @@ #define SWORD25_THEORADECODER_H #include "graphics/video/video_decoder.h" +#include "sound/audiostream.h" +#include "sound/mixer.h" #include #include @@ -45,7 +47,7 @@ namespace Sword25 { */ class TheoraDecoder : public Graphics::FixedRateVideoDecoder { public: - TheoraDecoder(); + TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType); virtual ~TheoraDecoder(); /** @@ -68,6 +70,8 @@ public: uint32 getFrameCount() const { return _frameCount; } Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); } + uint32 getElapsedTime() const; + protected: Common::Rational getFrameRate() const { return _frameRate; } @@ -81,6 +85,12 @@ private: Common::Rational _frameRate; uint32 _frameCount; + Audio::Mixer *_mixer; + Audio::Mixer::SoundType _soundType; + Audio::SoundHandle *_audHandle; + Audio::QueuingAudioStream *_audStream; + Audio::QueuingAudioStream *createAudioStream(); + ogg_sync_state _oggSync; ogg_page _oggPage; ogg_packet _oggPacket; @@ -97,20 +107,20 @@ private: int _theoraPacket; int _vorbisPacket; - int _stateFlag; + bool _stateFlag; int _ppLevelMax; int _ppLevel; int _ppInc; // single frame video buffering - int _videobufReady; + bool _videobufReady; ogg_int64_t _videobufGranulePos; double _videobufTime; // single audio fragment audio buffering int _audiobufFill; - int _audiobufReady; + bool _audiobufReady; ogg_int16_t *_audiobuf; ogg_int64_t _audiobufGranulePos; // time position of last sample }; -- cgit v1.2.3 From eb30ebde2a4e3181bc2ef2daccedfe852aa891e1 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 5 Aug 2010 12:16:21 +0000 Subject: SWORD25: Finish preliminary implementation of Theora decoder svn-id: r53213 --- engines/sword25/fmv/theora_decoder.cpp | 107 ++++++++++++--------------------- engines/sword25/fmv/theora_decoder.h | 3 +- 2 files changed, 40 insertions(+), 70 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index f0a4fd7eab..b6647559d2 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -37,10 +37,14 @@ */ #include "sword25/fmv/theora_decoder.h" + #include "common/system.h" +#include "sound/decoders/raw.h" namespace Sword25 { +#define AUDIOFD_FRAGSIZE 10240 + TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : _mixer(mixer) { _fileStream = 0; _surface = 0; @@ -180,6 +184,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { debugN(1, "Ogg logical stream %lx is Theora %dx%d %.02f fps", _theoraOut.serialno, _theoraInfo.pic_width, _theoraInfo.pic_height, (double)_theoraInfo.fps_numerator / _theoraInfo.fps_denominator); + switch (_theoraInfo.pixel_fmt) { case TH_PF_420: debug(1, " 4:2:0 video"); @@ -231,6 +236,10 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { _mixer->playStream(_soundType, _audHandle, _audStream); } + _surface = new Graphics::Surface(); + + _surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, 3); + return true; } @@ -281,17 +290,17 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { // if there's pending, decoded audio, grab it if ((ret = vorbis_synthesis_pcmout(&_vorbisDSP, &pcm)) > 0) { int count = _audiobufFill / 2; - int maxsamples = (audiofd_fragsize - _audiobufFill) / 2 / _vorbisInfo.channels; + int maxsamples = (AUDIOFD_FRAGSIZE - _audiobufFill) / 2 / _vorbisInfo.channels; for (i = 0; i < ret && i < maxsamples; i++) for (j = 0; j < _vorbisInfo.channels; j++) { - int val = CLIP(rint(pcm[j][i] * 32767.f), -32768, 32768); + int val = CLIP((int)rint(pcm[j][i] * 32767.f), -32768, 32768); _audiobuf[count++] = val; } vorbis_synthesis_read(&_vorbisDSP, i); _audiobufFill += i * _vorbisInfo.channels * 2; - if (_audiobufFill == audiofd_fragsize) + if (_audiobufFill == AUDIOFD_FRAGSIZE) _audiobufReady = true; if (_vorbisDSP.granulepos >= 0) @@ -331,26 +340,16 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { _videobufTime = th_granule_time(_theoraDecode, _videobufGranulePos); _curFrame++; - // is it already too old to be useful? This is only actually - // useful cosmetically after a SIGSTOP. Note that we have to - // decode the frame even if we don't show it (for now) due to - // keyframing. Soon enough libtheora will be able to deal - // with non-keyframe seeks. - - if (_videobufTime >= get_time()) - _videobufReady = true; - else { - // If we are too slow, reduce the pp level. - _ppInc = _ppLevel > 0 ? -1 : 0; - dropped++; - } + _videobufReady = true; } } else break; } - if (!_videobufReady && !_audiobufReady && _fileStream->eos()) - break; + if (!_videobufReady && !_audiobufReady && _fileStream->eos()) { + close(); + return _surface; + } if (!_videobufReady || !_audiobufReady) { // no data yet for somebody. Grab another page @@ -361,61 +360,29 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { } // If playback has begun, top audio buffer off immediately. - if (_stateFlag) - audio_write_nonblocking(); + if (_stateFlag) { + _audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::NO, Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_STEREO); + } // are we at or past time for this video frame? - if (_stateFlag && _videobufReady && _videobufTime <= get_time()) { - video_write(); - _videobufReady = false; - } + if (_stateFlag && _videobufReady) { + th_ycbcr_buffer yuv; + + th_decode_ycbcr_out(_theoraDecode, yuv); - if (_stateFlag && - (_audiobufReady || !_vorbisPacket) && - (_videobufReady || !_theoraPacket) && - !got_sigint) { - // we have an audio frame ready (which means the audio buffer is - // full), it's not time to play video, so wait until one of the - // audio buffer is ready or it's near time to play video - - // set up select wait on the audiobuffer and a timeout for video - struct timeval timeout; - fd_set writefs; - fd_set empty; - int n = 0; - - FD_ZERO(&writefs); - FD_ZERO(&empty); - if (audiofd >= 0) { - FD_SET(audiofd, &writefs); - n = audiofd + 1; + // TODO: YUV->RGB + switch (_theoraInfo.pixel_fmt) { + case TH_PF_420: + break; + case TH_PF_422: + break; + case TH_PF_444: + break; + default: + break; } - if (_theoraPacket) { - double tdiff; - long milliseconds; - tdiff = _videobufTime - get_time(); - - // If we have lots of extra time, increase the post-processing level. - if (tdiff > _theoraInfo.fps_denominator * 0.25 / _theoraInfo.fps_numerator) { - _ppInc = _ppLevel < _ppLevelMax ? 1 : 0; - } else if (tdiff < _theoraInfo.fps_denominator * 0.05 / _theoraInfo.fps_numerator) { - _ppInc = _ppLevel > 0 ? -1 : 0; - } - milliseconds = tdiff * 1000 - 5; - if (milliseconds > 500) - milliseconds = 500; - if (milliseconds > 0) { - timeout.tv_sec = milliseconds / 1000; - timeout.tv_usec = (milliseconds % 1000) * 1000; - - n = select(n, &empty, &writefs, &empty, &timeout); - if (n) - audio_calibrate_timer(0); - } - } else { - select(n, &empty, &writefs, &empty, NULL); - } + _videobufReady = false; } // if our buffers either don't exist or are ready to go, @@ -427,6 +394,8 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { // same if we've run out of input if (_fileStream->eos()) _stateFlag = true; + + return _surface; } void TheoraDecoder::reset() { @@ -450,7 +419,7 @@ uint32 TheoraDecoder::getElapsedTime() const { return VideoDecoder::getElapsedTime(); } -Audio::QueuingAudioStream *AviDecoder::createAudioStream() { +Audio::QueuingAudioStream *TheoraDecoder::createAudioStream() { return Audio::makeQueuingAudioStream(_vorbisInfo.rate, _vorbisInfo.channels); } diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index cd526b6ba0..b6cf4567fc 100755 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -56,6 +56,7 @@ public: */ bool load(Common::SeekableReadStream &stream); void close(); + void reset(); /** * Decode the next frame and return the frame's surface @@ -78,6 +79,7 @@ protected: private: void queuePage(ogg_page *page); int bufferData(); + Audio::QueuingAudioStream *createAudioStream(); private: Common::SeekableReadStream *_fileStream; @@ -89,7 +91,6 @@ private: Audio::Mixer::SoundType _soundType; Audio::SoundHandle *_audHandle; Audio::QueuingAudioStream *_audStream; - Audio::QueuingAudioStream *createAudioStream(); ogg_sync_state _oggSync; ogg_page _oggPage; -- cgit v1.2.3 From 47904bc7b2992189bb554833f00a79ff0fea9fb8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Fri, 6 Aug 2010 13:13:25 +0000 Subject: SWORD25: Mass-astyle. svn-id: r53222 --- engines/sword25/fmv/movieplayer.cpp | 6 ++++-- engines/sword25/fmv/movieplayer.h | 32 ++++++++++++++++---------------- engines/sword25/fmv/theora_decoder.cpp | 18 +++++++++--------- engines/sword25/fmv/theora_decoder.h | 26 +++++++++++++++++++------- 4 files changed, 48 insertions(+), 34 deletions(-) mode change 100755 => 100644 engines/sword25/fmv/theora_decoder.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index a031fc8283..ea22cfd3db 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -38,7 +38,9 @@ namespace Sword25 { #define BS_LOG_PREFIX "MOVIEPLAYER" -BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { return new BS_MoviePlayer(pKernel); } +BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { + return new BS_MoviePlayer(pKernel); +} BS_MoviePlayer::BS_MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) { if (!_RegisterScriptBindings()) diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index be841c51a9..08d0012388 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -23,7 +23,7 @@ * */ -/* +/* * This code is based on Broken Sword 2.5 engine * * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer @@ -67,16 +67,16 @@ public: * This method loads a movie file and prepares it for playback. * There can be oly one movie file loaded at a time. If you already have loaded a * movie file, it will be unloaded and, if necessary, stopped playing. - * @param Filename The filename of the movie file to be loaded - * @param Z Z indicates the position of the film on the main graphics layer - * @return Returns false if an error occured while loading, otherwise true. + * @param Filename The filename of the movie file to be loaded + * @param Z Z indicates the position of the film on the main graphics layer + * @return Returns false if an error occured while loading, otherwise true. */ bool LoadMovie(const Common::String &Filename, unsigned int Z); /** * Unloads the currently loaded movie file. - * @return Returns false if an error occurred while unloading, otherwise true. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @return Returns false if an error occurred while unloading, otherwise true. + * @remark This method can only be called when IsMovieLoaded() returns true. */ bool UnloadMovie(); @@ -85,8 +85,8 @@ public: * * The film will be keeping the aspect ratio of the screen. * If the film was previously paused with Pause(), then the film will resume playing. - * @return Returns false if an error occurred while starting, otherwise true. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @return Returns false if an error occurred while starting, otherwise true. + * @remark This method can only be called when IsMovieLoaded() returns true. */ bool Play(); @@ -94,8 +94,8 @@ public: * Pauses movie playback. * * A paused movie can later be resumed by calling the Play() method again. - * @return Returns false if an error occurred while pausing, otherwise true. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @return Returns false if an error occurred while pausing, otherwise true. + * @remark This method can only be called when IsMovieLoaded() returns true. */ bool Pause(); @@ -111,7 +111,7 @@ public: /** * Returns whether the movie playback is paused. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @remark This method can only be called when IsMovieLoaded() returns true. */ bool IsPaused(); @@ -120,21 +120,21 @@ public: * * When a movie is loaded, the scaling factor is automatically selected so that the film * takes the maximum screen space, without the film being distorted. - * @return Returns the scaling factor of the film. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @return Returns the scaling factor of the film. + * @remark This method can only be called when IsMovieLoaded() returns true. */ float GetScaleFactor(); /** * Sets the factor by which the loaded film is to be scaled. - * @param ScaleFactor The desired scale factor. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @param ScaleFactor The desired scale factor. + * @remark This method can only be called when IsMovieLoaded() returns true. */ void SetScaleFactor(float ScaleFactor); /** * Returns the current playing position in seconds. - * @remark This method can only be called when IsMovieLoaded() returns true. + * @remark This method can only be called when IsMovieLoaded() returns true. */ double GetTime(); diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index b6647559d2..133adb3007 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -64,11 +64,11 @@ TheoraDecoder::~TheoraDecoder() { } void TheoraDecoder::queuePage(ogg_page *page) { - if (_theoraPacket) - ogg_stream_pagein(&_theoraOut, page); + if (_theoraPacket) + ogg_stream_pagein(&_theoraOut, page); - if (_vorbisPacket) - ogg_stream_pagein(&_vorbisOut, page); + if (_vorbisPacket) + ogg_stream_pagein(&_vorbisOut, page); } int TheoraDecoder::bufferData() { @@ -203,7 +203,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { if (_theoraInfo.pic_width != _theoraInfo.frame_width || _theoraInfo.pic_height != _theoraInfo.frame_height) debug(1, " Frame content is %dx%d with offset (%d,%d).", - _theoraInfo.frame_width, _theoraInfo.frame_height, _theoraInfo.pic_x, _theoraInfo.pic_y); + _theoraInfo.frame_width, _theoraInfo.frame_height, _theoraInfo.pic_x, _theoraInfo.pic_y); th_decode_ctl(_theoraDecode, TH_DECCTL_GET_PPLEVEL_MAX, &_ppLevelMax, sizeof(_ppLevelMax)); _ppLevel = _ppLevelMax; @@ -222,7 +222,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { vorbis_synthesis_init(&_vorbisDSP, &_vorbisInfo); vorbis_block_init(&_vorbisDSP, &_vorbisBlock); debug(3, "Ogg logical stream %lx is Vorbis %d channel %ld Hz audio.", - _vorbisOut.serialno, _vorbisInfo.channels, _vorbisInfo.rate); + _vorbisOut.serialno, _vorbisInfo.channels, _vorbisInfo.rate); } else { // tear down the partial vorbis setup vorbis_info_clear(&_vorbisInfo); @@ -307,7 +307,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { _audiobufGranulePos = _vorbisDSP.granulepos - ret + i; else _audiobufGranulePos += i; - } else { + } else { // no pending audio; is there a pending packet to decode? if (ogg_stream_packetout(&_vorbisOut, &_oggPacket) > 0) { @@ -367,7 +367,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { // are we at or past time for this video frame? if (_stateFlag && _videobufReady) { th_ycbcr_buffer yuv; - + th_decode_ycbcr_out(_theoraDecode, yuv); // TODO: YUV->RGB @@ -388,7 +388,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { // if our buffers either don't exist or are ready to go, // we can begin playback if ((!_theoraPacket || _videobufReady) && - (!_vorbisPacket || _audiobufReady)) + (!_vorbisPacket || _audiobufReady)) _stateFlag = true; // same if we've run out of input diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h old mode 100755 new mode 100644 index b6cf4567fc..690763e940 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -34,7 +34,7 @@ #include namespace Common { - class SeekableReadStream; +class SeekableReadStream; } namespace Sword25 { @@ -65,16 +65,28 @@ public: */ Graphics::Surface *decodeNextFrame(); - bool isVideoLoaded() const { return _fileStream != 0; } - uint16 getWidth() const { return _surface->w; } - uint16 getHeight() const { return _surface->h; } - uint32 getFrameCount() const { return _frameCount; } - Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); } + bool isVideoLoaded() const { + return _fileStream != 0; + } + uint16 getWidth() const { + return _surface->w; + } + uint16 getHeight() const { + return _surface->h; + } + uint32 getFrameCount() const { + return _frameCount; + } + Graphics::PixelFormat getPixelFormat() const { + return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); + } uint32 getElapsedTime() const; protected: - Common::Rational getFrameRate() const { return _frameRate; } + Common::Rational getFrameRate() const { + return _frameRate; + } private: void queuePage(ogg_page *page); -- cgit v1.2.3 From 596684101e3431e61dbeabeb81eee66322e15042 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Tue, 17 Aug 2010 09:52:50 +0000 Subject: SWORD25: Added implementation of rint method Windows doesn't seem to implement this method; even examples for FMOD I saw had WIN32 defines that manually provided the method. svn-id: r53256 --- engines/sword25/fmv/theora_decoder.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index 133adb3007..ef9f904f77 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -45,6 +45,10 @@ namespace Sword25 { #define AUDIOFD_FRAGSIZE 10240 +static double rint(double v) { + return floor(v + 0.5); +} + TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : _mixer(mixer) { _fileStream = 0; _surface = 0; -- cgit v1.2.3 From 485ff15d23b3ae9545f5c9df794f1326185eae7a Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 18 Aug 2010 10:52:24 +0000 Subject: SWORD25: Mass-eliminating of BS_ prefix in fmv/ and gfx/ svn-id: r53258 --- engines/sword25/fmv/movieplayer.cpp | 24 ++++++++++++------------ engines/sword25/fmv/movieplayer.h | 6 +++--- engines/sword25/fmv/movieplayer_script.cpp | 22 +++++++++++----------- 3 files changed, 26 insertions(+), 26 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index ea22cfd3db..fffefde5db 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -39,51 +39,51 @@ namespace Sword25 { #define BS_LOG_PREFIX "MOVIEPLAYER" BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { - return new BS_MoviePlayer(pKernel); + return new MoviePlayer(pKernel); } -BS_MoviePlayer::BS_MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) { +MoviePlayer::MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); } -bool BS_MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { +bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { return true; } -bool BS_MoviePlayer::UnloadMovie() { +bool MoviePlayer::UnloadMovie() { return true; } -bool BS_MoviePlayer::Play() { +bool MoviePlayer::Play() { return true; } -bool BS_MoviePlayer::Pause() { +bool MoviePlayer::Pause() { return true; } -void BS_MoviePlayer::Update() { +void MoviePlayer::Update() { } -bool BS_MoviePlayer::IsMovieLoaded() { +bool MoviePlayer::IsMovieLoaded() { return true; } -bool BS_MoviePlayer::IsPaused() { +bool MoviePlayer::IsPaused() { return true; } -float BS_MoviePlayer::GetScaleFactor() { +float MoviePlayer::GetScaleFactor() { return 1.0f; } -void BS_MoviePlayer::SetScaleFactor(float ScaleFactor) { +void MoviePlayer::SetScaleFactor(float ScaleFactor) { } -double BS_MoviePlayer::GetTime() { +double MoviePlayer::GetTime() { return 1.0; } diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 08d0012388..ceb7c6dad9 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -48,14 +48,14 @@ namespace Sword25 { // Class definitions // ----------------------------------------------------------------------------- -class BS_MoviePlayer : public BS_Service { +class MoviePlayer : public BS_Service { public: // ----------------------------------------------------------------------------- // Constructor / Destructor // ----------------------------------------------------------------------------- - BS_MoviePlayer(BS_Kernel *pKernel); - ~BS_MoviePlayer() {}; + MoviePlayer(BS_Kernel *pKernel); + ~MoviePlayer() {}; // ----------------------------------------------------------------------------- // Abstract interface must be implemented by each Movie Player diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index 523cc2d4f3..dcf5cd334b 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -46,7 +46,7 @@ namespace Sword25 { int LoadMovie(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); @@ -57,7 +57,7 @@ int LoadMovie(lua_State *L) { // ------------------------------------------------------------------------- int UnloadMovie(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->UnloadMovie()); @@ -68,7 +68,7 @@ int UnloadMovie(lua_State *L) { // ------------------------------------------------------------------------- int Play(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->Play()); @@ -79,7 +79,7 @@ int Play(lua_State *L) { // ------------------------------------------------------------------------- int Pause(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->Pause()); @@ -90,7 +90,7 @@ int Pause(lua_State *L) { // ------------------------------------------------------------------------- int Update(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); FMVPtr->Update(); @@ -101,7 +101,7 @@ int Update(lua_State *L) { // ------------------------------------------------------------------------- int IsMovieLoaded(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->IsMovieLoaded()); @@ -112,7 +112,7 @@ int IsMovieLoaded(lua_State *L) { // ------------------------------------------------------------------------- int IsPaused(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->IsPaused()); @@ -123,7 +123,7 @@ int IsPaused(lua_State *L) { // ------------------------------------------------------------------------- int GetScaleFactor(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushnumber(L, FMVPtr->GetScaleFactor()); @@ -134,7 +134,7 @@ int GetScaleFactor(lua_State *L) { // ------------------------------------------------------------------------- int SetScaleFactor(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); FMVPtr->SetScaleFactor(static_cast(luaL_checknumber(L, 1))); @@ -145,7 +145,7 @@ int SetScaleFactor(lua_State *L) { // ------------------------------------------------------------------------- int GetTime(lua_State *L) { - BS_MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushnumber(L, FMVPtr->GetTime()); @@ -171,7 +171,7 @@ const luaL_reg LIBRARY_FUNCTIONS[] = { { 0, 0 } }; -bool BS_MoviePlayer::_RegisterScriptBindings() { +bool MoviePlayer::_RegisterScriptBindings() { BS_Kernel *pKernel = BS_Kernel::GetInstance(); BS_ASSERT(pKernel); BS_ScriptEngine *pScript = static_cast(pKernel->GetService("script")); -- cgit v1.2.3 From be44216e5c1d74879d7843215ce1cd3f488b4db8 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 18 Aug 2010 12:57:47 +0000 Subject: SWORD25: eliminated BS_ prefix in all but kernel/ svn-id: r53259 --- engines/sword25/fmv/movieplayer.cpp | 2 +- engines/sword25/fmv/movieplayer_script.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index fffefde5db..076226bf89 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -38,7 +38,7 @@ namespace Sword25 { #define BS_LOG_PREFIX "MOVIEPLAYER" -BS_Service *BS_OggTheora_CreateObject(BS_Kernel *pKernel) { +BS_Service *OggTheora_CreateObject(BS_Kernel *pKernel) { return new MoviePlayer(pKernel); } diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index dcf5cd334b..a89338f224 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -174,12 +174,12 @@ const luaL_reg LIBRARY_FUNCTIONS[] = { bool MoviePlayer::_RegisterScriptBindings() { BS_Kernel *pKernel = BS_Kernel::GetInstance(); BS_ASSERT(pKernel); - BS_ScriptEngine *pScript = static_cast(pKernel->GetService("script")); + ScriptEngine *pScript = static_cast(pKernel->GetService("script")); BS_ASSERT(pScript); lua_State *L = static_cast(pScript->GetScriptObject()); BS_ASSERT(L); - if (!BS_LuaBindhelper::AddFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false; + if (!LuaBindhelper::AddFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false; return true; } -- cgit v1.2.3 From b01994a53bbc96da907a4c28934e644184291017 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 18 Aug 2010 12:58:22 +0000 Subject: SWORD25: removed BS_ prefix from rest of the classes. The things which are intentionally left with the prefix: BS_LOG, BS_ASSERT, BS_Rect, BS_String. svn-id: r53261 --- engines/sword25/fmv/movieplayer.cpp | 4 ++-- engines/sword25/fmv/movieplayer.h | 4 ++-- engines/sword25/fmv/movieplayer_script.cpp | 22 +++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 076226bf89..e4b33bdf8c 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -38,11 +38,11 @@ namespace Sword25 { #define BS_LOG_PREFIX "MOVIEPLAYER" -BS_Service *OggTheora_CreateObject(BS_Kernel *pKernel) { +Service *OggTheora_CreateObject(Kernel *pKernel) { return new MoviePlayer(pKernel); } -MoviePlayer::MoviePlayer(BS_Kernel *pKernel) : BS_Service(pKernel) { +MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index ceb7c6dad9..3404eaacd8 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -48,13 +48,13 @@ namespace Sword25 { // Class definitions // ----------------------------------------------------------------------------- -class MoviePlayer : public BS_Service { +class MoviePlayer : public Service { public: // ----------------------------------------------------------------------------- // Constructor / Destructor // ----------------------------------------------------------------------------- - MoviePlayer(BS_Kernel *pKernel); + MoviePlayer(Kernel *pKernel); ~MoviePlayer() {}; // ----------------------------------------------------------------------------- diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index a89338f224..0b96d4dc34 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -46,7 +46,7 @@ namespace Sword25 { int LoadMovie(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); @@ -57,7 +57,7 @@ int LoadMovie(lua_State *L) { // ------------------------------------------------------------------------- int UnloadMovie(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->UnloadMovie()); @@ -68,7 +68,7 @@ int UnloadMovie(lua_State *L) { // ------------------------------------------------------------------------- int Play(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->Play()); @@ -79,7 +79,7 @@ int Play(lua_State *L) { // ------------------------------------------------------------------------- int Pause(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->Pause()); @@ -90,7 +90,7 @@ int Pause(lua_State *L) { // ------------------------------------------------------------------------- int Update(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); FMVPtr->Update(); @@ -101,7 +101,7 @@ int Update(lua_State *L) { // ------------------------------------------------------------------------- int IsMovieLoaded(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->IsMovieLoaded()); @@ -112,7 +112,7 @@ int IsMovieLoaded(lua_State *L) { // ------------------------------------------------------------------------- int IsPaused(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushbooleancpp(L, FMVPtr->IsPaused()); @@ -123,7 +123,7 @@ int IsPaused(lua_State *L) { // ------------------------------------------------------------------------- int GetScaleFactor(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushnumber(L, FMVPtr->GetScaleFactor()); @@ -134,7 +134,7 @@ int GetScaleFactor(lua_State *L) { // ------------------------------------------------------------------------- int SetScaleFactor(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); FMVPtr->SetScaleFactor(static_cast(luaL_checknumber(L, 1))); @@ -145,7 +145,7 @@ int SetScaleFactor(lua_State *L) { // ------------------------------------------------------------------------- int GetTime(lua_State *L) { - MoviePlayer *FMVPtr = BS_Kernel::GetInstance()->GetFMV(); + MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); lua_pushnumber(L, FMVPtr->GetTime()); @@ -172,7 +172,7 @@ const luaL_reg LIBRARY_FUNCTIONS[] = { }; bool MoviePlayer::_RegisterScriptBindings() { - BS_Kernel *pKernel = BS_Kernel::GetInstance(); + Kernel *pKernel = Kernel::GetInstance(); BS_ASSERT(pKernel); ScriptEngine *pScript = static_cast(pKernel->GetService("script")); BS_ASSERT(pScript); -- cgit v1.2.3 From cb95db7cc04a5a3d14f408835cd371e0a0abd4ed Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 30 Aug 2010 07:48:27 +0000 Subject: SWORD25: Commit of in-progress MoviePlayer code Frames aren't being corrected decoded yet; still trying to locate the cause svn-id: r53295 --- engines/sword25/fmv/movieplayer.cpp | 481 ++++++++++++++- engines/sword25/fmv/movieplayer.h | 68 ++- engines/sword25/fmv/oggtheora/audiobuffer.cpp | 54 +- engines/sword25/fmv/oggtheora/audiobuffer.h | 26 +- engines/sword25/fmv/oggtheora/moviefile.cpp | 34 +- engines/sword25/fmv/oggtheora/moviefile.h | 17 +- engines/sword25/fmv/oggtheora/oggstate.cpp | 19 +- engines/sword25/fmv/oggtheora/oggstate.h | 36 +- engines/sword25/fmv/oggtheora/oggstreamstate.cpp | 40 +- engines/sword25/fmv/oggtheora/oggstreamstate.h | 48 +- engines/sword25/fmv/oggtheora/oggtheora.cpp | 723 ----------------------- engines/sword25/fmv/oggtheora/oggtheora.h | 124 ---- engines/sword25/fmv/oggtheora/theorastate.cpp | 27 +- engines/sword25/fmv/oggtheora/theorastate.h | 19 +- engines/sword25/fmv/oggtheora/vorbisstate.cpp | 35 +- engines/sword25/fmv/oggtheora/vorbisstate.h | 21 +- engines/sword25/fmv/oggtheora/yuvtorgba.cpp | 587 +++++++----------- engines/sword25/fmv/oggtheora/yuvtorgba.h | 14 +- 18 files changed, 911 insertions(+), 1462 deletions(-) delete mode 100644 engines/sword25/fmv/oggtheora/oggtheora.cpp delete mode 100644 engines/sword25/fmv/oggtheora/oggtheora.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index e4b33bdf8c..69b8fe41ec 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -33,59 +33,524 @@ */ #include "sword25/fmv/movieplayer.h" +#include "sword25/fmv/oggtheora/oggstate.h" +#include "sword25/fmv/oggtheora/oggstreamstate.h" +#include "sword25/fmv/oggtheora/vorbisstate.h" +#include "sword25/fmv/oggtheora/yuvtorgba.h" +#include "sword25/gfx/graphicengine.h" +#include "sword25/gfx/panel.h" +#include "sword25/kernel/kernel.h" +#include "sword25/sfx/soundengine.h" + +#define BS_LOG_PREFIX "MOVIEPLAYER" + +#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */ namespace Sword25 { -#define BS_LOG_PREFIX "MOVIEPLAYER" +const int MAX_FRAMES_PER_TICK = 10; +const int READ_BLOCK_SIZE = 1024 * 40; +const float MAX_AUDIO_BUFFER_LENGTH = 1.0f; Service *OggTheora_CreateObject(Kernel *pKernel) { return new MoviePlayer(pKernel); } -MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { +// ----------------------------------------------------------------------------- + +inline bool VerifyRequiredServiceAvailability() { + char *RequiredServices[] = { "gfx", "sfx", "package" }; + for (size_t i = 0; i < sizeof(RequiredServices) / sizeof(RequiredServices[0]); ++i) { + if (!Kernel::GetInstance()->GetService(RequiredServices[i])) { + BS_LOG_ERRORLN("Required service \"%s\" is not active.", RequiredServices[i]); + return false; + } + } + + return true; +} + +bool ParseStreamHeaders(Common::SharedPtr &File, + Common::SharedPtr &OggState, + Common::SharedPtr &TheoraStreamState, + Common::SharedPtr &VorbisStreamState, + Common::SharedPtr &TheoraState, + Common::SharedPtr &VorbisState, + bool &TheoraPresent, + bool &VorbisPresent, + const Common::String &Filename) { + TheoraPresent = false; + VorbisPresent = false; + + // Ogg file open; parse the headers + // Only interested in Vorbis/Theora streams + bool FinishedHeaderParsing = false; + while (!FinishedHeaderParsing) { + if (File->BufferData(*OggState.get()) == 0) return false; + + ogg_page Page; + while(OggState->SyncPageout(&Page) > 0) { + // is this a mandated initial header? If not, stop parsing + if (!ogg_page_bos(&Page)) { + // don't leak the page; get it into the appropriate stream + if (TheoraPresent) TheoraStreamState->PageIn(&Page); + if (VorbisPresent) VorbisStreamState->PageIn(&Page); + + FinishedHeaderParsing = true; + break; + } + + Common::SharedPtr streamState(new OggStreamState(ogg_page_serialno(&Page))); + + streamState->PageIn(&Page); + + ogg_packet Packet; + streamState->PacketOut(&Packet); + + // identify the codec: try theora + if (!TheoraPresent && TheoraState->DecodeHeader(&Packet) >= 0) { + // it is theora + TheoraStreamState = streamState; + TheoraPresent = true; + } else if (!VorbisPresent && VorbisState->SynthesisHeaderIn(&Packet) >=0) { + // it is vorbis + VorbisStreamState = streamState; + VorbisPresent = true; + } + } + // fall through to non-bos page parsing + } + + // we're expecting more header packets. + unsigned int TheoraPacketsRead = TheoraPresent ? 1 : 0; + unsigned int VorbisPacketsRead = VorbisPresent ? 1 : 0; + while ((TheoraPresent && TheoraPacketsRead < 3) || (VorbisPresent && VorbisPacketsRead < 3)) { + int ret; + ogg_packet Packet; + + // look for further theora headers + while(TheoraPresent && (TheoraPacketsRead < 3) && (ret = TheoraStreamState->PacketOut(&Packet))) { + if (ret < 0 || TheoraState->DecodeHeader(&Packet)) { + BS_LOG_ERRORLN("Error parsing Theora stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); + return false; + } + + ++TheoraPacketsRead; + if (TheoraPacketsRead == 3) break; + } + + // look for more vorbis header packets + while(VorbisPresent && (VorbisPacketsRead < 3) && (ret = VorbisStreamState->PacketOut(&Packet))) { + if (ret < 0 || VorbisState->SynthesisHeaderIn(&Packet)) { + BS_LOG_ERRORLN("Error parsing Vorbis stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); + return false; + } + + ++VorbisPacketsRead; + if (VorbisPacketsRead == 3) break; + } + + // The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec + ogg_page Page; + if (OggState->SyncPageout(&Page) > 0) { + // demux into the appropriate stream + if (TheoraPresent) TheoraStreamState->PageIn(&Page); + if (VorbisPresent) VorbisStreamState->PageIn(&Page); + } else { + if (File->BufferData(*OggState.get()) == 0) { + BS_LOG_ERRORLN("End of file while searching for codec headers. (%s)", Filename.c_str()); + return false; + } + } + } + + return true; +} + +// ----------------------------------------------------------------------------- + +MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), + m_SoundHandle(0), _pixels(NULL) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); + + UnloadMovie(); +} + +MoviePlayer::~MoviePlayer() { + delete _pixels; } bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { + if (!VerifyRequiredServiceAvailability()) return false; + + UnloadMovie(); + + // Alle Objekte die in dieser Funktion erzeugt werden, werden in zunächst lokalen Auto-Pointern gehalten. + // Bei erfolgreicher Beendigung dieser Funktion werden sie den objektlokalen Auto-Pointern zugewiesen. + // So wird sichergestellt, dass sie korrekt deinitialisiert werden, wenn in dieser Funktion ein Fehler auftritt, denn beim Zerstören der + // lokalen Auto-Pointer werden die entsprechenden Destruktoren aufgerufen. + + // Film laden + // Für Filmdateien wird das Cachingsystem nicht benutzt, da Filme in der Regel nur ein Mal abgespielt werden. + bool Success = false; + Common::SharedPtr File(new MovieFile(Filename, READ_BLOCK_SIZE, Success)); + if (!Success) return false; + + // States erzeugen für Ogg, Vorbis und Theora, sowie die Ogg und Theora Streams + Common::SharedPtr OggState(new OggState()); + Common::SharedPtr VorbisState(new VorbisState()); + Common::SharedPtr TheoraState(new TheoraState()); + + Common::SharedPtr TheoraStreamState; + Common::SharedPtr VorbisStreamState; + + if (!ParseStreamHeaders(File, OggState, TheoraStreamState, VorbisStreamState, TheoraState, VorbisState, m_TheoraPresent, m_VorbisPresent, Filename)) return false; + + // Theora-Decoder Initialisieren + if (m_TheoraPresent) { + TheoraState->DecodeInit(); + + const theora_info & TheoraInfo = TheoraState->GetInfo(); + + if (TheoraInfo.pixelformat != OC_PF_444 && + TheoraInfo.pixelformat != OC_PF_422 && + TheoraInfo.pixelformat != OC_PF_420) { + BS_LOG_ERRORLN("Unknown chroma sampling. (%s)", Filename.c_str()); + return false; + } + + // Ausgabebitmap erstellen + GraphicEngine *pGfx = Kernel::GetInstance()->GetGfx(); + m_OutputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(TheoraInfo.frame_width, TheoraInfo.frame_height); + if (!m_OutputBitmap.IsValid()) { + BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); + return false; + } + + // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. + float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); + float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); + float ScaleFactor = MIN(ScreenToVideoWidth, ScreenToVideoHeight); + if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; + m_OutputBitmap->SetScaleFactor(ScaleFactor); + + // Z-Wert setzen + m_OutputBitmap->SetZ(Z); + + // Ausgabebitmap auf dem Bildschirm zentrieren + m_OutputBitmap->SetX((pGfx->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); + m_OutputBitmap->SetY((pGfx->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); + + // Buffer für die Pixeldaten erstellen + delete _pixels; + _pixelsSize = TheoraInfo.width * TheoraInfo.height * 4; + _pixels = (byte *)malloc(_pixelsSize); + assert(_pixels); + + m_VideoEnded = false; + } + + // Vorbis-Decoder initialisieren + if (m_VorbisPresent) { + VorbisState->SynthesisInit(); + VorbisState->BlockInit(); + m_AudioBuffer = Common::SharedPtr(new AudioBuffer()); + + m_AudioEnded = false; + } + + // Keine Kopie, überträgt Besitz der erzeugten Objekte von der Funktion auf das Objekt. + m_File = File; + m_OggState = OggState; + m_TheoraState = TheoraState; + m_TheoraStreamState = TheoraStreamState; + m_VorbisState = VorbisState; + m_VorbisStreamState = VorbisStreamState; + m_MovieLoaded = true; + m_Timer = 0; + return true; } bool MoviePlayer::UnloadMovie() { + m_MovieLoaded = false; + m_Paused = true; + + m_VorbisStreamState.reset(); + m_VorbisPresent = false; + m_VorbisState.reset(); + if (m_SoundHandle) { + Kernel::GetInstance()->GetSfx()->StopSound(m_SoundHandle); + m_SoundHandle = 0; + } + m_AudioEnded = true; + m_AudioBuffer.reset(); + + m_TheoraStreamState.reset(); + m_TheoraPresent = false; + m_TheoraState.reset(); + m_VideoEnded = true; + + m_OggState.reset(); + + m_File.reset(); + + m_StartTime = 0; + m_LastFrameTime = 0; + m_Timer = 0.0f; + +// Common::Array().swap(m_Pixels); + m_OutputBitmap.Erase(); + return true; } bool MoviePlayer::Play() { - return true; + if (m_MovieLoaded) { + if (m_Paused) { + if (m_SoundHandle) { + SoundEngine * SfxPtr = Kernel::GetInstance()->GetSfx(); + SfxPtr->ResumeSound(m_SoundHandle); + } + m_Paused = false; + } + + return true; + } else { + BS_LOG_WARNINGLN("Cannot play movie, when no movie is loaded."); + return false; + } } bool MoviePlayer::Pause() { - return true; + if (m_MovieLoaded) { + if (m_SoundHandle) { + SoundEngine *SfxPtr = Kernel::GetInstance()->GetSfx(); + SfxPtr->PauseSound(m_SoundHandle); + } + + m_Paused = true; + return true; + } else { + BS_LOG_WARNINGLN("Cannot pause movie, when no movie is loaded."); + return false; + } } void MoviePlayer::Update() { + if (m_AudioEnded && m_VideoEnded) { + m_Paused = true; + + // Falls der Sound noch läuft, muss er jetzt beendet werden. + if (m_SoundHandle) { + SoundEngine *SfxPtr = Kernel::GetInstance()->GetSfx(); + SfxPtr->StopSound(m_SoundHandle); + m_SoundHandle = 0; + } + } + + if (m_Paused) return; + + // Timer aktualisieren. + // Wird nur genutzt, wenn keine Audiodaten vorhanden sind. + m_Timer += Kernel::GetInstance()->GetGfx()->GetSecondaryFrameDuration(); + + // Audiodaten dekodieren + if (m_VorbisPresent && !m_AudioEnded) DecodeVorbis(); + + + // Videodaten dekodieren + if (m_TheoraPresent && !m_VideoEnded) { + bool Result = DecodeTheora(); + + if (Result) { + // YUV Framebuffer holen + yuv_buffer YUVBuffer; + m_TheoraState->DecodeYUVOut(&YUVBuffer); + + // YUV Bilddaten nach RGBA konvertieren + BS_YUVtoRGBA::YUVtoRGBA(YUVBuffer, m_TheoraState->GetInfo(), _pixels, _pixelsSize); + + // RGBA Bilddaten auf das Ausgabebild kopieren, dabei die Postion des Theoraframes innerhalb des dekodierten Frames beachten. + const theora_info &TheoraInfo = m_TheoraState->GetInfo(); + m_OutputBitmap->SetContent(_pixels, _pixelsSize, + (TheoraInfo.offset_x + TheoraInfo.width * TheoraInfo.offset_y) * 4, + (TheoraInfo.width - TheoraInfo.frame_width) * 4); + } + } } bool MoviePlayer::IsMovieLoaded() { - return true; + return m_MovieLoaded; } bool MoviePlayer::IsPaused() { - return true; + return m_Paused; } float MoviePlayer::GetScaleFactor() { - return 1.0f; + if (m_MovieLoaded) + return m_OutputBitmap->GetScaleFactorX(); + else + return 0; } void MoviePlayer::SetScaleFactor(float ScaleFactor) { + if (m_MovieLoaded) { + m_OutputBitmap->SetScaleFactor(ScaleFactor); + + // Ausgabebitmap auf dem Bildschirm zentrieren + GraphicEngine *gfxPtr = Kernel::GetInstance()->GetGfx(); + m_OutputBitmap->SetX((gfxPtr->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); + m_OutputBitmap->SetY((gfxPtr->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); + } } double MoviePlayer::GetTime() { - return 1.0; + if (m_VorbisPresent) { + if (m_SoundHandle) { + float time = Kernel::GetInstance()->GetSfx()->GetSoundTime(m_SoundHandle); + return time; + } else + return 0.0f; + } else + return m_Timer; } +// ----------------------------------------------------------------------------- + +bool MoviePlayer::DecodeTheora() { + double MovieTime = GetTime(); + + // Check if this frame time has not passed yet. If the frame is late we need + // to decode additonal ones and keep looping, since theora at this stage + // needs to decode all frames (due to keyframing) + // Getting the current time once at the beginning of the function rather than + // every time at the beginning of the loop produces the smoothest framerate + + unsigned int FramesDecoded = 0; + bool FrameReady = false; + while (m_TheoraState->GranuleTime() < MovieTime) { + // theora is one in, one out... + ogg_packet Packet; + if (m_TheoraStreamState->PacketOut(&Packet) > 0) { + if (FramesDecoded < MAX_FRAMES_PER_TICK || Packet.granulepos >= MovieTime) { + m_TheoraState->DecodePacketIn(&Packet); + FrameReady = true; + ++FramesDecoded; + } + } else { + if (m_TheoraStreamState->GetPageBufferSize() > 0) + m_TheoraStreamState->PageInBufferedPage(); + else { + if (m_File->IsEOF()) { + m_VideoEnded = true; + break; + } else + ReadData(); + } + } + } + m_LastFrameTime = MovieTime; + + return FrameReady; +} + +void MoviePlayer::DecodeVorbis() { + // Vorbis-Stream Infos holen. + const vorbis_info &Info = m_VorbisState->GetInfo(); + + // Maximalgröße des Audiobuffers berechnen. + size_t MaxAudioBufferSamples = static_cast(Info.channels * Info.rate * MAX_AUDIO_BUFFER_LENGTH); + + // Zwischenspeicher für die Samples. + Common::Array Samples; + + // Audiobuffer bis zur Maximalgröße füllen, wenn möglich. + while (m_AudioBuffer->Size() < MaxAudioBufferSamples) { + // Vorhandene Audiodaten auslesen + float **PCM; + int SampleCount = m_VorbisState->SynthesisPCMout(&PCM); + + // Wenn Audiodaten gelesen werden konnten, werden diese in 16-Bit Sample umgewandelt und in den Audiobuffer geschrieben. + if (SampleCount > 0) { + // Im Samplezwischenspeicher leeren und genügend Platz für die kommenden Samples reservieren. + Samples.reserve(SampleCount); + Samples.clear(); + + // Samples konvertieren und in die Samplezwischenspeicher schreiben. + for (int i = 0; i < SampleCount; ++i) { + for (int j = 0; j < Info.channels; ++j) { + int SampleValue = static_cast(PCM[j][i] * 32767.0f); + Samples.push_back(CLIP(SampleValue, -32700, 32700)); + } + } + + // Daten aus dem Samplezwischenspeicher in den Audiobuffer schreiben. + m_AudioBuffer->Push(&Samples[0], Samples.size()); + + // Vorbis mitteilen, dass wir alle Samples gelesen haben. + m_VorbisState->SynthesisRead(SampleCount); + } else { + // Wir konnten, keine Audiodaten auslesen, versuchen ein neues Paket zu dekodieren. + ogg_packet Packet; + if (m_VorbisStreamState->PacketOut(&Packet) > 0) { + if (m_VorbisState->Synthesis(&Packet) == 0) m_VorbisState->SynthesisBlockIn(); + } else { + // Gepufferte Daten in den Stream einfügen. + if (m_VorbisStreamState->GetPageBufferSize() > 0) + m_VorbisStreamState->PageInBufferedPage(); + else { + // Nicht genug Daten vorhanden. Wenn die Datei leer ist und bereits alle Audiodaten gelesen wurden, ist der Audiostream am Ende. + // Ansonsten Daten nachladen. + if (m_File->IsEOF()) { + if (m_AudioBuffer->Size() == 0) { + m_AudioEnded = true; + } + + break; + } else + ReadData(); + } + } + } + } + + // Soundkanal abspielen, wenn er noch nicht spielt und Audiodaten vorhanden sind. + if (m_SoundHandle == 0 && m_AudioBuffer->Size()) { + SoundEngine *SfxPtr = Kernel::GetInstance()->GetSfx(); + m_SoundHandle = SfxPtr->PlayDynamicSoundEx(&DynamicSoundCallBack, this, SoundEngine::SFX, Info.rate, 16, Info.channels); + } +} + +void MoviePlayer::ReadData() { + if (!m_File->IsEOF()) m_File->BufferData(*m_OggState.get()); + + ogg_page Page; + while(m_OggState->SyncPageout(&Page) > 0) { + if (m_TheoraPresent) m_TheoraStreamState->BufferPage(&Page); + if (m_VorbisPresent) m_VorbisStreamState->BufferPage(&Page); + } +} + +void MoviePlayer::DynamicSoundCallBack(void *UserData, void *Data, unsigned int DataLength) { + MoviePlayer &t = *reinterpret_cast(UserData); + + signed short *Buffer = reinterpret_cast(Data); + + // Audiodaten in den Soundbuffer schreiben. + DataLength -= t.m_AudioBuffer->Pop(Buffer, DataLength / 2) * 2; + + // Falls nicht genug Audiodaten vorhanden waren, wird der Rest mit Stille überschrieben. + if (DataLength) { + char *ByteBuffer = reinterpret_cast(Buffer); + while (DataLength--) { + *ByteBuffer++ = 0; + } + } +} } // End of namespace Sword25 diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 3404eaacd8..46890991d9 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -39,11 +39,38 @@ // Includes // ----------------------------------------------------------------------------- +#include "common/ptr.h" #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" +#include "sword25/fmv/oggtheora/audiobuffer.h" +#include "sword25/fmv/oggtheora/moviefile.h" +#include "sword25/fmv/oggtheora/oggstreamstate.h" +#include "sword25/fmv/oggtheora/theorastate.h" +#include "sword25/fmv/oggtheora/vorbisstate.h" +#include "sword25/gfx/bitmap.h" namespace Sword25 { +/* FIXME: Audio stubs +class OggStreamState { +public: + OggStreamState(int v) {} + void PageIn(void *v) {} + bool PacketOut(void *v) { return true; } +}; +class VorbisState { +public: + void BlockInit() {} + void SynthesisInit() {} + bool SynthesisHeaderIn(void *v) { return false; } +}; +class OggState { +public: + bool SyncPageout(void *v) { return false; } + char *SyncBuffer(int v) { return NULL; } +}; +*/ + // ----------------------------------------------------------------------------- // Class definitions // ----------------------------------------------------------------------------- @@ -55,10 +82,10 @@ public: // ----------------------------------------------------------------------------- MoviePlayer(Kernel *pKernel); - ~MoviePlayer() {}; + ~MoviePlayer(); // ----------------------------------------------------------------------------- - // Abstract interface must be implemented by each Movie Player + // Player interface must be implemented by a Movie Player // ----------------------------------------------------------------------------- /** @@ -137,9 +164,44 @@ public: * @remark This method can only be called when IsMovieLoaded() returns true. */ double GetTime(); - private: + // ----------------------------------------------------------------------------- + // Internal support methods + // ----------------------------------------------------------------------------- bool _RegisterScriptBindings(); + bool DecodeTheora(); + void DecodeVorbis(); + void ReadData(); + static void DynamicSoundCallBack(void *UserData, void *Data, unsigned int DataLength); + +private: + bool m_MovieLoaded; + bool m_Paused; + + Common::SharedPtr m_VorbisStreamState; + bool m_VorbisPresent; + Common::SharedPtr m_VorbisState; + unsigned int m_SoundHandle; + bool m_AudioEnded; + Common::SharedPtr m_AudioBuffer; + + Common::SharedPtr m_TheoraStreamState; + bool m_TheoraPresent; + Common::SharedPtr m_TheoraState; + bool m_VideoEnded; + + Common::SharedPtr m_OggState; + + Common::SharedPtr m_File; + + uint64_t m_StartTime; + double m_LastFrameTime; + + float m_Timer; + + byte * _pixels; + int _pixelsSize; + RenderObjectPtr m_OutputBitmap; }; } // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.cpp b/engines/sword25/fmv/oggtheora/audiobuffer.cpp index f9e6667ce5..1e5828f41b 100644 --- a/engines/sword25/fmv/oggtheora/audiobuffer.cpp +++ b/engines/sword25/fmv/oggtheora/audiobuffer.cpp @@ -37,72 +37,46 @@ // ----------------------------------------------------------------------------- #include "sword25/fmv/oggtheora/audiobuffer.h" -#include -#include - -using namespace std; // ----------------------------------------------------------------------------- -struct BS_AudioBuffer::Impl -{ - CRITICAL_SECTION CS; - queue Buffer; -}; +namespace Sword25 { // ----------------------------------------------------------------------------- -BS_AudioBuffer::BS_AudioBuffer() : t(new Impl()) -{ - InitializeCriticalSection(&t->CS); +AudioBuffer::AudioBuffer() { } // ----------------------------------------------------------------------------- -BS_AudioBuffer::~BS_AudioBuffer() -{ - DeleteCriticalSection(&t->CS); - - delete t; +AudioBuffer::~AudioBuffer() { } // ----------------------------------------------------------------------------- -void BS_AudioBuffer::Push(signed short * SamplePtr, unsigned int SampleCount) -{ - EnterCriticalSection(&t->CS); - - signed short * SampleEndPtr = SamplePtr + SampleCount; - while (SamplePtr != SampleEndPtr) t->Buffer.push(*SamplePtr++); - - LeaveCriticalSection(&t->CS); +void AudioBuffer::Push(signed short *SamplePtr, unsigned int SampleCount) { + signed short *SampleEndPtr = SamplePtr + SampleCount; + while (SamplePtr != SampleEndPtr) _buffer.push(*SamplePtr++); } // ----------------------------------------------------------------------------- -unsigned int BS_AudioBuffer::Pop(signed short * SamplePtr, unsigned int SampleCount) -{ - EnterCriticalSection(&t->CS); - +unsigned int AudioBuffer::Pop(signed short *SamplePtr, unsigned int SampleCount) { unsigned int i = 0; - for (; i < SampleCount && !t->Buffer.empty(); ++i) - { - SamplePtr[i] = t->Buffer.front(); - t->Buffer.pop(); + for (; i < SampleCount && !_buffer.empty(); ++i) { + SamplePtr[i] = _buffer.front(); + _buffer.pop(); } - LeaveCriticalSection(&t->CS); - return i; } // ----------------------------------------------------------------------------- -unsigned int BS_AudioBuffer::Size() const -{ - EnterCriticalSection(&t->CS); - unsigned int result = t->Buffer.size(); - LeaveCriticalSection(&t->CS); +unsigned int AudioBuffer::Size() const { + unsigned int result = _buffer.size(); return result; } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.h b/engines/sword25/fmv/oggtheora/audiobuffer.h index 0b4233bc4e..fad227a2bc 100644 --- a/engines/sword25/fmv/oggtheora/audiobuffer.h +++ b/engines/sword25/fmv/oggtheora/audiobuffer.h @@ -39,30 +39,32 @@ // Includes // ----------------------------------------------------------------------------- +#include "common/queue.h" #include "sword25/kernel/common.h" +namespace Sword25 { + // ----------------------------------------------------------------------------- -// Klassendefinition +// Class definitions // ----------------------------------------------------------------------------- -class BS_AudioBuffer -{ +class AudioBuffer { public: - BS_AudioBuffer(); - virtual ~BS_AudioBuffer(); + AudioBuffer(); + virtual ~AudioBuffer(); - void Push(signed short * SamplePtr, unsigned int SampleCount); - unsigned int Pop(signed short * SamplePtr, unsigned int SampleCount); + void Push(signed short *SamplePtr, unsigned int SampleCount); + unsigned int Pop(signed short *SamplePtr, unsigned int SampleCount); unsigned int Size() const; private: - // PIMPL Pattern - struct Impl; - Impl * t; + Common::Queue _buffer; // Kopie verbieten - BS_AudioBuffer(const BS_AudioBuffer &); - const BS_AudioBuffer & operator=(const BS_AudioBuffer &); + AudioBuffer(const AudioBuffer &); + const AudioBuffer & operator=(const AudioBuffer &); }; +} // End of namespace Sword25 + #endif diff --git a/engines/sword25/fmv/oggtheora/moviefile.cpp b/engines/sword25/fmv/oggtheora/moviefile.cpp index b764ab2d22..33c214a1c2 100644 --- a/engines/sword25/fmv/oggtheora/moviefile.cpp +++ b/engines/sword25/fmv/oggtheora/moviefile.cpp @@ -47,42 +47,37 @@ #include "sword25/fmv/oggtheora/oggstate.h" #include "sword25/fmv/oggtheora/moviefile.h" +namespace Sword25 { + // ----------------------------------------------------------------------------- -BS_MovieFile::BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success) : - m_Data(0), m_Size(0), m_ReadPos(0), m_ReadBlockSize(ReadBlockSize) -{ - m_Data = reinterpret_cast(BS_Kernel::GetInstance()->GetPackage()->GetFile(Filename, &m_Size)); - if (!m_Data) - { +MovieFile::MovieFile(const Common::String &Filename, unsigned int ReadBlockSize, bool &Success) : + m_Data(0), m_Size(0), m_ReadPos(0), m_ReadBlockSize(ReadBlockSize) { + m_Data = reinterpret_cast(Kernel::GetInstance()->GetPackage()->GetFile(Filename, &m_Size)); + if (!m_Data) { BS_LOG_ERRORLN("Could not load movie file \"%s\".", Filename.c_str()); Success = false; - } - else + } else Success = true; } // ----------------------------------------------------------------------------- -BS_MovieFile::~BS_MovieFile() -{ +MovieFile::~MovieFile() { if (m_Data) delete [] m_Data; } // ----------------------------------------------------------------------------- -int BS_MovieFile::BufferData(BS_OggState & OggState) -{ - if (!m_Data || !m_Size || m_ReadPos >= m_Size) - { +int MovieFile::BufferData(OggState &OggState) { + if (!m_Data || !m_Size || m_ReadPos >= m_Size) { BS_LOG_ERRORLN("Tried to read past the movie buffer's end."); return 0; } // just grab some more compressed bitstream and sync it for page extraction - char * Buffer = OggState.SyncBuffer(m_ReadBlockSize); - if (!Buffer) - { + char *Buffer = OggState.SyncBuffer(m_ReadBlockSize); + if (!Buffer) { BS_LOG_ERRORLN("ogg_sync_buffer() failed."); return 0; } @@ -99,7 +94,8 @@ int BS_MovieFile::BufferData(BS_OggState & OggState) // ----------------------------------------------------------------------------- -bool BS_MovieFile::IsEOF() const -{ +bool MovieFile::IsEOF() const { return m_ReadPos >= m_Size; } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/moviefile.h b/engines/sword25/fmv/oggtheora/moviefile.h index 5aa0ef5617..bdae585d73 100644 --- a/engines/sword25/fmv/oggtheora/moviefile.h +++ b/engines/sword25/fmv/oggtheora/moviefile.h @@ -41,25 +41,22 @@ #include "sword25/kernel/common.h" -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" +namespace Sword25 { // ----------------------------------------------------------------------------- -class BS_OggState; +class OggState; // ----------------------------------------------------------------------------- // Klassendefinition // ----------------------------------------------------------------------------- -class BS_MovieFile -{ +class MovieFile { public: - BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success); - virtual ~BS_MovieFile(); + MovieFile(const Common::String &Filename, unsigned int ReadBlockSize, bool &Success); + virtual ~MovieFile(); - int BufferData(BS_OggState & OggState); + int BufferData(OggState &OggState); bool IsEOF() const; private: @@ -69,4 +66,6 @@ private: unsigned int m_ReadBlockSize; }; +} // End of namespace Sword25 + #endif diff --git a/engines/sword25/fmv/oggtheora/oggstate.cpp b/engines/sword25/fmv/oggtheora/oggstate.cpp index 11788ce53b..750fe382d4 100644 --- a/engines/sword25/fmv/oggtheora/oggstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstate.cpp @@ -38,37 +38,36 @@ #include "sword25/fmv/oggtheora/oggstate.h" +namespace Sword25 { + // ----------------------------------------------------------------------------- -BS_OggState::BS_OggState() -{ +OggState::OggState() { ogg_sync_init(&m_SyncState); } // ----------------------------------------------------------------------------- -BS_OggState::~BS_OggState() -{ +OggState::~OggState() { ogg_sync_clear(&m_SyncState); } // ----------------------------------------------------------------------------- -int BS_OggState::SyncPageout(ogg_page * OggPage) -{ +int OggState::SyncPageout(ogg_page *OggPage) { return ogg_sync_pageout(&m_SyncState, OggPage); } // ----------------------------------------------------------------------------- -char * BS_OggState::SyncBuffer(long Size) -{ +char *OggState::SyncBuffer(long Size) { return ogg_sync_buffer(&m_SyncState, Size); } // ----------------------------------------------------------------------------- -int BS_OggState::SyncWrote(long Bytes) -{ +int OggState::SyncWrote(long Bytes) { return ogg_sync_wrote(&m_SyncState, Bytes); } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/oggstate.h b/engines/sword25/fmv/oggtheora/oggstate.h index 1c25ca5e3a..7df178b681 100644 --- a/engines/sword25/fmv/oggtheora/oggstate.h +++ b/engines/sword25/fmv/oggtheora/oggstate.h @@ -40,39 +40,37 @@ // ----------------------------------------------------------------------------- #include "sword25/kernel/common.h" -#include "ogg/ogg.h" -// XXX -#include -// XXX +#include + +namespace Sword25 { // ----------------------------------------------------------------------------- -// Klassendefinition +// Class definitions // ----------------------------------------------------------------------------- -class BS_OggState -{ +class OggState { public: - BS_OggState(); - virtual ~BS_OggState(); + OggState(); + virtual ~OggState(); - int SyncPageout(ogg_page * OggPage); + int SyncPageout(ogg_page *OggPage); char * SyncBuffer(long Size); int SyncWrote(long Bytes); // XXX - void DumpInternals() - { - std::cout << "bodybytes: " << m_SyncState.bodybytes << std::endl; - std::cout << "fill: " << m_SyncState.fill << std::endl; - std::cout << "headerbytes: " << m_SyncState.headerbytes << std::endl; - std::cout << "returned: " << m_SyncState.returned << std::endl; - std::cout << "storage: " << m_SyncState.storage << std::endl; - std::cout << "unsynched: " << m_SyncState.unsynced << std::endl; - std::cout << std::endl; + void DumpInternals() { + warning("bodybytes: %d", m_SyncState.bodybytes); + warning("fill: %d", m_SyncState.fill); + warning("headerbytes: %d", m_SyncState.headerbytes ); + warning("returned: %d", m_SyncState.returned ); + warning("storage: %d", m_SyncState.storage ); + warning("unsynched: %d", m_SyncState.unsynced ); } // XXX private: ogg_sync_state m_SyncState; }; +} // End of namespace Sword25 + #endif diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp index d787a96af2..70388cf2b1 100644 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp @@ -38,22 +38,21 @@ #include "sword25/fmv/oggtheora/oggstreamstate.h" +namespace Sword25 { + // ----------------------------------------------------------------------------- -BS_OggStreamState::BS_OggStreamState(int SerialNo) -{ +OggStreamState::OggStreamState(int SerialNo) { ogg_stream_init(&m_State, SerialNo); } // ----------------------------------------------------------------------------- -BS_OggStreamState::~BS_OggStreamState() -{ +OggStreamState::~OggStreamState() { ogg_stream_clear(&m_State); // Alle gepufferten Pages löschen. - while (!m_PageBuffer.empty()) - { + while (!m_PageBuffer.empty()) { delete [] m_PageBuffer.front().header; delete [] m_PageBuffer.front().body; m_PageBuffer.pop(); @@ -62,24 +61,20 @@ BS_OggStreamState::~BS_OggStreamState() // ----------------------------------------------------------------------------- -int BS_OggStreamState::PageIn(ogg_page * PagePtr) -{ +int OggStreamState::PageIn(ogg_page *PagePtr) { return ogg_stream_pagein(&m_State, PagePtr); } // ----------------------------------------------------------------------------- -int BS_OggStreamState::PacketOut(ogg_packet * PacketPtr) -{ +int OggStreamState::PacketOut(ogg_packet *PacketPtr) { return ogg_stream_packetout(&m_State, PacketPtr); } // ----------------------------------------------------------------------------- -void BS_OggStreamState::BufferPage(ogg_page * PagePtr) -{ - if (PageBelongsToStream(PagePtr)) - { +void OggStreamState::BufferPage(ogg_page *PagePtr) { + if (PageBelongsToStream(PagePtr)) { // Pages können nicht direkt gespeichert werden, da die Pointer im Laufe der Zeit ungültig werden. // Daher wird an dieser Stelle eine tiefe Kopie der Page im erzeugt und im Pagebuffer angelegt. ogg_page PageCopy; @@ -96,10 +91,8 @@ void BS_OggStreamState::BufferPage(ogg_page * PagePtr) // ----------------------------------------------------------------------------- -int BS_OggStreamState::PageInBufferedPage() -{ - if (GetPageBufferSize() > 0) - { +int OggStreamState::PageInBufferedPage() { + if (GetPageBufferSize() > 0) { // Page in den Stream einfügen, löschen und aus dem Puffer entfernen. int Result = PageIn(&m_PageBuffer.front()); delete [] m_PageBuffer.front().header; @@ -113,21 +106,20 @@ int BS_OggStreamState::PageInBufferedPage() // ----------------------------------------------------------------------------- -unsigned int BS_OggStreamState::GetPageBufferSize() const -{ +unsigned int OggStreamState::GetPageBufferSize() const { return m_PageBuffer.size(); } // ----------------------------------------------------------------------------- -unsigned int BS_OggStreamState::GetUnprocessedBytes() const -{ +unsigned int OggStreamState::GetUnprocessedBytes() const { return m_State.body_fill - m_State.body_returned; } // ----------------------------------------------------------------------------- -bool BS_OggStreamState::PageBelongsToStream(ogg_page * PagePtr) const -{ +bool OggStreamState::PageBelongsToStream(ogg_page *PagePtr) const { return m_State.serialno == ogg_page_serialno(PagePtr); } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.h b/engines/sword25/fmv/oggtheora/oggstreamstate.h index 7e291bd107..3ed845c51d 100644 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.h +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.h @@ -40,50 +40,46 @@ // ----------------------------------------------------------------------------- #include "sword25/kernel/common.h" -#include "ogg/ogg.h" -#include -// XXX -#include -// XXX +#include +#include "common/queue.h" + +namespace Sword25 { // ----------------------------------------------------------------------------- -// Klassendefinition +// Class definitions // ----------------------------------------------------------------------------- -class BS_OggStreamState -{ +class OggStreamState { public: - BS_OggStreamState(int SerialNo); - virtual ~BS_OggStreamState(); + OggStreamState(int SerialNo); + virtual ~OggStreamState(); - int PageIn(ogg_page * PagePtr); - int PacketOut(ogg_packet * PacketPtr); + int PageIn(ogg_page *PagePtr); + int PacketOut(ogg_packet *PacketPtr); - void BufferPage(ogg_page * PagePtr); + void BufferPage(ogg_page *PagePtr); int PageInBufferedPage(); unsigned int GetPageBufferSize() const; unsigned int GetUnprocessedBytes() const; - bool PageBelongsToStream(ogg_page * PagePtr) const; + bool PageBelongsToStream(ogg_page *PagePtr) const; // XXX - void DumpInternals() - { - using namespace std; - - cout << "body_storage: " << m_State.body_storage << endl; - cout << "body_fill: " << m_State.body_fill << endl; - cout << "body_returned: " << m_State.body_returned << endl; - cout << "lacing_storage: " << m_State.lacing_storage << endl; - cout << "lacing_fill: " << m_State.lacing_fill << endl; - cout << "lacing_returned: " << m_State.lacing_returned << endl; - cout << endl; + void DumpInternals() { + warning("body_storage: %d", m_State.body_storage); + warning("body_fill: %d", m_State.body_fill); + warning("body_returned: %d", m_State.body_returned); + warning("lacing_storage: %d", m_State.lacing_storage); + warning("lacing_fill: %d", m_State.lacing_fill); + warning("lacing_returned: %d", m_State.lacing_returned); } // XXX private: ogg_stream_state m_State; - std::queue m_PageBuffer; + Common::Queue m_PageBuffer; }; +} // End of namespace Sword25 + #endif diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp deleted file mode 100644 index 9d6eaa0baf..0000000000 --- a/engines/sword25/fmv/oggtheora/oggtheora.cpp +++ /dev/null @@ -1,723 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// The code in this file is based in part on code from the OggTheora Software -// codec source released under the following terms: -// -// Copyright (C) 2002-2007 Xiph.org Foundation -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// - Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// - Neither the name of the Xiph.org Foundation nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION -// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// ----------------------------------------------------------------------------- -// Logging -// ----------------------------------------------------------------------------- - -#define BS_LOG_PREFIX "OGGTHEORA" - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" -#include - -#include "sword25/package/packagemanager.h" -#include "sword25/sfx/soundengine.h" -#include "sword25/gfx/graphicengine.h" -#include "sword25/gfx/panel.h" -#include "sword25/fmv/oggtheora/oggtheora.h" -#include "sword25/fmv/oggtheora/yuvtorgba.h" - -using namespace std; - -// ----------------------------------------------------------------------------- -// Konstanten und Hilfsfunktionen -// ----------------------------------------------------------------------------- - -namespace -{ - // -------------------------------------------------------------------------- - - const int MAX_FRAMES_PER_TICK = 10; - const int READ_BLOCK_SIZE = 1024 * 40; - const float MAX_AUDIO_BUFFER_LENGTH = 1.0f; - - // -------------------------------------------------------------------------- - - template - inline T Clamp(T x, T low, T high) - { - return ((x > high) ? high : (( x < low) ? low : x)); - } -} - -// ----------------------------------------------------------------------------- -// Konstruktion / Destruktion -// ----------------------------------------------------------------------------- - -BS_OggTheora::BS_OggTheora(BS_Kernel * pKernel) : BS_MoviePlayer(pKernel), m_SoundHandle(0) -{ - UnloadMovie(); -} - -// ----------------------------------------------------------------------------- - -BS_OggTheora::~BS_OggTheora() -{ - UnloadMovie(); -} - -// ----------------------------------------------------------------------------- - -BS_Service * BS_OggTheora_CreateObject(BS_Kernel* pKernel) { return new BS_OggTheora(pKernel); } - -// ----------------------------------------------------------------------------- -// BS_MoviePlayer Interface -// ----------------------------------------------------------------------------- - - -// ----------------------------------------------------------------------------- -// LoadMovie() mit Hilfsfunktionen -// ----------------------------------------------------------------------------- - -namespace -{ - inline bool VerifyRequiredServiceAvailability() - { - char * RequiredServices[] = { "gfx", "sfx", "package" }; - for (size_t i = 0; i < sizeof(RequiredServices) / sizeof(RequiredServices[0]); ++i) - { - if (!BS_Kernel::GetInstance()->GetService(RequiredServices[i])) - { - BS_LOG_ERRORLN("Required service \"%s\" is not active.", RequiredServices[i]); - return false; - } - } - - return true; - } - - // ------------------------------------------------------------------------- - - bool ParseStreamHeaders(auto_ptr & File, - auto_ptr & OggState, - auto_ptr & TheoraStreamState, - auto_ptr & VorbisStreamState, - auto_ptr & TheoraState, - auto_ptr & VorbisState, - bool & TheoraPresent, - bool & VorbisPresent, - const std::string & Filename) - { - TheoraPresent = false; - VorbisPresent = false; - - // Ogg file open; parse the headers - // Only interested in Vorbis/Theora streams - bool FinishedHeaderParsing = false; - while (!FinishedHeaderParsing) - { - if (File->BufferData(*OggState.get()) == 0) return false; - - ogg_page Page; - while(OggState->SyncPageout(&Page) > 0) - { - // is this a mandated initial header? If not, stop parsing - if(!ogg_page_bos(&Page)) - { - // don't leak the page; get it into the appropriate stream - if (TheoraPresent) TheoraStreamState->PageIn(&Page); - if (VorbisPresent) VorbisStreamState->PageIn(&Page); - - FinishedHeaderParsing = true; - break; - } - - auto_ptr streamState(new BS_OggStreamState(ogg_page_serialno(&Page))); - - streamState->PageIn(&Page); - - ogg_packet Packet; - streamState->PacketOut(&Packet); - - // identify the codec: try theora - if(!TheoraPresent && TheoraState->DecodeHeader(&Packet) >= 0) - { - // it is theora - TheoraStreamState = streamState; - TheoraPresent = true; - } - else if(!VorbisPresent && VorbisState->SynthesisHeaderIn(&Packet) >=0) - { - // it is vorbis - VorbisStreamState = streamState; - VorbisPresent = true; - } - } - // fall through to non-bos page parsing - } - - // we're expecting more header packets. - unsigned int TheoraPacketsRead = TheoraPresent ? 1 : 0; - unsigned int VorbisPacketsRead = VorbisPresent ? 1 : 0; - while((TheoraPresent && TheoraPacketsRead < 3) || (VorbisPresent && VorbisPacketsRead < 3)) - { - int ret; - ogg_packet Packet; - - // look for further theora headers - while(TheoraPresent && (TheoraPacketsRead < 3) && (ret = TheoraStreamState->PacketOut(&Packet))) - { - if(ret < 0 || TheoraState->DecodeHeader(&Packet)) - { - BS_LOG_ERRORLN("Error parsing Theora stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); - return false; - } - - ++TheoraPacketsRead; - if (TheoraPacketsRead == 3) break; - } - - // look for more vorbis header packets - while(VorbisPresent && (VorbisPacketsRead < 3) && (ret = VorbisStreamState->PacketOut(&Packet))) - { - if(ret < 0 || VorbisState->SynthesisHeaderIn(&Packet)) - { - BS_LOG_ERRORLN("Error parsing Vorbis stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); - return false; - } - - ++VorbisPacketsRead; - if (VorbisPacketsRead == 3) break; - } - - // The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec - ogg_page Page; - if(OggState->SyncPageout(&Page) > 0) - { - // demux into the appropriate stream - if(TheoraPresent) TheoraStreamState->PageIn(&Page); - if(VorbisPresent) VorbisStreamState->PageIn(&Page); - } - else - { - if(File->BufferData(*OggState.get()) == 0) - { - BS_LOG_ERRORLN("End of file while searching for codec headers. (%s)", Filename.c_str()); - return false; - } - } - } - - return true; - } -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::LoadMovie(const std::string & Filename, unsigned int Z) -{ - if (!VerifyRequiredServiceAvailability()) return false; - - UnloadMovie(); - - // Alle Objekte die in dieser Funktion erzeugt werden, werden in zunächst lokalen Auto-Pointern gehalten. - // Bei erfolgreicher Beendigung dieser Funktion werden sie den objektlokalen Auto-Pointern zugewiesen. - // So wird sichergestellt, dass sie korrekt deinitialisiert werden, wenn in dieser Funktion ein Fehler auftritt, denn beim Zerstören der - // lokalen Auto-Pointer werden die entsprechenden Destruktoren aufgerufen. - - // Film laden - // Für Filmdateien wird das Cachingsystem nicht benutzt, da Filme in der Regel nur ein Mal abgespielt werden. - bool Success; - auto_ptr File(new BS_MovieFile(Filename, READ_BLOCK_SIZE, Success)); - if (!Success) return false; - - // States erzeugen für Ogg, Vorbis und Theora, sowie die Ogg und Theora Streams - auto_ptr OggState(new BS_OggState()); - auto_ptr VorbisState(new BS_VorbisState()); - auto_ptr TheoraState(new BS_TheoraState()); - - auto_ptr TheoraStreamState; - auto_ptr VorbisStreamState; - - if (!ParseStreamHeaders(File, OggState, TheoraStreamState, VorbisStreamState, TheoraState, VorbisState, m_TheoraPresent, m_VorbisPresent, Filename)) return false; - - // Theora-Decoder Initialisieren - if(m_TheoraPresent) - { - TheoraState->DecodeInit(); - - const theora_info & TheoraInfo = TheoraState->GetInfo(); - - if (TheoraInfo.pixelformat != OC_PF_444 && - TheoraInfo.pixelformat != OC_PF_422 && - TheoraInfo.pixelformat != OC_PF_420) - { - BS_LOG_ERRORLN("Unknown chroma sampling. (%s)", Filename.c_str()); - return false; - } - - // Ausgabebitmap erstellen - BS_GraphicEngine * pGfx = BS_Kernel::GetInstance()->GetGfx(); - m_OutputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(TheoraInfo.frame_width, TheoraInfo.frame_height); - if (!m_OutputBitmap.IsValid()) - { - BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); - return false; - } - - // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. - float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); - float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); - float ScaleFactor = std::min(ScreenToVideoWidth, ScreenToVideoHeight); - if (ABS(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; - m_OutputBitmap->SetScaleFactor(ScaleFactor); - - // Z-Wert setzen - m_OutputBitmap->SetZ(Z); - - // Ausgabebitmap auf dem Bildschirm zentrieren - m_OutputBitmap->SetX((pGfx->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); - m_OutputBitmap->SetY((pGfx->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); - - // Buffer für die Pixeldaten erstellen - m_Pixels.resize(TheoraInfo.width * TheoraInfo.height * 4); - - m_VideoEnded = false; - } - - // Vorbis-Decoder initialisieren - if(m_VorbisPresent) - { - VorbisState->SynthesisInit(); - VorbisState->BlockInit(); - m_AudioBuffer.reset(new BS_AudioBuffer()); - - m_AudioEnded = false; - } - - // Keine Kopie, überträgt Besitz der erzeugten Objekte von der Funktion auf das Objekt. - m_File = File; - m_OggState = OggState; - m_TheoraState = TheoraState; - m_TheoraStreamState = TheoraStreamState; - m_VorbisState = VorbisState; - m_VorbisStreamState = VorbisStreamState; - m_MovieLoaded = true; - m_Timer = 0; - - return true; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::UnloadMovie() -{ - m_MovieLoaded = false; - m_Paused = true; - - m_VorbisStreamState.reset(); - m_VorbisPresent = false; - m_VorbisState.reset(); - if (m_SoundHandle) - { - BS_Kernel::GetInstance()->GetSfx()->StopSound(m_SoundHandle); - m_SoundHandle = 0; - } - m_AudioEnded = true; - m_AudioBuffer.reset(); - - m_TheoraStreamState.reset(); - m_TheoraPresent = false; - m_TheoraState.reset(); - m_VideoEnded = true; - - m_OggState.reset(); - - m_File.reset(); - - m_StartTime = 0; - m_LastFrameTime = 0; - m_Timer = 0.0f; - - vector().swap(m_Pixels); - m_OutputBitmap.Erase(); - - return true; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::Play() -{ - if (m_MovieLoaded) - { - if (m_Paused) - { - if (m_SoundHandle) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - SfxPtr->ResumeSound(m_SoundHandle); - } - m_Paused = false; - } - - return true; - } - else - { - BS_LOG_WARNINGLN("Cannot play movie, when no movie is loaded."); - return false; - } -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::Pause() -{ - if (m_MovieLoaded) - { - if (m_SoundHandle) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - SfxPtr->PauseSound(m_SoundHandle); - } - - m_Paused = true; - return true; - } - else - { - BS_LOG_WARNINGLN("Cannot pause movie, when no movie is loaded."); - return false; - } -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::ReadData() -{ - if (!m_File->IsEOF()) m_File->BufferData(*m_OggState.get()); - - ogg_page Page; - while(m_OggState->SyncPageout(&Page) > 0) - { - if(m_TheoraPresent) m_TheoraStreamState->BufferPage(&Page); - if(m_VorbisPresent) m_VorbisStreamState->BufferPage(&Page); - } -} - -void BS_OggTheora::Update() -{ - if (m_AudioEnded && m_VideoEnded) - { - m_Paused = true; - - // Falls der Sound noch läuft, muss er jetzt beendet werden. - if (m_SoundHandle) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - SfxPtr->StopSound(m_SoundHandle); - m_SoundHandle = 0; - } - } - - if (m_Paused) return; - - // Timer aktualisieren. - // Wird nur genutzt, wenn keine Audiodaten vorhanden sind. - m_Timer += BS_Kernel::GetInstance()->GetGfx()->GetSecondaryFrameDuration(); - - // Audiodaten dekodieren - if (m_VorbisPresent && !m_AudioEnded) DecodeVorbis(); - - - // Videodaten dekodieren - if (m_TheoraPresent && !m_VideoEnded) - { - bool Result = DecodeTheora(); - - if (Result) - { - // YUV Framebuffer holen - yuv_buffer YUVBuffer; - m_TheoraState->DecodeYUVOut(&YUVBuffer); - - // YUV Bilddaten nach RGBA konvertieren - BS_YUVtoRGBA::YUVtoRGBA(YUVBuffer, m_TheoraState->GetInfo(), m_Pixels); - - // RGBA Bilddaten auf das Ausgabebild kopieren, dabei die Postion des Theoraframes innerhalb des dekodierten Frames beachten. - const theora_info & TheoraInfo = m_TheoraState->GetInfo(); - m_OutputBitmap->SetContent(m_Pixels, (TheoraInfo.offset_x + TheoraInfo.width * TheoraInfo.offset_y) * 4, (TheoraInfo.width - TheoraInfo.frame_width) * 4); - } - } -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::DecodeTheora() -{ - double MovieTime = GetTime(); - - // Check if this frame time has not passed yet. If the frame is late we need - // to decode additonal ones and keep looping, since theora at this stage - // needs to decode all frames (due to keyframing) - // Getting the current time once at the beginning of the function rather than - // every time at the beginning of the loop produces the smoothest framerate - - unsigned int FramesDecoded = 0; - bool FrameReady = false; - while (m_TheoraState->GranuleTime() < MovieTime) - { - // theora is one in, one out... - ogg_packet Packet; - if(m_TheoraStreamState->PacketOut(&Packet) > 0) - { - if (FramesDecoded < MAX_FRAMES_PER_TICK || Packet.granulepos >= MovieTime) - { - m_TheoraState->DecodePacketIn(&Packet); - FrameReady = true; - ++FramesDecoded; - } - } - else - { - if (m_TheoraStreamState->GetPageBufferSize() > 0) - m_TheoraStreamState->PageInBufferedPage(); - else - { - if(m_File->IsEOF()) - { - m_VideoEnded = true; - break; - } - else - ReadData(); - } - } - } - m_LastFrameTime = MovieTime; - - return FrameReady; -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength) -{ - BS_OggTheora & t = *reinterpret_cast(UserData); - - signed short * Buffer = reinterpret_cast(Data); - - // Audiodaten in den Soundbuffer schreiben. - DataLength -= t.m_AudioBuffer->Pop(Buffer, DataLength / 2) * 2; - - // Falls nicht genug Audiodaten vorhanden waren, wird der Rest mit Stille überschrieben. - if (DataLength) - { - char * ByteBuffer = reinterpret_cast(Buffer); - while (DataLength--) - { - *ByteBuffer++ = 0; - } - } -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::DecodeVorbis() -{ - // Vorbis-Stream Infos holen. - const vorbis_info & Info = m_VorbisState->GetInfo(); - - // Maximalgröße des Audiobuffers berechnen. - size_t MaxAudioBufferSamples = static_cast(Info.channels * Info.rate * MAX_AUDIO_BUFFER_LENGTH); - - // Zwischenspeicher für die Samples. - vector Samples; - - // Audiobuffer bis zur Maximalgröße füllen, wenn möglich. - while (m_AudioBuffer->Size() < MaxAudioBufferSamples) - { - // Vorhandene Audiodaten auslesen - float ** PCM; - int SampleCount = m_VorbisState->SynthesisPCMout(&PCM); - - // Wenn Audiodaten gelesen werden konnten, werden diese in 16-Bit Sample umgewandelt und in den Audiobuffer geschrieben. - if(SampleCount > 0) - { - // Im Samplezwischenspeicher leeren und genügend Platz für die kommenden Samples reservieren. - Samples.reserve(SampleCount); - Samples.clear(); - - // Samples konvertieren und in die Samplezwischenspeicher schreiben. - for (int i = 0; i < SampleCount; ++i) - { - for(int j = 0; j < Info.channels; ++j) - { - int SampleValue = static_cast(PCM[j][i] * 32767.0f); - Samples.push_back(Clamp(SampleValue, -32700, 32700)); - } - } - - // Daten aus dem Samplezwischenspeicher in den Audiobuffer schreiben. - m_AudioBuffer->Push(&Samples[0], Samples.size()); - - // Vorbis mitteilen, dass wir alle Samples gelesen haben. - m_VorbisState->SynthesisRead(SampleCount); - } - else - { - // Wir konnten, keine Audiodaten auslesen, versuchen ein neues Paket zu dekodieren. - ogg_packet Packet; - if(m_VorbisStreamState->PacketOut(&Packet) > 0) - { - if (m_VorbisState->Synthesis(&Packet) == 0) m_VorbisState->SynthesisBlockIn(); - } - else - { - // Gepufferte Daten in den Stream einfügen. - if (m_VorbisStreamState->GetPageBufferSize() > 0) - m_VorbisStreamState->PageInBufferedPage(); - else - { - // Nicht genug Daten vorhanden. Wenn die Datei leer ist und bereits alle Audiodaten gelesen wurden, ist der Audiostream am Ende. - // Ansonsten Daten nachladen. - if(m_File->IsEOF()) - { - if (m_AudioBuffer->Size() == 0) - { - m_AudioEnded = true; - } - - break; - } - else - ReadData(); - } - } - } - } - - // Soundkanal abspielen, wenn er noch nicht spielt und Audiodaten vorhanden sind. - if (m_SoundHandle == 0 && m_AudioBuffer->Size()) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - m_SoundHandle = SfxPtr->PlayDynamicSoundEx(&DynamicSoundCallBack, this, BS_SoundEngine::SFX, Info.rate, 16, Info.channels); - } -} - -// ----------------------------------------------------------------------------- - -double BS_OggTheora::GetTime() -{ - if(m_VorbisPresent) - { - if (m_SoundHandle) - { - float time = BS_Kernel::GetInstance()->GetSfx()->GetSoundTime(m_SoundHandle); - return time; - } - else - return 0.0f; - } - else - return m_Timer; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::IsMovieLoaded() -{ - return m_MovieLoaded; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::IsPaused() -{ - return m_Paused; -} - -// ----------------------------------------------------------------------------- - -float BS_OggTheora::GetScaleFactor() -{ - if (m_MovieLoaded) - return m_OutputBitmap->GetScaleFactorX(); - else - return 0; -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::SetScaleFactor(float ScaleFactor) -{ - if (m_MovieLoaded) - { - m_OutputBitmap->SetScaleFactor(ScaleFactor); - - // Ausgabebitmap auf dem Bildschirm zentrieren - BS_GraphicEngine * GfxPtr = BS_Kernel::GetInstance()->GetGfx(); - m_OutputBitmap->SetX((GfxPtr->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); - m_OutputBitmap->SetY((GfxPtr->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); - } -} diff --git a/engines/sword25/fmv/oggtheora/oggtheora.h b/engines/sword25/fmv/oggtheora/oggtheora.h deleted file mode 100644 index 62fa607935..0000000000 --- a/engines/sword25/fmv/oggtheora/oggtheora.h +++ /dev/null @@ -1,124 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_OGGTHEORA_H -#define SWORD25_OGGTHEORA_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/memlog_off.h" -#include -#include -#include -#include "sword25/kernel/memlog_on.h" - -#include "sword25/kernel/common.h" -#include "sword25/kernel/bs_stdint.h" -#include "sword25/gfx/bitmap.h" -#include "sword25/gfx/renderobjectptr.h" -#include "sword25/fmv/movieplayer.h" -#include "sword25/fmv/oggtheora/vorbisstate.h" -#include "sword25/fmv/oggtheora/theorastate.h" -#include "sword25/fmv/oggtheora/oggstate.h" -#include "sword25/fmv/oggtheora/oggstreamstate.h" -#include "sword25/fmv/oggtheora/moviefile.h" -#include "sword25/fmv/oggtheora/audiobuffer.h" - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_OggTheora : public BS_MoviePlayer -{ -public: - // ----------------------------------------------------------------------------- - // Konstruktion / Destruktion - // ----------------------------------------------------------------------------- - - BS_OggTheora(BS_Kernel * pKernel); - virtual ~BS_OggTheora(); - - // ----------------------------------------------------------------------------- - // BS_MoviePlayer Interface - // ----------------------------------------------------------------------------- - - virtual bool LoadMovie(const std::string & Filename, unsigned int Z); - virtual bool UnloadMovie(); - virtual bool Play(); - virtual bool Pause(); - virtual void Update(); - virtual bool IsMovieLoaded(); - virtual bool IsPaused(); - virtual float GetScaleFactor(); - virtual void SetScaleFactor(float ScaleFactor); - virtual double GetTime(); - -private: - bool DecodeTheora(); - void DecodeVorbis(); - void RefillOggBuffer(); - void ReadData(); - static void DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength); - - bool m_MovieLoaded; - bool m_Paused; - - std::auto_ptr m_VorbisStreamState; - bool m_VorbisPresent; - std::auto_ptr m_VorbisState; - unsigned int m_SoundHandle; - bool m_AudioEnded; - std::auto_ptr m_AudioBuffer; - - std::auto_ptr m_TheoraStreamState; - bool m_TheoraPresent; - std::auto_ptr m_TheoraState; - bool m_VideoEnded; - - std::auto_ptr m_OggState; - - std::auto_ptr m_File; - - uint64_t m_StartTime; - double m_LastFrameTime; - - float m_Timer; - - std::vector m_Pixels; - BS_RenderObjectPtr m_OutputBitmap; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/theorastate.cpp b/engines/sword25/fmv/oggtheora/theorastate.cpp index a270bab80c..2284098d2f 100644 --- a/engines/sword25/fmv/oggtheora/theorastate.cpp +++ b/engines/sword25/fmv/oggtheora/theorastate.cpp @@ -38,19 +38,19 @@ #include "sword25/fmv/oggtheora/theorastate.h" +namespace Sword25 { + // ----------------------------------------------------------------------------- -BS_TheoraState::BS_TheoraState() : - m_StateInitialized(false) -{ +TheoraState::TheoraState() : + m_StateInitialized(false) { theora_comment_init(&m_Comment); theora_info_init(&m_Info); } // ----------------------------------------------------------------------------- -BS_TheoraState::~BS_TheoraState() -{ +TheoraState::~TheoraState() { if (m_StateInitialized) theora_clear(&m_State); theora_info_clear(&m_Info); theora_comment_clear(&m_Comment); @@ -58,15 +58,13 @@ BS_TheoraState::~BS_TheoraState() // ----------------------------------------------------------------------------- -int BS_TheoraState::DecodeHeader(ogg_packet * OggPacketPtr) -{ +int TheoraState::DecodeHeader(ogg_packet *OggPacketPtr) { return theora_decode_header(&m_Info, &m_Comment, OggPacketPtr); } // ----------------------------------------------------------------------------- -int BS_TheoraState::DecodeInit() -{ +int TheoraState::DecodeInit() { int Result = theora_decode_init(&m_State, &m_Info); m_StateInitialized = (Result == 0); return Result; @@ -74,21 +72,20 @@ int BS_TheoraState::DecodeInit() // ----------------------------------------------------------------------------- -double BS_TheoraState::GranuleTime() -{ +double TheoraState::GranuleTime() { return theora_granule_time(&m_State, m_State.granulepos); } // ----------------------------------------------------------------------------- -int BS_TheoraState::DecodePacketIn(ogg_packet * OggPacketPtr) -{ +int TheoraState::DecodePacketIn(ogg_packet *OggPacketPtr) { return theora_decode_packetin(&m_State, OggPacketPtr); } // ----------------------------------------------------------------------------- -int BS_TheoraState::DecodeYUVOut(yuv_buffer * YUV) -{ +int TheoraState::DecodeYUVOut(yuv_buffer *YUV) { return theora_decode_YUVout(&m_State, YUV); } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/theorastate.h b/engines/sword25/fmv/oggtheora/theorastate.h index 07934c26ea..967ca259ad 100644 --- a/engines/sword25/fmv/oggtheora/theorastate.h +++ b/engines/sword25/fmv/oggtheora/theorastate.h @@ -42,20 +42,21 @@ #include "sword25/kernel/common.h" #include +namespace Sword25 { + // ----------------------------------------------------------------------------- -// Klassendefinition +// Class definitions // ----------------------------------------------------------------------------- -class BS_TheoraState -{ +class TheoraState { public: - BS_TheoraState(); - virtual ~BS_TheoraState(); + TheoraState(); + virtual ~TheoraState(); - int DecodeHeader(ogg_packet * OggPacketPtr); + int DecodeHeader(ogg_packet *OggPacketPtr); int DecodeInit(); - int DecodePacketIn(ogg_packet * OggPacketPtr); - int DecodeYUVOut(yuv_buffer * YUV); + int DecodePacketIn(ogg_packet *OggPacketPtr); + int DecodeYUVOut(yuv_buffer *YUV); double GranuleTime(); const theora_info & GetInfo() const { return m_Info; } @@ -67,4 +68,6 @@ private: theora_state m_State; }; +} // End of namespace Sword25 + #endif diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.cpp b/engines/sword25/fmv/oggtheora/vorbisstate.cpp index e9f6b7dc4f..53085a9832 100644 --- a/engines/sword25/fmv/oggtheora/vorbisstate.cpp +++ b/engines/sword25/fmv/oggtheora/vorbisstate.cpp @@ -38,20 +38,20 @@ #include "sword25/fmv/oggtheora/vorbisstate.h" +namespace Sword25 { + // ----------------------------------------------------------------------------- -BS_VorbisState::BS_VorbisState() : - m_DSPStateInitialized(false), - m_BlockInitialized(false) -{ +VorbisState::VorbisState() : + m_DSPStateInitialized(false), + m_BlockInitialized(false) { vorbis_info_init(&m_Info); vorbis_comment_init(&m_Comment); } // ----------------------------------------------------------------------------- -BS_VorbisState::~BS_VorbisState() -{ +VorbisState::~VorbisState() { if (m_BlockInitialized) vorbis_block_clear(&m_Block); if (m_DSPStateInitialized) vorbis_dsp_clear(&m_DSPState); vorbis_comment_clear(&m_Comment); @@ -60,15 +60,13 @@ BS_VorbisState::~BS_VorbisState() // ----------------------------------------------------------------------------- -int BS_VorbisState::SynthesisHeaderIn(ogg_packet * OggPacketPtr) -{ +int VorbisState::SynthesisHeaderIn(ogg_packet *OggPacketPtr) { return vorbis_synthesis_headerin(&m_Info, &m_Comment, OggPacketPtr); } // ----------------------------------------------------------------------------- -int BS_VorbisState::SynthesisInit() -{ +int VorbisState::SynthesisInit() { int Result = vorbis_synthesis_init(&m_DSPState, &m_Info); m_DSPStateInitialized = (Result == 0); return Result; @@ -76,8 +74,7 @@ int BS_VorbisState::SynthesisInit() // ----------------------------------------------------------------------------- -int BS_VorbisState::BlockInit() -{ +int VorbisState::BlockInit() { int Result = vorbis_block_init(&m_DSPState, &m_Block); m_BlockInitialized = (Result == 0); return Result; @@ -85,28 +82,26 @@ int BS_VorbisState::BlockInit() // ----------------------------------------------------------------------------- -int BS_VorbisState::SynthesisPCMout(float *** PCM) -{ +int VorbisState::SynthesisPCMout(float ***PCM) { return vorbis_synthesis_pcmout(&m_DSPState, PCM); } // ----------------------------------------------------------------------------- -int BS_VorbisState::SynthesisRead(int Samples) -{ +int VorbisState::SynthesisRead(int Samples) { return vorbis_synthesis_read(&m_DSPState, Samples); } // ----------------------------------------------------------------------------- -int BS_VorbisState::Synthesis(ogg_packet * OggPacketPtr) -{ +int VorbisState::Synthesis(ogg_packet *OggPacketPtr) { return vorbis_synthesis(&m_Block, OggPacketPtr); } // ----------------------------------------------------------------------------- -int BS_VorbisState::SynthesisBlockIn() -{ +int VorbisState::SynthesisBlockIn() { return vorbis_synthesis_blockin(&m_DSPState, &m_Block); } + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.h b/engines/sword25/fmv/oggtheora/vorbisstate.h index 126e59d0aa..4a87f13d9e 100644 --- a/engines/sword25/fmv/oggtheora/vorbisstate.h +++ b/engines/sword25/fmv/oggtheora/vorbisstate.h @@ -42,25 +42,26 @@ #include "sword25/kernel/common.h" #include +namespace Sword25 { + // ----------------------------------------------------------------------------- -// Klassendefinition +// Class definitions // ----------------------------------------------------------------------------- -class BS_VorbisState -{ +class VorbisState { public: - BS_VorbisState(); - virtual ~BS_VorbisState(); + VorbisState(); + virtual ~VorbisState(); - int SynthesisHeaderIn(ogg_packet * OggPacketPtr); + int SynthesisHeaderIn(ogg_packet *OggPacketPtr); int SynthesisInit(); int BlockInit(); - int SynthesisPCMout(float *** PCM); + int SynthesisPCMout(float ***PCM); int SynthesisRead(int Samples); - int Synthesis(ogg_packet * OggPacketPtr); + int Synthesis(ogg_packet *OggPacketPtr); int SynthesisBlockIn(); - const vorbis_info & GetInfo() const { return m_Info; } + const vorbis_info &GetInfo() const { return m_Info; } private: vorbis_info m_Info; @@ -71,4 +72,6 @@ private: vorbis_comment m_Comment; }; +} // End of namespace Sword25 + #endif diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp index d835d2ba0b..2c950745f1 100644 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp @@ -36,396 +36,213 @@ // Includes // ----------------------------------------------------------------------------- -#include "sword25/kernel/cpuinfo.h" -#include "sword25/fmv/ogghteora/yuvtorgba.h" - -#include - -using namespace std; +#include "sword25/fmv/oggtheora/yuvtorgba.h" // ----------------------------------------------------------------------------- -namespace -{ - - static const int PRECISION = 32768; - static const int COEFFS_Y[256] = { - -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, - 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, - 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, - 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, - 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, - 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, - 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, - 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, - 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, - 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, - 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, - 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, - 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, - 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, - 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, - 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, - }; - static const int COEFFS_RV[256] = { - -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, - -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, - -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, - -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, - -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, - -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, - -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, - -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, - 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, - 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, - 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, - 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, - 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, - 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, - 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, - 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, - }; - static const int COEFFS_GU[256] = { - 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, - 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, - 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, - 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, - 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, - 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, - 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, - 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, - 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, - -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, - -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, - -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, - -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, - -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, - -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, - -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, - }; - static const int COEFFS_GV[256] = { - 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, - 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, - 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, - 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, - 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, - 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, - 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, - 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, - 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, - -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, - -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, - -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, - -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, - -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, - -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, - -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, - }; - static const int COEFFS_BU[256] = { - -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, - -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, - -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, - -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, - -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, - -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, - -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, - -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, - 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, - 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, - 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, - 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, - 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, - 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, - 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, - 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, - }; - static const int CLAMP_TAB[1024] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - }; - - void YUVtoRGBA_c(const yuv_buffer & YUVBuffer, std::vector & PixelData) - { - // Width and height of all buffers have to be divisible by 2. - BS_ASSERT((YUVBuffer.y_width & 1) == 0); - BS_ASSERT((YUVBuffer.y_height & 1) == 0); - BS_ASSERT((YUVBuffer.uv_width & 1) == 0); - BS_ASSERT((YUVBuffer.uv_height & 1) == 0); - // UV images have to have a quarter of the Y image resolution - BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); - BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); - - const int *cl = &CLAMP_TAB[320]; - - const unsigned char * ySrc0 = YUVBuffer.y; - const unsigned char * ySrc1 = YUVBuffer.y + YUVBuffer.y_stride; - const unsigned char * uSrc = YUVBuffer.u; - const unsigned char * vSrc = YUVBuffer.v; - unsigned char * dst0 = &PixelData[0]; - unsigned char * dst1 = &PixelData[0] + YUVBuffer.y_width * 4; - - for (int h = 0; h < YUVBuffer.y_height / 2; ++h) - { - for (int w = 0; w < YUVBuffer.y_width / 2; ++w) - { - int u = *uSrc++; - int v = *vSrc++; - - int rUV = COEFFS_RV[v]; - int gUV = COEFFS_GU[u] + COEFFS_GV[v]; - int bUV = COEFFS_BU[u]; - - int y = *ySrc0++; - int r = COEFFS_Y[y] + rUV; - int g = COEFFS_Y[y] + gUV; - int b = COEFFS_Y[y] + bUV; - *dst0++ = cl[r / PRECISION]; - *dst0++ = cl[g / PRECISION]; - *dst0++ = cl[b / PRECISION]; - *dst0++ = 255; - - y = *ySrc1++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst1++ = cl[r / PRECISION]; - *dst1++ = cl[g / PRECISION]; - *dst1++ = cl[b / PRECISION]; - *dst1++ = 255; - - y = *ySrc0++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst0++ = cl[r / PRECISION]; - *dst0++ = cl[g / PRECISION]; - *dst0++ = cl[b / PRECISION]; - *dst0++ = 255; - - y = *ySrc1++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst1++ = cl[r / PRECISION]; - *dst1++ = cl[g / PRECISION]; - *dst1++ = cl[b / PRECISION]; - *dst1++ = 255; - } - - dst0 += YUVBuffer.y_width * 4; - dst1 += YUVBuffer.y_width * 4; - ySrc0 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; - ySrc1 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; - uSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; - vSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; - } - } - - // ----------------------------------------------------------------------------- - - static const __m64 COEFF_Y_MMX[256] = { - 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, - 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, - 0x1fff000000000000, 0x1fff004a004a004a, 0x1fff009500950095, 0x1fff00df00df00df, 0x1fff012a012a012a, 0x1fff017401740174, 0x1fff01bf01bf01bf, 0x1fff020902090209, - 0x1fff025402540254, 0x1fff029e029e029e, 0x1fff02e902e902e9, 0x1fff033303330333, 0x1fff037e037e037e, 0x1fff03c803c803c8, 0x1fff041304130413, 0x1fff045d045d045d, - 0x1fff04a804a804a8, 0x1fff04f204f204f2, 0x1fff053d053d053d, 0x1fff058705870587, 0x1fff05d205d205d2, 0x1fff061c061c061c, 0x1fff066706670667, 0x1fff06b106b106b1, - 0x1fff06fc06fc06fc, 0x1fff074607460746, 0x1fff079107910791, 0x1fff07db07db07db, 0x1fff082608260826, 0x1fff087008700870, 0x1fff08bb08bb08bb, 0x1fff090509050905, - 0x1fff095009500950, 0x1fff099a099a099a, 0x1fff09e509e509e5, 0x1fff0a2f0a2f0a2f, 0x1fff0a7a0a7a0a7a, 0x1fff0ac40ac40ac4, 0x1fff0b0f0b0f0b0f, 0x1fff0b590b590b59, - 0x1fff0ba40ba40ba4, 0x1fff0bee0bee0bee, 0x1fff0c390c390c39, 0x1fff0c830c830c83, 0x1fff0cce0cce0cce, 0x1fff0d180d180d18, 0x1fff0d630d630d63, 0x1fff0dad0dad0dad, - 0x1fff0df80df80df8, 0x1fff0e420e420e42, 0x1fff0e8d0e8d0e8d, 0x1fff0ed70ed70ed7, 0x1fff0f220f220f22, 0x1fff0f6c0f6c0f6c, 0x1fff0fb70fb70fb7, 0x1fff100110011001, - 0x1fff104c104c104c, 0x1fff109610961096, 0x1fff10e110e110e1, 0x1fff112b112b112b, 0x1fff117611761176, 0x1fff11c011c011c0, 0x1fff120b120b120b, 0x1fff125512551255, - 0x1fff12a012a012a0, 0x1fff12ea12ea12ea, 0x1fff133513351335, 0x1fff137f137f137f, 0x1fff13ca13ca13ca, 0x1fff141414141414, 0x1fff145f145f145f, 0x1fff14a914a914a9, - 0x1fff14f414f414f4, 0x1fff153e153e153e, 0x1fff158915891589, 0x1fff15d315d315d3, 0x1fff161e161e161e, 0x1fff166816681668, 0x1fff16b316b316b3, 0x1fff16fd16fd16fd, - 0x1fff174817481748, 0x1fff179217921792, 0x1fff17dd17dd17dd, 0x1fff182718271827, 0x1fff187218721872, 0x1fff18bc18bc18bc, 0x1fff190719071907, 0x1fff195119511951, - 0x1fff199c199c199c, 0x1fff19e619e619e6, 0x1fff1a311a311a31, 0x1fff1a7b1a7b1a7b, 0x1fff1ac61ac61ac6, 0x1fff1b101b101b10, 0x1fff1b5b1b5b1b5b, 0x1fff1ba51ba51ba5, - 0x1fff1bf01bf01bf0, 0x1fff1c3a1c3a1c3a, 0x1fff1c851c851c85, 0x1fff1ccf1ccf1ccf, 0x1fff1d1a1d1a1d1a, 0x1fff1d641d641d64, 0x1fff1daf1daf1daf, 0x1fff1df91df91df9, - 0x1fff1e441e441e44, 0x1fff1e8e1e8e1e8e, 0x1fff1ed91ed91ed9, 0x1fff1f231f231f23, 0x1fff1f6e1f6e1f6e, 0x1fff1fb81fb81fb8, 0x1fff200320032003, 0x1fff204d204d204d, - 0x1fff209820982098, 0x1fff20e220e220e2, 0x1fff212d212d212d, 0x1fff217721772177, 0x1fff21c221c221c2, 0x1fff220c220c220c, 0x1fff225722572257, 0x1fff22a122a122a1, - 0x1fff22ec22ec22ec, 0x1fff233623362336, 0x1fff238123812381, 0x1fff23cb23cb23cb, 0x1fff241624162416, 0x1fff246024602460, 0x1fff24aa24aa24aa, 0x1fff24f524f524f5, - 0x1fff253f253f253f, 0x1fff258a258a258a, 0x1fff25d425d425d4, 0x1fff261f261f261f, 0x1fff266926692669, 0x1fff26b426b426b4, 0x1fff26fe26fe26fe, 0x1fff274927492749, - 0x1fff279327932793, 0x1fff27de27de27de, 0x1fff282828282828, 0x1fff287328732873, 0x1fff28bd28bd28bd, 0x1fff290829082908, 0x1fff295229522952, 0x1fff299d299d299d, - 0x1fff29e729e729e7, 0x1fff2a322a322a32, 0x1fff2a7c2a7c2a7c, 0x1fff2ac72ac72ac7, 0x1fff2b112b112b11, 0x1fff2b5c2b5c2b5c, 0x1fff2ba62ba62ba6, 0x1fff2bf12bf12bf1, - 0x1fff2c3b2c3b2c3b, 0x1fff2c862c862c86, 0x1fff2cd02cd02cd0, 0x1fff2d1b2d1b2d1b, 0x1fff2d652d652d65, 0x1fff2db02db02db0, 0x1fff2dfa2dfa2dfa, 0x1fff2e452e452e45, - 0x1fff2e8f2e8f2e8f, 0x1fff2eda2eda2eda, 0x1fff2f242f242f24, 0x1fff2f6f2f6f2f6f, 0x1fff2fb92fb92fb9, 0x1fff300430043004, 0x1fff304e304e304e, 0x1fff309930993099, - 0x1fff30e330e330e3, 0x1fff312e312e312e, 0x1fff317831783178, 0x1fff31c331c331c3, 0x1fff320d320d320d, 0x1fff325832583258, 0x1fff32a232a232a2, 0x1fff32ed32ed32ed, - 0x1fff333733373337, 0x1fff338233823382, 0x1fff33cc33cc33cc, 0x1fff341734173417, 0x1fff346134613461, 0x1fff34ac34ac34ac, 0x1fff34f634f634f6, 0x1fff354135413541, - 0x1fff358b358b358b, 0x1fff35d635d635d6, 0x1fff362036203620, 0x1fff366b366b366b, 0x1fff36b536b536b5, 0x1fff370037003700, 0x1fff374a374a374a, 0x1fff379537953795, - 0x1fff37df37df37df, 0x1fff382a382a382a, 0x1fff387438743874, 0x1fff38bf38bf38bf, 0x1fff390939093909, 0x1fff395439543954, 0x1fff399e399e399e, 0x1fff39e939e939e9, - 0x1fff3a333a333a33, 0x1fff3a7e3a7e3a7e, 0x1fff3ac83ac83ac8, 0x1fff3b133b133b13, 0x1fff3b5d3b5d3b5d, 0x1fff3ba83ba83ba8, 0x1fff3bf23bf23bf2, 0x1fff3c3d3c3d3c3d, - 0x1fff3c873c873c87, 0x1fff3cd23cd23cd2, 0x1fff3d1c3d1c3d1c, 0x1fff3d673d673d67, 0x1fff3db13db13db1, 0x1fff3dfc3dfc3dfc, 0x1fff3e463e463e46, 0x1fff3e913e913e91, - 0x1fff3edb3edb3edb, 0x1fff3f263f263f26, 0x1fff3f703f703f70, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, - 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, - 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, - }; - static const __m64 COEFF_U_MMX[256] = { - 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, - 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, - 0x1fffc7800af30000, 0x1fffc8010ada0000, 0x1fffc8820ac10000, 0x1fffc9030aa80000, 0x1fffc9850a8f0000, 0x1fffca060a760000, 0x1fffca870a5d0000, 0x1fffcb080a440000, - 0x1fffcb890a2a0000, 0x1fffcc0a0a110000, 0x1fffcc8b09f80000, 0x1fffcd0d09df0000, 0x1fffcd8e09c60000, 0x1fffce0f09ad0000, 0x1fffce9009940000, 0x1fffcf11097b0000, - 0x1fffcf9209620000, 0x1fffd01409490000, 0x1fffd09509300000, 0x1fffd11609170000, 0x1fffd19708fe0000, 0x1fffd21808e50000, 0x1fffd29908cc0000, 0x1fffd31a08b30000, - 0x1fffd39c089a0000, 0x1fffd41d08810000, 0x1fffd49e08680000, 0x1fffd51f084f0000, 0x1fffd5a008360000, 0x1fffd621081d0000, 0x1fffd6a308040000, 0x1fffd72407eb0000, - 0x1fffd7a507d20000, 0x1fffd82607b90000, 0x1fffd8a707a00000, 0x1fffd92807870000, 0x1fffd9a9076e0000, 0x1fffda2b07550000, 0x1fffdaac073c0000, 0x1fffdb2d07230000, - 0x1fffdbae070a0000, 0x1fffdc2f06f10000, 0x1fffdcb006d80000, 0x1fffdd3206bf0000, 0x1fffddb306a60000, 0x1fffde34068d0000, 0x1fffdeb506740000, 0x1fffdf36065b0000, - 0x1fffdfb706420000, 0x1fffe03806290000, 0x1fffe0ba060f0000, 0x1fffe13b05f60000, 0x1fffe1bc05dd0000, 0x1fffe23d05c40000, 0x1fffe2be05ab0000, 0x1fffe33f05920000, - 0x1fffe3c005790000, 0x1fffe44205600000, 0x1fffe4c305470000, 0x1fffe544052e0000, 0x1fffe5c505150000, 0x1fffe64604fc0000, 0x1fffe6c704e30000, 0x1fffe74904ca0000, - 0x1fffe7ca04b10000, 0x1fffe84b04980000, 0x1fffe8cc047f0000, 0x1fffe94d04660000, 0x1fffe9ce044d0000, 0x1fffea4f04340000, 0x1fffead1041b0000, 0x1fffeb5204020000, - 0x1fffebd303e90000, 0x1fffec5403d00000, 0x1fffecd503b70000, 0x1fffed56039e0000, 0x1fffedd803850000, 0x1fffee59036c0000, 0x1fffeeda03530000, 0x1fffef5b033a0000, - 0x1fffefdc03210000, 0x1ffff05d03080000, 0x1ffff0de02ef0000, 0x1ffff16002d60000, 0x1ffff1e102bd0000, 0x1ffff26202a40000, 0x1ffff2e3028b0000, 0x1ffff36402720000, - 0x1ffff3e502590000, 0x1ffff46702400000, 0x1ffff4e802270000, 0x1ffff569020e0000, 0x1ffff5ea01f40000, 0x1ffff66b01db0000, 0x1ffff6ec01c20000, 0x1ffff76d01a90000, - 0x1ffff7ef01900000, 0x1ffff87001770000, 0x1ffff8f1015e0000, 0x1ffff97201450000, 0x1ffff9f3012c0000, 0x1ffffa7401130000, 0x1ffffaf500fa0000, 0x1ffffb7700e10000, - 0x1ffffbf800c80000, 0x1ffffc7900af0000, 0x1ffffcfa00960000, 0x1ffffd7b007d0000, 0x1ffffdfc00640000, 0x1ffffe7e004b0000, 0x1ffffeff00320000, 0x1fffff8000190000, - 0x1fff000000000000, 0x1fff0081ffe80000, 0x1fff0102ffcf0000, 0x1fff0183ffb60000, 0x1fff0205ff9d0000, 0x1fff0286ff840000, 0x1fff0307ff6b0000, 0x1fff0388ff520000, - 0x1fff0409ff390000, 0x1fff048aff200000, 0x1fff050cff070000, 0x1fff058dfeee0000, 0x1fff060efed50000, 0x1fff068ffebc0000, 0x1fff0710fea30000, 0x1fff0791fe8a0000, - 0x1fff0812fe710000, 0x1fff0894fe580000, 0x1fff0915fe3f0000, 0x1fff0996fe260000, 0x1fff0a17fe0d0000, 0x1fff0a98fdf30000, 0x1fff0b19fdda0000, 0x1fff0b9afdc10000, - 0x1fff0c1cfda80000, 0x1fff0c9dfd8f0000, 0x1fff0d1efd760000, 0x1fff0d9ffd5d0000, 0x1fff0e20fd440000, 0x1fff0ea1fd2b0000, 0x1fff0f23fd120000, 0x1fff0fa4fcf90000, - 0x1fff1025fce00000, 0x1fff10a6fcc70000, 0x1fff1127fcae0000, 0x1fff11a8fc950000, 0x1fff1229fc7c0000, 0x1fff12abfc630000, 0x1fff132cfc4a0000, 0x1fff13adfc310000, - 0x1fff142efc180000, 0x1fff14affbff0000, 0x1fff1530fbe60000, 0x1fff15b2fbcd0000, 0x1fff1633fbb40000, 0x1fff16b4fb9b0000, 0x1fff1735fb820000, 0x1fff17b6fb690000, - 0x1fff1837fb500000, 0x1fff18b8fb370000, 0x1fff193afb1e0000, 0x1fff19bbfb050000, 0x1fff1a3cfaec0000, 0x1fff1abdfad30000, 0x1fff1b3efaba0000, 0x1fff1bbffaa10000, - 0x1fff1c41fa880000, 0x1fff1cc2fa6f0000, 0x1fff1d43fa560000, 0x1fff1dc4fa3d0000, 0x1fff1e45fa240000, 0x1fff1ec6fa0b0000, 0x1fff1f47f9f20000, 0x1fff1fc9f9d80000, - 0x1fff204af9bf0000, 0x1fff20cbf9a60000, 0x1fff214cf98d0000, 0x1fff21cdf9740000, 0x1fff224ef95b0000, 0x1fff22cff9420000, 0x1fff2351f9290000, 0x1fff23d2f9100000, - 0x1fff2453f8f70000, 0x1fff24d4f8de0000, 0x1fff2555f8c50000, 0x1fff25d6f8ac0000, 0x1fff2658f8930000, 0x1fff26d9f87a0000, 0x1fff275af8610000, 0x1fff27dbf8480000, - 0x1fff285cf82f0000, 0x1fff28ddf8160000, 0x1fff295ef7fd0000, 0x1fff29e0f7e40000, 0x1fff2a61f7cb0000, 0x1fff2ae2f7b20000, 0x1fff2b63f7990000, 0x1fff2be4f7800000, - 0x1fff2c65f7670000, 0x1fff2ce7f74e0000, 0x1fff2d68f7350000, 0x1fff2de9f71c0000, 0x1fff2e6af7030000, 0x1fff2eebf6ea0000, 0x1fff2f6cf6d10000, 0x1fff2fedf6b80000, - 0x1fff306ff69f0000, 0x1fff30f0f6860000, 0x1fff3171f66d0000, 0x1fff31f2f6540000, 0x1fff3273f63b0000, 0x1fff32f4f6220000, 0x1fff3376f6090000, 0x1fff33f7f5f00000, - 0x1fff3478f5d70000, 0x1fff34f9f5bd0000, 0x1fff357af5a40000, 0x1fff35fbf58b0000, 0x1fff367cf5720000, 0x1fff36fef5590000, 0x1fff377ff5400000, 0x1fff3800f5270000, - 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, - 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, - }; - static const __m64 COEFF_V_MMX[256] = { - 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, - 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, - 0x1fff000016c4d351, 0x1fff00001690d3b7, 0x1fff0000165cd41d, 0x1fff00001627d483, 0x1fff000015f3d4e9, 0x1fff000015bfd550, 0x1fff0000158bd5b6, 0x1fff00001557d61c, - 0x1fff00001523d682, 0x1fff000014efd6e8, 0x1fff000014bbd74e, 0x1fff00001487d7b4, 0x1fff00001453d81b, 0x1fff0000141fd881, 0x1fff000013ebd8e7, 0x1fff000013b7d94d, - 0x1fff00001383d9b3, 0x1fff0000134fda19, 0x1fff0000131bda7f, 0x1fff000012e7dae6, 0x1fff000012b3db4c, 0x1fff0000127fdbb2, 0x1fff0000124bdc18, 0x1fff00001217dc7e, - 0x1fff000011e3dce4, 0x1fff000011afdd4a, 0x1fff0000117bddb1, 0x1fff00001147de17, 0x1fff00001113de7d, 0x1fff000010dfdee3, 0x1fff000010abdf49, 0x1fff00001077dfaf, - 0x1fff00001043e015, 0x1fff0000100fe07c, 0x1fff00000fdae0e2, 0x1fff00000fa6e148, 0x1fff00000f72e1ae, 0x1fff00000f3ee214, 0x1fff00000f0ae27a, 0x1fff00000ed6e2e0, - 0x1fff00000ea2e347, 0x1fff00000e6ee3ad, 0x1fff00000e3ae413, 0x1fff00000e06e479, 0x1fff00000dd2e4df, 0x1fff00000d9ee545, 0x1fff00000d6ae5ab, 0x1fff00000d36e612, - 0x1fff00000d02e678, 0x1fff00000ccee6de, 0x1fff00000c9ae744, 0x1fff00000c66e7aa, 0x1fff00000c32e810, 0x1fff00000bfee877, 0x1fff00000bcae8dd, 0x1fff00000b96e943, - 0x1fff00000b62e9a9, 0x1fff00000b2eea0f, 0x1fff00000afaea75, 0x1fff00000ac6eadb, 0x1fff00000a92eb42, 0x1fff00000a5eeba8, 0x1fff00000a2aec0e, 0x1fff000009f6ec74, - 0x1fff000009c2ecda, 0x1fff0000098eed40, 0x1fff00000959eda6, 0x1fff00000925ee0d, 0x1fff000008f1ee73, 0x1fff000008bdeed9, 0x1fff00000889ef3f, 0x1fff00000855efa5, - 0x1fff00000821f00b, 0x1fff000007edf071, 0x1fff000007b9f0d8, 0x1fff00000785f13e, 0x1fff00000751f1a4, 0x1fff0000071df20a, 0x1fff000006e9f270, 0x1fff000006b5f2d6, - 0x1fff00000681f33c, 0x1fff0000064df3a3, 0x1fff00000619f409, 0x1fff000005e5f46f, 0x1fff000005b1f4d5, 0x1fff0000057df53b, 0x1fff00000549f5a1, 0x1fff00000515f607, - 0x1fff000004e1f66e, 0x1fff000004adf6d4, 0x1fff00000479f73a, 0x1fff00000445f7a0, 0x1fff00000411f806, 0x1fff000003ddf86c, 0x1fff000003a9f8d2, 0x1fff00000375f939, - 0x1fff00000341f99f, 0x1fff0000030cfa05, 0x1fff000002d8fa6b, 0x1fff000002a4fad1, 0x1fff00000270fb37, 0x1fff0000023cfb9d, 0x1fff00000208fc04, 0x1fff000001d4fc6a, - 0x1fff000001a0fcd0, 0x1fff0000016cfd36, 0x1fff00000138fd9c, 0x1fff00000104fe02, 0x1fff000000d0fe68, 0x1fff0000009cfecf, 0x1fff00000068ff35, 0x1fff00000034ff9b, - 0x1fff000000000000, 0x1fff0000ffcd0066, 0x1fff0000ff9900cc, 0x1fff0000ff650132, 0x1fff0000ff310199, 0x1fff0000fefd01ff, 0x1fff0000fec90265, 0x1fff0000fe9502cb, - 0x1fff0000fe610331, 0x1fff0000fe2d0397, 0x1fff0000fdf903fd, 0x1fff0000fdc50464, 0x1fff0000fd9104ca, 0x1fff0000fd5d0530, 0x1fff0000fd290596, 0x1fff0000fcf505fc, - 0x1fff0000fcc00662, 0x1fff0000fc8c06c8, 0x1fff0000fc58072f, 0x1fff0000fc240795, 0x1fff0000fbf007fb, 0x1fff0000fbbc0861, 0x1fff0000fb8808c7, 0x1fff0000fb54092d, - 0x1fff0000fb200993, 0x1fff0000faec09fa, 0x1fff0000fab80a60, 0x1fff0000fa840ac6, 0x1fff0000fa500b2c, 0x1fff0000fa1c0b92, 0x1fff0000f9e80bf8, 0x1fff0000f9b40c5e, - 0x1fff0000f9800cc5, 0x1fff0000f94c0d2b, 0x1fff0000f9180d91, 0x1fff0000f8e40df7, 0x1fff0000f8b00e5d, 0x1fff0000f87c0ec3, 0x1fff0000f8480f29, 0x1fff0000f8140f90, - 0x1fff0000f7e00ff6, 0x1fff0000f7ac105c, 0x1fff0000f77810c2, 0x1fff0000f7441128, 0x1fff0000f710118e, 0x1fff0000f6dc11f4, 0x1fff0000f6a8125b, 0x1fff0000f67312c1, - 0x1fff0000f63f1327, 0x1fff0000f60b138d, 0x1fff0000f5d713f3, 0x1fff0000f5a31459, 0x1fff0000f56f14bf, 0x1fff0000f53b1526, 0x1fff0000f507158c, 0x1fff0000f4d315f2, - 0x1fff0000f49f1658, 0x1fff0000f46b16be, 0x1fff0000f4371724, 0x1fff0000f403178a, 0x1fff0000f3cf17f1, 0x1fff0000f39b1857, 0x1fff0000f36718bd, 0x1fff0000f3331923, - 0x1fff0000f2ff1989, 0x1fff0000f2cb19ef, 0x1fff0000f2971a56, 0x1fff0000f2631abc, 0x1fff0000f22f1b22, 0x1fff0000f1fb1b88, 0x1fff0000f1c71bee, 0x1fff0000f1931c54, - 0x1fff0000f15f1cba, 0x1fff0000f12b1d21, 0x1fff0000f0f71d87, 0x1fff0000f0c31ded, 0x1fff0000f08f1e53, 0x1fff0000f05b1eb9, 0x1fff0000f0271f1f, 0x1fff0000eff21f85, - 0x1fff0000efbe1fec, 0x1fff0000ef8a2052, 0x1fff0000ef5620b8, 0x1fff0000ef22211e, 0x1fff0000eeee2184, 0x1fff0000eeba21ea, 0x1fff0000ee862250, 0x1fff0000ee5222b7, - 0x1fff0000ee1e231d, 0x1fff0000edea2383, 0x1fff0000edb623e9, 0x1fff0000ed82244f, 0x1fff0000ed4e24b5, 0x1fff0000ed1a251b, 0x1fff0000ece62582, 0x1fff0000ecb225e8, - 0x1fff0000ec7e264e, 0x1fff0000ec4a26b4, 0x1fff0000ec16271a, 0x1fff0000ebe22780, 0x1fff0000ebae27e6, 0x1fff0000eb7a284d, 0x1fff0000eb4628b3, 0x1fff0000eb122919, - 0x1fff0000eade297f, 0x1fff0000eaaa29e5, 0x1fff0000ea762a4b, 0x1fff0000ea422ab1, 0x1fff0000ea0e2b18, 0x1fff0000e9da2b7e, 0x1fff0000e9a52be4, 0x1fff0000e9712c4a, - 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, - 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, - }; - - // ----------------------------------------------------------------------------- - - void YUVtoRGBA_MMX(yuv_buffer & YUVBuffer, std::vector & PixelData) - { - // Width and height of all buffers have to be divisible by 4. - BS_ASSERT((YUVBuffer.y_width & 3) == 0); - BS_ASSERT((YUVBuffer.y_height & 3) == 0); - BS_ASSERT((YUVBuffer.uv_width & 3) == 0); - BS_ASSERT((YUVBuffer.uv_height & 3) == 0); - // UV images have to have a quarter of the Y image resolution - BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); - BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); - - const unsigned char * ySrc = YUVBuffer.y; - const unsigned char * uSrc = YUVBuffer.u; - const unsigned char * vSrc = YUVBuffer.v; - unsigned char * dst = &PixelData[0]; - - const int yPadding = YUVBuffer.y_stride - YUVBuffer.y_width; - int uvStride = YUVBuffer.uv_stride; - - for (int h = 0; h < YUVBuffer.y_height; ++h) - { - uvStride ^= YUVBuffer.uv_stride; - for (int w = 0; w < YUVBuffer.y_width / 4; ++w) - { - __m64 uvCoeff0 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); - __m64 uvCoeff1 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); - - __m64 px01 = COEFF_Y_MMX[*ySrc++]; - __m64 px23 = COEFF_Y_MMX[*ySrc++]; - __m64 px45 = COEFF_Y_MMX[*ySrc++]; - __m64 px67 = COEFF_Y_MMX[*ySrc++]; - - px01 = _m_paddw(px01, uvCoeff0); - px23 = _m_paddw(px23, uvCoeff0); - px45 = _m_paddw(px45, uvCoeff1); - px67 = _m_paddw(px67, uvCoeff1); - - px01 = _m_psrawi(px01, 6); - px23 = _m_psrawi(px23, 6); - px45 = _m_psrawi(px45, 6); - px67 = _m_psrawi(px67, 6); - - ((__m64*)dst)[0] = _m_packuswb(px01, px23); - ((__m64*)dst)[1] = _m_packuswb(px45, px67); - dst += 16; - } - - ySrc += yPadding; - uSrc += uvStride - YUVBuffer.uv_width; - vSrc += uvStride - YUVBuffer.uv_width; +namespace Sword25 { + +static const int PRECISION = 32768; +static const int COEFFS_Y[256] = { + -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, + 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, + 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, + 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, + 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, + 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, + 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, + 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, + 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, + 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, + 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, + 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, + 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, + 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, + 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, + 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, +}; +static const int COEFFS_RV[256] = { + -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, + -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, + -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, + -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, + -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, + -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, + -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, + -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, + 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, + 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, + 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, + 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, + 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, + 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, + 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, + 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, +}; +static const int COEFFS_GU[256] = { + 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, + 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, + 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, + 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, + 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, + 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, + 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, + 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, + 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, + -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, + -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, + -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, + -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, + -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, + -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, + -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, +}; +static const int COEFFS_GV[256] = { + 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, + 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, + 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, + 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, + 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, + 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, + 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, + 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, + 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, + -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, + -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, + -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, + -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, + -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, + -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, + -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, +}; +static const int COEFFS_BU[256] = { + -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, + -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, + -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, + -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, + -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, + -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, + -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, + -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, + 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, + 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, + 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, + 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, + 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, + 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, + 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, + 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, +}; +static const int CLAMP_TAB[1024] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, +}; + +void BS_YUVtoRGBA::YUVtoRGBA(yuv_buffer &YUVBuffer, const theora_info &TheoraInfo, byte *Pixels, int PixelsSize) { + BS_ASSERT(TheoraInfo.pixelformat == OC_PF_420); + BS_ASSERT(PixelsSize >= (YUVBuffer.y_width * YUVBuffer.y_height)); + + // Width and height of all buffers have to be divisible by 2. + BS_ASSERT((YUVBuffer.y_width & 1) == 0); + BS_ASSERT((YUVBuffer.y_height & 1) == 0); + BS_ASSERT((YUVBuffer.uv_width & 1) == 0); + BS_ASSERT((YUVBuffer.uv_height & 1) == 0); + // UV images have to have a quarter of the Y image resolution + BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); + BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); + + const int *cl = &CLAMP_TAB[320]; + + const unsigned char *ySrc0 = YUVBuffer.y; + const unsigned char *ySrc1 = YUVBuffer.y + YUVBuffer.y_stride; + const unsigned char *uSrc = YUVBuffer.u; + const unsigned char *vSrc = YUVBuffer.v; + unsigned char *dst0 = &Pixels[0]; + unsigned char *dst1 = &Pixels[0] + YUVBuffer.y_width * 4; + + for (int h = 0; h < YUVBuffer.y_height / 2; ++h) { + for (int w = 0; w < YUVBuffer.y_width / 2; ++w) { + int u = *uSrc++; + int v = *vSrc++; + + int rUV = COEFFS_RV[v]; + int gUV = COEFFS_GU[u] + COEFFS_GV[v]; + int bUV = COEFFS_BU[u]; + + int y = *ySrc0++; + int r = COEFFS_Y[y] + rUV; + int g = COEFFS_Y[y] + gUV; + int b = COEFFS_Y[y] + bUV; + *dst0++ = cl[r / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[b / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[r / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[b / PRECISION]; + *dst1++ = 255; + + y = *ySrc0++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst0++ = cl[r / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[b / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[r / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[b / PRECISION]; + *dst1++ = 255; } - _m_empty(); + dst0 += YUVBuffer.y_width * 4; + dst1 += YUVBuffer.y_width * 4; + ySrc0 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; + ySrc1 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; + uSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; + vSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; } - } -// ----------------------------------------------------------------------------- - -void BS_YUVtoRGBA::YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, vector & Pixels) -{ - BS_ASSERT(TheoraInfo.pixelformat == OC_PF_420); - BS_ASSERT(int(Pixels.size()) >= YUVBuffer.y_width * YUVBuffer.y_height); - - return YUVtoRGBA_c(YUVBuffer, Pixels); - - if (BS_CPUInfo::GetInstance().IsMMXSupported()) - return YUVtoRGBA_MMX(YUVBuffer, Pixels); - else - return YUVtoRGBA_c(YUVBuffer, Pixels); -} +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.h b/engines/sword25/fmv/oggtheora/yuvtorgba.h index 6593254ff9..5b0332a807 100644 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.h +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.h @@ -39,21 +39,19 @@ // Includes // ----------------------------------------------------------------------------- -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" - #include "sword25/kernel/common.h" -#include "theora/theora.h" +#include +namespace Sword25 { // ----------------------------------------------------------------------------- // Klassendefinition // ----------------------------------------------------------------------------- -class BS_YUVtoRGBA -{ +class BS_YUVtoRGBA { public: - static void YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, std::vector & Pixels); + static void YUVtoRGBA(yuv_buffer &YUVBuffer, const theora_info &TheoraInfo, byte *Pixels, int PixelsSize); }; +} // End of namespace Sword25 + #endif -- cgit v1.2.3 From f71295ab6d6899b21809837b6c6bf317a45193ef Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 31 Aug 2010 09:45:15 +0000 Subject: Revert "SWORD25: Commit of in-progress MoviePlayer code" This reverts commit cb95db7cc04a5a3d14f408835cd371e0a0abd4ed. svn-id: r53296 --- engines/sword25/fmv/movieplayer.cpp | 481 +-------------- engines/sword25/fmv/movieplayer.h | 68 +-- engines/sword25/fmv/oggtheora/audiobuffer.cpp | 54 +- engines/sword25/fmv/oggtheora/audiobuffer.h | 26 +- engines/sword25/fmv/oggtheora/moviefile.cpp | 34 +- engines/sword25/fmv/oggtheora/moviefile.h | 17 +- engines/sword25/fmv/oggtheora/oggstate.cpp | 19 +- engines/sword25/fmv/oggtheora/oggstate.h | 36 +- engines/sword25/fmv/oggtheora/oggstreamstate.cpp | 40 +- engines/sword25/fmv/oggtheora/oggstreamstate.h | 48 +- engines/sword25/fmv/oggtheora/oggtheora.cpp | 723 +++++++++++++++++++++++ engines/sword25/fmv/oggtheora/oggtheora.h | 124 ++++ engines/sword25/fmv/oggtheora/theorastate.cpp | 27 +- engines/sword25/fmv/oggtheora/theorastate.h | 19 +- engines/sword25/fmv/oggtheora/vorbisstate.cpp | 35 +- engines/sword25/fmv/oggtheora/vorbisstate.h | 21 +- engines/sword25/fmv/oggtheora/yuvtorgba.cpp | 587 +++++++++++------- engines/sword25/fmv/oggtheora/yuvtorgba.h | 14 +- 18 files changed, 1462 insertions(+), 911 deletions(-) create mode 100644 engines/sword25/fmv/oggtheora/oggtheora.cpp create mode 100644 engines/sword25/fmv/oggtheora/oggtheora.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 69b8fe41ec..e4b33bdf8c 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -33,524 +33,59 @@ */ #include "sword25/fmv/movieplayer.h" -#include "sword25/fmv/oggtheora/oggstate.h" -#include "sword25/fmv/oggtheora/oggstreamstate.h" -#include "sword25/fmv/oggtheora/vorbisstate.h" -#include "sword25/fmv/oggtheora/yuvtorgba.h" -#include "sword25/gfx/graphicengine.h" -#include "sword25/gfx/panel.h" -#include "sword25/kernel/kernel.h" -#include "sword25/sfx/soundengine.h" - -#define BS_LOG_PREFIX "MOVIEPLAYER" - -#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */ namespace Sword25 { -const int MAX_FRAMES_PER_TICK = 10; -const int READ_BLOCK_SIZE = 1024 * 40; -const float MAX_AUDIO_BUFFER_LENGTH = 1.0f; +#define BS_LOG_PREFIX "MOVIEPLAYER" Service *OggTheora_CreateObject(Kernel *pKernel) { return new MoviePlayer(pKernel); } -// ----------------------------------------------------------------------------- - -inline bool VerifyRequiredServiceAvailability() { - char *RequiredServices[] = { "gfx", "sfx", "package" }; - for (size_t i = 0; i < sizeof(RequiredServices) / sizeof(RequiredServices[0]); ++i) { - if (!Kernel::GetInstance()->GetService(RequiredServices[i])) { - BS_LOG_ERRORLN("Required service \"%s\" is not active.", RequiredServices[i]); - return false; - } - } - - return true; -} - -bool ParseStreamHeaders(Common::SharedPtr &File, - Common::SharedPtr &OggState, - Common::SharedPtr &TheoraStreamState, - Common::SharedPtr &VorbisStreamState, - Common::SharedPtr &TheoraState, - Common::SharedPtr &VorbisState, - bool &TheoraPresent, - bool &VorbisPresent, - const Common::String &Filename) { - TheoraPresent = false; - VorbisPresent = false; - - // Ogg file open; parse the headers - // Only interested in Vorbis/Theora streams - bool FinishedHeaderParsing = false; - while (!FinishedHeaderParsing) { - if (File->BufferData(*OggState.get()) == 0) return false; - - ogg_page Page; - while(OggState->SyncPageout(&Page) > 0) { - // is this a mandated initial header? If not, stop parsing - if (!ogg_page_bos(&Page)) { - // don't leak the page; get it into the appropriate stream - if (TheoraPresent) TheoraStreamState->PageIn(&Page); - if (VorbisPresent) VorbisStreamState->PageIn(&Page); - - FinishedHeaderParsing = true; - break; - } - - Common::SharedPtr streamState(new OggStreamState(ogg_page_serialno(&Page))); - - streamState->PageIn(&Page); - - ogg_packet Packet; - streamState->PacketOut(&Packet); - - // identify the codec: try theora - if (!TheoraPresent && TheoraState->DecodeHeader(&Packet) >= 0) { - // it is theora - TheoraStreamState = streamState; - TheoraPresent = true; - } else if (!VorbisPresent && VorbisState->SynthesisHeaderIn(&Packet) >=0) { - // it is vorbis - VorbisStreamState = streamState; - VorbisPresent = true; - } - } - // fall through to non-bos page parsing - } - - // we're expecting more header packets. - unsigned int TheoraPacketsRead = TheoraPresent ? 1 : 0; - unsigned int VorbisPacketsRead = VorbisPresent ? 1 : 0; - while ((TheoraPresent && TheoraPacketsRead < 3) || (VorbisPresent && VorbisPacketsRead < 3)) { - int ret; - ogg_packet Packet; - - // look for further theora headers - while(TheoraPresent && (TheoraPacketsRead < 3) && (ret = TheoraStreamState->PacketOut(&Packet))) { - if (ret < 0 || TheoraState->DecodeHeader(&Packet)) { - BS_LOG_ERRORLN("Error parsing Theora stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); - return false; - } - - ++TheoraPacketsRead; - if (TheoraPacketsRead == 3) break; - } - - // look for more vorbis header packets - while(VorbisPresent && (VorbisPacketsRead < 3) && (ret = VorbisStreamState->PacketOut(&Packet))) { - if (ret < 0 || VorbisState->SynthesisHeaderIn(&Packet)) { - BS_LOG_ERRORLN("Error parsing Vorbis stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); - return false; - } - - ++VorbisPacketsRead; - if (VorbisPacketsRead == 3) break; - } - - // The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec - ogg_page Page; - if (OggState->SyncPageout(&Page) > 0) { - // demux into the appropriate stream - if (TheoraPresent) TheoraStreamState->PageIn(&Page); - if (VorbisPresent) VorbisStreamState->PageIn(&Page); - } else { - if (File->BufferData(*OggState.get()) == 0) { - BS_LOG_ERRORLN("End of file while searching for codec headers. (%s)", Filename.c_str()); - return false; - } - } - } - - return true; -} - -// ----------------------------------------------------------------------------- - -MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), - m_SoundHandle(0), _pixels(NULL) { +MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); - - UnloadMovie(); -} - -MoviePlayer::~MoviePlayer() { - delete _pixels; } bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { - if (!VerifyRequiredServiceAvailability()) return false; - - UnloadMovie(); - - // Alle Objekte die in dieser Funktion erzeugt werden, werden in zunächst lokalen Auto-Pointern gehalten. - // Bei erfolgreicher Beendigung dieser Funktion werden sie den objektlokalen Auto-Pointern zugewiesen. - // So wird sichergestellt, dass sie korrekt deinitialisiert werden, wenn in dieser Funktion ein Fehler auftritt, denn beim Zerstören der - // lokalen Auto-Pointer werden die entsprechenden Destruktoren aufgerufen. - - // Film laden - // Für Filmdateien wird das Cachingsystem nicht benutzt, da Filme in der Regel nur ein Mal abgespielt werden. - bool Success = false; - Common::SharedPtr File(new MovieFile(Filename, READ_BLOCK_SIZE, Success)); - if (!Success) return false; - - // States erzeugen für Ogg, Vorbis und Theora, sowie die Ogg und Theora Streams - Common::SharedPtr OggState(new OggState()); - Common::SharedPtr VorbisState(new VorbisState()); - Common::SharedPtr TheoraState(new TheoraState()); - - Common::SharedPtr TheoraStreamState; - Common::SharedPtr VorbisStreamState; - - if (!ParseStreamHeaders(File, OggState, TheoraStreamState, VorbisStreamState, TheoraState, VorbisState, m_TheoraPresent, m_VorbisPresent, Filename)) return false; - - // Theora-Decoder Initialisieren - if (m_TheoraPresent) { - TheoraState->DecodeInit(); - - const theora_info & TheoraInfo = TheoraState->GetInfo(); - - if (TheoraInfo.pixelformat != OC_PF_444 && - TheoraInfo.pixelformat != OC_PF_422 && - TheoraInfo.pixelformat != OC_PF_420) { - BS_LOG_ERRORLN("Unknown chroma sampling. (%s)", Filename.c_str()); - return false; - } - - // Ausgabebitmap erstellen - GraphicEngine *pGfx = Kernel::GetInstance()->GetGfx(); - m_OutputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(TheoraInfo.frame_width, TheoraInfo.frame_height); - if (!m_OutputBitmap.IsValid()) { - BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); - return false; - } - - // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. - float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); - float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); - float ScaleFactor = MIN(ScreenToVideoWidth, ScreenToVideoHeight); - if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; - m_OutputBitmap->SetScaleFactor(ScaleFactor); - - // Z-Wert setzen - m_OutputBitmap->SetZ(Z); - - // Ausgabebitmap auf dem Bildschirm zentrieren - m_OutputBitmap->SetX((pGfx->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); - m_OutputBitmap->SetY((pGfx->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); - - // Buffer für die Pixeldaten erstellen - delete _pixels; - _pixelsSize = TheoraInfo.width * TheoraInfo.height * 4; - _pixels = (byte *)malloc(_pixelsSize); - assert(_pixels); - - m_VideoEnded = false; - } - - // Vorbis-Decoder initialisieren - if (m_VorbisPresent) { - VorbisState->SynthesisInit(); - VorbisState->BlockInit(); - m_AudioBuffer = Common::SharedPtr(new AudioBuffer()); - - m_AudioEnded = false; - } - - // Keine Kopie, überträgt Besitz der erzeugten Objekte von der Funktion auf das Objekt. - m_File = File; - m_OggState = OggState; - m_TheoraState = TheoraState; - m_TheoraStreamState = TheoraStreamState; - m_VorbisState = VorbisState; - m_VorbisStreamState = VorbisStreamState; - m_MovieLoaded = true; - m_Timer = 0; - return true; } bool MoviePlayer::UnloadMovie() { - m_MovieLoaded = false; - m_Paused = true; - - m_VorbisStreamState.reset(); - m_VorbisPresent = false; - m_VorbisState.reset(); - if (m_SoundHandle) { - Kernel::GetInstance()->GetSfx()->StopSound(m_SoundHandle); - m_SoundHandle = 0; - } - m_AudioEnded = true; - m_AudioBuffer.reset(); - - m_TheoraStreamState.reset(); - m_TheoraPresent = false; - m_TheoraState.reset(); - m_VideoEnded = true; - - m_OggState.reset(); - - m_File.reset(); - - m_StartTime = 0; - m_LastFrameTime = 0; - m_Timer = 0.0f; - -// Common::Array().swap(m_Pixels); - m_OutputBitmap.Erase(); - return true; } bool MoviePlayer::Play() { - if (m_MovieLoaded) { - if (m_Paused) { - if (m_SoundHandle) { - SoundEngine * SfxPtr = Kernel::GetInstance()->GetSfx(); - SfxPtr->ResumeSound(m_SoundHandle); - } - m_Paused = false; - } - - return true; - } else { - BS_LOG_WARNINGLN("Cannot play movie, when no movie is loaded."); - return false; - } + return true; } bool MoviePlayer::Pause() { - if (m_MovieLoaded) { - if (m_SoundHandle) { - SoundEngine *SfxPtr = Kernel::GetInstance()->GetSfx(); - SfxPtr->PauseSound(m_SoundHandle); - } - - m_Paused = true; - return true; - } else { - BS_LOG_WARNINGLN("Cannot pause movie, when no movie is loaded."); - return false; - } + return true; } void MoviePlayer::Update() { - if (m_AudioEnded && m_VideoEnded) { - m_Paused = true; - - // Falls der Sound noch läuft, muss er jetzt beendet werden. - if (m_SoundHandle) { - SoundEngine *SfxPtr = Kernel::GetInstance()->GetSfx(); - SfxPtr->StopSound(m_SoundHandle); - m_SoundHandle = 0; - } - } - - if (m_Paused) return; - - // Timer aktualisieren. - // Wird nur genutzt, wenn keine Audiodaten vorhanden sind. - m_Timer += Kernel::GetInstance()->GetGfx()->GetSecondaryFrameDuration(); - - // Audiodaten dekodieren - if (m_VorbisPresent && !m_AudioEnded) DecodeVorbis(); - - - // Videodaten dekodieren - if (m_TheoraPresent && !m_VideoEnded) { - bool Result = DecodeTheora(); - - if (Result) { - // YUV Framebuffer holen - yuv_buffer YUVBuffer; - m_TheoraState->DecodeYUVOut(&YUVBuffer); - - // YUV Bilddaten nach RGBA konvertieren - BS_YUVtoRGBA::YUVtoRGBA(YUVBuffer, m_TheoraState->GetInfo(), _pixels, _pixelsSize); - - // RGBA Bilddaten auf das Ausgabebild kopieren, dabei die Postion des Theoraframes innerhalb des dekodierten Frames beachten. - const theora_info &TheoraInfo = m_TheoraState->GetInfo(); - m_OutputBitmap->SetContent(_pixels, _pixelsSize, - (TheoraInfo.offset_x + TheoraInfo.width * TheoraInfo.offset_y) * 4, - (TheoraInfo.width - TheoraInfo.frame_width) * 4); - } - } } bool MoviePlayer::IsMovieLoaded() { - return m_MovieLoaded; + return true; } bool MoviePlayer::IsPaused() { - return m_Paused; + return true; } float MoviePlayer::GetScaleFactor() { - if (m_MovieLoaded) - return m_OutputBitmap->GetScaleFactorX(); - else - return 0; + return 1.0f; } void MoviePlayer::SetScaleFactor(float ScaleFactor) { - if (m_MovieLoaded) { - m_OutputBitmap->SetScaleFactor(ScaleFactor); - - // Ausgabebitmap auf dem Bildschirm zentrieren - GraphicEngine *gfxPtr = Kernel::GetInstance()->GetGfx(); - m_OutputBitmap->SetX((gfxPtr->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); - m_OutputBitmap->SetY((gfxPtr->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); - } } double MoviePlayer::GetTime() { - if (m_VorbisPresent) { - if (m_SoundHandle) { - float time = Kernel::GetInstance()->GetSfx()->GetSoundTime(m_SoundHandle); - return time; - } else - return 0.0f; - } else - return m_Timer; + return 1.0; } -// ----------------------------------------------------------------------------- - -bool MoviePlayer::DecodeTheora() { - double MovieTime = GetTime(); - - // Check if this frame time has not passed yet. If the frame is late we need - // to decode additonal ones and keep looping, since theora at this stage - // needs to decode all frames (due to keyframing) - // Getting the current time once at the beginning of the function rather than - // every time at the beginning of the loop produces the smoothest framerate - - unsigned int FramesDecoded = 0; - bool FrameReady = false; - while (m_TheoraState->GranuleTime() < MovieTime) { - // theora is one in, one out... - ogg_packet Packet; - if (m_TheoraStreamState->PacketOut(&Packet) > 0) { - if (FramesDecoded < MAX_FRAMES_PER_TICK || Packet.granulepos >= MovieTime) { - m_TheoraState->DecodePacketIn(&Packet); - FrameReady = true; - ++FramesDecoded; - } - } else { - if (m_TheoraStreamState->GetPageBufferSize() > 0) - m_TheoraStreamState->PageInBufferedPage(); - else { - if (m_File->IsEOF()) { - m_VideoEnded = true; - break; - } else - ReadData(); - } - } - } - m_LastFrameTime = MovieTime; - - return FrameReady; -} - -void MoviePlayer::DecodeVorbis() { - // Vorbis-Stream Infos holen. - const vorbis_info &Info = m_VorbisState->GetInfo(); - - // Maximalgröße des Audiobuffers berechnen. - size_t MaxAudioBufferSamples = static_cast(Info.channels * Info.rate * MAX_AUDIO_BUFFER_LENGTH); - - // Zwischenspeicher für die Samples. - Common::Array Samples; - - // Audiobuffer bis zur Maximalgröße füllen, wenn möglich. - while (m_AudioBuffer->Size() < MaxAudioBufferSamples) { - // Vorhandene Audiodaten auslesen - float **PCM; - int SampleCount = m_VorbisState->SynthesisPCMout(&PCM); - - // Wenn Audiodaten gelesen werden konnten, werden diese in 16-Bit Sample umgewandelt und in den Audiobuffer geschrieben. - if (SampleCount > 0) { - // Im Samplezwischenspeicher leeren und genügend Platz für die kommenden Samples reservieren. - Samples.reserve(SampleCount); - Samples.clear(); - - // Samples konvertieren und in die Samplezwischenspeicher schreiben. - for (int i = 0; i < SampleCount; ++i) { - for (int j = 0; j < Info.channels; ++j) { - int SampleValue = static_cast(PCM[j][i] * 32767.0f); - Samples.push_back(CLIP(SampleValue, -32700, 32700)); - } - } - - // Daten aus dem Samplezwischenspeicher in den Audiobuffer schreiben. - m_AudioBuffer->Push(&Samples[0], Samples.size()); - - // Vorbis mitteilen, dass wir alle Samples gelesen haben. - m_VorbisState->SynthesisRead(SampleCount); - } else { - // Wir konnten, keine Audiodaten auslesen, versuchen ein neues Paket zu dekodieren. - ogg_packet Packet; - if (m_VorbisStreamState->PacketOut(&Packet) > 0) { - if (m_VorbisState->Synthesis(&Packet) == 0) m_VorbisState->SynthesisBlockIn(); - } else { - // Gepufferte Daten in den Stream einfügen. - if (m_VorbisStreamState->GetPageBufferSize() > 0) - m_VorbisStreamState->PageInBufferedPage(); - else { - // Nicht genug Daten vorhanden. Wenn die Datei leer ist und bereits alle Audiodaten gelesen wurden, ist der Audiostream am Ende. - // Ansonsten Daten nachladen. - if (m_File->IsEOF()) { - if (m_AudioBuffer->Size() == 0) { - m_AudioEnded = true; - } - - break; - } else - ReadData(); - } - } - } - } - - // Soundkanal abspielen, wenn er noch nicht spielt und Audiodaten vorhanden sind. - if (m_SoundHandle == 0 && m_AudioBuffer->Size()) { - SoundEngine *SfxPtr = Kernel::GetInstance()->GetSfx(); - m_SoundHandle = SfxPtr->PlayDynamicSoundEx(&DynamicSoundCallBack, this, SoundEngine::SFX, Info.rate, 16, Info.channels); - } -} - -void MoviePlayer::ReadData() { - if (!m_File->IsEOF()) m_File->BufferData(*m_OggState.get()); - - ogg_page Page; - while(m_OggState->SyncPageout(&Page) > 0) { - if (m_TheoraPresent) m_TheoraStreamState->BufferPage(&Page); - if (m_VorbisPresent) m_VorbisStreamState->BufferPage(&Page); - } -} - -void MoviePlayer::DynamicSoundCallBack(void *UserData, void *Data, unsigned int DataLength) { - MoviePlayer &t = *reinterpret_cast(UserData); - - signed short *Buffer = reinterpret_cast(Data); - - // Audiodaten in den Soundbuffer schreiben. - DataLength -= t.m_AudioBuffer->Pop(Buffer, DataLength / 2) * 2; - - // Falls nicht genug Audiodaten vorhanden waren, wird der Rest mit Stille überschrieben. - if (DataLength) { - char *ByteBuffer = reinterpret_cast(Buffer); - while (DataLength--) { - *ByteBuffer++ = 0; - } - } -} } // End of namespace Sword25 diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 46890991d9..3404eaacd8 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -39,38 +39,11 @@ // Includes // ----------------------------------------------------------------------------- -#include "common/ptr.h" #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" -#include "sword25/fmv/oggtheora/audiobuffer.h" -#include "sword25/fmv/oggtheora/moviefile.h" -#include "sword25/fmv/oggtheora/oggstreamstate.h" -#include "sword25/fmv/oggtheora/theorastate.h" -#include "sword25/fmv/oggtheora/vorbisstate.h" -#include "sword25/gfx/bitmap.h" namespace Sword25 { -/* FIXME: Audio stubs -class OggStreamState { -public: - OggStreamState(int v) {} - void PageIn(void *v) {} - bool PacketOut(void *v) { return true; } -}; -class VorbisState { -public: - void BlockInit() {} - void SynthesisInit() {} - bool SynthesisHeaderIn(void *v) { return false; } -}; -class OggState { -public: - bool SyncPageout(void *v) { return false; } - char *SyncBuffer(int v) { return NULL; } -}; -*/ - // ----------------------------------------------------------------------------- // Class definitions // ----------------------------------------------------------------------------- @@ -82,10 +55,10 @@ public: // ----------------------------------------------------------------------------- MoviePlayer(Kernel *pKernel); - ~MoviePlayer(); + ~MoviePlayer() {}; // ----------------------------------------------------------------------------- - // Player interface must be implemented by a Movie Player + // Abstract interface must be implemented by each Movie Player // ----------------------------------------------------------------------------- /** @@ -164,44 +137,9 @@ public: * @remark This method can only be called when IsMovieLoaded() returns true. */ double GetTime(); -private: - // ----------------------------------------------------------------------------- - // Internal support methods - // ----------------------------------------------------------------------------- - bool _RegisterScriptBindings(); - bool DecodeTheora(); - void DecodeVorbis(); - void ReadData(); - static void DynamicSoundCallBack(void *UserData, void *Data, unsigned int DataLength); private: - bool m_MovieLoaded; - bool m_Paused; - - Common::SharedPtr m_VorbisStreamState; - bool m_VorbisPresent; - Common::SharedPtr m_VorbisState; - unsigned int m_SoundHandle; - bool m_AudioEnded; - Common::SharedPtr m_AudioBuffer; - - Common::SharedPtr m_TheoraStreamState; - bool m_TheoraPresent; - Common::SharedPtr m_TheoraState; - bool m_VideoEnded; - - Common::SharedPtr m_OggState; - - Common::SharedPtr m_File; - - uint64_t m_StartTime; - double m_LastFrameTime; - - float m_Timer; - - byte * _pixels; - int _pixelsSize; - RenderObjectPtr m_OutputBitmap; + bool _RegisterScriptBindings(); }; } // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.cpp b/engines/sword25/fmv/oggtheora/audiobuffer.cpp index 1e5828f41b..f9e6667ce5 100644 --- a/engines/sword25/fmv/oggtheora/audiobuffer.cpp +++ b/engines/sword25/fmv/oggtheora/audiobuffer.cpp @@ -37,46 +37,72 @@ // ----------------------------------------------------------------------------- #include "sword25/fmv/oggtheora/audiobuffer.h" +#include +#include + +using namespace std; // ----------------------------------------------------------------------------- -namespace Sword25 { +struct BS_AudioBuffer::Impl +{ + CRITICAL_SECTION CS; + queue Buffer; +}; // ----------------------------------------------------------------------------- -AudioBuffer::AudioBuffer() { +BS_AudioBuffer::BS_AudioBuffer() : t(new Impl()) +{ + InitializeCriticalSection(&t->CS); } // ----------------------------------------------------------------------------- -AudioBuffer::~AudioBuffer() { +BS_AudioBuffer::~BS_AudioBuffer() +{ + DeleteCriticalSection(&t->CS); + + delete t; } // ----------------------------------------------------------------------------- -void AudioBuffer::Push(signed short *SamplePtr, unsigned int SampleCount) { - signed short *SampleEndPtr = SamplePtr + SampleCount; - while (SamplePtr != SampleEndPtr) _buffer.push(*SamplePtr++); +void BS_AudioBuffer::Push(signed short * SamplePtr, unsigned int SampleCount) +{ + EnterCriticalSection(&t->CS); + + signed short * SampleEndPtr = SamplePtr + SampleCount; + while (SamplePtr != SampleEndPtr) t->Buffer.push(*SamplePtr++); + + LeaveCriticalSection(&t->CS); } // ----------------------------------------------------------------------------- -unsigned int AudioBuffer::Pop(signed short *SamplePtr, unsigned int SampleCount) { +unsigned int BS_AudioBuffer::Pop(signed short * SamplePtr, unsigned int SampleCount) +{ + EnterCriticalSection(&t->CS); + unsigned int i = 0; - for (; i < SampleCount && !_buffer.empty(); ++i) { - SamplePtr[i] = _buffer.front(); - _buffer.pop(); + for (; i < SampleCount && !t->Buffer.empty(); ++i) + { + SamplePtr[i] = t->Buffer.front(); + t->Buffer.pop(); } + LeaveCriticalSection(&t->CS); + return i; } // ----------------------------------------------------------------------------- -unsigned int AudioBuffer::Size() const { - unsigned int result = _buffer.size(); +unsigned int BS_AudioBuffer::Size() const +{ + EnterCriticalSection(&t->CS); + unsigned int result = t->Buffer.size(); + LeaveCriticalSection(&t->CS); return result; } - -} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.h b/engines/sword25/fmv/oggtheora/audiobuffer.h index fad227a2bc..0b4233bc4e 100644 --- a/engines/sword25/fmv/oggtheora/audiobuffer.h +++ b/engines/sword25/fmv/oggtheora/audiobuffer.h @@ -39,32 +39,30 @@ // Includes // ----------------------------------------------------------------------------- -#include "common/queue.h" #include "sword25/kernel/common.h" -namespace Sword25 { - // ----------------------------------------------------------------------------- -// Class definitions +// Klassendefinition // ----------------------------------------------------------------------------- -class AudioBuffer { +class BS_AudioBuffer +{ public: - AudioBuffer(); - virtual ~AudioBuffer(); + BS_AudioBuffer(); + virtual ~BS_AudioBuffer(); - void Push(signed short *SamplePtr, unsigned int SampleCount); - unsigned int Pop(signed short *SamplePtr, unsigned int SampleCount); + void Push(signed short * SamplePtr, unsigned int SampleCount); + unsigned int Pop(signed short * SamplePtr, unsigned int SampleCount); unsigned int Size() const; private: - Common::Queue _buffer; + // PIMPL Pattern + struct Impl; + Impl * t; // Kopie verbieten - AudioBuffer(const AudioBuffer &); - const AudioBuffer & operator=(const AudioBuffer &); + BS_AudioBuffer(const BS_AudioBuffer &); + const BS_AudioBuffer & operator=(const BS_AudioBuffer &); }; -} // End of namespace Sword25 - #endif diff --git a/engines/sword25/fmv/oggtheora/moviefile.cpp b/engines/sword25/fmv/oggtheora/moviefile.cpp index 33c214a1c2..b764ab2d22 100644 --- a/engines/sword25/fmv/oggtheora/moviefile.cpp +++ b/engines/sword25/fmv/oggtheora/moviefile.cpp @@ -47,37 +47,42 @@ #include "sword25/fmv/oggtheora/oggstate.h" #include "sword25/fmv/oggtheora/moviefile.h" -namespace Sword25 { - // ----------------------------------------------------------------------------- -MovieFile::MovieFile(const Common::String &Filename, unsigned int ReadBlockSize, bool &Success) : - m_Data(0), m_Size(0), m_ReadPos(0), m_ReadBlockSize(ReadBlockSize) { - m_Data = reinterpret_cast(Kernel::GetInstance()->GetPackage()->GetFile(Filename, &m_Size)); - if (!m_Data) { +BS_MovieFile::BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success) : + m_Data(0), m_Size(0), m_ReadPos(0), m_ReadBlockSize(ReadBlockSize) +{ + m_Data = reinterpret_cast(BS_Kernel::GetInstance()->GetPackage()->GetFile(Filename, &m_Size)); + if (!m_Data) + { BS_LOG_ERRORLN("Could not load movie file \"%s\".", Filename.c_str()); Success = false; - } else + } + else Success = true; } // ----------------------------------------------------------------------------- -MovieFile::~MovieFile() { +BS_MovieFile::~BS_MovieFile() +{ if (m_Data) delete [] m_Data; } // ----------------------------------------------------------------------------- -int MovieFile::BufferData(OggState &OggState) { - if (!m_Data || !m_Size || m_ReadPos >= m_Size) { +int BS_MovieFile::BufferData(BS_OggState & OggState) +{ + if (!m_Data || !m_Size || m_ReadPos >= m_Size) + { BS_LOG_ERRORLN("Tried to read past the movie buffer's end."); return 0; } // just grab some more compressed bitstream and sync it for page extraction - char *Buffer = OggState.SyncBuffer(m_ReadBlockSize); - if (!Buffer) { + char * Buffer = OggState.SyncBuffer(m_ReadBlockSize); + if (!Buffer) + { BS_LOG_ERRORLN("ogg_sync_buffer() failed."); return 0; } @@ -94,8 +99,7 @@ int MovieFile::BufferData(OggState &OggState) { // ----------------------------------------------------------------------------- -bool MovieFile::IsEOF() const { +bool BS_MovieFile::IsEOF() const +{ return m_ReadPos >= m_Size; } - -} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/moviefile.h b/engines/sword25/fmv/oggtheora/moviefile.h index bdae585d73..5aa0ef5617 100644 --- a/engines/sword25/fmv/oggtheora/moviefile.h +++ b/engines/sword25/fmv/oggtheora/moviefile.h @@ -41,22 +41,25 @@ #include "sword25/kernel/common.h" -namespace Sword25 { +#include "sword25/kernel/memlog_off.h" +#include +#include "sword25/kernel/memlog_on.h" // ----------------------------------------------------------------------------- -class OggState; +class BS_OggState; // ----------------------------------------------------------------------------- // Klassendefinition // ----------------------------------------------------------------------------- -class MovieFile { +class BS_MovieFile +{ public: - MovieFile(const Common::String &Filename, unsigned int ReadBlockSize, bool &Success); - virtual ~MovieFile(); + BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success); + virtual ~BS_MovieFile(); - int BufferData(OggState &OggState); + int BufferData(BS_OggState & OggState); bool IsEOF() const; private: @@ -66,6 +69,4 @@ private: unsigned int m_ReadBlockSize; }; -} // End of namespace Sword25 - #endif diff --git a/engines/sword25/fmv/oggtheora/oggstate.cpp b/engines/sword25/fmv/oggtheora/oggstate.cpp index 750fe382d4..11788ce53b 100644 --- a/engines/sword25/fmv/oggtheora/oggstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstate.cpp @@ -38,36 +38,37 @@ #include "sword25/fmv/oggtheora/oggstate.h" -namespace Sword25 { - // ----------------------------------------------------------------------------- -OggState::OggState() { +BS_OggState::BS_OggState() +{ ogg_sync_init(&m_SyncState); } // ----------------------------------------------------------------------------- -OggState::~OggState() { +BS_OggState::~BS_OggState() +{ ogg_sync_clear(&m_SyncState); } // ----------------------------------------------------------------------------- -int OggState::SyncPageout(ogg_page *OggPage) { +int BS_OggState::SyncPageout(ogg_page * OggPage) +{ return ogg_sync_pageout(&m_SyncState, OggPage); } // ----------------------------------------------------------------------------- -char *OggState::SyncBuffer(long Size) { +char * BS_OggState::SyncBuffer(long Size) +{ return ogg_sync_buffer(&m_SyncState, Size); } // ----------------------------------------------------------------------------- -int OggState::SyncWrote(long Bytes) { +int BS_OggState::SyncWrote(long Bytes) +{ return ogg_sync_wrote(&m_SyncState, Bytes); } - -} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/oggstate.h b/engines/sword25/fmv/oggtheora/oggstate.h index 7df178b681..1c25ca5e3a 100644 --- a/engines/sword25/fmv/oggtheora/oggstate.h +++ b/engines/sword25/fmv/oggtheora/oggstate.h @@ -40,37 +40,39 @@ // ----------------------------------------------------------------------------- #include "sword25/kernel/common.h" -#include - -namespace Sword25 { +#include "ogg/ogg.h" +// XXX +#include +// XXX // ----------------------------------------------------------------------------- -// Class definitions +// Klassendefinition // ----------------------------------------------------------------------------- -class OggState { +class BS_OggState +{ public: - OggState(); - virtual ~OggState(); + BS_OggState(); + virtual ~BS_OggState(); - int SyncPageout(ogg_page *OggPage); + int SyncPageout(ogg_page * OggPage); char * SyncBuffer(long Size); int SyncWrote(long Bytes); // XXX - void DumpInternals() { - warning("bodybytes: %d", m_SyncState.bodybytes); - warning("fill: %d", m_SyncState.fill); - warning("headerbytes: %d", m_SyncState.headerbytes ); - warning("returned: %d", m_SyncState.returned ); - warning("storage: %d", m_SyncState.storage ); - warning("unsynched: %d", m_SyncState.unsynced ); + void DumpInternals() + { + std::cout << "bodybytes: " << m_SyncState.bodybytes << std::endl; + std::cout << "fill: " << m_SyncState.fill << std::endl; + std::cout << "headerbytes: " << m_SyncState.headerbytes << std::endl; + std::cout << "returned: " << m_SyncState.returned << std::endl; + std::cout << "storage: " << m_SyncState.storage << std::endl; + std::cout << "unsynched: " << m_SyncState.unsynced << std::endl; + std::cout << std::endl; } // XXX private: ogg_sync_state m_SyncState; }; -} // End of namespace Sword25 - #endif diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp index 70388cf2b1..d787a96af2 100644 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp @@ -38,21 +38,22 @@ #include "sword25/fmv/oggtheora/oggstreamstate.h" -namespace Sword25 { - // ----------------------------------------------------------------------------- -OggStreamState::OggStreamState(int SerialNo) { +BS_OggStreamState::BS_OggStreamState(int SerialNo) +{ ogg_stream_init(&m_State, SerialNo); } // ----------------------------------------------------------------------------- -OggStreamState::~OggStreamState() { +BS_OggStreamState::~BS_OggStreamState() +{ ogg_stream_clear(&m_State); // Alle gepufferten Pages löschen. - while (!m_PageBuffer.empty()) { + while (!m_PageBuffer.empty()) + { delete [] m_PageBuffer.front().header; delete [] m_PageBuffer.front().body; m_PageBuffer.pop(); @@ -61,20 +62,24 @@ OggStreamState::~OggStreamState() { // ----------------------------------------------------------------------------- -int OggStreamState::PageIn(ogg_page *PagePtr) { +int BS_OggStreamState::PageIn(ogg_page * PagePtr) +{ return ogg_stream_pagein(&m_State, PagePtr); } // ----------------------------------------------------------------------------- -int OggStreamState::PacketOut(ogg_packet *PacketPtr) { +int BS_OggStreamState::PacketOut(ogg_packet * PacketPtr) +{ return ogg_stream_packetout(&m_State, PacketPtr); } // ----------------------------------------------------------------------------- -void OggStreamState::BufferPage(ogg_page *PagePtr) { - if (PageBelongsToStream(PagePtr)) { +void BS_OggStreamState::BufferPage(ogg_page * PagePtr) +{ + if (PageBelongsToStream(PagePtr)) + { // Pages können nicht direkt gespeichert werden, da die Pointer im Laufe der Zeit ungültig werden. // Daher wird an dieser Stelle eine tiefe Kopie der Page im erzeugt und im Pagebuffer angelegt. ogg_page PageCopy; @@ -91,8 +96,10 @@ void OggStreamState::BufferPage(ogg_page *PagePtr) { // ----------------------------------------------------------------------------- -int OggStreamState::PageInBufferedPage() { - if (GetPageBufferSize() > 0) { +int BS_OggStreamState::PageInBufferedPage() +{ + if (GetPageBufferSize() > 0) + { // Page in den Stream einfügen, löschen und aus dem Puffer entfernen. int Result = PageIn(&m_PageBuffer.front()); delete [] m_PageBuffer.front().header; @@ -106,20 +113,21 @@ int OggStreamState::PageInBufferedPage() { // ----------------------------------------------------------------------------- -unsigned int OggStreamState::GetPageBufferSize() const { +unsigned int BS_OggStreamState::GetPageBufferSize() const +{ return m_PageBuffer.size(); } // ----------------------------------------------------------------------------- -unsigned int OggStreamState::GetUnprocessedBytes() const { +unsigned int BS_OggStreamState::GetUnprocessedBytes() const +{ return m_State.body_fill - m_State.body_returned; } // ----------------------------------------------------------------------------- -bool OggStreamState::PageBelongsToStream(ogg_page *PagePtr) const { +bool BS_OggStreamState::PageBelongsToStream(ogg_page * PagePtr) const +{ return m_State.serialno == ogg_page_serialno(PagePtr); } - -} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.h b/engines/sword25/fmv/oggtheora/oggstreamstate.h index 3ed845c51d..7e291bd107 100644 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.h +++ b/engines/sword25/fmv/oggtheora/oggstreamstate.h @@ -40,46 +40,50 @@ // ----------------------------------------------------------------------------- #include "sword25/kernel/common.h" -#include -#include "common/queue.h" - -namespace Sword25 { +#include "ogg/ogg.h" +#include +// XXX +#include +// XXX // ----------------------------------------------------------------------------- -// Class definitions +// Klassendefinition // ----------------------------------------------------------------------------- -class OggStreamState { +class BS_OggStreamState +{ public: - OggStreamState(int SerialNo); - virtual ~OggStreamState(); + BS_OggStreamState(int SerialNo); + virtual ~BS_OggStreamState(); - int PageIn(ogg_page *PagePtr); - int PacketOut(ogg_packet *PacketPtr); + int PageIn(ogg_page * PagePtr); + int PacketOut(ogg_packet * PacketPtr); - void BufferPage(ogg_page *PagePtr); + void BufferPage(ogg_page * PagePtr); int PageInBufferedPage(); unsigned int GetPageBufferSize() const; unsigned int GetUnprocessedBytes() const; - bool PageBelongsToStream(ogg_page *PagePtr) const; + bool PageBelongsToStream(ogg_page * PagePtr) const; // XXX - void DumpInternals() { - warning("body_storage: %d", m_State.body_storage); - warning("body_fill: %d", m_State.body_fill); - warning("body_returned: %d", m_State.body_returned); - warning("lacing_storage: %d", m_State.lacing_storage); - warning("lacing_fill: %d", m_State.lacing_fill); - warning("lacing_returned: %d", m_State.lacing_returned); + void DumpInternals() + { + using namespace std; + + cout << "body_storage: " << m_State.body_storage << endl; + cout << "body_fill: " << m_State.body_fill << endl; + cout << "body_returned: " << m_State.body_returned << endl; + cout << "lacing_storage: " << m_State.lacing_storage << endl; + cout << "lacing_fill: " << m_State.lacing_fill << endl; + cout << "lacing_returned: " << m_State.lacing_returned << endl; + cout << endl; } // XXX private: ogg_stream_state m_State; - Common::Queue m_PageBuffer; + std::queue m_PageBuffer; }; -} // End of namespace Sword25 - #endif diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp new file mode 100644 index 0000000000..9d6eaa0baf --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggtheora.cpp @@ -0,0 +1,723 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ + +// The code in this file is based in part on code from the OggTheora Software +// codec source released under the following terms: +// +// Copyright (C) 2002-2007 Xiph.org Foundation +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions +// are met: +// +// - Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// - Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// - Neither the name of the Xiph.org Foundation nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION +// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +// ----------------------------------------------------------------------------- +// Logging +// ----------------------------------------------------------------------------- + +#define BS_LOG_PREFIX "OGGTHEORA" + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "sword25/kernel/memlog_off.h" +#include +#include "sword25/kernel/memlog_on.h" +#include + +#include "sword25/package/packagemanager.h" +#include "sword25/sfx/soundengine.h" +#include "sword25/gfx/graphicengine.h" +#include "sword25/gfx/panel.h" +#include "sword25/fmv/oggtheora/oggtheora.h" +#include "sword25/fmv/oggtheora/yuvtorgba.h" + +using namespace std; + +// ----------------------------------------------------------------------------- +// Konstanten und Hilfsfunktionen +// ----------------------------------------------------------------------------- + +namespace +{ + // -------------------------------------------------------------------------- + + const int MAX_FRAMES_PER_TICK = 10; + const int READ_BLOCK_SIZE = 1024 * 40; + const float MAX_AUDIO_BUFFER_LENGTH = 1.0f; + + // -------------------------------------------------------------------------- + + template + inline T Clamp(T x, T low, T high) + { + return ((x > high) ? high : (( x < low) ? low : x)); + } +} + +// ----------------------------------------------------------------------------- +// Konstruktion / Destruktion +// ----------------------------------------------------------------------------- + +BS_OggTheora::BS_OggTheora(BS_Kernel * pKernel) : BS_MoviePlayer(pKernel), m_SoundHandle(0) +{ + UnloadMovie(); +} + +// ----------------------------------------------------------------------------- + +BS_OggTheora::~BS_OggTheora() +{ + UnloadMovie(); +} + +// ----------------------------------------------------------------------------- + +BS_Service * BS_OggTheora_CreateObject(BS_Kernel* pKernel) { return new BS_OggTheora(pKernel); } + +// ----------------------------------------------------------------------------- +// BS_MoviePlayer Interface +// ----------------------------------------------------------------------------- + + +// ----------------------------------------------------------------------------- +// LoadMovie() mit Hilfsfunktionen +// ----------------------------------------------------------------------------- + +namespace +{ + inline bool VerifyRequiredServiceAvailability() + { + char * RequiredServices[] = { "gfx", "sfx", "package" }; + for (size_t i = 0; i < sizeof(RequiredServices) / sizeof(RequiredServices[0]); ++i) + { + if (!BS_Kernel::GetInstance()->GetService(RequiredServices[i])) + { + BS_LOG_ERRORLN("Required service \"%s\" is not active.", RequiredServices[i]); + return false; + } + } + + return true; + } + + // ------------------------------------------------------------------------- + + bool ParseStreamHeaders(auto_ptr & File, + auto_ptr & OggState, + auto_ptr & TheoraStreamState, + auto_ptr & VorbisStreamState, + auto_ptr & TheoraState, + auto_ptr & VorbisState, + bool & TheoraPresent, + bool & VorbisPresent, + const std::string & Filename) + { + TheoraPresent = false; + VorbisPresent = false; + + // Ogg file open; parse the headers + // Only interested in Vorbis/Theora streams + bool FinishedHeaderParsing = false; + while (!FinishedHeaderParsing) + { + if (File->BufferData(*OggState.get()) == 0) return false; + + ogg_page Page; + while(OggState->SyncPageout(&Page) > 0) + { + // is this a mandated initial header? If not, stop parsing + if(!ogg_page_bos(&Page)) + { + // don't leak the page; get it into the appropriate stream + if (TheoraPresent) TheoraStreamState->PageIn(&Page); + if (VorbisPresent) VorbisStreamState->PageIn(&Page); + + FinishedHeaderParsing = true; + break; + } + + auto_ptr streamState(new BS_OggStreamState(ogg_page_serialno(&Page))); + + streamState->PageIn(&Page); + + ogg_packet Packet; + streamState->PacketOut(&Packet); + + // identify the codec: try theora + if(!TheoraPresent && TheoraState->DecodeHeader(&Packet) >= 0) + { + // it is theora + TheoraStreamState = streamState; + TheoraPresent = true; + } + else if(!VorbisPresent && VorbisState->SynthesisHeaderIn(&Packet) >=0) + { + // it is vorbis + VorbisStreamState = streamState; + VorbisPresent = true; + } + } + // fall through to non-bos page parsing + } + + // we're expecting more header packets. + unsigned int TheoraPacketsRead = TheoraPresent ? 1 : 0; + unsigned int VorbisPacketsRead = VorbisPresent ? 1 : 0; + while((TheoraPresent && TheoraPacketsRead < 3) || (VorbisPresent && VorbisPacketsRead < 3)) + { + int ret; + ogg_packet Packet; + + // look for further theora headers + while(TheoraPresent && (TheoraPacketsRead < 3) && (ret = TheoraStreamState->PacketOut(&Packet))) + { + if(ret < 0 || TheoraState->DecodeHeader(&Packet)) + { + BS_LOG_ERRORLN("Error parsing Theora stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); + return false; + } + + ++TheoraPacketsRead; + if (TheoraPacketsRead == 3) break; + } + + // look for more vorbis header packets + while(VorbisPresent && (VorbisPacketsRead < 3) && (ret = VorbisStreamState->PacketOut(&Packet))) + { + if(ret < 0 || VorbisState->SynthesisHeaderIn(&Packet)) + { + BS_LOG_ERRORLN("Error parsing Vorbis stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); + return false; + } + + ++VorbisPacketsRead; + if (VorbisPacketsRead == 3) break; + } + + // The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec + ogg_page Page; + if(OggState->SyncPageout(&Page) > 0) + { + // demux into the appropriate stream + if(TheoraPresent) TheoraStreamState->PageIn(&Page); + if(VorbisPresent) VorbisStreamState->PageIn(&Page); + } + else + { + if(File->BufferData(*OggState.get()) == 0) + { + BS_LOG_ERRORLN("End of file while searching for codec headers. (%s)", Filename.c_str()); + return false; + } + } + } + + return true; + } +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::LoadMovie(const std::string & Filename, unsigned int Z) +{ + if (!VerifyRequiredServiceAvailability()) return false; + + UnloadMovie(); + + // Alle Objekte die in dieser Funktion erzeugt werden, werden in zunächst lokalen Auto-Pointern gehalten. + // Bei erfolgreicher Beendigung dieser Funktion werden sie den objektlokalen Auto-Pointern zugewiesen. + // So wird sichergestellt, dass sie korrekt deinitialisiert werden, wenn in dieser Funktion ein Fehler auftritt, denn beim Zerstören der + // lokalen Auto-Pointer werden die entsprechenden Destruktoren aufgerufen. + + // Film laden + // Für Filmdateien wird das Cachingsystem nicht benutzt, da Filme in der Regel nur ein Mal abgespielt werden. + bool Success; + auto_ptr File(new BS_MovieFile(Filename, READ_BLOCK_SIZE, Success)); + if (!Success) return false; + + // States erzeugen für Ogg, Vorbis und Theora, sowie die Ogg und Theora Streams + auto_ptr OggState(new BS_OggState()); + auto_ptr VorbisState(new BS_VorbisState()); + auto_ptr TheoraState(new BS_TheoraState()); + + auto_ptr TheoraStreamState; + auto_ptr VorbisStreamState; + + if (!ParseStreamHeaders(File, OggState, TheoraStreamState, VorbisStreamState, TheoraState, VorbisState, m_TheoraPresent, m_VorbisPresent, Filename)) return false; + + // Theora-Decoder Initialisieren + if(m_TheoraPresent) + { + TheoraState->DecodeInit(); + + const theora_info & TheoraInfo = TheoraState->GetInfo(); + + if (TheoraInfo.pixelformat != OC_PF_444 && + TheoraInfo.pixelformat != OC_PF_422 && + TheoraInfo.pixelformat != OC_PF_420) + { + BS_LOG_ERRORLN("Unknown chroma sampling. (%s)", Filename.c_str()); + return false; + } + + // Ausgabebitmap erstellen + BS_GraphicEngine * pGfx = BS_Kernel::GetInstance()->GetGfx(); + m_OutputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(TheoraInfo.frame_width, TheoraInfo.frame_height); + if (!m_OutputBitmap.IsValid()) + { + BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); + return false; + } + + // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. + float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); + float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); + float ScaleFactor = std::min(ScreenToVideoWidth, ScreenToVideoHeight); + if (ABS(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; + m_OutputBitmap->SetScaleFactor(ScaleFactor); + + // Z-Wert setzen + m_OutputBitmap->SetZ(Z); + + // Ausgabebitmap auf dem Bildschirm zentrieren + m_OutputBitmap->SetX((pGfx->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); + m_OutputBitmap->SetY((pGfx->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); + + // Buffer für die Pixeldaten erstellen + m_Pixels.resize(TheoraInfo.width * TheoraInfo.height * 4); + + m_VideoEnded = false; + } + + // Vorbis-Decoder initialisieren + if(m_VorbisPresent) + { + VorbisState->SynthesisInit(); + VorbisState->BlockInit(); + m_AudioBuffer.reset(new BS_AudioBuffer()); + + m_AudioEnded = false; + } + + // Keine Kopie, überträgt Besitz der erzeugten Objekte von der Funktion auf das Objekt. + m_File = File; + m_OggState = OggState; + m_TheoraState = TheoraState; + m_TheoraStreamState = TheoraStreamState; + m_VorbisState = VorbisState; + m_VorbisStreamState = VorbisStreamState; + m_MovieLoaded = true; + m_Timer = 0; + + return true; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::UnloadMovie() +{ + m_MovieLoaded = false; + m_Paused = true; + + m_VorbisStreamState.reset(); + m_VorbisPresent = false; + m_VorbisState.reset(); + if (m_SoundHandle) + { + BS_Kernel::GetInstance()->GetSfx()->StopSound(m_SoundHandle); + m_SoundHandle = 0; + } + m_AudioEnded = true; + m_AudioBuffer.reset(); + + m_TheoraStreamState.reset(); + m_TheoraPresent = false; + m_TheoraState.reset(); + m_VideoEnded = true; + + m_OggState.reset(); + + m_File.reset(); + + m_StartTime = 0; + m_LastFrameTime = 0; + m_Timer = 0.0f; + + vector().swap(m_Pixels); + m_OutputBitmap.Erase(); + + return true; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::Play() +{ + if (m_MovieLoaded) + { + if (m_Paused) + { + if (m_SoundHandle) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + SfxPtr->ResumeSound(m_SoundHandle); + } + m_Paused = false; + } + + return true; + } + else + { + BS_LOG_WARNINGLN("Cannot play movie, when no movie is loaded."); + return false; + } +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::Pause() +{ + if (m_MovieLoaded) + { + if (m_SoundHandle) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + SfxPtr->PauseSound(m_SoundHandle); + } + + m_Paused = true; + return true; + } + else + { + BS_LOG_WARNINGLN("Cannot pause movie, when no movie is loaded."); + return false; + } +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::ReadData() +{ + if (!m_File->IsEOF()) m_File->BufferData(*m_OggState.get()); + + ogg_page Page; + while(m_OggState->SyncPageout(&Page) > 0) + { + if(m_TheoraPresent) m_TheoraStreamState->BufferPage(&Page); + if(m_VorbisPresent) m_VorbisStreamState->BufferPage(&Page); + } +} + +void BS_OggTheora::Update() +{ + if (m_AudioEnded && m_VideoEnded) + { + m_Paused = true; + + // Falls der Sound noch läuft, muss er jetzt beendet werden. + if (m_SoundHandle) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + SfxPtr->StopSound(m_SoundHandle); + m_SoundHandle = 0; + } + } + + if (m_Paused) return; + + // Timer aktualisieren. + // Wird nur genutzt, wenn keine Audiodaten vorhanden sind. + m_Timer += BS_Kernel::GetInstance()->GetGfx()->GetSecondaryFrameDuration(); + + // Audiodaten dekodieren + if (m_VorbisPresent && !m_AudioEnded) DecodeVorbis(); + + + // Videodaten dekodieren + if (m_TheoraPresent && !m_VideoEnded) + { + bool Result = DecodeTheora(); + + if (Result) + { + // YUV Framebuffer holen + yuv_buffer YUVBuffer; + m_TheoraState->DecodeYUVOut(&YUVBuffer); + + // YUV Bilddaten nach RGBA konvertieren + BS_YUVtoRGBA::YUVtoRGBA(YUVBuffer, m_TheoraState->GetInfo(), m_Pixels); + + // RGBA Bilddaten auf das Ausgabebild kopieren, dabei die Postion des Theoraframes innerhalb des dekodierten Frames beachten. + const theora_info & TheoraInfo = m_TheoraState->GetInfo(); + m_OutputBitmap->SetContent(m_Pixels, (TheoraInfo.offset_x + TheoraInfo.width * TheoraInfo.offset_y) * 4, (TheoraInfo.width - TheoraInfo.frame_width) * 4); + } + } +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::DecodeTheora() +{ + double MovieTime = GetTime(); + + // Check if this frame time has not passed yet. If the frame is late we need + // to decode additonal ones and keep looping, since theora at this stage + // needs to decode all frames (due to keyframing) + // Getting the current time once at the beginning of the function rather than + // every time at the beginning of the loop produces the smoothest framerate + + unsigned int FramesDecoded = 0; + bool FrameReady = false; + while (m_TheoraState->GranuleTime() < MovieTime) + { + // theora is one in, one out... + ogg_packet Packet; + if(m_TheoraStreamState->PacketOut(&Packet) > 0) + { + if (FramesDecoded < MAX_FRAMES_PER_TICK || Packet.granulepos >= MovieTime) + { + m_TheoraState->DecodePacketIn(&Packet); + FrameReady = true; + ++FramesDecoded; + } + } + else + { + if (m_TheoraStreamState->GetPageBufferSize() > 0) + m_TheoraStreamState->PageInBufferedPage(); + else + { + if(m_File->IsEOF()) + { + m_VideoEnded = true; + break; + } + else + ReadData(); + } + } + } + m_LastFrameTime = MovieTime; + + return FrameReady; +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength) +{ + BS_OggTheora & t = *reinterpret_cast(UserData); + + signed short * Buffer = reinterpret_cast(Data); + + // Audiodaten in den Soundbuffer schreiben. + DataLength -= t.m_AudioBuffer->Pop(Buffer, DataLength / 2) * 2; + + // Falls nicht genug Audiodaten vorhanden waren, wird der Rest mit Stille überschrieben. + if (DataLength) + { + char * ByteBuffer = reinterpret_cast(Buffer); + while (DataLength--) + { + *ByteBuffer++ = 0; + } + } +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::DecodeVorbis() +{ + // Vorbis-Stream Infos holen. + const vorbis_info & Info = m_VorbisState->GetInfo(); + + // Maximalgröße des Audiobuffers berechnen. + size_t MaxAudioBufferSamples = static_cast(Info.channels * Info.rate * MAX_AUDIO_BUFFER_LENGTH); + + // Zwischenspeicher für die Samples. + vector Samples; + + // Audiobuffer bis zur Maximalgröße füllen, wenn möglich. + while (m_AudioBuffer->Size() < MaxAudioBufferSamples) + { + // Vorhandene Audiodaten auslesen + float ** PCM; + int SampleCount = m_VorbisState->SynthesisPCMout(&PCM); + + // Wenn Audiodaten gelesen werden konnten, werden diese in 16-Bit Sample umgewandelt und in den Audiobuffer geschrieben. + if(SampleCount > 0) + { + // Im Samplezwischenspeicher leeren und genügend Platz für die kommenden Samples reservieren. + Samples.reserve(SampleCount); + Samples.clear(); + + // Samples konvertieren und in die Samplezwischenspeicher schreiben. + for (int i = 0; i < SampleCount; ++i) + { + for(int j = 0; j < Info.channels; ++j) + { + int SampleValue = static_cast(PCM[j][i] * 32767.0f); + Samples.push_back(Clamp(SampleValue, -32700, 32700)); + } + } + + // Daten aus dem Samplezwischenspeicher in den Audiobuffer schreiben. + m_AudioBuffer->Push(&Samples[0], Samples.size()); + + // Vorbis mitteilen, dass wir alle Samples gelesen haben. + m_VorbisState->SynthesisRead(SampleCount); + } + else + { + // Wir konnten, keine Audiodaten auslesen, versuchen ein neues Paket zu dekodieren. + ogg_packet Packet; + if(m_VorbisStreamState->PacketOut(&Packet) > 0) + { + if (m_VorbisState->Synthesis(&Packet) == 0) m_VorbisState->SynthesisBlockIn(); + } + else + { + // Gepufferte Daten in den Stream einfügen. + if (m_VorbisStreamState->GetPageBufferSize() > 0) + m_VorbisStreamState->PageInBufferedPage(); + else + { + // Nicht genug Daten vorhanden. Wenn die Datei leer ist und bereits alle Audiodaten gelesen wurden, ist der Audiostream am Ende. + // Ansonsten Daten nachladen. + if(m_File->IsEOF()) + { + if (m_AudioBuffer->Size() == 0) + { + m_AudioEnded = true; + } + + break; + } + else + ReadData(); + } + } + } + } + + // Soundkanal abspielen, wenn er noch nicht spielt und Audiodaten vorhanden sind. + if (m_SoundHandle == 0 && m_AudioBuffer->Size()) + { + BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); + m_SoundHandle = SfxPtr->PlayDynamicSoundEx(&DynamicSoundCallBack, this, BS_SoundEngine::SFX, Info.rate, 16, Info.channels); + } +} + +// ----------------------------------------------------------------------------- + +double BS_OggTheora::GetTime() +{ + if(m_VorbisPresent) + { + if (m_SoundHandle) + { + float time = BS_Kernel::GetInstance()->GetSfx()->GetSoundTime(m_SoundHandle); + return time; + } + else + return 0.0f; + } + else + return m_Timer; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::IsMovieLoaded() +{ + return m_MovieLoaded; +} + +// ----------------------------------------------------------------------------- + +bool BS_OggTheora::IsPaused() +{ + return m_Paused; +} + +// ----------------------------------------------------------------------------- + +float BS_OggTheora::GetScaleFactor() +{ + if (m_MovieLoaded) + return m_OutputBitmap->GetScaleFactorX(); + else + return 0; +} + +// ----------------------------------------------------------------------------- + +void BS_OggTheora::SetScaleFactor(float ScaleFactor) +{ + if (m_MovieLoaded) + { + m_OutputBitmap->SetScaleFactor(ScaleFactor); + + // Ausgabebitmap auf dem Bildschirm zentrieren + BS_GraphicEngine * GfxPtr = BS_Kernel::GetInstance()->GetGfx(); + m_OutputBitmap->SetX((GfxPtr->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); + m_OutputBitmap->SetY((GfxPtr->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); + } +} diff --git a/engines/sword25/fmv/oggtheora/oggtheora.h b/engines/sword25/fmv/oggtheora/oggtheora.h new file mode 100644 index 0000000000..62fa607935 --- /dev/null +++ b/engines/sword25/fmv/oggtheora/oggtheora.h @@ -0,0 +1,124 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ + +#ifndef SWORD25_OGGTHEORA_H +#define SWORD25_OGGTHEORA_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "sword25/kernel/memlog_off.h" +#include +#include +#include +#include "sword25/kernel/memlog_on.h" + +#include "sword25/kernel/common.h" +#include "sword25/kernel/bs_stdint.h" +#include "sword25/gfx/bitmap.h" +#include "sword25/gfx/renderobjectptr.h" +#include "sword25/fmv/movieplayer.h" +#include "sword25/fmv/oggtheora/vorbisstate.h" +#include "sword25/fmv/oggtheora/theorastate.h" +#include "sword25/fmv/oggtheora/oggstate.h" +#include "sword25/fmv/oggtheora/oggstreamstate.h" +#include "sword25/fmv/oggtheora/moviefile.h" +#include "sword25/fmv/oggtheora/audiobuffer.h" + +// ----------------------------------------------------------------------------- +// Klassendefinition +// ----------------------------------------------------------------------------- + +class BS_OggTheora : public BS_MoviePlayer +{ +public: + // ----------------------------------------------------------------------------- + // Konstruktion / Destruktion + // ----------------------------------------------------------------------------- + + BS_OggTheora(BS_Kernel * pKernel); + virtual ~BS_OggTheora(); + + // ----------------------------------------------------------------------------- + // BS_MoviePlayer Interface + // ----------------------------------------------------------------------------- + + virtual bool LoadMovie(const std::string & Filename, unsigned int Z); + virtual bool UnloadMovie(); + virtual bool Play(); + virtual bool Pause(); + virtual void Update(); + virtual bool IsMovieLoaded(); + virtual bool IsPaused(); + virtual float GetScaleFactor(); + virtual void SetScaleFactor(float ScaleFactor); + virtual double GetTime(); + +private: + bool DecodeTheora(); + void DecodeVorbis(); + void RefillOggBuffer(); + void ReadData(); + static void DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength); + + bool m_MovieLoaded; + bool m_Paused; + + std::auto_ptr m_VorbisStreamState; + bool m_VorbisPresent; + std::auto_ptr m_VorbisState; + unsigned int m_SoundHandle; + bool m_AudioEnded; + std::auto_ptr m_AudioBuffer; + + std::auto_ptr m_TheoraStreamState; + bool m_TheoraPresent; + std::auto_ptr m_TheoraState; + bool m_VideoEnded; + + std::auto_ptr m_OggState; + + std::auto_ptr m_File; + + uint64_t m_StartTime; + double m_LastFrameTime; + + float m_Timer; + + std::vector m_Pixels; + BS_RenderObjectPtr m_OutputBitmap; +}; + +#endif diff --git a/engines/sword25/fmv/oggtheora/theorastate.cpp b/engines/sword25/fmv/oggtheora/theorastate.cpp index 2284098d2f..a270bab80c 100644 --- a/engines/sword25/fmv/oggtheora/theorastate.cpp +++ b/engines/sword25/fmv/oggtheora/theorastate.cpp @@ -38,19 +38,19 @@ #include "sword25/fmv/oggtheora/theorastate.h" -namespace Sword25 { - // ----------------------------------------------------------------------------- -TheoraState::TheoraState() : - m_StateInitialized(false) { +BS_TheoraState::BS_TheoraState() : + m_StateInitialized(false) +{ theora_comment_init(&m_Comment); theora_info_init(&m_Info); } // ----------------------------------------------------------------------------- -TheoraState::~TheoraState() { +BS_TheoraState::~BS_TheoraState() +{ if (m_StateInitialized) theora_clear(&m_State); theora_info_clear(&m_Info); theora_comment_clear(&m_Comment); @@ -58,13 +58,15 @@ TheoraState::~TheoraState() { // ----------------------------------------------------------------------------- -int TheoraState::DecodeHeader(ogg_packet *OggPacketPtr) { +int BS_TheoraState::DecodeHeader(ogg_packet * OggPacketPtr) +{ return theora_decode_header(&m_Info, &m_Comment, OggPacketPtr); } // ----------------------------------------------------------------------------- -int TheoraState::DecodeInit() { +int BS_TheoraState::DecodeInit() +{ int Result = theora_decode_init(&m_State, &m_Info); m_StateInitialized = (Result == 0); return Result; @@ -72,20 +74,21 @@ int TheoraState::DecodeInit() { // ----------------------------------------------------------------------------- -double TheoraState::GranuleTime() { +double BS_TheoraState::GranuleTime() +{ return theora_granule_time(&m_State, m_State.granulepos); } // ----------------------------------------------------------------------------- -int TheoraState::DecodePacketIn(ogg_packet *OggPacketPtr) { +int BS_TheoraState::DecodePacketIn(ogg_packet * OggPacketPtr) +{ return theora_decode_packetin(&m_State, OggPacketPtr); } // ----------------------------------------------------------------------------- -int TheoraState::DecodeYUVOut(yuv_buffer *YUV) { +int BS_TheoraState::DecodeYUVOut(yuv_buffer * YUV) +{ return theora_decode_YUVout(&m_State, YUV); } - -} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/theorastate.h b/engines/sword25/fmv/oggtheora/theorastate.h index 967ca259ad..07934c26ea 100644 --- a/engines/sword25/fmv/oggtheora/theorastate.h +++ b/engines/sword25/fmv/oggtheora/theorastate.h @@ -42,21 +42,20 @@ #include "sword25/kernel/common.h" #include -namespace Sword25 { - // ----------------------------------------------------------------------------- -// Class definitions +// Klassendefinition // ----------------------------------------------------------------------------- -class TheoraState { +class BS_TheoraState +{ public: - TheoraState(); - virtual ~TheoraState(); + BS_TheoraState(); + virtual ~BS_TheoraState(); - int DecodeHeader(ogg_packet *OggPacketPtr); + int DecodeHeader(ogg_packet * OggPacketPtr); int DecodeInit(); - int DecodePacketIn(ogg_packet *OggPacketPtr); - int DecodeYUVOut(yuv_buffer *YUV); + int DecodePacketIn(ogg_packet * OggPacketPtr); + int DecodeYUVOut(yuv_buffer * YUV); double GranuleTime(); const theora_info & GetInfo() const { return m_Info; } @@ -68,6 +67,4 @@ private: theora_state m_State; }; -} // End of namespace Sword25 - #endif diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.cpp b/engines/sword25/fmv/oggtheora/vorbisstate.cpp index 53085a9832..e9f6b7dc4f 100644 --- a/engines/sword25/fmv/oggtheora/vorbisstate.cpp +++ b/engines/sword25/fmv/oggtheora/vorbisstate.cpp @@ -38,20 +38,20 @@ #include "sword25/fmv/oggtheora/vorbisstate.h" -namespace Sword25 { - // ----------------------------------------------------------------------------- -VorbisState::VorbisState() : - m_DSPStateInitialized(false), - m_BlockInitialized(false) { +BS_VorbisState::BS_VorbisState() : + m_DSPStateInitialized(false), + m_BlockInitialized(false) +{ vorbis_info_init(&m_Info); vorbis_comment_init(&m_Comment); } // ----------------------------------------------------------------------------- -VorbisState::~VorbisState() { +BS_VorbisState::~BS_VorbisState() +{ if (m_BlockInitialized) vorbis_block_clear(&m_Block); if (m_DSPStateInitialized) vorbis_dsp_clear(&m_DSPState); vorbis_comment_clear(&m_Comment); @@ -60,13 +60,15 @@ VorbisState::~VorbisState() { // ----------------------------------------------------------------------------- -int VorbisState::SynthesisHeaderIn(ogg_packet *OggPacketPtr) { +int BS_VorbisState::SynthesisHeaderIn(ogg_packet * OggPacketPtr) +{ return vorbis_synthesis_headerin(&m_Info, &m_Comment, OggPacketPtr); } // ----------------------------------------------------------------------------- -int VorbisState::SynthesisInit() { +int BS_VorbisState::SynthesisInit() +{ int Result = vorbis_synthesis_init(&m_DSPState, &m_Info); m_DSPStateInitialized = (Result == 0); return Result; @@ -74,7 +76,8 @@ int VorbisState::SynthesisInit() { // ----------------------------------------------------------------------------- -int VorbisState::BlockInit() { +int BS_VorbisState::BlockInit() +{ int Result = vorbis_block_init(&m_DSPState, &m_Block); m_BlockInitialized = (Result == 0); return Result; @@ -82,26 +85,28 @@ int VorbisState::BlockInit() { // ----------------------------------------------------------------------------- -int VorbisState::SynthesisPCMout(float ***PCM) { +int BS_VorbisState::SynthesisPCMout(float *** PCM) +{ return vorbis_synthesis_pcmout(&m_DSPState, PCM); } // ----------------------------------------------------------------------------- -int VorbisState::SynthesisRead(int Samples) { +int BS_VorbisState::SynthesisRead(int Samples) +{ return vorbis_synthesis_read(&m_DSPState, Samples); } // ----------------------------------------------------------------------------- -int VorbisState::Synthesis(ogg_packet *OggPacketPtr) { +int BS_VorbisState::Synthesis(ogg_packet * OggPacketPtr) +{ return vorbis_synthesis(&m_Block, OggPacketPtr); } // ----------------------------------------------------------------------------- -int VorbisState::SynthesisBlockIn() { +int BS_VorbisState::SynthesisBlockIn() +{ return vorbis_synthesis_blockin(&m_DSPState, &m_Block); } - -} // End of namespace Sword25 diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.h b/engines/sword25/fmv/oggtheora/vorbisstate.h index 4a87f13d9e..126e59d0aa 100644 --- a/engines/sword25/fmv/oggtheora/vorbisstate.h +++ b/engines/sword25/fmv/oggtheora/vorbisstate.h @@ -42,26 +42,25 @@ #include "sword25/kernel/common.h" #include -namespace Sword25 { - // ----------------------------------------------------------------------------- -// Class definitions +// Klassendefinition // ----------------------------------------------------------------------------- -class VorbisState { +class BS_VorbisState +{ public: - VorbisState(); - virtual ~VorbisState(); + BS_VorbisState(); + virtual ~BS_VorbisState(); - int SynthesisHeaderIn(ogg_packet *OggPacketPtr); + int SynthesisHeaderIn(ogg_packet * OggPacketPtr); int SynthesisInit(); int BlockInit(); - int SynthesisPCMout(float ***PCM); + int SynthesisPCMout(float *** PCM); int SynthesisRead(int Samples); - int Synthesis(ogg_packet *OggPacketPtr); + int Synthesis(ogg_packet * OggPacketPtr); int SynthesisBlockIn(); - const vorbis_info &GetInfo() const { return m_Info; } + const vorbis_info & GetInfo() const { return m_Info; } private: vorbis_info m_Info; @@ -72,6 +71,4 @@ private: vorbis_comment m_Comment; }; -} // End of namespace Sword25 - #endif diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp index 2c950745f1..d835d2ba0b 100644 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp @@ -36,213 +36,396 @@ // Includes // ----------------------------------------------------------------------------- -#include "sword25/fmv/oggtheora/yuvtorgba.h" +#include "sword25/kernel/cpuinfo.h" +#include "sword25/fmv/ogghteora/yuvtorgba.h" + +#include + +using namespace std; // ----------------------------------------------------------------------------- -namespace Sword25 { - -static const int PRECISION = 32768; -static const int COEFFS_Y[256] = { - -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, - 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, - 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, - 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, - 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, - 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, - 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, - 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, - 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, - 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, - 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, - 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, - 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, - 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, - 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, - 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, -}; -static const int COEFFS_RV[256] = { - -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, - -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, - -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, - -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, - -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, - -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, - -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, - -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, - 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, - 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, - 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, - 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, - 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, - 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, - 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, - 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, -}; -static const int COEFFS_GU[256] = { - 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, - 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, - 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, - 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, - 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, - 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, - 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, - 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, - 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, - -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, - -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, - -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, - -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, - -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, - -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, - -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, -}; -static const int COEFFS_GV[256] = { - 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, - 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, - 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, - 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, - 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, - 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, - 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, - 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, - 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, - -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, - -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, - -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, - -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, - -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, - -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, - -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, -}; -static const int COEFFS_BU[256] = { - -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, - -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, - -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, - -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, - -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, - -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, - -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, - -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, - 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, - 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, - 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, - 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, - 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, - 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, - 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, - 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, -}; -static const int CLAMP_TAB[1024] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, -}; - -void BS_YUVtoRGBA::YUVtoRGBA(yuv_buffer &YUVBuffer, const theora_info &TheoraInfo, byte *Pixels, int PixelsSize) { - BS_ASSERT(TheoraInfo.pixelformat == OC_PF_420); - BS_ASSERT(PixelsSize >= (YUVBuffer.y_width * YUVBuffer.y_height)); - - // Width and height of all buffers have to be divisible by 2. - BS_ASSERT((YUVBuffer.y_width & 1) == 0); - BS_ASSERT((YUVBuffer.y_height & 1) == 0); - BS_ASSERT((YUVBuffer.uv_width & 1) == 0); - BS_ASSERT((YUVBuffer.uv_height & 1) == 0); - // UV images have to have a quarter of the Y image resolution - BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); - BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); - - const int *cl = &CLAMP_TAB[320]; - - const unsigned char *ySrc0 = YUVBuffer.y; - const unsigned char *ySrc1 = YUVBuffer.y + YUVBuffer.y_stride; - const unsigned char *uSrc = YUVBuffer.u; - const unsigned char *vSrc = YUVBuffer.v; - unsigned char *dst0 = &Pixels[0]; - unsigned char *dst1 = &Pixels[0] + YUVBuffer.y_width * 4; - - for (int h = 0; h < YUVBuffer.y_height / 2; ++h) { - for (int w = 0; w < YUVBuffer.y_width / 2; ++w) { - int u = *uSrc++; - int v = *vSrc++; - - int rUV = COEFFS_RV[v]; - int gUV = COEFFS_GU[u] + COEFFS_GV[v]; - int bUV = COEFFS_BU[u]; - - int y = *ySrc0++; - int r = COEFFS_Y[y] + rUV; - int g = COEFFS_Y[y] + gUV; - int b = COEFFS_Y[y] + bUV; - *dst0++ = cl[r / PRECISION]; - *dst0++ = cl[g / PRECISION]; - *dst0++ = cl[b / PRECISION]; - *dst0++ = 255; - - y = *ySrc1++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst1++ = cl[r / PRECISION]; - *dst1++ = cl[g / PRECISION]; - *dst1++ = cl[b / PRECISION]; - *dst1++ = 255; - - y = *ySrc0++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst0++ = cl[r / PRECISION]; - *dst0++ = cl[g / PRECISION]; - *dst0++ = cl[b / PRECISION]; - *dst0++ = 255; - - y = *ySrc1++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst1++ = cl[r / PRECISION]; - *dst1++ = cl[g / PRECISION]; - *dst1++ = cl[b / PRECISION]; - *dst1++ = 255; +namespace +{ + + static const int PRECISION = 32768; + static const int COEFFS_Y[256] = { + -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, + 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, + 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, + 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, + 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, + 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, + 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, + 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, + 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, + 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, + 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, + 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, + 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, + 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, + 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, + 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, + }; + static const int COEFFS_RV[256] = { + -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, + -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, + -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, + -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, + -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, + -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, + -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, + -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, + 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, + 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, + 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, + 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, + 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, + 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, + 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, + 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, + }; + static const int COEFFS_GU[256] = { + 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, + 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, + 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, + 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, + 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, + 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, + 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, + 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, + 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, + -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, + -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, + -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, + -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, + -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, + -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, + -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, + }; + static const int COEFFS_GV[256] = { + 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, + 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, + 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, + 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, + 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, + 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, + 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, + 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, + 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, + -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, + -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, + -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, + -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, + -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, + -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, + -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, + }; + static const int COEFFS_BU[256] = { + -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, + -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, + -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, + -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, + -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, + -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, + -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, + -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, + 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, + 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, + 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, + 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, + 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, + 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, + 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, + 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, + }; + static const int CLAMP_TAB[1024] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + }; + + void YUVtoRGBA_c(const yuv_buffer & YUVBuffer, std::vector & PixelData) + { + // Width and height of all buffers have to be divisible by 2. + BS_ASSERT((YUVBuffer.y_width & 1) == 0); + BS_ASSERT((YUVBuffer.y_height & 1) == 0); + BS_ASSERT((YUVBuffer.uv_width & 1) == 0); + BS_ASSERT((YUVBuffer.uv_height & 1) == 0); + // UV images have to have a quarter of the Y image resolution + BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); + BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); + + const int *cl = &CLAMP_TAB[320]; + + const unsigned char * ySrc0 = YUVBuffer.y; + const unsigned char * ySrc1 = YUVBuffer.y + YUVBuffer.y_stride; + const unsigned char * uSrc = YUVBuffer.u; + const unsigned char * vSrc = YUVBuffer.v; + unsigned char * dst0 = &PixelData[0]; + unsigned char * dst1 = &PixelData[0] + YUVBuffer.y_width * 4; + + for (int h = 0; h < YUVBuffer.y_height / 2; ++h) + { + for (int w = 0; w < YUVBuffer.y_width / 2; ++w) + { + int u = *uSrc++; + int v = *vSrc++; + + int rUV = COEFFS_RV[v]; + int gUV = COEFFS_GU[u] + COEFFS_GV[v]; + int bUV = COEFFS_BU[u]; + + int y = *ySrc0++; + int r = COEFFS_Y[y] + rUV; + int g = COEFFS_Y[y] + gUV; + int b = COEFFS_Y[y] + bUV; + *dst0++ = cl[r / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[b / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[r / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[b / PRECISION]; + *dst1++ = 255; + + y = *ySrc0++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst0++ = cl[r / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[b / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[r / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[b / PRECISION]; + *dst1++ = 255; + } + + dst0 += YUVBuffer.y_width * 4; + dst1 += YUVBuffer.y_width * 4; + ySrc0 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; + ySrc1 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; + uSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; + vSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; } + } + + // ----------------------------------------------------------------------------- + + static const __m64 COEFF_Y_MMX[256] = { + 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, + 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, + 0x1fff000000000000, 0x1fff004a004a004a, 0x1fff009500950095, 0x1fff00df00df00df, 0x1fff012a012a012a, 0x1fff017401740174, 0x1fff01bf01bf01bf, 0x1fff020902090209, + 0x1fff025402540254, 0x1fff029e029e029e, 0x1fff02e902e902e9, 0x1fff033303330333, 0x1fff037e037e037e, 0x1fff03c803c803c8, 0x1fff041304130413, 0x1fff045d045d045d, + 0x1fff04a804a804a8, 0x1fff04f204f204f2, 0x1fff053d053d053d, 0x1fff058705870587, 0x1fff05d205d205d2, 0x1fff061c061c061c, 0x1fff066706670667, 0x1fff06b106b106b1, + 0x1fff06fc06fc06fc, 0x1fff074607460746, 0x1fff079107910791, 0x1fff07db07db07db, 0x1fff082608260826, 0x1fff087008700870, 0x1fff08bb08bb08bb, 0x1fff090509050905, + 0x1fff095009500950, 0x1fff099a099a099a, 0x1fff09e509e509e5, 0x1fff0a2f0a2f0a2f, 0x1fff0a7a0a7a0a7a, 0x1fff0ac40ac40ac4, 0x1fff0b0f0b0f0b0f, 0x1fff0b590b590b59, + 0x1fff0ba40ba40ba4, 0x1fff0bee0bee0bee, 0x1fff0c390c390c39, 0x1fff0c830c830c83, 0x1fff0cce0cce0cce, 0x1fff0d180d180d18, 0x1fff0d630d630d63, 0x1fff0dad0dad0dad, + 0x1fff0df80df80df8, 0x1fff0e420e420e42, 0x1fff0e8d0e8d0e8d, 0x1fff0ed70ed70ed7, 0x1fff0f220f220f22, 0x1fff0f6c0f6c0f6c, 0x1fff0fb70fb70fb7, 0x1fff100110011001, + 0x1fff104c104c104c, 0x1fff109610961096, 0x1fff10e110e110e1, 0x1fff112b112b112b, 0x1fff117611761176, 0x1fff11c011c011c0, 0x1fff120b120b120b, 0x1fff125512551255, + 0x1fff12a012a012a0, 0x1fff12ea12ea12ea, 0x1fff133513351335, 0x1fff137f137f137f, 0x1fff13ca13ca13ca, 0x1fff141414141414, 0x1fff145f145f145f, 0x1fff14a914a914a9, + 0x1fff14f414f414f4, 0x1fff153e153e153e, 0x1fff158915891589, 0x1fff15d315d315d3, 0x1fff161e161e161e, 0x1fff166816681668, 0x1fff16b316b316b3, 0x1fff16fd16fd16fd, + 0x1fff174817481748, 0x1fff179217921792, 0x1fff17dd17dd17dd, 0x1fff182718271827, 0x1fff187218721872, 0x1fff18bc18bc18bc, 0x1fff190719071907, 0x1fff195119511951, + 0x1fff199c199c199c, 0x1fff19e619e619e6, 0x1fff1a311a311a31, 0x1fff1a7b1a7b1a7b, 0x1fff1ac61ac61ac6, 0x1fff1b101b101b10, 0x1fff1b5b1b5b1b5b, 0x1fff1ba51ba51ba5, + 0x1fff1bf01bf01bf0, 0x1fff1c3a1c3a1c3a, 0x1fff1c851c851c85, 0x1fff1ccf1ccf1ccf, 0x1fff1d1a1d1a1d1a, 0x1fff1d641d641d64, 0x1fff1daf1daf1daf, 0x1fff1df91df91df9, + 0x1fff1e441e441e44, 0x1fff1e8e1e8e1e8e, 0x1fff1ed91ed91ed9, 0x1fff1f231f231f23, 0x1fff1f6e1f6e1f6e, 0x1fff1fb81fb81fb8, 0x1fff200320032003, 0x1fff204d204d204d, + 0x1fff209820982098, 0x1fff20e220e220e2, 0x1fff212d212d212d, 0x1fff217721772177, 0x1fff21c221c221c2, 0x1fff220c220c220c, 0x1fff225722572257, 0x1fff22a122a122a1, + 0x1fff22ec22ec22ec, 0x1fff233623362336, 0x1fff238123812381, 0x1fff23cb23cb23cb, 0x1fff241624162416, 0x1fff246024602460, 0x1fff24aa24aa24aa, 0x1fff24f524f524f5, + 0x1fff253f253f253f, 0x1fff258a258a258a, 0x1fff25d425d425d4, 0x1fff261f261f261f, 0x1fff266926692669, 0x1fff26b426b426b4, 0x1fff26fe26fe26fe, 0x1fff274927492749, + 0x1fff279327932793, 0x1fff27de27de27de, 0x1fff282828282828, 0x1fff287328732873, 0x1fff28bd28bd28bd, 0x1fff290829082908, 0x1fff295229522952, 0x1fff299d299d299d, + 0x1fff29e729e729e7, 0x1fff2a322a322a32, 0x1fff2a7c2a7c2a7c, 0x1fff2ac72ac72ac7, 0x1fff2b112b112b11, 0x1fff2b5c2b5c2b5c, 0x1fff2ba62ba62ba6, 0x1fff2bf12bf12bf1, + 0x1fff2c3b2c3b2c3b, 0x1fff2c862c862c86, 0x1fff2cd02cd02cd0, 0x1fff2d1b2d1b2d1b, 0x1fff2d652d652d65, 0x1fff2db02db02db0, 0x1fff2dfa2dfa2dfa, 0x1fff2e452e452e45, + 0x1fff2e8f2e8f2e8f, 0x1fff2eda2eda2eda, 0x1fff2f242f242f24, 0x1fff2f6f2f6f2f6f, 0x1fff2fb92fb92fb9, 0x1fff300430043004, 0x1fff304e304e304e, 0x1fff309930993099, + 0x1fff30e330e330e3, 0x1fff312e312e312e, 0x1fff317831783178, 0x1fff31c331c331c3, 0x1fff320d320d320d, 0x1fff325832583258, 0x1fff32a232a232a2, 0x1fff32ed32ed32ed, + 0x1fff333733373337, 0x1fff338233823382, 0x1fff33cc33cc33cc, 0x1fff341734173417, 0x1fff346134613461, 0x1fff34ac34ac34ac, 0x1fff34f634f634f6, 0x1fff354135413541, + 0x1fff358b358b358b, 0x1fff35d635d635d6, 0x1fff362036203620, 0x1fff366b366b366b, 0x1fff36b536b536b5, 0x1fff370037003700, 0x1fff374a374a374a, 0x1fff379537953795, + 0x1fff37df37df37df, 0x1fff382a382a382a, 0x1fff387438743874, 0x1fff38bf38bf38bf, 0x1fff390939093909, 0x1fff395439543954, 0x1fff399e399e399e, 0x1fff39e939e939e9, + 0x1fff3a333a333a33, 0x1fff3a7e3a7e3a7e, 0x1fff3ac83ac83ac8, 0x1fff3b133b133b13, 0x1fff3b5d3b5d3b5d, 0x1fff3ba83ba83ba8, 0x1fff3bf23bf23bf2, 0x1fff3c3d3c3d3c3d, + 0x1fff3c873c873c87, 0x1fff3cd23cd23cd2, 0x1fff3d1c3d1c3d1c, 0x1fff3d673d673d67, 0x1fff3db13db13db1, 0x1fff3dfc3dfc3dfc, 0x1fff3e463e463e46, 0x1fff3e913e913e91, + 0x1fff3edb3edb3edb, 0x1fff3f263f263f26, 0x1fff3f703f703f70, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, + 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, + 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, + }; + static const __m64 COEFF_U_MMX[256] = { + 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, + 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, + 0x1fffc7800af30000, 0x1fffc8010ada0000, 0x1fffc8820ac10000, 0x1fffc9030aa80000, 0x1fffc9850a8f0000, 0x1fffca060a760000, 0x1fffca870a5d0000, 0x1fffcb080a440000, + 0x1fffcb890a2a0000, 0x1fffcc0a0a110000, 0x1fffcc8b09f80000, 0x1fffcd0d09df0000, 0x1fffcd8e09c60000, 0x1fffce0f09ad0000, 0x1fffce9009940000, 0x1fffcf11097b0000, + 0x1fffcf9209620000, 0x1fffd01409490000, 0x1fffd09509300000, 0x1fffd11609170000, 0x1fffd19708fe0000, 0x1fffd21808e50000, 0x1fffd29908cc0000, 0x1fffd31a08b30000, + 0x1fffd39c089a0000, 0x1fffd41d08810000, 0x1fffd49e08680000, 0x1fffd51f084f0000, 0x1fffd5a008360000, 0x1fffd621081d0000, 0x1fffd6a308040000, 0x1fffd72407eb0000, + 0x1fffd7a507d20000, 0x1fffd82607b90000, 0x1fffd8a707a00000, 0x1fffd92807870000, 0x1fffd9a9076e0000, 0x1fffda2b07550000, 0x1fffdaac073c0000, 0x1fffdb2d07230000, + 0x1fffdbae070a0000, 0x1fffdc2f06f10000, 0x1fffdcb006d80000, 0x1fffdd3206bf0000, 0x1fffddb306a60000, 0x1fffde34068d0000, 0x1fffdeb506740000, 0x1fffdf36065b0000, + 0x1fffdfb706420000, 0x1fffe03806290000, 0x1fffe0ba060f0000, 0x1fffe13b05f60000, 0x1fffe1bc05dd0000, 0x1fffe23d05c40000, 0x1fffe2be05ab0000, 0x1fffe33f05920000, + 0x1fffe3c005790000, 0x1fffe44205600000, 0x1fffe4c305470000, 0x1fffe544052e0000, 0x1fffe5c505150000, 0x1fffe64604fc0000, 0x1fffe6c704e30000, 0x1fffe74904ca0000, + 0x1fffe7ca04b10000, 0x1fffe84b04980000, 0x1fffe8cc047f0000, 0x1fffe94d04660000, 0x1fffe9ce044d0000, 0x1fffea4f04340000, 0x1fffead1041b0000, 0x1fffeb5204020000, + 0x1fffebd303e90000, 0x1fffec5403d00000, 0x1fffecd503b70000, 0x1fffed56039e0000, 0x1fffedd803850000, 0x1fffee59036c0000, 0x1fffeeda03530000, 0x1fffef5b033a0000, + 0x1fffefdc03210000, 0x1ffff05d03080000, 0x1ffff0de02ef0000, 0x1ffff16002d60000, 0x1ffff1e102bd0000, 0x1ffff26202a40000, 0x1ffff2e3028b0000, 0x1ffff36402720000, + 0x1ffff3e502590000, 0x1ffff46702400000, 0x1ffff4e802270000, 0x1ffff569020e0000, 0x1ffff5ea01f40000, 0x1ffff66b01db0000, 0x1ffff6ec01c20000, 0x1ffff76d01a90000, + 0x1ffff7ef01900000, 0x1ffff87001770000, 0x1ffff8f1015e0000, 0x1ffff97201450000, 0x1ffff9f3012c0000, 0x1ffffa7401130000, 0x1ffffaf500fa0000, 0x1ffffb7700e10000, + 0x1ffffbf800c80000, 0x1ffffc7900af0000, 0x1ffffcfa00960000, 0x1ffffd7b007d0000, 0x1ffffdfc00640000, 0x1ffffe7e004b0000, 0x1ffffeff00320000, 0x1fffff8000190000, + 0x1fff000000000000, 0x1fff0081ffe80000, 0x1fff0102ffcf0000, 0x1fff0183ffb60000, 0x1fff0205ff9d0000, 0x1fff0286ff840000, 0x1fff0307ff6b0000, 0x1fff0388ff520000, + 0x1fff0409ff390000, 0x1fff048aff200000, 0x1fff050cff070000, 0x1fff058dfeee0000, 0x1fff060efed50000, 0x1fff068ffebc0000, 0x1fff0710fea30000, 0x1fff0791fe8a0000, + 0x1fff0812fe710000, 0x1fff0894fe580000, 0x1fff0915fe3f0000, 0x1fff0996fe260000, 0x1fff0a17fe0d0000, 0x1fff0a98fdf30000, 0x1fff0b19fdda0000, 0x1fff0b9afdc10000, + 0x1fff0c1cfda80000, 0x1fff0c9dfd8f0000, 0x1fff0d1efd760000, 0x1fff0d9ffd5d0000, 0x1fff0e20fd440000, 0x1fff0ea1fd2b0000, 0x1fff0f23fd120000, 0x1fff0fa4fcf90000, + 0x1fff1025fce00000, 0x1fff10a6fcc70000, 0x1fff1127fcae0000, 0x1fff11a8fc950000, 0x1fff1229fc7c0000, 0x1fff12abfc630000, 0x1fff132cfc4a0000, 0x1fff13adfc310000, + 0x1fff142efc180000, 0x1fff14affbff0000, 0x1fff1530fbe60000, 0x1fff15b2fbcd0000, 0x1fff1633fbb40000, 0x1fff16b4fb9b0000, 0x1fff1735fb820000, 0x1fff17b6fb690000, + 0x1fff1837fb500000, 0x1fff18b8fb370000, 0x1fff193afb1e0000, 0x1fff19bbfb050000, 0x1fff1a3cfaec0000, 0x1fff1abdfad30000, 0x1fff1b3efaba0000, 0x1fff1bbffaa10000, + 0x1fff1c41fa880000, 0x1fff1cc2fa6f0000, 0x1fff1d43fa560000, 0x1fff1dc4fa3d0000, 0x1fff1e45fa240000, 0x1fff1ec6fa0b0000, 0x1fff1f47f9f20000, 0x1fff1fc9f9d80000, + 0x1fff204af9bf0000, 0x1fff20cbf9a60000, 0x1fff214cf98d0000, 0x1fff21cdf9740000, 0x1fff224ef95b0000, 0x1fff22cff9420000, 0x1fff2351f9290000, 0x1fff23d2f9100000, + 0x1fff2453f8f70000, 0x1fff24d4f8de0000, 0x1fff2555f8c50000, 0x1fff25d6f8ac0000, 0x1fff2658f8930000, 0x1fff26d9f87a0000, 0x1fff275af8610000, 0x1fff27dbf8480000, + 0x1fff285cf82f0000, 0x1fff28ddf8160000, 0x1fff295ef7fd0000, 0x1fff29e0f7e40000, 0x1fff2a61f7cb0000, 0x1fff2ae2f7b20000, 0x1fff2b63f7990000, 0x1fff2be4f7800000, + 0x1fff2c65f7670000, 0x1fff2ce7f74e0000, 0x1fff2d68f7350000, 0x1fff2de9f71c0000, 0x1fff2e6af7030000, 0x1fff2eebf6ea0000, 0x1fff2f6cf6d10000, 0x1fff2fedf6b80000, + 0x1fff306ff69f0000, 0x1fff30f0f6860000, 0x1fff3171f66d0000, 0x1fff31f2f6540000, 0x1fff3273f63b0000, 0x1fff32f4f6220000, 0x1fff3376f6090000, 0x1fff33f7f5f00000, + 0x1fff3478f5d70000, 0x1fff34f9f5bd0000, 0x1fff357af5a40000, 0x1fff35fbf58b0000, 0x1fff367cf5720000, 0x1fff36fef5590000, 0x1fff377ff5400000, 0x1fff3800f5270000, + 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, + 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, + }; + static const __m64 COEFF_V_MMX[256] = { + 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, + 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, + 0x1fff000016c4d351, 0x1fff00001690d3b7, 0x1fff0000165cd41d, 0x1fff00001627d483, 0x1fff000015f3d4e9, 0x1fff000015bfd550, 0x1fff0000158bd5b6, 0x1fff00001557d61c, + 0x1fff00001523d682, 0x1fff000014efd6e8, 0x1fff000014bbd74e, 0x1fff00001487d7b4, 0x1fff00001453d81b, 0x1fff0000141fd881, 0x1fff000013ebd8e7, 0x1fff000013b7d94d, + 0x1fff00001383d9b3, 0x1fff0000134fda19, 0x1fff0000131bda7f, 0x1fff000012e7dae6, 0x1fff000012b3db4c, 0x1fff0000127fdbb2, 0x1fff0000124bdc18, 0x1fff00001217dc7e, + 0x1fff000011e3dce4, 0x1fff000011afdd4a, 0x1fff0000117bddb1, 0x1fff00001147de17, 0x1fff00001113de7d, 0x1fff000010dfdee3, 0x1fff000010abdf49, 0x1fff00001077dfaf, + 0x1fff00001043e015, 0x1fff0000100fe07c, 0x1fff00000fdae0e2, 0x1fff00000fa6e148, 0x1fff00000f72e1ae, 0x1fff00000f3ee214, 0x1fff00000f0ae27a, 0x1fff00000ed6e2e0, + 0x1fff00000ea2e347, 0x1fff00000e6ee3ad, 0x1fff00000e3ae413, 0x1fff00000e06e479, 0x1fff00000dd2e4df, 0x1fff00000d9ee545, 0x1fff00000d6ae5ab, 0x1fff00000d36e612, + 0x1fff00000d02e678, 0x1fff00000ccee6de, 0x1fff00000c9ae744, 0x1fff00000c66e7aa, 0x1fff00000c32e810, 0x1fff00000bfee877, 0x1fff00000bcae8dd, 0x1fff00000b96e943, + 0x1fff00000b62e9a9, 0x1fff00000b2eea0f, 0x1fff00000afaea75, 0x1fff00000ac6eadb, 0x1fff00000a92eb42, 0x1fff00000a5eeba8, 0x1fff00000a2aec0e, 0x1fff000009f6ec74, + 0x1fff000009c2ecda, 0x1fff0000098eed40, 0x1fff00000959eda6, 0x1fff00000925ee0d, 0x1fff000008f1ee73, 0x1fff000008bdeed9, 0x1fff00000889ef3f, 0x1fff00000855efa5, + 0x1fff00000821f00b, 0x1fff000007edf071, 0x1fff000007b9f0d8, 0x1fff00000785f13e, 0x1fff00000751f1a4, 0x1fff0000071df20a, 0x1fff000006e9f270, 0x1fff000006b5f2d6, + 0x1fff00000681f33c, 0x1fff0000064df3a3, 0x1fff00000619f409, 0x1fff000005e5f46f, 0x1fff000005b1f4d5, 0x1fff0000057df53b, 0x1fff00000549f5a1, 0x1fff00000515f607, + 0x1fff000004e1f66e, 0x1fff000004adf6d4, 0x1fff00000479f73a, 0x1fff00000445f7a0, 0x1fff00000411f806, 0x1fff000003ddf86c, 0x1fff000003a9f8d2, 0x1fff00000375f939, + 0x1fff00000341f99f, 0x1fff0000030cfa05, 0x1fff000002d8fa6b, 0x1fff000002a4fad1, 0x1fff00000270fb37, 0x1fff0000023cfb9d, 0x1fff00000208fc04, 0x1fff000001d4fc6a, + 0x1fff000001a0fcd0, 0x1fff0000016cfd36, 0x1fff00000138fd9c, 0x1fff00000104fe02, 0x1fff000000d0fe68, 0x1fff0000009cfecf, 0x1fff00000068ff35, 0x1fff00000034ff9b, + 0x1fff000000000000, 0x1fff0000ffcd0066, 0x1fff0000ff9900cc, 0x1fff0000ff650132, 0x1fff0000ff310199, 0x1fff0000fefd01ff, 0x1fff0000fec90265, 0x1fff0000fe9502cb, + 0x1fff0000fe610331, 0x1fff0000fe2d0397, 0x1fff0000fdf903fd, 0x1fff0000fdc50464, 0x1fff0000fd9104ca, 0x1fff0000fd5d0530, 0x1fff0000fd290596, 0x1fff0000fcf505fc, + 0x1fff0000fcc00662, 0x1fff0000fc8c06c8, 0x1fff0000fc58072f, 0x1fff0000fc240795, 0x1fff0000fbf007fb, 0x1fff0000fbbc0861, 0x1fff0000fb8808c7, 0x1fff0000fb54092d, + 0x1fff0000fb200993, 0x1fff0000faec09fa, 0x1fff0000fab80a60, 0x1fff0000fa840ac6, 0x1fff0000fa500b2c, 0x1fff0000fa1c0b92, 0x1fff0000f9e80bf8, 0x1fff0000f9b40c5e, + 0x1fff0000f9800cc5, 0x1fff0000f94c0d2b, 0x1fff0000f9180d91, 0x1fff0000f8e40df7, 0x1fff0000f8b00e5d, 0x1fff0000f87c0ec3, 0x1fff0000f8480f29, 0x1fff0000f8140f90, + 0x1fff0000f7e00ff6, 0x1fff0000f7ac105c, 0x1fff0000f77810c2, 0x1fff0000f7441128, 0x1fff0000f710118e, 0x1fff0000f6dc11f4, 0x1fff0000f6a8125b, 0x1fff0000f67312c1, + 0x1fff0000f63f1327, 0x1fff0000f60b138d, 0x1fff0000f5d713f3, 0x1fff0000f5a31459, 0x1fff0000f56f14bf, 0x1fff0000f53b1526, 0x1fff0000f507158c, 0x1fff0000f4d315f2, + 0x1fff0000f49f1658, 0x1fff0000f46b16be, 0x1fff0000f4371724, 0x1fff0000f403178a, 0x1fff0000f3cf17f1, 0x1fff0000f39b1857, 0x1fff0000f36718bd, 0x1fff0000f3331923, + 0x1fff0000f2ff1989, 0x1fff0000f2cb19ef, 0x1fff0000f2971a56, 0x1fff0000f2631abc, 0x1fff0000f22f1b22, 0x1fff0000f1fb1b88, 0x1fff0000f1c71bee, 0x1fff0000f1931c54, + 0x1fff0000f15f1cba, 0x1fff0000f12b1d21, 0x1fff0000f0f71d87, 0x1fff0000f0c31ded, 0x1fff0000f08f1e53, 0x1fff0000f05b1eb9, 0x1fff0000f0271f1f, 0x1fff0000eff21f85, + 0x1fff0000efbe1fec, 0x1fff0000ef8a2052, 0x1fff0000ef5620b8, 0x1fff0000ef22211e, 0x1fff0000eeee2184, 0x1fff0000eeba21ea, 0x1fff0000ee862250, 0x1fff0000ee5222b7, + 0x1fff0000ee1e231d, 0x1fff0000edea2383, 0x1fff0000edb623e9, 0x1fff0000ed82244f, 0x1fff0000ed4e24b5, 0x1fff0000ed1a251b, 0x1fff0000ece62582, 0x1fff0000ecb225e8, + 0x1fff0000ec7e264e, 0x1fff0000ec4a26b4, 0x1fff0000ec16271a, 0x1fff0000ebe22780, 0x1fff0000ebae27e6, 0x1fff0000eb7a284d, 0x1fff0000eb4628b3, 0x1fff0000eb122919, + 0x1fff0000eade297f, 0x1fff0000eaaa29e5, 0x1fff0000ea762a4b, 0x1fff0000ea422ab1, 0x1fff0000ea0e2b18, 0x1fff0000e9da2b7e, 0x1fff0000e9a52be4, 0x1fff0000e9712c4a, + 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, + 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, + }; + + // ----------------------------------------------------------------------------- - dst0 += YUVBuffer.y_width * 4; - dst1 += YUVBuffer.y_width * 4; - ySrc0 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; - ySrc1 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; - uSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; - vSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; + void YUVtoRGBA_MMX(yuv_buffer & YUVBuffer, std::vector & PixelData) + { + // Width and height of all buffers have to be divisible by 4. + BS_ASSERT((YUVBuffer.y_width & 3) == 0); + BS_ASSERT((YUVBuffer.y_height & 3) == 0); + BS_ASSERT((YUVBuffer.uv_width & 3) == 0); + BS_ASSERT((YUVBuffer.uv_height & 3) == 0); + // UV images have to have a quarter of the Y image resolution + BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); + BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); + + const unsigned char * ySrc = YUVBuffer.y; + const unsigned char * uSrc = YUVBuffer.u; + const unsigned char * vSrc = YUVBuffer.v; + unsigned char * dst = &PixelData[0]; + + const int yPadding = YUVBuffer.y_stride - YUVBuffer.y_width; + int uvStride = YUVBuffer.uv_stride; + + for (int h = 0; h < YUVBuffer.y_height; ++h) + { + uvStride ^= YUVBuffer.uv_stride; + for (int w = 0; w < YUVBuffer.y_width / 4; ++w) + { + __m64 uvCoeff0 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); + __m64 uvCoeff1 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); + + __m64 px01 = COEFF_Y_MMX[*ySrc++]; + __m64 px23 = COEFF_Y_MMX[*ySrc++]; + __m64 px45 = COEFF_Y_MMX[*ySrc++]; + __m64 px67 = COEFF_Y_MMX[*ySrc++]; + + px01 = _m_paddw(px01, uvCoeff0); + px23 = _m_paddw(px23, uvCoeff0); + px45 = _m_paddw(px45, uvCoeff1); + px67 = _m_paddw(px67, uvCoeff1); + + px01 = _m_psrawi(px01, 6); + px23 = _m_psrawi(px23, 6); + px45 = _m_psrawi(px45, 6); + px67 = _m_psrawi(px67, 6); + + ((__m64*)dst)[0] = _m_packuswb(px01, px23); + ((__m64*)dst)[1] = _m_packuswb(px45, px67); + dst += 16; + } + + ySrc += yPadding; + uSrc += uvStride - YUVBuffer.uv_width; + vSrc += uvStride - YUVBuffer.uv_width; + } + + _m_empty(); } + } -} // End of namespace Sword25 +// ----------------------------------------------------------------------------- + +void BS_YUVtoRGBA::YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, vector & Pixels) +{ + BS_ASSERT(TheoraInfo.pixelformat == OC_PF_420); + BS_ASSERT(int(Pixels.size()) >= YUVBuffer.y_width * YUVBuffer.y_height); + + return YUVtoRGBA_c(YUVBuffer, Pixels); + + if (BS_CPUInfo::GetInstance().IsMMXSupported()) + return YUVtoRGBA_MMX(YUVBuffer, Pixels); + else + return YUVtoRGBA_c(YUVBuffer, Pixels); +} diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.h b/engines/sword25/fmv/oggtheora/yuvtorgba.h index 5b0332a807..6593254ff9 100644 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.h +++ b/engines/sword25/fmv/oggtheora/yuvtorgba.h @@ -39,19 +39,21 @@ // Includes // ----------------------------------------------------------------------------- +#include "sword25/kernel/memlog_off.h" +#include +#include "sword25/kernel/memlog_on.h" + #include "sword25/kernel/common.h" -#include +#include "theora/theora.h" -namespace Sword25 { // ----------------------------------------------------------------------------- // Klassendefinition // ----------------------------------------------------------------------------- -class BS_YUVtoRGBA { +class BS_YUVtoRGBA +{ public: - static void YUVtoRGBA(yuv_buffer &YUVBuffer, const theora_info &TheoraInfo, byte *Pixels, int PixelsSize); + static void YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, std::vector & Pixels); }; -} // End of namespace Sword25 - #endif -- cgit v1.2.3 From 384468c0148ede9ae8140b4fd75183368d26ada6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 31 Aug 2010 09:45:21 +0000 Subject: SWORD25: Started to hook TheoraDecoder. Crashes at startup. svn-id: r53297 --- engines/sword25/fmv/movieplayer.cpp | 21 ++++++++++++++++++++- engines/sword25/fmv/movieplayer.h | 6 +++--- engines/sword25/fmv/theora_decoder.cpp | 14 ++++++++------ engines/sword25/fmv/theora_decoder.h | 4 ++-- 4 files changed, 33 insertions(+), 12 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index e4b33bdf8c..3114d68bdc 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -33,6 +33,9 @@ */ #include "sword25/fmv/movieplayer.h" +#include "sword25/fmv/theora_decoder.h" +#include "sword25/kernel/kernel.h" +#include "sword25/package/packagemanager.h" namespace Sword25 { @@ -47,13 +50,29 @@ MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); + + _decoder = new TheoraDecoder(); } -bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { +bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int Z) { + Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); + + if (!in) { + BS_LOG_ERRORLN("Could not open movie file \"%s\".", filename.c_str()); + return false; + } + + if (!_decoder->load(in)) { + BS_LOG_ERRORLN("Could not load movie file \"%s\".", filename.c_str()); + return false; + } + return true; } bool MoviePlayer::UnloadMovie() { + _decoder->close(); + return true; } diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 3404eaacd8..233c500fd5 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -44,9 +44,7 @@ namespace Sword25 { -// ----------------------------------------------------------------------------- -// Class definitions -// ----------------------------------------------------------------------------- +class TheoraDecoder; class MoviePlayer : public Service { public: @@ -140,6 +138,8 @@ public: private: bool _RegisterScriptBindings(); + + TheoraDecoder *_decoder; }; } // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index ef9f904f77..31458a2deb 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -84,10 +84,10 @@ int TheoraDecoder::bufferData() { return(bytes); } -bool TheoraDecoder::load(Common::SeekableReadStream &stream) { +bool TheoraDecoder::load(Common::SeekableReadStream *stream) { close(); - _fileStream = &stream; + _fileStream = stream; // start up Ogg stream synchronization layer ogg_sync_init(&_oggSync); @@ -236,7 +236,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream &stream) { // open audio if (_vorbisPacket) { _audStream = createAudioStream(); - if (_audStream) + if (_audStream && _mixer) _mixer->playStream(_soundType, _audHandle, _audStream); } @@ -255,7 +255,8 @@ void TheoraDecoder::close() { vorbis_comment_clear(&_vorbisComment); vorbis_info_clear(&_vorbisInfo); - _mixer->stopHandle(*_audHandle); + if (_mixer) + _mixer->stopHandle(*_audHandle); _audStream = 0; } if (_theoraPacket) { @@ -264,11 +265,12 @@ void TheoraDecoder::close() { th_comment_clear(&_theoraComment); th_info_clear(&_theoraInfo); } - ogg_sync_clear(&_oggSync); if (!_fileStream) return; + ogg_sync_clear(&_oggSync); + delete _fileStream; _fileStream = 0; @@ -417,7 +419,7 @@ void TheoraDecoder::reset() { } uint32 TheoraDecoder::getElapsedTime() const { - if (_audStream) + if (_audStream && _mixer) return _mixer->getSoundElapsedTime(*_audHandle); return VideoDecoder::getElapsedTime(); diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index 690763e940..7faadfd9dc 100644 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -47,14 +47,14 @@ namespace Sword25 { */ class TheoraDecoder : public Graphics::FixedRateVideoDecoder { public: - TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType); + TheoraDecoder(Audio::Mixer *mixer = 0, Audio::Mixer::SoundType soundType = Audio::Mixer::kMusicSoundType); virtual ~TheoraDecoder(); /** * Load a video file * @param stream the stream to load */ - bool load(Common::SeekableReadStream &stream); + bool load(Common::SeekableReadStream *stream); void close(); void reset(); -- cgit v1.2.3 From f06db87a0ee0323ceb5a1e946fa9ed1f8576abca Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 31 Aug 2010 18:37:59 +0000 Subject: SWORD25: Implement playback. Blitting is TODO. svn-id: r53298 --- engines/sword25/fmv/movieplayer.cpp | 20 +++++++++--- engines/sword25/fmv/theora_decoder.cpp | 58 ++++++++++++++++++++++++++++++++-- engines/sword25/fmv/theora_decoder.h | 12 +++++-- 3 files changed, 81 insertions(+), 9 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 3114d68bdc..e4b417adc5 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -54,7 +54,7 @@ MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { _decoder = new TheoraDecoder(); } -bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int Z) { +bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); if (!in) { @@ -62,11 +62,15 @@ bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int Z) { return false; } + debug(2, "LoadMovie(%s, %d)", filename.c_str(), z); + if (!_decoder->load(in)) { BS_LOG_ERRORLN("Could not load movie file \"%s\".", filename.c_str()); return false; } + warning("STUB: MoviePlayer::LoadMovie(). Z is not handled"); + return true; } @@ -77,22 +81,30 @@ bool MoviePlayer::UnloadMovie() { } bool MoviePlayer::Play() { + _decoder->pauseVideo(false); + return true; } bool MoviePlayer::Pause() { + _decoder->pauseVideo(true); + return true; } void MoviePlayer::Update() { + if (!_decoder->isVideoLoaded()) + return; + + Graphics::Surface *surface = _decoder->decodeNextFrame(); } bool MoviePlayer::IsMovieLoaded() { - return true; + return _decoder->isVideoLoaded(); } bool MoviePlayer::IsPaused() { - return true; + return _decoder->isPaused(); } float MoviePlayer::GetScaleFactor() { @@ -103,7 +115,7 @@ void MoviePlayer::SetScaleFactor(float ScaleFactor) { } double MoviePlayer::GetTime() { - return 1.0; + return (double)_decoder->getElapsedTime() / 1000.0; } diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index 31458a2deb..bcd77ca880 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -60,11 +60,21 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT _soundType = soundType; _audStream = 0; _audHandle = new Audio::SoundHandle(); + + _theoraDecode = 0; + _theoraSetup = 0; + + _curFrame = 0; + + _audiobuf = (ogg_int16_t *)calloc(AUDIOFD_FRAGSIZE, sizeof(ogg_int16_t)); + + reset(); } TheoraDecoder::~TheoraDecoder() { close(); delete _audHandle; + free(_audiobuf); } void TheoraDecoder::queuePage(ogg_page *page) { @@ -81,7 +91,7 @@ int TheoraDecoder::bufferData() { ogg_sync_wrote(&_oggSync, bytes); - return(bytes); + return bytes; } bool TheoraDecoder::load(Common::SeekableReadStream *stream) { @@ -209,6 +219,36 @@ bool TheoraDecoder::load(Common::SeekableReadStream *stream) { debug(1, " Frame content is %dx%d with offset (%d,%d).", _theoraInfo.frame_width, _theoraInfo.frame_height, _theoraInfo.pic_x, _theoraInfo.pic_y); + switch (_theoraInfo.colorspace){ + case TH_CS_UNSPECIFIED: + /* nothing to report */ + break;; + case TH_CS_ITU_REC_470M: + debug(1, " encoder specified ITU Rec 470M (NTSC) color."); + break; + case TH_CS_ITU_REC_470BG: + debug(1, " encoder specified ITU Rec 470BG (PAL) color."); + break; + default: + debug(1, "warning: encoder specified unknown colorspace (%d).", _theoraInfo.colorspace); + break; + } + + debug(1, "Encoded by %s", _theoraComment.vendor); + if (_theoraComment.comments) { + debug(1, "theora comment header:"); + for (int i = 0; i < _theoraComment.comments; i++) { + if (_theoraComment.user_comments[i]) { + int len = _theoraComment.comment_lengths[i]; + char *value = (char *)malloc(len + 1); + memcpy(value, _theoraComment.user_comments[i], len); + value[len] = '\0'; + debug(1, "\t%s", value); + free(value); + } + } + } + th_decode_ctl(_theoraDecode, TH_DECCTL_GET_PPLEVEL_MAX, &_ppLevelMax, sizeof(_ppLevelMax)); _ppLevel = _ppLevelMax; th_decode_ctl(_theoraDecode, TH_DECCTL_SET_PPLEVEL, &_ppLevel, sizeof(_ppLevel)); @@ -220,7 +260,9 @@ bool TheoraDecoder::load(Common::SeekableReadStream *stream) { th_comment_clear(&_theoraComment); } + th_setup_free(_theoraSetup); + _theoraSetup = 0; if (_vorbisPacket) { vorbis_synthesis_init(&_vorbisDSP, &_vorbisInfo); @@ -241,8 +283,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream *stream) { } _surface = new Graphics::Surface(); - - _surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, 3); + _surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, 4); return true; } @@ -258,12 +299,15 @@ void TheoraDecoder::close() { if (_mixer) _mixer->stopHandle(*_audHandle); _audStream = 0; + _vorbisPacket = 0; } if (_theoraPacket) { ogg_stream_clear(&_theoraOut); th_decode_free(_theoraDecode); th_comment_clear(&_theoraComment); th_info_clear(&_theoraInfo); + _theoraDecode = 0; + _theoraPacket = 0; } if (!_fileStream) @@ -406,6 +450,7 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { void TheoraDecoder::reset() { VideoDecoder::reset(); + if (_fileStream) _fileStream->seek(0); @@ -416,8 +461,15 @@ void TheoraDecoder::reset() { _audiobufFill = 0; _audiobufReady = false; _audiobufGranulePos = 0; + + _curFrame = 0; } +bool TheoraDecoder::endOfVideo() const { + return !isVideoLoaded(); +} + + uint32 TheoraDecoder::getElapsedTime() const { if (_audStream && _mixer) return _mixer->getSoundElapsedTime(*_audHandle); diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index 7faadfd9dc..3ce53e0900 100644 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -68,6 +68,10 @@ public: bool isVideoLoaded() const { return _fileStream != 0; } + bool isPaused() const { + return (VideoDecoder::isPaused() || !isVideoLoaded()); + } + uint16 getWidth() const { return _surface->w; } @@ -75,14 +79,18 @@ public: return _surface->h; } uint32 getFrameCount() const { - return _frameCount; + // It is not possible to get frame count easily + // I.e. seeking is required + assert(0); } Graphics::PixelFormat getPixelFormat() const { - return Graphics::PixelFormat(3, 8, 8, 8, 0, 0, 0, 0, 0); + return Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); } uint32 getElapsedTime() const; + bool endOfVideo() const; + protected: Common::Rational getFrameRate() const { return _frameRate; -- cgit v1.2.3 From 579d872e96862882d4cf92e82a0e8deb82496020 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Tue, 31 Aug 2010 21:07:36 +0000 Subject: SWORD25: Bugfixes for video playback. svn-id: r53299 --- engines/sword25/fmv/movieplayer.cpp | 9 +++++++++ engines/sword25/fmv/movieplayer.h | 2 ++ engines/sword25/fmv/theora_decoder.cpp | 10 ++++------ 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index e4b417adc5..f3504fcb8f 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -32,9 +32,12 @@ * */ +#include "graphics/surface.h" + #include "sword25/fmv/movieplayer.h" #include "sword25/fmv/theora_decoder.h" #include "sword25/kernel/kernel.h" +#include "sword25/gfx/graphicengine.h" #include "sword25/package/packagemanager.h" namespace Sword25 { @@ -52,6 +55,7 @@ MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { BS_LOGLN("Script bindings registered."); _decoder = new TheoraDecoder(); + _backSurface = (static_cast(Kernel::GetInstance()->GetService("gfx")))->getSurface(); } bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { @@ -97,6 +101,11 @@ void MoviePlayer::Update() { return; Graphics::Surface *surface = _decoder->decodeNextFrame(); + + // Probably it's better to copy to _backSurface + if (surface->w > 0 && surface->h > 0) + g_system->copyRectToScreen((byte *)surface->getBasePtr(0, 0), surface->pitch, 0, 0, + MIN(surface->w, _backSurface->w), MIN(surface->h, _backSurface->h)); } bool MoviePlayer::IsMovieLoaded() { diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index 233c500fd5..afca1eb808 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -41,6 +41,7 @@ #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" +#include "graphics/surface.h" namespace Sword25 { @@ -140,6 +141,7 @@ private: bool _RegisterScriptBindings(); TheoraDecoder *_decoder; + Graphics::Surface *_backSurface; }; } // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index bcd77ca880..bc95e10678 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -53,10 +53,6 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT _fileStream = 0; _surface = 0; - _theoraPacket = 0; - _vorbisPacket = 0; - _stateFlag = false; - _soundType = soundType; _audStream = 0; _audHandle = new Audio::SoundHandle(); @@ -299,7 +295,6 @@ void TheoraDecoder::close() { if (_mixer) _mixer->stopHandle(*_audHandle); _audStream = 0; - _vorbisPacket = 0; } if (_theoraPacket) { ogg_stream_clear(&_theoraOut); @@ -307,7 +302,6 @@ void TheoraDecoder::close() { th_comment_clear(&_theoraComment); th_info_clear(&_theoraInfo); _theoraDecode = 0; - _theoraPacket = 0; } if (!_fileStream) @@ -463,6 +457,10 @@ void TheoraDecoder::reset() { _audiobufGranulePos = 0; _curFrame = 0; + + _theoraPacket = 0; + _vorbisPacket = 0; + _stateFlag = false; } bool TheoraDecoder::endOfVideo() const { -- cgit v1.2.3 From 3d3f1db15c50c9b675e29e0a10ee896fd8928445 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 1 Sep 2010 07:35:38 +0000 Subject: SWORD25: Merge of my pending changes to movie playback svn-id: r53300 --- engines/sword25/fmv/movieplayer.cpp | 98 +++++++++++++++++++++------------- engines/sword25/fmv/movieplayer.h | 17 +++--- engines/sword25/fmv/theora_decoder.cpp | 19 ++++--- engines/sword25/fmv/theora_decoder.h | 1 + 4 files changed, 86 insertions(+), 49 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index f3504fcb8f..0475c9003e 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -32,100 +32,126 @@ * */ -#include "graphics/surface.h" - #include "sword25/fmv/movieplayer.h" -#include "sword25/fmv/theora_decoder.h" -#include "sword25/kernel/kernel.h" #include "sword25/gfx/graphicengine.h" +#include "sword25/gfx/panel.h" +#include "sword25/kernel/kernel.h" #include "sword25/package/packagemanager.h" +#include "sword25/sfx/soundengine.h" namespace Sword25 { #define BS_LOG_PREFIX "MOVIEPLAYER" +#define FLT_EPSILON 1.192092896e-07F /* smallest such that 1.0+FLT_EPSILON != 1.0 */ + Service *OggTheora_CreateObject(Kernel *pKernel) { return new MoviePlayer(pKernel); } -MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel) { +MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), + _decoder(g_system->getMixer()) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); - - _decoder = new TheoraDecoder(); - _backSurface = (static_cast(Kernel::GetInstance()->GetService("gfx")))->getSurface(); } -bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { - Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); +MoviePlayer::~MoviePlayer() { + _decoder.close(); +} - if (!in) { - BS_LOG_ERRORLN("Could not open movie file \"%s\".", filename.c_str()); +bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { + // Get the file and load it into the decoder + uint dataSize; + const byte *data = reinterpret_cast(Kernel::GetInstance()->GetPackage()->GetFile(Filename, &dataSize)); + Common::MemoryReadStream *stream = new Common::MemoryReadStream( + data, dataSize, DisposeAfterUse::YES); + _decoder.load(stream); + + // Ausgabebitmap erstellen + GraphicEngine *pGfx = Kernel::GetInstance()->GetGfx(); + _outputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap( + _decoder.getWidth(), _decoder.getHeight()); + if (!_outputBitmap.IsValid()) { + BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); return false; } - debug(2, "LoadMovie(%s, %d)", filename.c_str(), z); + // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. + float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) _outputBitmap->GetWidth(); + float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) _outputBitmap->GetHeight(); + float ScaleFactor = MIN(ScreenToVideoWidth, ScreenToVideoHeight); + if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; + _outputBitmap->SetScaleFactor(ScaleFactor); - if (!_decoder->load(in)) { - BS_LOG_ERRORLN("Could not load movie file \"%s\".", filename.c_str()); - return false; - } + // Z-Wert setzen + _outputBitmap->SetZ(Z); - warning("STUB: MoviePlayer::LoadMovie(). Z is not handled"); + // Ausgabebitmap auf dem Bildschirm zentrieren + _outputBitmap->SetX((pGfx->GetDisplayWidth() - _outputBitmap->GetWidth()) / 2); + _outputBitmap->SetY((pGfx->GetDisplayHeight() - _outputBitmap->GetHeight()) / 2); return true; } bool MoviePlayer::UnloadMovie() { - _decoder->close(); + _decoder.close(); + _outputBitmap.Erase(); return true; } bool MoviePlayer::Play() { - _decoder->pauseVideo(false); - + _decoder.pauseVideo(false); return true; } bool MoviePlayer::Pause() { - _decoder->pauseVideo(true); - + _decoder.pauseVideo(true); return true; } void MoviePlayer::Update() { - if (!_decoder->isVideoLoaded()) - return; + if (_decoder.isVideoLoaded()) { + Graphics::Surface *s = _decoder.decodeNextFrame(); - Graphics::Surface *surface = _decoder->decodeNextFrame(); - - // Probably it's better to copy to _backSurface - if (surface->w > 0 && surface->h > 0) - g_system->copyRectToScreen((byte *)surface->getBasePtr(0, 0), surface->pitch, 0, 0, - MIN(surface->w, _backSurface->w), MIN(surface->h, _backSurface->h)); + // Transfer the next frame + assert(s->bytesPerPixel == 4); + byte *frameData = (byte *)s->getBasePtr(0, 0); + _outputBitmap->SetContent(frameData, s->pitch * s->h, 0, s->pitch); + } } bool MoviePlayer::IsMovieLoaded() { - return _decoder->isVideoLoaded(); + return _decoder.isVideoLoaded(); } bool MoviePlayer::IsPaused() { - return _decoder->isPaused(); + return _decoder.isPaused(); } float MoviePlayer::GetScaleFactor() { - return 1.0f; + if (_decoder.isVideoLoaded()) + return _outputBitmap->GetScaleFactorX(); + else + return 0; } void MoviePlayer::SetScaleFactor(float ScaleFactor) { + if (_decoder.isVideoLoaded()) { + _outputBitmap->SetScaleFactor(ScaleFactor); + + // Ausgabebitmap auf dem Bildschirm zentrieren + GraphicEngine *gfxPtr = Kernel::GetInstance()->GetGfx(); + _outputBitmap->SetX((gfxPtr->GetDisplayWidth() - _outputBitmap->GetWidth()) / 2); + _outputBitmap->SetY((gfxPtr->GetDisplayHeight() - _outputBitmap->GetHeight()) / 2); + } } double MoviePlayer::GetTime() { - return (double)_decoder->getElapsedTime() / 1000.0; + // FIXME: This may need conversion + return _decoder.getElapsedTime(); } - } // End of namespace Sword25 diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index afca1eb808..cdbcf13f53 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -41,11 +41,14 @@ #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" -#include "graphics/surface.h" +#include "sword25/fmv/theora_decoder.h" +#include "sword25/gfx/bitmap.h" namespace Sword25 { -class TheoraDecoder; +// ----------------------------------------------------------------------------- +// Class definitions +// ----------------------------------------------------------------------------- class MoviePlayer : public Service { public: @@ -54,10 +57,10 @@ public: // ----------------------------------------------------------------------------- MoviePlayer(Kernel *pKernel); - ~MoviePlayer() {}; + ~MoviePlayer(); // ----------------------------------------------------------------------------- - // Abstract interface must be implemented by each Movie Player + // Player interface must be implemented by a Movie Player // ----------------------------------------------------------------------------- /** @@ -136,12 +139,12 @@ public: * @remark This method can only be called when IsMovieLoaded() returns true. */ double GetTime(); - private: bool _RegisterScriptBindings(); - TheoraDecoder *_decoder; - Graphics::Surface *_backSurface; + TheoraDecoder _decoder; + + RenderObjectPtr _outputBitmap; }; } // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index bc95e10678..cbd60d9fdd 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -53,15 +53,18 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT _fileStream = 0; _surface = 0; + _theoraPacket = 0; + _vorbisPacket = 0; + _theoraSetup = 0; + _stateFlag = false; + _soundType = soundType; _audStream = 0; _audHandle = new Audio::SoundHandle(); - _theoraDecode = 0; - _theoraSetup = 0; + ogg_sync_init(&_oggSync); _curFrame = 0; - _audiobuf = (ogg_int16_t *)calloc(AUDIOFD_FRAGSIZE, sizeof(ogg_int16_t)); reset(); @@ -69,6 +72,7 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT TheoraDecoder::~TheoraDecoder() { close(); + delete _fileStream; delete _audHandle; free(_audiobuf); } @@ -249,14 +253,12 @@ bool TheoraDecoder::load(Common::SeekableReadStream *stream) { _ppLevel = _ppLevelMax; th_decode_ctl(_theoraDecode, TH_DECCTL_SET_PPLEVEL, &_ppLevel, sizeof(_ppLevel)); _ppInc = 0; - } else { // tear down the partial theora setup th_info_clear(&_theoraInfo); th_comment_clear(&_theoraComment); } - th_setup_free(_theoraSetup); _theoraSetup = 0; @@ -279,6 +281,7 @@ bool TheoraDecoder::load(Common::SeekableReadStream *stream) { } _surface = new Graphics::Surface(); + _surface->create(_theoraInfo.frame_width, _theoraInfo.frame_height, 4); return true; @@ -295,6 +298,7 @@ void TheoraDecoder::close() { if (_mixer) _mixer->stopHandle(*_audHandle); _audStream = 0; + _vorbisPacket = false; } if (_theoraPacket) { ogg_stream_clear(&_theoraOut); @@ -302,6 +306,7 @@ void TheoraDecoder::close() { th_comment_clear(&_theoraComment); th_info_clear(&_theoraInfo); _theoraDecode = 0; + _theoraPacket = false; } if (!_fileStream) @@ -322,7 +327,7 @@ void TheoraDecoder::close() { Graphics::Surface *TheoraDecoder::decodeNextFrame() { int i, j; - _stateFlag = false; // playback has not begun +// _stateFlag = false; // playback has not begun // we want a video and audio frame ready to go at all times. If // we have to buffer incoming, buffer the compressed data (ie, let @@ -404,9 +409,11 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { } // If playback has begun, top audio buffer off immediately. +/* FIXME: This is currently crashing if (_stateFlag) { _audStream->queueBuffer((byte *)_audiobuf, AUDIOFD_FRAGSIZE, DisposeAfterUse::NO, Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN | Audio::FLAG_STEREO); } +*/ // are we at or past time for this video frame? if (_stateFlag && _videobufReady) { diff --git a/engines/sword25/fmv/theora_decoder.h b/engines/sword25/fmv/theora_decoder.h index 3ce53e0900..12d8035c0a 100644 --- a/engines/sword25/fmv/theora_decoder.h +++ b/engines/sword25/fmv/theora_decoder.h @@ -82,6 +82,7 @@ public: // It is not possible to get frame count easily // I.e. seeking is required assert(0); + return 0; } Graphics::PixelFormat getPixelFormat() const { return Graphics::PixelFormat(4, 8, 8, 8, 8, 16, 8, 0, 24); -- cgit v1.2.3 From 3b80a9378223b807a1ec3865bdeb94ba55d508e3 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 1 Sep 2010 08:42:51 +0000 Subject: SWORD25: Put back changes accidentally removed in previous merge. svn-id: r53301 --- engines/sword25/fmv/movieplayer.cpp | 14 +++++--------- engines/sword25/fmv/theora_decoder.cpp | 1 + 2 files changed, 6 insertions(+), 9 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 0475c9003e..1941809c1a 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -61,13 +61,10 @@ MoviePlayer::~MoviePlayer() { _decoder.close(); } -bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { +bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { // Get the file and load it into the decoder - uint dataSize; - const byte *data = reinterpret_cast(Kernel::GetInstance()->GetPackage()->GetFile(Filename, &dataSize)); - Common::MemoryReadStream *stream = new Common::MemoryReadStream( - data, dataSize, DisposeAfterUse::YES); - _decoder.load(stream); + Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); + _decoder.load(in); // Ausgabebitmap erstellen GraphicEngine *pGfx = Kernel::GetInstance()->GetGfx(); @@ -86,7 +83,7 @@ bool MoviePlayer::LoadMovie(const Common::String &Filename, unsigned int Z) { _outputBitmap->SetScaleFactor(ScaleFactor); // Z-Wert setzen - _outputBitmap->SetZ(Z); + _outputBitmap->SetZ(z); // Ausgabebitmap auf dem Bildschirm zentrieren _outputBitmap->SetX((pGfx->GetDisplayWidth() - _outputBitmap->GetWidth()) / 2); @@ -150,8 +147,7 @@ void MoviePlayer::SetScaleFactor(float ScaleFactor) { } double MoviePlayer::GetTime() { - // FIXME: This may need conversion - return _decoder.getElapsedTime(); + return _decoder.getElapsedTime() / 1000.0; } } // End of namespace Sword25 diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index cbd60d9fdd..7aee428fbb 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -55,6 +55,7 @@ TheoraDecoder::TheoraDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundT _theoraPacket = 0; _vorbisPacket = 0; + _theoraDecode = 0; _theoraSetup = 0; _stateFlag = false; -- cgit v1.2.3 From 77cfc170755e3a21167a409767c5a8239aa3cde6 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 1 Sep 2010 08:42:56 +0000 Subject: SWORD25: Formatting fixes svn-id: r53302 --- engines/sword25/fmv/movieplayer.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 1941809c1a..a54be8a757 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -49,8 +49,7 @@ Service *OggTheora_CreateObject(Kernel *pKernel) { return new MoviePlayer(pKernel); } -MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), - _decoder(g_system->getMixer()) { +MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), _decoder(g_system->getMixer()) { if (!_RegisterScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else @@ -68,8 +67,7 @@ bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { // Ausgabebitmap erstellen GraphicEngine *pGfx = Kernel::GetInstance()->GetGfx(); - _outputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap( - _decoder.getWidth(), _decoder.getHeight()); + _outputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(_decoder.getWidth(), _decoder.getHeight()); if (!_outputBitmap.IsValid()) { BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); return false; @@ -79,7 +77,10 @@ bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) _outputBitmap->GetWidth(); float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) _outputBitmap->GetHeight(); float ScaleFactor = MIN(ScreenToVideoWidth, ScreenToVideoHeight); - if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; + + if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) + ScaleFactor = 1.0f; + _outputBitmap->SetScaleFactor(ScaleFactor); // Z-Wert setzen @@ -135,9 +136,9 @@ float MoviePlayer::GetScaleFactor() { return 0; } -void MoviePlayer::SetScaleFactor(float ScaleFactor) { +void MoviePlayer::SetScaleFactor(float scaleFactor) { if (_decoder.isVideoLoaded()) { - _outputBitmap->SetScaleFactor(ScaleFactor); + _outputBitmap->SetScaleFactor(scaleFactor); // Ausgabebitmap auf dem Bildschirm zentrieren GraphicEngine *gfxPtr = Kernel::GetInstance()->GetGfx(); -- cgit v1.2.3 From 2b2330ce65783a5dd86bc882481e383df501f460 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Wed, 1 Sep 2010 09:34:05 +0000 Subject: SWORD25: Movie playback now works svn-id: r53303 --- engines/sword25/fmv/oggtheora/audiobuffer.cpp | 108 ---- engines/sword25/fmv/oggtheora/audiobuffer.h | 68 --- engines/sword25/fmv/oggtheora/moviefile.cpp | 105 ---- engines/sword25/fmv/oggtheora/moviefile.h | 72 --- engines/sword25/fmv/oggtheora/oggstate.cpp | 74 --- engines/sword25/fmv/oggtheora/oggstate.h | 78 --- engines/sword25/fmv/oggtheora/oggstreamstate.cpp | 133 ----- engines/sword25/fmv/oggtheora/oggstreamstate.h | 89 --- engines/sword25/fmv/oggtheora/oggtheora.cpp | 723 ----------------------- engines/sword25/fmv/oggtheora/oggtheora.h | 124 ---- engines/sword25/fmv/oggtheora/theorastate.cpp | 94 --- engines/sword25/fmv/oggtheora/theorastate.h | 70 --- engines/sword25/fmv/oggtheora/vorbisstate.cpp | 112 ---- engines/sword25/fmv/oggtheora/vorbisstate.h | 74 --- engines/sword25/fmv/oggtheora/yuvtorgba.cpp | 431 -------------- engines/sword25/fmv/oggtheora/yuvtorgba.h | 59 -- engines/sword25/fmv/theora_decoder.cpp | 6 +- engines/sword25/fmv/yuvtorgba.cpp | 248 ++++++++ engines/sword25/fmv/yuvtorgba.h | 59 ++ 19 files changed, 311 insertions(+), 2416 deletions(-) delete mode 100644 engines/sword25/fmv/oggtheora/audiobuffer.cpp delete mode 100644 engines/sword25/fmv/oggtheora/audiobuffer.h delete mode 100644 engines/sword25/fmv/oggtheora/moviefile.cpp delete mode 100644 engines/sword25/fmv/oggtheora/moviefile.h delete mode 100644 engines/sword25/fmv/oggtheora/oggstate.cpp delete mode 100644 engines/sword25/fmv/oggtheora/oggstate.h delete mode 100644 engines/sword25/fmv/oggtheora/oggstreamstate.cpp delete mode 100644 engines/sword25/fmv/oggtheora/oggstreamstate.h delete mode 100644 engines/sword25/fmv/oggtheora/oggtheora.cpp delete mode 100644 engines/sword25/fmv/oggtheora/oggtheora.h delete mode 100644 engines/sword25/fmv/oggtheora/theorastate.cpp delete mode 100644 engines/sword25/fmv/oggtheora/theorastate.h delete mode 100644 engines/sword25/fmv/oggtheora/vorbisstate.cpp delete mode 100644 engines/sword25/fmv/oggtheora/vorbisstate.h delete mode 100644 engines/sword25/fmv/oggtheora/yuvtorgba.cpp delete mode 100644 engines/sword25/fmv/oggtheora/yuvtorgba.h create mode 100644 engines/sword25/fmv/yuvtorgba.cpp create mode 100644 engines/sword25/fmv/yuvtorgba.h (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.cpp b/engines/sword25/fmv/oggtheora/audiobuffer.cpp deleted file mode 100644 index f9e6667ce5..0000000000 --- a/engines/sword25/fmv/oggtheora/audiobuffer.cpp +++ /dev/null @@ -1,108 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/fmv/oggtheora/audiobuffer.h" -#include -#include - -using namespace std; - -// ----------------------------------------------------------------------------- - -struct BS_AudioBuffer::Impl -{ - CRITICAL_SECTION CS; - queue Buffer; -}; - -// ----------------------------------------------------------------------------- - -BS_AudioBuffer::BS_AudioBuffer() : t(new Impl()) -{ - InitializeCriticalSection(&t->CS); -} - -// ----------------------------------------------------------------------------- - -BS_AudioBuffer::~BS_AudioBuffer() -{ - DeleteCriticalSection(&t->CS); - - delete t; -} - -// ----------------------------------------------------------------------------- - -void BS_AudioBuffer::Push(signed short * SamplePtr, unsigned int SampleCount) -{ - EnterCriticalSection(&t->CS); - - signed short * SampleEndPtr = SamplePtr + SampleCount; - while (SamplePtr != SampleEndPtr) t->Buffer.push(*SamplePtr++); - - LeaveCriticalSection(&t->CS); -} - -// ----------------------------------------------------------------------------- - -unsigned int BS_AudioBuffer::Pop(signed short * SamplePtr, unsigned int SampleCount) -{ - EnterCriticalSection(&t->CS); - - unsigned int i = 0; - for (; i < SampleCount && !t->Buffer.empty(); ++i) - { - SamplePtr[i] = t->Buffer.front(); - t->Buffer.pop(); - } - - LeaveCriticalSection(&t->CS); - - return i; -} - -// ----------------------------------------------------------------------------- - -unsigned int BS_AudioBuffer::Size() const -{ - EnterCriticalSection(&t->CS); - unsigned int result = t->Buffer.size(); - LeaveCriticalSection(&t->CS); - - return result; -} diff --git a/engines/sword25/fmv/oggtheora/audiobuffer.h b/engines/sword25/fmv/oggtheora/audiobuffer.h deleted file mode 100644 index 0b4233bc4e..0000000000 --- a/engines/sword25/fmv/oggtheora/audiobuffer.h +++ /dev/null @@ -1,68 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_AUDIOBUFFER_H -#define SWORD25_AUDIOBUFFER_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_AudioBuffer -{ -public: - BS_AudioBuffer(); - virtual ~BS_AudioBuffer(); - - void Push(signed short * SamplePtr, unsigned int SampleCount); - unsigned int Pop(signed short * SamplePtr, unsigned int SampleCount); - unsigned int Size() const; - -private: - // PIMPL Pattern - struct Impl; - Impl * t; - - // Kopie verbieten - BS_AudioBuffer(const BS_AudioBuffer &); - const BS_AudioBuffer & operator=(const BS_AudioBuffer &); -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/moviefile.cpp b/engines/sword25/fmv/oggtheora/moviefile.cpp deleted file mode 100644 index b764ab2d22..0000000000 --- a/engines/sword25/fmv/oggtheora/moviefile.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Logging -// ----------------------------------------------------------------------------- - -#define BS_LOG_PREFIX "MOVIEFILE" - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/kernel.h" -#include "sword25/package/packagemanager.h" -#include "sword25/fmv/oggtheora/oggstate.h" -#include "sword25/fmv/oggtheora/moviefile.h" - -// ----------------------------------------------------------------------------- - -BS_MovieFile::BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success) : - m_Data(0), m_Size(0), m_ReadPos(0), m_ReadBlockSize(ReadBlockSize) -{ - m_Data = reinterpret_cast(BS_Kernel::GetInstance()->GetPackage()->GetFile(Filename, &m_Size)); - if (!m_Data) - { - BS_LOG_ERRORLN("Could not load movie file \"%s\".", Filename.c_str()); - Success = false; - } - else - Success = true; -} - -// ----------------------------------------------------------------------------- - -BS_MovieFile::~BS_MovieFile() -{ - if (m_Data) delete [] m_Data; -} - -// ----------------------------------------------------------------------------- - -int BS_MovieFile::BufferData(BS_OggState & OggState) -{ - if (!m_Data || !m_Size || m_ReadPos >= m_Size) - { - BS_LOG_ERRORLN("Tried to read past the movie buffer's end."); - return 0; - } - - // just grab some more compressed bitstream and sync it for page extraction - char * Buffer = OggState.SyncBuffer(m_ReadBlockSize); - if (!Buffer) - { - BS_LOG_ERRORLN("ogg_sync_buffer() failed."); - return 0; - } - - // Feststellen wie viele Bytes kopiert werden sollen, maximal READ_BLOCK_SIZE, weniger falls das Ende der Daten erreicht ist. - int Bytes = (m_Size - m_ReadPos) > m_ReadBlockSize ? m_ReadBlockSize : m_Size - m_ReadPos; - memcpy(Buffer, &m_Data[m_ReadPos], Bytes); - m_ReadPos += Bytes; - - OggState.SyncWrote(Bytes); - - return Bytes; -} - -// ----------------------------------------------------------------------------- - -bool BS_MovieFile::IsEOF() const -{ - return m_ReadPos >= m_Size; -} diff --git a/engines/sword25/fmv/oggtheora/moviefile.h b/engines/sword25/fmv/oggtheora/moviefile.h deleted file mode 100644 index 5aa0ef5617..0000000000 --- a/engines/sword25/fmv/oggtheora/moviefile.h +++ /dev/null @@ -1,72 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_MOVIEFILE_H -#define SWORD25_MOVIEFILE_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" - -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" - -// ----------------------------------------------------------------------------- - -class BS_OggState; - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_MovieFile -{ -public: - BS_MovieFile(const std::string & Filename, unsigned int ReadBlockSize, bool & Success); - virtual ~BS_MovieFile(); - - int BufferData(BS_OggState & OggState); - bool IsEOF() const; - -private: - char * m_Data; - unsigned int m_Size; - unsigned int m_ReadPos; - unsigned int m_ReadBlockSize; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/oggstate.cpp b/engines/sword25/fmv/oggtheora/oggstate.cpp deleted file mode 100644 index 11788ce53b..0000000000 --- a/engines/sword25/fmv/oggtheora/oggstate.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/fmv/oggtheora/oggstate.h" - -// ----------------------------------------------------------------------------- - -BS_OggState::BS_OggState() -{ - ogg_sync_init(&m_SyncState); -} - -// ----------------------------------------------------------------------------- - -BS_OggState::~BS_OggState() -{ - ogg_sync_clear(&m_SyncState); -} - -// ----------------------------------------------------------------------------- - -int BS_OggState::SyncPageout(ogg_page * OggPage) -{ - return ogg_sync_pageout(&m_SyncState, OggPage); -} - -// ----------------------------------------------------------------------------- - -char * BS_OggState::SyncBuffer(long Size) -{ - return ogg_sync_buffer(&m_SyncState, Size); -} - -// ----------------------------------------------------------------------------- - -int BS_OggState::SyncWrote(long Bytes) -{ - return ogg_sync_wrote(&m_SyncState, Bytes); -} diff --git a/engines/sword25/fmv/oggtheora/oggstate.h b/engines/sword25/fmv/oggtheora/oggstate.h deleted file mode 100644 index 1c25ca5e3a..0000000000 --- a/engines/sword25/fmv/oggtheora/oggstate.h +++ /dev/null @@ -1,78 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_OGGSTATE_H -#define SWORD25_OGGSTATE_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" -#include "ogg/ogg.h" -// XXX -#include -// XXX - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_OggState -{ -public: - BS_OggState(); - virtual ~BS_OggState(); - - int SyncPageout(ogg_page * OggPage); - char * SyncBuffer(long Size); - int SyncWrote(long Bytes); - - // XXX - void DumpInternals() - { - std::cout << "bodybytes: " << m_SyncState.bodybytes << std::endl; - std::cout << "fill: " << m_SyncState.fill << std::endl; - std::cout << "headerbytes: " << m_SyncState.headerbytes << std::endl; - std::cout << "returned: " << m_SyncState.returned << std::endl; - std::cout << "storage: " << m_SyncState.storage << std::endl; - std::cout << "unsynched: " << m_SyncState.unsynced << std::endl; - std::cout << std::endl; - } - // XXX -private: - ogg_sync_state m_SyncState; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp b/engines/sword25/fmv/oggtheora/oggstreamstate.cpp deleted file mode 100644 index d787a96af2..0000000000 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.cpp +++ /dev/null @@ -1,133 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/fmv/oggtheora/oggstreamstate.h" - -// ----------------------------------------------------------------------------- - -BS_OggStreamState::BS_OggStreamState(int SerialNo) -{ - ogg_stream_init(&m_State, SerialNo); -} - -// ----------------------------------------------------------------------------- - -BS_OggStreamState::~BS_OggStreamState() -{ - ogg_stream_clear(&m_State); - - // Alle gepufferten Pages löschen. - while (!m_PageBuffer.empty()) - { - delete [] m_PageBuffer.front().header; - delete [] m_PageBuffer.front().body; - m_PageBuffer.pop(); - } -} - -// ----------------------------------------------------------------------------- - -int BS_OggStreamState::PageIn(ogg_page * PagePtr) -{ - return ogg_stream_pagein(&m_State, PagePtr); -} - -// ----------------------------------------------------------------------------- - -int BS_OggStreamState::PacketOut(ogg_packet * PacketPtr) -{ - return ogg_stream_packetout(&m_State, PacketPtr); -} - -// ----------------------------------------------------------------------------- - -void BS_OggStreamState::BufferPage(ogg_page * PagePtr) -{ - if (PageBelongsToStream(PagePtr)) - { - // Pages können nicht direkt gespeichert werden, da die Pointer im Laufe der Zeit ungültig werden. - // Daher wird an dieser Stelle eine tiefe Kopie der Page im erzeugt und im Pagebuffer angelegt. - ogg_page PageCopy; - PageCopy.header_len = PagePtr->header_len; - PageCopy.header = new unsigned char[PageCopy.header_len]; - memcpy(PageCopy.header, PagePtr->header, PageCopy.header_len); - PageCopy.body_len = PagePtr->body_len; - PageCopy.body = new unsigned char[PageCopy.body_len]; - memcpy(PageCopy.body, PagePtr->body, PageCopy.body_len); - - m_PageBuffer.push(PageCopy); - } -} - -// ----------------------------------------------------------------------------- - -int BS_OggStreamState::PageInBufferedPage() -{ - if (GetPageBufferSize() > 0) - { - // Page in den Stream einfügen, löschen und aus dem Puffer entfernen. - int Result = PageIn(&m_PageBuffer.front()); - delete [] m_PageBuffer.front().header; - delete [] m_PageBuffer.front().body; - m_PageBuffer.pop(); - return Result; - } - - return -1; -} - -// ----------------------------------------------------------------------------- - -unsigned int BS_OggStreamState::GetPageBufferSize() const -{ - return m_PageBuffer.size(); -} - -// ----------------------------------------------------------------------------- - -unsigned int BS_OggStreamState::GetUnprocessedBytes() const -{ - return m_State.body_fill - m_State.body_returned; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggStreamState::PageBelongsToStream(ogg_page * PagePtr) const -{ - return m_State.serialno == ogg_page_serialno(PagePtr); -} diff --git a/engines/sword25/fmv/oggtheora/oggstreamstate.h b/engines/sword25/fmv/oggtheora/oggstreamstate.h deleted file mode 100644 index 7e291bd107..0000000000 --- a/engines/sword25/fmv/oggtheora/oggstreamstate.h +++ /dev/null @@ -1,89 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_OGGSTREAMSTATE_H -#define SWORD25_OGGSTREAMSTATE_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" -#include "ogg/ogg.h" -#include -// XXX -#include -// XXX - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_OggStreamState -{ -public: - BS_OggStreamState(int SerialNo); - virtual ~BS_OggStreamState(); - - int PageIn(ogg_page * PagePtr); - int PacketOut(ogg_packet * PacketPtr); - - void BufferPage(ogg_page * PagePtr); - int PageInBufferedPage(); - unsigned int GetPageBufferSize() const; - - unsigned int GetUnprocessedBytes() const; - bool PageBelongsToStream(ogg_page * PagePtr) const; - - // XXX - void DumpInternals() - { - using namespace std; - - cout << "body_storage: " << m_State.body_storage << endl; - cout << "body_fill: " << m_State.body_fill << endl; - cout << "body_returned: " << m_State.body_returned << endl; - cout << "lacing_storage: " << m_State.lacing_storage << endl; - cout << "lacing_fill: " << m_State.lacing_fill << endl; - cout << "lacing_returned: " << m_State.lacing_returned << endl; - cout << endl; - } - // XXX - -private: - ogg_stream_state m_State; - std::queue m_PageBuffer; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/oggtheora.cpp b/engines/sword25/fmv/oggtheora/oggtheora.cpp deleted file mode 100644 index 9d6eaa0baf..0000000000 --- a/engines/sword25/fmv/oggtheora/oggtheora.cpp +++ /dev/null @@ -1,723 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// The code in this file is based in part on code from the OggTheora Software -// codec source released under the following terms: -// -// Copyright (C) 2002-2007 Xiph.org Foundation -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// -// - Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// -// - Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// - Neither the name of the Xiph.org Foundation nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION -// OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -// ----------------------------------------------------------------------------- -// Logging -// ----------------------------------------------------------------------------- - -#define BS_LOG_PREFIX "OGGTHEORA" - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" -#include - -#include "sword25/package/packagemanager.h" -#include "sword25/sfx/soundengine.h" -#include "sword25/gfx/graphicengine.h" -#include "sword25/gfx/panel.h" -#include "sword25/fmv/oggtheora/oggtheora.h" -#include "sword25/fmv/oggtheora/yuvtorgba.h" - -using namespace std; - -// ----------------------------------------------------------------------------- -// Konstanten und Hilfsfunktionen -// ----------------------------------------------------------------------------- - -namespace -{ - // -------------------------------------------------------------------------- - - const int MAX_FRAMES_PER_TICK = 10; - const int READ_BLOCK_SIZE = 1024 * 40; - const float MAX_AUDIO_BUFFER_LENGTH = 1.0f; - - // -------------------------------------------------------------------------- - - template - inline T Clamp(T x, T low, T high) - { - return ((x > high) ? high : (( x < low) ? low : x)); - } -} - -// ----------------------------------------------------------------------------- -// Konstruktion / Destruktion -// ----------------------------------------------------------------------------- - -BS_OggTheora::BS_OggTheora(BS_Kernel * pKernel) : BS_MoviePlayer(pKernel), m_SoundHandle(0) -{ - UnloadMovie(); -} - -// ----------------------------------------------------------------------------- - -BS_OggTheora::~BS_OggTheora() -{ - UnloadMovie(); -} - -// ----------------------------------------------------------------------------- - -BS_Service * BS_OggTheora_CreateObject(BS_Kernel* pKernel) { return new BS_OggTheora(pKernel); } - -// ----------------------------------------------------------------------------- -// BS_MoviePlayer Interface -// ----------------------------------------------------------------------------- - - -// ----------------------------------------------------------------------------- -// LoadMovie() mit Hilfsfunktionen -// ----------------------------------------------------------------------------- - -namespace -{ - inline bool VerifyRequiredServiceAvailability() - { - char * RequiredServices[] = { "gfx", "sfx", "package" }; - for (size_t i = 0; i < sizeof(RequiredServices) / sizeof(RequiredServices[0]); ++i) - { - if (!BS_Kernel::GetInstance()->GetService(RequiredServices[i])) - { - BS_LOG_ERRORLN("Required service \"%s\" is not active.", RequiredServices[i]); - return false; - } - } - - return true; - } - - // ------------------------------------------------------------------------- - - bool ParseStreamHeaders(auto_ptr & File, - auto_ptr & OggState, - auto_ptr & TheoraStreamState, - auto_ptr & VorbisStreamState, - auto_ptr & TheoraState, - auto_ptr & VorbisState, - bool & TheoraPresent, - bool & VorbisPresent, - const std::string & Filename) - { - TheoraPresent = false; - VorbisPresent = false; - - // Ogg file open; parse the headers - // Only interested in Vorbis/Theora streams - bool FinishedHeaderParsing = false; - while (!FinishedHeaderParsing) - { - if (File->BufferData(*OggState.get()) == 0) return false; - - ogg_page Page; - while(OggState->SyncPageout(&Page) > 0) - { - // is this a mandated initial header? If not, stop parsing - if(!ogg_page_bos(&Page)) - { - // don't leak the page; get it into the appropriate stream - if (TheoraPresent) TheoraStreamState->PageIn(&Page); - if (VorbisPresent) VorbisStreamState->PageIn(&Page); - - FinishedHeaderParsing = true; - break; - } - - auto_ptr streamState(new BS_OggStreamState(ogg_page_serialno(&Page))); - - streamState->PageIn(&Page); - - ogg_packet Packet; - streamState->PacketOut(&Packet); - - // identify the codec: try theora - if(!TheoraPresent && TheoraState->DecodeHeader(&Packet) >= 0) - { - // it is theora - TheoraStreamState = streamState; - TheoraPresent = true; - } - else if(!VorbisPresent && VorbisState->SynthesisHeaderIn(&Packet) >=0) - { - // it is vorbis - VorbisStreamState = streamState; - VorbisPresent = true; - } - } - // fall through to non-bos page parsing - } - - // we're expecting more header packets. - unsigned int TheoraPacketsRead = TheoraPresent ? 1 : 0; - unsigned int VorbisPacketsRead = VorbisPresent ? 1 : 0; - while((TheoraPresent && TheoraPacketsRead < 3) || (VorbisPresent && VorbisPacketsRead < 3)) - { - int ret; - ogg_packet Packet; - - // look for further theora headers - while(TheoraPresent && (TheoraPacketsRead < 3) && (ret = TheoraStreamState->PacketOut(&Packet))) - { - if(ret < 0 || TheoraState->DecodeHeader(&Packet)) - { - BS_LOG_ERRORLN("Error parsing Theora stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); - return false; - } - - ++TheoraPacketsRead; - if (TheoraPacketsRead == 3) break; - } - - // look for more vorbis header packets - while(VorbisPresent && (VorbisPacketsRead < 3) && (ret = VorbisStreamState->PacketOut(&Packet))) - { - if(ret < 0 || VorbisState->SynthesisHeaderIn(&Packet)) - { - BS_LOG_ERRORLN("Error parsing Vorbis stream headers. Stream is possibly corrupt. (%s)", Filename.c_str()); - return false; - } - - ++VorbisPacketsRead; - if (VorbisPacketsRead == 3) break; - } - - // The header pages/packets will arrive before anything else we care about, or the stream is not obeying spec - ogg_page Page; - if(OggState->SyncPageout(&Page) > 0) - { - // demux into the appropriate stream - if(TheoraPresent) TheoraStreamState->PageIn(&Page); - if(VorbisPresent) VorbisStreamState->PageIn(&Page); - } - else - { - if(File->BufferData(*OggState.get()) == 0) - { - BS_LOG_ERRORLN("End of file while searching for codec headers. (%s)", Filename.c_str()); - return false; - } - } - } - - return true; - } -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::LoadMovie(const std::string & Filename, unsigned int Z) -{ - if (!VerifyRequiredServiceAvailability()) return false; - - UnloadMovie(); - - // Alle Objekte die in dieser Funktion erzeugt werden, werden in zunächst lokalen Auto-Pointern gehalten. - // Bei erfolgreicher Beendigung dieser Funktion werden sie den objektlokalen Auto-Pointern zugewiesen. - // So wird sichergestellt, dass sie korrekt deinitialisiert werden, wenn in dieser Funktion ein Fehler auftritt, denn beim Zerstören der - // lokalen Auto-Pointer werden die entsprechenden Destruktoren aufgerufen. - - // Film laden - // Für Filmdateien wird das Cachingsystem nicht benutzt, da Filme in der Regel nur ein Mal abgespielt werden. - bool Success; - auto_ptr File(new BS_MovieFile(Filename, READ_BLOCK_SIZE, Success)); - if (!Success) return false; - - // States erzeugen für Ogg, Vorbis und Theora, sowie die Ogg und Theora Streams - auto_ptr OggState(new BS_OggState()); - auto_ptr VorbisState(new BS_VorbisState()); - auto_ptr TheoraState(new BS_TheoraState()); - - auto_ptr TheoraStreamState; - auto_ptr VorbisStreamState; - - if (!ParseStreamHeaders(File, OggState, TheoraStreamState, VorbisStreamState, TheoraState, VorbisState, m_TheoraPresent, m_VorbisPresent, Filename)) return false; - - // Theora-Decoder Initialisieren - if(m_TheoraPresent) - { - TheoraState->DecodeInit(); - - const theora_info & TheoraInfo = TheoraState->GetInfo(); - - if (TheoraInfo.pixelformat != OC_PF_444 && - TheoraInfo.pixelformat != OC_PF_422 && - TheoraInfo.pixelformat != OC_PF_420) - { - BS_LOG_ERRORLN("Unknown chroma sampling. (%s)", Filename.c_str()); - return false; - } - - // Ausgabebitmap erstellen - BS_GraphicEngine * pGfx = BS_Kernel::GetInstance()->GetGfx(); - m_OutputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(TheoraInfo.frame_width, TheoraInfo.frame_height); - if (!m_OutputBitmap.IsValid()) - { - BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); - return false; - } - - // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. - float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) m_OutputBitmap->GetWidth(); - float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) m_OutputBitmap->GetHeight(); - float ScaleFactor = std::min(ScreenToVideoWidth, ScreenToVideoHeight); - if (ABS(ScaleFactor - 1.0f) < FLT_EPSILON) ScaleFactor = 1.0f; - m_OutputBitmap->SetScaleFactor(ScaleFactor); - - // Z-Wert setzen - m_OutputBitmap->SetZ(Z); - - // Ausgabebitmap auf dem Bildschirm zentrieren - m_OutputBitmap->SetX((pGfx->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); - m_OutputBitmap->SetY((pGfx->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); - - // Buffer für die Pixeldaten erstellen - m_Pixels.resize(TheoraInfo.width * TheoraInfo.height * 4); - - m_VideoEnded = false; - } - - // Vorbis-Decoder initialisieren - if(m_VorbisPresent) - { - VorbisState->SynthesisInit(); - VorbisState->BlockInit(); - m_AudioBuffer.reset(new BS_AudioBuffer()); - - m_AudioEnded = false; - } - - // Keine Kopie, überträgt Besitz der erzeugten Objekte von der Funktion auf das Objekt. - m_File = File; - m_OggState = OggState; - m_TheoraState = TheoraState; - m_TheoraStreamState = TheoraStreamState; - m_VorbisState = VorbisState; - m_VorbisStreamState = VorbisStreamState; - m_MovieLoaded = true; - m_Timer = 0; - - return true; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::UnloadMovie() -{ - m_MovieLoaded = false; - m_Paused = true; - - m_VorbisStreamState.reset(); - m_VorbisPresent = false; - m_VorbisState.reset(); - if (m_SoundHandle) - { - BS_Kernel::GetInstance()->GetSfx()->StopSound(m_SoundHandle); - m_SoundHandle = 0; - } - m_AudioEnded = true; - m_AudioBuffer.reset(); - - m_TheoraStreamState.reset(); - m_TheoraPresent = false; - m_TheoraState.reset(); - m_VideoEnded = true; - - m_OggState.reset(); - - m_File.reset(); - - m_StartTime = 0; - m_LastFrameTime = 0; - m_Timer = 0.0f; - - vector().swap(m_Pixels); - m_OutputBitmap.Erase(); - - return true; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::Play() -{ - if (m_MovieLoaded) - { - if (m_Paused) - { - if (m_SoundHandle) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - SfxPtr->ResumeSound(m_SoundHandle); - } - m_Paused = false; - } - - return true; - } - else - { - BS_LOG_WARNINGLN("Cannot play movie, when no movie is loaded."); - return false; - } -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::Pause() -{ - if (m_MovieLoaded) - { - if (m_SoundHandle) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - SfxPtr->PauseSound(m_SoundHandle); - } - - m_Paused = true; - return true; - } - else - { - BS_LOG_WARNINGLN("Cannot pause movie, when no movie is loaded."); - return false; - } -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::ReadData() -{ - if (!m_File->IsEOF()) m_File->BufferData(*m_OggState.get()); - - ogg_page Page; - while(m_OggState->SyncPageout(&Page) > 0) - { - if(m_TheoraPresent) m_TheoraStreamState->BufferPage(&Page); - if(m_VorbisPresent) m_VorbisStreamState->BufferPage(&Page); - } -} - -void BS_OggTheora::Update() -{ - if (m_AudioEnded && m_VideoEnded) - { - m_Paused = true; - - // Falls der Sound noch läuft, muss er jetzt beendet werden. - if (m_SoundHandle) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - SfxPtr->StopSound(m_SoundHandle); - m_SoundHandle = 0; - } - } - - if (m_Paused) return; - - // Timer aktualisieren. - // Wird nur genutzt, wenn keine Audiodaten vorhanden sind. - m_Timer += BS_Kernel::GetInstance()->GetGfx()->GetSecondaryFrameDuration(); - - // Audiodaten dekodieren - if (m_VorbisPresent && !m_AudioEnded) DecodeVorbis(); - - - // Videodaten dekodieren - if (m_TheoraPresent && !m_VideoEnded) - { - bool Result = DecodeTheora(); - - if (Result) - { - // YUV Framebuffer holen - yuv_buffer YUVBuffer; - m_TheoraState->DecodeYUVOut(&YUVBuffer); - - // YUV Bilddaten nach RGBA konvertieren - BS_YUVtoRGBA::YUVtoRGBA(YUVBuffer, m_TheoraState->GetInfo(), m_Pixels); - - // RGBA Bilddaten auf das Ausgabebild kopieren, dabei die Postion des Theoraframes innerhalb des dekodierten Frames beachten. - const theora_info & TheoraInfo = m_TheoraState->GetInfo(); - m_OutputBitmap->SetContent(m_Pixels, (TheoraInfo.offset_x + TheoraInfo.width * TheoraInfo.offset_y) * 4, (TheoraInfo.width - TheoraInfo.frame_width) * 4); - } - } -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::DecodeTheora() -{ - double MovieTime = GetTime(); - - // Check if this frame time has not passed yet. If the frame is late we need - // to decode additonal ones and keep looping, since theora at this stage - // needs to decode all frames (due to keyframing) - // Getting the current time once at the beginning of the function rather than - // every time at the beginning of the loop produces the smoothest framerate - - unsigned int FramesDecoded = 0; - bool FrameReady = false; - while (m_TheoraState->GranuleTime() < MovieTime) - { - // theora is one in, one out... - ogg_packet Packet; - if(m_TheoraStreamState->PacketOut(&Packet) > 0) - { - if (FramesDecoded < MAX_FRAMES_PER_TICK || Packet.granulepos >= MovieTime) - { - m_TheoraState->DecodePacketIn(&Packet); - FrameReady = true; - ++FramesDecoded; - } - } - else - { - if (m_TheoraStreamState->GetPageBufferSize() > 0) - m_TheoraStreamState->PageInBufferedPage(); - else - { - if(m_File->IsEOF()) - { - m_VideoEnded = true; - break; - } - else - ReadData(); - } - } - } - m_LastFrameTime = MovieTime; - - return FrameReady; -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength) -{ - BS_OggTheora & t = *reinterpret_cast(UserData); - - signed short * Buffer = reinterpret_cast(Data); - - // Audiodaten in den Soundbuffer schreiben. - DataLength -= t.m_AudioBuffer->Pop(Buffer, DataLength / 2) * 2; - - // Falls nicht genug Audiodaten vorhanden waren, wird der Rest mit Stille überschrieben. - if (DataLength) - { - char * ByteBuffer = reinterpret_cast(Buffer); - while (DataLength--) - { - *ByteBuffer++ = 0; - } - } -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::DecodeVorbis() -{ - // Vorbis-Stream Infos holen. - const vorbis_info & Info = m_VorbisState->GetInfo(); - - // Maximalgröße des Audiobuffers berechnen. - size_t MaxAudioBufferSamples = static_cast(Info.channels * Info.rate * MAX_AUDIO_BUFFER_LENGTH); - - // Zwischenspeicher für die Samples. - vector Samples; - - // Audiobuffer bis zur Maximalgröße füllen, wenn möglich. - while (m_AudioBuffer->Size() < MaxAudioBufferSamples) - { - // Vorhandene Audiodaten auslesen - float ** PCM; - int SampleCount = m_VorbisState->SynthesisPCMout(&PCM); - - // Wenn Audiodaten gelesen werden konnten, werden diese in 16-Bit Sample umgewandelt und in den Audiobuffer geschrieben. - if(SampleCount > 0) - { - // Im Samplezwischenspeicher leeren und genügend Platz für die kommenden Samples reservieren. - Samples.reserve(SampleCount); - Samples.clear(); - - // Samples konvertieren und in die Samplezwischenspeicher schreiben. - for (int i = 0; i < SampleCount; ++i) - { - for(int j = 0; j < Info.channels; ++j) - { - int SampleValue = static_cast(PCM[j][i] * 32767.0f); - Samples.push_back(Clamp(SampleValue, -32700, 32700)); - } - } - - // Daten aus dem Samplezwischenspeicher in den Audiobuffer schreiben. - m_AudioBuffer->Push(&Samples[0], Samples.size()); - - // Vorbis mitteilen, dass wir alle Samples gelesen haben. - m_VorbisState->SynthesisRead(SampleCount); - } - else - { - // Wir konnten, keine Audiodaten auslesen, versuchen ein neues Paket zu dekodieren. - ogg_packet Packet; - if(m_VorbisStreamState->PacketOut(&Packet) > 0) - { - if (m_VorbisState->Synthesis(&Packet) == 0) m_VorbisState->SynthesisBlockIn(); - } - else - { - // Gepufferte Daten in den Stream einfügen. - if (m_VorbisStreamState->GetPageBufferSize() > 0) - m_VorbisStreamState->PageInBufferedPage(); - else - { - // Nicht genug Daten vorhanden. Wenn die Datei leer ist und bereits alle Audiodaten gelesen wurden, ist der Audiostream am Ende. - // Ansonsten Daten nachladen. - if(m_File->IsEOF()) - { - if (m_AudioBuffer->Size() == 0) - { - m_AudioEnded = true; - } - - break; - } - else - ReadData(); - } - } - } - } - - // Soundkanal abspielen, wenn er noch nicht spielt und Audiodaten vorhanden sind. - if (m_SoundHandle == 0 && m_AudioBuffer->Size()) - { - BS_SoundEngine * SfxPtr = BS_Kernel::GetInstance()->GetSfx(); - m_SoundHandle = SfxPtr->PlayDynamicSoundEx(&DynamicSoundCallBack, this, BS_SoundEngine::SFX, Info.rate, 16, Info.channels); - } -} - -// ----------------------------------------------------------------------------- - -double BS_OggTheora::GetTime() -{ - if(m_VorbisPresent) - { - if (m_SoundHandle) - { - float time = BS_Kernel::GetInstance()->GetSfx()->GetSoundTime(m_SoundHandle); - return time; - } - else - return 0.0f; - } - else - return m_Timer; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::IsMovieLoaded() -{ - return m_MovieLoaded; -} - -// ----------------------------------------------------------------------------- - -bool BS_OggTheora::IsPaused() -{ - return m_Paused; -} - -// ----------------------------------------------------------------------------- - -float BS_OggTheora::GetScaleFactor() -{ - if (m_MovieLoaded) - return m_OutputBitmap->GetScaleFactorX(); - else - return 0; -} - -// ----------------------------------------------------------------------------- - -void BS_OggTheora::SetScaleFactor(float ScaleFactor) -{ - if (m_MovieLoaded) - { - m_OutputBitmap->SetScaleFactor(ScaleFactor); - - // Ausgabebitmap auf dem Bildschirm zentrieren - BS_GraphicEngine * GfxPtr = BS_Kernel::GetInstance()->GetGfx(); - m_OutputBitmap->SetX((GfxPtr->GetDisplayWidth() - m_OutputBitmap->GetWidth()) / 2); - m_OutputBitmap->SetY((GfxPtr->GetDisplayHeight() - m_OutputBitmap->GetHeight()) / 2); - } -} diff --git a/engines/sword25/fmv/oggtheora/oggtheora.h b/engines/sword25/fmv/oggtheora/oggtheora.h deleted file mode 100644 index 62fa607935..0000000000 --- a/engines/sword25/fmv/oggtheora/oggtheora.h +++ /dev/null @@ -1,124 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_OGGTHEORA_H -#define SWORD25_OGGTHEORA_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/memlog_off.h" -#include -#include -#include -#include "sword25/kernel/memlog_on.h" - -#include "sword25/kernel/common.h" -#include "sword25/kernel/bs_stdint.h" -#include "sword25/gfx/bitmap.h" -#include "sword25/gfx/renderobjectptr.h" -#include "sword25/fmv/movieplayer.h" -#include "sword25/fmv/oggtheora/vorbisstate.h" -#include "sword25/fmv/oggtheora/theorastate.h" -#include "sword25/fmv/oggtheora/oggstate.h" -#include "sword25/fmv/oggtheora/oggstreamstate.h" -#include "sword25/fmv/oggtheora/moviefile.h" -#include "sword25/fmv/oggtheora/audiobuffer.h" - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_OggTheora : public BS_MoviePlayer -{ -public: - // ----------------------------------------------------------------------------- - // Konstruktion / Destruktion - // ----------------------------------------------------------------------------- - - BS_OggTheora(BS_Kernel * pKernel); - virtual ~BS_OggTheora(); - - // ----------------------------------------------------------------------------- - // BS_MoviePlayer Interface - // ----------------------------------------------------------------------------- - - virtual bool LoadMovie(const std::string & Filename, unsigned int Z); - virtual bool UnloadMovie(); - virtual bool Play(); - virtual bool Pause(); - virtual void Update(); - virtual bool IsMovieLoaded(); - virtual bool IsPaused(); - virtual float GetScaleFactor(); - virtual void SetScaleFactor(float ScaleFactor); - virtual double GetTime(); - -private: - bool DecodeTheora(); - void DecodeVorbis(); - void RefillOggBuffer(); - void ReadData(); - static void DynamicSoundCallBack(void * UserData, void * Data, unsigned int DataLength); - - bool m_MovieLoaded; - bool m_Paused; - - std::auto_ptr m_VorbisStreamState; - bool m_VorbisPresent; - std::auto_ptr m_VorbisState; - unsigned int m_SoundHandle; - bool m_AudioEnded; - std::auto_ptr m_AudioBuffer; - - std::auto_ptr m_TheoraStreamState; - bool m_TheoraPresent; - std::auto_ptr m_TheoraState; - bool m_VideoEnded; - - std::auto_ptr m_OggState; - - std::auto_ptr m_File; - - uint64_t m_StartTime; - double m_LastFrameTime; - - float m_Timer; - - std::vector m_Pixels; - BS_RenderObjectPtr m_OutputBitmap; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/theorastate.cpp b/engines/sword25/fmv/oggtheora/theorastate.cpp deleted file mode 100644 index a270bab80c..0000000000 --- a/engines/sword25/fmv/oggtheora/theorastate.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/fmv/oggtheora/theorastate.h" - -// ----------------------------------------------------------------------------- - -BS_TheoraState::BS_TheoraState() : - m_StateInitialized(false) -{ - theora_comment_init(&m_Comment); - theora_info_init(&m_Info); -} - -// ----------------------------------------------------------------------------- - -BS_TheoraState::~BS_TheoraState() -{ - if (m_StateInitialized) theora_clear(&m_State); - theora_info_clear(&m_Info); - theora_comment_clear(&m_Comment); -} - -// ----------------------------------------------------------------------------- - -int BS_TheoraState::DecodeHeader(ogg_packet * OggPacketPtr) -{ - return theora_decode_header(&m_Info, &m_Comment, OggPacketPtr); -} - -// ----------------------------------------------------------------------------- - -int BS_TheoraState::DecodeInit() -{ - int Result = theora_decode_init(&m_State, &m_Info); - m_StateInitialized = (Result == 0); - return Result; -} - -// ----------------------------------------------------------------------------- - -double BS_TheoraState::GranuleTime() -{ - return theora_granule_time(&m_State, m_State.granulepos); -} - -// ----------------------------------------------------------------------------- - -int BS_TheoraState::DecodePacketIn(ogg_packet * OggPacketPtr) -{ - return theora_decode_packetin(&m_State, OggPacketPtr); -} - -// ----------------------------------------------------------------------------- - -int BS_TheoraState::DecodeYUVOut(yuv_buffer * YUV) -{ - return theora_decode_YUVout(&m_State, YUV); -} diff --git a/engines/sword25/fmv/oggtheora/theorastate.h b/engines/sword25/fmv/oggtheora/theorastate.h deleted file mode 100644 index 07934c26ea..0000000000 --- a/engines/sword25/fmv/oggtheora/theorastate.h +++ /dev/null @@ -1,70 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_THEORASTATE_H -#define SWORD25_THEORASTATE_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" -#include - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_TheoraState -{ -public: - BS_TheoraState(); - virtual ~BS_TheoraState(); - - int DecodeHeader(ogg_packet * OggPacketPtr); - int DecodeInit(); - int DecodePacketIn(ogg_packet * OggPacketPtr); - int DecodeYUVOut(yuv_buffer * YUV); - double GranuleTime(); - - const theora_info & GetInfo() const { return m_Info; } - -private: - theora_info m_Info; - theora_comment m_Comment; - bool m_StateInitialized; - theora_state m_State; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.cpp b/engines/sword25/fmv/oggtheora/vorbisstate.cpp deleted file mode 100644 index e9f6b7dc4f..0000000000 --- a/engines/sword25/fmv/oggtheora/vorbisstate.cpp +++ /dev/null @@ -1,112 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/fmv/oggtheora/vorbisstate.h" - -// ----------------------------------------------------------------------------- - -BS_VorbisState::BS_VorbisState() : - m_DSPStateInitialized(false), - m_BlockInitialized(false) -{ - vorbis_info_init(&m_Info); - vorbis_comment_init(&m_Comment); -} - -// ----------------------------------------------------------------------------- - -BS_VorbisState::~BS_VorbisState() -{ - if (m_BlockInitialized) vorbis_block_clear(&m_Block); - if (m_DSPStateInitialized) vorbis_dsp_clear(&m_DSPState); - vorbis_comment_clear(&m_Comment); - vorbis_info_clear(&m_Info); -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::SynthesisHeaderIn(ogg_packet * OggPacketPtr) -{ - return vorbis_synthesis_headerin(&m_Info, &m_Comment, OggPacketPtr); -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::SynthesisInit() -{ - int Result = vorbis_synthesis_init(&m_DSPState, &m_Info); - m_DSPStateInitialized = (Result == 0); - return Result; -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::BlockInit() -{ - int Result = vorbis_block_init(&m_DSPState, &m_Block); - m_BlockInitialized = (Result == 0); - return Result; -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::SynthesisPCMout(float *** PCM) -{ - return vorbis_synthesis_pcmout(&m_DSPState, PCM); -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::SynthesisRead(int Samples) -{ - return vorbis_synthesis_read(&m_DSPState, Samples); -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::Synthesis(ogg_packet * OggPacketPtr) -{ - return vorbis_synthesis(&m_Block, OggPacketPtr); -} - -// ----------------------------------------------------------------------------- - -int BS_VorbisState::SynthesisBlockIn() -{ - return vorbis_synthesis_blockin(&m_DSPState, &m_Block); -} diff --git a/engines/sword25/fmv/oggtheora/vorbisstate.h b/engines/sword25/fmv/oggtheora/vorbisstate.h deleted file mode 100644 index 126e59d0aa..0000000000 --- a/engines/sword25/fmv/oggtheora/vorbisstate.h +++ /dev/null @@ -1,74 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_VORBISSTATE_H -#define SWORD25_VORBISSTATE_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/common.h" -#include - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_VorbisState -{ -public: - BS_VorbisState(); - virtual ~BS_VorbisState(); - - int SynthesisHeaderIn(ogg_packet * OggPacketPtr); - int SynthesisInit(); - int BlockInit(); - int SynthesisPCMout(float *** PCM); - int SynthesisRead(int Samples); - int Synthesis(ogg_packet * OggPacketPtr); - int SynthesisBlockIn(); - - const vorbis_info & GetInfo() const { return m_Info; } - -private: - vorbis_info m_Info; - bool m_DSPStateInitialized; - vorbis_dsp_state m_DSPState; - bool m_BlockInitialized; - vorbis_block m_Block; - vorbis_comment m_Comment; -}; - -#endif diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp b/engines/sword25/fmv/oggtheora/yuvtorgba.cpp deleted file mode 100644 index d835d2ba0b..0000000000 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.cpp +++ /dev/null @@ -1,431 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/cpuinfo.h" -#include "sword25/fmv/ogghteora/yuvtorgba.h" - -#include - -using namespace std; - -// ----------------------------------------------------------------------------- - -namespace -{ - - static const int PRECISION = 32768; - static const int COEFFS_Y[256] = { - -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, - 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, - 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, - 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, - 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, - 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, - 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, - 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, - 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, - 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, - 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, - 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, - 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, - 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, - 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, - 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, - }; - static const int COEFFS_RV[256] = { - -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, - -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, - -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, - -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, - -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, - -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, - -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, - -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, - 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, - 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, - 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, - 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, - 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, - 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, - 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, - 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, - }; - static const int COEFFS_GU[256] = { - 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, - 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, - 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, - 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, - 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, - 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, - 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, - 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, - 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, - -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, - -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, - -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, - -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, - -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, - -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, - -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, - }; - static const int COEFFS_GV[256] = { - 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, - 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, - 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, - 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, - 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, - 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, - 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, - 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, - 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, - -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, - -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, - -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, - -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, - -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, - -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, - -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, - }; - static const int COEFFS_BU[256] = { - -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, - -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, - -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, - -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, - -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, - -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, - -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, - -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, - 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, - 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, - 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, - 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, - 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, - 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, - 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, - 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, - }; - static const int CLAMP_TAB[1024] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, - 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, - 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, - 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, - 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, - 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, - 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, - }; - - void YUVtoRGBA_c(const yuv_buffer & YUVBuffer, std::vector & PixelData) - { - // Width and height of all buffers have to be divisible by 2. - BS_ASSERT((YUVBuffer.y_width & 1) == 0); - BS_ASSERT((YUVBuffer.y_height & 1) == 0); - BS_ASSERT((YUVBuffer.uv_width & 1) == 0); - BS_ASSERT((YUVBuffer.uv_height & 1) == 0); - // UV images have to have a quarter of the Y image resolution - BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); - BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); - - const int *cl = &CLAMP_TAB[320]; - - const unsigned char * ySrc0 = YUVBuffer.y; - const unsigned char * ySrc1 = YUVBuffer.y + YUVBuffer.y_stride; - const unsigned char * uSrc = YUVBuffer.u; - const unsigned char * vSrc = YUVBuffer.v; - unsigned char * dst0 = &PixelData[0]; - unsigned char * dst1 = &PixelData[0] + YUVBuffer.y_width * 4; - - for (int h = 0; h < YUVBuffer.y_height / 2; ++h) - { - for (int w = 0; w < YUVBuffer.y_width / 2; ++w) - { - int u = *uSrc++; - int v = *vSrc++; - - int rUV = COEFFS_RV[v]; - int gUV = COEFFS_GU[u] + COEFFS_GV[v]; - int bUV = COEFFS_BU[u]; - - int y = *ySrc0++; - int r = COEFFS_Y[y] + rUV; - int g = COEFFS_Y[y] + gUV; - int b = COEFFS_Y[y] + bUV; - *dst0++ = cl[r / PRECISION]; - *dst0++ = cl[g / PRECISION]; - *dst0++ = cl[b / PRECISION]; - *dst0++ = 255; - - y = *ySrc1++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst1++ = cl[r / PRECISION]; - *dst1++ = cl[g / PRECISION]; - *dst1++ = cl[b / PRECISION]; - *dst1++ = 255; - - y = *ySrc0++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst0++ = cl[r / PRECISION]; - *dst0++ = cl[g / PRECISION]; - *dst0++ = cl[b / PRECISION]; - *dst0++ = 255; - - y = *ySrc1++; - r = COEFFS_Y[y] + rUV; - g = COEFFS_Y[y] + gUV; - b = COEFFS_Y[y] + bUV; - *dst1++ = cl[r / PRECISION]; - *dst1++ = cl[g / PRECISION]; - *dst1++ = cl[b / PRECISION]; - *dst1++ = 255; - } - - dst0 += YUVBuffer.y_width * 4; - dst1 += YUVBuffer.y_width * 4; - ySrc0 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; - ySrc1 += YUVBuffer.y_stride * 2 - YUVBuffer.y_width; - uSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; - vSrc += YUVBuffer.uv_stride - YUVBuffer.uv_width; - } - } - - // ----------------------------------------------------------------------------- - - static const __m64 COEFF_Y_MMX[256] = { - 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, - 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, 0x1fff000000000000, - 0x1fff000000000000, 0x1fff004a004a004a, 0x1fff009500950095, 0x1fff00df00df00df, 0x1fff012a012a012a, 0x1fff017401740174, 0x1fff01bf01bf01bf, 0x1fff020902090209, - 0x1fff025402540254, 0x1fff029e029e029e, 0x1fff02e902e902e9, 0x1fff033303330333, 0x1fff037e037e037e, 0x1fff03c803c803c8, 0x1fff041304130413, 0x1fff045d045d045d, - 0x1fff04a804a804a8, 0x1fff04f204f204f2, 0x1fff053d053d053d, 0x1fff058705870587, 0x1fff05d205d205d2, 0x1fff061c061c061c, 0x1fff066706670667, 0x1fff06b106b106b1, - 0x1fff06fc06fc06fc, 0x1fff074607460746, 0x1fff079107910791, 0x1fff07db07db07db, 0x1fff082608260826, 0x1fff087008700870, 0x1fff08bb08bb08bb, 0x1fff090509050905, - 0x1fff095009500950, 0x1fff099a099a099a, 0x1fff09e509e509e5, 0x1fff0a2f0a2f0a2f, 0x1fff0a7a0a7a0a7a, 0x1fff0ac40ac40ac4, 0x1fff0b0f0b0f0b0f, 0x1fff0b590b590b59, - 0x1fff0ba40ba40ba4, 0x1fff0bee0bee0bee, 0x1fff0c390c390c39, 0x1fff0c830c830c83, 0x1fff0cce0cce0cce, 0x1fff0d180d180d18, 0x1fff0d630d630d63, 0x1fff0dad0dad0dad, - 0x1fff0df80df80df8, 0x1fff0e420e420e42, 0x1fff0e8d0e8d0e8d, 0x1fff0ed70ed70ed7, 0x1fff0f220f220f22, 0x1fff0f6c0f6c0f6c, 0x1fff0fb70fb70fb7, 0x1fff100110011001, - 0x1fff104c104c104c, 0x1fff109610961096, 0x1fff10e110e110e1, 0x1fff112b112b112b, 0x1fff117611761176, 0x1fff11c011c011c0, 0x1fff120b120b120b, 0x1fff125512551255, - 0x1fff12a012a012a0, 0x1fff12ea12ea12ea, 0x1fff133513351335, 0x1fff137f137f137f, 0x1fff13ca13ca13ca, 0x1fff141414141414, 0x1fff145f145f145f, 0x1fff14a914a914a9, - 0x1fff14f414f414f4, 0x1fff153e153e153e, 0x1fff158915891589, 0x1fff15d315d315d3, 0x1fff161e161e161e, 0x1fff166816681668, 0x1fff16b316b316b3, 0x1fff16fd16fd16fd, - 0x1fff174817481748, 0x1fff179217921792, 0x1fff17dd17dd17dd, 0x1fff182718271827, 0x1fff187218721872, 0x1fff18bc18bc18bc, 0x1fff190719071907, 0x1fff195119511951, - 0x1fff199c199c199c, 0x1fff19e619e619e6, 0x1fff1a311a311a31, 0x1fff1a7b1a7b1a7b, 0x1fff1ac61ac61ac6, 0x1fff1b101b101b10, 0x1fff1b5b1b5b1b5b, 0x1fff1ba51ba51ba5, - 0x1fff1bf01bf01bf0, 0x1fff1c3a1c3a1c3a, 0x1fff1c851c851c85, 0x1fff1ccf1ccf1ccf, 0x1fff1d1a1d1a1d1a, 0x1fff1d641d641d64, 0x1fff1daf1daf1daf, 0x1fff1df91df91df9, - 0x1fff1e441e441e44, 0x1fff1e8e1e8e1e8e, 0x1fff1ed91ed91ed9, 0x1fff1f231f231f23, 0x1fff1f6e1f6e1f6e, 0x1fff1fb81fb81fb8, 0x1fff200320032003, 0x1fff204d204d204d, - 0x1fff209820982098, 0x1fff20e220e220e2, 0x1fff212d212d212d, 0x1fff217721772177, 0x1fff21c221c221c2, 0x1fff220c220c220c, 0x1fff225722572257, 0x1fff22a122a122a1, - 0x1fff22ec22ec22ec, 0x1fff233623362336, 0x1fff238123812381, 0x1fff23cb23cb23cb, 0x1fff241624162416, 0x1fff246024602460, 0x1fff24aa24aa24aa, 0x1fff24f524f524f5, - 0x1fff253f253f253f, 0x1fff258a258a258a, 0x1fff25d425d425d4, 0x1fff261f261f261f, 0x1fff266926692669, 0x1fff26b426b426b4, 0x1fff26fe26fe26fe, 0x1fff274927492749, - 0x1fff279327932793, 0x1fff27de27de27de, 0x1fff282828282828, 0x1fff287328732873, 0x1fff28bd28bd28bd, 0x1fff290829082908, 0x1fff295229522952, 0x1fff299d299d299d, - 0x1fff29e729e729e7, 0x1fff2a322a322a32, 0x1fff2a7c2a7c2a7c, 0x1fff2ac72ac72ac7, 0x1fff2b112b112b11, 0x1fff2b5c2b5c2b5c, 0x1fff2ba62ba62ba6, 0x1fff2bf12bf12bf1, - 0x1fff2c3b2c3b2c3b, 0x1fff2c862c862c86, 0x1fff2cd02cd02cd0, 0x1fff2d1b2d1b2d1b, 0x1fff2d652d652d65, 0x1fff2db02db02db0, 0x1fff2dfa2dfa2dfa, 0x1fff2e452e452e45, - 0x1fff2e8f2e8f2e8f, 0x1fff2eda2eda2eda, 0x1fff2f242f242f24, 0x1fff2f6f2f6f2f6f, 0x1fff2fb92fb92fb9, 0x1fff300430043004, 0x1fff304e304e304e, 0x1fff309930993099, - 0x1fff30e330e330e3, 0x1fff312e312e312e, 0x1fff317831783178, 0x1fff31c331c331c3, 0x1fff320d320d320d, 0x1fff325832583258, 0x1fff32a232a232a2, 0x1fff32ed32ed32ed, - 0x1fff333733373337, 0x1fff338233823382, 0x1fff33cc33cc33cc, 0x1fff341734173417, 0x1fff346134613461, 0x1fff34ac34ac34ac, 0x1fff34f634f634f6, 0x1fff354135413541, - 0x1fff358b358b358b, 0x1fff35d635d635d6, 0x1fff362036203620, 0x1fff366b366b366b, 0x1fff36b536b536b5, 0x1fff370037003700, 0x1fff374a374a374a, 0x1fff379537953795, - 0x1fff37df37df37df, 0x1fff382a382a382a, 0x1fff387438743874, 0x1fff38bf38bf38bf, 0x1fff390939093909, 0x1fff395439543954, 0x1fff399e399e399e, 0x1fff39e939e939e9, - 0x1fff3a333a333a33, 0x1fff3a7e3a7e3a7e, 0x1fff3ac83ac83ac8, 0x1fff3b133b133b13, 0x1fff3b5d3b5d3b5d, 0x1fff3ba83ba83ba8, 0x1fff3bf23bf23bf2, 0x1fff3c3d3c3d3c3d, - 0x1fff3c873c873c87, 0x1fff3cd23cd23cd2, 0x1fff3d1c3d1c3d1c, 0x1fff3d673d673d67, 0x1fff3db13db13db1, 0x1fff3dfc3dfc3dfc, 0x1fff3e463e463e46, 0x1fff3e913e913e91, - 0x1fff3edb3edb3edb, 0x1fff3f263f263f26, 0x1fff3f703f703f70, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, - 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, - 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, 0x1fff3fbb3fbb3fbb, - }; - static const __m64 COEFF_U_MMX[256] = { - 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, - 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, 0x1fffc7800af30000, - 0x1fffc7800af30000, 0x1fffc8010ada0000, 0x1fffc8820ac10000, 0x1fffc9030aa80000, 0x1fffc9850a8f0000, 0x1fffca060a760000, 0x1fffca870a5d0000, 0x1fffcb080a440000, - 0x1fffcb890a2a0000, 0x1fffcc0a0a110000, 0x1fffcc8b09f80000, 0x1fffcd0d09df0000, 0x1fffcd8e09c60000, 0x1fffce0f09ad0000, 0x1fffce9009940000, 0x1fffcf11097b0000, - 0x1fffcf9209620000, 0x1fffd01409490000, 0x1fffd09509300000, 0x1fffd11609170000, 0x1fffd19708fe0000, 0x1fffd21808e50000, 0x1fffd29908cc0000, 0x1fffd31a08b30000, - 0x1fffd39c089a0000, 0x1fffd41d08810000, 0x1fffd49e08680000, 0x1fffd51f084f0000, 0x1fffd5a008360000, 0x1fffd621081d0000, 0x1fffd6a308040000, 0x1fffd72407eb0000, - 0x1fffd7a507d20000, 0x1fffd82607b90000, 0x1fffd8a707a00000, 0x1fffd92807870000, 0x1fffd9a9076e0000, 0x1fffda2b07550000, 0x1fffdaac073c0000, 0x1fffdb2d07230000, - 0x1fffdbae070a0000, 0x1fffdc2f06f10000, 0x1fffdcb006d80000, 0x1fffdd3206bf0000, 0x1fffddb306a60000, 0x1fffde34068d0000, 0x1fffdeb506740000, 0x1fffdf36065b0000, - 0x1fffdfb706420000, 0x1fffe03806290000, 0x1fffe0ba060f0000, 0x1fffe13b05f60000, 0x1fffe1bc05dd0000, 0x1fffe23d05c40000, 0x1fffe2be05ab0000, 0x1fffe33f05920000, - 0x1fffe3c005790000, 0x1fffe44205600000, 0x1fffe4c305470000, 0x1fffe544052e0000, 0x1fffe5c505150000, 0x1fffe64604fc0000, 0x1fffe6c704e30000, 0x1fffe74904ca0000, - 0x1fffe7ca04b10000, 0x1fffe84b04980000, 0x1fffe8cc047f0000, 0x1fffe94d04660000, 0x1fffe9ce044d0000, 0x1fffea4f04340000, 0x1fffead1041b0000, 0x1fffeb5204020000, - 0x1fffebd303e90000, 0x1fffec5403d00000, 0x1fffecd503b70000, 0x1fffed56039e0000, 0x1fffedd803850000, 0x1fffee59036c0000, 0x1fffeeda03530000, 0x1fffef5b033a0000, - 0x1fffefdc03210000, 0x1ffff05d03080000, 0x1ffff0de02ef0000, 0x1ffff16002d60000, 0x1ffff1e102bd0000, 0x1ffff26202a40000, 0x1ffff2e3028b0000, 0x1ffff36402720000, - 0x1ffff3e502590000, 0x1ffff46702400000, 0x1ffff4e802270000, 0x1ffff569020e0000, 0x1ffff5ea01f40000, 0x1ffff66b01db0000, 0x1ffff6ec01c20000, 0x1ffff76d01a90000, - 0x1ffff7ef01900000, 0x1ffff87001770000, 0x1ffff8f1015e0000, 0x1ffff97201450000, 0x1ffff9f3012c0000, 0x1ffffa7401130000, 0x1ffffaf500fa0000, 0x1ffffb7700e10000, - 0x1ffffbf800c80000, 0x1ffffc7900af0000, 0x1ffffcfa00960000, 0x1ffffd7b007d0000, 0x1ffffdfc00640000, 0x1ffffe7e004b0000, 0x1ffffeff00320000, 0x1fffff8000190000, - 0x1fff000000000000, 0x1fff0081ffe80000, 0x1fff0102ffcf0000, 0x1fff0183ffb60000, 0x1fff0205ff9d0000, 0x1fff0286ff840000, 0x1fff0307ff6b0000, 0x1fff0388ff520000, - 0x1fff0409ff390000, 0x1fff048aff200000, 0x1fff050cff070000, 0x1fff058dfeee0000, 0x1fff060efed50000, 0x1fff068ffebc0000, 0x1fff0710fea30000, 0x1fff0791fe8a0000, - 0x1fff0812fe710000, 0x1fff0894fe580000, 0x1fff0915fe3f0000, 0x1fff0996fe260000, 0x1fff0a17fe0d0000, 0x1fff0a98fdf30000, 0x1fff0b19fdda0000, 0x1fff0b9afdc10000, - 0x1fff0c1cfda80000, 0x1fff0c9dfd8f0000, 0x1fff0d1efd760000, 0x1fff0d9ffd5d0000, 0x1fff0e20fd440000, 0x1fff0ea1fd2b0000, 0x1fff0f23fd120000, 0x1fff0fa4fcf90000, - 0x1fff1025fce00000, 0x1fff10a6fcc70000, 0x1fff1127fcae0000, 0x1fff11a8fc950000, 0x1fff1229fc7c0000, 0x1fff12abfc630000, 0x1fff132cfc4a0000, 0x1fff13adfc310000, - 0x1fff142efc180000, 0x1fff14affbff0000, 0x1fff1530fbe60000, 0x1fff15b2fbcd0000, 0x1fff1633fbb40000, 0x1fff16b4fb9b0000, 0x1fff1735fb820000, 0x1fff17b6fb690000, - 0x1fff1837fb500000, 0x1fff18b8fb370000, 0x1fff193afb1e0000, 0x1fff19bbfb050000, 0x1fff1a3cfaec0000, 0x1fff1abdfad30000, 0x1fff1b3efaba0000, 0x1fff1bbffaa10000, - 0x1fff1c41fa880000, 0x1fff1cc2fa6f0000, 0x1fff1d43fa560000, 0x1fff1dc4fa3d0000, 0x1fff1e45fa240000, 0x1fff1ec6fa0b0000, 0x1fff1f47f9f20000, 0x1fff1fc9f9d80000, - 0x1fff204af9bf0000, 0x1fff20cbf9a60000, 0x1fff214cf98d0000, 0x1fff21cdf9740000, 0x1fff224ef95b0000, 0x1fff22cff9420000, 0x1fff2351f9290000, 0x1fff23d2f9100000, - 0x1fff2453f8f70000, 0x1fff24d4f8de0000, 0x1fff2555f8c50000, 0x1fff25d6f8ac0000, 0x1fff2658f8930000, 0x1fff26d9f87a0000, 0x1fff275af8610000, 0x1fff27dbf8480000, - 0x1fff285cf82f0000, 0x1fff28ddf8160000, 0x1fff295ef7fd0000, 0x1fff29e0f7e40000, 0x1fff2a61f7cb0000, 0x1fff2ae2f7b20000, 0x1fff2b63f7990000, 0x1fff2be4f7800000, - 0x1fff2c65f7670000, 0x1fff2ce7f74e0000, 0x1fff2d68f7350000, 0x1fff2de9f71c0000, 0x1fff2e6af7030000, 0x1fff2eebf6ea0000, 0x1fff2f6cf6d10000, 0x1fff2fedf6b80000, - 0x1fff306ff69f0000, 0x1fff30f0f6860000, 0x1fff3171f66d0000, 0x1fff31f2f6540000, 0x1fff3273f63b0000, 0x1fff32f4f6220000, 0x1fff3376f6090000, 0x1fff33f7f5f00000, - 0x1fff3478f5d70000, 0x1fff34f9f5bd0000, 0x1fff357af5a40000, 0x1fff35fbf58b0000, 0x1fff367cf5720000, 0x1fff36fef5590000, 0x1fff377ff5400000, 0x1fff3800f5270000, - 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, - 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, 0x1fff3881f50e0000, - }; - static const __m64 COEFF_V_MMX[256] = { - 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, - 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, 0x1fff000016c4d351, - 0x1fff000016c4d351, 0x1fff00001690d3b7, 0x1fff0000165cd41d, 0x1fff00001627d483, 0x1fff000015f3d4e9, 0x1fff000015bfd550, 0x1fff0000158bd5b6, 0x1fff00001557d61c, - 0x1fff00001523d682, 0x1fff000014efd6e8, 0x1fff000014bbd74e, 0x1fff00001487d7b4, 0x1fff00001453d81b, 0x1fff0000141fd881, 0x1fff000013ebd8e7, 0x1fff000013b7d94d, - 0x1fff00001383d9b3, 0x1fff0000134fda19, 0x1fff0000131bda7f, 0x1fff000012e7dae6, 0x1fff000012b3db4c, 0x1fff0000127fdbb2, 0x1fff0000124bdc18, 0x1fff00001217dc7e, - 0x1fff000011e3dce4, 0x1fff000011afdd4a, 0x1fff0000117bddb1, 0x1fff00001147de17, 0x1fff00001113de7d, 0x1fff000010dfdee3, 0x1fff000010abdf49, 0x1fff00001077dfaf, - 0x1fff00001043e015, 0x1fff0000100fe07c, 0x1fff00000fdae0e2, 0x1fff00000fa6e148, 0x1fff00000f72e1ae, 0x1fff00000f3ee214, 0x1fff00000f0ae27a, 0x1fff00000ed6e2e0, - 0x1fff00000ea2e347, 0x1fff00000e6ee3ad, 0x1fff00000e3ae413, 0x1fff00000e06e479, 0x1fff00000dd2e4df, 0x1fff00000d9ee545, 0x1fff00000d6ae5ab, 0x1fff00000d36e612, - 0x1fff00000d02e678, 0x1fff00000ccee6de, 0x1fff00000c9ae744, 0x1fff00000c66e7aa, 0x1fff00000c32e810, 0x1fff00000bfee877, 0x1fff00000bcae8dd, 0x1fff00000b96e943, - 0x1fff00000b62e9a9, 0x1fff00000b2eea0f, 0x1fff00000afaea75, 0x1fff00000ac6eadb, 0x1fff00000a92eb42, 0x1fff00000a5eeba8, 0x1fff00000a2aec0e, 0x1fff000009f6ec74, - 0x1fff000009c2ecda, 0x1fff0000098eed40, 0x1fff00000959eda6, 0x1fff00000925ee0d, 0x1fff000008f1ee73, 0x1fff000008bdeed9, 0x1fff00000889ef3f, 0x1fff00000855efa5, - 0x1fff00000821f00b, 0x1fff000007edf071, 0x1fff000007b9f0d8, 0x1fff00000785f13e, 0x1fff00000751f1a4, 0x1fff0000071df20a, 0x1fff000006e9f270, 0x1fff000006b5f2d6, - 0x1fff00000681f33c, 0x1fff0000064df3a3, 0x1fff00000619f409, 0x1fff000005e5f46f, 0x1fff000005b1f4d5, 0x1fff0000057df53b, 0x1fff00000549f5a1, 0x1fff00000515f607, - 0x1fff000004e1f66e, 0x1fff000004adf6d4, 0x1fff00000479f73a, 0x1fff00000445f7a0, 0x1fff00000411f806, 0x1fff000003ddf86c, 0x1fff000003a9f8d2, 0x1fff00000375f939, - 0x1fff00000341f99f, 0x1fff0000030cfa05, 0x1fff000002d8fa6b, 0x1fff000002a4fad1, 0x1fff00000270fb37, 0x1fff0000023cfb9d, 0x1fff00000208fc04, 0x1fff000001d4fc6a, - 0x1fff000001a0fcd0, 0x1fff0000016cfd36, 0x1fff00000138fd9c, 0x1fff00000104fe02, 0x1fff000000d0fe68, 0x1fff0000009cfecf, 0x1fff00000068ff35, 0x1fff00000034ff9b, - 0x1fff000000000000, 0x1fff0000ffcd0066, 0x1fff0000ff9900cc, 0x1fff0000ff650132, 0x1fff0000ff310199, 0x1fff0000fefd01ff, 0x1fff0000fec90265, 0x1fff0000fe9502cb, - 0x1fff0000fe610331, 0x1fff0000fe2d0397, 0x1fff0000fdf903fd, 0x1fff0000fdc50464, 0x1fff0000fd9104ca, 0x1fff0000fd5d0530, 0x1fff0000fd290596, 0x1fff0000fcf505fc, - 0x1fff0000fcc00662, 0x1fff0000fc8c06c8, 0x1fff0000fc58072f, 0x1fff0000fc240795, 0x1fff0000fbf007fb, 0x1fff0000fbbc0861, 0x1fff0000fb8808c7, 0x1fff0000fb54092d, - 0x1fff0000fb200993, 0x1fff0000faec09fa, 0x1fff0000fab80a60, 0x1fff0000fa840ac6, 0x1fff0000fa500b2c, 0x1fff0000fa1c0b92, 0x1fff0000f9e80bf8, 0x1fff0000f9b40c5e, - 0x1fff0000f9800cc5, 0x1fff0000f94c0d2b, 0x1fff0000f9180d91, 0x1fff0000f8e40df7, 0x1fff0000f8b00e5d, 0x1fff0000f87c0ec3, 0x1fff0000f8480f29, 0x1fff0000f8140f90, - 0x1fff0000f7e00ff6, 0x1fff0000f7ac105c, 0x1fff0000f77810c2, 0x1fff0000f7441128, 0x1fff0000f710118e, 0x1fff0000f6dc11f4, 0x1fff0000f6a8125b, 0x1fff0000f67312c1, - 0x1fff0000f63f1327, 0x1fff0000f60b138d, 0x1fff0000f5d713f3, 0x1fff0000f5a31459, 0x1fff0000f56f14bf, 0x1fff0000f53b1526, 0x1fff0000f507158c, 0x1fff0000f4d315f2, - 0x1fff0000f49f1658, 0x1fff0000f46b16be, 0x1fff0000f4371724, 0x1fff0000f403178a, 0x1fff0000f3cf17f1, 0x1fff0000f39b1857, 0x1fff0000f36718bd, 0x1fff0000f3331923, - 0x1fff0000f2ff1989, 0x1fff0000f2cb19ef, 0x1fff0000f2971a56, 0x1fff0000f2631abc, 0x1fff0000f22f1b22, 0x1fff0000f1fb1b88, 0x1fff0000f1c71bee, 0x1fff0000f1931c54, - 0x1fff0000f15f1cba, 0x1fff0000f12b1d21, 0x1fff0000f0f71d87, 0x1fff0000f0c31ded, 0x1fff0000f08f1e53, 0x1fff0000f05b1eb9, 0x1fff0000f0271f1f, 0x1fff0000eff21f85, - 0x1fff0000efbe1fec, 0x1fff0000ef8a2052, 0x1fff0000ef5620b8, 0x1fff0000ef22211e, 0x1fff0000eeee2184, 0x1fff0000eeba21ea, 0x1fff0000ee862250, 0x1fff0000ee5222b7, - 0x1fff0000ee1e231d, 0x1fff0000edea2383, 0x1fff0000edb623e9, 0x1fff0000ed82244f, 0x1fff0000ed4e24b5, 0x1fff0000ed1a251b, 0x1fff0000ece62582, 0x1fff0000ecb225e8, - 0x1fff0000ec7e264e, 0x1fff0000ec4a26b4, 0x1fff0000ec16271a, 0x1fff0000ebe22780, 0x1fff0000ebae27e6, 0x1fff0000eb7a284d, 0x1fff0000eb4628b3, 0x1fff0000eb122919, - 0x1fff0000eade297f, 0x1fff0000eaaa29e5, 0x1fff0000ea762a4b, 0x1fff0000ea422ab1, 0x1fff0000ea0e2b18, 0x1fff0000e9da2b7e, 0x1fff0000e9a52be4, 0x1fff0000e9712c4a, - 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, - 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, 0x1fff0000e93d2cb0, - }; - - // ----------------------------------------------------------------------------- - - void YUVtoRGBA_MMX(yuv_buffer & YUVBuffer, std::vector & PixelData) - { - // Width and height of all buffers have to be divisible by 4. - BS_ASSERT((YUVBuffer.y_width & 3) == 0); - BS_ASSERT((YUVBuffer.y_height & 3) == 0); - BS_ASSERT((YUVBuffer.uv_width & 3) == 0); - BS_ASSERT((YUVBuffer.uv_height & 3) == 0); - // UV images have to have a quarter of the Y image resolution - BS_ASSERT(YUVBuffer.uv_width == YUVBuffer.y_width >> 1); - BS_ASSERT(YUVBuffer.uv_height == YUVBuffer.y_height >> 1); - - const unsigned char * ySrc = YUVBuffer.y; - const unsigned char * uSrc = YUVBuffer.u; - const unsigned char * vSrc = YUVBuffer.v; - unsigned char * dst = &PixelData[0]; - - const int yPadding = YUVBuffer.y_stride - YUVBuffer.y_width; - int uvStride = YUVBuffer.uv_stride; - - for (int h = 0; h < YUVBuffer.y_height; ++h) - { - uvStride ^= YUVBuffer.uv_stride; - for (int w = 0; w < YUVBuffer.y_width / 4; ++w) - { - __m64 uvCoeff0 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); - __m64 uvCoeff1 = _m_paddw(COEFF_U_MMX[*uSrc++], COEFF_V_MMX[*vSrc++]); - - __m64 px01 = COEFF_Y_MMX[*ySrc++]; - __m64 px23 = COEFF_Y_MMX[*ySrc++]; - __m64 px45 = COEFF_Y_MMX[*ySrc++]; - __m64 px67 = COEFF_Y_MMX[*ySrc++]; - - px01 = _m_paddw(px01, uvCoeff0); - px23 = _m_paddw(px23, uvCoeff0); - px45 = _m_paddw(px45, uvCoeff1); - px67 = _m_paddw(px67, uvCoeff1); - - px01 = _m_psrawi(px01, 6); - px23 = _m_psrawi(px23, 6); - px45 = _m_psrawi(px45, 6); - px67 = _m_psrawi(px67, 6); - - ((__m64*)dst)[0] = _m_packuswb(px01, px23); - ((__m64*)dst)[1] = _m_packuswb(px45, px67); - dst += 16; - } - - ySrc += yPadding; - uSrc += uvStride - YUVBuffer.uv_width; - vSrc += uvStride - YUVBuffer.uv_width; - } - - _m_empty(); - } - -} - -// ----------------------------------------------------------------------------- - -void BS_YUVtoRGBA::YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, vector & Pixels) -{ - BS_ASSERT(TheoraInfo.pixelformat == OC_PF_420); - BS_ASSERT(int(Pixels.size()) >= YUVBuffer.y_width * YUVBuffer.y_height); - - return YUVtoRGBA_c(YUVBuffer, Pixels); - - if (BS_CPUInfo::GetInstance().IsMMXSupported()) - return YUVtoRGBA_MMX(YUVBuffer, Pixels); - else - return YUVtoRGBA_c(YUVBuffer, Pixels); -} diff --git a/engines/sword25/fmv/oggtheora/yuvtorgba.h b/engines/sword25/fmv/oggtheora/yuvtorgba.h deleted file mode 100644 index 6593254ff9..0000000000 --- a/engines/sword25/fmv/oggtheora/yuvtorgba.h +++ /dev/null @@ -1,59 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -/* - * This code is based on Broken Sword 2.5 engine - * - * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer - * - * Licensed under GNU GPL v2 - * - */ - -#ifndef SWORD25_YUVTORGBA_H -#define SWORD25_YUVTORGBA_H - -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - -#include "sword25/kernel/memlog_off.h" -#include -#include "sword25/kernel/memlog_on.h" - -#include "sword25/kernel/common.h" -#include "theora/theora.h" - -// ----------------------------------------------------------------------------- -// Klassendefinition -// ----------------------------------------------------------------------------- - -class BS_YUVtoRGBA -{ -public: - static void YUVtoRGBA(yuv_buffer & YUVBuffer, const theora_info & TheoraInfo, std::vector & Pixels); -}; - -#endif diff --git a/engines/sword25/fmv/theora_decoder.cpp b/engines/sword25/fmv/theora_decoder.cpp index 7aee428fbb..9b1951828e 100644 --- a/engines/sword25/fmv/theora_decoder.cpp +++ b/engines/sword25/fmv/theora_decoder.cpp @@ -37,7 +37,7 @@ */ #include "sword25/fmv/theora_decoder.h" - +#include "sword25/fmv/yuvtorgba.h" #include "common/system.h" #include "sound/decoders/raw.h" @@ -422,7 +422,9 @@ Graphics::Surface *TheoraDecoder::decodeNextFrame() { th_decode_ycbcr_out(_theoraDecode, yuv); - // TODO: YUV->RGB + // Convert YUV data to RGB data + YUVtoBGRA::translate(yuv, _theoraInfo, (byte *)_surface->getBasePtr(0, 0), _surface->pitch * _surface->h); + switch (_theoraInfo.pixel_fmt) { case TH_PF_420: break; diff --git a/engines/sword25/fmv/yuvtorgba.cpp b/engines/sword25/fmv/yuvtorgba.cpp new file mode 100644 index 0000000000..c2b9505f72 --- /dev/null +++ b/engines/sword25/fmv/yuvtorgba.cpp @@ -0,0 +1,248 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "sword25/fmv/yuvtorgba.h" + +namespace Sword25 { +// ----------------------------------------------------------------------------- + +static const int PRECISION = 32768; +static const int COEFFS_Y[256] = { + -593888, -555746, -517604, -479462, -441320, -403178, -365036, -326894, -288752, -250610, -212468, -174326, -136184, -98042, -59900, -21758, + 16384, 54526, 92668, 130810, 168952, 207094, 245236, 283378, 321520, 359662, 397804, 435946, 474088, 512230, 550372, 588514, + 626656, 664798, 702940, 741082, 779224, 817366, 855508, 893650, 931792, 969934, 1008076, 1046218, 1084360, 1122502, 1160644, 1198786, + 1236928, 1275070, 1313212, 1351354, 1389496, 1427638, 1465780, 1503922, 1542064, 1580206, 1618348, 1656490, 1694632, 1732774, 1770916, 1809058, + 1847200, 1885342, 1923484, 1961626, 1999768, 2037910, 2076052, 2114194, 2152336, 2190478, 2228620, 2266762, 2304904, 2343046, 2381188, 2419330, + 2457472, 2495614, 2533756, 2571898, 2610040, 2648182, 2686324, 2724466, 2762608, 2800750, 2838892, 2877034, 2915176, 2953318, 2991460, 3029602, + 3067744, 3105886, 3144028, 3182170, 3220312, 3258454, 3296596, 3334738, 3372880, 3411022, 3449164, 3487306, 3525448, 3563590, 3601732, 3639874, + 3678016, 3716158, 3754300, 3792442, 3830584, 3868726, 3906868, 3945010, 3983152, 4021294, 4059436, 4097578, 4135720, 4173862, 4212004, 4250146, + 4288288, 4326430, 4364572, 4402714, 4440856, 4478998, 4517140, 4555282, 4593424, 4631566, 4669708, 4707850, 4745992, 4784134, 4822276, 4860418, + 4898560, 4936702, 4974844, 5012986, 5051128, 5089270, 5127412, 5165554, 5203696, 5241838, 5279980, 5318122, 5356264, 5394406, 5432548, 5470690, + 5508832, 5546974, 5585116, 5623258, 5661400, 5699542, 5737684, 5775826, 5813968, 5852110, 5890252, 5928394, 5966536, 6004678, 6042820, 6080962, + 6119104, 6157246, 6195388, 6233530, 6271672, 6309814, 6347956, 6386098, 6424240, 6462382, 6500524, 6538666, 6576808, 6614950, 6653092, 6691234, + 6729376, 6767518, 6805660, 6843802, 6881944, 6920086, 6958228, 6996370, 7034512, 7072654, 7110796, 7148938, 7187080, 7225222, 7263364, 7301506, + 7339648, 7377790, 7415932, 7454074, 7492216, 7530358, 7568500, 7606642, 7644784, 7682926, 7721068, 7759210, 7797352, 7835494, 7873636, 7911778, + 7949920, 7988062, 8026204, 8064346, 8102488, 8140630, 8178772, 8216914, 8255056, 8293198, 8331340, 8369482, 8407624, 8445766, 8483908, 8522050, + 8560192, 8598334, 8636476, 8674618, 8712760, 8750902, 8789044, 8827186, 8865328, 8903470, 8941612, 8979754, 9017896, 9056038, 9094180, 9132322, +}; +static const int COEFFS_RV[256] = { + -6694144, -6641846, -6589548, -6537250, -6484952, -6432654, -6380356, -6328058, -6275760, -6223462, -6171164, -6118866, -6066568, -6014270, -5961972, -5909674, + -5857376, -5805078, -5752780, -5700482, -5648184, -5595886, -5543588, -5491290, -5438992, -5386694, -5334396, -5282098, -5229800, -5177502, -5125204, -5072906, + -5020608, -4968310, -4916012, -4863714, -4811416, -4759118, -4706820, -4654522, -4602224, -4549926, -4497628, -4445330, -4393032, -4340734, -4288436, -4236138, + -4183840, -4131542, -4079244, -4026946, -3974648, -3922350, -3870052, -3817754, -3765456, -3713158, -3660860, -3608562, -3556264, -3503966, -3451668, -3399370, + -3347072, -3294774, -3242476, -3190178, -3137880, -3085582, -3033284, -2980986, -2928688, -2876390, -2824092, -2771794, -2719496, -2667198, -2614900, -2562602, + -2510304, -2458006, -2405708, -2353410, -2301112, -2248814, -2196516, -2144218, -2091920, -2039622, -1987324, -1935026, -1882728, -1830430, -1778132, -1725834, + -1673536, -1621238, -1568940, -1516642, -1464344, -1412046, -1359748, -1307450, -1255152, -1202854, -1150556, -1098258, -1045960, -993662, -941364, -889066, + -836768, -784470, -732172, -679874, -627576, -575278, -522980, -470682, -418384, -366086, -313788, -261490, -209192, -156894, -104596, -52298, + 0, 52298, 104596, 156894, 209192, 261490, 313788, 366086, 418384, 470682, 522980, 575278, 627576, 679874, 732172, 784470, + 836768, 889066, 941364, 993662, 1045960, 1098258, 1150556, 1202854, 1255152, 1307450, 1359748, 1412046, 1464344, 1516642, 1568940, 1621238, + 1673536, 1725834, 1778132, 1830430, 1882728, 1935026, 1987324, 2039622, 2091920, 2144218, 2196516, 2248814, 2301112, 2353410, 2405708, 2458006, + 2510304, 2562602, 2614900, 2667198, 2719496, 2771794, 2824092, 2876390, 2928688, 2980986, 3033284, 3085582, 3137880, 3190178, 3242476, 3294774, + 3347072, 3399370, 3451668, 3503966, 3556264, 3608562, 3660860, 3713158, 3765456, 3817754, 3870052, 3922350, 3974648, 4026946, 4079244, 4131542, + 4183840, 4236138, 4288436, 4340734, 4393032, 4445330, 4497628, 4549926, 4602224, 4654522, 4706820, 4759118, 4811416, 4863714, 4916012, 4968310, + 5020608, 5072906, 5125204, 5177502, 5229800, 5282098, 5334396, 5386694, 5438992, 5491290, 5543588, 5595886, 5648184, 5700482, 5752780, 5805078, + 5857376, 5909674, 5961972, 6014270, 6066568, 6118866, 6171164, 6223462, 6275760, 6328058, 6380356, 6432654, 6484952, 6537250, 6589548, 6641846, +}; +static const int COEFFS_GU[256] = { + 1639936, 1627124, 1614312, 1601500, 1588688, 1575876, 1563064, 1550252, 1537440, 1524628, 1511816, 1499004, 1486192, 1473380, 1460568, 1447756, + 1434944, 1422132, 1409320, 1396508, 1383696, 1370884, 1358072, 1345260, 1332448, 1319636, 1306824, 1294012, 1281200, 1268388, 1255576, 1242764, + 1229952, 1217140, 1204328, 1191516, 1178704, 1165892, 1153080, 1140268, 1127456, 1114644, 1101832, 1089020, 1076208, 1063396, 1050584, 1037772, + 1024960, 1012148, 999336, 986524, 973712, 960900, 948088, 935276, 922464, 909652, 896840, 884028, 871216, 858404, 845592, 832780, + 819968, 807156, 794344, 781532, 768720, 755908, 743096, 730284, 717472, 704660, 691848, 679036, 666224, 653412, 640600, 627788, + 614976, 602164, 589352, 576540, 563728, 550916, 538104, 525292, 512480, 499668, 486856, 474044, 461232, 448420, 435608, 422796, + 409984, 397172, 384360, 371548, 358736, 345924, 333112, 320300, 307488, 294676, 281864, 269052, 256240, 243428, 230616, 217804, + 204992, 192180, 179368, 166556, 153744, 140932, 128120, 115308, 102496, 89684, 76872, 64060, 51248, 38436, 25624, 12812, + 0, -12812, -25624, -38436, -51248, -64060, -76872, -89684, -102496, -115308, -128120, -140932, -153744, -166556, -179368, -192180, + -204992, -217804, -230616, -243428, -256240, -269052, -281864, -294676, -307488, -320300, -333112, -345924, -358736, -371548, -384360, -397172, + -409984, -422796, -435608, -448420, -461232, -474044, -486856, -499668, -512480, -525292, -538104, -550916, -563728, -576540, -589352, -602164, + -614976, -627788, -640600, -653412, -666224, -679036, -691848, -704660, -717472, -730284, -743096, -755908, -768720, -781532, -794344, -807156, + -819968, -832780, -845592, -858404, -871216, -884028, -896840, -909652, -922464, -935276, -948088, -960900, -973712, -986524, -999336, -1012148, + -1024960, -1037772, -1050584, -1063396, -1076208, -1089020, -1101832, -1114644, -1127456, -1140268, -1153080, -1165892, -1178704, -1191516, -1204328, -1217140, + -1229952, -1242764, -1255576, -1268388, -1281200, -1294012, -1306824, -1319636, -1332448, -1345260, -1358072, -1370884, -1383696, -1396508, -1409320, -1422132, + -1434944, -1447756, -1460568, -1473380, -1486192, -1499004, -1511816, -1524628, -1537440, -1550252, -1563064, -1575876, -1588688, -1601500, -1614312, -1627124, +}; +static const int COEFFS_GV[256] = { + 3409920, 3383280, 3356640, 3330000, 3303360, 3276720, 3250080, 3223440, 3196800, 3170160, 3143520, 3116880, 3090240, 3063600, 3036960, 3010320, + 2983680, 2957040, 2930400, 2903760, 2877120, 2850480, 2823840, 2797200, 2770560, 2743920, 2717280, 2690640, 2664000, 2637360, 2610720, 2584080, + 2557440, 2530800, 2504160, 2477520, 2450880, 2424240, 2397600, 2370960, 2344320, 2317680, 2291040, 2264400, 2237760, 2211120, 2184480, 2157840, + 2131200, 2104560, 2077920, 2051280, 2024640, 1998000, 1971360, 1944720, 1918080, 1891440, 1864800, 1838160, 1811520, 1784880, 1758240, 1731600, + 1704960, 1678320, 1651680, 1625040, 1598400, 1571760, 1545120, 1518480, 1491840, 1465200, 1438560, 1411920, 1385280, 1358640, 1332000, 1305360, + 1278720, 1252080, 1225440, 1198800, 1172160, 1145520, 1118880, 1092240, 1065600, 1038960, 1012320, 985680, 959040, 932400, 905760, 879120, + 852480, 825840, 799200, 772560, 745920, 719280, 692640, 666000, 639360, 612720, 586080, 559440, 532800, 506160, 479520, 452880, + 426240, 399600, 372960, 346320, 319680, 293040, 266400, 239760, 213120, 186480, 159840, 133200, 106560, 79920, 53280, 26640, + 0, -26640, -53280, -79920, -106560, -133200, -159840, -186480, -213120, -239760, -266400, -293040, -319680, -346320, -372960, -399600, + -426240, -452880, -479520, -506160, -532800, -559440, -586080, -612720, -639360, -666000, -692640, -719280, -745920, -772560, -799200, -825840, + -852480, -879120, -905760, -932400, -959040, -985680, -1012320, -1038960, -1065600, -1092240, -1118880, -1145520, -1172160, -1198800, -1225440, -1252080, + -1278720, -1305360, -1332000, -1358640, -1385280, -1411920, -1438560, -1465200, -1491840, -1518480, -1545120, -1571760, -1598400, -1625040, -1651680, -1678320, + -1704960, -1731600, -1758240, -1784880, -1811520, -1838160, -1864800, -1891440, -1918080, -1944720, -1971360, -1998000, -2024640, -2051280, -2077920, -2104560, + -2131200, -2157840, -2184480, -2211120, -2237760, -2264400, -2291040, -2317680, -2344320, -2370960, -2397600, -2424240, -2450880, -2477520, -2504160, -2530800, + -2557440, -2584080, -2610720, -2637360, -2664000, -2690640, -2717280, -2743920, -2770560, -2797200, -2823840, -2850480, -2877120, -2903760, -2930400, -2957040, + -2983680, -3010320, -3036960, -3063600, -3090240, -3116880, -3143520, -3170160, -3196800, -3223440, -3250080, -3276720, -3303360, -3330000, -3356640, -3383280, +}; +static const int COEFFS_BU[256] = { + -8464128, -8398002, -8331876, -8265750, -8199624, -8133498, -8067372, -8001246, -7935120, -7868994, -7802868, -7736742, -7670616, -7604490, -7538364, -7472238, + -7406112, -7339986, -7273860, -7207734, -7141608, -7075482, -7009356, -6943230, -6877104, -6810978, -6744852, -6678726, -6612600, -6546474, -6480348, -6414222, + -6348096, -6281970, -6215844, -6149718, -6083592, -6017466, -5951340, -5885214, -5819088, -5752962, -5686836, -5620710, -5554584, -5488458, -5422332, -5356206, + -5290080, -5223954, -5157828, -5091702, -5025576, -4959450, -4893324, -4827198, -4761072, -4694946, -4628820, -4562694, -4496568, -4430442, -4364316, -4298190, + -4232064, -4165938, -4099812, -4033686, -3967560, -3901434, -3835308, -3769182, -3703056, -3636930, -3570804, -3504678, -3438552, -3372426, -3306300, -3240174, + -3174048, -3107922, -3041796, -2975670, -2909544, -2843418, -2777292, -2711166, -2645040, -2578914, -2512788, -2446662, -2380536, -2314410, -2248284, -2182158, + -2116032, -2049906, -1983780, -1917654, -1851528, -1785402, -1719276, -1653150, -1587024, -1520898, -1454772, -1388646, -1322520, -1256394, -1190268, -1124142, + -1058016, -991890, -925764, -859638, -793512, -727386, -661260, -595134, -529008, -462882, -396756, -330630, -264504, -198378, -132252, -66126, + 0, 66126, 132252, 198378, 264504, 330630, 396756, 462882, 529008, 595134, 661260, 727386, 793512, 859638, 925764, 991890, + 1058016, 1124142, 1190268, 1256394, 1322520, 1388646, 1454772, 1520898, 1587024, 1653150, 1719276, 1785402, 1851528, 1917654, 1983780, 2049906, + 2116032, 2182158, 2248284, 2314410, 2380536, 2446662, 2512788, 2578914, 2645040, 2711166, 2777292, 2843418, 2909544, 2975670, 3041796, 3107922, + 3174048, 3240174, 3306300, 3372426, 3438552, 3504678, 3570804, 3636930, 3703056, 3769182, 3835308, 3901434, 3967560, 4033686, 4099812, 4165938, + 4232064, 4298190, 4364316, 4430442, 4496568, 4562694, 4628820, 4694946, 4761072, 4827198, 4893324, 4959450, 5025576, 5091702, 5157828, 5223954, + 5290080, 5356206, 5422332, 5488458, 5554584, 5620710, 5686836, 5752962, 5819088, 5885214, 5951340, 6017466, 6083592, 6149718, 6215844, 6281970, + 6348096, 6414222, 6480348, 6546474, 6612600, 6678726, 6744852, 6810978, 6877104, 6943230, 7009356, 7075482, 7141608, 7207734, 7273860, 7339986, + 7406112, 7472238, 7538364, 7604490, 7670616, 7736742, 7802868, 7868994, 7935120, 8001246, 8067372, 8133498, 8199624, 8265750, 8331876, 8398002, +}; +static const int CLAMP_TAB[1024] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, + 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, + 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, + 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, + 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, + 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, + 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, +}; + +void YUVtoBGRA::translate(th_ycbcr_buffer &YUVBuffer, const th_info &TheoraInfo, byte *PixelData, int PixelsSize) { + + // Width and height of all buffers have to be divisible by 2. + BS_ASSERT((YUVBuffer[0].width & 1) == 0); + BS_ASSERT((YUVBuffer[0].height & 1) == 0); + BS_ASSERT((YUVBuffer[1].width & 1) == 0); + BS_ASSERT((YUVBuffer[2].width & 1) == 0); + + // UV images have to have a quarter of the Y image resolution + BS_ASSERT(YUVBuffer[1].width == YUVBuffer[0].width >> 1); + BS_ASSERT(YUVBuffer[2].width == YUVBuffer[0].width >> 1); + BS_ASSERT(YUVBuffer[1].height == YUVBuffer[0].height >> 1); + BS_ASSERT(YUVBuffer[2].height == YUVBuffer[0].height >> 1); + + const int *cl = &CLAMP_TAB[320]; + + const unsigned char *ySrc0 = YUVBuffer[0].data; + const unsigned char *ySrc1 = YUVBuffer[0].data + YUVBuffer[0].stride; + const unsigned char *uSrc = YUVBuffer[1].data; + const unsigned char *vSrc = YUVBuffer[2].data; + unsigned char *dst0 = &PixelData[0]; + unsigned char *dst1 = &PixelData[0] + YUVBuffer[0].width * 4; + + for (int h = 0; h < YUVBuffer[0].height / 2; ++h) { + for (int w = 0; w < YUVBuffer[0].width / 2; ++w) { + int u = *uSrc++; + int v = *vSrc++; + + int rUV = COEFFS_RV[v]; + int gUV = COEFFS_GU[u] + COEFFS_GV[v]; + int bUV = COEFFS_BU[u]; + + int y = *ySrc0++; + int r = COEFFS_Y[y] + rUV; + int g = COEFFS_Y[y] + gUV; + int b = COEFFS_Y[y] + bUV; + *dst0++ = cl[b / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[r / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[b / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[r / PRECISION]; + *dst1++ = 255; + + y = *ySrc0++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst0++ = cl[b / PRECISION]; + *dst0++ = cl[g / PRECISION]; + *dst0++ = cl[r / PRECISION]; + *dst0++ = 255; + + y = *ySrc1++; + r = COEFFS_Y[y] + rUV; + g = COEFFS_Y[y] + gUV; + b = COEFFS_Y[y] + bUV; + *dst1++ = cl[b / PRECISION]; + *dst1++ = cl[g / PRECISION]; + *dst1++ = cl[r / PRECISION]; + *dst1++ = 255; + } + + dst0 += YUVBuffer[0].width * 4; + dst1 += YUVBuffer[0].width * 4; + ySrc0 += YUVBuffer[0].stride * 2 - YUVBuffer[0].width; + ySrc1 += YUVBuffer[0].stride * 2 - YUVBuffer[0].width; + uSrc += YUVBuffer[1].stride - YUVBuffer[1].width; + vSrc += YUVBuffer[2].stride - YUVBuffer[2].width; + } +} + +} // End of namespace Sword25 diff --git a/engines/sword25/fmv/yuvtorgba.h b/engines/sword25/fmv/yuvtorgba.h new file mode 100644 index 0000000000..3df994abc8 --- /dev/null +++ b/engines/sword25/fmv/yuvtorgba.h @@ -0,0 +1,59 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +/* + * This code is based on Broken Sword 2.5 engine + * + * Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer + * + * Licensed under GNU GPL v2 + * + */ + +#ifndef SWORD25_YUVTORGBA_H +#define SWORD25_YUVTORGBA_H + +// ----------------------------------------------------------------------------- +// Includes +// ----------------------------------------------------------------------------- + +#include "sword25/kernel/common.h" +#include +#include + +namespace Sword25 { + +// ----------------------------------------------------------------------------- +// Class definitions +// ----------------------------------------------------------------------------- + +class YUVtoBGRA { +public: + static void translate(th_ycbcr_buffer &YUVBuffer, const th_info &TheoraInfo, byte *PixelData, int PixelsSize); +}; + +} // End of namespace Sword25 + +#endif -- cgit v1.2.3 From 0cdb2ded85d17150cb108a5d63dd8957c29af2a5 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 2 Sep 2010 11:54:44 +0000 Subject: SWORD25: unsigned char -> byte svn-id: r53308 --- engines/sword25/fmv/yuvtorgba.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/yuvtorgba.cpp b/engines/sword25/fmv/yuvtorgba.cpp index c2b9505f72..20ca610f98 100644 --- a/engines/sword25/fmv/yuvtorgba.cpp +++ b/engines/sword25/fmv/yuvtorgba.cpp @@ -183,12 +183,12 @@ void YUVtoBGRA::translate(th_ycbcr_buffer &YUVBuffer, const th_info &TheoraInfo, const int *cl = &CLAMP_TAB[320]; - const unsigned char *ySrc0 = YUVBuffer[0].data; - const unsigned char *ySrc1 = YUVBuffer[0].data + YUVBuffer[0].stride; - const unsigned char *uSrc = YUVBuffer[1].data; - const unsigned char *vSrc = YUVBuffer[2].data; - unsigned char *dst0 = &PixelData[0]; - unsigned char *dst1 = &PixelData[0] + YUVBuffer[0].width * 4; + const byte *ySrc0 = YUVBuffer[0].data; + const byte *ySrc1 = YUVBuffer[0].data + YUVBuffer[0].stride; + const byte *uSrc = YUVBuffer[1].data; + const byte *vSrc = YUVBuffer[2].data; + byte *dst0 = &PixelData[0]; + byte *dst1 = &PixelData[0] + YUVBuffer[0].width * 4; for (int h = 0; h < YUVBuffer[0].height / 2; ++h) { for (int w = 0; w < YUVBuffer[0].width / 2; ++w) { -- cgit v1.2.3 From 086f5961b6575c50bb386750b6e9a3ed1efdd8cd Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 2 Sep 2010 12:14:04 +0000 Subject: SWORD25: unsigned int -> uint svn-id: r53309 --- engines/sword25/fmv/movieplayer.cpp | 2 +- engines/sword25/fmv/movieplayer.h | 2 +- engines/sword25/fmv/movieplayer_script.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index a54be8a757..4aad57d435 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -60,7 +60,7 @@ MoviePlayer::~MoviePlayer() { _decoder.close(); } -bool MoviePlayer::LoadMovie(const Common::String &filename, unsigned int z) { +bool MoviePlayer::LoadMovie(const Common::String &filename, uint z) { // Get the file and load it into the decoder Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); _decoder.load(in); diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index cdbcf13f53..f72178a707 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -73,7 +73,7 @@ public: * @param Z Z indicates the position of the film on the main graphics layer * @return Returns false if an error occured while loading, otherwise true. */ - bool LoadMovie(const Common::String &Filename, unsigned int Z); + bool LoadMovie(const Common::String &Filename, uint Z); /** * Unloads the currently loaded movie file. diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index 0b96d4dc34..60d42ac2b5 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -49,7 +49,7 @@ int LoadMovie(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); + lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); return 1; } -- cgit v1.2.3 From 06bce68860696f67f0a0ac1e9682635081918801 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Thu, 2 Sep 2010 17:11:45 +0000 Subject: SWORD25: Comply to the code conventions for several classes svn-id: r53310 --- engines/sword25/fmv/movieplayer.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 4aad57d435..355a1a14cc 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -67,35 +67,35 @@ bool MoviePlayer::LoadMovie(const Common::String &filename, uint z) { // Ausgabebitmap erstellen GraphicEngine *pGfx = Kernel::GetInstance()->GetGfx(); - _outputBitmap = pGfx->GetMainPanel()->AddDynamicBitmap(_decoder.getWidth(), _decoder.getHeight()); - if (!_outputBitmap.IsValid()) { + _outputBitmap = pGfx->GetMainPanel()->addDynamicBitmap(_decoder.getWidth(), _decoder.getHeight()); + if (!_outputBitmap.isValid()) { BS_LOG_ERRORLN("Output bitmap for movie playback could not be created."); return false; } // Skalierung des Ausgabebitmaps berechnen, so dass es möglichst viel Bildschirmfläche einnimmt. - float ScreenToVideoWidth = (float) pGfx->GetDisplayWidth() / (float) _outputBitmap->GetWidth(); - float ScreenToVideoHeight = (float) pGfx->GetDisplayHeight() / (float) _outputBitmap->GetHeight(); - float ScaleFactor = MIN(ScreenToVideoWidth, ScreenToVideoHeight); + float screenToVideoWidth = (float)pGfx->GetDisplayWidth() / (float)_outputBitmap->getWidth(); + float screenToVideoHeight = (float)pGfx->GetDisplayHeight() / (float)_outputBitmap->getHeight(); + float scaleFactor = MIN(screenToVideoWidth, screenToVideoHeight); - if (abs(ScaleFactor - 1.0f) < FLT_EPSILON) - ScaleFactor = 1.0f; + if (abs(scaleFactor - 1.0f) < FLT_EPSILON) + scaleFactor = 1.0f; - _outputBitmap->SetScaleFactor(ScaleFactor); + _outputBitmap->setScaleFactor(scaleFactor); // Z-Wert setzen - _outputBitmap->SetZ(z); + _outputBitmap->setZ(z); // Ausgabebitmap auf dem Bildschirm zentrieren - _outputBitmap->SetX((pGfx->GetDisplayWidth() - _outputBitmap->GetWidth()) / 2); - _outputBitmap->SetY((pGfx->GetDisplayHeight() - _outputBitmap->GetHeight()) / 2); + _outputBitmap->setX((pGfx->GetDisplayWidth() - _outputBitmap->getWidth()) / 2); + _outputBitmap->setY((pGfx->GetDisplayHeight() - _outputBitmap->getHeight()) / 2); return true; } bool MoviePlayer::UnloadMovie() { _decoder.close(); - _outputBitmap.Erase(); + _outputBitmap.erase(); return true; } @@ -117,7 +117,7 @@ void MoviePlayer::Update() { // Transfer the next frame assert(s->bytesPerPixel == 4); byte *frameData = (byte *)s->getBasePtr(0, 0); - _outputBitmap->SetContent(frameData, s->pitch * s->h, 0, s->pitch); + _outputBitmap->setContent(frameData, s->pitch * s->h, 0, s->pitch); } } @@ -131,19 +131,19 @@ bool MoviePlayer::IsPaused() { float MoviePlayer::GetScaleFactor() { if (_decoder.isVideoLoaded()) - return _outputBitmap->GetScaleFactorX(); + return _outputBitmap->getScaleFactorX(); else return 0; } void MoviePlayer::SetScaleFactor(float scaleFactor) { if (_decoder.isVideoLoaded()) { - _outputBitmap->SetScaleFactor(scaleFactor); + _outputBitmap->setScaleFactor(scaleFactor); // Ausgabebitmap auf dem Bildschirm zentrieren GraphicEngine *gfxPtr = Kernel::GetInstance()->GetGfx(); - _outputBitmap->SetX((gfxPtr->GetDisplayWidth() - _outputBitmap->GetWidth()) / 2); - _outputBitmap->SetY((gfxPtr->GetDisplayHeight() - _outputBitmap->GetHeight()) / 2); + _outputBitmap->setX((gfxPtr->GetDisplayWidth() - _outputBitmap->getWidth()) / 2); + _outputBitmap->setY((gfxPtr->GetDisplayHeight() - _outputBitmap->getHeight()) / 2); } } -- cgit v1.2.3 From e5ac21dcac9a4c18dd5934b4db19b02db06163ca Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 8 Sep 2010 14:34:36 +0000 Subject: SWORD25: Fix some warnings svn-id: r53338 --- engines/sword25/fmv/movieplayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 355a1a14cc..d0901ec4b4 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -78,7 +78,7 @@ bool MoviePlayer::LoadMovie(const Common::String &filename, uint z) { float screenToVideoHeight = (float)pGfx->GetDisplayHeight() / (float)_outputBitmap->getHeight(); float scaleFactor = MIN(screenToVideoWidth, screenToVideoHeight); - if (abs(scaleFactor - 1.0f) < FLT_EPSILON) + if (abs((int)(scaleFactor - 1.0f)) < FLT_EPSILON) scaleFactor = 1.0f; _outputBitmap->setScaleFactor(scaleFactor); -- cgit v1.2.3 From 8582c1ad5770b6385381f524a4610934d115cd88 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sat, 25 Sep 2010 19:48:26 +0000 Subject: SWORD25: Enforse code naming conventions in PackageManager and Sword25Engine svn-id: r53380 --- engines/sword25/fmv/movieplayer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index d0901ec4b4..8b1d6d2e08 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -62,7 +62,7 @@ MoviePlayer::~MoviePlayer() { bool MoviePlayer::LoadMovie(const Common::String &filename, uint z) { // Get the file and load it into the decoder - Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->GetStream(filename); + Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->getStream(filename); _decoder.load(in); // Ausgabebitmap erstellen -- cgit v1.2.3 From bf22def884986e4bd5bec2b42dea7f91b5417ccc Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Wed, 29 Sep 2010 10:40:06 +0000 Subject: SWORD25: Enforce code naming conventions in fmv/* svn-id: r53388 --- engines/sword25/fmv/movieplayer.cpp | 22 ++++---- engines/sword25/fmv/movieplayer.h | 31 +++++------ engines/sword25/fmv/movieplayer_script.cpp | 86 +++++++++++------------------- engines/sword25/fmv/yuvtorgba.cpp | 11 ++-- engines/sword25/fmv/yuvtorgba.h | 10 +--- 5 files changed, 58 insertions(+), 102 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer.cpp b/engines/sword25/fmv/movieplayer.cpp index 8b1d6d2e08..f6757b9a8e 100644 --- a/engines/sword25/fmv/movieplayer.cpp +++ b/engines/sword25/fmv/movieplayer.cpp @@ -50,7 +50,7 @@ Service *OggTheora_CreateObject(Kernel *pKernel) { } MoviePlayer::MoviePlayer(Kernel *pKernel) : Service(pKernel), _decoder(g_system->getMixer()) { - if (!_RegisterScriptBindings()) + if (!registerScriptBindings()) BS_LOG_ERRORLN("Script bindings could not be registered."); else BS_LOGLN("Script bindings registered."); @@ -60,7 +60,7 @@ MoviePlayer::~MoviePlayer() { _decoder.close(); } -bool MoviePlayer::LoadMovie(const Common::String &filename, uint z) { +bool MoviePlayer::loadMovie(const Common::String &filename, uint z) { // Get the file and load it into the decoder Common::SeekableReadStream *in = Kernel::GetInstance()->GetPackage()->getStream(filename); _decoder.load(in); @@ -93,24 +93,24 @@ bool MoviePlayer::LoadMovie(const Common::String &filename, uint z) { return true; } -bool MoviePlayer::UnloadMovie() { +bool MoviePlayer::unloadMovie() { _decoder.close(); _outputBitmap.erase(); return true; } -bool MoviePlayer::Play() { +bool MoviePlayer::play() { _decoder.pauseVideo(false); return true; } -bool MoviePlayer::Pause() { +bool MoviePlayer::pause() { _decoder.pauseVideo(true); return true; } -void MoviePlayer::Update() { +void MoviePlayer::update() { if (_decoder.isVideoLoaded()) { Graphics::Surface *s = _decoder.decodeNextFrame(); @@ -121,22 +121,22 @@ void MoviePlayer::Update() { } } -bool MoviePlayer::IsMovieLoaded() { +bool MoviePlayer::isMovieLoaded() { return _decoder.isVideoLoaded(); } -bool MoviePlayer::IsPaused() { +bool MoviePlayer::isPaused() { return _decoder.isPaused(); } -float MoviePlayer::GetScaleFactor() { +float MoviePlayer::getScaleFactor() { if (_decoder.isVideoLoaded()) return _outputBitmap->getScaleFactorX(); else return 0; } -void MoviePlayer::SetScaleFactor(float scaleFactor) { +void MoviePlayer::setScaleFactor(float scaleFactor) { if (_decoder.isVideoLoaded()) { _outputBitmap->setScaleFactor(scaleFactor); @@ -147,7 +147,7 @@ void MoviePlayer::SetScaleFactor(float scaleFactor) { } } -double MoviePlayer::GetTime() { +double MoviePlayer::getTime() { return _decoder.getElapsedTime() / 1000.0; } diff --git a/engines/sword25/fmv/movieplayer.h b/engines/sword25/fmv/movieplayer.h index f72178a707..96beb648c0 100644 --- a/engines/sword25/fmv/movieplayer.h +++ b/engines/sword25/fmv/movieplayer.h @@ -35,10 +35,6 @@ #ifndef SWORD25_MOVIEPLAYER_H #define SWORD25_MOVIEPLAYER_H -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "sword25/kernel/common.h" #include "sword25/kernel/service.h" #include "sword25/fmv/theora_decoder.h" @@ -46,10 +42,6 @@ namespace Sword25 { -// ----------------------------------------------------------------------------- -// Class definitions -// ----------------------------------------------------------------------------- - class MoviePlayer : public Service { public: // ----------------------------------------------------------------------------- @@ -73,14 +65,14 @@ public: * @param Z Z indicates the position of the film on the main graphics layer * @return Returns false if an error occured while loading, otherwise true. */ - bool LoadMovie(const Common::String &Filename, uint Z); + bool loadMovie(const Common::String &filename, uint z); /** * Unloads the currently loaded movie file. * @return Returns false if an error occurred while unloading, otherwise true. * @remark This method can only be called when IsMovieLoaded() returns true. */ - bool UnloadMovie(); + bool unloadMovie(); /** * Plays the loaded movie. @@ -90,7 +82,7 @@ public: * @return Returns false if an error occurred while starting, otherwise true. * @remark This method can only be called when IsMovieLoaded() returns true. */ - bool Play(); + bool play(); /** * Pauses movie playback. @@ -99,23 +91,23 @@ public: * @return Returns false if an error occurred while pausing, otherwise true. * @remark This method can only be called when IsMovieLoaded() returns true. */ - bool Pause(); + bool pause(); /** * This function must be called once per frame. */ - void Update(); + void update(); /** * Returns whether a film is loaded for playback. */ - bool IsMovieLoaded(); + bool isMovieLoaded(); /** * Returns whether the movie playback is paused. * @remark This method can only be called when IsMovieLoaded() returns true. */ - bool IsPaused(); + bool isPaused(); /** * Returns the scaling factor for the loaded film. @@ -125,22 +117,23 @@ public: * @return Returns the scaling factor of the film. * @remark This method can only be called when IsMovieLoaded() returns true. */ - float GetScaleFactor(); + float getScaleFactor(); /** * Sets the factor by which the loaded film is to be scaled. * @param ScaleFactor The desired scale factor. * @remark This method can only be called when IsMovieLoaded() returns true. */ - void SetScaleFactor(float ScaleFactor); + void setScaleFactor(float scaleFactor); /** * Returns the current playing position in seconds. * @remark This method can only be called when IsMovieLoaded() returns true. */ - double GetTime(); + double getTime(); + private: - bool _RegisterScriptBindings(); + bool registerScriptBindings(); TheoraDecoder _decoder; diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index 60d42ac2b5..8a47721c95 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -32,10 +32,6 @@ * */ -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "sword25/kernel/common.h" #include "sword25/kernel/kernel.h" #include "sword25/script/script.h" @@ -45,133 +41,113 @@ namespace Sword25 { -int LoadMovie(lua_State *L) { +int loadMovie(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->LoadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); + lua_pushbooleancpp(L, FMVPtr->loadMovie(luaL_checkstring(L, 1), lua_gettop(L) == 2 ? static_cast(luaL_checknumber(L, 2)) : 10)); return 1; } -// ------------------------------------------------------------------------- - -int UnloadMovie(lua_State *L) { +int unloadMovie(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->UnloadMovie()); + lua_pushbooleancpp(L, FMVPtr->unloadMovie()); return 1; } -// ------------------------------------------------------------------------- - -int Play(lua_State *L) { +int play(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->Play()); + lua_pushbooleancpp(L, FMVPtr->play()); return 1; } -// ------------------------------------------------------------------------- - -int Pause(lua_State *L) { +int pause(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->Pause()); + lua_pushbooleancpp(L, FMVPtr->pause()); return 1; } -// ------------------------------------------------------------------------- - -int Update(lua_State *L) { +int update(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - FMVPtr->Update(); + FMVPtr->update(); return 0; } -// ------------------------------------------------------------------------- - -int IsMovieLoaded(lua_State *L) { +int isMovieLoaded(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->IsMovieLoaded()); + lua_pushbooleancpp(L, FMVPtr->isMovieLoaded()); return 1; } -// ------------------------------------------------------------------------- - -int IsPaused(lua_State *L) { +int isPaused(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushbooleancpp(L, FMVPtr->IsPaused()); + lua_pushbooleancpp(L, FMVPtr->isPaused()); return 1; } -// ------------------------------------------------------------------------- - -int GetScaleFactor(lua_State *L) { +int getScaleFactor(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushnumber(L, FMVPtr->GetScaleFactor()); + lua_pushnumber(L, FMVPtr->getScaleFactor()); return 1; } -// ------------------------------------------------------------------------- - -int SetScaleFactor(lua_State *L) { +int setScaleFactor(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - FMVPtr->SetScaleFactor(static_cast(luaL_checknumber(L, 1))); + FMVPtr->setScaleFactor(static_cast(luaL_checknumber(L, 1))); return 0; } -// ------------------------------------------------------------------------- - -int GetTime(lua_State *L) { +int getTime(lua_State *L) { MoviePlayer *FMVPtr = Kernel::GetInstance()->GetFMV(); BS_ASSERT(FMVPtr); - lua_pushnumber(L, FMVPtr->GetTime()); + lua_pushnumber(L, FMVPtr->getTime()); return 1; } -// ------------------------------------------------------------------------- - const char *LIBRARY_NAME = "Movieplayer"; const luaL_reg LIBRARY_FUNCTIONS[] = { - { "LoadMovie", LoadMovie }, - { "UnloadMovie", UnloadMovie }, - { "Play", Play }, - { "Pause", Pause }, - { "Update", Update }, - { "IsMovieLoaded", IsMovieLoaded }, - { "IsPaused", IsPaused }, - { "GetScaleFactor", GetScaleFactor }, - { "SetScaleFactor", SetScaleFactor }, - { "GetTime", GetTime }, + { "LoadMovie", loadMovie }, + { "UnloadMovie", unloadMovie }, + { "Play", play }, + { "Pause", pause }, + { "Update", update }, + { "IsMovieLoaded", isMovieLoaded }, + { "IsPaused", isPaused }, + { "GetScaleFactor", getScaleFactor }, + { "SetScaleFactor", setScaleFactor }, + { "GetTime", getTime }, { 0, 0 } }; -bool MoviePlayer::_RegisterScriptBindings() { +bool MoviePlayer::registerScriptBindings() { Kernel *pKernel = Kernel::GetInstance(); BS_ASSERT(pKernel); ScriptEngine *pScript = static_cast(pKernel->GetService("script")); diff --git a/engines/sword25/fmv/yuvtorgba.cpp b/engines/sword25/fmv/yuvtorgba.cpp index 20ca610f98..12d11b6784 100644 --- a/engines/sword25/fmv/yuvtorgba.cpp +++ b/engines/sword25/fmv/yuvtorgba.cpp @@ -32,14 +32,9 @@ * */ -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "sword25/fmv/yuvtorgba.h" namespace Sword25 { -// ----------------------------------------------------------------------------- static const int PRECISION = 32768; static const int COEFFS_Y[256] = { @@ -167,7 +162,7 @@ static const int CLAMP_TAB[1024] = { 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, }; -void YUVtoBGRA::translate(th_ycbcr_buffer &YUVBuffer, const th_info &TheoraInfo, byte *PixelData, int PixelsSize) { +void YUVtoBGRA::translate(th_ycbcr_buffer &YUVBuffer, const th_info &theoraInfo, byte *pixelData, int pixelsSize) { // Width and height of all buffers have to be divisible by 2. BS_ASSERT((YUVBuffer[0].width & 1) == 0); @@ -187,8 +182,8 @@ void YUVtoBGRA::translate(th_ycbcr_buffer &YUVBuffer, const th_info &TheoraInfo, const byte *ySrc1 = YUVBuffer[0].data + YUVBuffer[0].stride; const byte *uSrc = YUVBuffer[1].data; const byte *vSrc = YUVBuffer[2].data; - byte *dst0 = &PixelData[0]; - byte *dst1 = &PixelData[0] + YUVBuffer[0].width * 4; + byte *dst0 = &pixelData[0]; + byte *dst1 = &pixelData[0] + YUVBuffer[0].width * 4; for (int h = 0; h < YUVBuffer[0].height / 2; ++h) { for (int w = 0; w < YUVBuffer[0].width / 2; ++w) { diff --git a/engines/sword25/fmv/yuvtorgba.h b/engines/sword25/fmv/yuvtorgba.h index 3df994abc8..15fa85b7e4 100644 --- a/engines/sword25/fmv/yuvtorgba.h +++ b/engines/sword25/fmv/yuvtorgba.h @@ -35,23 +35,15 @@ #ifndef SWORD25_YUVTORGBA_H #define SWORD25_YUVTORGBA_H -// ----------------------------------------------------------------------------- -// Includes -// ----------------------------------------------------------------------------- - #include "sword25/kernel/common.h" #include #include namespace Sword25 { -// ----------------------------------------------------------------------------- -// Class definitions -// ----------------------------------------------------------------------------- - class YUVtoBGRA { public: - static void translate(th_ycbcr_buffer &YUVBuffer, const th_info &TheoraInfo, byte *PixelData, int PixelsSize); + static void translate(th_ycbcr_buffer &YUVBuffer, const th_info &theoraInfo, byte *pixelData, int pixelsSize); }; } // End of namespace Sword25 -- cgit v1.2.3 From 54ccc8f4c906cd4f84c955581c0368886a7a9c78 Mon Sep 17 00:00:00 2001 From: Eugene Sandulenko Date: Sun, 3 Oct 2010 13:25:22 +0000 Subject: SWORD25: Enforced code naming conventions in script/* svn-id: r53391 --- engines/sword25/fmv/movieplayer_script.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'engines/sword25/fmv') diff --git a/engines/sword25/fmv/movieplayer_script.cpp b/engines/sword25/fmv/movieplayer_script.cpp index 8a47721c95..13bb149672 100644 --- a/engines/sword25/fmv/movieplayer_script.cpp +++ b/engines/sword25/fmv/movieplayer_script.cpp @@ -152,10 +152,10 @@ bool MoviePlayer::registerScriptBindings() { BS_ASSERT(pKernel); ScriptEngine *pScript = static_cast(pKernel->GetService("script")); BS_ASSERT(pScript); - lua_State *L = static_cast(pScript->GetScriptObject()); + lua_State *L = static_cast(pScript->getScriptObject()); BS_ASSERT(L); - if (!LuaBindhelper::AddFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false; + if (!LuaBindhelper::addFunctionsToLib(L, LIBRARY_NAME, LIBRARY_FUNCTIONS)) return false; return true; } -- cgit v1.2.3