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();
52 if (buffer->HasChunks())
54 auto chunks = buffer->Chunks();
55 for (
const auto& chunk : chunks)
57 if (0x73020405 == chunk->ID())
59 uint16_t* chunkBase =
static_cast<uint16_t*
>(chunk->BasePtr());
61 usableHeight =
static_cast<size_t>(chunkBase[1]);
62 size_t usableOffsetY =
static_cast<size_t>(chunkBase[3]);
65 size_t pitch = buffer->Size() / buffer->Height();
66 cutOff = pitch * usableOffsetY;
73 return peak::ipl::Image(static_cast<peak::ipl::PixelFormatName>(buffer->PixelFormat()),
74 static_cast<uint8_t*>(buffer->BasePtr()) + buffer->ImageOffset() + cutOff, buffer->Size() - buffer->ImageOffset() - cutOff,
75 buffer->Width(), usableHeight, buffer->Timestamp_ns());
79 auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps()[0];
80 remoteNodeMap->UpdateChunkNodes(buffer);
87 auto width = chunkWidth->Value();
94 auto height = chunkHeight->Value();
101 auto pixelFormatValue = chunkPixelFormat->CurrentEntry()->NumericValue();
102 auto pixelFormat =
static_cast<peak::ipl::PixelFormatName
>(pixelFormatValue);
105 auto imageData = buffer->Chunks()[0];
107 auto expectedDataSize = peak::ipl::PixelFormat(pixelFormat).CalculateStorageSizeOfPixels(static_cast<uint64_t>(width * height));
108 if (imageData->Size() < expectedDataSize)
110 std::stringstream msg;
111 msg <<
"The buffer's first chunk's size (" << imageData->Size()
112 <<
") is smaller than the expected data size (" << expectedDataSize <<
").";
116 return peak::ipl::Image(pixelFormat, static_cast<uint8_t*>(imageData->BasePtr()), imageData->Size(),
117 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
Represents a GenAPI enumeration node.
Definition: peak_enumeration_node.hpp:36