Removed unnecessary comment from license text which got there by a copy&paste error...
authorFlorian Schulze <crow@icculus.org>
Fri, 21 Mar 2003 14:47:10 +0000 (14:47 +0000)
committerFlorian Schulze <crow@icculus.org>
Fri, 21 Mar 2003 14:47:10 +0000 (14:47 +0000)
Using new scaling filter which works with 8bit graphics.
Removed all code which deals with non 8bit color modes.

VisualC6/jumpnbump.dsp
globals.pre
main.c
sdl/gfx.c

index cbb3aaf..50efec3 100644 (file)
@@ -61,8 +61,7 @@ InputPath=.\Release\jumpnbump.exe
 SOURCE="$(InputPath)"
 
 BuildCmds= \
-       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Release\gobpack.exe" "..\VisualC6\pack\Release\jnbpack.exe" \
-       
+       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Release\gobpack.exe" "..\VisualC6\pack\Release\jnbpack.exe"
 
 "$(ProjDir)\..\data\font.gob" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
    $(BuildCmds)
@@ -111,8 +110,7 @@ InputPath=.\Debug\jumpnbump.exe
 SOURCE="$(InputPath)"
 
 BuildCmds= \
-       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Debug\gobpack.exe" "..\VisualC6\pack\Debug\jnbpack.exe" \
-       
+       call "$(ProjDir)\..\data\pack.bat" "$(ProjDir)\..\data" "..\VisualC6\gobpack\Debug\gobpack.exe" "..\VisualC6\pack\Debug\jnbpack.exe"
 
 "$(ProjDir)\..\data\font.gob" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
    $(BuildCmds)
@@ -141,6 +139,10 @@ BuildCmds= \
 # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
 # Begin Source File
 
+SOURCE=..\filter.c
+# End Source File
+# Begin Source File
+
 SOURCE=..\fireworks.c
 # End Source File
 # Begin Source File
@@ -181,6 +183,10 @@ SOURCE=..\dj.h
 # End Source File
 # Begin Source File
 
+SOURCE=..\filter.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\globals.pre
 
 !IF  "$(CFG)" == "jumpnbump - Win32 Release"
index 11337b9..b2bb7c9 100644 (file)
@@ -6,10 +6,6 @@
  *
  * Copyright (C) 2002 Florian Schulze <crow@icculus.org>
  *
- * Portions of this code are from the MPEG software simulation group
- * idct implementation. This code will be replaced with a new
- * implementation soon.
- *
  * This file is part of Jump'n'Bump.
  *
  * Jump'n'Bump is free software; you can redistribute it and/or modify
@@ -92,7 +88,6 @@ extern int screen_width;
 extern int screen_height;
 extern int screen_pitch;
 extern int scale_up;
-extern int bytes_per_pixel;
 
 #ifndef USE_SDL
 #define KEY_PL1_LEFT 0xcb
diff --git a/main.c b/main.c
index 1eb34d6..d8a9c7d 100644 (file)
--- a/main.c
+++ b/main.c
@@ -6,10 +6,6 @@
  *
  * Copyright (C) 2002 Florian Schulze <crow@icculus.org>
  *
- * Portions of this code are from the MPEG software simulation group
- * idct implementation. This code will be replaced with a new
- * implementation soon.
- *
  * This file is part of Jump'n'Bump.
  *
  * Jump'n'Bump is free software; you can redistribute it and/or modify
@@ -2465,9 +2461,9 @@ void draw_pobs(int page)
                main_info.page_info[page].pobs[c1].back_buf_ofs = back_buf_ofs;
                get_block(page, main_info.page_info[page].pobs[c1].x - pob_hs_x(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), main_info.page_info[page].pobs[c1].y - pob_hs_y(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data), (unsigned char *)main_info.pob_backbuf[page] + back_buf_ofs);
                if (scale_up)
-                       back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * 4 * bytes_per_pixel;
+                       back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * 4;
                else
-                       back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * bytes_per_pixel;
+                       back_buf_ofs += pob_width(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data) * pob_height(main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data);
                put_pob(page, main_info.page_info[page].pobs[c1].x, main_info.page_info[page].pobs[c1].y, main_info.page_info[page].pobs[c1].image, main_info.page_info[page].pobs[c1].pob_data, 1, mask_pic);
        }
 
@@ -2843,8 +2839,8 @@ all provided the user didn't choose one on the commandline. */
        }
 #endif
 
