Skip to content

Commit 8e2caa5

Browse files
committed
testshade: automatically convert to sRGB when outputting jpg, gif, or png.
Makes it easier to output directly to web-friendly formats, without a second oiiotool step to apply the right color spaces.
1 parent e9063df commit 8e2caa5

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

src/testshade/testshade.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,8 +1160,26 @@ test_shade (int argc, const char *argv[])
11601160
// Write the output images to disk
11611161
for (size_t i = 0; i < outputimgs.size(); ++i) {
11621162
if (outputimgs[i]) {
1163-
if (! print_outputs)
1164-
outputimgs[i]->write (outputimgs[i]->name());
1163+
if (! print_outputs) {
1164+
std::string filename = outputimgs[i]->name();
1165+
// JPEG, GIF, and PNG images should be automatically saved
1166+
// as sRGB because they are almost certainly supposed to
1167+
// be displayed on web pages.
1168+
using namespace OIIO;
1169+
if (Strutil::iends_with (filename, ".jpg") ||
1170+
Strutil::iends_with (filename, ".jpeg") ||
1171+
Strutil::iends_with (filename, ".gif") ||
1172+
Strutil::iends_with (filename, ".png")) {
1173+
ImageBuf ccbuf;
1174+
ImageBufAlgo::colorconvert (ccbuf, *outputimgs[i],
1175+
"linear", "sRGB", false,
1176+
"", "");
1177+
ccbuf.set_write_format (outputimgs[i]->spec().format);
1178+
ccbuf.write (filename);
1179+
} else {
1180+
outputimgs[i]->write (filename);
1181+
}
1182+
}
11651183
delete outputimgs[i];
11661184
outputimgs[i] = NULL;
11671185
}

0 commit comments

Comments
 (0)