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

dpx: use OIIO functions for byte swapping to make Sonar happy #4174

Merged
merged 2 commits into from
Mar 5, 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
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
Loading