| 8 | namespace PJ { |
| 9 | |
| 10 | QImage imageForActiveFrame(const unsigned char* data, int size_bytes) { |
| 11 | using namespace pj_raster; |
| 12 | if (data == nullptr || size_bytes < static_cast<int>(sizeof(ShmHeader))) { |
| 13 | return {}; |
| 14 | } |
| 15 | const auto* hdr = reinterpret_cast<const ShmHeader*>(data); |
| 16 | if (hdr->magic != kShmMagic || hdr->version != kShmVersion || hdr->bytes_per_pixel != kBytesPerPixel || |
| 17 | hdr->width == 0 || hdr->height == 0 || hdr->active_index >= hdr->buffer_count) { |
| 18 | return {}; |
| 19 | } |
| 20 | const uint32_t need = shmTotalSize(hdr->width, hdr->height, hdr->bytes_per_pixel); |
| 21 | if (size_bytes < static_cast<int>(need)) { |
| 22 | return {}; |
| 23 | } |
| 24 | const uint32_t off = bufferOffset(hdr->active_index, hdr->width, hdr->height, hdr->bytes_per_pixel); |
| 25 | const uchar* pixels = data + off; |
| 26 | return QImage( |
| 27 | pixels, static_cast<int>(hdr->width), static_cast<int>(hdr->height), |
| 28 | static_cast<int>(hdr->width * hdr->bytes_per_pixel), QImage::Format_RGB32); |
| 29 | } |
| 30 | |
| 31 | } // namespace PJ |