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

Invert hue option.. Can it be brought back? #9

Open
jccr opened this issue Mar 12, 2014 · 86 comments
Open

Invert hue option.. Can it be brought back? #9

jccr opened this issue Mar 12, 2014 · 86 comments

Comments

@jccr
Copy link

jccr commented Mar 12, 2014

Nocturne used to have this feature that not only inverted the screen, but it also let you invert the color hues. For those that didn't know about this: Blue colors became orange colors when the screen was inverted, but with the invert hue option everything stayed dark but orange became blue again for example.

Can this feature be implemented again for 10.9?

Bountysource

@amitmarkel
Copy link

Please bring this option back - Hue inversion was the reason I'd used this application extensively.

@ylluminate
Copy link

A big +1 here as well. That is exceptionally necessary for this app as I prefer to see colors as they originally were -- or as close to them as possible vs what we presently have.

@ejwessel
Copy link

I hope I'm not hijacking this thread to a different area, but I as well have been in pursuit to bring back the invert hue option.
There was some talk of this on the blacktree-nocturne forum here
There was some speculation that "hue inversion was relying on a private API that may have changed."

If anybody has any ideas please share!

@amitmarkel
Copy link

Yes, I think I'd seen that. That feature was very important to me, so now I
don't have real use for this program (yet). I wonder why Apple did not
incorporate a similar option.

On Oct 22, 2014, at 5:43, ejwessel notifications@github.com wrote:

I hope I'm not hijacking this thread to a different area, but I as well
have been in pursuit to bring back the invert hue option.
There was some talk of this on the blacktree-nocturne forum here
https://code.google.com/p/blacktree-nocturne/issues/detail?id=63
There was some speculation that "hue inversion was relying on a private API
that may have changed."

If anybody has any ideas please share!


Reply to this email directly or view it on GitHub
#9 (comment).

@jccr
Copy link
Author

jccr commented Oct 22, 2014

I've done some research and I believe we might be able to achieve a similar effect with a highly customized ICC display profile. One that inverts the white point and black point and messes with the gamma levels. I have no idea as to how to actually create this profile, and have not found any "ICC profile editing" tool that specialized yet.

@amitmarkel
Copy link

Interesting, never thought about that direction. I think I encountered
such an editor on the internet a few years ago; so it might be worth a
search.

@amitmarkel
Copy link

Perhaps one can attempt to edit their default/retina display profile at /Library/ColorSync/Profiles/Displays with the builtin property editor.

@ylluminate
Copy link

👍 Very good suggestion. It would be an enormous asset for this to have such a feature.

@jbenet
Copy link

jbenet commented Oct 29, 2014

+:100: Hue inversion is the main only real reason to use Nocturne Tranquility. I will pay for this feature.

@jbenet
Copy link

jbenet commented Oct 29, 2014

