@@ -37,37 +37,57 @@ bool progress_callback(void* opaque_data, float portion_done)
3737}
3838
3939// int main(int argc, char* argv[]) {
40- int solidify_main (const std::string& inputFileName, const std::string& outputFileName) {
41- // if (argc != 3) {
42- // std::cerr << "Usage: " << argv[0] << " INPUT OUTPUT\n";
43- // return 1;
44- // }
45-
40+ int solidify_main (const std::string& mask_file, const std::string& inputFileName, const std::string& outputFileName) {
4641 Timer g_timer;
4742
48- // const char* input_filename = argv[0];
49- // const char* output_filename = argv[1];
50-
5143 // Create an ImageBuf object for the input file
5244 ImageBuf input_buf (inputFileName);
45+ ImageBuf mask_buf (mask_file);
5346
5447 // Read the image with a progress callback
48+
49+ int last_channel = -1 ;
50+
51+ if (mask_file != " " ) {
52+ last_channel = 3 ;
53+ std::cout << " Reading " << mask_file << std::endl;
54+ bool read_ok = mask_buf.read (0 , 0 , 0 , 1 , true , TypeDesc::FLOAT, nullptr , nullptr );
55+ if (!read_ok) {
56+ std::cerr << " Error: Could not read mask image\n " ;
57+ return 1 ;
58+ }
59+ }
5560 std::cout << " Reading " << inputFileName << std::endl;
56- bool read_ok = input_buf.read (0 , 0 , 0 , -1 , true , TypeUnknown, *progress_callback, nullptr );
61+
62+ bool read_ok = input_buf.read (0 , 0 , 0 , last_channel, true , TypeUnknown, *progress_callback, nullptr );
5763 if (!read_ok) {
5864 std::cerr << " Error: Could not read input image\n " ;
5965 return 1 ;
6066 }
6167 std::cout << std::endl;
6268
6369 // Create an ImageBuf object to store the result
64- ImageBuf result_buf;
70+ ImageBuf result_buf, rgba_buf ;
6571
66- // Call fillholes_pushpull
6772 std::cout << " Filling holes in process...\n " ;
6873
6974 Timer pushpull_timer;
70- bool ok = ImageBufAlgo::fillholes_pushpull (result_buf, input_buf);
75+
76+ if (mask_file != " " ) {
77+ ImageBuf alpha_ch, alpha_c3;
78+ bool ok = ImageBufAlgo::channel_append (alpha_ch, mask_buf, mask_buf);
79+ ok = ok && ImageBufAlgo::channel_append (alpha_c3, alpha_ch, mask_buf);
80+ ImageBufAlgo::mul (input_buf, input_buf, alpha_c3);
81+ ok = ok && ImageBufAlgo::channel_append (rgba_buf, input_buf, mask_buf);
82+ if (!ok) {
83+ std::cerr << " Error: " << rgba_buf.geterror () << std::endl;
84+ return 1 ;
85+ }
86+ }
87+
88+ // Call fillholes_pushpull
89+
90+ bool ok = ImageBufAlgo::fillholes_pushpull (result_buf, (mask_file == " " ) ? input_buf : rgba_buf);
7191
7292 if (!ok) {
7393 std::cerr << " Error: " << result_buf.geterror () << std::endl;
@@ -95,6 +115,19 @@ int solidify_main(const std::string& inputFileName, const std::string& outputFil
95115 *progress_callback, nullptr );
96116 out->close ();
97117
118+ #if 0
119+ spec = rgba_buf.spec();
120+ spec.nchannels = 4;
121+
122+ out->open("debug.exr", spec, ImageOutput::Create);
123+
124+ out->write_image(rgba_buf.spec().format, rgba_buf.localpixels(),
125+ rgba_buf.pixel_stride(), rgba_buf.scanline_stride(), rgba_buf.z_stride(),
126+ *progress_callback, nullptr);
127+ out->close();
128+
129+ #endif
130+
98131 std::cout << std::endl << " Total processing time : " << g_timer.nowText () << std::endl;
99132
100133 return 0 ;
0 commit comments