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

[BUG] ImageBuf not working with in-memory DDS files #4043

Closed
MiroslavR opened this issue Nov 1, 2023 · 1 comment · Fixed by #4048
Closed

[BUG] ImageBuf not working with in-memory DDS files #4043

MiroslavR opened this issue Nov 1, 2023 · 1 comment · Fixed by #4048

Comments

@MiroslavR
Copy link

I am trying to create ImageBuf using an IOMemReader pointing to an in-memory DDS file. However, ImageBuf::init_spec fails with Invalid DDS header, possibly corrupt file. ImageInput::open works fine with IOMemReader. The problem seems to be specific to DDS format, I could not reproduce with PNG.

Code for reproduction:

#include <OpenImageIO/filesystem.h>
#include <OpenImageIO/imagebuf.h>

#include <fstream>
#include <iostream>

namespace OIIO = OpenImageIO_v2_4;

void fails(const std::string& ddsData)
{
	OIIO::Filesystem::IOMemReader memReader(ddsData.data(), ddsData.size());
	OIIO::ImageBuf buf("not_existing_on_disk.dds", 0, 0, nullptr, nullptr, &memReader);

	if (!buf.init_spec(buf.name(), 0, 0))
	{
		std::cout << "init_spec failed: " << buf.geterror() << std::endl;
		return;
	}

	std::cout << "init_spec succeeded; size: " << buf.spec().width << " x " << buf.spec().height << std::endl;
}

void works(const std::string& ddsData)
{
	OIIO::Filesystem::IOMemReader imageReader(ddsData.data(), ddsData.size());
	auto in = OIIO::ImageInput::open("not_existing_on_disk.dds", nullptr, &imageReader);
	if (!in)
	{
		std::cout << "ImageInput::open failed" << std::endl;
		return;
	}

	std::cout << "ImageInput::open succeeded; size: " << in->spec().width << " x " << in->spec().height << std::endl;
}

int main()
{
	std::fstream fs("example.dds");
	const std::string ddsData((std::istreambuf_iterator<char>(fs)), std::istreambuf_iterator<char>());

	fails(ddsData);
	works(ddsData);

	return 0;
}

The result I get:

init_spec failed: Invalid image file "not_existing_on_disk.dds": Invalid DDS header, possibly corrupt file
ImageInput::open succeeded; size: 512 x 256

The result I expect:

init_spec succeeded; size: 512 x 256
ImageInput::open succeeded; size: 512 x 256

I am on Debian Testing, using OIIO version 2.4.14 (distro package). Here's the whole project along with example.dds:
openimageio_test.zip

@jessey-git
Copy link
Contributor

I'll take a look at this one. I think it's pretty simple so I'll send a PR around tomorrow for it.

lgritz pushed a commit that referenced this issue Nov 3, 2023
…and PSD files (#4048)

During certain creation tasks, open may be called twice on the
ImageInput. If the first open call moves the ioproxy forward, then the
second call to open may fail.

DDS and PSD were affected so they've been fixed to mirror what other
formats (png, hdr, tga, etc.) do by always explicitly seeking to
position 0.

Fixes #4043 

Signed-off-by: Jesse Yurkovich <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants