| Description: |
OriginalBugID: 4919 Bug
Version: 8.3
SubmitDate: '2000-04-07'
LastModified: '2000-04-16'
Severity: MED
Status: Released
Submitter: angie
ChangedBy: hobbs
OS: All Windows
FixedDate: '2000-04-16'
FixedInVersion: 8.3.1
Name: George A. Howlett
ObservedBehavior:
In tkWinColor.c the RGB components are scaled incorrectly. It's a common
error to simply shift the values.
colorPtr->red = GetRValue(colorPtr->pixel) << 8;
colorPtr->green = GetGValue(colorPtr->pixel) << 8;
colorPtr->blue = GetBValue(colorPtr->pixel) << 8;
This scales each 8-bit RGB color component into its corresponding
16-bit component in an XColor structure.
For example, if the 8-bit value is 255, the 16-bit value should be 65535.
but FF << 8 is FF00, not FFFF
Instead of left shifting 8 (multiply by 256), the value needs to be
multiplied by 257.
255 * 257 = 65535
Since it's rare to use an RGB component bigger than 8-bits, you usually
don't notice the error. This causes problems when generating PostScript.
Patch:
*** tkWinColor.c.~1~Thu Apr 15 21:51:49 1999
--- tkWinColor.cThu Apr 06 16:05:19 2000
***************
*** 156,164 ****
*indexPtr = sysColors[i].index;
colorPtr->pixel = GetSysColor(sysColors[i].index);
! colorPtr->red = GetRValue(colorPtr->pixel) << 8;
! colorPtr->green = GetGValue(colorPtr->pixel) << 8;
! colorPtr->blue = GetBValue(colorPtr->pixel) << 8;
colorPtr->flags = DoRed|DoGreen|DoBlue;
colorPtr->pad = 0;
return 1;
--- 156,164 ----
*indexPtr = sysColors[i].index;
colorPtr->pixel = GetSysColor(sysColors[i].index);
! colorPtr->red = GetRValue(colorPtr->pixel) * 257;
! colorPtr->green = GetGValue(colorPtr->pixel) * 257;
! colorPtr->blue = GetBValue(colorPtr->pixel) * 257;
colorPtr->flags = DoRed|DoGreen|DoBlue;
colorPtr->pad = 0;
return 1;
***************
*** 373,381 ****
if ((index >= cmap->size) || (newPixel != closePixel)) {
if (cmap->size == sizePalette) {
! color->red = closeEntry.peRed << 8;
! color->green = closeEntry.peGreen << 8;
! color->blue = closeEntry.peBlue << 8;
entry = closeEntry;
if (index >= cmap->size) {
OutputDebugString("XAllocColor: Colormap is bigger than we thought");
--- 373,381 ----
if ((index >= cmap->size) || (newPixel != closePixel)) {
if (cmap->size == sizePalette) {
! color->red = closeEntry.peRed * 257;
! color->green = closeEntry.peGreen * 257;
! color->blue = closeEntry.peBlue * 257;
entry = closeEntry;
if (index >= cmap->size) {
OutputDebugString("XAllocColor: Colormap is bigger than we thought");
***************
*** 404,412 ****
color->pixel = GetNearestColor(dc,
RGB(entry.peRed, entry.peGreen, entry.peBlue));
! color->red = (GetRValue(color->pixel) << 8);
! color->green = (GetGValue(color->pixel) << 8);
! color->blue = (GetBValue(color->pixel) << 8);
}
ReleaseDC(NULL, dc);
--- 404,412 ----
color->pixel = GetNearestColor(dc,
RGB(entry.peRed, entry.peGreen, entry.peBlue));
! color->red = (GetRValue(color->pixel) * 257);
! color->green = (GetGValue(color->pixel) * 257);
! color->blue = (GetBValue(color->pixel) * 257);
}
ReleaseDC(NULL, dc);
Comments:
This bug exists is all versions of Tk 8.x.
Posted To comp.lang.tcl: Posted Successfully
Fixed for 8.3.1.
-- 04/16/2000 hobbs
|