[Scummvm-cvs-logs] SF.net SVN: scummvm: [21817] scummvm/trunk/gui/ThemeNew.cpp
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Tue Apr 11 19:29:04 CEST 2006
Revision: 21817
Author: lordhoto
Date: 2006-04-11 19:27:56 -0700 (Tue, 11 Apr 2006)
ViewCVS: http://svn.sourceforge.net/scummvm/?rev=21817&view=rev
Log Message:
-----------
- some little clean ups
- improves speed of the dimming effect (get's rid of divisions in favour of shifts)
- improves speed of calcGradient (nearlly twice as fast in my tests now)
Modified Paths:
--------------
scummvm/trunk/gui/ThemeNew.cpp
Modified: scummvm/trunk/gui/ThemeNew.cpp
===================================================================
--- scummvm/trunk/gui/ThemeNew.cpp 2006-04-12 01:48:15 UTC (rev 21816)
+++ scummvm/trunk/gui/ThemeNew.cpp 2006-04-12 02:27:56 UTC (rev 21817)
@@ -296,7 +296,7 @@
}
if (_dimPercentValue != 0) {
- _dimPercentValue = 100 - _dimPercentValue;
+ _dimPercentValue = 256 * (100 - _dimPercentValue) / 100;
_dialogShadingCallback = &ThemeNew::calcDimColor;
createCacheTable = true;
_shadingEffect = kShadingEffectDim;
@@ -965,9 +965,7 @@
for (int y = 0; y < partsH; ++y) {
int xPos = r.left;
- bool upDown = false;
- if (y == partsH - 1)
- upDown = true;
+ bool upDown = (y == partsH - 1);
// calculate the correct drawing height
int usedHeight = drawHeight;
@@ -979,7 +977,6 @@
OverlayColor endCol = calcGradient(start, end, yPos-r.top+usedHeight, r.height(), factor);
for (int i = 0; i < partsW; ++i) {
-
// calculate the correct drawing width
int usedWidth = drawWidth;
if (specialWidth && i == 1) {
@@ -987,25 +984,20 @@
}
// draw the right surface
- if (!i) {
+ if (!i || i == partsW - 1) {
if (!y || (y == partsH - 1 && !skipLastRow)) {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), corner, upDown, false, alpha, startCol, endCol);
+ drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), corner, upDown, (i == partsW - 1), alpha, startCol, endCol);
} else {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, false, alpha, startCol, endCol);
+ drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, (i == partsW - 1), alpha, startCol, endCol);
}
- } else if (i == partsW - 1) {
- if (!y || (y == partsH - 1 && !skipLastRow)) {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), corner, upDown, true, alpha, startCol, endCol);
- } else {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, true, alpha, startCol, endCol);
- }
} else if (!y || (y == partsH - 1 && !skipLastRow)) {
drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), top, upDown, false, alpha, startCol, endCol);
} else {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), fill, upDown, false, alpha, startCol, endCol);
+ drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), fill, false, false, alpha, startCol, endCol);
}
xPos += usedWidth;
}
+
yPos += usedHeight;
}
}
@@ -1136,9 +1128,7 @@
}
int xPos = r.left;
- bool upDown = false;
- if (y == partsH - 1)
- upDown = true;
+ bool upDown = (y == partsH - 1);
for (int i = 0; i < partsW; ++i) {
// calculate the correct drawing width
@@ -1153,18 +1143,12 @@
}
// draw the right surface
- if (!i) {
+ if (!i || i == partsW - 1) {
if (!y || (y == partsH - 1 && !skipLastRow)) {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), corner, upDown, false, alpha, startCol, endCol);
+ drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), corner, upDown, (i == partsW - 1), alpha, startCol, endCol);
} else {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, false, alpha, startCol, endCol);
+ drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, (i == partsW - 1), alpha, startCol, endCol);
}
- } else if (i == partsW - 1) {
- if (!y || (y == partsH - 1 && !skipLastRow)) {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), corner, upDown, true, alpha, startCol, endCol);
- } else {
- drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), left, upDown, true, alpha, startCol, endCol);
- }
} else if (!y || (y == partsH - 1 && !skipLastRow)) {
drawSurfaceMasked(Common::Rect(xPos, yPos, xPos+usedWidth, yPos+usedHeight), top, upDown, false, alpha, startCol, endCol);
} else {
@@ -1405,7 +1389,7 @@
switch (_shadingEffect) {
case kShadingEffectDim: {
- int cachedDim = cacheFile.readByte();
+ int cachedDim = cacheFile.readUint32BE();
if (cachedDim != _dimPercentValue)
return false;
} break;
@@ -1458,7 +1442,7 @@
switch (_shadingEffect) {
case kShadingEffectDim: {
- cacheFile.writeByte(_dimPercentValue);
+ cacheFile.writeUint32BE(_dimPercentValue);
} break;
case kShadingEffectCustom: {
@@ -1508,9 +1492,6 @@
_system->colorToRGB(col, r, g, b);
}
- //uint lum = (76 * r / 0xFF);
- //lum += (151 * g / 0xFF);
- //lum += (28 * b / 0xFF);
uint lum = (r >> 2) + (g >> 1) + (b >> 3);
return _system->RGBToColor(lum, lum, lum);
@@ -1526,9 +1507,9 @@
_system->colorToRGB(col, r, g, b);
}
- r = r * _dimPercentValue / 100;
- g = g * _dimPercentValue / 100;
- b = b * _dimPercentValue / 100;
+ r = r * _dimPercentValue >> 8;
+ g = g * _dimPercentValue >> 8;
+ b = b * _dimPercentValue >> 8;
return _system->RGBToColor(r, g, b);
}
@@ -1565,8 +1546,6 @@
}
OverlayColor getColorAlpha(OverlayColor col1, OverlayColor col2, int alpha) {
- if (alpha >= 256)
- return col1;
if (gBitFormat == 565) {
return getColorAlphaImpl<ColorMasks<565> >(col1, col2, alpha);
} else {
@@ -1575,29 +1554,26 @@
}
template<class T>
-inline OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max) {
+inline OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos) {
OverlayColor output = 0;
- output |= ((start & T::kRedMask) + (((((end & T::kRedMask) - (start & T::kRedMask))) * pos / max) & T::kRedMask)) & T::kRedMask;
- output |= ((start & T::kGreenMask) + (((((end & T::kGreenMask) - (start & T::kGreenMask))) * pos / max) & T::kGreenMask)) & T::kGreenMask;
- output |= ((start & T::kBlueMask) + (((((end & T::kBlueMask) - (start & T::kBlueMask))) * pos / max) & T::kBlueMask)) & T::kBlueMask;
+ output |= ((start & T::kRedMask) + (((((end & T::kRedMask) - (start & T::kRedMask))) * pos >> 12) & T::kRedMask)) & T::kRedMask;
+ output |= ((start & T::kGreenMask) + (((((end & T::kGreenMask) - (start & T::kGreenMask))) * pos >> 12) & T::kGreenMask)) & T::kGreenMask;
+ output |= ((start & T::kBlueMask) + (((((end & T::kBlueMask) - (start & T::kBlueMask))) * pos >> 12) & T::kBlueMask)) & T::kBlueMask;
return output;
}
OverlayColor calcGradient(OverlayColor start, OverlayColor end, int pos, int max, uint factor = 1) {
max /= factor;
pos *= factor;
- if (pos > max) {
+ if (pos >= max)
return end;
- } else if (!pos) {
- return start;
- } else if (start == end) {
- return end;
- }
+ pos = (0x1000 * pos) / max;
+
if (gBitFormat == 565) {
- return calcGradient<ColorMasks<565> >(start, end, pos, max);
+ return calcGradient<ColorMasks<565> >(start, end, pos);
} else {
- return calcGradient<ColorMasks<555> >(start, end, pos, max);
+ return calcGradient<ColorMasks<555> >(start, end, pos);
}
}
} // end of namespace GUI
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list