diff options
author | culler <culler> | 2020-08-03 13:21:24 (GMT) |
---|---|---|
committer | culler <culler> | 2020-08-03 13:21:24 (GMT) |
commit | f9538307478bacf4b7abd687579c497f993edf40 (patch) | |
tree | e39fdb6a9b0dfece9e53aae24239ab72f30a0895 | |
parent | 78ff00814bd1260e38a3990c46571c8f5ff94c5d (diff) | |
parent | 2c6e31f7fd99017ab613b39e77357ad91b0be8c7 (diff) | |
download | tk-f9538307478bacf4b7abd687579c497f993edf40.zip tk-f9538307478bacf4b7abd687579c497f993edf40.tar.gz tk-f9538307478bacf4b7abd687579c497f993edf40.tar.bz2 |
Fix [fca13549b6]: TkMacOSXRGBPixel() used incorrectly in ImageGetPixel()
-rw-r--r-- | macosx/tkMacOSXColor.c | 13 | ||||
-rw-r--r-- | macosx/tkMacOSXImage.c | 22 | ||||
-rw-r--r-- | macosx/tkMacOSXPort.h | 2 |
3 files changed, 23 insertions, 14 deletions
diff --git a/macosx/tkMacOSXColor.c b/macosx/tkMacOSXColor.c index b4347b8..ce91520 100644 --- a/macosx/tkMacOSXColor.c +++ b/macosx/tkMacOSXColor.c @@ -112,11 +112,10 @@ void initColorTable() * Return an unsigned long value suitable for use in the pixel * field of an XColor with the specified red, green and blue * intensities. The inputs are cast as unsigned longs but are - * expected to have values representable by an unsigned short - * as used in the XColor struct. These values are divided by - * 256 to generate a 24-bit RGB pixel value. + * expected to have values representable by an unsigned char. * - * This is called by the TkpGetPixel macro, used in xcolor.c. + * This is called in the TkpGetPixel macro, used in xcolor.c, + * and in ImageGetPixel. * * Results: * An unsigned long that can be used as the pixel field of an XColor. @@ -134,9 +133,9 @@ TkMacOSXRGBPixel( { MacPixel p; p.pixel.colortype = rgbColor; - p.pixel.value = (((red >> 8) & 0xff) << 16) | - (((green >> 8) & 0xff) << 8) | - ((blue >> 8) & 0xff); + p.pixel.value = ((red & 0xff) << 16) | + ((green & 0xff) << 8) | + (blue & 0xff); return p.ulong; } diff --git a/macosx/tkMacOSXImage.c b/macosx/tkMacOSXImage.c index 4691e41..0e33b23 100644 --- a/macosx/tkMacOSXImage.c +++ b/macosx/tkMacOSXImage.c @@ -300,7 +300,11 @@ DestroyImage( * Get a single pixel from an image. * * Results: - * Returns the 32 bit pixel value. + * The XColor structure contains an unsigned long field named pixel which + * identifies the color. This function returns the unsigned long that + * would be used as the pixel value of an XColor that has the same red + * green and blue components as the XImage pixel at the specified + * location. * * Side effects: * None. @@ -316,13 +320,18 @@ ImageGetPixel( { unsigned char r = 0, g = 0, b = 0; + /* + * Compute 8 bit red green and blue values, which are passed as inputs to + * TkMacOSXRGBPixel to produce the pixel value. + */ + if (image && image->data) { unsigned char *srcPtr = ((unsigned char*) image->data) + (y * image->bytes_per_line) + (((image->xoffset + x) * image->bits_per_pixel) / NBBY); switch (image->bits_per_pixel) { - case 32: + case 32: /* 8 bits per channel */ r = (*((unsigned int*) srcPtr) >> 16) & 0xff; g = (*((unsigned int*) srcPtr) >> 8) & 0xff; b = (*((unsigned int*) srcPtr) ) & 0xff; @@ -332,12 +341,12 @@ ImageGetPixel( r = srcPtr[1]; g = srcPtr[2]; b = srcPtr[3]; }*/ break; - case 16: + case 16: /* 5 bits per channel */ r = (*((unsigned short*) srcPtr) >> 7) & 0xf8; g = (*((unsigned short*) srcPtr) >> 2) & 0xf8; b = (*((unsigned short*) srcPtr) << 3) & 0xf8; break; - case 8: + case 8: /* 2 bits per channel */ r = (*srcPtr << 2) & 0xc0; g = (*srcPtr << 4) & 0xc0; b = (*srcPtr << 6) & 0xc0; @@ -345,7 +354,7 @@ ImageGetPixel( g |= g >> 2 | g >> 4 | g >> 6; b |= b >> 2 | b >> 4 | b >> 6; break; - case 4: { + case 4: { /* 1 bit per channel */ unsigned char c = (x % 2) ? *srcPtr : (*srcPtr >> 4); r = (c & 0x04) ? 0xff : 0; @@ -353,11 +362,12 @@ ImageGetPixel( b = (c & 0x01) ? 0xff : 0; break; } - case 1: + case 1: /* Black-white bitmap. */ r = g = b = ((*srcPtr) & (0x80 >> (x % 8))) ? 0xff : 0; break; } } + return TkMacOSXRGBPixel(r, g, b); } diff --git a/macosx/tkMacOSXPort.h b/macosx/tkMacOSXPort.h index f5c3689..4347766 100644 --- a/macosx/tkMacOSXPort.h +++ b/macosx/tkMacOSXPort.h @@ -168,6 +168,6 @@ MODULE_SCOPE unsigned long TkMacOSXRGBPixel(unsigned long red, unsigned long green, unsigned long blue); -#define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red, p->green, p->blue)) +#define TkpGetPixel(p) (TkMacOSXRGBPixel(p->red >> 8, p->green >> 8, p->blue >> 8)) #endif /* _TKMACPORT */ |