2010-07-31 09:53:02 +00:00
|
|
|
|
/* 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$
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2010-08-06 13:13:25 +00:00
|
|
|
|
/*
|
2010-07-31 09:53:02 +00:00
|
|
|
|
* This code is based on Broken Sword 2.5 engine
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) Malte Thiesen, Daniel Queteschiner and Michael Elsdoerfer
|
|
|
|
|
*
|
|
|
|
|
* Licensed under GNU GPL v2
|
|
|
|
|
*
|
|
|
|
|
*/
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Includes
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-07-30 09:02:39 +00:00
|
|
|
|
#include "sword25/gfx/dynamicbitmap.h"
|
|
|
|
|
#include "sword25/gfx/bitmapresource.h"
|
|
|
|
|
#include "sword25/package/packagemanager.h"
|
|
|
|
|
#include "sword25/kernel/inputpersistenceblock.h"
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-08-05 12:48:19 +00:00
|
|
|
|
namespace Sword25 {
|
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Logging
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
#define BS_LOG_PREFIX "DYNAMICBITMAP"
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Konstruktion / Destruktion
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
DynamicBitmap::DynamicBitmap(RenderObjectPtr<RenderObject> ParentPtr, unsigned int Width, unsigned int Height) :
|
|
|
|
|
Bitmap(ParentPtr, TYPE_DYNAMICBITMAP) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Das BS_Bitmap konnte nicht erzeugt werden, daher muss an dieser Stelle abgebrochen werden.
|
|
|
|
|
if (!m_InitSuccess) return;
|
|
|
|
|
|
|
|
|
|
m_InitSuccess = CreateGLImage(Width, Height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
DynamicBitmap::DynamicBitmap(InputPersistenceBlock &Reader, RenderObjectPtr<RenderObject> ParentPtr, unsigned int Handle) :
|
2010-08-18 10:52:24 +00:00
|
|
|
|
Bitmap(ParentPtr, TYPE_DYNAMICBITMAP, Handle) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
m_InitSuccess = Unpersist(Reader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::CreateGLImage(unsigned int Width, unsigned int Height) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// GLImage mit den gew<65>nschten Ma<4D>en erstellen
|
|
|
|
|
bool Result;
|
2010-08-18 10:52:24 +00:00
|
|
|
|
m_Image.reset(new GLImage(Width, Height, Result));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
m_OriginalWidth = m_Width = Width;
|
|
|
|
|
m_OriginalHeight = m_Height = Height;
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
DynamicBitmap::~DynamicBitmap() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
unsigned int DynamicBitmap::GetPixel(int X, int Y) const {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_ASSERT(X >= 0 && X < m_Width);
|
|
|
|
|
BS_ASSERT(Y >= 0 && Y < m_Height);
|
|
|
|
|
|
|
|
|
|
return m_Image->GetPixel(X, Y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::DoRender() {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Framebufferobjekt holen
|
2010-08-18 12:58:22 +00:00
|
|
|
|
GraphicEngine *pGfx = static_cast<GraphicEngine *>(Kernel::GetInstance()->GetService("gfx"));
|
2010-07-29 19:53:02 +00:00
|
|
|
|
BS_ASSERT(pGfx);
|
|
|
|
|
|
|
|
|
|
// Bitmap zeichnen
|
|
|
|
|
bool Result;
|
2010-08-06 13:13:25 +00:00
|
|
|
|
if (m_ScaleFactorX == 1.0f && m_ScaleFactorY == 1.0f) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
2010-08-18 10:52:24 +00:00
|
|
|
|
(m_FlipV ? BitmapResource::FLIP_V : 0) |
|
|
|
|
|
(m_FlipH ? BitmapResource::FLIP_H : 0),
|
2010-08-06 13:13:25 +00:00
|
|
|
|
0, m_ModulationColor, -1, -1);
|
|
|
|
|
} else {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
Result = m_Image->Blit(m_AbsoluteX, m_AbsoluteY,
|
2010-08-18 10:52:24 +00:00
|
|
|
|
(m_FlipV ? BitmapResource::FLIP_V : 0) |
|
|
|
|
|
(m_FlipH ? BitmapResource::FLIP_H : 0),
|
2010-08-06 13:13:25 +00:00
|
|
|
|
0, m_ModulationColor, m_Width, m_Height);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::SetContent(const byte *Pixeldata, uint size, unsigned int Offset, unsigned int Stride) {
|
2010-08-10 12:16:31 +00:00
|
|
|
|
return m_Image->SetContent(Pixeldata, size, Offset, Stride);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Auskunftsmethoden
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::IsScalingAllowed() const {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return m_Image->IsScalingAllowed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::IsAlphaAllowed() const {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return m_Image->IsAlphaAllowed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::IsColorModulationAllowed() const {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return m_Image->IsColorModulationAllowed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
bool DynamicBitmap::IsSetContentAllowed() const {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
// Persistenz
|
|
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
bool DynamicBitmap::Persist(OutputPersistenceBlock &Writer) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
bool Result = true;
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
Result &= Bitmap::Persist(Writer);
|
2010-08-06 13:13:25 +00:00
|
|
|
|
|
2010-07-29 19:53:02 +00:00
|
|
|
|
// Bilddaten werden nicht gespeichert. Dies ist auch nicht weiter von bedeutung, da BS_DynamicBitmap nur vom Videoplayer benutzt wird.
|
|
|
|
|
// W<>hrend ein Video abl<62>uft kann niemals gespeichert werden. BS_DynamicBitmap kann nur der Vollst<73>ndigkeit halber persistiert werden.
|
|
|
|
|
BS_LOG_WARNINGLN("Persisting a BS_DynamicBitmap. Bitmap content is not persisted.");
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
Result &= RenderObject::PersistChildren(Writer);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
return Result;
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-18 12:58:22 +00:00
|
|
|
|
bool DynamicBitmap::Unpersist(InputPersistenceBlock &Reader) {
|
2010-07-29 19:53:02 +00:00
|
|
|
|
bool Result = true;
|
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
Result &= Bitmap::Unpersist(Reader);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
// Ein BS_GLImage mit den gespeicherten Ma<4D>en erstellen.
|
|
|
|
|
Result &= CreateGLImage(m_Width, m_Height);
|
|
|
|
|
|
|
|
|
|
// Bilddaten werden nicht gespeichert (s.o.).
|
|
|
|
|
BS_LOG_WARNINGLN("Unpersisting a BS_DynamicBitmap. Bitmap contents are missing.");
|
|
|
|
|
|
|
|
|
|
// Bild mit durchsichtigen Bilddaten initialisieren.
|
2010-08-06 10:59:50 +00:00
|
|
|
|
byte *TransparentImageData = (byte *)calloc(m_Width * m_Height * 4, 1);
|
2010-08-10 12:16:31 +00:00
|
|
|
|
m_Image->SetContent(TransparentImageData, m_Width * m_Height);
|
2010-08-06 10:59:50 +00:00
|
|
|
|
free(TransparentImageData);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
2010-08-18 10:52:24 +00:00
|
|
|
|
Result &= RenderObject::UnpersistChildren(Reader);
|
2010-07-29 19:53:02 +00:00
|
|
|
|
|
|
|
|
|
return Reader.IsGood() && Result;
|
|
|
|
|
}
|
2010-08-05 12:48:19 +00:00
|
|
|
|
|
|
|
|
|
} // End of namespace Sword25
|