foxygit / doom Log in
commit 308905898ebf7fea415e8e01ed2cb88baba4f69b
Author:     Fabian Greffrath <fabian@greffrath.com>
AuthorDate: Sun Oct 8 11:08:57 2017 +0200
Commit:     Fabian Greffrath <fabian@greffrath.com>
CommitDate: Sun Oct 8 11:08:57 2017 +0200

    video: simplify PNG screenshot code

    Only one check for aspect_ratio_correct, same code path for both
    choices.
---
 src/v_video.c | 44 ++++++++++++++++----------------------------
 1 file changed, 16 insertions(+), 28 deletions(-)

diff --git a/src/v_video.c b/src/v_video.c
index 14e8adc7..55be9964 100644
--- a/src/v_video.c
+++ b/src/v_video.c
@@ -725,7 +725,7 @@ static void warning_fn(png_structp p, png_const_charp s)
 }

 void WritePNGfile(char *filename, byte *data,
-                  int inwidth, int inheight,
+                  int width, int height,
                   byte *palette)
 {
     png_structp ppng;
@@ -733,19 +733,22 @@ void WritePNGfile(char *filename, byte *data,
     png_colorp pcolor;
     FILE *handle;
     int i, j;
-    int width, height;
+    int w_factor, h_factor;
     byte *rowbuf;

     if (aspect_ratio_correct)
     {
         // scale up to accommodate aspect ratio correction
-        width = inwidth * 5;
-        height = inheight * 6;
+        w_factor = 5;
+        h_factor = 6;
+
+        width *= w_factor;
+        height *= h_factor;
     }
     else
     {
-        width = inwidth;
-        height = inheight;
+        w_factor = 1;
+        h_factor = 1;
     }

     handle = fopen(filename, "wb");
@@ -800,32 +803,17 @@ void WritePNGfile(char *filename, byte *data,

     if (rowbuf)
     {
-        if (aspect_ratio_correct)
+        for (i = 0; i < SCREENHEIGHT; i++)
         {
-            for (i = 0; i < SCREENHEIGHT; i++)
+            // expand the row 5x
+            for (j = 0; j < SCREENWIDTH; j++)
             {
-                // expand the row 5x
-                for (j = 0; j < SCREENWIDTH; j++)
-                {
-                    memset(rowbuf + j * 5, *(data + i*SCREENWIDTH + j), 5);
-                }
-
-                // write the row 6 times
-                for (j = 0; j < 6; j++)
-                {
-                    png_write_row(ppng, rowbuf);
-                }
+                memset(rowbuf + j * w_factor, *(data + i*SCREENWIDTH + j), w_factor);
             }
-        }
-        else
-        {
-            for (i = 0; i < SCREENHEIGHT; i++)
-            {
-                for (j = 0; j < SCREENWIDTH; j++)
-                {
-                    memset(rowbuf + j, *(data + i*SCREENWIDTH + j), 1);
-                }

+            // write the row 6 times
+            for (j = 0; j < h_factor; j++)
+            {
                 png_write_row(ppng, rowbuf);
             }
         }