Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[image] Fix bug with input RGBA Images #743

Merged
merged 1 commit into from
Feb 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 22 additions & 12 deletions src/aliceVision/image/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,23 +278,33 @@ void readImage(const std::string& path,
oiio::ImageBuf grayscaleBuf;
oiio::ImageBufAlgo::channel_sum(grayscaleBuf, inBuf, weights, convertionROI);
inBuf.copy(grayscaleBuf);

// TODO: if inSpec.nchannels == 4: premult?
}

// add missing channels
if(nchannels > inSpec.nchannels)
// duplicate first channel for RGB
if (nchannels >= 3 && inSpec.nchannels == 1)
{
oiio::ImageSpec requestedSpec(inSpec.width, inSpec.height, nchannels, format);
oiio::ImageSpec requestedSpec(inSpec.width, inSpec.height, 3, format);
oiio::ImageBuf requestedBuf(requestedSpec);
int channelOrder[] = { 0, 0, 0 };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

float channelValues[] = { 0 /*ignore*/, 0 /*ignore*/, 0 /*ignore*/ };
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

oiio::ImageBufAlgo::channels(requestedBuf, inBuf, 3, channelOrder, channelValues);
inBuf.swap(requestedBuf);
}

// duplicate first channel for RGB
if(requestedSpec.nchannels >= 3 && inSpec.nchannels < 3)
{
oiio::ImageBufAlgo::paste(requestedBuf, 0, 0, 0, 0, inBuf);
oiio::ImageBufAlgo::paste(requestedBuf, 0, 0, 0, 1, inBuf);
oiio::ImageBufAlgo::paste(requestedBuf, 0, 0, 0, 2, inBuf);
}

inBuf.copy(requestedBuf);
// Add an alpha channel if needed
if (nchannels == 4 && inBuf.spec().nchannels == 3)
{
oiio::ImageSpec requestedSpec(inSpec.width, inSpec.height, 3, format);
oiio::ImageBuf requestedBuf(requestedSpec);
int channelOrder[] = { 0, 1, 2, -1 /*constant value*/ };
float channelValues[] = { 0 /*ignore*/, 0 /*ignore*/, 0 /*ignore*/, 1.0 };
Comment on lines +301 to +302
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

oiio::ImageBufAlgo::channels(requestedBuf, inBuf,
4, // create an image with 4 channels
channelOrder,
channelValues); // only the 4th value is used
inBuf.swap(requestedBuf);
}

// copy pixels from oiio to eigen
Expand Down