Hi, sorry this seemed to slip through the cracks. I hope the information is 
still useful to somebody.

You have the basic idea for how to write a multi-subimage file using the 
ImageOutput interface, with the data just in a big array.

If I understand your question correctly, you want to use ImageBufAlgo:: crop() 
to crop those images to a given ROI, but now you are stuck for how to write a 
multi-image file (multi-part exr) for the resulting ImageBuf's.

Here's the outline of how you would do that:


// Start off the same way: you have your original images all in the big 
'scratch' buffer,
// and an array of specs.
// Assume you want to crop them all to ROI 'cropped_roi'.

// Make a new set of specs with the cropped sizes
std::vector<ImageSpec> cropped_specs (orig_fb_count);
for (int s = 0; s < orig_fb_count; ++s) {
    cropped_specs[s] = specs[s];
    cropped_specs[s].set_roi (cropped_roi);
}

// Open an ImageOutput for multi-subimage as you did before
out->open (filename.toStdString(), orig_fb_count, cropped_specs.data());

// Crop each individual image and write it
unsigned int xoffset = 0;
for (int s = 0;  s < orig_fb_count;  s++) {
    if (s > 0) { // Not needed for the first, which is already open
        out->open (filename.toStdString(), cropped_specs[s], 
ImageOutput::AppendSubimage);
    }

    // Make a light-weight ImageBuf that "wraps" your existing data.
    ImageBuf uncropped (specs[s], scratch + xoffset);

    // Crop it. (This will make a copy of just the cropped region.
    ImageBuf cropped = ImageBufAlgo::crop (uncropped, cropped_roi);

    // Write the new ImageBuf to the open file
    cropped.write (out);

    // Move to the next buffer position.
    xoffset += specs[s].image_bytes();

    // Note: the 'cropped' ImageBuf will automatically be destroyed and
    // have its memory freed when it exits scope at the end of this loop.
}



> On Jun 3, 2020, at 6:24 AM, Sven Steinbauer <s...@themill.com> wrote:
> 
> Hello,
> 
> I've sent an email about this before but I think my reply got lost somewhere. 
> Anyway, I am trying to crop a multi-image Exr file.
> 
> I have managed to write out the multi-image like this (because 
> out->supports("appendsubimage") returns false)
> 
> out->open (filename.toStdString(), orig_fb_count, specs);
> 
> // Write the individual subimages
> unsigned int xoffset = 0;
> for (int s = 0;  s < orig_fb_count;  s++) {
>     if (s > 0) { // Not needed for the first, which is already open
>         out->open (filename.toStdString(), specs[s], 
> ImageOutput::AppendSubimage);
>     }
>     out->write_image (TypeDesc::BASETYPE(specs[s].format.basetype), scratch + 
> xoffset);
>     xoffset += specs[s].image_bytes();        
> }
> 
> Here the scratch is a scratch file buffer storing all the aovs contiguously, 
> and the arrap of specs stores the spec for each one. This is working great, 
> but I want to add an autocrop feature. 
> 
> I can calculate the ROI (or BBox) for the overall image, but I am not sure 
> how to crop the images. 
> 
> The original code I inherited uses ImageBufAlgo::crop, and then 
> ImageBuf::write to save the file. I am not sure how to write out the result 
> from the crop to a multi-image EXR
> 
> out->open (filename.toStdString(), orig_fb_count, specs);
> 
> 
> What's the correct method to crop the image and write it out as a multi-image 
> EXR?
>  
> SVEN STEINBAUER​
> Senior R&D Engineer
> T 
> +44 20 7287 4041
>  <http://www.themill.com/>
> SUPPORTING WORLD PRIDE MONTH 2020
> THE MILL 11‑14 WINDMILL STREET, LONDON, W1T 2JG
> FOLLOW @MILLCHANNEL |         FACEBOOK <http://www.facebook.com/millchannel>  
>  |      LINKEDIN <https://www.linkedin.com/company/9328>         |      
> INSTAGRAM <https://www.instagram.com/millchannel>       
> |
> THEMILL.COM <http://www.themill.com/>
>  
> _______________________________________________
> Oiio-dev mailing list
> Oiio-dev@lists.openimageio.org <mailto:Oiio-dev@lists.openimageio.org>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
--
Larry Gritz
l...@larrygritz.com




_______________________________________________
Oiio-dev mailing list
Oiio-dev@lists.openimageio.org
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to