LibVNC / libvncserver

LibVNCServer/LibVNCClient are cross-platform C libraries that allow you to easily implement VNC server or client functionality in your program.
GNU General Public License v2.0
1.13k stars 491 forks source link

Client blurry #636

Open fxzxmicah opened 1 week ago

fxzxmicah commented 1 week ago

I know this may not be the right place to ask questions, but I couldn't find anywhere else to ask.

The vnc client I wrote renders the remote desktop blurry, how can I fix it? I use GTK4. If you need any other information, feel free to ask.

Init:

static void initialize_client(const char *addr, int port) {
    client = rfbGetClient(8, 3, 4);
    client->appData.compressLevel = -1;
    client->appData.qualityLevel = 9;
    client->appData.useRemoteCursor = TRUE;
    client->serverHost = g_strdup(addr);
    client->serverPort = port;
    if (!rfbInitClient(client, NULL, NULL)) {
        fprintf(stderr, "Failed to initialize VNC client\n");
        exit(EXIT_FAILURE);
    }
}

Draw:

static void on_draw(GtkDrawingArea *area, cairo_t *cr, int width, int height, gpointer data) {
    pthread_mutex_lock(&lock);
    if (client->frameBuffer) {
        GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(
            client->frameBuffer,
            GDK_COLORSPACE_RGB,
            TRUE,
            8,
            client->width,
            client->height,
            client->width * 4,
            NULL,
            NULL
        );
        gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0);
        cairo_paint(cr);
        g_object_unref(pixbuf);
    }
    pthread_mutex_unlock(&lock);
}

Log:

04/11/2024 17:09:44 VNC server supports protocol version 3.8 (viewer 3.8)
04/11/2024 17:09:44 We have 1 security types to read
04/11/2024 17:09:44 0) Received security type 1
04/11/2024 17:09:44 Selecting security type 1 (0/1 in the list)
04/11/2024 17:09:44 Selected Security Scheme 1
04/11/2024 17:09:44 No authentication needed
04/11/2024 17:09:44 VNC authentication succeeded
04/11/2024 17:09:44 Desktop name "WayVNC"
04/11/2024 17:09:44 Connected to VNC server, using protocol version 3.8
04/11/2024 17:09:44 VNC server default format:
04/11/2024 17:09:44   32 bits per pixel.
04/11/2024 17:09:44   Least significant byte first in each pixel.
04/11/2024 17:09:44   TRUE colour: max red 255 green 255 blue 255, shift red 16 green 8 blue 0
bk138 commented 1 week ago

The right place to ask is highlighted just at the very top of the README ;-)

To answer your question: I recommend looking at the other client examples in https://github.com/LibVNC/libvncserver/tree/master/examples/client and check whether they behave the same and if not, find the difference to your code. HTH!

fxzxmicah commented 1 week ago

The gtkvncviewer is a GTK3 program? It may be too old to build it on GTK3.

bk138 commented 1 week ago

Might be GTK2, you can check in the build system.

fxzxmicah commented 1 week ago

Also I don't see anything special in the code so maybe it's blurry even if it compiles.

bk138 commented 1 week ago

Yeah maybe your server is forcing some Tight encoding parameters - you can try with another viewer and check.

fxzxmicah commented 1 week ago

I've used tigervnc and it's very clear when it connects to my server. Is it some kind of codec issue? tigervnc seems to be using a video codec. Also I can't turn off JPEG, if I do, it causes GDK to fail to render, so there may be some kind of compatibility issue between the two.

bk138 commented 1 week ago

It's basically tight quality and compression and bit depth you can play with. You can also check https://github.com/bk138/multivnc/blob/master/src/VNCConn.cpp and remmina, they're both using libvncclient.

fxzxmicah commented 1 week ago

Then is it a bug that turning off JPEG causes the GDK to not render?

bk138 commented 1 week ago

I don't know. I can just guess that you're setting quality level and/or compress level to strange values. For instance -1 for compress is pretty uncommon. Check other's code where they're having non-blurry images.

fxzxmicah commented 1 week ago

This must not be my problem, because even if I use all the defaults I still can't turn off JPEG with client->appData.enableJPEG = FALSE. If I set this value, GDK stops rendering.

bk138 commented 1 week ago

I don't know what this setting does. To "turn off" tight encoding, you simply must not request it. See https://github.com/bk138/multivnc/blob/master/src/VNCConn.cpp#L1163 for instance.

fxzxmicah commented 1 week ago

Encoding without tight will still result in no screen.

bk138 commented 1 week ago

Please just look at the provided client and maybe server examples. They do work.

fxzxmicah commented 1 week ago

multivnc doesn't use GTK4 and I can barely reference it. I've also tried a number of techniques for rendering the screen, but they're all blurry. Not being able to use other encodings might be a server issue though.

bk138 commented 1 week ago

A server always must report Raw encoding if I'm not mistaken.

Anyway, I think we're getting off-topic here - isn't this more GTK4-related then?

fxzxmicah commented 1 week ago

I can't think of any other reason if the image given by libvncclient itself is not blurry.

bk138 commented 1 week ago

Maybe it is - you can verify with another libvncclient-based client like Remmina or MultiVNC.