aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gfx/gfx_pixmap_scale.cpp
diff options
context:
space:
mode:
authorFilippos Karapetis2009-09-06 22:27:29 +0000
committerFilippos Karapetis2009-09-06 22:27:29 +0000
commit876a7b657fabd6722432fa3eface3137a12eb34f (patch)
treee41e5e42e4298c80ae9d4ee226aa6989dae2c60a /engines/sci/gfx/gfx_pixmap_scale.cpp
parentf98dc19f71f008af8642704aa13cd953f05de8e0 (diff)
downloadscummvm-rg350-876a7b657fabd6722432fa3eface3137a12eb34f.tar.gz
scummvm-rg350-876a7b657fabd6722432fa3eface3137a12eb34f.tar.bz2
scummvm-rg350-876a7b657fabd6722432fa3eface3137a12eb34f.zip
Removed the hi-color code (16bpp & 24bpp). All SCI games use up to 256 colors, so hi-color isn't really used anywhere, and it only makes the overall code more complex for no reason
svn-id: r43994
Diffstat (limited to 'engines/sci/gfx/gfx_pixmap_scale.cpp')
-rw-r--r--engines/sci/gfx/gfx_pixmap_scale.cpp80
1 files changed, 15 insertions, 65 deletions
diff --git a/engines/sci/gfx/gfx_pixmap_scale.cpp b/engines/sci/gfx/gfx_pixmap_scale.cpp
index 865fcf3662..6131c88619 100644
--- a/engines/sci/gfx/gfx_pixmap_scale.cpp
+++ b/engines/sci/gfx/gfx_pixmap_scale.cpp
@@ -26,7 +26,6 @@
/* Required defines:
** FUNCNAME: Function name
** SIZETYPE: Type used for each pixel
-** EXTRA_BYTE_OFFSET: Extra source byte offset for copying (used on big-endian machines in 24 bit mode)
*/
#include "sci/gfx/gfx_system.h"
@@ -39,18 +38,14 @@ namespace Sci {
// TODO: Replace this code with our common scalers (/graphics/scaler.h)
-#define EXTEND_COLOR(x) (unsigned) ((((unsigned) x) << 24) | (((unsigned) x) << 16) | (((unsigned) x) << 8) | ((unsigned) x))
-
-template<int COPY_BYTES, typename SIZETYPE, int EXTRA_BYTE_OFFSET>
-void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, int scale) {
- SIZETYPE result_colors[GFX_PIC_COLORS];
- SIZETYPE alpha_color = 0;
- SIZETYPE alpha_ormask = 0xffffffff & 0;
+static void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, int scale) {
+ byte result_colors[GFX_PIC_COLORS];
+ byte alpha_color = 0;
+ byte alpha_ormask = 0xffffffff & 0;
int xfact = (scale) ? mode->xfact : 1;
int yfact = (scale) ? mode->yfact : 1;
int widthc, heightc; // Width duplication counter
int line_width = xfact * pxm->index_width;
- int bytespp = mode->bytespp;
int x, y;
int i;
byte byte_transparent = 0;
@@ -61,23 +56,12 @@ void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, int scale
int using_alpha = pxm->color_key != GFX_PIXMAP_COLOR_KEY_NONE;
int separate_alpha_map = using_alpha;
- assert(bytespp == COPY_BYTES);
-
if (separate_alpha_map && !alpha_dest)
alpha_dest = pxm->alpha_map = (byte *)malloc(pxm->index_width * xfact * pxm->index_height * yfact);
// Calculate all colors
- for (i = 0; i < pxm->colors_nr(); i++) {
- int col;
- const PaletteEntry& color = pxm->palette->getColor(i);
- if (mode->palette)
- col = color.parent_index;
- else {
- col = mode->format.ARGBToColor(0, color.r, color.g, color.b);
- col |= alpha_ormask;
- }
- result_colors[i] = col;
- }
+ for (i = 0; i < pxm->colors_nr(); i++)
+ result_colors[i] = pxm->palette->getColor(i).parent_index;
if (!separate_alpha_map && pxm->color_key != GFX_PIXMAP_COLOR_KEY_NONE)
result_colors[pxm->color_key] = alpha_color;
@@ -89,15 +73,15 @@ void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, int scale
for (x = 0; x < pxm->index_width; x++) {
int isalpha;
- SIZETYPE col = result_colors[isalpha = *src++] << (EXTRA_BYTE_OFFSET * 8);
+ byte col = result_colors[isalpha = *src++];
isalpha = (isalpha == pxm->color_key) && using_alpha;
// O(n) loops. There is an O(ln(n)) algorithm for this, but its slower for small n (which we're optimizing for here).
// And, anyway, most of the time is spent in memcpy() anyway.
for (widthc = 0; widthc < xfact; widthc++) {
- memcpy(dest, &col, COPY_BYTES);
- dest += COPY_BYTES;
+ memcpy(dest, &col, 1);
+ dest++;
}
if (separate_alpha_map) { // Set separate alpha map
@@ -109,42 +93,14 @@ void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, int scale
// Copies each line. O(n) iterations; again, this could be optimized to O(ln(n)) for very high resolutions,
// but that wouldn't really help that much, as the same amount of data still would have to be transferred.
for (heightc = 1; heightc < yfact; heightc++) {
- memcpy(dest, prev_dest, line_width * bytespp);
- dest += line_width * bytespp;
+ memcpy(dest, prev_dest, line_width);
+ dest += line_width;
if (separate_alpha_map) {
memcpy(alpha_dest, prev_alpha_dest, line_width);
alpha_dest += line_width;
}
}
}
-}
-
-static void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, int scale) {
- switch (mode->bytespp) {
-
- case 1:
- _gfx_xlate_pixmap_unfiltered<1, uint8, 0>(mode, pxm, scale);
- break;
-
- case 2:
- _gfx_xlate_pixmap_unfiltered<2, uint16, 0>(mode, pxm, scale);
- break;
-
- case 3:
-#ifdef SCUMM_BIG_ENDIAN
- _gfx_xlate_pixmap_unfiltered<3, uint32, 1>(mode, pxm, scale);
-#else
- _gfx_xlate_pixmap_unfiltered<3, uint32, 0>(mode, pxm, scale);
-#endif
- break;
-
- case 4:
- _gfx_xlate_pixmap_unfiltered<4, uint32, 0>(mode, pxm, scale);
- break;
-
- default:
- error("Invalid mode->bytespp=%d", mode->bytespp);
- }
if (pxm->flags & GFX_PIXMAP_FLAG_SCALED_INDEX) {
pxm->width = pxm->index_width;
@@ -157,24 +113,18 @@ static void _gfx_xlate_pixmap_unfiltered(gfx_mode_t *mode, gfx_pixmap_t *pxm, in
void gfx_xlate_pixmap(gfx_pixmap_t *pxm, gfx_mode_t *mode) {
- int was_allocated = 0;
-
- if (mode->palette) {
- if (pxm->palette && pxm->palette != mode->palette)
- pxm->palette->mergeInto(mode->palette);
- }
-
+ if (pxm->palette && pxm->palette != mode->palette)
+ pxm->palette->mergeInto(mode->palette);
if (!pxm->data) {
- pxm->data = (byte*)malloc(mode->xfact * mode->yfact * pxm->index_width * pxm->index_height * mode->bytespp + 1);
+ pxm->data = (byte*)malloc(mode->xfact * mode->yfact * pxm->index_width * pxm->index_height + 1);
// +1: Eases coying on BE machines in 24 bpp packed mode
// Assume that memory, if allocated already, will be sufficient
// Allocate alpha map
if (pxm->colors_nr() < GFX_PIC_COLORS)
pxm->alpha_map = (byte*)malloc(mode->xfact * mode->yfact * pxm->index_width * pxm->index_height + 1);
- } else
- was_allocated = 1;
+ }
_gfx_xlate_pixmap_unfiltered(mode, pxm, !(pxm->flags & GFX_PIXMAP_FLAG_SCALED_INDEX));