changeset 88:03823fa2cb01

Refactor export_image() and export_image_sans_border() to use common code, and also rename them to mpRenderImageWithBorder() and mpRenderImageWithoutBorder().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Jul 2018 00:23:23 +0300
parents 8dd5146c881f
children 09c1a4aba305
files exporters.pde multipaint.pde
diffstat 2 files changed, 60 insertions(+), 72 deletions(-) [+]
line wrap: on
line diff
--- a/exporters.pde	Fri Jul 06 00:19:38 2018 +0300
+++ b/exporters.pde	Fri Jul 06 00:23:23 2018 +0300
@@ -1157,83 +1157,73 @@
 
 }
 
-void export_image(String name) {
+
+void mpRenderToImageAt(PImage output, int xoffs, int yoffs)
+{
+    if (output == null)
+        return;
+
+    for (int yy = 0; yy < output.width; yy++)
+    for (int xx = 0; xx < output.width; xx++)
+    {
+        color c = color(g_r[259], g_g[259], g_b[259]);
+        output.set(xx, yy, c);
+    }
+
+    for (int yy = 0; yy < Y; yy++)
+    for (int xx = 0; xx < X; xx++)
+    {
+        int f;
+        if (g_multic == 1 || g_hzoomer == 2)
+            f = getmultic(chop2(xx), yy, 0);
+        else
+            f = getabsa(xx, yy, 0);
+
+        if (machine == MSX && f == 0)
+            f = g_map[1];
+
+        color c = color(g_r[f], g_g[f], g_b[f]);
+
+        for (int vertti = 0; vertti <= g_omag; vertti++)
+        for (int mortti = 0; mortti <= g_omag; mortti++)
+        {
+            output.set(
+                xx * g_omag + xoffs + mortti,
+                yy * g_omag + yoffs + vertti,
+                c);
+        }
+    }
+}
+
+
+PImage mpRenderImageWithBorder()
+{
     //output the visible graphics as image
     //with border
     //processing style
-    int xx, yy, f, x2;
-    color c;
-    for (xx = 0; xx < output.width; xx++) {
-        for (yy = 0; yy < output.width; yy++) {
-            c = color(g_r[259], g_g[259], g_b[259]);
-            output.set(xx, yy, c);
-        }
-    }
+    PImage output = createImage(
+        X * g_omag + g_bordh * g_omag,
+        Y * g_omag + g_bordv * g_omag,
+        RGB);
 
-    for (xx = 0; xx < X; xx++) {
-        for (yy = 0; yy < Y; yy++) {
-            x2 = xx;
-            f = getabsa(x2, yy, 0);
-            if (g_multic == 1 || g_hzoomer == 2) {
-                x2 = xx / 2;
-                x2 = x2 * 2;
-                f = getmultic(x2, yy, 0);
-            }
-            if (machine == MSX) {
-                if (f == 0) {
-                    f = g_map[1];
-                }
-            }
-            c = color(g_r[f], g_g[f], g_b[f]);
-            for (int vertti = 0; vertti <= g_omag; vertti++) {
-                for (int mortti = 0; mortti <= g_omag; mortti++) {
-                    output.set((g_bordh * g_omag) / 2 + xx * g_omag + mortti, (g_bordv * g_omag) / 2 + yy * g_omag + vertti, c);
-                }
-            }
-        }
-    }
-    output.save(name);
+    mpRenderToImageAt(output, int((g_bordh * g_omag) / 2), int((g_bordv * g_omag) / 2));
+
+    return output;
 }
 
-void export_image_sans_border(String name) {
+
+PImage mpRenderImageWithoutBorder()
+{
     //output the visible graphics as image
     //processing style
     //without border
-    int xx, yy, f, x2;
-    color c;
+    PImage output = createImage(X * g_omag, Y * g_omag, RGB);
 
-    for (xx = 0; xx < outputsans.width; xx++) {
-        for (yy = 0; yy < outputsans.width; yy++) {
-            c = color(g_r[259], g_g[259], g_b[259]);
-            outputsans.set(xx, yy, c);
-        }
-    }
+    mpRenderToImageAt(output, 0, 0);
 
-    for (xx = 0; xx < X; xx++) {
-        for (yy = 0; yy < Y; yy++) {
-            x2 = xx;
-            f = getabsa(x2, yy, 0);
-            if (g_multic == 1 || g_hzoomer == 2) {
-                x2 = xx / 2;
-                x2 = x2 * 2;
-                f = getmultic(x2, yy, 0);
-            }
+    return output;
+}
 
-            if (machine == MSX) {
-                if (f == 0) {
-                    f = g_map[1];
-                }
-            }
-            c = color(g_r[f], g_g[f], g_b[f]);
-            for (int vertti = 0; vertti <= g_omag; vertti++) {
-                for (int mortti = 0; mortti <= g_omag; mortti++) {
-                    outputsans.set(xx * g_omag + mortti, yy * g_omag + vertti, c);
-                }
-            }
-        }
-    }
-    outputsans.save(name);
-}
 
 void make_c64_palette() {
     // Pepto's murky C64 palette: http://www.pepto.de/projects/colorvic
--- a/multipaint.pde	Fri Jul 06 00:19:38 2018 +0300
+++ b/multipaint.pde	Fri Jul 06 00:23:23 2018 +0300
@@ -61,8 +61,6 @@
 
 
 byte g_realfront, g_realback;
-PImage output, outputsans;
-String g_name;
 
 
 //dimensions
@@ -188,9 +186,6 @@
     g_realfront = byte(g_farge);
     g_realback = byte(g_backg);
 
-    output = createImage(X * g_omag + g_bordh * g_omag, Y * g_omag + g_bordv * g_omag, RGB);
-    outputsans = createImage(X * g_omag, Y * g_omag, RGB);
-
     for (int y = 0; y < Y; y++)
     for (int x = 0; x < X; x++)
         absolute_clearpoint(x, y);
@@ -318,10 +313,13 @@
 
 void mpSavePNGImage(String name)
 {
+    PImage simg;
     if (g_data[int('Q')] == 0)
-        export_image_sans_border(name);
+        simg = mpRenderImageWithoutBorder();
     else
-        export_image(name);
+        simg = mpRenderImageWithBorder();
+
+    // XXX TODO .. actually save the image
 }