From 6731f75e9c48a925e8f366948eaef480ffc7a732 Mon Sep 17 00:00:00 2001 From: Ketmar Dark Date: Sat, 23 Apr 2016 14:45:41 +0300 Subject: [PATCH] added "vga2png" converter --- vga2png.d | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ xmain_d2d.d | 2 +- 2 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 vga2png.d diff --git a/vga2png.d b/vga2png.d new file mode 100644 index 0000000..290b70f --- /dev/null +++ b/vga2png.d @@ -0,0 +1,86 @@ +/* DooM2D: Midnight on the Firing Line + * coded by Ketmar // Invisible Vector + * Understanding is not required. Only obedience. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +module vga2png is aliced; + +private: +import iv.glbinds; +import glutils; +import console; +import wadarc; + +import iv.vfs; + +import d2dimage; + + +// ////////////////////////////////////////////////////////////////////////// // +import arsd.color; +import arsd.png; + + +// ////////////////////////////////////////////////////////////////////////// // +int main (string[] args) { + if (args.length < 2 || args.length > 3) { + conwriteln("usage: vga2png infile.vga [outfile.png]"); + return -1; + } + + string ifname = args[1]; + string ofname; + if (args.length == 3) { + ofname = args[3]; + } else { + import std.algorithm : endsWith; + if (ifname.endsWith(".vga")) { + ofname = ifname[0..$-4]~".png"; + } else { + ofname = ifname~".png"; + } + } + + if (ifname.length == 0) { + conwriteln("image name?"); + return -1; + } + if (ifname[0] != '/') ifname = "./"~ifname; + + static void setDP () { + /*version(rdmd) { + setDataPath("data"); + } else*/ { + import std.file : thisExePath; + import std.path : dirName; + setDataPath(thisExePath.dirName~"/data"); + } + addPak(getDataPath~"base.pk3"); + } + + setDP(); + + try { + loadD2DPalette(); + auto img = new D2DImage(ifname); + conwriteln("writing image '", ofname, "'"); + img.savePng(ofname); + } catch (Exception e) { + import std.stdio : stderr; + stderr.writeln("FUUUUUUUUUUUU\n", e.toString); + return -1; + } + return 0; +} diff --git a/xmain_d2d.d b/xmain_d2d.d index cb90f5a..8ffff06 100644 --- a/xmain_d2d.d +++ b/xmain_d2d.d @@ -98,7 +98,7 @@ void main (string[] args) { } else { import std.file : thisExePath; import std.path : dirName; - setDataPath(thisExePath.dirName); + setDataPath(thisExePath.dirName~"/data"); } addPak(getDataPath~"base.pk3"); registerWadScripts(); //addWad("/home/ketmar/k8prj/doom2d-tl/data/doom2d.wad"); registerWadScripts(); -- 2.11.4.GIT