44 const std::shared_ptr<peak::core::BufferChunk>& chunk)
51 const auto* base =
static_cast<uint16_t*
>(chunk->BasePtr());
52 return { base[0], base[1], base[2], base[3] };
56 const std::vector<std::shared_ptr<peak::core::BufferChunk>>& chunks, uint64_t chunkId)
58 const auto it = std::find_if(
59 chunks.cbegin(), chunks.cend(), [chunkId](
const auto& chunk) { return chunk->ID() == chunkId; });
60 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)
113 const std::shared_ptr<peak::core::Buffer>& buffer)
120 result.
size = {
static_cast<uint32_t
>(buffer->Width()),
static_cast<uint32_t
>(buffer->Height()) };
122 result.
dataPtr =
static_cast<uint8_t*
>(buffer->BasePtr()) + buffer->ImageOffset();
126 result.
bytesPerLine = pixelFormatInfo.GetSizeInBytes({
static_cast<uint32_t
>(buffer->Width()), 1 });
128 result.
dataSize = pixelFormatInfo.GetSizeInBytes(
129 {
static_cast<uint32_t
>(buffer->Width()),
static_cast<uint32_t
>(buffer->Height()) });
131 const auto imageSizeWithPadding = buffer->Size() - buffer->ImageOffset();
132 if (result.
dataSize > imageSizeWithPadding)
137 if (buffer->HasChunks())
146 const std::shared_ptr<peak::core::Buffer>& buffer)
148 const auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps().at(0);
149 remoteNodeMap->UpdateChunkNodes(buffer);
164 static_cast<uint32_t
>(chunkWidth->Value()),
static_cast<uint32_t
>(chunkHeight->Value()));
173 chunkPixelFormat->CurrentEntry()->NumericValue());
177 if (imageChunk ==
nullptr)
182 const auto sizeInBytes = imageChunk->Size();
185 const auto expectedDataSize = pixelFormatInfo.GetSizeInBytes(size);
186 if (sizeInBytes < expectedDataSize)
188 std::stringstream msg;
189 msg <<
"The buffer's first chunk's size (" << imageChunk->Size() <<
") is smaller than the expected data size ("
190 << expectedDataSize <<
").";
194 return { size, pixelFormat, imageChunk->BasePtr(), sizeInBytes,
199 const std::shared_ptr<peak::core::BufferPart>& part)
206 const auto partType = part->Type();
220 return {
peak::common::Size{
static_cast<uint32_t
>(part->Width()),
static_cast<uint32_t
>(part->Height()) },
221 pixelFormat, part->BasePtr(), part->Size(), bytesPerLine, 0 };
225 const std::shared_ptr<peak::core::Buffer>& buffer)
227 if (buffer ==
nullptr)
232 if (buffer->HasImage())
248 if (buffer ==
nullptr)
253 auto metadata = std::make_shared<peak::common::Metadata>();
281 const auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps().at(0);
282 const auto chunkExposureTimeNode = remoteNodeMap->TryFindNode<
nodes::FloatNode>(
"ChunkExposureTime");
283 const auto chunkGainSelectorNode = remoteNodeMap->TryFindNode<
nodes::EnumerationNode>(
"ChunkGainSelector");
284 const auto chunkGainNode = remoteNodeMap->TryFindNode<
nodes::FloatNode>(
"ChunkGain");
286 const auto lock = remoteNodeMap->Lock();
287 remoteNodeMap->UpdateChunkNodes(buffer);
289 if (chunkExposureTimeNode !=
nullptr && chunkExposureTimeNode->IsReadable())
295 && chunkGainNode !=
nullptr)
297 const auto availableEntries = chunkGainSelectorNode->AvailableEntries();
300 auto readChunkGain = [&](
const std::string& entryName) {
301 const auto entry = chunkGainSelectorNode->TryFindEntry(entryName);
302 if (entry ==
nullptr || !entry->IsAvailable())
307 chunkGainSelectorNode->SetCurrentEntry(entry);
313 return chunkGainNode->Value();
316 const auto gainAll = readChunkGain(
"All");
317 const auto gainAnalogAll = readChunkGain(
"AnalogAll");
318 const auto gainDigitalAll = readChunkGain(
"DigitalAll");
323 gainAll * gainAnalogAll * gainDigitalAll);
333 const detail::ExtractedPayload& payload, std::shared_ptr<peak::common::Metadata> metadata)
334 : m_metadata{ std::move(metadata) }
335 , m_payload{ payload }
342 m_parentBuffer = buffer;
346 :
ImageView(
detail::ExtractPayloadFromBuffer(buffer),
detail::ExtractMetadataFromBuffer(buffer, mode))
348 m_parentBuffer = buffer;
355 m_parentBuffer = part->ParentBuffer();
360 detail::ExtractPayloadFromBufferPart(part),
detail::ExtractMetadataFromBuffer(part->ParentBuffer(), mode))
362 m_parentBuffer = part->ParentBuffer();
367 return static_cast<uint8_t*
>(m_payload.dataPtr);
372 return static_cast<uint8_t*
>(m_payload.dataPtr);
377 return m_payload.lineStartOffset;
382 return m_payload.dataSize;
387 return m_payload.pixelFormat;
397 return m_payload.size;
407 return m_payload.size.GetHeight();
417 return m_payload.bytesPerLine;
432 return LockOrThrow(m_parentBuffer);
PEAK_COMMON_NO_DISCARD constexpr T GetWidth() const
Returns the width.
Definition peak_common_size.hpp:114
The base class for all exceptions thrown by the library.
Definition peak_exception.hpp:24
PEAK_COMMON_NO_DISCARD uint32_t GetHeight() const override
Height of the image in pixels.
Definition peak_image_view_impl.hpp:405
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:380
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:375
PEAK_COMMON_NO_DISCARD size_t GetBytesPerLine() const override
The amount of bytes per line.
Definition peak_image_view_impl.hpp:415
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:390
PEAK_COMMON_NO_DISCARD size_t GetBitsPerPixel() const override
The amount of bits in one pixel.
Definition peak_image_view_impl.hpp:410
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:430
PEAK_COMMON_NO_DISCARD uint32_t GetWidth() const override
Width of the image in pixels.
Definition peak_image_view_impl.hpp:400
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:365
ImageView(const std::shared_ptr< Buffer > &buffer)
Construct an ImageView from a Buffer.
Definition peak_image_view_impl.hpp:338
PEAK_COMMON_NO_DISCARD peak::common::PixelFormat GetPixelFormat() const override
PixelFormat of the contained image.
Definition peak_image_view_impl.hpp:385
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:395
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:420
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:118
The exception thrown for trying to apply an invalid cast.
Definition peak_exception.hpp:146
Represents a GenAPI enumeration node.
Definition peak_enumeration_node.hpp:37
Represents a GenAPI float node.
Definition peak_float_node.hpp:48
Represents a GenAPI integer node.
Definition peak_integer_node.hpp:38
PEAK_COMMON_NO_DISCARD bool IsReadable() const
Returns whether the node is currently readable.
Definition peak_node.hpp:874
PEAK_COMMON_NO_DISCARD NodeAccessStatus AccessStatus() const
Returns the access status.
Definition peak_node.hpp:866
@ Image3D
Definition peak_buffer_part.hpp:40
@ ConfidenceMap
Definition peak_buffer_part.hpp:44
@ Image2D
Definition peak_buffer_part.hpp:36
@ Chunk
Definition peak_buffer.hpp:46
@ Custom
Definition peak_buffer.hpp:70
@ IIDC
Definition peak_buffer.hpp:66
detail::SizeT< uint32_t > Size
Size with unsigned 32-bit integer dimensions.
Definition peak_common_size.hpp:268
PixelFormat
Enum listing all supported pixel formats and their internal IDs.
Definition peak_common_pixel_format.hpp:59
@ NotAvailable
Definition peak_node.hpp:45
@ ReadWrite
Definition peak_node.hpp:48
@ DeviceGain
Device gain the image was captured with.
Definition peak_common_metadata_key.hpp:126
@ DeviceExposureTime
Device exposure time the image was captured with.
Definition peak_common_metadata_key.hpp:89
@ DeviceTimestamp
Device-provided image acquisition timestamp in nanoseconds.
Definition peak_common_metadata_key.hpp:38
@ SystemTimestamp
Timestamp of the system since unix epoch in nanoseconds.
Definition peak_common_metadata_key.hpp:105
@ DeviceFrameID
A sequentially incremented identifier for the frame.
Definition peak_common_metadata_key.hpp:51
Definition peak_image_view.hpp:29
PEAK_COMMON_NO_DISCARD std::shared_ptr< peak::common::Metadata > ExtractMetadataFromBuffer(const std::shared_ptr< peak::core::Buffer > &buffer, MetadataExtractionMode mode)
Definition peak_image_view_impl.hpp:245
PEAK_COMMON_NO_DISCARD UsableRoiChunkInfo ExtractUsableRoiChunkInfo(const std::shared_ptr< peak::core::BufferChunk > &chunk)
Definition peak_image_view_impl.hpp:43
PEAK_COMMON_NO_DISCARD ExtractedPayload ExtractPayloadFromBuffer(const std::shared_ptr< peak::core::Buffer > &buffer)
Definition peak_image_view_impl.hpp:224
PEAK_COMMON_NO_DISCARD ExtractedPayload ExtractPayloadTypeImage(const std::shared_ptr< peak::core::Buffer > &buffer)
Definition peak_image_view_impl.hpp:112
PEAK_COMMON_NO_DISCARD 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:55
PEAK_COMMON_NO_DISCARD ExtractedPayload ExtractPayloadFromBufferPart(const std::shared_ptr< peak::core::BufferPart > &part)
Definition peak_image_view_impl.hpp:198
PEAK_COMMON_NO_DISCARD ExtractedPayload ExtractPayloadTypeChunk(const std::shared_ptr< peak::core::Buffer > &buffer)
Definition peak_image_view_impl.hpp:145
constexpr uint64_t imageChunkId
Definition peak_image_view_impl.hpp:33
PEAK_COMMON_NO_DISCARD ExtractedPayload UpdatePayloadInfoWithChunks(const peak::core::detail::ExtractedPayload &payload, const std::vector< std::shared_ptr< peak::core::BufferChunk > > &chunks)
Definition peak_image_view_impl.hpp:67
constexpr uint64_t usableRoiChunkId
Definition peak_image_view_impl.hpp:32
The "core" namespace contains the direct GenAPI and GenTL wrapper.
Definition peak_buffer.hpp:32
MetadataExtractionMode
Controls how metadata is extracted when constructing an ImageView.
Definition peak_image_view.hpp:50
@ Minimal
Definition peak_image_view.hpp:55
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_buffer.hpp:29
#define PEAK_COMMON_NO_DISCARD
Definition peak_common_defines.h:89
Definition peak_image_view_impl.hpp:36
uint16_t offsetY
Definition peak_image_view_impl.hpp:40
uint16_t usableWidth
Definition peak_image_view_impl.hpp:37
uint16_t offsetX
Definition peak_image_view_impl.hpp:39
uint16_t usableHeight
Definition peak_image_view_impl.hpp:38