-       main_info.pob_backbuf[0] = malloc(screen_pitch*screen_height*bytes_per_pixel);
-       main_info.pob_backbuf[1] = malloc(screen_pitch*screen_height*bytes_per_pixel);
+       main_info.pob_backbuf[0] = malloc(screen_pitch*screen_height);
+       main_info.pob_backbuf[1] = malloc(screen_pitch*screen_height);
 
        for (c1 = 0; c1 < 7; c1++) {
                player_anims[c1].num_frames = player_anim_data[c1 * 10];
index 6c4e0b0..9585632 100644 (file)
--- a/sdl/gfx.c
+++ b/sdl/gfx.c
@@ -6,10 +6,6 @@
  *
  * Copyright (C) 2002 Florian Schulze <crow@icculus.org>
  *
- * Portions of this code are from the MPEG software simulation group
- * idct implementation. This code will be replaced with a new
- * implementation soon.
- *
  * This file is part of Jump'n'Bump.
  *
  * Jump'n'Bump is free software; you can redistribute it and/or modify
@@ -29,6 +25,7 @@
 
 #include "globals.h"
 #include "SDL_endian.h"
+#include "filter.h"
 
 #ifdef _MSC_VER
     #include "jumpnbump32.xpm"
@@ -43,10 +40,8 @@ int screen_width=400;
 int screen_height=256;
 int screen_pitch=400;
 int scale_up=0;
-int bytes_per_pixel=1;
 int dirty_block_shift=4;
 
-static int current_pal[256];
 static SDL_Surface *jnb_surface;
 static int fullscreen = 0;
 static int vinited = 0;
@@ -145,11 +140,11 @@ static SDL_Surface *load_xpm_from_array(char **xpm)
        return surface;
 }
 
-void *get_vgaptr(int page, int x, int y)
+unsigned char *get_vgaptr(int page, int x, int y)
 {
        assert(drawing_enable==1);
 
-       return (unsigned char *)screen_buffer[page] + (y*screen_pitch)+(x*bytes_per_pixel);
+       return (unsigned char *)screen_buffer[page] + (y*screen_pitch)+(x);
 }
 
 
@@ -159,23 +154,20 @@ void set_scaling(int scale)
                screen_width=800;
                screen_height=512;
                scale_up=1;
-               bytes_per_pixel=2;
                dirty_block_shift=5;
-               screen_pitch=screen_width*bytes_per_pixel;
+               screen_pitch=screen_width;
        } else {
                screen_width=400;
                screen_height=256;
                scale_up=0;
-               bytes_per_pixel=1;
                dirty_block_shift=4;
-               screen_pitch=screen_width*bytes_per_pixel;
+               screen_pitch=screen_width;
        }
 }
 
 void open_screen(void)
 {
        int lval = 0;
-       int bpp;
        int flags;
 
        lval = SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO | SDL_INIT_JOYSTICK);
@@ -184,14 +176,10 @@ void open_screen(void)
                exit(EXIT_FAILURE);
        }
 
-       if (scale_up)
-               bpp = 16;
-       else
-               bpp = 8;
        flags = SDL_SWSURFACE;
        if (fullscreen)
                flags |= SDL_FULLSCREEN;
