Did something change in the way Graphics forwards CGContextRef with 2019r1?

  1. 4 weeks ago

    Ulrich B

    Aug 17 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    I recently became aware that my CSTrueColors module which can be used for full dynamic system color support on macOS does not work anymore. (None of my customers told me, so I think it did not cause much harm).

    In investigating this, I found that my attempts to set the CGColor representation of a NSColor as fill color for a Xojo picture graphics object do not work anymore. I tried every possible approach, but a direct CGContextFillRect command does only result NOT in a black square if I use Xojo’s graphics‘ ForeColor property. Which is quite sad because to avoid the usual quality loss in color conversion, I used to draw the color with CGContext into a buffered Xojo picture and read it from its RGBSurface which resulted in much better Xojo Colors than the mathematical approach.

    I found higher level API calls to be still working and can use AppKit’s NSRectFill to draw the color into a canvas graphics object (phew), but trying the same with a Xojo picture’s graphics handle resulted in a black picture. I can declare a NSImage and use NSRectFill to draw the color Into it, but the conversion to a Xojo picture via TiffRepresentation is as bad as the mathematical approach. And quite expensive.

    So I wonder: Has something changed in the way Xojo handles CGContext properties? Or was it Apple again? Or – although I swear the same code worked before – even me who failed?

    @Ulrich B — From a NSColor object, colorUsingColorSpace: should do to convert to another colorspace

  2. @Ulrich B — I am not really familiar with the behind-the-scene of Graphics so excuse me if it is a naive question, but are you sure that your NSColor and your Graphics have the same colorimetric space?

  3. Ulrich B

    Aug 18 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    Obviously they don’t. I am currently investigating a ColorSpace transformation to regain the conversion quality I had before, which I did not have to do before.

    My initial question might be a bit confusing. To shorten it:
    I’d be glad if an engineer could answer me why every call to CGContextSetColorWithColor, SetColor or other available method is ignored when I do a CGContextFillRect afterwards into a graphics context – the rectangle stays black. Only if I set graphics.ForeColor, the draw commands result in colored areas.

  4. Stéphane M

    Aug 18 Answer France

    @Ulrich B — From a NSColor object, colorUsingColorSpace: should do to convert to another colorspace

  5. Ulrich B

    Aug 18 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    Yes, but even conversion to main screen.colorspace does only result in some of the colors looking ok – upper half is Xojo conversion, lower half is NSColor written directly into the Canvas graphics.

    -image-

  6. Ulrich B

    Aug 18 Pre-Release Testers, Xojo Pro Europe (Germany, Berlin) · xo...

    Ah! But after finding an old thread here, GenericRGBColorspace did the trick.
    Riddle not solved but fix found. Thanks a lot!

    -image-

  7. @Ulrich B — I knew it!! ... or not :-)

or Sign Up to reply!