14 #include <peak_ipl/peak_ipl.hpp> 37 inline peak::ipl::Image BufferTo<peak::ipl::Image>(
const std::shared_ptr<core::Buffer>& buffer)
39 if (buffer->HasImage())
44 size_t usableHeight = buffer->Height();
47 if (buffer->HasChunks())
49 auto chunks = buffer->Chunks();
50 for (
const auto& chunk : chunks)
52 if (0x73020405 == chunk->ID())
54 uint16_t* chunkBase =
static_cast<uint16_t*
>(chunk->BasePtr());
56 usableHeight =
static_cast<size_t>(chunkBase[1]);
57 size_t usableOffsetY =
static_cast<size_t>(chunkBase[3]);
60 size_t pitch = buffer->Size() / buffer->Height();
61 cutOff = pitch * usableOffsetY;
68 return peak::ipl::Image(static_cast<peak::ipl::PixelFormatName>(buffer->PixelFormat()),
69 static_cast<uint8_t*>(buffer->BasePtr()) + buffer->ImageOffset() + cutOff, buffer->Size() - buffer->ImageOffset() - cutOff,
70 buffer->Width(), usableHeight);
74 auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps()[0];
75 remoteNodeMap->UpdateChunkNodes(buffer);
82 auto width = chunkWidth->Value();
89 auto height = chunkHeight->Value();
96 auto pixelFormatValue = chunkPixelFormat->CurrentEntry()->NumericValue();
97 auto pixelFormat =
static_cast<peak::ipl::PixelFormatName
>(pixelFormatValue);
100 auto imageData = buffer->Chunks()[0];
102 auto expectedDataSize = peak::ipl::PixelFormat(pixelFormat).CalculateStorageSizeOfPixels(width * height);
103 if (imageData->Size() < expectedDataSize)
105 std::stringstream msg;
106 msg <<
"The buffer's first chunk's size (" << imageData->Size()
107 <<
") is smaller than the expected data size (" << expectedDataSize <<
").";
111 return peak::ipl::Image(pixelFormat, static_cast<uint8_t*>(imageData->BasePtr()), imageData->Size(),
112 static_cast<size_t>(width), static_cast<size_t>(height));
Represents a GenAPI integer node.
Definition: peak_integer_node.hpp:35
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