-       jnb_surface = SDL_SetVideoMode(screen_width, screen_height, bpp, flags);
+       jnb_surface = SDL_SetVideoMode(screen_width, screen_height, 8, flags);
 
        if (!jnb_surface) {
                fprintf(stderr, "SDL ERROR: %s\n", SDL_GetError());
@@ -203,7 +191,7 @@ void open_screen(void)
        else
                SDL_ShowCursor(1);
 
-       SDL_WM_SetCaption("Jump n Bump","");
+       SDL_WM_SetCaption("Jump'n'Bump","");
 
        icon=load_xpm_from_array(jumpnbump_xpm);
        if (icon==NULL) {
@@ -214,11 +202,10 @@ void open_screen(void)
 
        vinited = 1;
 
-       memset(current_pal, 0, sizeof(current_pal));
        memset(dirty_blocks, 0, sizeof(dirty_blocks));
 
-       screen_buffer[0]=malloc(screen_width*screen_height*bytes_per_pixel);
-       screen_buffer[1]=malloc(screen_width*screen_height*bytes_per_pixel);
+       screen_buffer[0]=malloc(screen_width*screen_height);
+       screen_buffer[1]=malloc(screen_width*screen_height);
 
 /*
        dirty_blocks[0]=malloc(sizeof(int)*25*16+1000);
@@ -249,31 +236,16 @@ void wait_vrt(int mix)
 void clear_page(int page, int color)
 {
        int i,j;
+       unsigned char *buf = get_vgaptr(page, 0, 0);
 
        assert(drawing_enable==1);
 
        for (i=0; i<(25*16); i++)
                dirty_blocks[page][i] = 1;
 
-       if (bytes_per_pixel==1) {
-               unsigned char *buf = get_vgaptr(page, 0, 0);
-
-               for (i=0; i<screen_height; i++)
-                       for (j=0; j<screen_width; j++)
-                               *buf++ = color;
-       } else if (bytes_per_pixel==2) {
-               unsigned short *buf = get_vgaptr(page, 0, 0);
-
-               for (i=0; i<screen_height; i++)
-                       for (j=0; j<screen_width; j++)
-                               *buf++ = color;
-       } else {
-               unsigned int *buf = get_vgaptr(page, 0, 0);
-
-               for (i=0; i<screen_height; i++)
-                       for (j=0; j<screen_width; j++)
-                               *buf++ = color;
-       }
+       for (i=0; i<screen_height; i++)
+               for (j=0; j<screen_width; j++)
+                       *buf++ = color;
 }
 
 
@@ -288,29 +260,11 @@ void clear_lines(int page, int y, int count, int color)
                y *= 2;
        }
 
-       if (bytes_per_pixel==1) {
-               for (i=0; i<count; i++) {
-                       if ((i+y)<screen_height) {
-                               unsigned char *buf = get_vgaptr(page, 0, i+y);
-                               for (j=0; j<screen_width; j++)
-                                       *buf++ = color;
-                       }
-               }
-       } else if (bytes_per_pixel==2) {
-               for (i=0; i<count; i++) {
-                       if ((i+y)<screen_height) {
-                               unsigned short *buf = get_vgaptr(page, 0, i+y);
-                               for (j=0; j<screen_width; j++)
-                                       *buf++ = color;
-                       }
-               }
-       } else {
-               for (i=0; i<count; i++) {
-                       if ((i+y)<screen_height) {
-                               unsigned int *buf = get_vgaptr(page, 0, i+y);
-                               for (j=0; j<screen_width; j++)
-                                       *buf++ = color;
-                       }
+       for (i=0; i<count; i++) {
+               if ((i+y)<screen_height) {
+                       unsigned char *buf = get_vgaptr(page, 0, i+y);
+                       for (j=0; j<screen_width; j++)
+                               *buf++ = color;
                }
        }
        count = ((y+count)>>dirty_block_shift) - (y>>dirty_block_shift) + 1;
@@ -341,12 +295,7 @@ int get_pixel(int page, int x, int y)
        assert(x<screen_width);
        assert(y<screen_height);
 
-       if (bytes_per_pixel==1)
-               return *(unsigned char *)get_vgaptr(page, x, y);
-       else if (bytes_per_pixel==2)
-               return *(unsigned short *)get_vgaptr(page, x, y);
-       else
-               return *(unsigned int *)get_vgaptr(page, x, y);
+       return *(unsigned char *)get_vgaptr(page, x, y);
 }
 
 
@@ -364,326 +313,7 @@ void set_pixel(int page, int x, int y, int color)
 
        dirty_blocks[page][(y>>dirty_block_shift)*25+(x>>dirty_block_shift)] = 1;
 
-       if (bytes_per_pixel==1)
-               *(unsigned char *)get_vgaptr(page, x, y) = color;
-       else if (bytes_per_pixel==2)
-               *(unsigned short *)get_vgaptr(page, x, y) = color;
-       else
-               *(unsigned int *)get_vgaptr(page, x, y) = color;
-}
-
-
-static unsigned int colorMask = 0xF7DEF7DE;
-static unsigned int lowPixelMask = 0x08210821;
-static unsigned int qcolorMask = 0xE79CE79C;
-static unsigned int qlowpixelMask = 0x18631863;
-static unsigned int redblueMask = 0xF81F;
-static unsigned int greenMask = 0x7E0;
-
-int Init_2xSaI (unsigned int BitFormat)
-{
-    if (BitFormat == 565)
-    {
-       colorMask = (0xF7DEF7DE);
-       lowPixelMask = (0x08210821);
-       qcolorMask = (0xE79CE79C);
-       qlowpixelMask = (0x18631863);
-       redblueMask = (0xF81F);
-       greenMask = (0x7E0);
-    }
-    else if (BitFormat == 555)
-    {
-       colorMask = (0x7BDE7BDE);
-       lowPixelMask = (0x04210421);
-       qcolorMask = (0x739C739C);
-       qlowpixelMask = (0x0C630C63);
-       redblueMask = (0x7C1F);
-       greenMask = (0x3E0);
-    }
-    else
-    {
-       return 0;
-    }
-
-#ifdef MMX
-    Init_2xSaIMMX (BitFormat);
-#endif
-
-    return 1;
-}
-
-
-void Scale2x (unsigned char *src, unsigned int src_pitch, int src_bytes_per_pixel,
-                unsigned char *dst, unsigned int dst_pitch, int dst_bytes_per_pixel,
-                int width, int height, int pal[256])
-{
-#define GET_COLOR(x) (pal[(x)])
-
-       int x,y;
-       unsigned char *src_line;
-       unsigned char *dst_line[2];
-
-       src_line = src;
-       dst_line[0] = dst;
-       dst_line[1] = dst + dst_pitch;
-       for (y=0; y<height; y++) {
-               for (x=0; x<width; x++) {
-                       int color;
-
-                       if (src_bytes_per_pixel == 1) {
-                               color = GET_COLOR(*(((unsigned char*)src_line) + x));
-                       } else if (src_bytes_per_pixel == 2) {
-                               color = *(((unsigned short*)src_line) + x);
-                       } else {
-                               color = *(((unsigned int*)src_line) + x);
-                       }
-
-                       if (dst_bytes_per_pixel == 2) {
-                               *((unsigned long *) (&dst_line[0][x * 4])) = color | (color << 16);
-                               *((unsigned long *) (&dst_line[1][x * 4])) = color | (color << 16);
-                       } else {
-                               *((unsigned long *) (&dst_line[0][x * 8])) = color;
-                               *((unsigned long *) (&dst_line[0][x * 8 + 4])) = color;
-                               *((unsigned long *) (&dst_line[1][x * 8])) = color;
-                               *((unsigned long *) (&dst_line[1][x * 8 + 4])) = color;
-                       }
-               }
-
-               src_line += src_pitch;
-
-               if (y < height - 1) {
-                       dst_line[0] += dst_pitch * 2;
-                       dst_line[1] += dst_pitch * 2;
-               }
-       }
-}
-
-
-void Super2xSaI (unsigned char *src, unsigned int src_pitch, int src_bytes_per_pixel,
-                unsigned char *dst, unsigned int dst_pitch, int dst_bytes_per_pixel,
-                int width, int height, int pal[256])
-{
-#define GET_RESULT(A, B, C, D) ((A != C || A != D) - (B != C || B != D))
-
-#define INTERPOLATE(A, B) (((A & colorMask) >> 1) + ((B & colorMask) >> 1) + (A & B & lowPixelMask))
-
-#define Q_INTERPOLATE(A, B, C, D) ((A & qcolorMask) >> 2) + ((B & qcolorMask) >> 2) + ((C & qcolorMask) >> 2) + ((D & qcolorMask) >> 2) \
-       + ((((A & qlowpixelMask) + (B & qlowpixelMask) + (C & qlowpixelMask) + (D & qlowpixelMask)) >> 2) & qlowpixelMask)
-
-#define GET_COLOR(x) (pal[(x)])
-
-       unsigned char *src_line[4];
-       unsigned char *dst_line[2];
-       int x, y;
-       unsigned long color[16];
-
-       if ( (width<2) || (height<2) ) {
-               Scale2x(src, src_pitch, src_bytes_per_pixel, dst, dst_pitch, dst_bytes_per_pixel, width, height, pal);
-               return;
-       }
-
-       /* Point to the first 3 lines. */
-       src_line[0] = src;
-       src_line[1] = src;
-       src_line[2] = src + src_pitch;
-       src_line[3] = src + (src_pitch * 2);
-       
-       dst_line[0] = dst;
-       dst_line[1] = dst + dst_pitch;
-       
-       x = 0, y = 0;
-       
-       if (src_bytes_per_pixel == 1) {
-               unsigned char *sbp;
-               sbp = src_line[0];
-               color[0] = GET_COLOR(*sbp);       color[1] = color[0];   color[2] = color[0];    color[3] = color[0];
-               color[4] = color[0];   color[5] = color[0];   color[6] = GET_COLOR(*(sbp + 1));  color[7] = GET_COLOR(*(sbp + 2));
-               sbp = src_line[2];
-               color[8] = GET_COLOR(*sbp);     color[9] = color[8];     color[10] = GET_COLOR(*(sbp + 1)); color[11] = GET_COLOR(*(sbp + 2));
-               sbp = src_line[3];
-               color[12] = GET_COLOR(*sbp);    color[13] = color[12];   color[14] = GET_COLOR(*(sbp + 1)); color[15] = GET_COLOR(*(sbp + 2));
-       } else if (src_bytes_per_pixel == 2) {
-               unsigned short *sbp;
-               sbp = (unsigned short*)src_line[0];
-               color[0] = *sbp;       color[1] = color[0];   color[2] = color[0];    color[3] = color[0];
-               color[4] = color[0];   color[5] = color[0];   color[6] = *(sbp + 1);  color[7] = *(sbp + 2);
-               sbp = (unsigned short*)src_line[2];
-               color[8] = *sbp;     color[9] = color[8];     color[10] = *(sbp + 1); color[11] = *(sbp + 2);
-               sbp = (unsigned short*)src_line[3];
-               color[12] = *sbp;    color[13] = color[12];   color[14] = *(sbp + 1); color[15] = *(sbp + 2);
-       } else {
-               unsigned long *lbp;
-               lbp = (unsigned long*)src_line[0];
-               color[0] = *lbp;       color[1] = color[0];   color[2] = color[0];    color[3] = color[0];
-               color[4] = color[0];   color[5] = color[0];   color[6] = *(lbp + 1);  color[7] = *(lbp + 2);
-               lbp = (unsigned long*)src_line[2];
-               color[8] = *lbp;     color[9] = color[8];     color[10] = *(lbp + 1); color[11] = *(lbp + 2);
-               lbp = (unsigned long*)src_line[3];
-               color[12] = *lbp;    color[13] = color[12];   color[14] = *(lbp + 1); color[15] = *(lbp + 2);
-       }
-
-       for (y = 0; y < height; y++) {
-       
-               /* Todo: x = width - 2, x = width - 1 */
-               
-               for (x = 0; x < width; x++) {
-                       unsigned long product1a, product1b, product2a, product2b;
-
-/*
-
-//---------------------------------------  B0 B1 B2 B3    0  1  2  3
-//                                         4  5* 6  S2 -> 4  5* 6  7
-//                                         1  2  3  S1    8  9 10 11
-//                                         A0 A1 A2 A3   12 13 14 15
-//--------------------------------------
-
-*/
-
-                       if (color[9] == color[6] && color[5] != color[10]) {
-                               product2b = color[9];
-                               product1b = product2b;
-                       }
-                       else if (color[5] == color[10] && color[9] != color[6]) {
-                               product2b = color[5];
-                               product1b = product2b;
-                       }
-                       else if (color[5] == color[10] && color[9] == color[6]) {
-                               int r = 0;
-
-                               r += GET_RESULT(color[6], color[5], color[8], color[13]);
-                               r += GET_RESULT(color[6], color[5], color[4], color[1]);
-                               r += GET_RESULT(color[6], color[5], color[14], color[11]);
-                               r += GET_RESULT(color[6], color[5], color[2], color[7]);
-
-                               if (r > 0)
-                                       product1b = color[6];
-                               else if (r < 0)
-                                       product1b = color[5];
-                               else
-                                       product1b = INTERPOLATE(color[5], color[6]);
-                                       
-                               product2b = product1b;
-
-                       }
-                       else {
-                               if (color[6] == color[10] && color[10] == color[13] && color[9] != color[14] && color[10] != color[12])
-                                       product2b = Q_INTERPOLATE(color[10], color[10], color[10], color[9]);
-                               else if (color[5] == color[9] && color[9] == color[14] && color[13] != color[10] && color[9] != color[15])
-                                       product2b = Q_INTERPOLATE(color[9], color[9], color[9], color[10]);
-                               else
-                                       product2b = INTERPOLATE(color[9], color[10]);
-
-                               if (color[6] == color[10] && color[6] == color[1] && color[5] != color[2] && color[6] != color[0])
-                                       product1b = Q_INTERPOLATE(color[6], color[6], color[6], color[5]);
-                               else if (color[5] == color[9] && color[5] == color[2] && color[1] != color[6] && color[5] != color[3])
-                                       product1b = Q_INTERPOLATE(color[6], color[5], color[5], color[5]);
-                               else
-                                       product1b = INTERPOLATE(color[5], color[6]);
-                       }
-
-                       if (color[5] == color[10] && color[9] != color[6] && color[4] == color[5] && color[5] != color[14])
-                               product2a = INTERPOLATE(color[9], color[5]);
-                       else if (color[5] == color[8] && color[6] == color[5] && color[4] != color[9] && color[5] != color[12])
-                               product2a = INTERPOLATE(color[9], color[5]);
-                       else
-                               product2a = color[9];
-
-                       if (color[9] == color[6] && color[5] != color[10] && color[8] == color[9] && color[9] != color[2])
-                               product1a = INTERPOLATE(color[9], color[5]);
-                       else if (color[4] == color[9] && color[10] == color[9] && color[8] != color[5] && color[9] != color[0])
-                               product1a = INTERPOLATE(color[9], color[5]);
-                       else
-                               product1a = color[5];
-       
-                       if (dst_bytes_per_pixel == 2) {
-                               unsigned long tmp;
-                               tmp = SDL_SwapLE16(product1a) | SDL_SwapLE16(product1b) << 16;
-                               *((unsigned long *) (&dst_line[0][x * 4])) = SDL_SwapLE32(tmp);
-                               tmp = SDL_SwapLE16(product2a) | SDL_SwapLE16(product2b) << 16;
-                               *((unsigned long *) (&dst_line[1][x * 4])) = SDL_SwapLE32(tmp);
-                       } else {
-                               *((unsigned long *) (&dst_line[0][x * 8])) = product1a;
-                               *((unsigned long *) (&dst_line[0][x * 8 + 4])) = product1b;
-                               *((unsigned long *) (&dst_line[1][x * 8])) = product2a;
-                               *((unsigned long *) (&dst_line[1][x * 8 + 4])) = product2b;
-                       }
-                       
-                       /* Move color matrix forward */
-                       color[0] = color[1]; color[4] = color[5]; color[8] = color[9];   color[12] = color[13];
-                       color[1] = color[2]; color[5] = color[6]; color[9] = color[10];  color[13] = color[14];
-                       color[2] = color[3]; color[6] = color[7]; color[10] = color[11]; color[14] = color[15];
-                       
-                       if (x < width - 3) {
-                               x+=3;
-                               if (src_bytes_per_pixel == 1) {
-                                       color[3] = GET_COLOR(*(((unsigned char*)src_line[0]) + x));
-                                       color[7] = GET_COLOR(*(((unsigned char*)src_line[1]) + x));
-                                       color[11] = GET_COLOR(*(((unsigned char*)src_line[2]) + x));
-                                       color[15] = GET_COLOR(*(((unsigned char*)src_line[3]) + x));
-                               } else if (src_bytes_per_pixel == 2) {
-                                       color[3] = *(((unsigned short*)src_line[0]) + x);                                       
-                                       color[7] = *(((unsigned short*)src_line[1]) + x);
-                                       color[11] = *(((unsigned short*)src_line[2]) + x);
-                                       color[15] = *(((unsigned short*)src_line[3]) + x);
-                               } else {
-                                       color[3] = *(((unsigned long*)src_line[0]) + x);
-                                       color[7] = *(((unsigned long*)src_line[1]) + x);
-                                       color[11] = *(((unsigned long*)src_line[2]) + x);
-                                       color[15] = *(((unsigned long*)src_line[3]) + x);
-                               }
-                               x-=3;
-                       }
-               }
-
-               /* We're done with one line, so we shift the source lines up */
-               src_line[0] = src_line[1];
-               src_line[1] = src_line[2];
-               src_line[2] = src_line[3];              
-
-               /* Read next line */
-               if (y + 3 >= height)
-                       src_line[3] = src_line[2];
-               else
-                       src_line[3] = src_line[2] + src_pitch;
-                       
-               /* Then shift the color matrix up */
-               if (src_bytes_per_pixel == 1) {
-                       unsigned char *sbp;
-                       sbp = src_line[0];
-                       color[0] = GET_COLOR(*sbp);     color[1] = color[0];    color[2] = GET_COLOR(*(sbp + 1));  color[3] = GET_COLOR(*(sbp + 2));
-                       sbp = src_line[1];
-                       color[4] = GET_COLOR(*sbp);     color[5] = color[4];    color[6] = GET_COLOR(*(sbp + 1));  color[7] = GET_COLOR(*(sbp + 2));
-                       sbp = src_line[2];
-                       color[8] = GET_COLOR(*sbp);     color[9] = color[8];    color[10] = GET_COLOR(*(sbp + 1)); color[11] = GET_COLOR(*(sbp + 2));
-                       sbp = src_line[3];
-                       color[12] = GET_COLOR(*sbp);    color[13] = color[12];  color[14] = GET_COLOR(*(sbp + 1)); color[15] = GET_COLOR(*(sbp + 2));
-               } else if (src_bytes_per_pixel == 2) {
-                       unsigned short *sbp;
-                       sbp = (unsigned short*)src_line[0];
-                       color[0] = *sbp;     color[1] = color[0];    color[2] = *(sbp + 1);  color[3] = *(sbp + 2);
-                       sbp = (unsigned short*)src_line[1];
-                       color[4] = *sbp;     color[5] = color[4];    color[6] = *(sbp + 1);  color[7] = *(sbp + 2);
-                       sbp = (unsigned short*)src_line[2];
-                       color[8] = *sbp;     color[9] = color[9];    color[10] = *(sbp + 1); color[11] = *(sbp + 2);
-                       sbp = (unsigned short*)src_line[3];
-                       color[12] = *sbp;    color[13] = color[12];  color[14] = *(sbp + 1); color[15] = *(sbp + 2);
-               } else {
-                       unsigned long *lbp;
-                       lbp = (unsigned long*)src_line[0];
-                       color[0] = *lbp;     color[1] = color[0];    color[2] = *(lbp + 1);  color[3] = *(lbp + 2);
-                       lbp = (unsigned long*)src_line[1];
-                       color[4] = *lbp;     color[5] = color[4];    color[6] = *(lbp + 1);  color[7] = *(lbp + 2);
-                       lbp = (unsigned long*)src_line[2];
-                       color[8] = *lbp;     color[9] = color[9];    color[10] = *(lbp + 1); color[11] = *(lbp + 2);
-                       lbp = (unsigned long*)src_line[3];
-                       color[12] = *lbp;    color[13] = color[12];  color[14] = *(lbp + 1); color[15] = *(lbp + 2);
-               }
-               
-               if (y < height - 1) {
-                       dst_line[0] += dst_pitch * 2;
-                       dst_line[1] += dst_pitch * 2;
-               }
-       }
+       *(unsigned char *)get_vgaptr(page, x, y) = color;
 }
 
 
@@ -705,11 +335,6 @@ void flippage(int page)
 
                return;
        }
