aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/titanic/support/font.cpp4
-rw-r--r--engines/titanic/support/transparency_surface.h4
-rw-r--r--engines/titanic/support/video_surface.cpp48
-rw-r--r--engines/titanic/support/video_surface.h13
-rw-r--r--engines/wage/world.cpp2
-rw-r--r--graphics/macgui/macfontmanager.cpp28
-rw-r--r--graphics/macgui/macfontmanager.h12
7 files changed, 78 insertions, 33 deletions
diff --git a/engines/titanic/support/font.cpp b/engines/titanic/support/font.cpp
index 39a0b777a1..45d593755e 100644
--- a/engines/titanic/support/font.cpp
+++ b/engines/titanic/support/font.cpp
@@ -292,13 +292,13 @@ void STFont::copyRect(CVideoSurface *surface, const Point &pt, Rect &rect) {
if (surface->lock()) {
uint16 *lineP = surface->getBasePtr(pt.x, pt.y);
uint16 color = getColor();
- bool is16Bit = surface->getPixelDepth() == 2;
for (int yp = rect.top; yp < rect.bottom; ++yp, lineP += surface->getWidth()) {
uint16 *destP = lineP;
for (int xp = rect.left; xp < rect.right; ++xp, ++destP) {
const byte *transP = _dataPtr + yp * _dataWidth + xp;
- surface->copyPixel(destP, &color, *transP >> 3, is16Bit, true);
+ surface->copyPixel(destP, &color, *transP >> 3,
+ surface->getRawSurface()->format, true);
}
}
diff --git a/engines/titanic/support/transparency_surface.h b/engines/titanic/support/transparency_surface.h
index 06861b609b..0391b6d5b7 100644
--- a/engines/titanic/support/transparency_surface.h
+++ b/engines/titanic/support/transparency_surface.h
@@ -71,12 +71,12 @@ public:
/**
* Returns the alpha value for the pixel (0-31)
*/
- uint getAlpha() const { return getPixel() >> 3; }
+ uint getAlpha() const { return 31 - (getPixel() >> 3); }
/**
* Returns true if the pixel is completely transparent
*/
- bool isPixelTransparent() const { return getAlpha() == 0; }
+ bool isPixelTransparent() const { return getAlpha() == 31; }
};
} // End of namespace Titanic
diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp
index 79d1f075c2..c71f898889 100644
--- a/engines/titanic/support/video_surface.cpp
+++ b/engines/titanic/support/video_surface.cpp
@@ -53,14 +53,10 @@ void CVideoSurface::setupPalette(byte palette[32][32], byte val) {
for (uint idx1 = 0; idx1 < 32; ++idx1) {
for (uint idx2 = 0, base = 0; idx2 < 32; ++idx2, base += idx1) {
uint v = base / 31;
- uint v2 = (v >> 36);
- v = ((v2 >> 31) + v2) & 0xff;
- palette[idx1][idx2] = v << 3;
+ palette[idx1][idx2] = (byte)v;
if (val != 0xff && v != idx2) {
- v = 0x80808081 * v * val;
- v2 = v >> 39;
- palette[idx1][idx2] = ((v2 >> 31) + v2) << 3;
+ assert(0);
}
}
}
@@ -237,7 +233,6 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi
const uint16 *srcPtr = (const uint16 *)srcSurface->getBasePtr(
srcRect.left, flipFlag ? srcRect.top : srcRect.bottom - 1);
uint16 *destPtr = (uint16 *)destArea.getBasePtr(0, destArea.h - 1);
- bool is16Bit = src->getPixelDepth() == 2;
bool isAlpha = src->_transparencyMode == TRANS_ALPHA0 ||
src->_transparencyMode == TRANS_ALPHA255;
@@ -252,7 +247,7 @@ void CVideoSurface::transBlitRect(const Rect &srcRect, const Rect &destRect, CVi
for (int srcX = srcRect.left; srcX < srcRect.right; ++srcX) {
if (!transSurface.isPixelTransparent()) {
- copyPixel(lineDestP, lineSrcP, transSurface.getAlpha(), is16Bit, isAlpha);
+ copyPixel(lineDestP, lineSrcP, transSurface.getAlpha(), srcSurface->format, isAlpha);
}
++lineSrcP;
@@ -291,30 +286,37 @@ bool CVideoSurface::hasFrame() {
}
}
-void CVideoSurface::copyPixel(uint16 *destP, const uint16 *srcP, byte transVal, bool is16Bit, bool isAlpha) {
- const Graphics::PixelFormat srcFormat = is16Bit ?
- Graphics::PixelFormat(2, 5, 6, 5, 0, 11, 5, 0, 0) :
- Graphics::PixelFormat(2, 5, 5, 5, 0, 10, 5, 0, 0);
+#define RGB_SHIFT 3
+void CVideoSurface::copyPixel(uint16 *destP, const uint16 *srcP, byte alpha,
+ const Graphics::PixelFormat &srcFormat, bool isAlpha) {
const Graphics::PixelFormat destFormat = _ddSurface->getFormat();
- transVal &= 0xff;
- assert(transVal < 32);
+ alpha &= 0xff;
+ assert(alpha < 32);
- // Get the color
+ // Get the source color
byte r, g, b;
srcFormat.colorToRGB(*srcP, r, g, b);
+ r >>= RGB_SHIFT;
+ g >>= RGB_SHIFT;
+ b >>= RGB_SHIFT;
+
if (isAlpha) {
- r = _palette1[31 - transVal][r >> 3];
- g = _palette1[31 - transVal][g >> 3];
- b = _palette1[31 - transVal][b >> 3];
+ r = _palette1[31 - alpha][r];
+ g = _palette1[31 - alpha][g];
+ b = _palette1[31 - alpha][b];
}
byte r2, g2, b2;
destFormat.colorToRGB(*destP, r2, g2, b2);
- r2 = _palette1[transVal][r2 >> 3];
- g2 = _palette1[transVal][g2 >> 3];
- b2 = _palette1[transVal][b2 >> 3];
-
- *destP = destFormat.RGBToColor(r + r2, g + g2, b + b2);
+ r2 >>= RGB_SHIFT;
+ g2 >>= RGB_SHIFT;
+ b2 >>= RGB_SHIFT;
+ r2 = _palette1[alpha][r2];
+ g2 = _palette1[alpha][g2];
+ b2 = _palette1[alpha][b2];
+
+ *destP = destFormat.RGBToColor((r + r2) << RGB_SHIFT,
+ (g + g2) << RGB_SHIFT, (b + b2) << RGB_SHIFT);
}
/*------------------------------------------------------------------------*/
diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h
index 4a4ce1861a..690669b79b 100644
--- a/engines/titanic/support/video_surface.h
+++ b/engines/titanic/support/video_surface.h
@@ -58,7 +58,6 @@ public:
*/
static void setup() {
setupPalette(_palette1, 0xff);
- setupPalette(_palette2, 0xe0);
}
private:
/**
@@ -340,8 +339,16 @@ public:
/**
* Copies a pixel, handling transparency
- */
- void copyPixel(uint16 *destP, const uint16 *srcP, byte transVal, bool is16Bit, bool isAlpha);
+ * @param destP Dest pointer to 16-bit pixel
+ * @param srcP Source pointer to 16-bit pixel
+ * @param alpha Alpha (0-31). At 0, it's completely opaque,
+ * and overwrites the dest pixel. Through to 31, which is completely
+ * transparent, and ignores the source pixel.
+ * @param srcFormat The source surface format
+ * @param isAlpha If true, has alpha channel
+ */
+ void copyPixel(uint16 *destP, const uint16 *srcP, byte alpha,
+ const Graphics::PixelFormat &srcFormat, bool isAlpha);
};
class OSVideoSurface : public CVideoSurface {
diff --git a/engines/wage/world.cpp b/engines/wage/world.cpp
index 100517b836..90d689720e 100644
--- a/engines/wage/world.cpp
+++ b/engines/wage/world.cpp
@@ -206,7 +206,7 @@ bool World::loadWorld(Common::MacResManager *resMan) {
scene->_textBounds = readRect(res);
int fontType = res->readUint16BE();
int fontSize = res->readUint16BE();
- scene->_font = new Graphics::MacFont(fontType, fontSize, Graphics::FontManager::kConsoleFont);
+ scene->_font = new Graphics::MacFont(fontType, fontSize, Graphics::kMacFontRegular, Graphics::FontManager::kConsoleFont);
Common::String text;
while (res->pos() < res->size()) {
diff --git a/graphics/macgui/macfontmanager.cpp b/graphics/macgui/macfontmanager.cpp
index 03fcb41f91..97da1a6d96 100644
--- a/graphics/macgui/macfontmanager.cpp
+++ b/graphics/macgui/macfontmanager.cpp
@@ -72,6 +72,7 @@ void MacFontManager::loadFonts() {
}
FontMan.assignFontToName(fontName, font);
+ _fontRegistry.setVal(fontName, font);
debug(2, " %s", fontName.c_str());
}
@@ -86,7 +87,10 @@ const Font *MacFontManager::getFont(MacFont macFont) {
if (!_builtInFonts) {
if (macFont.getName().empty())
- macFont.setName(getFontName(macFont.getId(), macFont.getSize()));
+ macFont.setName(getFontName(macFont.getId(), macFont.getSize(), macFont.getSlant()));
+
+ if (!_fontRegistry.contains(macFont.getName()))
+ generateFontSubstitute(macFont);
font = FontMan.getFontByName(macFont.getName());
@@ -172,4 +176,26 @@ const char *MacFontManager::getFontName(int id, int size, int slant) {
return name;
}
+const char *MacFontManager::getFontName(MacFont &font) {
+ return getFontName(font.getId(), font.getSize(), font.getSlant());
+}
+
+void MacFontManager::generateFontSubstitute(MacFont &macFont) {
+ if (_fontRegistry.contains(getFontName(macFont.getId(), macFont.getSize() * 2, macFont.getSlant()))) {
+ generateFont(macFont, MacFont(macFont.getId(), macFont.getSize() * 2, macFont.getSlant()));
+
+ return;
+ }
+
+ if (_fontRegistry.contains(getFontName(macFont.getId(), macFont.getSize() / 2, macFont.getSlant()))) {
+ generateFont(macFont, MacFont(macFont.getId(), macFont.getSize() / 2, macFont.getSlant()));
+
+ return;
+ }
+}
+
+void MacFontManager::generateFont(MacFont fromFont, MacFont toFont) {
+ warning("Found font substitute from font %s to %s", getFontName(fromFont), getFontName(toFont));
+}
+
} // End of namespace Graphics
diff --git a/graphics/macgui/macfontmanager.h b/graphics/macgui/macfontmanager.h
index 568c1530c0..a263ab52ed 100644
--- a/graphics/macgui/macfontmanager.h
+++ b/graphics/macgui/macfontmanager.h
@@ -37,16 +37,20 @@ enum {
kMacFontItalic
};
+class BdfFont;
+
class MacFont {
public:
- MacFont(int id = kMacFontChicago, int size = 12, FontManager::FontUsage fallback = Graphics::FontManager::kBigGUIFont) {
+ MacFont(int id = kMacFontChicago, int size = 12, int slant = kMacFontRegular, FontManager::FontUsage fallback = Graphics::FontManager::kBigGUIFont) {
_id = id;
_size = size;
+ _slant = slant;
_fallback = fallback;
}
int getId() { return _id; };
int getSize() { return _size; }
+ int getSlant() { return _slant; }
Common::String getName() { return _name; }
void setName(Common::String &name) { _name = name; }
void setName(const char *name) { _name = name; }
@@ -55,6 +59,7 @@ public:
private:
int _id;
int _size;
+ int _slant;
Common::String _name;
FontManager::FontUsage _fallback;
};
@@ -86,9 +91,14 @@ private:
* @return the font name or NULL if ID goes beyond the mapping
*/
const char *getFontName(int id, int size, int slant = kMacFontRegular);
+ const char *getFontName(MacFont &font);
+
+ void generateFontSubstitute(MacFont &macFont);
+ void generateFont(MacFont fromFont, MacFont toFont);
private:
bool _builtInFonts;
+ Common::HashMap<Common::String, BdfFont *> _fontRegistry;
};
} // End of namespace Graphics