@@ -47,6 +47,11 @@ void SolumIGTL::setNodeName(const QString &name)
4747 nodeName_ = name.toStdString ();
4848}
4949
50+ void SolumIGTL::setFlip (bool flip)
51+ {
52+ flip_ = flip;
53+ }
54+
5055void SolumIGTL::sendImage (const void * img, int w, int h, int bpp, size_t sz)
5156{
5257 if (!isClientConnected ())
@@ -69,9 +74,27 @@ void SolumIGTL::sendImage(const void* img, int w, int h, int bpp, size_t sz)
6974 // Also necessary to force a repack below.
7075 msg_->SetMessageID (msg_->GetMessageID () + 1 );
7176
72- // Even C++23 does not have output ranges anyway...
73- // (https://thephd.dev/output-ranges)
74- memcpy (msg_->GetScalarPointer (), img, sz);
77+ if (flip_)
78+ {
79+ // Copy the image upside down
80+ const auto stride = (w * (bpp / 8 ));
81+ auto * dst_row = reinterpret_cast <std::byte *>(msg_->GetScalarPointer ());
82+ const auto * src_row = (
83+ reinterpret_cast <const std::byte *>(img) + sz - stride
84+ );
85+ for (int y = 0 ; y < h; y++)
86+ {
87+ memcpy (dst_row, src_row, stride);
88+ dst_row += stride;
89+ src_row -= stride;
90+ }
91+ }
92+ else
93+ {
94+ // Even C++23 does not have output ranges anyway...
95+ // (https://thephd.dev/output-ranges)
96+ memcpy (msg_->GetScalarPointer (), img, sz);
97+ }
7598
7699 msg_->Pack ();
77100 if (client_->Send (msg_->GetPackPointer (), msg_->GetPackSize ()) == 0 )
0 commit comments