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");
180 template<
class StructHeader>
183 : _accToData(accToData) {
184 static_assert(std::is_base_of<OpaqueStructHeader, StructHeader>::value,
185 "MappedStruct expects StructHeader to implement OpaqueStructHeader");
191 template<
class StructHeader>
193 return _accToData.data();
196 template<
class StructHeader>
199 return const_cast<MappedStruct*
>(
this)->_accToData.getNElements();
202 template<
class StructHeader>
204 size_t sh =
sizeof(StructHeader);
205 if(capacity() < sh) {
206 throw logic_error(
"buffer provided to MappedStruct is too small for correct initialization");
210 header()->totalLength = sh;
211 memset(p + sh, 0, capacity() - sh);
217 unsigned channels{0}, bytesPerPixel{0};
220 assert(
false &&
"ImgFormat::Unset not allowed");
240 bytesPerPixel = 4 * channels;
244 bytesPerPixel = 4 * channels;
248 bytesPerPixel = 4 * channels;
252 bytesPerPixel = 4 * channels;
256 bytesPerPixel = 8 * channels;
260 bytesPerPixel = 8 * channels;
264 bytesPerPixel = 8 * channels;
268 bytesPerPixel = 8 * channels;
271 return {channels, bytesPerPixel};
276 return sizeof(
ImgHeader) +
size_t(width) * height * bytesPerPixel;
283 throw logic_error(
"MappedImage: provided buffer to small for requested image shape");
289 h->totalLength = totalLen;
292 h->channels = channels;
293 h->bytesPerPixel = bytesPerPixel;
296 template<
typename ValType, ImgOptions OPTIONS>
299 assert(dy < h->height);
300 assert(dx < h->width);
301 assert(channel < h->channels);
309 return vec()[(dy * h->width + dx) * h->channels + channel];
312 return vec()[(dy + dx * h->height) * h->channels + channel];
316 template<
typename ValType, ImgOptions OPTIONS>
318 return _mi->header();
321 template<
typename ValType, ImgOptions OPTIONS>
323 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.
static std::pair< uint32_t, uint32_t > getFormatDefinition(ImgFormat fmt)
Returns a pair of nChannels and nBytesPerPixel matching to the image format.
static 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.