Tk Source Code

View Ticket
Login
Ticket UUID: fca13549b64fa1cde0b354890e52dfcce157bc15
Title: Aqua: improper TkMacOSXRGBPixel() usage in ImageGetPixel()
Type: Bug Version: core-8-6-branch
Submitter: chrstphrchvz Created on: 2020-08-02 18:18:45
Subsystem: 39. Image Basics Assigned To: marc_culler
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2020-08-03 13:27:16
Resolution: Fixed Closed By: marc_culler
    Closed on: 2020-08-03 13:27:16
Description:

The very recent refactoring added a function TkMacOSXRGBPixel(r, g, b) which retrieves color values from bits 15:8 of r, g, and b. Usage of this function was added to ImageGetPixel() (maybe also elsewhere) but it is being provided 8-bit values (unsigned char) for r/g/b, and so TkMacOSXRGBPixel() always returns black pixels in this case.

User Comments: marc_culler (claiming to be Marc Culler) added on 2020-08-03 13:27:16:
Thank you.

I merged those changes, and am closing the ticket.

chrstphrchvz added on 2020-08-03 08:33:52:

The revisions in bug-fca13549b6 will fix the problem. You may want to adjust this comment:

    /*
     * Compute 8 bit red green and blue values, which are multiplied by 256 and
     * ed as inputs to TkMacOSXRGBPixel.
     */


marc_culler (claiming to be Marc Culler) added on 2020-08-03 02:19:41:
I decided to make tkMacOSXRGBPixel take 8 bit inputs and do the shifting in
the TkpGetPixel macro, since that is slightly more efficient.

marc_culler added on 2020-08-03 01:47:02:
Thank you Christopher!  TkMacOSXRGBPixel is primarily used by xcolor.c which
actually calls TkpGetPixel.  The argument to TkpGetPixel is an XColor, which
has 16-bit red blue and green values.  The macro implementation of TkpGetPixel
just passes those channel values to tkMacOSXRGBPixel.  The interpretation of
the pixel field of an XColor was changed in the refactoring.  The former
implementation of ImageGetPixel used an ad-hoc construction of the pixel
value, which really should be private to tkMacOSXColor.c since that module
is responsible for the interface between XColors and NSColors or CGColors.
So I changed ImageGetPixel to have it call tkMacOSXRGBPixel instead.  But I
completely missed that the computed values were in the range 0-255 not
0-65535.  That is the only call to tkMacOSXRGBPixel outside of xlib.

I am glad you noticed that!

Can you please test the new bug-fca13549b6 branch, which addresses this by
simply shiftign the color values before passing them to tkMacOSXRGBPixel?

chrstphrchvz added on 2020-08-02 19:26:32:

I currently do not have a simple script to demonstrate this issue. I observed this while experimenting with NSImage → CALayer drawing (prompted by [685ac30727]), where trying to capture a window with TkImg only produces a completely black image. (In TkImg, ObjRead() in window.c calls XGetPixel() aka ImageGetPixel().)