shithub: choc

Download patch

ref: 308905898ebf7fea415e8e01ed2cb88baba4f69b
parent: a9cf8ba9c229eca57a91a85502946f5bb7a47f07
author: Fabian Greffrath <[email protected]>
date: Sun Oct 8 07:08:57 EDT 2017

video: simplify PNG screenshot code

Only one check for aspect_ratio_correct, same code path for both
choices.

--- a/src/v_video.c
+++ b/src/v_video.c
@@ -725,7 +725,7 @@
 }
 
 void WritePNGfile(char *filename, byte *data,
-                  int inwidth, int inheight,
+                  int width, int height,
                   byte *palette)
 {
     png_structp ppng;
@@ -733,19 +733,22 @@
     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 @@
 
     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);
             }
         }