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

Fix for reading memory mapped files with DWA compression #1333

Merged
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
9 changes: 6 additions & 3 deletions src/lib/OpenEXR/ImfDwaCompressor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@
#include "half.h"

#include <algorithm>
#include <array>
#include <cassert>
#include <cctype>
#include <limits>
Expand Down Expand Up @@ -2250,10 +2251,12 @@ DwaCompressor::uncompress (
// Flip the counters from XDR to NATIVE
//

std::array<uint64_t, NUM_SIZES_SINGLE> counterBuf;
memcpy (counterBuf.data (), inPtr, counterBuf.size() * sizeof (uint64_t));
Copy link
Contributor

Choose a reason for hiding this comment

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

I imagine since the data is all going to be touched subsequently, this has no performance implication, and may improve things through cache prewarming?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's a fairly small buffer, currently NUM_SIZES_SINGLE = 11, so 88 bytes?

for (int i = 0; i < NUM_SIZES_SINGLE; ++i)
{
uint64_t* dst = (((uint64_t*) inPtr) + i);
const char* src = (char*) (((uint64_t*) inPtr) + i);
uint64_t* dst = counterBuf.data() + i;
const char* src = (char*) (counterBuf.data() + i);

Xdr::read<CharPtrIO> (src, *dst);
}
Expand All @@ -2262,7 +2265,7 @@ DwaCompressor::uncompress (
// Unwind all the counter info
//

const uint64_t* inPtr64 = (const uint64_t*) inPtr;
const uint64_t* inPtr64 = counterBuf.data();

uint64_t version = *(inPtr64 + VERSION);
uint64_t unknownUncompressedSize = *(inPtr64 + UNKNOWN_UNCOMPRESSED_SIZE);
Expand Down
10 changes: 10 additions & 0 deletions src/lib/OpenEXR/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
#include <ImfTileDescription.h>
#include <ImfXdr.h>

#include <codecvt>
#include <locale>

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER

using IMATH_NAMESPACE::Box2i;
Expand Down Expand Up @@ -1981,4 +1984,11 @@ getChunkOffsetTableSize (const Header& header)
return getTiledChunkOffsetTableSize (header);
}

std::wstring
WidenFilename (const char* filename)
{
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> converter;
return converter.from_bytes (filename);
}

OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT
8 changes: 8 additions & 0 deletions src/lib/OpenEXR/ImfMisc.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,14 @@ bool usesLongNames (const Header& header);
IMF_EXPORT
int getChunkOffsetTableSize (const Header& header);

//
// Convert a filename to a wide string. This is useful for working with
// filenames on Windows.
//

IMF_EXPORT
std::wstring WidenFilename (const char* filename);

OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT

#endif
15 changes: 1 addition & 14 deletions src/lib/OpenEXR/ImfStdIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//-----------------------------------------------------------------------------

#include "Iex.h"
#include <ImfMisc.h>
#include <ImfStdIO.h>
#include <errno.h>
#ifdef _WIN32
Expand All @@ -35,20 +36,6 @@ namespace
{

#ifdef _WIN32
wstring
WidenFilename (const char* filename)
{
wstring ret;
int fnlen = static_cast<int> (strlen (filename));
int len = MultiByteToWideChar (CP_UTF8, 0, filename, fnlen, NULL, 0);
if (len > 0)
{
ret.resize (len);
MultiByteToWideChar (CP_UTF8, 0, filename, fnlen, &ret[0], len);
}
return ret;
}

# if defined(__GLIBCXX__) && \
!(defined(_GLIBCXX_HAVE_WFOPEN) && defined(_GLIBCXX_USE_WCHAR_T))
# define USE_CUSTOM_WIDE_OPEN 1
Expand Down
16 changes: 2 additions & 14 deletions src/test/OpenEXRTest/TestUtilFStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#ifndef INCLUDE_TestUtilFStream_h_
# define INCLUDE_TestUtilFStream_h_ 1

# include <ImfMisc.h>

# include <fstream>
# include <string>

Expand All @@ -26,20 +28,6 @@
namespace testutil
{
# ifdef _WIN32
inline std::wstring
WidenFilename (const char* filename)
{
std::wstring ret;
int fnlen = static_cast<int> (strlen (filename));
int len = MultiByteToWideChar (CP_UTF8, 0, filename, fnlen, NULL, 0);
if (len > 0)
{
ret.resize (len);
MultiByteToWideChar (CP_UTF8, 0, filename, fnlen, &ret[0], len);
}
return ret;
}

// This is a big work around mechanism for compiling using mingw / gcc under windows
// until mingw 9 where they add the wide filename version of open
# if ( \
Expand Down
Loading