# HG changeset patch # User Matti Hamalainen # Date 1530825803 -10800 # Node ID 03823fa2cb01b4e3639107c34e4a6da28f7df0a5 # Parent 8dd5146c881f6d4794518c3d850d6ae4628875fb Refactor export_image() and export_image_sans_border() to use common code, and also rename them to mpRenderImageWithBorder() and mpRenderImageWithoutBorder(). diff -r 8dd5146c881f -r 03823fa2cb01 exporters.pde --- 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 diff -r 8dd5146c881f -r 03823fa2cb01 multipaint.pde --- 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 }