diff --git a/tools/decoupe-voiture/dub.json b/tools/decoupe-voiture/dub.json index 5c0bfd8..4808da8 100644 --- a/tools/decoupe-voiture/dub.json +++ b/tools/decoupe-voiture/dub.json @@ -5,7 +5,8 @@ "dependencies": { - "gamut": "~>3.0" + "gamut": "~>3.0", + "expression-plus": "~>1.0" }, "subConfigurations": diff --git a/tools/decoupe-voiture/patterns/classic_complete_48x48.json b/tools/decoupe-voiture/patterns/classic_complete_48x48.json index 1cd5a37..e839f6f 100644 --- a/tools/decoupe-voiture/patterns/classic_complete_48x48.json +++ b/tools/decoupe-voiture/patterns/classic_complete_48x48.json @@ -2,12 +2,16 @@ "input-size": "3984x2160", "output-size": "3456x960", - "default-size": "48x48", + "default-size": "288x240", "copyRects": [ - { "from": "0,0-48x48", "to": "0,0" }, - { "from": "0,0-48x48", "to": "0,0" } + { "from": "62+240*0,224-(240-62)x168", "to": "288*0,0" }, + { "from": "62+240*1,224-(240-62)x168", "to": "288*1,0" }, + { "from": "62+240*1,224-(240-62)x168", "to": "288*2,0" }, + { "from": "62+240*1,224-(240-62)x168", "to": "288*3,0" }, + { "from": "62+240*1,224-(240-62)x168", "to": "288*4,0" }, + { "from": "62+240*1,224-(240-62)x168", "to": "288*5,0" } ] } \ No newline at end of file diff --git a/tools/decoupe-voiture/source/main.d b/tools/decoupe-voiture/source/main.d index 635f0b2..3db23bf 100644 --- a/tools/decoupe-voiture/source/main.d +++ b/tools/decoupe-voiture/source/main.d @@ -6,7 +6,7 @@ import std.file; import std.conv; import std.string; import gamut; - +import expression; void usage() { @@ -109,9 +109,10 @@ void processFile(string inputPath, string outputPath, string pattern) input.convertTo(PixelType.rgba8); + Size defaultSize = parseSize(patternFile, "default-size", Size(16, 16)); - Size inputSize = parseSize(patternFile, "input-size"); - Size outputSize = parseSize(patternFile, "output-size"); + Size inputSize = parseSize(patternFile, "input-size", defaultSize); + Size outputSize = parseSize(patternFile, "output-size", defaultSize); if (inputSize.w != input.width || inputSize.h != input.height) throw new Exception("input size mismatch"); @@ -119,7 +120,6 @@ void processFile(string inputPath, string outputPath, string pattern) Image output; output.create(outputSize.w, outputSize.h, PixelType.rgba8); - Size defaultSize = parseSize(patternFile, "default-size"); void copyRect(Rect src, Rect dst) { @@ -194,36 +194,36 @@ void rectInsideImage(ref Image i, Rect r) throw new Exception("Rectangle exceeds height of image"); } -Point parsePoint(JSONValue parent, string keyName) +Point parsePoint(JSONValue parent, string keyName, Size defaultSize) { string r = parent[keyName].str; - return parsePoint(r); + return parsePoint(r, defaultSize); } -Point parsePoint(string r) +Point parsePoint(string r, Size defaultSize) { r = strip(r); int cPos = cast(int) r.indexOf(","); if (cPos == -1) throw new Exception("Point should follow this in format: 4,5"); - int x = to!int(r[0..cPos]); - int y = to!int(r[cPos+1..$]); + int x = parseIntegerExpression(r[0..cPos], defaultSize); + int y = parseIntegerExpression(r[cPos+1..$], defaultSize); return Point(x, y); } -Size parseSize(JSONValue parent, string keyName) +Size parseSize(JSONValue parent, string keyName, Size defaultSize) { - return parseSize(parent[keyName].str); + return parseSize(parent[keyName].str, defaultSize); } -Size parseSize(string r) +Size parseSize(string r, Size defaultSize) { r = strip(r); int xPos = cast(int) r.indexOf("x"); if (xPos == -1) throw new Exception("Size should follow this in format: 48x48"); - int w = to!int(r[0..xPos]); - int h = to!int(r[xPos+1..$]); + int w = parseIntegerExpression(r[0..xPos], defaultSize); + int h = parseIntegerExpression(r[xPos+1..$], defaultSize); return Size(w, h); } @@ -245,16 +245,23 @@ Rect parseRect(string r, Size defaultSize) if (mPos == -1) { - pos = parsePoint(r); + pos = parsePoint(r, defaultSize); size = defaultSize; } else { - pos = parsePoint(r[0..mPos]); - size = parseSize(r[mPos+1..$]); + pos = parsePoint(r[0..mPos], defaultSize); + size = parseSize(r[mPos+1..$], defaultSize); } return Rect(pos, size); } - \ No newline at end of file +int parseIntegerExpression(string source, + Size defaultSize) +{ + auto e = compileExpression!int(source); + //e["TX"] = defaultSize.w; + //e["TY"] = defaultSize.h; + return e(); +} \ No newline at end of file