-#ifdef SCALE_UP
-        dest=(unsigned char *)jnb_surface->pixels;
-       src=screen_buffer[page];
-       Super2xSaI(src, JNB_WIDTH, 1, dest, jnb_surface->pitch, 2, JNB_WIDTH, JNB_HEIGHT, current_pal);
-#else
        dest=(unsigned char *)jnb_surface->pixels;
        src=screen_buffer[page];
        for (y=0; y<screen_height; y++) {
@@ -724,15 +349,14 @@ void flippage(int page)
                                test_x++;
                        }
                        if (count) {
-                               memcpy( &dest[y*jnb_surface->pitch+(x<<dirty_block_shift)*bytes_per_pixel],
-                                       &src[y*screen_pitch+((x<<dirty_block_shift)*bytes_per_pixel)],
-                                       ((16<<dirty_block_shift)>>4)*bytes_per_pixel*count);
+                               memcpy( &dest[y*jnb_surface->pitch+(x<<dirty_block_shift)],
+                                       &src[y*screen_pitch+((x<<dirty_block_shift))],
+                                       ((16<<dirty_block_shift)>>4)*count);
                        }
                        x = test_x;
                }
        }
        memset(&dirty_blocks[page], 0, sizeof(int)*25*16);
-#endif
         SDL_UnlockSurface(jnb_surface);
        SDL_Flip(jnb_surface);
 }
