Skip Menu |

This queue is for tickets about the Tk CPAN distribution.

Report information
The Basics
Id: 59089
Status: resolved
Priority: 0/
Queue: Tk

People
Owner: Nobody in particular
Requestors: DJIBEL [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Critical
Broken in:
  • 804.028
  • 804.029
Fixed in: (no value)



Subject: Bug in rgb method (Tk::Widget)
Dear, I am using Perl v5.10.1 Binary build 1007 [291969]. OS : WinVista, WinXP, Win2000, Linux Debian, Linux Suse, ... There is a bug with rgb method when the argument is a hexa code color with 3 letters (perldoc Tk::Widget). For example, print $top->rgb('#FFF'); => give 61680, 61680, 61680 and it is wrong. The good result should be 65535, 65535, 65535. Then #FFF give #F0F0F0 and not #FFFFFF That is a program test which show bugs and how to resolve it. I have not found the code in Tk package to create a patch then you can use this program to update Tk module. #!/usr/bin/perl use strict; use warnings; use Tk; use Test::More tests => 80; my %ColorCode = ( #3Letters 6Letters RGB 16 bits RGB 8 bits '#F8D' => [ '#FF88DD', ( 65535, 34952, 56797 ), ( 255, 136, 221 ) ], '#FFF' => [ '#FFFFFF', ( 65535, 65535, 65535 ), ( 255, 255, 255 ) ], '#000' => [ '#000000', ( 0, 0, 0 ), ( 0, 0, 0 ) ], '#FFC' => [ '#FFFFCC', ( 65535, 65535, 52428 ), ( 255, 255, 204 ) ], '#FF9' => [ '#FFFF99', ( 65535, 65535, 39321 ), ( 255, 255, 153 ) ], '#FF6' => [ '#FFFF66', ( 65535, 65535, 26214 ), ( 255, 255, 102 ) ], '#FC0' => [ '#FFCC00', ( 65535, 52428, 0 ), ( 255, 204, 0 ) ], '#669' => [ '#666699', ( 26214, 26214, 39321 ), ( 102, 102, 153 ) ], '#66C' => [ '#6666CC', ( 26214, 26214, 52428 ), ( 102, 102, 204 ) ], '#C00' => [ '#CC0000', ( 52428, 0, 0 ), ( 204, 0, 0 ) ], ); my $top = new MainWindow; foreach my $color ( sort keys %ColorCode ) { # RGB Tk my ( $Redtk, $Greentk, $Bluetk ) = $top->rgb($color); # Found hex color (6 letters) my $hex_color_tk = sprintf( "#%02X%02X%02X", map { $_ / 257 } ( $Redtk, $Greentk, $Bluetk ) ); print "Color : $color\nRGB Tk : $Redtk, $Greentk, $Bluetk\nHex TK : $hex_color_tk\n"; #============================ # Test RGB Tk from real code # R is( $Redtk, $ColorCode{$color}->[1], 'Good R' ); # G is( $Greentk, $ColorCode{$color}->[2], 'Good G' ); # B is( $Bluetk, $ColorCode{$color}->[3], 'Good B' ); # Hex is( $hex_color_tk, $ColorCode{$color}->[0], 'Good hexa color - letters' ); print "=================================================================\n"; } #================================================== # How to calculate real hexa code from 3 letters to 6 print "=================================================================\n"; print "=================================================================\n"; foreach my $color ( sort keys %ColorCode ) { if ( my @RGB = $color =~ m{^#([0-9A-Z])([0-9A-Z])([0-9A-Z])$}i ) { @RGB = map { hex($_) * 17 * 257 } @RGB; my $hex_color = sprintf( "#%02X%02X%02X", map { $_ / 257 } @RGB ); print "Color : $hex_color\nRGB : @RGB\n"; #============================ # Test RGB Tk from real code # R is( $RGB[0], $ColorCode{$color}->[1], 'Good R' ); # G is( $RGB[1], $ColorCode{$color}->[2], 'Good G' ); # B is( $RGB[2], $ColorCode{$color}->[3], 'Good B' ); # Hex is( $hex_color, $ColorCode{$color}->[0], 'Good hexa color - letters' ); print "=================================================================\n"; } } The result of this program is in the join file. Best Regards,
Subject: RGBResult.txt
1..80 Color : #000 RGB Tk : 0, 0, 0 Hex TK : #000000 ok 1 - Good R ok 2 - Good G ok 3 - Good B ok 4 - Good hexa color - letters ================================================================= Color : #669 RGB Tk : 24672, 24672, 37008 Hex TK : #606090 not ok 5 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '24672' # expected: '26214' not ok 6 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '24672' # expected: '26214' not ok 7 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '37008' # expected: '39321' not ok 8 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#606090' # expected: '#666699' ================================================================= Color : #66C RGB Tk : 24672, 24672, 49344 Hex TK : #6060C0 not ok 9 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '24672' # expected: '26214' not ok 10 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '24672' # expected: '26214' not ok 11 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '49344' # expected: '52428' not ok 12 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#6060C0' # expected: '#6666CC' ================================================================= Color : #C00 RGB Tk : 49344, 0, 0 Hex TK : #C00000 not ok 13 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '49344' # expected: '52428' ok 14 - Good G ok 15 - Good B not ok 16 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#C00000' # expected: '#CC0000' ================================================================= Color : #F8D RGB Tk : 61680, 32896, 53456 Hex TK : #F080D0 not ok 17 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '61680' # expected: '65535' not ok 18 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '32896' # expected: '34952' not ok 19 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '53456' # expected: '56797' not ok 20 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#F080D0' # expected: '#FF88DD' ================================================================= Color : #FC0 RGB Tk : 61680, 49344, 0 Hex TK : #F0C000 not ok 21 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '61680' # expected: '65535' not ok 22 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '49344' # expected: '52428' ok 23 - Good B not ok 24 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#F0C000' # expected: '#FFCC00' ================================================================= Color : #FF6 RGB Tk : 61680, 61680, 24672 Hex TK : #F0F060 not ok 25 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '61680' # expected: '65535' not ok 26 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '61680' # expected: '65535' not ok 27 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '24672' # expected: '26214' not ok 28 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#F0F060' # expected: '#FFFF66' ================================================================= Color : #FF9 RGB Tk : 61680, 61680, 37008 Hex TK : #F0F090 not ok 29 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '61680' # expected: '65535' not ok 30 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '61680' # expected: '65535' not ok 31 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '37008' # expected: '39321' not ok 32 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#F0F090' # expected: '#FFFF99' ================================================================= Color : #FFC RGB Tk : 61680, 61680, 49344 Hex TK : #F0F0C0 not ok 33 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '61680' # expected: '65535' not ok 34 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '61680' # expected: '65535' not ok 35 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '49344' # expected: '52428' not ok 36 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#F0F0C0' # expected: '#FFFFCC' ================================================================= Color : #FFF RGB Tk : 61680, 61680, 61680 Hex TK : #F0F0F0 not ok 37 - Good R # Failed test 'Good R' # at C:\test.pl line 36. # got: '61680' # expected: '65535' not ok 38 - Good G # Failed test 'Good G' # at C:\test.pl line 39. # got: '61680' # expected: '65535' not ok 39 - Good B # Failed test 'Good B' # at C:\test.pl line 42. # got: '61680' # expected: '65535' not ok 40 - Good hexa color - letters # Failed test 'Good hexa color - letters' # at C:\test.pl line 45. # got: '#F0F0F0' # expected: '#FFFFFF' ================================================================= ================================================================= ================================================================= Color : #000000 RGB : 0 0 0 ok 41 - Good R ok 42 - Good G ok 43 - Good B ok 44 - Good hexa color - letters ================================================================= Color : #666699 RGB : 26214 26214 39321 ok 45 - Good R ok 46 - Good G ok 47 - Good B ok 48 - Good hexa color - letters ================================================================= Color : #6666CC RGB : 26214 26214 52428 ok 49 - Good R ok 50 - Good G ok 51 - Good B ok 52 - Good hexa color - letters ================================================================= Color : #CC0000 RGB : 52428 0 0 ok 53 - Good R ok 54 - Good G ok 55 - Good B ok 56 - Good hexa color - letters ================================================================= Color : #FF88DD RGB : 65535 34952 56797 ok 57 - Good R ok 58 - Good G ok 59 - Good B ok 60 - Good hexa color - letters ================================================================= Color : #FFCC00 RGB : 65535 52428 0 ok 61 - Good R ok 62 - Good G ok 63 - Good B ok 64 - Good hexa color - letters ================================================================= Color : #FFFF66 RGB : 65535 65535 26214 ok 65 - Good R ok 66 - Good G ok 67 - Good B ok 68 - Good hexa color - letters ================================================================= Color : #FFFF99 RGB : 65535 65535 39321 ok 69 - Good R ok 70 - Good G ok 71 - Good B ok 72 - Good hexa color - letters ================================================================= Color : #FFFFCC RGB : 65535 65535 52428 ok 73 - Good R ok 74 - Good G ok 75 - Good B ok 76 - Good hexa color - letters ================================================================= Color : #FFFFFF RGB : 65535 65535 65535 ok 77 - Good R ok 78 - Good G ok 79 - Good B ok 80 - Good hexa color - letters ================================================================= # Looks like you failed 33 tests of 80. C:\>
On 2010-07-04 10:33:35, DJIBEL wrote: Show quoted text
> Dear, > > I am using Perl v5.10.1 Binary build 1007 [291969]. > OS : WinVista, WinXP, Win2000, Linux Debian, Linux Suse, ... > > There is a bug with rgb method when the argument is a hexa code color > with 3 letters (perldoc Tk::Widget). > For example, > print $top->rgb('#FFF'); > > => give 61680, 61680, 61680 and it is wrong. The good result should
be Show quoted text
> 65535, 65535, 65535. Then #FFF give #F0F0F0 and not #FFFFFF > > That is a program test which show bugs and how to resolve it. I have
not Show quoted text
> found the code in Tk package to create a patch then you can use this > program to update Tk module. >
[...] Show quoted text
> > The result of this program is in the join file. > > Best Regards, >
I think Tk is behaving correct here. Please look into http://www.xfree86.org/current/X.7.html#sect10 and especially the paragraph: The R, G, and B represent single hexadecimal digits. When fewer than 16 bits each are specified, they represent the most-significant bits of the value (unlike the "rgb:" syntax, in which values are scaled). For example, #3a7 is the same as #3000a0007000. So #FFF -> (240,240,240) is correct. Regards, Slaven
CC: undisclosed-recipients: ;
Subject: Re: [rt.cpan.org #59089] Bug in rgb method (Tk::Widget)
Date: Sun, 26 Sep 2010 16:35:20 -0700
To: Slaven_Rezic via RT <bug-Tk [...] rt.cpan.org>
From: Ilya Zakharevich <nospam-abuse [...] ilyaz.org>
On Sun, Sep 26, 2010 at 04:56:26PM -0400, Slaven_Rezic via RT wrote: Show quoted text
> The R, G, and B represent single hexadecimal digits. When fewer than 16 > bits each are specified, they represent the most-significant bits of the > value (unlike the "rgb:" syntax, in which values are scaled). For > example, #3a7 is the same as #3000a0007000. > > So #FFF -> (240,240,240) is correct.
On contemporary systems, "they represent the most-significant bits" does not preclude the less significant bits to have "the correct" values. So #A is scaled to 0xAAAA when going from 4-bit to 16-bit. The heuristic is that 0 represents black, and MAX represents white. Yours, Ilya
Le Dim 26 Sep 2010 19:35:32, nospam-abuse@ilyaz.org a écrit : Show quoted text
> On Sun, Sep 26, 2010 at 04:56:26PM -0400, Slaven_Rezic via RT wrote:
> > The R, G, and B represent single hexadecimal digits. When fewer than 16 > > bits each are specified, they represent the most-significant bits of the > > value (unlike the "rgb:" syntax, in which values are scaled). For > > example, #3a7 is the same as #3000a0007000. > > > > So #FFF -> (240,240,240) is correct.
> > On contemporary systems, "they represent the most-significant bits" > does not preclude the less significant bits to have "the correct" values. > So #A is scaled to 0xAAAA when going from 4-bit to 16-bit. > > The heuristic is that 0 represents black, and MAX represents white. > > Yours, > Ilya
Thank you