42 if (buffer ==
nullptr)
47 if (buffer->HasImage())
52 size_t usableHeight = buffer->Height();
53 const size_t usableWidth = buffer->Width();
54 size_t usableBytes = buffer->Size() - buffer->ImageOffset();
55 uint8_t* firstPixelPtr =
static_cast<uint8_t*
>(buffer->BasePtr()) + buffer->ImageOffset();
57 if (buffer->HasChunks())
59 auto chunks = buffer->Chunks();
66 const auto imageSizeWithoutChunks = chunks[0]->Size();
68 for (
const auto& chunk : chunks)
70 if (0x73020405 == chunk->ID())
72 uint16_t* chunkBase =
static_cast<uint16_t*
>(chunk->BasePtr());
74 usableHeight =
static_cast<size_t>(chunkBase[1]);
75 const auto usableOffsetY =
static_cast<size_t>(chunkBase[3]);
78 const auto pitch = imageSizeWithoutChunks / buffer->Height();
79 const auto cutOffTop = pitch * usableOffsetY;
80 const auto cutOff = (buffer->Height() - usableHeight) * pitch;
82 firstPixelPtr += cutOffTop;
83 usableBytes = imageSizeWithoutChunks - cutOff;
90 return peak::ipl::Image(
static_cast<peak::ipl::PixelFormatName
>(buffer->PixelFormat()),
91 firstPixelPtr, usableBytes, usableWidth, usableHeight, buffer->Timestamp_ns());
95 auto remoteNodeMap = buffer->ParentDataStream()->ParentDevice()->RemoteDevice()->NodeMaps()[0];
96 remoteNodeMap->UpdateChunkNodes(buffer);
103 auto width = chunkWidth->Value();
110 auto height = chunkHeight->Value();
117 auto pixelFormatValue = chunkPixelFormat->CurrentEntry()->NumericValue();
118 auto pixelFormat =
static_cast<peak::ipl::PixelFormatName
>(pixelFormatValue);
121 auto imageData = buffer->Chunks()[0];
123 auto expectedDataSize = peak::ipl::PixelFormat(pixelFormat).CalculateStorageSizeOfPixels(
static_cast<uint64_t
>(width * height));
124 if (imageData->Size() < expectedDataSize)
126 std::stringstream msg;
127 msg <<
"The buffer's first chunk's size (" << imageData->Size()
128 <<
") is smaller than the expected data size (" << expectedDataSize <<
").";
132 return peak::ipl::Image(pixelFormat,
static_cast<uint8_t*
>(imageData->BasePtr()), imageData->Size(),
133 static_cast<size_t>(width),
static_cast<size_t>(height), buffer->Timestamp_ns());
The "peak" namespace directly contains convenience functionality like the DeviceManager as well as th...
Definition peak_dynamic_loader.h:32
peak::ipl::Image BufferTo< peak::ipl::Image >(const std::shared_ptr< peak::core::Buffer > &buffer)
Converts a core::Buffer into a peak::ipl::Image.
Definition peak_buffer_converter_ipl.hpp:40