aboutsummaryrefslogtreecommitdiff
path: root/graphics/thumbnail.cpp
diff options
context:
space:
mode:
authorEugene Sandulenko2013-05-17 00:18:09 +0300
committerEugene Sandulenko2013-05-17 00:18:09 +0300
commitf59512c47ea21c851535eeabf822aabdfde9167f (patch)
tree19c58c54c897dde0188e28951f0827a20ef3c4a0 /graphics/thumbnail.cpp
parent4a62d6c25a4994a72c59ca3b8f2913ead565a173 (diff)
downloadscummvm-rg350-f59512c47ea21c851535eeabf822aabdfde9167f.tar.gz
scummvm-rg350-f59512c47ea21c851535eeabf822aabdfde9167f.tar.bz2
scummvm-rg350-f59512c47ea21c851535eeabf822aabdfde9167f.zip
RECORDER: Implement Events Recorder
Diffstat (limited to 'graphics/thumbnail.cpp')
-rw-r--r--graphics/thumbnail.cpp53
1 files changed, 52 insertions, 1 deletions
diff --git a/graphics/thumbnail.cpp b/graphics/thumbnail.cpp
index ddb377306d..d04c218624 100644
--- a/graphics/thumbnail.cpp
+++ b/graphics/thumbnail.cpp
@@ -23,6 +23,7 @@
#include "graphics/scaler.h"
#include "graphics/colormasks.h"
#include "common/endian.h"
+#include "common/algorithm.h"
#include "common/system.h"
#include "common/stream.h"
#include "common/textconsole.h"
@@ -143,7 +144,6 @@ Graphics::Surface *loadThumbnail(Common::SeekableReadStream &in) {
assert(0);
}
}
-
return to;
}
@@ -216,4 +216,55 @@ bool saveThumbnail(Common::WriteStream &out, const Graphics::Surface &thumb) {
return true;
}
+
+/**
+ * Returns an array indicating which pixels of a source image horizontally or vertically get
+ * included in a scaled image
+ */
+int *scaleLine(int size, int srcSize) {
+ int scale = 100 * size / srcSize;
+ assert(scale > 0);
+ int *v = new int[size];
+ Common::fill(v, &v[size], 0);
+
+ int distCtr = 0;
+ int *destP = v;
+ for (int distIndex = 0; distIndex < srcSize; ++distIndex) {
+ distCtr += scale;
+ while (distCtr >= 100) {
+ assert(destP < &v[size]);
+ *destP++ = distIndex;
+ distCtr -= 100;
+ }
+ }
+
+ return v;
+}
+
+Graphics::Surface *scale(const Graphics::Surface &srcImage, int xSize, int ySize) {
+ Graphics::Surface *s = new Graphics::Surface();
+ s->create(xSize, ySize, srcImage.format);
+
+ int *horizUsage = scaleLine(xSize, srcImage.w);
+ int *vertUsage = scaleLine(ySize, srcImage.h);
+
+ // Loop to create scaled version
+ for (int yp = 0; yp < ySize; ++yp) {
+ const byte *srcP = (const byte *)srcImage.getBasePtr(0, vertUsage[yp]);
+ byte *destP = (byte *)s->getBasePtr(0, yp);
+
+ for (int xp = 0; xp < xSize; ++xp) {
+ const byte *tempSrcP = srcP + (horizUsage[xp] * srcImage.format.bytesPerPixel);
+ for (int byteCtr = 0; byteCtr < srcImage.format.bytesPerPixel; ++byteCtr) {
+ *destP++ = *tempSrcP++;
+ }
+ }
+ }
+
+ // Delete arrays and return surface
+ delete[] horizUsage;
+ delete[] vertUsage;
+ return s;
+}
+
} // End of namespace Graphics