@@ -775,10 +399,8 @@ void setpalette(int index, int count, char *palette)
                colors[i+index].r = palette[i * 3 + 0] << 2;
                colors[i+index].g = palette[i * 3 + 1] << 2;
                colors[i+index].b = palette[i * 3 + 2] << 2;
-               current_pal[i+index] = SDL_MapRGB(jnb_surface->format, colors[i+index].r, colors[i+index].g, colors[i+index].b);
        }
-       if (!scale_up)
-               SDL_SetColors(jnb_surface, &colors[index], index, count);
+       SDL_SetColors(jnb_surface, &colors[index], index, count);
 }
 
 
@@ -793,10 +415,8 @@ void fillpalette(int red, int green, int blue)
                colors[i].r = red << 2;
                colors[i].g = green << 2;
                colors[i].b = blue << 2;
-               current_pal[i] = SDL_MapRGB(jnb_surface->format, colors[i].r, colors[i].g, colors[i].b);
        }
-       if (!scale_up)
-               SDL_SetColors(jnb_surface, colors, 0, 256);
+       SDL_SetColors(jnb_surface, colors, 0, 256);
 }
 
 
@@ -830,9 +450,9 @@ void get_block(int page, int x, int y, int width, int height, void *buffer)
        vga_ptr = get_vgaptr(page, x, y);
        buffer_ptr = buffer;
        for (h = 0; h < height; h++) {
-               memcpy(buffer_ptr, vga_ptr, width * bytes_per_pixel);
+               memcpy(buffer_ptr, vga_ptr, width);
                vga_ptr += screen_pitch;
-               buffer_ptr += width * bytes_per_pixel;
+               buffer_ptr += width;
        }
 
 }
