@@ -46,6 +46,12 @@ std::pair<ImageBuf, ImageBuf> mask_load(const std::string& mask_file) {
4646 exit (-1 );
4747 }
4848
49+ int width = alpha_buf.spec ().width ;
50+ int height = alpha_buf.spec ().height ;
51+ std::cout << " Mask size: " << width << " x" << height << std::endl;
52+ // get bit depth of the image channels
53+ // int bit_depth = alpha_buf.spec().format.basesize * 8;
54+
4955 // rename channel to alpha and set it as an alpha channel
5056 alpha_buf.specmod ().channelnames [0 ] = " A" ;
5157 alpha_buf.specmod ().alpha_channel = 0 ;
@@ -91,10 +97,41 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
9197 }
9298
9399 std::cout << std::endl;
94- std::cout << " channels: " << input_buf.nchannels () << std::endl;
100+
101+ // Get the image's spec
102+ const ImageSpec& ispec = input_buf.spec ();
103+
104+ // Get the format (bit depth and type)
105+ TypeDesc format = ispec.format ;
106+
107+ if (format == TypeDesc::UINT8) {
108+ std::cout << " 8-bit unsigned int" << std::endl;
109+ }
110+ else if (format == TypeDesc::UINT16) {
111+ std::cout << " 16-bit unsigned int" << std::endl;
112+ }
113+ else if (format == TypeDesc::HALF) {
114+ std::cout << " 16-bit float" << std::endl;
115+ }
116+ else if (format == TypeDesc::FLOAT) {
117+ std::cout << " 32-bit float" << std::endl;
118+ }
119+ else if (format == TypeDesc::DOUBLE) {
120+ std::cout << " 64-bit float" << std::endl;
121+ }
122+ else {
123+ std::cout << " Unknown or unsupported format" << std::endl;
124+ }
125+
126+ // get the image size
127+ int width = input_buf.spec ().width ;
128+ int height = input_buf.spec ().height ;
129+ std::cout << " Image size: " << width << " x" << height << std::endl;
130+
131+ std::cout << " Channels: " << input_buf.nchannels () << std::endl;
95132
96133 int alpha_channel = input_buf.spec ().alpha_channel ;
97- std::cout << " alpha channel: " << alpha_channel << std::endl;
134+ std::cout << " Alpha channel: " << alpha_channel << std::endl;
98135
99136 bool isValid = true ;
100137 int inputCh = input_buf.nchannels ();
@@ -140,15 +177,23 @@ bool solidify_main(const std::string& inputFileName, const std::string& outputFi
140177 }
141178
142179 // Create an ImageBuf object to store the result
143- ImageBuf result_buf, rgba_buf;
180+ ImageBuf result_buf, rgba_buf, bit_alpha_buf ;
144181
145182 std::cout << " Filling holes in process...\n " ;
146183
147184 Timer pushpull_timer;
148185
149186 if (external_alpha) {
187+
188+ ImageBuf* alpha_buf_ptr = &mask_pair.first ;
189+
190+ if (format != TypeDesc::FLOAT) {
191+ bit_alpha_buf = mask_pair.first .copy (format);
192+ alpha_buf_ptr = &bit_alpha_buf;
193+ }
194+
150195 bool ok = ImageBufAlgo::mul (input_buf, input_buf, grayscale ? mask_pair.first : mask_pair.second );
151- ok = ok && ImageBufAlgo::channel_append (rgba_buf, input_buf, mask_pair. first );
196+ ok = ok && ImageBufAlgo::channel_append (rgba_buf, input_buf, bit_alpha_buf );
152197 if (!ok) {
153198 std::cerr << " Error: " << rgba_buf.geterror () << std::endl;
154199 return false ;
0 commit comments