#include "vnc_pixel_codecs.h" namespace VncPixelCodecs { QRgb rgbFromPixelBytes(const uchar* bytes) { // Byte order B,G,R,pad -- matches VncSessionBackend's negotiated // SetPixelFormat (32bpp little-endian, R at shift 16 / G at 8 / B at 0). return qRgb(bytes[2], bytes[1], bytes[0]); } int hextileFixedMetaByteCount(quint8 subencoding) { int count = 0; if ((subencoding & HextileFlags::kBackgroundSpecified) != 0) { count += 4; } if ((subencoding & HextileFlags::kForegroundSpecified) != 0) { count += 4; } if ((subencoding & HextileFlags::kAnySubrects) != 0) { count += 1; } return count; } int decodeHextileFixedMeta(quint8 subencoding, const QByteArray& data, QRgb* background, QRgb* foreground) { int offset = 0; const auto* bytes = reinterpret_cast(data.constData()); if ((subencoding & HextileFlags::kBackgroundSpecified) != 0) { *background = rgbFromPixelBytes(bytes + offset); offset += 4; } if ((subencoding & HextileFlags::kForegroundSpecified) != 0) { *foreground = rgbFromPixelBytes(bytes + offset); offset += 4; } if ((subencoding & HextileFlags::kAnySubrects) != 0) { return static_cast(static_cast(data.at(offset))); } return 0; } int hextileSubrectByteCount(bool coloured, int subrectCount) { return subrectCount * (coloured ? 6 : 2); } QVector decodeHextileSubrects(bool coloured, int subrectCount, const QByteArray& data, QRgb foreground) { QVector subrects; subrects.reserve(subrectCount); const auto* bytes = reinterpret_cast(data.constData()); const int stride = coloured ? 6 : 2; for (int i = 0; i < subrectCount; ++i) { const uchar* entry = bytes + (i * stride); QRgb color = foreground; int fieldOffset = 0; if (coloured) { color = rgbFromPixelBytes(entry); fieldOffset = 4; } const uchar xy = entry[fieldOffset]; const uchar wh = entry[fieldOffset + 1]; // High nibble = x (or width-1), low nibble = y (or height-1). const int x = (xy >> 4) & 0x0F; const int y = xy & 0x0F; const int width = ((wh >> 4) & 0x0F) + 1; const int height = (wh & 0x0F) + 1; subrects.append(HextileSubrect{QRect(x, y, width, height), color}); } return subrects; } }