7 #include "fwDataTools/ImageDiff.hpp" 15 m_imgEltSize(imageElementSize),
16 m_eltSize(imageElementSize * 2 + sizeof(::
fwData::
Image::IndexType)),
18 m_reservedSize(reservedElements * imageElementSize),
33 m_imgEltSize(other.m_imgEltSize),
34 m_eltSize(other.m_eltSize),
35 m_nbElts(other.m_nbElts),
36 m_reservedSize(other.m_reservedSize),
37 m_buffer(reinterpret_cast<
std::uint8_t*>(malloc(other.m_reservedSize)))
39 std::memcpy(m_buffer, other.m_buffer, m_reservedSize);
45 m_imgEltSize(other.m_imgEltSize),
46 m_eltSize(other.m_eltSize),
47 m_nbElts(other.m_nbElts),
48 m_reservedSize(other.m_reservedSize),
49 m_buffer(other.m_buffer)
51 other.m_buffer =
nullptr;
59 *
this = std::move(tmpImageDiffs);
70 m_buffer = other.m_buffer;
71 other.m_buffer =
nullptr;
73 m_imgEltSize = other.m_imgEltSize;
74 m_eltSize = other.m_eltSize;
75 m_nbElts = other.m_nbElts;
76 m_reservedSize = other.m_reservedSize;
85 SLM_ASSERT(
"Diff elements must be the same size.", m_eltSize == diff.m_eltSize);
87 const size_t oldSize = this->
getSize();
88 const size_t newSize = oldSize + diff.
getSize();
90 if(m_reservedSize < newSize || m_buffer ==
nullptr)
93 m_reservedSize = newSize + m_reservedSize * 2;
94 m_buffer =
reinterpret_cast<std::uint8_t*
>(realloc(m_buffer, m_reservedSize));
96 SLM_FATAL_IF(
"Reallocation failed.", m_buffer ==
nullptr);
99 std::uint8_t* eltPtr = (m_buffer + oldSize);
100 std::memcpy(eltPtr, diff.m_buffer, diff.
getSize());
102 m_nbElts += diff.m_nbElts;
107 void ImageDiff::addDiff(const ::fwData::Image::IndexType index, const ::fwData::Image::BufferType* oldValue,
108 const ::fwData::Image::BufferType* newValue)
110 const size_t oldSize = this->
getSize();
111 const size_t newSize = oldSize + m_eltSize;
113 if(m_reservedSize < newSize || m_buffer ==
nullptr)
116 m_reservedSize = m_reservedSize * 2 + m_eltSize;
117 m_buffer =
reinterpret_cast<std::uint8_t*
>(realloc(m_buffer, m_reservedSize));
119 SLM_FATAL_IF(
"Reallocation failed.", m_buffer ==
nullptr);
122 std::uint8_t* eltPtr = (m_buffer + oldSize);
124 std::memcpy(eltPtr, &index,
sizeof(index));
125 size_t offset =
sizeof(index);
126 std::memcpy(eltPtr + offset, oldValue, m_imgEltSize);
127 offset += m_imgEltSize;
128 std::memcpy(eltPtr + offset, newValue, m_imgEltSize);
139 for(
size_t i = 0; i < m_nbElts; ++i)
141 applyDiffElt(imgHelper, i);
151 for(
size_t i = 0; i < m_nbElts; ++i)
153 revertDiffElt(imgHelper, i);
161 return m_nbElts * m_eltSize;
182 m_reservedSize = this->
getSize();
183 m_buffer =
reinterpret_cast<std::uint8_t*
>(realloc(m_buffer, m_reservedSize));
185 SLM_FATAL_IF(
"Reallocation failed.", m_buffer ==
nullptr);
192 std::uint8_t* eltPtr = m_buffer + index * m_eltSize;
194 elt.m_index = *
reinterpret_cast< ::fwData::Image::IndexType*
>(eltPtr);
196 size_t offset =
sizeof(::fwData::Image::IndexType);
198 elt.m_oldValue =
reinterpret_cast< ::fwData::Image::BufferType*
>(eltPtr + offset);
200 offset += m_imgEltSize;
202 elt.m_newValue =
reinterpret_cast< ::fwData::Image::BufferType*
>(eltPtr + offset);
209 void ImageDiff::applyDiffElt(
helper::Image& img,
size_t eltIndex)
const 211 std::uint8_t* eltPtr = m_buffer + eltIndex * m_eltSize;
212 const ::fwData::Image::IndexType index = *
reinterpret_cast< ::fwData::Image::IndexType*
>(eltPtr);
214 const size_t offset =
sizeof(index) + m_imgEltSize;
216 ::fwData::Image::BufferType* newValue =
reinterpret_cast< ::fwData::Image::BufferType*
>(eltPtr + offset);
223 void ImageDiff::revertDiffElt(
helper::Image& img,
size_t eltIndex)
const 225 std::uint8_t* eltPtr = m_buffer + eltIndex * m_eltSize;
226 const ::fwData::Image::IndexType index = *
reinterpret_cast< ::fwData::Image::IndexType*
>(eltPtr);
228 const size_t offset =
sizeof(index);
230 ::fwData::Image::BufferType* oldValue =
reinterpret_cast< ::fwData::Image::BufferType*
>(eltPtr + offset);
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
#define SLM_FATAL_IF(message, cond)
Contains the representation of the data objects used in the framework.