I just set a $50 on bountysource, because i want my greens to stay $@%&ing green. https://www.bountysource.com/issues/3167101-invert-hue-option-can-it-be-brought-back
I recommend others who care about this issue to back it too. Whoever fixes this will deserve it, and it may get it to us sooner at all. (cc @kzsh - if you fix it on the original repo, i'll pay it there)

Hurry, Obi Wan Kenobi. You're my only hope. My computer now feels horribly unfamiliar and hostile.

@kzsh
Copy link

kzsh commented Oct 30, 2014

I spent some time looking into this for Nocturne. I agree with @jccr that one solution would be a custom ICC profile, though, like him, I don't know how to do that. It's also possible that there's a filter we could use.

@jbenet
Copy link

jbenet commented Oct 31, 2014

@jccr @kzsh can we figure something out together? Do we know anyone who knows ICC profiles?

@ylluminate
Copy link

That is a very interesting find there @jbenet. Any luck playing around with these two options?

@jbenet
Copy link

jbenet commented Nov 5, 2014

@ylluminate not yet :( -- i dont have the bandwdith to sink into and figure out how to edit / make ICC profiles.

@amitmarkel
Copy link

A filter which does inversion and hue inversion is easy to do, but it cannot be applied to a color profile I think.

@ejwessel
Copy link

ejwessel commented Nov 6, 2014

I've been watching videos and reading a bit about how ICC profiles work and can be edited. I do have to say they aren't trivial(like the link above this mentions). Given that I'm no color expert and I'm assuming nobody else here is, I was entertaining the idea of purchasing, or better yet using, an ICC profile generator. Though that wouldn't solve the problem of how to get what we want it might be a step closer.
Thats all I have for now. I'm going to go back to reading.

http://www.color.org/opensource.xalter

@jbenet
Copy link

jbenet commented Nov 6, 2014

@ejwessel have you found a good ICC generator?

We should find someone who knows ICC profiles well. Anyone have any leads?

@ejwessel
Copy link

ejwessel commented Nov 7, 2014

I haven't tried any of the open source ones yet.
No leads yet either =/
I do plan to start messing around with them this weekend, but we'll see what my schedule allows for =P

@amitmarkel
Copy link

I have managed to edit the standard Color LCD profile's tristimulus values with a hex editor. I think we need to understand how to rotate the projective coordinates values so that either lightness is inverted or the hue values are rotated so that inversion inverts it back.

@amitmarkel
Copy link

I almost got it right.

I altered the Color LCD profile as I described here https://dl.dropboxusercontent.com/u/6674137/ICC%20Modification.pdf.

https://dl.dropboxusercontent.com/u/6674137/ICC-img.jpg

@jccr
Copy link
Author

jccr commented Nov 7, 2014

@amitmarkel Thanks for looking into the color profiles. This is great stuff but may I ask as to why you removed the links to your icc profile and document? I was looking forward to trying out your modified profile..

@amitmarkel
Copy link

I edited the document. The colors' hue values are accurately inverted, but something is wrong with the grays. I suspect that the "Apple display native information > Phosphor values" section might be related somehow. I use the Skype icon for observation.

@jccr
Copy link
Author

jccr commented Nov 7, 2014

Oh that's cool. Looking at your screenshot, wow looks like you are getting close.

@amitmarkel
Copy link

Here is the profile https://dl.dropboxusercontent.com/u/6674137/Invert%20Hue.icc.

Hopefully someone can resolve the remaining little problem with lightness (I assume). Although the problem doesn't seem to be great, it does affect user experience; it makes the OS look like Yosemite.

@amitmarkel
Copy link

I think I forgot to invert the white point. Will do that tomorrow!

@amitmarkel
Copy link

I have been working on this for three days now. Tomorrow I will have limited time to do this. I hope that this will resolve the issue I mentioned.

@jbenet
Copy link

jbenet commented Nov 7, 2014

@amitmarkel this is a great step forward! thank you

(for others, install profile in /System/Library/ColorSync/Profiles)

I'm getting these.

  • Do you need to reboot / reboot apps (didnt think so... should be system-wise)? some colors in browsers remain uninverted (note the Green github "Comment" button). Is this whitepoint related?
  • Yep, i also note the grays + lightness problem (not quite smooth enough to be usable, but we're getting there)

just hue

with nocturne

@amitmarkel
Copy link

I suppose so. Will fix it tomorrow.

@ejwessel
Copy link

ejwessel commented Nov 8, 2014

@amitmarkel
Great job! Fantastic write up including references.

@amitmarkel
Copy link

The details are correct; cool. I'm currently in a computer science exam period so I can't quite assist with the actual digging at this time. If this approach works then there will be no need for manipulating ICC profiles, which is a plus due to the different per application behavior.

@dmitrym0
Copy link

I spent some time looking at this issue. I'm not sure why CGSNewCIFilterByName has been removed, but it doesn't appear to have been replaced by anything public. NSView has a backgroundFilters property which is expressly not supported for the root CALayer (see comment in the header). Thus you can add CIFilters to a window but then they only affect the contents of said window (see a sample on cocoasnippets). It seems like a potential approach would be to capture the screen, rasterize it into the window and then apply a filter to it. I can't see it working beyond a proof of concept though.

TLDR:

  • Apple removed a private API call that let you add filters to the root layer of a window. There's no public API.
  • Next step, proof of concept: take a screenshot, apply filters and see if it looks right.

@lswank
Copy link
Owner

lswank commented Mar 2, 2015

Yes, CGSNewCIFilterByName returns kCGErrorNotImplemented in OS X 10.8+. Doing this on an NSView certainly won't work, but perhaps iterating over all of the NSWindow instances will. We've already seen from parts of the original code that the background of Finder is also an NSWindow instance.

There is a pretty clear (looking) way to handle applying a CIFilter to an NSWindow instance. The real questions are:

  • Can we get all of the instances of NSWindows in the world? (Likely yes.)
  • Can we apply the same filter to them? (Likely yes, but we'll have to be clever.)
  • Can that filter be the same filter we had before -- or something better? (Likely yes.)
  • Is there an easier way to do this with color profiles? (From class-dumping ColorSync.app, it doesn't seem like there's a really easy way to do this, but I am not sure.)
  • Can we set an ICC color profile in code? (Probably yes, but I couldn't find quick documentation to do this, so it might not be all that common.)

"Now," you're probably asking yourself, "doesn't Apple do this with color inversion and color profiles anyway? Shouldn't it all be nicely documented?" It should, but the internal team doesn't always document like they should. If anyone is going to WWDC this year -- and yes, I know tickets aren't being sold quiet yet -- this is an excellent question for the CoreGraphics / CoreImage developers. At WWDC, the engineers always say a whole lot more than they should, because no one is watching over their shoulders. They also give you way more tools and way more hands-on time. So, if anyone wants to send me to WWDC, I will get any answers we can't. ;)

@lswank lswank closed this as completed Mar 2, 2015
@lswank lswank reopened this Mar 2, 2015
@lswank
Copy link
Owner

lswank commented Mar 2, 2015

(Whoops. Didn't mean to close it.)

@flowerornament
Copy link

🙏 Hoping somebody figures this out!

@jbenet
Copy link

jbenet commented Jun 13, 2015

@dmitrym0 any luck?

@dmitrym0
Copy link

I left it in late february and hasn't returned to it. @lswank had some good idea that are worth trying though.

@lswank
Copy link
Owner

lswank commented Jun 15, 2015

I punted on this for the time being. I'd love some ancillary assistance
rethinking the UI and cleaning the rest of the application up for the bits
that do work well before moving back to tackle this one. Anyone know any of
the CoreGraphics team guys? They could also provide some insight. (Or in a
different world, they might actually add in just the private method we need
for the new version of the operating system and tell us about it with a
wink-wink-nudge-nudge . . .)

On Sat, Jun 13, 2015 at 1:54 PM, Dmitry notifications@github.com wrote:

I left it in late february and hasn't returned to it. @lswank
https://github.com/lswank had some good idea
#9 (comment)
that are worth trying though.


Reply to this email directly or view it on GitHub
#9 (comment).

@dmitrym0
Copy link

Looks like https://hazeover.com/ is doing something similar, maybe the author would be open to sharing his approach. Hazeover darkens everything but your front most window.

@amitmarkel
Copy link

Interesting; but it may be possible they're creating a transparent window behind the foremost window all the time, which would require no implementation for being interactive... They direct one to press fn once to hide the shade temporarily to drag files etc, on the page... Haven't tried the software though.

@pointum
Copy link

pointum commented Jan 17, 2016

@dmitrym0 @amitmarkel HazeOver is a translucent black window that is reordered behind the front window

@reversefold
Copy link

reversefold commented Jul 5, 2016

I managed to get a display screenshot and invert its hues in a clone of Nocturne:
reversefold/blacktree-nocturne@ad0f087

Lots of commented out code and possibly non-needed code as I was throwing everything at the wall to see what stuck. It's a promising line of research if nothing else. I plan to look into CGDisplayStream next as it appears to be the way to get a constantly updating view of the screen. Pair that with the click-through window I have working now and we may have a version of this which minimally works.

Apologies for any bad code, I'm not familiar with Apple's display frameworks and most of this was copied from example code and StackOverflow.

Also found https://github.com/reversefold/PresenterMirror which looks like a good reference for the constantly updating screen capture. It's using OpenGL, though, so it may require more work to get that working.

@amitmarkel
Copy link

Great news; looking forward to seeing your approach working!
I hope OpenGL doesn't invoke the discrete video card, although it may work with gfxCardStatus to force the integrated Intel chip.

@fsargent
Copy link

Just put in another $10 on Bountysource.
Really looking forward to this working.

@jbenet
Copy link

jbenet commented Oct 28, 2016

:( really wish this worked. just added $50 more to Bountysource.

@jbenet
Copy link

jbenet commented Oct 28, 2016

@reversefold wonder if your approach will be super fast or introduce display latency? any further luck getting it working?

@vn971
Copy link

vn971 commented Mar 6, 2017

Hi folks.
If anything, I found a way for it to work under Linux: https://github.com/vn971/linux-color-inversion

@jccr
Copy link
Author

jccr commented Mar 6, 2017

@vn971 nice work!

I didn't know about mlaily/NegativeScreen
Looks like Windows and Linux have this covered

@danielng01
Copy link

danielng01 commented May 8, 2017

I managed to make it for 1 window, but there seems to be no way to get all NSWindow instances. As you can imagine this will be security issue to add CALayer to other process NSWindow.

Maybe with the Accessibility API, but again not possible. You can get CGWindowId, but I don't think this can be transformed to NSWindow and NSView.

The screenshot approach seems to be the best option which I will try next. I was trying to do this for 2 months so it's really not so easy.

I also wrote to one guy who is expert in ICC profiles and I wait for response. If ICC profile would work this will be best, but from my understanding this is not possible.

Is there some other way to hook to the graphics pipeline and apply color matrix before the image goes to the screen?

CGSAddWindowFilter seemed so nice solution. I really want it back :D

screen shot 2017-05-08 at 3 22 53 pm
screen shot 2017-05-08 at 4 23 39 pm
screen shot 2017-05-08 at 4 25 15 pm
screen shot 2017-05-08 at 4 25 56 pm

@danielng01
Copy link

danielng01 commented May 9, 2017

Update:
I made it with really heavy use of C++ and with taking a screenshot of the desktop.

You can find working example here:
https://github.com/danielng01/Iris-Builds/raw/master/OSX/experiments/Iris-Smart-Inversion-OSX.zip
Demonstration video:
https://youtu.be/dQepAWXoVAY

Basically once upon a time Apple has this awesome private API CGSNewCIFilterByName, but they dropped it for some reason. I first tried with ICC profiles, but this is impossible since you can only change the gamma.

Then I tried making filter to NSWindow, but this only works for windows of the app and we don't have access to other program NSWindows. There is some way to get access with Apple Accessibility API, but the other app needs to whitelist you in the source code.

The only working approach for OSX Sierra and newer versions seems to be the screenshot approach. The best way was to try with the streaming API CGDisplayStream, but you can't ignore the window in which you are displaying the output and you get recursive output and no update of the screen. More info here:
http://stackoverflow.com/questions/18158390/avcapturescreeninput-and-kcgwindowlistoptiononscreenbelowwindow

Based on the Apple example here:
https://developer.apple.com/library/mac/samplecode/SonOfGrab/Introduction/Intro.html

I took a screenshot made a transparent window and put the screenshot to it. This thing updates every 20 ms for relatively good framerate and uses OpenGL rendering, to perform a little faster. After all the optimization it still uses 20% CPU on my Mac which is bad, but this seems to be the only approach. Even if you perform even more optimizations to drop 5% CPU it's still high.

You need to calculate the Smart inversion every frame and take a picture. Taking the picture alone tooks 10% and can't be optimized. I would welcome any other approaches, but it seems to me like you just can't do this faster on OSX anymore.

@jccr
Copy link
Author

jccr commented May 11, 2017

@danielng01
Hey, thanks for giving this a shot! Really want to see how it works, but whenever I run it I see the "temperature" of the colors go down (flux like effect) and then a few seconds later my screen turns black and I can only see the cursor. I am using nvidia's osx "web" drivers if that makes any difference.

@danielng01
Copy link

Maybe it's the drivers.

I just tested on Sierra and Yosemite both real Mac and Virtual machine and it works. The black thing is the overlay. Maybe the screenshot function fails on your machine. It's from the SonOfGrab demo see if you can get it working on your machine

Yes the temperature thing is normal ignore it.

@jccr
Copy link
Author

jccr commented May 11, 2017

@danielng01
Just tried it on the regular drivers, you are correct it works there.

@ylluminate
Copy link

@danielng01 same problem here. Flux like effect (perhaps triggering Fl.ux) and then black main screen (5 monitors). I'm using the native ATI drivers on 10.12.5ß5.

@danielng01
Copy link

How much CPU it uses. Is this usefull for me it's unusable on my old Mac.

@ylluminate I really don't know, I write Carbon and Cocoa for the first time. The function is CGWindowListCreateImage. Try with only 1 monitor connected.

You get f.lux effect, because I added the window to my software Iris (https://iristech.co/). I can't make working demo from scratch.

@jccr
Copy link
Author

jccr commented May 11, 2017

@danielng01
It works on my MBP from late-2013, Core i5 of the time. It's unusable for me :( but the effect is exactly what I hoped for.
I'm running macOS natively on another machine with better specs, Core i7 6700k but my GPU is an NVIDIA 900 series and it doesn't work with the native drivers. I have had issues with iBooks for example where it is just a black or sometimes transparent window.

@dmitrym0
Copy link

I get a black screen as well. Sierra, on an early 2013 Macbook Pro. Fans start as well, as soon as I start Iris.

@jccr
Copy link
Author

jccr commented May 11, 2017

@danielng01
I restarted my laptop so it would be at the lowest CPU usage possible, it looks like it's using 50-60% CPU (maybe a whole core since this CPU is dual core)

It's somewhat usable, not sure how fast it's actually updating but it looks like 10-15 FPS to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests