Skip to content

Commit d19ce99

Browse files
authored
Merge pull request #757 from lgritz/lg-testshade
testshade improvements
2 parents 54e5434 + 20331f7 commit d19ce99

2 files changed

Lines changed: 57 additions & 17 deletions

File tree

src/testshade/testshade.cpp

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ static bool do_oslquery = false;
7878
static bool inbuffer = false;
7979
static bool use_shade_image = false;
8080
static bool userdata_isconnected = false;
81+
static bool print_outputs = false;
8182
static int xres = 1, yres = 1;
8283
static int num_threads = 0;
8384
static std::string groupname;
@@ -101,8 +102,8 @@ static ShaderGroupRef shadergroup;
101102
static std::string archivegroup;
102103
static int exprcount = 0;
103104
static bool shadingsys_options_set = false;
104-
static float sscale = 1, tscale = 1;
105-
static float soffset = 0, toffset = 0;
105+
static float uscale = 1, vscale = 1;
106+
static float uoffset = 0, voffset = 0;
106107

107108

108109

@@ -464,8 +465,10 @@ getargs (int argc, const char *argv[])
464465
"--texoptions %s", &texoptions, "Set extra TextureSystem options",
465466
"-o %L %L", &outputvars, &outputfiles,
466467
"Output (variable, filename)",
467-
"-od %s", &dataformatname, "Set the output data format to one of: "
468+
"-d %s", &dataformatname, "Set the output data format to one of: "
468469
"uint8, half, float",
470+
"-od %s", &dataformatname, "", // old name
471+
"--print", &print_outputs, "Print values of all -o outputs to console instead of saving images",
469472
"--groupname %s", &groupname, "Set shader group name",
470473
"--layer %s", &layername, "Set next layer name",
471474
"--param %@ %s %s", &action_param, NULL, NULL,
@@ -496,8 +499,10 @@ getargs (int argc, const char *argv[])
496499
"--shadeimage", &use_shade_image, "Use shade_image utility",
497500
"--noshadeimage %!", &use_shade_image, "Don't use shade_image utility",
498501
"--expr %@ %s", &specify_expr, NULL, "Specify an OSL expression to evaluate",
499-
"--offsetst %f %f", &soffset, &toffset, "Offset s & t texture coordinates (default: 0 0)",
500-
"--scalest %f %f", &sscale, &tscale, "Scale s & t texture lookups (default: 1, 1)",
502+
"--offsetuv %f %f", &uoffset, &voffset, "Offset s & t texture coordinates (default: 0 0)",
503+
"--offsetst %f %f", &uoffset, &voffset, "", // old name
504+
"--scaleuv %f %f", &uscale, &vscale, "Scale s & t texture lookups (default: 1, 1)",
505+
"--scalest %f %f", &uscale, &vscale, "", // old name
501506
"--userdata_isconnected", &userdata_isconnected, "Consider lockgeom=0 to be isconnected()",
502507
"-v", &verbose, "Verbose output",
503508
NULL);
@@ -587,17 +592,17 @@ setup_shaderglobals (ShaderGlobals &sg, ShadingSystem *shadingsys,
587592
if (pixelcenters) {
588593
// Our patch is like an "image" with shading samples at the
589594
// centers of each pixel.
590-
sg.u = sscale * (float)(x+0.5f) / xres + soffset;
591-
sg.v = tscale * (float)(y+0.5f) / yres + toffset;
592-
sg.dudx = sscale / xres;
593-
sg.dvdy = tscale / yres;
595+
sg.u = uscale * (float)(x+0.5f) / xres + uoffset;
596+
sg.v = vscale * (float)(y+0.5f) / yres + voffset;
597+
sg.dudx = uscale / xres;
598+
sg.dvdy = vscale / yres;
594599
} else {
595600
// Our patch is like a Reyes grid of points, with the border
596601
// samples being exactly on u,v == 0 or 1.
597-
sg.u = sscale * ((xres == 1) ? 0.5f : (float) x / (xres - 1)) + soffset;
598-
sg.v = tscale * ((yres == 1) ? 0.5f : (float) y / (yres - 1)) + toffset;
599-
sg.dudx = sscale / std::max (1, xres-1);
600-
sg.dvdy = tscale / std::max (1, yres-1);
602+
sg.u = uscale * ((xres == 1) ? 0.5f : (float) x / (xres - 1)) + uoffset;
603+
sg.v = vscale * ((yres == 1) ? 0.5f : (float) y / (yres - 1)) + voffset;
604+
sg.dudx = uscale / std::max (1, xres-1);
605+
sg.dvdy = vscale / std::max (1, yres-1);
601606
}
602607

603608
// Assume that position P is simply (u,v,1), that makes the patch lie
@@ -760,6 +765,8 @@ setup_output_images (ShadingSystem *shadingsys,
760765
static void
761766
save_outputs (ShadingSystem *shadingsys, ShadingContext *ctx, int x, int y)
762767
{
768+
if (print_outputs)
769+
printf ("Pixel (%d, %d):\n", x, y);
763770
// For each output requested on the command line...
764771
for (size_t i = 0; i < outputfiles.size(); ++i) {
765772
// Skip if we couldn't open the image or didn't match a known output
@@ -773,18 +780,30 @@ save_outputs (ShadingSystem *shadingsys, ShadingContext *ctx, int x, int y)
773780
if (!data)
774781
continue; // Skip if symbol isn't found
775782

783+
int nchans = outputimgs[i]->nchannels();
776784
if (t.basetype == TypeDesc::FLOAT) {
777785
// If the variable we are outputting is float-based, set it
778786
// directly in the output buffer.
779787
outputimgs[i]->setpixel (x, y, (const float *)data);
788+
if (print_outputs) {
789+
printf (" %s :", outputvarnames[i].c_str());
790+
for (int c = 0; c < nchans; ++c)
791+
printf (" %g", ((const float *)data)[c]);
792+
printf ("\n");
793+
}
780794
} else if (t.basetype == TypeDesc::INT) {
781795
// We are outputting an integer variable, so we need to
782796
// convert it to floating point.
783-
int nchans = outputimgs[i]->nchannels();
784797
float *pixel = (float *) alloca (nchans * sizeof(float));
785798
OIIO::convert_types (TypeDesc::BASETYPE(t.basetype), data,
786799
TypeDesc::FLOAT, pixel, nchans);
787800
outputimgs[i]->setpixel (x, y, &pixel[0]);
801+
if (print_outputs) {
802+
printf (" %s :", outputvarnames[i].c_str());
803+
for (int c = 0; c < nchans; ++c)
804+
printf (" %d", ((const int *)data)[c]);
805+
printf ("\n");
806+
}
788807
}
789808
// N.B. Drop any outputs that aren't float- or int-based
790809
}
@@ -1135,25 +1154,46 @@ test_shade (int argc, const char *argv[])
11351154
}
11361155
}
11371156
}
1157+
double runtime = timer.lap();
11381158