@@ -868,9 +488,9 @@ void put_block(int page, int x, int y, int width, int height, void *buffer)
        vga_ptr = get_vgaptr(page, x, y);
        buffer_ptr = buffer;
        for (h = 0; h < height; h++) {
-               memcpy(vga_ptr, buffer_ptr, width * bytes_per_pixel);
+               memcpy(vga_ptr, buffer_ptr, width);
                vga_ptr += screen_pitch;
-               buffer_ptr += width * bytes_per_pixel;
+               buffer_ptr += width;
        }
        width = ((x+width)>>dirty_block_shift) - (x>>dirty_block_shift) + 1;
        height = ((y+height)>>dirty_block_shift) - (y>>dirty_block_shift) + 1;
@@ -1021,6 +641,9 @@ void put_pob(int page, int x, int y, int image, gob_t *gob, int use_mask, void *
        int width, height;
        int draw_width, draw_height;
        int colour;
+       unsigned char *vga_ptr;
+       unsigned char *pob_ptr;
+       unsigned char *mask_ptr;
 
        assert(drawing_enable==1);
        assert(gob);
@@ -1063,82 +686,25 @@ void put_pob(int page, int x, int y, int image, gob_t *gob, int use_mask, void *
        if ((y + height) > screen_height)
                draw_height -= y + height - screen_height;
 
-
-       if (bytes_per_pixel==1) {
-               unsigned char *vga_ptr;
-               unsigned char *pob_ptr;
-               unsigned char *mask_ptr;
-
-               vga_ptr = get_vgaptr(page, x, y);
-               pob_ptr = ((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x);
-               mask_ptr = ((unsigned char *)mask) + ((y * screen_pitch) + (x*bytes_per_pixel));
-               for (c1 = 0; c1 < draw_height; c1++) {
-                       for (c2 = 0; c2 < draw_width; c2++) {
-                               colour = *mask_ptr;
-                               if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
-                                       colour = *pob_ptr;
-                                       if (colour != 0) {
-                                               *vga_ptr = colour;
-                                       }
-                               }
-                               vga_ptr++;
-                               pob_ptr++;
-                               mask_ptr++;
-                       }
-                       pob_ptr += width - c2;
-                       vga_ptr += (screen_width - c2);
-                       mask_ptr += (screen_width - c2);
-               }
-       } else if (bytes_per_pixel==2) {
-               unsigned short *vga_ptr;
-               unsigned short *pob_ptr;
-               unsigned short *mask_ptr;
-
-               vga_ptr = get_vgaptr(page, x, y);
-               pob_ptr = (unsigned short *)(((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x));
-               mask_ptr = (unsigned short *)(((unsigned char *)mask) + ((y * screen_pitch) + (x*bytes_per_pixel)));
-               for (c1 = 0; c1 < draw_height; c1++) {
-                       for (c2 = 0; c2 < draw_width; c2++) {
-                               colour = *mask_ptr;
-                               if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
-                                       colour = *pob_ptr;
-                                       if (colour != 0) {
-                                               *vga_ptr = colour;
-                                       }
-                               }
-                               vga_ptr++;
-                               pob_ptr++;
-                               mask_ptr++;
-                       }
-                       pob_ptr += width - c2;
-                       vga_ptr += (screen_width - c2);
-                       mask_ptr += (screen_width - c2);
-               }
-       } else {
-               unsigned int *vga_ptr;
-               unsigned int *pob_ptr;
-               unsigned int *mask_ptr;
-
-               vga_ptr = get_vgaptr(page, x, y);
-               pob_ptr = (unsigned int *)(((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x));
-               mask_ptr = (unsigned int *)(((unsigned char *)mask) + ((y * screen_pitch) + (x*bytes_per_pixel)));
-               for (c1 = 0; c1 < draw_height; c1++) {
-                       for (c2 = 0; c2 < draw_width; c2++) {
-                               colour = *mask_ptr;
-                               if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
-                                       colour = *pob_ptr;
-                                       if (colour != 0) {
-                                               *vga_ptr = colour;
-                                       }
+       vga_ptr = get_vgaptr(page, x, y);
+       pob_ptr = ((unsigned char *)gob->data[image]) + ((pob_y * width) + pob_x);
+       mask_ptr = ((unsigned char *)mask) + ((y * screen_pitch) + (x));
+       for (c1 = 0; c1 < draw_height; c1++) {
+               for (c2 = 0; c2 < draw_width; c2++) {
+                       colour = *mask_ptr;
+                       if (use_mask == 0 || (use_mask == 1 && colour == 0)) {
+                               colour = *pob_ptr;
+                               if (colour != 0) {
+                                       *vga_ptr = colour;
                                }
-                               vga_ptr++;
-                               pob_ptr++;
-                               mask_ptr++;
                        }
-                       pob_ptr += width - c2;
-                       vga_ptr += (screen_width - c2);
-                       mask_ptr += (screen_width - c2);
+                       vga_ptr++;
+                       pob_ptr++;
+                       mask_ptr++;
                }
+               pob_ptr += width - c2;
+               vga_ptr += (screen_width - c2);
+               mask_ptr += (screen_width - c2);
        }
        draw_width = ((x+draw_width)>>dirty_block_shift) - (x>>dirty_block_shift) + 1;
        draw_height = ((y+draw_height)>>dirty_block_shift) - (y>>dirty_block_shift) + 1;
@@ -1226,15 +792,9 @@ void register_background(char *pixels, char pal[768])
                return;
        assert(pal);
        if (scale_up) {
-               int int_pal[256];
-               int i;
-
-               for (i=0; i<256; i++)
-                       int_pal[i] = SDL_MapRGB(jnb_surface->format, (Uint8)(pal[i*3+0]<<2), (Uint8)(pal[i*3+1]<<2), (Uint8)(pal[i*3+2]<<2));
                background = malloc(screen_pitch*screen_height);
                assert(background);
-               Init_2xSaI(565);
-               Super2xSaI((unsigned char *)pixels, JNB_WIDTH, 1, (unsigned char *)background, screen_pitch, bytes_per_pixel, JNB_WIDTH, JNB_HEIGHT, int_pal);
+               do_scale2x((unsigned char *)pixels, JNB_WIDTH, JNB_HEIGHT, (unsigned char *)background);
        } else {
                background = malloc(JNB_WIDTH*JNB_HEIGHT);
                assert(background);
@@ -1273,8 +833,9 @@ int register_gob(unsigned char *handle, gob_t *gob, int len)
                gob->orig_data[i] = malloc(image_size);
                memcpy(gob->orig_data[i], &gob_data[offset], image_size);
                if (scale_up) {
-                       image_size = gob->width[i] * gob->height[i] * 4 * bytes_per_pixel;
+                       image_size = gob->width[i] * gob->height[i] * 4;
                        gob->data[i] = malloc(image_size);
+                       do_scale2x((unsigned char *)gob->orig_data[i], gob->width[i], gob->height[i], (unsigned char *)gob->data[i]);
                } else {
                        gob->data[i] = (unsigned short *)gob->orig_data[i];
                }
@@ -1286,24 +847,6 @@ int register_gob(unsigned char *handle, gob_t *gob, int len)
 
 void recalculate_gob(gob_t *gob, char pal[768])
 {
-       int int_pal[256];
-       int i;
-
-       if (!scale_up)
-               return;
-
-       Init_2xSaI(565);
-
-       for (i=1; i<256; i++) {
-               int_pal[i] = SDL_MapRGB(jnb_surface->format, (Uint8)(pal[i*3+0]<<2), (Uint8)(pal[i*3+1]<<2), (Uint8)(pal[i*3+2]<<2));
-               if (int_pal[i] == 0)
-                       int_pal[i] = SDL_MapRGB(jnb_surface->format, 8, 8, 8);
-       }
-       int_pal[0] = 0;
-
-       for (i=0; i<gob->num_images; i++) {
-               Super2xSaI(gob->orig_data[i], gob->width[i], 1, (unsigned char *)gob->data[i], gob->width[i]*2*bytes_per_pixel, bytes_per_pixel, gob->width[i], gob->height[i], int_pal);
-       }
 }
 
 void register_mask(void *pixels)
@@ -1314,16 +857,9 @@ void register_mask(void *pixels)
        }
        assert(pixels);
        if (scale_up) {
-               int int_pal[256];
-               int i;
-
-               int_pal[0] = 0;
-               for (i=1; i<256; i++)
-                       int_pal[i] = 0xffffffff;
                mask = malloc(screen_pitch*screen_height);
                assert(mask);
-               Init_2xSaI(565);
-               Scale2x(pixels, JNB_WIDTH, 1, (unsigned char *)mask, screen_pitch, bytes_per_pixel, JNB_WIDTH, JNB_HEIGHT, int_pal);
+               do_scale2x((unsigned char *)pixels, JNB_WIDTH, JNB_HEIGHT, (unsigned char *)mask);
        } else {
                mask = malloc(JNB_WIDTH*JNB_HEIGHT);
                assert(mask);