Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Bug in RGB() function
Message
De
26/06/2015 04:12:10
 
 
À
26/06/2015 03:43:37
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01621469
Message ID:
01621477
Vues:
70
The Fox Wiki page explains pretty clearly how it all works.

>if the decimal number returned by RGB() is using the parameters in backwards order, that is a major bug that contradicts all the VFP docs and common sense. It also is internally contradictory. Using the RGB() function to set a color property works exactly as the docs say and as one would assume - R then G then B. But the RGB() functon returns a completely different number when used not to set a property but as a function to return a value.
>
>IOW .backcolor=rgb(204,198,149) shows the correct color. And it returns the correct value. But the function RGB() when used by itself returns a number based on backwards BGR order. That is beyond inexplicable. VFP is really using BGR but internally converts everything in a color property to RGB?
>
>
>>>Either I am missing something or there is a significant bug in the RGB function.
>>>
>>>The value of RGB((204,198,149) is returned as 9815756. In hex this is #95C6CC.
>>>
>>>That is completely wrong. The value of RGB(204,198,149) is 13420181. In hex that is #CCC695.
>>>
>>>I finally figured out the problem: any time the first number was > 99, the RGB() function is returning the number of the RGB in _opposite_ order! IOW the value of RGB(204,198,149) should be 13420181, yet VFP returns 9815756. However doing the RGB backwards, as in RGB(149,198,204) results in the correct decimal for the original order: 13420181.
>>>
>>>VFP is reversing the parameters, seemingly randomly, but I ran that RGB on 3 different PC's and it always came up the same wrong answer.
>>>
>>>Anybody know anything about this?
>>>
>>>TIA
>>
>>It might be that the RGB() function is not doing what you expect: http://fox.wikis.com/wc.dll?Wiki~VFPFunctionRGB~Wiki
>>
>>The RGB() function and its inverse RGBCOMP() (in FoxTools.FLL) are consistent:
>>
>>SET LIBRARY TO ( HOME( ) + "FoxTools.FLL" ) && for RGBCOMP() function, see FoxTools.CHM help
>>
>>CREATE CURSOR TestResults ;
>>	( RedVal I ;
>>	, GreenVal I ;
>>	, BlueVal I ;
>>	, RedValOK L ;
>>	, GreenValOK L ;
>>	, BlueValOK L )
>>
>>LOCAL ;
>>	lnRedTest ;
>>	, lnGreenTest ;
>>	, lnBlueTest ;
>>	, lnRedResult ;
>>	, lnGreenResult ;
>>	, lnBlueResult
>>
>>FOR m.lnRedTest = 0 TO 255 STEP 1
>>	FOR m.lnGreenTest = 0 TO 255 STEP 1
>>		FOR m.lnBlueTest = 0 TO 255 STEP 1
>>			=RGBCOMP( RGB( m.lnRedTest, m.lnGreenTest, m.lnBlueTest ), @m.lnRedResult, @m.lnGreenResult, @m.lnBlueResult )
>>			
>>			INSERT INTO TestResults ;
>>				( RedVal ;
>>				, GreenVal ;
>>				, BlueVal ;
>>				, RedValOK ;
>>				, GreenValOK ;
>>				, BlueValOK ) ;
>>				VALUES ;
>>					( m.lnRedTest ;
>>					, m.lnGreenTest ;
>>					, m.lnBlueTest ;
>>					, ( m.lnRedTest = m.lnRedResult ) ;
>>					, ( m.lnGreenTest = m.lnGreenResult ) ;
>>					, ( m.lnBlueTest = m.lnBlueResult ) )
>>		
>>		ENDFOR
>>	
>>	ENDFOR
>>
>>ENDFOR
>>
>>SELECT ;
>>	* ;
>>	FROM TestResults A ;
>>	WHERE NOT A.RedValOK ;
>>		OR NOT A.GreenValOK ;
>>		OR NOT A.BlueValOK ;
>>	INTO CURSOR RGBFuncBugs ;
>>	ORDER BY A.RedVal, A.GreenVal, A.BlueVal
>>
>>* Zero rows returned in RGBFuncBugs cursor
>>
>>Interesting side note - on my system, all of the above code, including the SELECT at the end, runs in just about exactly one minute. It's generating a little over 16M rows in the TestResults cursor in that time, or more than 250,000 rows per second !
Regards. Al

"Violence is the last refuge of the incompetent." -- Isaac Asimov
"Never let your sense of morals prevent you from doing what is right." -- Isaac Asimov

Neither a despot, nor a doormat, be

Every app wants to be a database app when it grows up
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform