aboutsummaryrefslogtreecommitdiff
path: root/graphics/VectorRendererSpec.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2011-12-09 12:13:42 +0000
committerEugene Sandulenko2011-12-10 11:51:10 +0000
commit04d1c1d54bfc1640208b69524a115a0fb4b608e5 (patch)
treefedd9fbca4b64fd080c20878fdcb36f4411f0cd5 /graphics/VectorRendererSpec.cpp
parent75478959ab5204f59b4b90793d8618d24fe6d2d8 (diff)
downloadscummvm-rg350-04d1c1d54bfc1640208b69524a115a0fb4b608e5.tar.gz
scummvm-rg350-04d1c1d54bfc1640208b69524a115a0fb4b608e5.tar.bz2
scummvm-rg350-04d1c1d54bfc1640208b69524a115a0fb4b608e5.zip
GUI: Implemented color dithering for background
Diffstat (limited to 'graphics/VectorRendererSpec.cpp')
-rw-r--r--graphics/VectorRendererSpec.cpp58
1 files changed, 55 insertions, 3 deletions
diff --git a/graphics/VectorRendererSpec.cpp b/graphics/VectorRendererSpec.cpp
index 1bd07af237..430b865a4a 100644
--- a/graphics/VectorRendererSpec.cpp
+++ b/graphics/VectorRendererSpec.cpp
@@ -252,6 +252,7 @@ fillSurface() {
byte *ptr = (byte *)_activeSurface->getBasePtr(0, 0);
int h = _activeSurface->h;
+ int w = _activeSurface->w;
int pitch = _activeSurface->pitch;
if (Base::_fillMode == kFillBackground) {
@@ -259,9 +260,60 @@ fillSurface() {
} else if (Base::_fillMode == kFillForeground) {
colorFill<PixelType>((PixelType *)ptr, (PixelType *)(ptr + pitch * h), _fgColor);
} else if (Base::_fillMode == kFillGradient) {
- int i = h;
- while (i--) {
- colorFill<PixelType>((PixelType *)ptr, (PixelType *)(ptr + pitch), calcGradient(h - i, h));
+ Common::Array<PixelType> gradCache;
+ Common::Array<int> gradIndexes;
+ PixelType prevcolor = 0, color;
+ int numColors = 0;
+
+ for (int i = 0; i < h + 2; i++) {
+ color = calcGradient(i, h);
+ if (color != prevcolor || i == 0 || i > h - 1) {
+ prevcolor = color;
+ gradCache.push_back(color);
+ gradIndexes.push_back(i);
+ numColors++;
+ }
+ }
+
+ int curGrad = -1;
+ for (int i = 0; i < h; i++) {
+ PixelType *ptr1 = (PixelType *)ptr;
+
+ bool ox = (i & 1 == 1);
+ int stripSize;
+
+ if (i == gradIndexes[curGrad + 1]) {
+ curGrad++;
+
+ stripSize = gradIndexes[curGrad + 1] - gradIndexes[curGrad];
+ }
+
+ int grad = (((i - gradIndexes[curGrad]) % stripSize) << 2) / stripSize;
+
+ // Dithering:
+ // +--+ +--+ +--+ +--+
+ // | | | | | *| | *|
+ // | | | *| |* | |**|
+ // +--+ +--+ +--+ +--+
+ // 0 1 2 3
+ if (grad == 0 ||
+ gradCache[curGrad] == gradCache[curGrad + 1] || // no color change
+ stripSize < 2) { // the stip is small
+ colorFill<PixelType>((PixelType *)ptr, (PixelType *)(ptr + pitch), gradCache[curGrad]);
+ } else if (grad == 3 && ox) {
+ colorFill<PixelType>((PixelType *)ptr, (PixelType *)(ptr + pitch), gradCache[curGrad + 1]);
+ } else {
+ for (int j = 0; j < w; j++, ptr1++) {
+ bool oy = (j & 1 == 1);
+
+ if ((ox && oy) ||
+ ((grad == 2 || grad == 3) && ox && !oy) ||
+ (grad == 3 && oy))
+ *ptr1 = gradCache[curGrad + 1];
+ else
+ *ptr1 = gradCache[curGrad];
+ }
+ }
ptr += pitch;
}
}