aboutsummaryrefslogtreecommitdiff
path: root/graphics/scaler
diff options
context:
space:
mode:
authorJohannes Schickel2008-08-20 14:03:34 +0000
committerJohannes Schickel2008-08-20 14:03:34 +0000
commitf4fc8c3e4c1621e8c40392881a6c647f9915fa38 (patch)
treee4f8b46333677a458d790b511047d7a44b4abbc7 /graphics/scaler
parenta79e9385a19530698e5c1cc1da39cb6b80cb9f74 (diff)
downloadscummvm-rg350-f4fc8c3e4c1621e8c40392881a6c647f9915fa38.tar.gz
scummvm-rg350-f4fc8c3e4c1621e8c40392881a6c647f9915fa38.tar.bz2
scummvm-rg350-f4fc8c3e4c1621e8c40392881a6c647f9915fa38.zip
Committed patch #2050337 "KYRA/SCUMM: Thumbnail support/improvement". (Without Max' compressed backward seeking support for now)
svn-id: r34053
Diffstat (limited to 'graphics/scaler')
-rw-r--r--graphics/scaler/thumbnail.cpp91
1 files changed, 57 insertions, 34 deletions
diff --git a/graphics/scaler/thumbnail.cpp b/graphics/scaler/thumbnail.cpp
index f1caa5d2e5..bdfa0ff5f6 100644
--- a/graphics/scaler/thumbnail.cpp
+++ b/graphics/scaler/thumbnail.cpp
@@ -126,70 +126,93 @@ static bool grabScreen565(Graphics::Surface *surf) {
return true;
}
-bool createThumbnailFromScreen(Graphics::Surface* surf) {
- assert(surf);
-
- int screenWidth = g_system->getWidth();
- int screenHeight = g_system->getHeight();
-
- Graphics::Surface screen;
-
- if (!grabScreen565(&screen))
- return false;
+static bool createThumbnail(Graphics::Surface &out, Graphics::Surface &in) {
+ uint16 width = in.w;
+ uint16 inHeight = in.h;
- uint16 width = screenWidth;
-
- if (screenWidth < 320) {
+ if (width < 320) {
// Special case to handle MM NES (uses a screen width of 256)
width = 320;
// center MM NES screen
Graphics::Surface newscreen;
- newscreen.create(width, screen.h, screen.bytesPerPixel);
+ newscreen.create(width, in.h, in.bytesPerPixel);
- uint8 *dst = (uint8*)newscreen.getBasePtr((320 - screenWidth) / 2, 0);
- uint8 *src = (uint8*)screen.getBasePtr(0, 0);
- uint16 height = screen.h;
+ uint8 *dst = (uint8*)newscreen.getBasePtr((320 - in.w) / 2, 0);
+ const uint8 *src = (uint8*)in.getBasePtr(0, 0);
+ uint16 height = in.h;
while (height--) {
- memcpy(dst, src, screen.pitch);
+ memcpy(dst, src, in.pitch);
dst += newscreen.pitch;
- src += screen.pitch;
+ src += in.pitch;
}
- screen.free();
- screen = newscreen;
- } else if (screenWidth == 720) {
+ in.free();
+ in = newscreen;
+ } else if (width == 720) {
// Special case to handle Hercules mode
width = 640;
- screenHeight = 400;
+ inHeight = 400;
// cut off menu and so on..
Graphics::Surface newscreen;
- newscreen.create(width, 400, screen.bytesPerPixel);
+ newscreen.create(width, 400, in.bytesPerPixel);
- uint8 *dst = (uint8*)newscreen.getBasePtr(0, (400 - 240) / 2);
- uint8 *src = (uint8*)screen.getBasePtr(41, 28);
+ uint8 *dst = (uint8*)in.getBasePtr(0, (400 - 240) / 2);
+ const uint8 *src = (uint8*)in.getBasePtr(41, 28);
for (int y = 0; y < 240; ++y) {
- memcpy(dst, src, 640 * screen.bytesPerPixel);
+ memcpy(dst, src, 640 * in.bytesPerPixel);
dst += newscreen.pitch;
- src += screen.pitch;
+ src += in.pitch;
}
- screen.free();
- screen = newscreen;
+ in.free();
+ in = newscreen;
}
- uint16 newHeight = !(screenHeight % 240) ? kThumbnailHeight2 : kThumbnailHeight1;
+ uint16 newHeight = !(inHeight % 240) ? kThumbnailHeight2 : kThumbnailHeight1;
int gBitFormatBackUp = gBitFormat;
gBitFormat = 565;
- surf->create(kThumbnailWidth, newHeight, sizeof(uint16));
- createThumbnail((const uint8*)screen.pixels, width * sizeof(uint16), (uint8*)surf->pixels, surf->pitch, width, screenHeight);
+ out.create(kThumbnailWidth, newHeight, sizeof(uint16));
+ createThumbnail((const uint8 *)in.pixels, width * sizeof(uint16), (uint8 *)out.pixels, out.pitch, width, inHeight);
gBitFormat = gBitFormatBackUp;
- screen.free();
+ in.free();
return true;
}
+
+bool createThumbnailFromScreen(Graphics::Surface* surf) {
+ assert(surf);
+
+ Graphics::Surface screen;
+
+ if (!grabScreen565(&screen))
+ return false;
+
+ return createThumbnail(*surf, screen);
+}
+
+bool createThumbnail(Graphics::Surface *surf, const uint8 *pixels, int w, int h, const uint8 *palette) {
+ assert(surf);
+
+ Graphics::Surface screen;
+ screen.create(w, h, 2);
+
+ for (uint y = 0; y < screen.h; ++y) {
+ for (uint x = 0; x < screen.w; ++x) {
+ byte r, g, b;
+ r = palette[pixels[y * w + x] * 3];
+ g = palette[pixels[y * w + x] * 3 + 1];
+ b = palette[pixels[y * w + x] * 3 + 2];
+
+ ((uint16 *)screen.pixels)[y * screen.w + x] = RGBToColor<ColorMasks<565> >(r, g, b);
+ }
+ }
+
+ return createThumbnail(*surf, screen);
+}
+