Use independent width and height scaling
authorBill Lash <william.lash@gmail.com>
Wed, 2 Oct 2019 01:25:08 +0000 (20:25 -0500)
committerBill Lash <william.lash@gmail.com>
Wed, 2 Oct 2019 01:25:08 +0000 (20:25 -0500)
Calculate independent width and height scaling by a floating point
value based on the -W and -H options in sdl interface

src/sdl/sf_frotz.h
src/sdl/sf_resource.c
src/sdl/sf_video.c

index b2c7305893ff5e8fb06f19139c3b4600a7dbc046..0ebea9d3cab53a055d976715f148278c362c66e6 100644 (file)
@@ -54,7 +54,8 @@ int colour_in_use(zword colour);
 /*  various data */
 extern bool m_tandy;
 extern int m_v6scale;
-extern int m_gfxScale;
+extern double m_gfxScale_w;
+extern double m_gfxScale_h;
 extern ulong m_defaultFore;
 extern ulong m_defaultBack;
 extern ulong m_colours[11];
index 9b50b5bf55cbc5d463f2c6d98a981134ae875503..235db348fbd5b501b85ef24a647c982fe85abb46 100644 (file)
@@ -23,7 +23,8 @@ z_header_t z_header;
 /* various data */
 bool m_tandy = 0;
 int m_v6scale;
-int m_gfxScale = 1;
+double m_gfxScale_w = 1.0;
+double m_gfxScale_h = 1.0;
 ulong m_defaultFore;
 ulong m_defaultBack;
 ulong m_colours[11];
@@ -289,8 +290,8 @@ int os_picture_data(int picture, int *height, int *width)
                } else {
                        sf_picture *res = sf_getpic(picture);
                        if (res) {
-                               *height = m_gfxScale * res->height;
-                               *width = m_gfxScale * res->width;
+                               *height = m_gfxScale_h * res->height;
+                               *width = m_gfxScale_w * res->width;
                                return 1;
                        }
                }
@@ -489,7 +490,8 @@ void sf_readsettings(void)
 
        m_frequency = sf_GetProfileInt("Audio", "Frequency", m_frequency);
        m_v6scale = sf_GetProfileInt("Display", "Infocom V6 Scaling", 2);
-       m_gfxScale = 1;
+       m_gfxScale_w = 1.0;
+       m_gfxScale_h = 1.0;
        m_defaultFore = (sf_GetProfileInt("Display", "Foreground", 0xffffff));
        m_defaultBack = (sf_GetProfileInt("Display", "Background", 0x800000));
        m_morePrompts =
@@ -669,10 +671,15 @@ void os_init_screen(void)
        sf_initvideo(AcWidth, AcHeight, (m_fullscreen != -1));
 
        /* Set the graphics scaling */
-       if (sf_IsInfocomV6() || (story_id == BEYOND_ZORK))
-               m_gfxScale = m_v6scale;
-       else
-               m_gfxScale = 1;
+       if (sf_IsInfocomV6() || (story_id == BEYOND_ZORK)) {
+               m_gfxScale_w = (double)m_v6scale;
+               m_gfxScale_h = (double)m_v6scale;
+       } else {
+               m_gfxScale_w = 1.0;
+               m_gfxScale_h = 1.0;
+       }
+       m_gfxScale_w *= (double) AcWidth /640.0;
+       m_gfxScale_h *= (double) AcHeight /400.0;
 
        /* Set the configuration */
        if (z_header.version == V3) {
index f1509e8485391bfa2aeaaa8c875d88f9ed86d58a..2d47520e2aa787c273b8f95c786b94963b2aab40 100644 (file)
@@ -549,8 +549,8 @@ void os_draw_picture(int picture, int y, int x)
 
        x--;
        y--;
-       ew = m_gfxScale * pic->width;
-       eh = m_gfxScale * pic->height;
+       ew = m_gfxScale_w * pic->width;
+       eh = m_gfxScale_h * pic->height;
 
        /* this takes care of the fact that x, y are really 16 bit values */
        if (x & 0x8000)
@@ -574,7 +574,7 @@ void os_draw_picture(int picture, int y, int x)
        }
        if (x + ew > xmax)
                ew = xmax - x;
-       ew /= m_gfxScale;
+       ew /= m_gfxScale_w;
 
        if (y < ymin) {
                d = ymin - y;
@@ -584,7 +584,7 @@ void os_draw_picture(int picture, int y, int x)
        }
        if (y + eh > ymax)
                eh = ymax - y;
-       eh /= m_gfxScale;
+       eh /= m_gfxScale_h;
 
        sf_setclip(ox, oy, ow, oh);
 
@@ -599,10 +599,10 @@ void os_draw_picture(int picture, int y, int x)
                if (!pic->adaptive && ApplyPalette(pic))
                        sf_flushdisplay();
 
-               for (yy = 0; yy < eh * m_gfxScale; yy++) {
-                       int ys = yy / m_gfxScale;
-                       for (xx = 0; xx < ew * m_gfxScale; xx++) {
-                               int xs = xx / m_gfxScale;
+               for (yy = 0; yy < eh * m_gfxScale_h; yy++) {
+                       int ys = yy / m_gfxScale_h;
+                       for (xx = 0; xx < ew * m_gfxScale_w; xx++) {
+                               int xs = xx / m_gfxScale_w;
                                int index = pic->pixels[ys * pic->width + xs];
                                if (index != pic->transparentcolor)
                                        sf_wpixel(x + xx, y + yy,
@@ -616,8 +616,8 @@ void os_draw_picture(int picture, int y, int x)
                for (yy = 0; yy < eh; yy++) {
                        for (xx = 0; xx < ew; xx++) {
                                dst =
-                                   sbuffer + x + xx * m_gfxScale +
-                                   sbpitch * (y + yy * m_gfxScale);
+                                   sbuffer + x + (uint32_t)(xx * m_gfxScale_w) +
+                                   sbpitch * (y + (uint32_t)(yy * m_gfxScale_h));
                                sval = src[xx];
                                alpha = (sval >> 24);
                                if (alpha == 255)
@@ -627,8 +627,8 @@ void os_draw_picture(int picture, int y, int x)
                                            sf_blend((int)
                                                     (alpha + (alpha >> 7)),
                                                     sval, dst[0]);
-                               for (iy = 0; iy < m_gfxScale; iy++) {
-                                       for (ix = 0; ix < m_gfxScale; ix++)
+                               for (iy = 0; iy < m_gfxScale_h; iy++) {
+                                       for (ix = 0; ix < m_gfxScale_w; ix++)
                                                dst[ix] = dval;
                                        dst += sbpitch;
                                }