Skip to content

Commit bc6ef29

Browse files
lgritzscott-wilson
authored andcommitted
dpx: use OIIO functions for byte swapping to make Sonar happy (AcademySoftwareFoundation#4174)
Signed-off-by: Larry Gritz <[email protected]> Signed-off-by: Scott Wilson <[email protected]>
1 parent 31fe2b0 commit bc6ef29

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/dpx.imageio/dpxinput.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010

1111
// Note: libdpx originally from: https://github.com/PatrickPalmer/dpx
1212
// But that seems not to be actively maintained.
13+
//
14+
// Nevertheless, because the contents of the libdpx subdirectory is "imported"
15+
// code, we have always strived to keep our copy as textually close to the
16+
// original as possible, to enable us to diff it against the original and keep
17+
// up with any changes (if there ever are any). So we exclude this file from
18+
// clang-format and try to keep changes as minimal as possible.
19+
//
20+
// At some point, we may want to consider just accepting that we forked long
21+
// ago and are probably the sole maintainers of this code, and just allow
22+
// ourselves to diverge from the original.
23+
1324
#include "libdpx/DPX.h"
1425
#include "libdpx/DPXColorConverter.h"
1526
#include "libdpx/DPXHeader.h"

src/dpx.imageio/libdpx/EndianSwap.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,32 @@
3636
#ifndef _DPX_ENDIANSWAP_H
3737
#define _DPX_ENDIANSWAP_H 1
3838

39+
#include <OpenImageIO/fmath.h>
40+
41+
#define USE_OIIO_BYTESWAP 1
42+
3943

4044
namespace dpx
4145
{
4246

47+
#if USE_OIIO_BYTESWAP
48+
49+
template<typename T>
50+
inline T
51+
SwapBytes(T& value)
52+
{
53+
return value = OIIO::byteswap(value);
54+
}
55+
56+
template<typename T>
57+
void
58+
SwapBuffer(T* buf, unsigned int len)
59+
{
60+
OIIO::byteswap_span(OIIO::span<T>(buf, len));
61+
}
62+
63+
#else
64+
4365
template <typename T>
4466
T SwapBytes(T& value)
4567
{
@@ -92,6 +114,8 @@ void SwapBuffer(T *buf, unsigned int len)
92114
SwapBytes(buf[i]);
93115
}
94116

117+
#endif
118+
95119

96120
template <DataSize SIZE>
97121
void EndianSwapImageBuffer(void *data, int length)

0 commit comments

Comments
 (0)