diff --git a/src/main.cc b/src/main.cc index b75bed7..654e3a2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -178,7 +178,7 @@ readEXR(const char fileName[], height = dw.max.y - dw.min.y + 1; const ChannelList channels = header.channels(); const bool hasAlpha = channels.findChannel("A") != nullptr; - bool readAlpha = hasAlpha && readAlphaIfPresent; + readAlpha = hasAlpha && readAlphaIfPresent; const int stride = readAlpha ? 4 : 3; @@ -290,7 +290,7 @@ int main( int argc, char *argv[], char *envp[] ) { Parser p(expression); if(p.isValid()) { - cout << p.getRoot()->toString() << "\n"; + cout << p.getRoot()->toString("") << "\n"; vector inputFilePaths; string outputFilePath; std::function collectFunc; @@ -467,16 +467,21 @@ int main( int argc, char *argv[], char *envp[] ) { } } else if (leftResult.type == CalcResult::ARRAY && rightResult.type == CalcResult::ARRAY) { - res.type = CalcResult::ARRAY; - res.array.resizeErase(leftResult.array.height(), leftResult.array.width()); - if (leftResult.array.width() != rightResult.array.width() || leftResult.array.height() != rightResult.array.height()) { - cout << "error: resolution mismatch.\n"; + if (leftResult.hasAlpha != rightResult.hasAlpha) { + cout << "error: in " << node->toString(patch) << " \n"; + cout << "Alpha mismatch.\n"; + cout << "Some inputs have Alpha channels, others do not. Consider using -rgb argument to ignore alpha channels altogether.\n"; assert(false); } - if (leftResult.hasAlpha != rightResult.hasAlpha) { - cout << "error: some inputs have Alpha channels, others do not. Consider using -rgb argument.\n"; + if (leftResult.array.width() != rightResult.array.width() || leftResult.array.height() != rightResult.array.height()) { + const int stride = leftResult.hasAlpha ? 4 : 3; + cout << "error: in " << node->toString(patch) << " \n"; + cout << "resolution mismatch. Left is " << leftResult.array.width()/stride << "x" << leftResult.array.height() + << " and right is " << rightResult.array.width()/stride << "x" << rightResult.array.height() << "\n"; assert(false); } + res.type = CalcResult::ARRAY; + res.array.resizeErase(leftResult.array.height(), leftResult.array.width()); res.hasAlpha = leftResult.hasAlpha; CALCRESULT(leftResult.array[y][x], node->type, rightResult.array[y][x]); } @@ -531,12 +536,13 @@ int main( int argc, char *argv[], char *envp[] ) { writeEXR(targetFileName.c_str(), res.array[0], res.array.width() / stride, res.array.height(), res.hasAlpha, compression); }); if(verify) { - cout << "verifying written images..."; + cout << "verifying written images...\n"; Array2D pixels; int width, height; bool verificationSuccessful = true; for(int i=0; itoString():"null") + " + " + - (right?right->toString():"null") + ")"; + return string("(") + (left?left->toString(patch):"null") + " + " + + (right?right->toString(patch):"null") + ")"; case Node::SUB: - return string("(") + (left?left->toString():"null") + " - " + - (right?right->toString():"null") + ")"; + return string("(") + (left?left->toString(patch):"null") + " - " + + (right?right->toString(patch):"null") + ")"; case Node::MULT: - return string("(") + (left?left->toString():"null") + " * " + - (right?right->toString():"null") + ")"; + return string("(") + (left?left->toString(patch):"null") + " * " + + (right?right->toString(patch):"null") + ")"; case Node::DIV: - return string("(") + (left?left->toString():"null") + " / " + - (right?right->toString():"null") + ")"; + return string("(") + (left?left->toString(patch):"null") + " / " + + (right?right->toString(patch):"null") + ")"; case Node::ASSIGN: - return (left?left->toString():"null") + " = " + - (right?right->toString():"null"); + return (left?left->toString(patch):"null") + " = " + + (right?right->toString(patch):"null"); default: return string("NOT IMPLEMENTED:") + to_string(type) + "this:" + to_string(size_t(this)); } diff --git a/src/parser.h b/src/parser.h index 51d0749..ef5d098 100644 --- a/src/parser.h +++ b/src/parser.h @@ -12,7 +12,7 @@ class Parser { enum NodeType { INVALID, INPUTFILEPATH, OUTPUTFILEPATH, CONSTANT, ADD, SUB, MULT, DIV, ASSIGN }; Node() : type(INVALID), path(""), constant(0.0f), left(nullptr), right(nullptr) {} ~Node() { if (left) delete left; if (right) delete right; } - std::string toString() const; + std::string toString(const std::string& patch = "") const; void evaluate(std::function& lambda) const; NodeType type; std::string path;