Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libvncclient: enhance tight decoder to support all 32bpp pixel formats #606

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 52 additions & 26 deletions src/libvncclient/tight.c
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,9 @@ DecompressJpegRectBPP(rfbClient* client, int x, int y, int w, int h)
int compressedLen;
uint8_t *compressedData, *dst;
int pixelSize, pitch, flags = 0;
#if BPP == 32
int convertingRequired = 0;
#endif

compressedLen = (int)ReadCompactLen(client);
if (compressedLen <= 0) {
Expand Down Expand Up @@ -629,20 +632,40 @@ DecompressJpegRectBPP(rfbClient* client, int x, int y, int w, int h)
}
}

#if BPP == 16
flags = 0;
pixelSize = 3;
pitch = w * pixelSize;
dst = (uint8_t *)client->buffer;
#else
if (client->format.bigEndian) flags |= TJ_ALPHAFIRST;
if (client->format.redShift == 16 && client->format.blueShift == 0)
flags |= TJ_BGR;
if (client->format.bigEndian) flags ^= TJ_BGR;
pixelSize = BPP / 8;
pitch = client->width * pixelSize;
dst = &client->frameBuffer[y * pitch + x * pixelSize];
#if BPP == 32
if (client->format.depth == 24 && client->format.redMax == 0xFF &&
client->format.greenMax == 0xFF && client->format.blueMax == 0xFF) {
/* TurboJPEG can directly output some 24-bit depth 32 bpp pixel formats */
if (client->format.redShift == 24 &&
client->format.greenShift == 16 && client->format.blueShift == 8) {
flags |= TJ_ALPHAFIRST | TJ_BGR; /* ABGR */
} else if (client->format.redShift == 16 &&
client->format.greenShift == 8 && client->format.blueShift == 0) {
flags |= TJ_BGR; /* BGRA */
} else if (client->format.redShift == 8 &&
client->format.greenShift == 16 && client->format.blueShift == 24) {
flags |= TJ_ALPHAFIRST; /* ARGB */
} else if (client->format.redShift == 0 &&
client->format.greenShift == 8 && client->format.blueShift == 16) {
flags |= 0; /* RGBA */
} else {
convertingRequired = 1; /* TurboJPEG cannot output this 24-bit depth format */
}
} else {
convertingRequired = 1; /* TurboJPEG cannot output formats with this color depth and these maximums */
}
if (!convertingRequired) {
if (client->format.bigEndian) flags ^= TJ_ALPHAFIRST | TJ_BGR;
pixelSize = BPP / 8;
pitch = client->width * pixelSize;
dst = &client->frameBuffer[y * pitch + x * pixelSize];
} else
#endif
{
pixelSize = 3; /* RGB */
pitch = w * pixelSize;
dst = (uint8_t *)client->buffer;
}

if (tjDecompress(client->tjhnd, compressedData, (unsigned long)compressedLen,
dst, w, pitch, h, pixelSize, flags)==-1) {
Expand All @@ -653,23 +676,26 @@ DecompressJpegRectBPP(rfbClient* client, int x, int y, int w, int h)

free(compressedData);

#if BPP == 16
pixelSize = BPP / 8;
pitch = client->width * pixelSize;
dst = &client->frameBuffer[y * pitch + x * pixelSize];
#if BPP == 32
if (convertingRequired)
#endif
{
CARDBPP *dst16=(CARDBPP *)dst, *dst2;
char *src = client->buffer;
int i, j;

for (j = 0; j < h; j++) {
for (i = 0, dst2 = dst16; i < w; i++, dst2++, src += 3) {
*dst2 = RGB24_TO_PIXEL(BPP, src[0], src[1], src[2]);
pixelSize = BPP / 8;
pitch = client->width * pixelSize;
dst = &client->frameBuffer[y * pitch + x * pixelSize];
{
CARDBPP *dstbpp=(CARDBPP *)dst, *dst2;
char *src = client->buffer;
int i, j;

for (j = 0; j < h; j++) {
for (i = 0, dst2 = dstbpp; i < w; i++, dst2++, src += 3) {
*dst2 = RGB24_TO_PIXEL(BPP, src[0], src[1], src[2]);
}
dstbpp += client->width;
}
dst16 += client->width;
}
}
#endif

return TRUE;
}
Expand Down
Loading