SimulaVR / Simula

Linux VR Desktop
MIT License
2.91k stars 87 forks source link

Applications are weirdly coloured #54

Closed lboklin closed 5 years ago

lboklin commented 5 years ago

With or without HDR enabled, this happens:

QT_QPA_PLATFORM=wayland-egl konsole
QT_QPA_PLATFORM=wayland-egl kate

image

lboklin commented 5 years ago

This seems to apply for all applications, regardless of whether run in XWayland or native Wayland.

georgewsinger commented 5 years ago

Red is blue, and blue is red:

lboklin commented 5 years ago

So I experimented with swapping red and blue, and the colours are more correct but they appear washed out: Simula: image vs desktop: image

So it doesn't appear to just be an BGRA8 -> RGBA8 issue.

KaneTW commented 5 years ago

Maybe something transparency related? Hmm.

lboklin commented 5 years ago

I tried messing with the alpha channel too but the only alpha value was around the border.

When alpha is set to 1: image

lboklin commented 5 years ago

Should be noted that the only thing I'm doing is manipulating the colour of the pixels in the image after it has been created from the byte array.

Don't mind the insane performance implications since it's only for testing, but here's the code I'm using:

    colorCorrect img = do
      width <- G.get_width img
      height <- G.get_height img
      -- walk through every pixel - SUPER SLOW
      let pixels = [ (x,y) | x <- [0..(width-1)], y <- [0..(height-1)] ]
      bracket
        (G.lock img)
        (const $ G.unlock img)
        $ const $ flip mapM_ pixels $ \(x,y) -> do
          clr <- G.get_pixel img x y :: IO GodotColor

          r <- godot_color_get_r clr :: IO CFloat
          b <- godot_color_get_b clr :: IO CFloat

          godot_color_set_r clr b
          godot_color_set_b clr r
          godot_color_set_a clr (fromRational 1)

          G.set_pixel img x y clr

I've been ignoring the apparent ARGB8888 vs RGBA8 discrepancy here since it doesn't seem to be an issue of A->R, R->G, G->B, B->A, but maybe I'm not understanding the implications correctly. WlShmFormatArgb8888 -> Image.FORMAT_RGBA8

ChristophHaag commented 5 years ago

Maybe qt is using a different color space, like sRGB vs RGBA? That would be one cause for "washed out" colors.

lboklin commented 5 years ago

It happens with any toolkit though. Chromium in Simula (forgot to disable the alpha manipulation so ignore the black borders): image and on desktop: image

lboklin commented 5 years ago

Regarding sRGB and RGBA, this is what the Godot docs have to say about the format conversion:

FORMAT_RGBA8 = 5 — OpenGL texture format RGBA with four components, each with a bitdepth of 8. Note that when creating an ImageTexture, an sRGB to linear color space conversion is performed.

For no particularly informed reason I tested with G.srgb_to_linear img (in addition to the R<->B swap) as well and it looked surprisingly close to correct, with the exception that very light pixels became green. Maybe that makes sense to someone who knows more about colour formats than me.

Also for completeness sake, here's what it says in the header file about the Wayland format:

    /**
     * 32-bit ARGB format, [31:0] A:R:G:B 8:8:8:8 little endian
     */
    WL_SHM_FORMAT_ARGB8888 = 0,
lboklin commented 5 years ago

Fixed in d103d920fc72b87a298f28df2818fdb85d1fb222