0

I'm trying to convert .hdr and .exr images to resized .png images. The conversion part works as expected but when I try to resize the image before saving the result is just a black image. I'm using the latest OpenImageIO from github.

// read in an HDR or exr image
 auto in = ImageInput::open (image_path.hdr);
 const ImageSpec& spec = in->spec();
 int w = spec.width;
 int h = spec.height;
 int channels = spec.nchannels;

 // convert float to UNIT8
 std::vector<unsigned char> pixels (w * h * channels);
 in->read_image (TypeDesc::UINT8, pixels.data());
 
 // resize and save to png format
 ImageSpec s;
 s.format = TypeDesc::UINT8;
 s.width = w;
 s.height = h;
 s.nchannels = channels;
 ImageBuf A (s, pixels.data());

// without resizing saving to .png works correctly
A.write(image_path.png);

// this results in an all black image
ROI roi (0, w/2, 0, h/2, 0, 1, 0,channels);
ImageBuf B; 
ImageBufAlgo::resize (B, A, "", 0, roi);
B.write(image_path.png);
Bird33
  • 11
  • 2
  • It may be more fruitful to ask this on the oiio-dev mail list. Be sure to say which OIIO release you are using. – Larry Gritz Dec 14 '20 at 06:22

1 Answers1

1

Turns out when resizing, the ImageSpec fields full_width and full_height need to be filled in too. When they are, resizing works as expected.

ImageSpec s;
s.format = TypeDesc::UINT8;
s.width = w;
s.height = h;
s.full_width = w;
s.full_height = h;
Bird33
  • 11
  • 2