14 #include <peak_ipl/peak_ipl.hpp> 37 inline peak::ipl::Image BufferTo<peak::ipl::Image>(
const std::shared_ptr<peak::core::Buffer>& buffer)
39 if (buffer ==
nullptr)
44 if (buffer->HasImage())
49 size_t usableHeight = buffer->Height();
50 const size_t usableWidth = buffer->Width();
51 size_t usableBytes = buffer->Size() - buffer->ImageOffset();
52 uint8_t* firstPixelPtr =
static_cast<uint8_t*
>(buffer->BasePtr()) + buffer->ImageOffset();
54 if (buffer->HasChunks())
56 auto chunks = buffer->Chunks();
63 const auto imageSizeWithoutChunks = chunks[0]->Size();
65 for (
const auto& chunk : chunks)
67 if (0x73020405 == chunk->ID())
69 uint16_t* chunkBase =
static_cast<uint16_t*
>(chunk->BasePtr());
71 usableHeight =
static_cast<size_t>(chunkBase[1]);
72 const auto usableOffsetY =
static_cast<size_t>(chunkBase[3]);
75 const auto pitch = imageSizeWithoutChunks / buffer->Height();
76 const auto cutOffTop = pitch * usableOffsetY;
77 const auto cutOff = (buffer->Height() - usableHeight) * pitch;
79 firstPixelPtr += cutOffTop;
80 usableBytes = imageSizeWithoutChunks - cutOff;
87 return peak::ipl::Image(static_cast<peak::ipl::PixelFormatName>(buffer->PixelFormat()),
88 firstPixelPtr, usableBytes, usableWidth, usableHeight, buffer->Timestamp_ns());
92 auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps()[0];
93 remoteNodeMap->UpdateChunkNodes(buffer);
100 auto width = chunkWidth->Value();
107 auto height = chunkHeight->Value();
114 auto pixelFormatValue = chunkPixelFormat->CurrentEntry()->NumericValue();
115 auto pixelFormat =
static_cast<peak::ipl::PixelFormatName
>(pixelFormatValue);
118 auto imageData = buffer->Chunks()[0];
120 auto expectedDataSize = peak::ipl::PixelFormat(pixelFormat).CalculateStorageSizeOfPixels(static_cast<uint64_t>(width * height));
121 if (imageData->Size() < expectedDataSize)
123 std::stringstream msg;
124 msg <<
"The buffer's first chunk's size (" << imageData->Size()
125 <<
") is smaller than the expected data size (" << expectedDataSize <<
").";
129 return peak::ipl::Image(pixelFormat, static_cast<uint8_t*>(imageData->BasePtr()), imageData->Size(),
130 static_cast<size_t>(width), static_cast<size_t>(height), buffer->Timestamp_ns());
Represents a GenAPI integer node.
Definition: peak_integer_node.hpp:35
The exception thrown for pass an invalid argument to a function.
Definition: peak_exception.hpp:73
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition: peak_dynamic_loader.h:32
The exception thrown for trying to apply an invalid cast.
Definition: peak_exception.hpp:81
The exception thrown for internal errors.
Definition: peak_exception.hpp:57
Represents a GenAPI enumeration node.
Definition: peak_enumeration_node.hpp:36