@@ -78,6 +78,7 @@ static bool do_oslquery = false;
7878static bool inbuffer = false ;
7979static bool use_shade_image = false ;
8080static bool userdata_isconnected = false ;
81+ static bool print_outputs = false ;
8182static int xres = 1 , yres = 1 ;
8283static int num_threads = 0 ;
8384static std::string groupname;
@@ -466,6 +467,7 @@ getargs (int argc, const char *argv[])
466467 " Output (variable, filename)" ,
467468 " -od %s" , &dataformatname, " Set the output data format to one of: "
468469 " uint8, half, float" ,
470+ " --print" , &print_outputs, " Print values of all -o outputs to console instead of saving images" ,
469471 " --groupname %s" , &groupname, " Set shader group name" ,
470472 " --layer %s" , &layername, " Set next layer name" ,
471473 " --param %@ %s %s" , &action_param, NULL , NULL ,
@@ -762,6 +764,8 @@ setup_output_images (ShadingSystem *shadingsys,
762764static void
763765save_outputs (ShadingSystem *shadingsys, ShadingContext *ctx, int x, int y)
764766{
767+ if (print_outputs)
768+ printf (" Pixel (%d, %d):\n " , x, y);
765769 // For each output requested on the command line...
766770 for (size_t i = 0 ; i < outputfiles.size (); ++i) {
767771 // Skip if we couldn't open the image or didn't match a known output
@@ -775,18 +779,30 @@ save_outputs (ShadingSystem *shadingsys, ShadingContext *ctx, int x, int y)
775779 if (!data)
776780 continue ; // Skip if symbol isn't found
777781
782+ int nchans = outputimgs[i]->nchannels ();
778783 if (t.basetype == TypeDesc::FLOAT) {
779784 // If the variable we are outputting is float-based, set it
780785 // directly in the output buffer.
781786 outputimgs[i]->setpixel (x, y, (const float *)data);
787+ if (print_outputs) {
788+ printf (" %s :" , outputvarnames[i].c_str ());
789+ for (int c = 0 ; c < nchans; ++c)
790+ printf (" %g" , ((const float *)data)[c]);
791+ printf (" \n " );
792+ }
782793 } else if (t.basetype == TypeDesc::INT) {
783794 // We are outputting an integer variable, so we need to
784795 // convert it to floating point.
785- int nchans = outputimgs[i]->nchannels ();
786796 float *pixel = (float *) alloca (nchans * sizeof (float ));
787797 OIIO::convert_types (TypeDesc::BASETYPE (t.basetype ), data,
788798 TypeDesc::FLOAT, pixel, nchans);
789799 outputimgs[i]->setpixel (x, y, &pixel[0 ]);
800+ if (print_outputs) {
801+ printf (" %s :" , outputvarnames[i].c_str ());
802+ for (int c = 0 ; c < nchans; ++c)
803+ printf (" %d" , ((const int *)data)[c]);
804+ printf (" \n " );
805+ }
790806 }
791807 // N.B. Drop any outputs that aren't float- or int-based
792808 }
@@ -1144,7 +1160,8 @@ test_shade (int argc, const char *argv[])
11441160 // Write the output images to disk
11451161 for (size_t i = 0 ; i < outputimgs.size (); ++i) {
11461162 if (outputimgs[i]) {
1147- outputimgs[i]->write (outputimgs[i]->name ());
1163+ if (! print_outputs)
1164+ outputimgs[i]->write (outputimgs[i]->name ());
11481165 delete outputimgs[i];
11491166 outputimgs[i] = NULL ;
11501167 }
0 commit comments