11391159
if (outputfiles.size() == 0)
11401160
std::cout << "\n";
11411161

11421162
// Write the output images to disk
11431163
for (size_t i = 0; i < outputimgs.size(); ++i) {
11441164
if (outputimgs[i]) {
1145-
outputimgs[i]->write (outputimgs[i]->name());
1165+
if (! print_outputs) {
1166+
std::string filename = outputimgs[i]->name();
1167+
// JPEG, GIF, and PNG images should be automatically saved
1168+
// as sRGB because they are almost certainly supposed to
1169+
// be displayed on web pages.
1170+
using namespace OIIO;
1171+
if (Strutil::iends_with (filename, ".jpg") ||
1172+
Strutil::iends_with (filename, ".jpeg") ||
1173+
Strutil::iends_with (filename, ".gif") ||
1174+
Strutil::iends_with (filename, ".png")) {
1175+
ImageBuf ccbuf;
1176+
ImageBufAlgo::colorconvert (ccbuf, *outputimgs[i],
1177+
"linear", "sRGB", false,
1178+
"", "");
1179+
ccbuf.set_write_format (outputimgs[i]->spec().format);
1180+
ccbuf.write (filename);
1181+
} else {
1182+
outputimgs[i]->write (filename);
1183+
}
1184+
}
11461185
delete outputimgs[i];
11471186
outputimgs[i] = NULL;
11481187
}
11491188
}
11501189

11511190
// Print some debugging info
11521191
if (debug || runstats || profile) {
1153-
double runtime = timer.lap();
1192+
double writetime = timer.lap();
11541193
std::cout << "\n";
11551194
std::cout << "Setup: " << OIIO::Strutil::timeintervalformat (setuptime,2) << "\n";
11561195
std::cout << "Run : " << OIIO::Strutil::timeintervalformat (runtime,2) << "\n";
1196+
std::cout << "Write: " << OIIO::Strutil::timeintervalformat (writetime,2) << "\n";
11571197
std::cout << "\n";
11581198
std::cout << shadingsys->getstats (5) << "\n";
11591199
OIIO::TextureSystem *texturesys = shadingsys->texturesys();

testsuite/texture-udim/run.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77

88
# Purposely only create two of the four UDIM textures
99

10-
command += testshade("-g 128 128 --center -scalest 2 2 -od uint8 -o Cout out.tif test")
10+
command += testshade("-g 128 128 --center -scaleuv 2 2 -od uint8 -o Cout out.tif test")
1111
outputs = [ "out.txt", "out.tif" ]

0 commit comments

Comments
 (0)