Skip to content

Commit

Permalink
Align pixel format with common server convention
Browse files Browse the repository at this point in the history
This a workaround for servers which don't respect the pixel format sent by AVNC.
  • Loading branch information
gujjwal00 committed Mar 23, 2024
1 parent 5ab9f52 commit 1e3621f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 15 additions & 0 deletions app/src/main/cpp/native-vnc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,17 @@ Java_com_gaurav_avnc_vnc_VncClient_nativeConfigure(JNIEnv *env, jobject thiz, jl
client->appData.qualityLevel = image_quality;
if (use_raw_encoding)
client->appData.encodingsString = "raw";

// Change pixel format to match with the default format used by most VNC
// servers. Technically, we should not have to this as VNC servers have to
// respect whatever pixel format client prefers. But there are some wierd
// servers which ignore pixel format sent by client. As a result, users
// blame AVNC for not rendering the colors properly.
// Note: This change affects how OpenGL Texture for framebuffer is rendered,
// and it only works for 24 bit-per-pixel density.
client->format.redShift = 16;
client->format.greenShift = 8;
client->format.blueShift = 0;
}

extern "C"
Expand Down Expand Up @@ -480,6 +491,10 @@ Java_com_gaurav_avnc_vnc_VncClient_nativeUploadFrameTexture(JNIEnv *env, jobject
GL_RGBA,
GL_UNSIGNED_BYTE,
client->frameBuffer);

// Note: client->frameBuffer data is actually in 'BGRA' format, instead of 'RGBA'.
// But OpenGL ES doesn't support that directly. So we use 'GL_RGBA' here, and flip
// the components to correct order inside fragment shader.
}

UNLOCK(ex->mutex);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/gaurav/avnc/ui/vnc/gl/Shaders.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ object Shaders {
varying vec2 v_TextureCoordinates;
void main()
{
gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates);
gl_FragColor = texture2D(u_TextureUnit, v_TextureCoordinates).bgra;
}"""
}

0 comments on commit 1e3621f

Please sign in to comment.