maiself / gnome-shell-extension-invert-color

GNOME Shell extension for inverting the color of windows
MIT License
43 stars 24 forks source link

Colors Effects and Brightness / Contrast settings #1

Open fastrizwaan opened 8 years ago

fastrizwaan commented 8 years ago

Could you please add color effect like gnome, as can be seen in the accessibility settings:

screenshot from 2016-03-23 13-49-13

Also, please consider options for LIGHT and DARK colors screen-dimmer-night-theme-google-play-books-

There's a software for windows called negativescreen, which has a smart mode that can invert black and white colors keeping other colors intact. i.e., invert only white and black, that'd be cool as well

Please see http://arcanesanctum.net/negativescreen/

All in all, invert color extension is really useful for me, as Linux Admin and as a Reader. Thank you I don't need to use xcalib (which is not supported in wayland) :-)

wbolster commented 8 years ago

thank you for writing this extension.

it would indeed be great if you could add super-+ and super-- to adjust the window brightness. increasing it above zero (slider to the right in accessibility settings) does not make sense for this extension i think, since it's about darkening mostly.

wbolster commented 8 years ago

the shell-invert-lightness-effect.c file from gnome-shell contains this shader source code to achieve the "invert lightness" effect which the "black on white" toggle shown in the screenshot above uses:

/* Lightness inversion in GLSL.
 */
static const gchar *invert_lightness_source =
  "cogl_texel = texture2D (cogl_sampler, cogl_tex_coord.st);\n"
  "vec3 effect = vec3 (cogl_texel);\n"
  "\n"
  "float maxColor = max (cogl_texel.r, max (cogl_texel.g, cogl_texel.b));\n"
  "float minColor = min (cogl_texel.r, min (cogl_texel.g, cogl_texel.b));\n"
  "float lightness = (maxColor + minColor) / 2.0;\n"
  "\n"
  "float delta = (1.0 - lightness) - lightness;\n"
  "effect.rgb = (effect.rgb + delta);\n"
  "\n"
  "cogl_texel = vec4 (effect, cogl_texel.a);\n";
wbolster commented 8 years ago

Adapting this extension to use the same "smart" colour inversion logic using this code seems to work:

        this.set_shader_source(' \
            uniform sampler2D tex; \
            void main() { \
                vec4 color = texture2D(tex, cogl_tex_coord_in[0].st); \
                if(color.a > 0.0) { \
                    color.rgb /= color.a; \
                } \
                float maxColor = max (color.r, max (color.g, color.b)); \
                float minColor = min (color.r, min (color.g, color.b)); \
                float lightness = (maxColor + minColor) / 2.0; \
                float delta = (1.0 - lightness) - lightness; \
                color.rgb = (color.rgb + delta); \
                color.rgb *= color.a; \
                cogl_color_out = color * cogl_color_in; \
            } \
        ');

Let me know if you want to incorporate this alternative colour inversion (yes please!), and let me know whether you want me to prepare a pull request for it.

wbolster commented 8 years ago

mandatory screenshots follow below. :)

normal view:

image

after pressing the S-i shortcut it looks like this:

image

as you can see: blue stays blue.

fastrizwaan commented 8 years ago

Wow wbolster, how can I test this?

wbolster commented 8 years ago

@fastrizwaan the easiest way to test this is to open ~/.local/share/gnome-shell/extensions/invert-window@maiself/extension.js, and changing the piece of code that reads this.set_shader_source(...) with exactly the code i posted in my comment above: https://github.com/maiself/gnome-shell-extension-invert-color/issues/1#issuecomment-207787404

wbolster commented 8 years ago

@fastrizwaan or just take my version of the extension.js from #4 and save it in the right place. don't forget to relogin.

fastrizwaan commented 8 years ago

Thanks, works but text becomes colourful and rather difficult to read in inverted mode.

Invert-window (without colors text is readable) without-colors

Invert-window (with colors, inverted text is colored (RGB) hence difficult to read)

with-colors

extension.js.txt

wbolster commented 8 years ago

i'm not sure i see any problem here?

if you're really looking at source code, you should use a dark theme instead. (e.g. solarized light vs solarized dark).

brightness inversion makes most sense for e.g. a web browser where you can't control the colours. brightness inversion gives much better results than colour inversion in those cases.

if you're looking for a darker gnome environment, you should probably try making the adwaita dark theme (as used by some applications by default, e.g. totem) the default. this is available as a switch in gnome tweak tool.

log69 commented 5 years ago

@wbolster Thank you for your code, it works amazing. And thank you for the original author @maiself for creating this nice extension.

log69 commented 5 years ago

@wbolster I fixed your code a bit to make the inverted colors be closer to their original saturation, so the less saturated color on white will be less saturated on black. See here:

    this.set_shader_source(' \
        uniform sampler2D tex; \
        void main() { \
            vec4 color = texture2D(tex, cogl_tex_coord_in[0].st); \
            if(color.a > 0.0) { \
                color.rgb /= color.a; \
            } \
            float lightness = (color.r + color.g + color.b) / 3.0; \
            float delta = (1.0 - lightness) - lightness; \
            color.rgb = (color.rgb + delta); \
            color.rgb *= color.a; \
            cogl_color_out = color * cogl_color_in; \
        } \
    ');
iamjackg commented 5 years ago

A downside to this approach is that it messes with text antialiasing. That might be very difficult to prevent though.

iamjackg commented 5 years ago

I ended up going with this altered version of the shader that reduces the overall contrast. It can cause bright colors to go above 1.0, but it's good enough.

                this.set_shader_source(' \
                        uniform sampler2D tex; \
                        void main() { \
                                vec4 color = texture2D(tex, cogl_tex_coord_in[0].st); \
                                if(color.a > 0.0) { \
                                        color.rgb /= color.a; \
                                } \
                                color.rgb = vec3(1.0, 1.0, 1.0) - color.rgb; \
                                color.rgb *= color.a; \
                                color.rgb += 0.1; \
                                color.rgb *= 0.8; \
                                cogl_color_out = color * cogl_color_in; \
                        } \
                ');
log69 commented 5 years ago

Thanks.

natask commented 5 years ago

I have implemented these feature. currently I have put @log69's, @iamjackg's, @wbolster's and the original as shader sources to select from by default as a thank you gift. which one to use can be selected from the preferences page or directly by editing the schema entry pertaining to it. users can also place their custom shader source to select from in an other schema entry. selection is done using a string key associated with the shade source. users can also override a default shader source using this method. I will push the code to my repo and do a pull request soon.