diff options
Diffstat (limited to 'engines/sci/graphics')
-rw-r--r-- | engines/sci/graphics/celobj32.cpp | 45 | ||||
-rw-r--r-- | engines/sci/graphics/celobj32.h | 28 | ||||
-rw-r--r-- | engines/sci/graphics/text32.cpp | 40 | ||||
-rw-r--r-- | engines/sci/graphics/text32.h | 5 |
4 files changed, 73 insertions, 45 deletions
diff --git a/engines/sci/graphics/celobj32.cpp b/engines/sci/graphics/celobj32.cpp index 62db02b554..787d295d5e 100644 --- a/engines/sci/graphics/celobj32.cpp +++ b/engines/sci/graphics/celobj32.cpp @@ -968,6 +968,40 @@ byte *CelObjPic::getResPointer() const { #pragma mark - #pragma mark CelObjMem +void CelObjMem::buildBitmapHeader(byte *bitmap, const int16 width, const int16 height, const uint8 skipColor, const int16 displaceX, const int16 displaceY, const int16 scaledWidth, const int16 scaledHeight, const uint32 hunkPaletteOffset, const bool useRemap) { + const uint16 bitmapHeaderSize = getBitmapHeaderSize(); + + WRITE_SCI11ENDIAN_UINT16(bitmap + 0, width); + WRITE_SCI11ENDIAN_UINT16(bitmap + 2, height); + WRITE_SCI11ENDIAN_UINT16(bitmap + 4, (uint16)displaceX); + WRITE_SCI11ENDIAN_UINT16(bitmap + 6, (uint16)displaceY); + bitmap[8] = skipColor; + bitmap[9] = 0; + WRITE_SCI11ENDIAN_UINT16(bitmap + 10, 0); + + if (useRemap) { + bitmap[10] |= 2; + } + + WRITE_SCI11ENDIAN_UINT32(bitmap + 12, width * height); + WRITE_SCI11ENDIAN_UINT32(bitmap + 16, 0); + + if (hunkPaletteOffset) { + WRITE_SCI11ENDIAN_UINT32(bitmap + 20, hunkPaletteOffset + bitmapHeaderSize); + } else { + WRITE_SCI11ENDIAN_UINT32(bitmap + 20, 0); + } + + WRITE_SCI11ENDIAN_UINT32(bitmap + 24, bitmapHeaderSize); + WRITE_SCI11ENDIAN_UINT32(bitmap + 28, bitmapHeaderSize); + WRITE_SCI11ENDIAN_UINT32(bitmap + 32, 0); + + if (bitmapHeaderSize >= 40) { + WRITE_SCI11ENDIAN_UINT16(bitmap + 36, scaledWidth); + WRITE_SCI11ENDIAN_UINT16(bitmap + 38, scaledHeight); + } +} + CelObjMem::CelObjMem(const reg_t bitmap) { _info.type = kCelTypeMem; _info.bitmap = bitmap; @@ -976,8 +1010,9 @@ CelObjMem::CelObjMem(const reg_t bitmap) { _celHeaderOffset = 0; _transparent = true; + const uint32 bitmapHeaderSize = getBitmapHeaderSize(); byte *bitmapData = g_sci->getEngineState()->_segMan->getHunkPointer(bitmap); - if (bitmapData == nullptr || READ_SCI11ENDIAN_UINT32(bitmapData + 28) != 46) { + if (bitmapData == nullptr || READ_SCI11ENDIAN_UINT32(bitmapData + 28) != bitmapHeaderSize) { error("Invalid Text bitmap %04x:%04x", PRINT_REG(bitmap)); } @@ -986,8 +1021,12 @@ CelObjMem::CelObjMem(const reg_t bitmap) { _displace.x = READ_SCI11ENDIAN_UINT16(bitmapData + 4); _displace.y = READ_SCI11ENDIAN_UINT16(bitmapData + 6); _transparentColor = bitmapData[8]; - _scaledWidth = READ_SCI11ENDIAN_UINT16(bitmapData + 36); - _scaledHeight = READ_SCI11ENDIAN_UINT16(bitmapData + 38); + if (bitmapHeaderSize >= 40) { + _scaledWidth = READ_SCI11ENDIAN_UINT16(bitmapData + 36); + _scaledHeight = READ_SCI11ENDIAN_UINT16(bitmapData + 38); + } else { + error("TODO: SCI2 bitmaps not implemented yet!"); + } _hunkPaletteOffset = READ_SCI11ENDIAN_UINT16(bitmapData + 20); _remap = (READ_SCI11ENDIAN_UINT16(bitmapData + 10) & 2) ? true : false; } diff --git a/engines/sci/graphics/celobj32.h b/engines/sci/graphics/celobj32.h index 1422b76a57..5707333818 100644 --- a/engines/sci/graphics/celobj32.h +++ b/engines/sci/graphics/celobj32.h @@ -547,6 +547,34 @@ public: */ class CelObjMem : public CelObj { public: + /** + * Writes a bitmap header to the given data buffer. + */ + static void buildBitmapHeader(byte *bitmap, const int16 width, const int16 height, const uint8 skipColor, const int16 displaceX, const int16 displaceY, const int16 scaledWidth, const int16 scaledHeight, const uint32 hunkPaletteOffset, const bool useRemap); + + /** + * Gets the size of the bitmap header for the current + * engine version. + */ + inline static uint32 getBitmapHeaderSize() { + // TODO: These values are accurate for each engine, but there may be no reason + // to not simply just always use size 40, since SCI2.1mid does not seem to + // actually store any data above byte 40, and SCI2 did not allow bitmaps with + // scaling resolutions other than the default (320x200). Perhaps SCI3 used + // the extra bytes, or there is some reason why they tried to align the header + // size with other headers like pic headers? +// uint32 bitmapHeaderSize; +// if (getSciVersion() >= SCI_VERSION_2_1_MIDDLE) { +// bitmapHeaderSize = 46; +// } else if (getSciVersion() == SCI_VERSION_2_1_EARLY) { +// bitmapHeaderSize = 40; +// } else { +// bitmapHeaderSize = 36; +// } +// return bitmapHeaderSize; + return 46; + } + CelObjMem(reg_t bitmap); virtual ~CelObjMem() override {}; diff --git a/engines/sci/graphics/text32.cpp b/engines/sci/graphics/text32.cpp index d7738b22c9..ca132d8b11 100644 --- a/engines/sci/graphics/text32.cpp +++ b/engines/sci/graphics/text32.cpp @@ -29,6 +29,7 @@ #include "sci/engine/selector.h" #include "sci/engine/state.h" #include "sci/graphics/cache.h" +#include "sci/graphics/celobj32.h" #include "sci/graphics/compare.h" #include "sci/graphics/font.h" #include "sci/graphics/frameout.h" @@ -59,37 +60,6 @@ GfxText32::GfxText32(SegManager *segMan, GfxCache *fonts, GfxScreen *screen) : _font = _cache->getFont(_defaultFontId); } -#define BITMAP_HEADER_SIZE 46 -void GfxText32::buildBitmapHeader(byte *bitmap, const int16 width, const int16 height, const uint8 skipColor, const int16 displaceX, const int16 displaceY, const int16 scaledWidth, const int16 scaledHeight, const uint32 hunkPaletteOffset, const bool useRemap) const { - - WRITE_SCI11ENDIAN_UINT16(bitmap + 0, width); - WRITE_SCI11ENDIAN_UINT16(bitmap + 2, height); - WRITE_SCI11ENDIAN_UINT16(bitmap + 4, (uint16)displaceX); - WRITE_SCI11ENDIAN_UINT16(bitmap + 6, (uint16)displaceY); - bitmap[8] = skipColor; - bitmap[9] = 0; - WRITE_SCI11ENDIAN_UINT16(bitmap + 10, 0); - - if (useRemap) { - bitmap[10] |= 2; - } - - WRITE_SCI11ENDIAN_UINT32(bitmap + 12, width * height); - WRITE_SCI11ENDIAN_UINT32(bitmap + 16, 0); - - if (hunkPaletteOffset) { - WRITE_SCI11ENDIAN_UINT32(bitmap + 20, hunkPaletteOffset + BITMAP_HEADER_SIZE); - } else { - WRITE_SCI11ENDIAN_UINT32(bitmap + 20, 0); - } - - WRITE_SCI11ENDIAN_UINT32(bitmap + 24, BITMAP_HEADER_SIZE); - WRITE_SCI11ENDIAN_UINT32(bitmap + 28, BITMAP_HEADER_SIZE); - WRITE_SCI11ENDIAN_UINT32(bitmap + 32, 0); - WRITE_SCI11ENDIAN_UINT16(bitmap + 36, scaledWidth); - WRITE_SCI11ENDIAN_UINT16(bitmap + 38, scaledHeight); -} - reg_t GfxText32::createFontBitmap(int16 width, int16 height, const Common::Rect &rect, const Common::String &text, const uint8 foreColor, const uint8 backColor, const uint8 skipColor, const GuiResourceId fontId, const TextAlign alignment, const int16 borderColor, const bool dimmed, const bool doScaling, reg_t *outBitmapObject) { _field_22 = 0; @@ -128,10 +98,10 @@ reg_t GfxText32::createFontBitmap(int16 width, int16 height, const Common::Rect _textRect = Common::Rect(); } - _bitmap = _segMan->allocateHunkEntry("FontBitmap()", _width * _height + BITMAP_HEADER_SIZE); + _bitmap = _segMan->allocateHunkEntry("FontBitmap()", _width * _height + CelObjMem::getBitmapHeaderSize()); byte *bitmap = _segMan->getHunkPointer(_bitmap); - buildBitmapHeader(bitmap, _width, _height, _skipColor, 0, 0, _scaledWidth, _scaledHeight, 0, false); + CelObjMem::buildBitmapHeader(bitmap, _width, _height, _skipColor, 0, 0, _scaledWidth, _scaledHeight, 0, false); erase(bitmapRect, false); @@ -526,10 +496,6 @@ void GfxText32::erase(const Common::Rect &rect, const bool doScaling) { buffer.fillRect(targetRect, _backColor); } -void GfxText32::disposeTextBitmap(reg_t hunkId) { - _segMan->freeHunkEntry(hunkId); -} - int16 GfxText32::getStringWidth(const Common::String &text) { // TODO: The fact that this double-scales the text makes it // seem pretty unlikely that this is ever called in real life diff --git a/engines/sci/graphics/text32.h b/engines/sci/graphics/text32.h index f9a302a65c..d95792aa8d 100644 --- a/engines/sci/graphics/text32.h +++ b/engines/sci/graphics/text32.h @@ -132,11 +132,6 @@ private: */ Common::Point _drawPosition; - // TODO: This is general for all CelObjMem and should be - // put in a single location, like maybe as a static - // method of CelObjMem?! - void buildBitmapHeader(byte *bitmap, const int16 width, const int16 height, const uint8 skipColor, const int16 displaceX, const int16 displaceY, const int16 scaledWidth, const int16 scaledHeight, const uint32 hunkPaletteOffset, const bool useRemap) const; - void drawFrame(const Common::Rect &rect, const int16 size, const uint8 color, const bool doScaling); void drawTextBox(); void erase(const Common::Rect &rect, const bool doScaling); |