MtsBlend: refresh feature

metadata
Wenzel Jakob 2010-11-12 15:43:07 +01:00
parent a5b07f06ab
commit 81982c8932
5 changed files with 53 additions and 10 deletions

View File

@ -55,8 +55,13 @@ public:
/// Clear the bitmap to zero
void clear();
/// Save the bitmap using the give file format
void save(EFileFormat format, Stream *stream) const;
/**
* Save the bitmap using the give file format. Where
* applicable, the \a compression parameter can be used
* to control amount of compression (1: lowest, 9: highest)
* */
void save(EFileFormat format, Stream *stream, int compression = 5) const;
/// Return the image's title identifier
inline const std::string &getTile() const { return m_title; }
@ -134,7 +139,7 @@ protected:
void loadEXR(Stream *stream);
/// Save a file using the PNG file format
void savePNG(Stream *stream) const;
void savePNG(Stream *stream, int compression) const;
/// Save a file using the EXR file format
void saveEXR(Stream *stream) const;

View File

@ -403,7 +403,7 @@ public:
Log(EInfo, "Writing image to \"%s\" ..", filename.leaf().c_str());
ref<FileStream> stream = new FileStream(filename, FileStream::ETruncWrite);
bitmap->setGamma(m_gamma);
bitmap->save(Bitmap::EPNG, stream);
bitmap->save(Bitmap::EPNG, stream, 1);
}
bool destinationExists(const fs::path &baseName) const {

View File

@ -537,7 +537,7 @@ bool Bitmap::operator==(const Bitmap &bitmap) const {
return false;
}
void Bitmap::save(EFileFormat format, Stream *stream) const {
void Bitmap::save(EFileFormat format, Stream *stream, int compression) const {
if (m_bpp == 96 || m_bpp == 128)
AssertEx(format == EEXR, "Bitmap: 96/128 bpp images can only be stored "
"using the EXR file format");
@ -548,7 +548,7 @@ void Bitmap::save(EFileFormat format, Stream *stream) const {
if (format == EEXR)
saveEXR(stream);
else if (format == EPNG)
savePNG(stream);
savePNG(stream, compression);
else
Log(EError, "Bitmap: Invalid file format!");
}
@ -576,7 +576,7 @@ void Bitmap::saveEXR(Stream *stream) const {
delete[] rgba;
}
void Bitmap::savePNG(Stream *stream) const {
void Bitmap::savePNG(Stream *stream, int compression) const {
png_structp png_ptr;
png_infop info_ptr;
png_text text[4];
@ -605,7 +605,7 @@ void Bitmap::savePNG(Stream *stream) const {
}
png_set_write_fn(png_ptr, stream, (png_rw_ptr) png_write_data, (png_flush_ptr) png_flush_data);
png_set_compression_level(png_ptr, 5);
png_set_compression_level(png_ptr, compression);
memset(text, 0, sizeof(png_text)*4);
text[0].key = (char *) "Generated by";

View File

@ -65,6 +65,7 @@ void help() {
cout << " -n name Assign a node name to this instance (Default: host name)" << endl << endl;
cout << " -t Test case mode (see Mitsuba docs for more information)" << endl << endl;
cout << " -x Skip rendering of files where output already exists" << endl << endl;
cout << " -r sec Write (partial) output images every 'sec' seconds" << endl << endl;
cout << " -b res Specify the block resolution used to split images into parallel" << endl;
cout << " workloads (default: 32). Only applies to some integrators." << endl << endl;
cout << " -v Be more verbose" << endl << endl;
@ -85,6 +86,28 @@ void signalHandler(int signal) {
}
#endif
class FlushThread : public Thread {
public:
FlushThread(int timeout) : Thread("flush"),
m_flag(new WaitFlag()),
m_timeout(timeout) { }
void run() {
while (!m_flag->get()) {
m_flag->wait(m_timeout * 1000);
renderQueue->flush();
}
}
void quit() {
m_flag->set(true);
join();
}
private:
ref<WaitFlag> m_flag;
int m_timeout;
};
int ubi_main(int argc, char **argv) {
char optchar, *end_ptr = NULL;
@ -99,6 +122,7 @@ int ubi_main(int argc, char **argv) {
bool testCaseMode = false;
std::map<std::string, std::string> parameters;
int blockSize = 32;
int flushTimer = -1;
if (argc < 2) {
help();
@ -107,7 +131,7 @@ int ubi_main(int argc, char **argv) {
optind = 1;
/* Parse command-line arguments */
while ((optchar = getopt(argc, argv, "a:c:D:s:j:n:o:b:p:qhzvtx")) != -1) {
while ((optchar = getopt(argc, argv, "a:c:D:s:j:n:o:r:b:p:qhzvtx")) != -1) {
switch (optchar) {
case 'a': {
std::vector<std::string> paths = tokenize(optarg, ";");
@ -162,6 +186,11 @@ int ubi_main(int argc, char **argv) {
if (*end_ptr != '\0')
SLog(EError, "Could not parse the parallel scene count!");
break;
case 'r':
flushTimer = strtol(optarg, &end_ptr, 10);
if (*end_ptr != '\0')
SLog(EError, "Could not parse the '-r' parameter argument!");
break;
case 'b':
blockSize = strtol(optarg, &end_ptr, 10);
if (*end_ptr != '\0')
@ -288,6 +317,12 @@ int ubi_main(int argc, char **argv) {
if (testCaseMode)
testSupervisor = new TestSupervisor(argc-optind);
ref<FlushThread> flushThread;
if (flushTimer > 0) {
flushThread = new FlushThread(flushTimer);
flushThread->start();
}
int jobIdx = 0;
for (int i=optind; i<argc; ++i) {
fs::path
@ -320,6 +355,8 @@ int ubi_main(int argc, char **argv) {
/* Wait for all render processes to finish */
renderQueue->waitLeft(0);
if (flushThread)
flushThread->quit();
renderQueue = NULL;
delete handler;

View File

@ -126,7 +126,8 @@ class RENDERENGINE_mitsuba(bpy.types.RenderEngine, engine_base):
self.output_file = efutil.export_path[:-4] + ".png"
mitsuba_process = subprocess.Popen(
[mitsuba_binary, efutil.export_path, '-o', self.output_file],
[mitsuba_binary, '-r', '%d' % scene.mitsuba_engine.refresh_interval,
'-o', self.output_file, efutil.export_path],
env = env,
cwd = self.output_dir
)