nicer error handling in the tonemapper when given the -t parameter
parent
f24b51666a
commit
31761b3afd
|
@ -283,6 +283,7 @@ public:
|
||||||
|
|
||||||
if (runParallel) {
|
if (runParallel) {
|
||||||
ref<Logger> logger = Thread::getThread()->getLogger();
|
ref<Logger> logger = Thread::getThread()->getLogger();
|
||||||
|
std::vector<std::string> messages;
|
||||||
|
|
||||||
#if defined(MTS_OPENMP)
|
#if defined(MTS_OPENMP)
|
||||||
#pragma omp parallel for schedule(static)
|
#pragma omp parallel for schedule(static)
|
||||||
|
@ -293,62 +294,71 @@ public:
|
||||||
thread = Thread::registerUnmanagedThread("omp");
|
thread = Thread::registerUnmanagedThread("omp");
|
||||||
thread->setLogger(logger);
|
thread->setLogger(logger);
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
fs::path inputFile = fileResolver->resolve(argv[i]);
|
||||||
|
Log(EInfo, "Loading image \"%s\" ..", inputFile.string().c_str());
|
||||||
|
ref<FileStream> is = new FileStream(inputFile, FileStream::EReadOnly);
|
||||||
|
ref<Bitmap> input = new Bitmap(Bitmap::EAuto, is);
|
||||||
|
|
||||||
fs::path inputFile = fileResolver->resolve(argv[i]);
|
if (crop[2] != -1 && crop[3] != -1)
|
||||||
Log(EInfo, "Loading image \"%s\" ..", inputFile.string().c_str());
|
input = input->crop(Point2i(crop[0], crop[1]), Vector2i(crop[2], crop[3]));
|
||||||
ref<FileStream> is = new FileStream(inputFile, FileStream::EReadOnly);
|
|
||||||
ref<Bitmap> input = new Bitmap(Bitmap::EAuto, is);
|
|
||||||
|
|
||||||
if (crop[2] != -1 && crop[3] != -1)
|
if (bloomFov != 0) {
|
||||||
input = input->crop(Point2i(crop[0], crop[1]), Vector2i(crop[2], crop[3]));
|
int maxDim = std::max(input->getWidth(), input->getHeight());
|
||||||
|
if (maxDim % 2 == 0)
|
||||||
|
++maxDim;
|
||||||
|
|
||||||
if (bloomFov != 0) {
|
ref<Bitmap> bloomFilter = computeBloomFilter(maxDim, bloomFov);
|
||||||
int maxDim = std::max(input->getWidth(), input->getHeight());
|
|
||||||
if (maxDim % 2 == 0)
|
|
||||||
++maxDim;
|
|
||||||
|
|
||||||
ref<Bitmap> bloomFilter = computeBloomFilter(maxDim, bloomFov);
|
if (input->getComponentFormat() != Bitmap::EFloat)
|
||||||
|
input = input->convert(input->getPixelFormat(), Bitmap::EFloat);
|
||||||
|
|
||||||
if (input->getComponentFormat() != Bitmap::EFloat)
|
Log(EInfo, "Convolving image with bloom filter ..");
|
||||||
input = input->convert(input->getPixelFormat(), Bitmap::EFloat);
|
input->convolve(bloomFilter);
|
||||||
|
}
|
||||||
|
|
||||||
Log(EInfo, "Convolving image with bloom filter ..");
|
if (resize[0] != -1)
|
||||||
input->convolve(bloomFilter);
|
input = input->resample(rfilter, ReconstructionFilter::EClamp,
|
||||||
|
ReconstructionFilter::EClamp, Vector2i(resize[0], resize[1]));
|
||||||
|
|
||||||
|
if (cbal[0] != 1 || cbal[1] != 1 || cbal[2] != 1)
|
||||||
|
input->colorBalance(cbal[0], cbal[1], cbal[2]);
|
||||||
|
|
||||||
|
if (tonemapper[0] != -1) {
|
||||||
|
Float logAvgLuminance = 0, maxLuminance = 0;
|
||||||
|
input->tonemapReinhard(logAvgLuminance, maxLuminance, tonemapper[0], tonemapper[1]);
|
||||||
|
Log(EInfo, "Tonemapper reports: log-average luminance = %f, max. luminance = %f",
|
||||||
|
logAvgLuminance, maxLuminance);
|
||||||
|
}
|
||||||
|
|
||||||
|
ref<Bitmap> output = input->convert(pixelFormat, Bitmap::EUInt8, gamma, multiplier);
|
||||||
|
|
||||||
|
for (size_t i=0; i<rects.size(); ++i) {
|
||||||
|
int *r = rects[i].r;
|
||||||
|
output->drawRect(Point2i(r[0], r[1]), Vector2i(r[2], r[3]), Spectrum(r[4]/255.0f));
|
||||||
|
}
|
||||||
|
|
||||||
|
fs::path outputFile = inputFile;
|
||||||
|
if (format == Bitmap::EPNG)
|
||||||
|
outputFile.replace_extension(".png");
|
||||||
|
else if (format == Bitmap::EJPEG)
|
||||||
|
outputFile.replace_extension(".jpg");
|
||||||
|
else
|
||||||
|
Log(EError, "Unknown target format!");
|
||||||
|
|
||||||
|
Log(EInfo, "Writing tonemapped image to \"%s\" ..", outputFile.string().c_str());
|
||||||
|
|
||||||
|
ref<FileStream> os = new FileStream(outputFile, FileStream::ETruncReadWrite);
|
||||||
|
output->write(format, os);
|
||||||
|
} catch (const std::exception &e) {
|
||||||
|
#pragma omp critical
|
||||||
|
messages.push_back(e.what());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (resize[0] != -1)
|
if (!messages.empty()) {
|
||||||
input = input->resample(rfilter, ReconstructionFilter::EClamp,
|
Log(EWarn, "The tonemapping worker threads encountered several issues:");
|
||||||
ReconstructionFilter::EClamp, Vector2i(resize[0], resize[1]));
|
for (size_t i=0; i<messages.size(); ++i)
|
||||||
|
Log(EWarn, "Exception %i: %s", (int) i, messages[i].c_str());
|
||||||
if (cbal[0] != 1 || cbal[1] != 1 || cbal[2] != 1)
|
|
||||||
input->colorBalance(cbal[0], cbal[1], cbal[2]);
|
|
||||||
|
|
||||||
if (tonemapper[0] != -1) {
|
|
||||||
Float logAvgLuminance = 0, maxLuminance = 0;
|
|
||||||
input->tonemapReinhard(logAvgLuminance, maxLuminance, tonemapper[0], tonemapper[1]);
|
|
||||||
Log(EInfo, "Tonemapper reports: log-average luminance = %f, max. luminance = %f",
|
|
||||||
logAvgLuminance, maxLuminance);
|
|
||||||
}
|
|
||||||
|
|
||||||
ref<Bitmap> output = input->convert(pixelFormat, Bitmap::EUInt8, gamma, multiplier);
|
|
||||||
|
|
||||||
for (size_t i=0; i<rects.size(); ++i) {
|
|
||||||
int *r = rects[i].r;
|
|
||||||
output->drawRect(Point2i(r[0], r[1]), Vector2i(r[2], r[3]), Spectrum(r[4]/255.0f));
|
|
||||||
}
|
|
||||||
|
|
||||||
fs::path outputFile = inputFile;
|
|
||||||
if (format == Bitmap::EPNG)
|
|
||||||
outputFile.replace_extension(".png");
|
|
||||||
else if (format == Bitmap::EJPEG)
|
|
||||||
outputFile.replace_extension(".jpg");
|
|
||||||
else
|
|
||||||
Log(EError, "Unknown target format!");
|
|
||||||
|
|
||||||
Log(EInfo, "Writing tonemapped image to \"%s\" ..", outputFile.string().c_str());
|
|
||||||
|
|
||||||
ref<FileStream> os = new FileStream(outputFile, FileStream::ETruncReadWrite);
|
|
||||||
output->write(format, os);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ref<Bitmap> bloomFilter;
|
ref<Bitmap> bloomFilter;
|
||||||
|
|
Loading…
Reference in New Issue