52 const auto* base =
static_cast<uint16_t*
>(chunk->BasePtr());
53 return { base[0], base[1], base[2], base[3] };
57 const std::vector<std::shared_ptr<peak::core::BufferChunk>>& chunks, uint64_t chunkId)
59 const auto it = std::find_if(
60 chunks.cbegin(), chunks.cend(), [chunkId](
const auto& chunk) { return chunk->ID() == chunkId; });
61 if (it == chunks.cend())
69 const std::vector<std::shared_ptr<peak::core::BufferChunk>>& chunks)
72 if (imageChunk ==
nullptr)
77 const auto imageSizeWithPaddingWithoutChunks = imageChunk->Size();
80 if (usableRoiChunk ==
nullptr)
91 auto buffer = imageChunk->ParentBuffer();
92 if (result.
bytesPerLine != imageSizeWithPaddingWithoutChunks / buffer->Height())
97 const auto bytesToSkip = result.
bytesPerLine * chunkInfo.offsetY;
98 result.
dataPtr =
static_cast<void*
>(
static_cast<uint8_t*
>(result.
dataPtr) + bytesToSkip);
103 {
static_cast<uint32_t
>(buffer->Width()), chunkInfo.usableHeight });
104 if (result.
dataSize > imageSizeWithPaddingWithoutChunks)
119 result.
size = {
static_cast<uint32_t
>(buffer->Width()),
static_cast<uint32_t
>(buffer->Height()) };
121 result.
dataPtr =
static_cast<uint8_t*
>(buffer->BasePtr()) + buffer->ImageOffset();
125 result.
bytesPerLine = pixelFormatInfo.GetSizeInBytes({
static_cast<uint32_t
>(buffer->Width()), 1 });
127 result.
dataSize = pixelFormatInfo.GetSizeInBytes(
128 {
static_cast<uint32_t
>(buffer->Width()),
static_cast<uint32_t
>(buffer->Height()) });
130 const auto imageSizeWithPadding = buffer->Size() - buffer->ImageOffset();
131 if (result.
dataSize > imageSizeWithPadding)
136 if (buffer->HasChunks())
146 const auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps().at(0);
147 remoteNodeMap->UpdateChunkNodes(buffer);
162 static_cast<uint32_t
>(chunkWidth->Value()),
static_cast<uint32_t
>(chunkHeight->Value()));
171 chunkPixelFormat->CurrentEntry()->NumericValue());
175 if (imageChunk ==
nullptr)
180 const auto sizeInBytes = imageChunk->Size();
183 const auto expectedDataSize = pixelFormatInfo.GetSizeInBytes(size);
184 if (sizeInBytes < expectedDataSize)
186 std::stringstream msg;
187 msg <<
"The buffer's first chunk's size (" << imageChunk->Size() <<
") is smaller than the expected data size ("
188 << expectedDataSize <<
").";
192 return { size, pixelFormat, imageChunk->BasePtr(), sizeInBytes,
203 const auto partType = part->Type();
217 return {
peak::common::Size{
static_cast<uint32_t
>(part->Width()),
static_cast<uint32_t
>(part->Height()) },
218 pixelFormat, part->BasePtr(), part->Size(), bytesPerLine, 0 };
223 if (buffer ==
nullptr)
228 if (buffer->HasImage())
244 if (buffer ==
nullptr)
249 auto metadata = std::make_shared<peak::common::Metadata>();
277 const auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps().at(0);
278 const auto chunkExposureTimeNode = remoteNodeMap->TryFindNode<
nodes::FloatNode>(
"ChunkExposureTime");
279 const auto chunkGainSelectorNode = remoteNodeMap->TryFindNode<
nodes::EnumerationNode>(
"ChunkGainSelector");
280 const auto chunkGainNode = remoteNodeMap->TryFindNode<
nodes::FloatNode>(
"ChunkGain");
282 const auto lock = remoteNodeMap->Lock();
283 remoteNodeMap->UpdateChunkNodes(buffer);
285 if (chunkExposureTimeNode !=
nullptr && chunkExposureTimeNode->IsReadable())
291 && chunkGainNode !=
nullptr)
293 const auto availableEntries = chunkGainSelectorNode->AvailableEntries();
296 auto readChunkGain = [&](
const std::string& entryName) {
297 const auto entry = chunkGainSelectorNode->TryFindEntry(entryName);
298 if (entry ==
nullptr || !entry->IsAvailable())
303 chunkGainSelectorNode->SetCurrentEntry(entry);
309 return chunkGainNode->Value();
312 const auto gainAll = readChunkGain(
"All");
313 const auto gainAnalogAll = readChunkGain(
"AnalogAll");
314 const auto gainDigitalAll = readChunkGain(
"DigitalAll");
319 gainAll * gainAnalogAll * gainDigitalAll);
329 const detail::ExtractedPayload& payload, std::shared_ptr<peak::common::Metadata> metadata)
330 : m_metadata{ std::move(metadata) }
331 , m_payload{ payload }
338 m_parentBuffer = buffer;
342 :
ImageView(
detail::ExtractPayloadFromBuffer(buffer),
detail::ExtractMetadataFromBuffer(buffer, mode))
344 m_parentBuffer = buffer;
351 m_parentBuffer = part->ParentBuffer();
356 detail::ExtractMetadataFromBuffer(part->ParentBuffer(), mode))
358 m_parentBuffer = part->ParentBuffer();
363 return static_cast<uint8_t*
>(m_payload.dataPtr);
368 return static_cast<uint8_t*
>(m_payload.dataPtr);
373 return m_payload.lineStartOffset;
378 return m_payload.dataSize;
383 return m_payload.pixelFormat;
393 return m_payload.size;
403 return m_payload.size.GetHeight();
413 return m_payload.bytesPerLine;
428 return LockOrThrow(m_parentBuffer);
PEAK_COMMON_NO_DISCARD constexpr T GetWidth() const
Returns the width.
Definition peak_common_size.hpp:119
The base class for all exceptions thrown by the library.
Definition peak_exception.hpp:28
PEAK_COMMON_NO_DISCARD uint32_t GetHeight() const override
Height of the image in pixels.
Definition peak_image_view_impl.hpp:401
PEAK_COMMON_NO_DISCARD std::size_t GetSizeInBytes() const override
Returns the number of bytes in a single image row.
Definition peak_image_view_impl.hpp:376
PEAK_COMMON_NO_DISCARD std::size_t GetLineStartOffset() const override
Returns the byte offset to the first pixel of a line.
Definition peak_image_view_impl.hpp:371
PEAK_COMMON_NO_DISCARD size_t GetBytesPerLine() const override
The amount of bytes per line.
Definition peak_image_view_impl.hpp:411
PEAK_COMMON_NO_DISCARD peak::common::PixelFormatInfo GetPixelFormatInfo() const override
Information object for the PixelFormat of the contained image.
Definition peak_image_view_impl.hpp:386
PEAK_COMMON_NO_DISCARD size_t GetBitsPerPixel() const override
The amount of bits in one pixel.
Definition peak_image_view_impl.hpp:406
PEAK_COMMON_NO_DISCARD std::shared_ptr< peak::core::Buffer > GetParentBuffer() const
The parent buffer object, the image view was created from.
Definition peak_image_view_impl.hpp:426
PEAK_COMMON_NO_DISCARD uint32_t GetWidth() const override
Width of the image in pixels.
Definition peak_image_view_impl.hpp:396
PEAK_COMMON_NO_DISCARD const uint8_t * GetData() const override
Returns a pointer to the start of the first line that contains valid image data (read-only).
Definition peak_image_view_impl.hpp:361
ImageView(const std::shared_ptr< Buffer > &buffer)
Construct an ImageView from a Buffer.
Definition peak_image_view_impl.hpp:334
PEAK_COMMON_NO_DISCARD peak::common::PixelFormat GetPixelFormat() const override
PixelFormat of the contained image.
Definition peak_image_view_impl.hpp:381
PEAK_COMMON_NO_DISCARD peak::common::Size GetSize() const override
Get the dimensions of the image. I.e. Width, Height, etc.
Definition peak_image_view_impl.hpp:391
PEAK_COMMON_NO_DISCARD std::shared_ptr< peak::common::Metadata > GetMetadata() override
The metadata object belonging to the image.
Definition peak_image_view_impl.hpp:416
The exception thrown for internal errors.
Definition peak_exception.hpp:81
The exception thrown for passing an invalid argument to a function.
Definition peak_exception.hpp:116
The exception thrown for trying to apply an invalid cast.
Definition peak_exception.hpp:142
Represents a GenAPI enumeration node.
Definition peak_enumeration_node.hpp:40
Represents a GenAPI float node.
Definition peak_float_node.hpp:48
Represents a GenAPI integer node.
Definition peak_integer_node.hpp:38
bool IsReadable() const
Returns whether the node is currently readable.
Definition peak_node.hpp:843
NodeAccessStatus AccessStatus() const
Returns the access status.
Definition peak_node.hpp:835
@ Image3D
Definition peak_buffer_part.hpp:42
@ ConfidenceMap
Definition peak_buffer_part.hpp:46
@ Image2D
Definition peak_buffer_part.hpp:38
@ Chunk
Definition peak_buffer.hpp:48
@ Custom
Definition peak_buffer.hpp:72
@ IIDC
Definition peak_buffer.hpp:68
detail::SizeT< uint32_t > Size
Size with unsigned 32-bit integer dimensions.
Definition peak_common_size.hpp:273
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Definition peak_common_pixel_format.hpp:51
@ NotAvailable
Definition peak_node.hpp:48
@ ReadWrite
Definition peak_node.hpp:51
@ DeviceGain
Device gain the image was captured with.
Definition peak_common_metadata_key.hpp:131
@ DeviceExposureTime
Device exposure time the image was captured with.
Definition peak_common_metadata_key.hpp:94
@ DeviceTimestamp
Device-provided image acquisition timestamp in nanoseconds.
Definition peak_common_metadata_key.hpp:43
@ SystemTimestamp
Timestamp of the system since unix epoch in nanoseconds.
Definition peak_common_metadata_key.hpp:110
@ DeviceFrameID
A sequentially incremented identifier for the frame.
Definition peak_common_metadata_key.hpp:56
Definition peak_image_view.hpp:31
ExtractedPayload UpdatePayloadInfoWithChunks(const peak::core::detail::ExtractedPayload &payload, const std::vector< std::shared_ptr< peak::core::BufferChunk > > &chunks)
Definition peak_image_view_impl.hpp:68
ExtractedPayload ExtractPayloadFromBuffer(const std::shared_ptr< peak::core::Buffer > &buffer)
Definition peak_image_view_impl.hpp:221
ExtractedPayload ExtractPayloadTypeChunk(const std::shared_ptr< peak::core::Buffer > &buffer)
Definition peak_image_view_impl.hpp:144
std::shared_ptr< core::BufferChunk > FindBufferChunkById(const std::vector< std::shared_ptr< peak::core::BufferChunk > > &chunks, uint64_t chunkId)
Definition peak_image_view_impl.hpp:56
ExtractedPayload ExtractPayloadFromBufferPart(const std::shared_ptr< peak::core::BufferPart > &part)
Definition peak_image_view_impl.hpp:196
UsableRoiChunkInfo ExtractUsableRoiChunkInfo(const std::shared_ptr< peak::core::BufferChunk > &chunk)
Definition peak_image_view_impl.hpp:45
constexpr uint64_t imageChunkId
Definition peak_image_view_impl.hpp:35
std::shared_ptr< peak::common::Metadata > ExtractMetadataFromBuffer(const std::shared_ptr< peak::core::Buffer > &buffer, MetadataExtractionMode mode)
Definition peak_image_view_impl.hpp:241
constexpr uint64_t usableRoiChunkId
Definition peak_image_view_impl.hpp:34
ExtractedPayload ExtractPayloadTypeImage(const std::shared_ptr< peak::core::Buffer > &buffer)
Definition peak_image_view_impl.hpp:112
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:34
MetadataExtractionMode
Controls how metadata is extracted when constructing an ImageView.
Definition peak_image_view.hpp:52
@ Minimal
Definition peak_image_view.hpp:57
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:33
Definition peak_image_view_impl.hpp:38
uint16_t offsetY
Definition peak_image_view_impl.hpp:42
uint16_t usableWidth
Definition peak_image_view_impl.hpp:39
uint16_t offsetX
Definition peak_image_view_impl.hpp:41
uint16_t usableHeight
Definition peak_image_view_impl.hpp:40