Skip to content

Commit

Permalink
dpx: use OIIO functions for byte swapping to make Sonar happy (Academ…
Browse files Browse the repository at this point in the history
…ySoftwareFoundation#4174)

Signed-off-by: Larry Gritz <lg@larrygritz.com>
  • Loading branch information
lgritz authored Mar 5, 2024
1 parent 2fc8fe9 commit 0e5292b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/dpx.imageio/dpxinput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@

// Note: libdpx originally from: https://github.com/PatrickPalmer/dpx
// But that seems not to be actively maintained.
//
// Nevertheless, because the contents of the libdpx subdirectory is "imported"
// code, we have always strived to keep our copy as textually close to the
// original as possible, to enable us to diff it against the original and keep
// up with any changes (if there ever are any). So we exclude this file from
// clang-format and try to keep changes as minimal as possible.
//
// At some point, we may want to consider just accepting that we forked long
// ago and are probably the sole maintainers of this code, and just allow
// ourselves to diverge from the original.

#include "libdpx/DPX.h"
#include "libdpx/DPXColorConverter.h"
#include "libdpx/DPXHeader.h"
Expand Down
24 changes: 24 additions & 0 deletions src/dpx.imageio/libdpx/EndianSwap.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,32 @@
#ifndef _DPX_ENDIANSWAP_H
#define _DPX_ENDIANSWAP_H 1

#include <OpenImageIO/fmath.h>

#define USE_OIIO_BYTESWAP 1


namespace dpx
{

#if USE_OIIO_BYTESWAP

template<typename T>
inline T
SwapBytes(T& value)
{
return value = OIIO::byteswap(value);
}

template<typename T>
void
SwapBuffer(T* buf, unsigned int len)
{
OIIO::byteswap_span(OIIO::span<T>(buf, len));
}

#else

template <typename T>
T SwapBytes(T& value)
{
Expand Down Expand Up @@ -92,6 +114,8 @@ void SwapBuffer(T *buf, unsigned int len)
SwapBytes(buf[i]);
}

#endif


template <DataSize SIZE>
void EndianSwapImageBuffer(void *data, int length)
Expand Down

0 comments on commit 0e5292b

Please sign in to comment.