On May 19, 2017, at 10:32 AM, Steve Huey <[email protected]> wrote:
> 
> I’ve tried using the C++ interface by setting the “planarconfig” attribute in 
> the ImageSpec used ImageOutput but the resulting image is corrupted.
> 
> Here’s what I’m doing:
> 1. I’m opening a JPEG that is 4272 pixels wide as TypeDesc::UINT8.
> 2. I pass the buffer of pixel data to the third party code which returns the 
> data as UINT8, but planar. However, each row of image data now has 8 bytes of 
> padding so each row is 4280 bytes long. My planar to interleaved conversion 
> code ignores these 8 bytes in each row.
> 3. I’m able to save the image using OpenImageIO without issue using my 
> conversion code. I’d like to know if there’s a way to call 
> attribute(“planarconfig”, “contig”), pass it planar data, and have it ignore 
> those 8 bytes of padding in each row of data.


Yes, you need to use the stride parameters.

Everything on the App side of OIIO is *contiguous*.

So let's walk through your steps.

> 1. I’m opening a JPEG that is 4272 pixels wide as TypeDesc::UINT8.

    ImageInput *in = ImageInput::open ("my.jpg");
    if (! in) { /* error */ }
    ImageSpec inspec = in->spec();
    // For your file, inspec.width should be 4272
    std::unique_ptr<unsigned char[]> buf (new unsigned char [inspec.width * 
inspec.height * inspec.nchannels]);
    in->read_image (TypeDesc::UINT8, &buf[0]);
    in->close();
    ImageInput::destroy (in);


> 2. I pass the buffer of pixel data to the third party code which returns the 
> data as UINT8, but planar. However, each row of image data now has 8 bytes of 
> padding so each row is 4280 bytes long.

So let's say that you are doing:

    unsigned char *modified = third_party_code (&buf[0]);
    // And for some reason, modified is planar, and it has been padded to 4280 
bytes per line per channel.
    // Let's assume the line length is stored in size_t padded_line_length.
    // So modified is like unsigned char [4280 * nchannels * height]

> My planar to interleaved conversion code ignores these 8 bytes in each row.

So you are doing something like:

    my_conversion (modified);
    // Now modified points to interleaved scanlines of 4272 pixels each,
    // but each scanline is spaced 4280*nchannels bytes apart. Right?

Is that right?


> 3. I’m able to save the image using OpenImageIO without issue using my 
> conversion code. I’d like to know if there’s a way to call 
> attribute(“planarconfig”, “contig”), pass it planar data, and have it ignore 
> those 8 bytes of padding in each row of data.

No, there is no way to do that. OIIO's APIs assume/require contiguous 
(interleaved) configuration on the app side of the interface. The attribute you 
mention requests that your interleaved data be saved as contiguous in the file 
itself. (The distinction is not a choice for JPEG files anyway. TIFF is the 
only format that lets you choose, I think.)

So let's keep your conversion conversion code, it is required.

The way to output with padding is:

    ImageOutput *out = ImageOutput::create ("out.jpg");
    out->open ("out.jpg", inspec);   // just copy the spec from input
    out->write_image (TypeDesc::UINT8, &modified[0],
                                   nchannels,   // custom pixel-to-pixel stride
                                   4280 * nchannels);  // custom 
scanline-to-scanline stride
    out->close ();
    ImageOutput::destroy (out);


Does that help?


> 
> 
> On May 19, 2017 at 1:22 PM, Larry Gritz <[email protected] 
> <mailto:[email protected]>> wrote:
> 
> 
> You can convert between planar configurations (for formats that support the 
> distinction) on the command line with oiiotool:
> 
>     oiiotool myinterleaved.tif --planarconfig separate -o myseparate.tif
> 
>     oiiotool mycontiguous.tif --planarconfig contig -o myinterleaved.tif
> 
> If you're using the C++ interface, you don't have to actually "do" anything, 
> no shuffling of memory on your own, it's all handled in the output just by 
> setting that one attribute for the output configuration.
> 
> I'm not sure what you mean by "padding". Can you explain what you're trying 
> to achieve?
> 
> Full PDF documentation (a 400 page book!) can be found in the OIIO 
> distribution itself. Look for openimageio.pdf.
> 
> 
>> On May 19, 2017, at 10:13 AM, Steve Huey <[email protected] 
>> <mailto:[email protected]>> wrote:
>> 
>> Hi,
>> 
>> I’ve just started using OpenImageIO to load and save images which I’m apply 
>> some effects to with a a third party library. After processing, the third 
>> party library converts images to planar (separate) format, and adds some 
>> padding to each row.
>> 
>> I’ve been converting them back to interleaved (contig) using some code I 
>> wrote before saving the images with OpenImageIO but noticed that some of the 
>> command line tools included with the OpenImageIO distribution support this 
>> conversion as well. If OpenImageIO can handle this conversion for me, I’d 
>> like to learn how.
>> 
>> From looking at the source for some of these tools they just appear to set 
>> call the attribute method of the ImageSpec class with something like: 
>> spec.attribute(“planarconfig”, “contig”). Because of the row padding (I 
>> think) this approach isn’t working for me, and the output image is corrupted.
>> 
>> Given this, I have two questions:
>> 
>> 1. Does OpenImageIO support conversion from planar to interleaved with 
>> padding?
>> 2. If so, can you please point me in the direction of the recommended 
>> functions / docs?
>> 
>> Thanks,
>> Steve Huey
>> 
>> -- 
>> // Steven Huey * Senior Software Engineer
>> // [email protected] <mailto:[email protected]>
>> // www.artandlogic.com <http://www.artandlogic.com/> 
>> // Art & Logic -- Coding the "impossible."™
>> 
>> 
>> _______________________________________________
>> Oiio-dev mailing list
>> [email protected] <mailto:[email protected]>
>> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
>> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
> 
> --
> Larry Gritz
> [email protected] <mailto:[email protected]>
> 
> 
> 
> _______________________________________________
> Oiio-dev mailing list
> [email protected] <mailto:[email protected]>
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org 
> <http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org>
> _______________________________________________
> Oiio-dev mailing list
> [email protected]
> http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

--
Larry Gritz
[email protected]


_______________________________________________
Oiio-dev mailing list
[email protected]
http://lists.openimageio.org/listinfo.cgi/oiio-dev-openimageio.org

Reply via email to