How does on-screen color inversion work in OS X?

后端 未结 4 2067
感动是毒
感动是毒 2021-02-06 13:24

This is what OS X\'s built in color inversion feature can turn your screen into:

\"enter

4条回答
  •  一生所求
    2021-02-06 14:13

    The way OS X itself does it is through a set of undocumented CoreGraphics API calls. I don't think they're declared in any official header file, but you can always just declare the prototypes yourself.

    // clang -g -O2 -std=c11 -Wall -framework ApplicationServices
    
    #include 
    #include 
    
    CG_EXTERN bool CGDisplayUsesInvertedPolarity(void);
    CG_EXTERN void CGDisplaySetInvertedPolarity(bool invertedPolarity);
    
    int
    main(int argc, char** argv)
    {
        bool isInverted = CGDisplayUsesInvertedPolarity();
        printf("isInverted = %d\n", isInverted);
    
        sleep(2);
        CGDisplaySetInvertedPolarity(!isInverted);
        printf("Polarity is now: %d\n", CGDisplayUsesInvertedPolarity());
    
        sleep(2);
        CGDisplaySetInvertedPolarity(isInverted);
        printf("Polarity is now: %d\n", CGDisplayUsesInvertedPolarity());
    
        return 0;
    }
    

    There are similar API calls for other accessibility features, such as grayscale:

    CG_EXTERN bool CGDisplayUsesForceToGray(void);
    CG_EXTERN void CGDisplayForceToGray(bool forceToGray);
    

提交回复
热议问题