Mercurial > hg > forks > multipaint-js
diff exporters.pde @ 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 | dffafe05d520 |
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