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

Allow empty file name #1898

Merged
merged 1 commit into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions src/lib/OpenEXRCore/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ exr_test_file_header (
exr_context_t ret = NULL;
exr_context_initializer_t inits = fill_context_data (ctxtdata);

if (filename && filename[0] != '\0')
if (filename)
{
rv = internal_exr_alloc_context (
&ret,
Expand Down Expand Up @@ -244,7 +244,7 @@ exr_start_read (
return EXR_ERR_INVALID_ARGUMENT;
}

if (filename && filename[0] != '\0')
if (filename)
{
rv = internal_exr_alloc_context (
&ret,
Expand Down Expand Up @@ -311,7 +311,7 @@ exr_start_write (
return EXR_ERR_INVALID_ARGUMENT;
}

if (filename && filename[0] != '\0')
if (filename)
{
rv = internal_exr_alloc_context (
&ret,
Expand Down
2 changes: 1 addition & 1 deletion src/test/OpenEXRCoreTest/read.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ testReadBadArgs (const std::string& tempdir)
EXRCORE_TEST_RVAL_FAIL (
EXR_ERR_INVALID_ARGUMENT, exr_start_read (&f, NULL, &cinit));
EXRCORE_TEST_RVAL_FAIL (
EXR_ERR_INVALID_ARGUMENT, exr_start_read (&f, "", &cinit));
EXR_ERR_FILE_ACCESS, exr_start_read (&f, "", &cinit));
// windows fails on directory open, where under unix you can open
// the directory as a file handle but not read from it
#ifdef _WIN32
Expand Down
56 changes: 56 additions & 0 deletions src/test/OpenEXRTest/testExistingStreams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,29 @@ MMIFStream::readMemoryMapped (int n)
return retVal;
}

class PassThruIFStream : public OPENEXR_IMF_NAMESPACE::IStream
{
public:
//-------------------------------------------------------
// A constructor that opens the file with the given name.
//-------------------------------------------------------

PassThruIFStream (MMIFStream &s) : IStream(""), _s (s) {}

virtual ~PassThruIFStream () {}

virtual bool isMemoryMapped () const { return _s.isMemoryMapped (); }

virtual bool read (char c[/*n*/], int n) { return _s.read (c, n); }
virtual char* readMemoryMapped (int n) { return _s.readMemoryMapped (n); }
virtual uint64_t tellg () { return _s.tellg (); }
virtual void seekg (uint64_t pos) { _s.seekg (pos); }
virtual void clear () { _s.clear (); }

private:
MMIFStream &_s;
};

void
writeReadScanLines (
const char fileName[],
Expand Down Expand Up @@ -345,6 +368,39 @@ writeReadScanLines (
}
}

{
cout << ", reading (memory-mapped, passthru)";
MMIFStream ifs (fileName);
PassThruIFStream pfs (ifs);

RgbaInputFile in (pfs);

const Box2i& dw = in.dataWindow ();
int w = dw.max.x - dw.min.x + 1;
int h = dw.max.y - dw.min.y + 1;
int dx = dw.min.x;
int dy = dw.min.y;

Array2D<Rgba> p2 (h, w);
in.setFrameBuffer (&p2[-dy][-dx], 1, w);
in.readPixels (dw.min.y, dw.max.y);

if (!isLossyCompression (compression))
{
cout << ", comparing";
for (int y = 0; y < h; ++y)
{
for (int x = 0; x < w; ++x)
{
assert (p2[y][x].r == p1[y][x].r);
assert (p2[y][x].g == p1[y][x].g);
assert (p2[y][x].b == p1[y][x].b);
assert (p2[y][x].a == p1[y][x].a);
}
}
}
}

cout << endl;

remove (fileName);
Expand Down
Loading