Need expression parser else intractable
This commit is contained in:
@@ -5,7 +5,8 @@
|
|||||||
|
|
||||||
"dependencies":
|
"dependencies":
|
||||||
{
|
{
|
||||||
"gamut": "~>3.0"
|
"gamut": "~>3.0",
|
||||||
|
"expression-plus": "~>1.0"
|
||||||
},
|
},
|
||||||
|
|
||||||
"subConfigurations":
|
"subConfigurations":
|
||||||
|
|||||||
@@ -2,12 +2,16 @@
|
|||||||
"input-size": "3984x2160",
|
"input-size": "3984x2160",
|
||||||
"output-size": "3456x960",
|
"output-size": "3456x960",
|
||||||
|
|
||||||
"default-size": "48x48",
|
"default-size": "288x240",
|
||||||
|
|
||||||
"copyRects": [
|
"copyRects": [
|
||||||
|
|
||||||
{ "from": "0,0-48x48", "to": "0,0" },
|
{ "from": "62+240*0,224-(240-62)x168", "to": "288*0,0" },
|
||||||
{ "from": "0,0-48x48", "to": "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" }
|
||||||
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ import std.file;
|
|||||||
import std.conv;
|
import std.conv;
|
||||||
import std.string;
|
import std.string;
|
||||||
import gamut;
|
import gamut;
|
||||||
|
import expression;
|
||||||
|
|
||||||
void usage()
|
void usage()
|
||||||
{
|
{
|
||||||
@@ -109,9 +109,10 @@ void processFile(string inputPath, string outputPath, string pattern)
|
|||||||
|
|
||||||
input.convertTo(PixelType.rgba8);
|
input.convertTo(PixelType.rgba8);
|
||||||
|
|
||||||
|
Size defaultSize = parseSize(patternFile, "default-size", Size(16, 16));
|
||||||
|
|
||||||
Size inputSize = parseSize(patternFile, "input-size");
|
Size inputSize = parseSize(patternFile, "input-size", defaultSize);
|
||||||
Size outputSize = parseSize(patternFile, "output-size");
|
Size outputSize = parseSize(patternFile, "output-size", defaultSize);
|
||||||
|
|
||||||
if (inputSize.w != input.width || inputSize.h != input.height)
|
if (inputSize.w != input.width || inputSize.h != input.height)
|
||||||
throw new Exception("input size mismatch");
|
throw new Exception("input size mismatch");
|
||||||
@@ -119,7 +120,6 @@ void processFile(string inputPath, string outputPath, string pattern)
|
|||||||
Image output;
|
Image output;
|
||||||
output.create(outputSize.w, outputSize.h, PixelType.rgba8);
|
output.create(outputSize.w, outputSize.h, PixelType.rgba8);
|
||||||
|
|
||||||
Size defaultSize = parseSize(patternFile, "default-size");
|
|
||||||
|
|
||||||
void copyRect(Rect src, Rect dst)
|
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");
|
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;
|
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);
|
r = strip(r);
|
||||||
int cPos = cast(int) r.indexOf(",");
|
int cPos = cast(int) r.indexOf(",");
|
||||||
if (cPos == -1)
|
if (cPos == -1)
|
||||||
throw new Exception("Point should follow this in format: 4,5");
|
throw new Exception("Point should follow this in format: 4,5");
|
||||||
int x = to!int(r[0..cPos]);
|
int x = parseIntegerExpression(r[0..cPos], defaultSize);
|
||||||
int y = to!int(r[cPos+1..$]);
|
int y = parseIntegerExpression(r[cPos+1..$], defaultSize);
|
||||||
return Point(x, y);
|
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);
|
r = strip(r);
|
||||||
int xPos = cast(int) r.indexOf("x");
|
int xPos = cast(int) r.indexOf("x");
|
||||||
if (xPos == -1)
|
if (xPos == -1)
|
||||||
throw new Exception("Size should follow this in format: 48x48");
|
throw new Exception("Size should follow this in format: 48x48");
|
||||||
int w = to!int(r[0..xPos]);
|
int w = parseIntegerExpression(r[0..xPos], defaultSize);
|
||||||
int h = to!int(r[xPos+1..$]);
|
int h = parseIntegerExpression(r[xPos+1..$], defaultSize);
|
||||||
return Size(w, h);
|
return Size(w, h);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -245,16 +245,23 @@ Rect parseRect(string r, Size defaultSize)
|
|||||||
|
|
||||||
if (mPos == -1)
|
if (mPos == -1)
|
||||||
{
|
{
|
||||||
pos = parsePoint(r);
|
pos = parsePoint(r, defaultSize);
|
||||||
size = defaultSize;
|
size = defaultSize;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pos = parsePoint(r[0..mPos]);
|
pos = parsePoint(r[0..mPos], defaultSize);
|
||||||
size = parseSize(r[mPos+1..$]);
|
size = parseSize(r[mPos+1..$], defaultSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
return Rect(pos, size);
|
return Rect(pos, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int parseIntegerExpression(string source,
|
||||||
|
Size defaultSize)
|
||||||
|
{
|
||||||
|
auto e = compileExpression!int(source);
|
||||||
|
//e["TX"] = defaultSize.w;
|
||||||
|
//e["TY"] = defaultSize.h;
|
||||||
|
return e();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user