37 template<
class StructHeader>
54 StructHeader*
header() {
return reinterpret_cast<StructHeader*
>(
data()); }
112 template<
typename ValType, ImgOptions OPTIONS>
122 ValType&
operator()(
unsigned dx,
unsigned dy,
unsigned channel = 0);
160 template<
typename UserType, ImgOptions OPTIONS = ImgOptions::RowMajor>
162 [[maybe_unused]]
auto* h =
header();
163 assert(h->channels > 0 &&
"call setShape() before interpretedView()!");
164 assert(h->bytesPerPixel == h->channels *
sizeof(UserType) &&
165 "choose correct bytesPerPixel and channels value before conversion!");
168 "inconsistent data ordering col/row major");
179 template<
class StructHeader>
182 : _accToData(accToData) {
183 static_assert(std::is_base_of<OpaqueStructHeader, StructHeader>::value,
184 "MappedStruct expects StructHeader to implement OpaqueStructHeader");
190 template<
class StructHeader>
192 return _accToData.data();
195 template<
class StructHeader>
198 return const_cast<MappedStruct*
>(
this)->_accToData.getNElements();
201 template<
class StructHeader>
203 size_t sh =
sizeof(StructHeader);
204 if(capacity() < sh) {
205 throw logic_error(
"buffer provided to MappedStruct is too small for correct initialization");
209 header()->totalLength = sh;
210 memset(p + sh, 0, capacity() - sh);
218 assert(
false &&
"ImgFormat::Unset not allowed");
241 bytesPerPixel = 4 * channels;
248 bytesPerPixel = 8 * channels;
255 unsigned bytesPerPixel;
257 return sizeof(
ImgHeader) + (
size_t)width * height * bytesPerPixel;
262 unsigned bytesPerPixel;
266 throw logic_error(
"MappedImage: provided buffer to small for requested image shape");
272 h->totalLength = totalLen;
275 h->channels = channels;
276 h->bytesPerPixel = bytesPerPixel;
279 template<
typename ValType, ImgOptions OPTIONS>
282 assert(dy < h->height);
283 assert(dx < h->width);
284 assert(channel < h->channels);
292 return vec()[(dy * h->width + dx) * h->channels + channel];
295 return vec()[(dy + dx * h->height) * h->channels + channel];
299 template<
typename ValType, ImgOptions OPTIONS>
301 return _mi->header();
304 template<
typename ValType, ImgOptions OPTIONS>
306 return reinterpret_cast<ValType*
>(_mi->imgBody());
provides convenient matrix-like access for MappedImage
ValType & operator()(unsigned dx, unsigned dy, unsigned channel=0)
This allows to read/write image pixel values, for given coordinates.
ValType * endRow(unsigned row)
ImgView(MappedImage *owner)
ValType * beginRow(unsigned row)
interface to an image that is mapped onto a 1D array of ValType
ImgView< UserType, OPTIONS > interpretedView()
returns an ImgView object which can be used like a matrix.
void formatsDefinition(ImgFormat fmt, unsigned &channels, unsigned &bytesPerPixel)
size_t lengthForShape(unsigned width, unsigned height, ImgFormat fmt)
void setShape(unsigned width, unsigned height, ImgFormat fmt)
needs to be called after construction.
unsigned char * imgBody()
returns pointer to image payload data
Provides interface to a struct that is mapped onto a 1D array of ValType StructHeader must be derived...
StructHeader * header()
returns header, e.g. for setting meta data
ChimeraTK::OneDRegisterAccessor< unsigned char > & _accToData
void initData()
default initialize header and zero out data that follows
MappedStruct(ChimeraTK::OneDRegisterAccessor< unsigned char > &accToData, InitData doInitData=InitData::No)
This keeps a reference to given OneDRegisterAccessor.
size_t capacity() const
capacity of used container
size_t size() const
currently used size
unsigned char * data()
returns pointer to data for header and struct content.
Accessor class to read and write registers transparently by using the accessor object like a vector o...
Exception thrown when a logic error has occured.