35 #ifndef CHANNEL_UTILITIES_HH
36 #define CHANNEL_UTILITIES_HH
41 #include <MultiSense/MultiSenseChannel.hh>
53 channelPtr_(
Channel::Create(ipAddress))
86 callbackBuffer_(driver->reserveCallbackBuffer()),
94 driver_->releaseCallbackBuffer(callbackBuffer_);
120 const uint8_t* lumaP =
reinterpret_cast<const uint8_t*
>(luma.
imageDataP);
121 const uint8_t* chromaP =
reinterpret_cast<const uint8_t*
>(chroma.
imageDataP);
123 const size_t luma_offset = (v * luma.
width) + u;
124 const size_t chroma_offset = 2 * (((v / 2) * (luma.
width / 2)) + (u / 2));
126 const float px_y =
static_cast<float>(lumaP[luma_offset]);
127 const float px_cb =
static_cast<float>(chromaP[chroma_offset + 0]) - 128.0
f;
128 const float px_cr =
static_cast<float>(chromaP[chroma_offset + 1]) - 128.0
f;
130 float px_r = px_y + 1.13983f * px_cr;
131 float px_g = px_y - 0.39465f * px_cb - 0.58060f * px_cr;
132 float px_b = px_y + 2.03211f * px_cb;
134 if (px_r < 0.0
f) px_r = 0.0f;
135 else if (px_r > 255.0
f) px_r = 255.0f;
136 if (px_g < 0.0
f) px_g = 0.0f;
137 else if (px_g > 255.0
f) px_g = 255.0f;
138 if (px_b < 0.0
f) px_b = 0.0f;
139 else if (px_b > 255.0
f) px_b = 255.0f;
141 return { {
static_cast<uint8_t
>(px_r),
static_cast<uint8_t
>(px_g),
static_cast<uint8_t
>(px_b)} };
150 throw std::runtime_error(
"Only 8-bit luma and 16-bit chroma images are supported by the \
151 ycbcrToBgr conversion function");
154 const size_t rgb_stride = luma.
width * 3;
156 for (uint32_t y = 0; y < luma.
height; ++y)
158 const size_t row_offset = y * rgb_stride;
160 for (uint32_t x = 0; x < luma.
width; ++x)
162 memcpy(output + row_offset + (3 * x), ycbcrToBgr<uint8_t>(luma, chroma, x, y).data(), 3);
167 #endif //CHANNEL_UTILITIES_HH