Colours slightly off in plugin host


#1

I'm creating a plugin on the Mac. If I fill my main component with 0xff232323, when I look at the colour with a zoomin tool, it's actually drawn as 0xff202020. In Pro Tools it's 0xff232323 as I'd expect. 

It matters because I'm trying to draw an OpenGL component and I want it to match. If I fill the OpenGL component with OpenGLHelpers::clear(), on both hosts it actually fills with 0xff232323. 

Any idea why it's drawing with different colours?


#2

Most likely because OSX is applying some kind of colourspace conversion..? If not, then I don't know - certainly there's nowhere in juce that messes with the colours that it's drawing..


#3

This is atually more of a general OS X issue, maybe the thread should be moved there. My monitors have different colour spaces, so when I was running plugin host on one and ProTools on the other, the colours didn't match. Anyway, here is a function to determine what colour a colour will actually be drawn.

Pass in uint32_t colour and Component::getWindowHandle()

uint32_t outputColour (uint32_t inColour, void* inView)
{
    if (NSView* view = (NSView*)inView)
    {
        if (NSWindow* window = view.window)
        {
            if (NSColorSpace* colourSpace = window.colorSpace)
            {
                NSColor* nsColour = [NSColor colorWithRed: ((inColour & 0x00FF0000) >> 16) / 255.0
                                                    green: ((inColour & 0x0000FF00) >> 8)  / 255.0
                                                     blue: ((inColour & 0x000000FF) >> 0)  / 255.0
                                                    alpha: ((inColour & 0xFF000000) >> 24) / 255.0];
                
                nsColour = [nsColour colorUsingColorSpace:colourSpace];
                if (nsColour)
                {
                    CGFloat r, g, b, a;
                    
                    [nsColour getRed:&r green:&g blue:&b alpha:&a];
                    
                    uint32 outColour = (((uint8_t)(a * 255 + 0.5)) << 24) |
                                       (((uint8_t)(r * 255 + 0.5)) << 16) |
                                       (((uint8_t)(g * 255 + 0.5)) <<  8) |
                                       (((uint8_t)(b * 255 + 0.5)) <<  0);
                    
                    return outColour;
                }
            }
        }
    }
    return inColour;
}