Sign in to follow this  
Followers 0
Skitty

String color conversion

12 posts in this topic

#1 ·  Posted (edited)

I've searched and cannot find a solution.

I am attempting to convert some color values from RGB to BGR, obviously it's harder to do this when the color is fetched as a string from a file.

a(Dec(Hex(BinaryMid(0xFF0000, 1, 3)))); turns into a blue color well
b(Dec(Hex(BinaryMid("FF0000", 1, 3)))); mocks me as it turns into an ugly poop color and adding the "0x" just makes it red...
Sleep(3000)
Func a($a)
GUICreate("")
GUISetBkColor($a)
GUISetState()
EndFunc
Func b($b)
GUICreate("")
GUISetBkColor($b)
GUISetState()
EndFunc
Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites



0xFF0000 is just a number. That's clear right?

"FF0000" is hexadecimal string representation of that number.

Dec() returns a numeric representation of a hexadecimal string.

Therefore, if I want to turn "FF0000" into 0xFF0000 I have to Dec() it.

b(Dec(Hex(BinaryMid(Dec("FF0000"), 1, 3))))
1 person likes this

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

0xFF0000 is just a number. That's clear right?

"FF0000" is hexadecimal string representation of that number.

Dec() returns a numeric representation of a hexadecimal string.

Affirmative.

Here's what I was after.

Func _Rev($Color)
    Switch StringIsInt($Color)
        Case True
            Return Dec(Hex(BinaryMid($Color, 1, 3)))
        Case False
            Return Dec(Hex(BinaryMid(Dec(StringReplace($Color,"0x","")), 1, 3)))
    EndSwitch
EndFunc   ;==>_Rev
Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

More correct is to use If...Then than Switch for that. That's typical misuse.

Ternary operator too eventually.

edit:

Here's a question for you. How would you write that function using ternary operator?

(There are several ways, but only one is actually correct).

Don't disappoint me. :D

Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

More correct is to use If...Then than Switch for that. That's typical misuse.

Ternary operator too eventually.

edit:

Here's a question for you. How would you write that function using ternary operator?

(There are several ways, but only one is actually correct).

Don't disappoint me. :D

I remember reading a statment you made in the dev chat about enclosing them. So I would probably be cheating.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AutoIt3=C:Program FilesAutoIt3Betaautoit3.exe
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

$a1 = _Rev("090000")
$b1 = _Rev(0x090000)

ConsoleWrite((Random(0, 1, 1) ? a($a1) : b($b1))&@CR)

Sleep(3000)

Func a($a2)
GUICreate("")
GUISetBkColor($a2)
GUISetState()
Return "a"
EndFunc

Func b($b2)
GUICreate("")
GUISetBkColor($b2)
GUISetState()
Return "b"
EndFunc

Func _Rev($Color)
Return (StringIsInt($Color) ? Dec(Hex(BinaryMid($Color, 1, 3))) : Dec(Hex(BinaryMid(Dec(StringReplace($Color,"0x","")), 1, 3))))
EndFunc ;==>_Rev

Also, there seems to be a problem, that color I'm converting should be a navy blue hue, instead I am getting a black color, why?


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I remember reading a statment you made in the dev chat about enclosing them. So I would probably be cheating.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_AutoIt3=C:Program FilesAutoIt3Betaautoit3.exe
#AutoIt3Wrapper_Run_AU3Check=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

$a1 = _Rev("090000")
$b1 = _Rev(0x090000)

ConsoleWrite((Random(0, 1, 1) ? a($a1) : b($b1))&@CR)

Sleep(3000)

Func a($a2)
GUICreate("")
GUISetBkColor($a2)
GUISetState()
Return "a"
EndFunc

Func b($b2)
GUICreate("")
GUISetBkColor($b2)
GUISetState()
Return "b"
EndFunc

Func _Rev($Color)
Return (StringIsInt($Color) ? Dec(Hex(BinaryMid($Color, 1, 3))) : Dec(Hex(BinaryMid(Dec(StringReplace($Color,"0x","")), 1, 3))))
EndFunc ;==>_Rev

I'm disappointed.

Also, there seems to be a problem, that color I'm converting should be a navy blue hue, instead I am getting a black color, why?

Funny guy. Edited by trancexx

♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

I'm disappointed.

Funny guy.

Ok, so I just got back from my laboratory, dissected a goldfish and installed a new brain, and now I am able to see the fallacy in my previous post. Let me throw some context in the whole of this.

I'm working (playing really) with scintilla. I'm making a script that parses the SciTE configuration files and am extracting the color values.

As I have noticed, the color values are stored in RGB format, but they need to be sent to the scintilla control in BGR format.

This code causes the syntax highlighting for functions to appear grey, while everything else is highlighted as expected.

$Function_Fore = _GetProperty($SciteConfig, "style.au3.4","fore"); the _Rev() func is used in this call
SetStyle($Sci, $SCE_AU3_FUNCTION, $Function_Fore, $Function_Back, 0, "", 1, 1)

and using this works fine.

$Function_Fore = _Rev(0x000090)
SetStyle($Sci, $SCE_AU3_FUNCTION, $Function_Fore, $Function_Back, 0, "", 1, 1)

In the first example, the string is returned as "000090" and then I use the _rev() func to convert it for use with Scintilla and it appears black.

Func _GetProperty($Config, $Property, $Which = 0, $Rev = 0)
Local $Test = StringRegExp($Config, StringReplace($Property, ".", ".") & "=(.*)[rn]", 3)
If @error Then Return SetError(1, 0, 0x000000)
Switch StringLower($Which)
Case "fore" ; Foreground color
$Test = StringRegExp($Test[0], "fore:#(.*?)[,rn]", 3)
Case "back" ; Background color
$Test = StringRegExp($Test[0], "back:#(.*?)[,rn]", 3)
Case "#" ; just the color
$Test = StringRegExp($Test[0], "#(.*?)[,rn]", 3)
EndSwitch
If $Rev Then
$Test[0] = _Rev($Test[0])
EndIf
If @error Then Return SetError(1, 0, 0x000000)
Return SetError(0, 0, $Test[0])
EndFunc ;==>_GetProperty

Currently I have an unholy amount of free time on my hands and and decided to spend it doing this.

Posted Image

Like I was saying, it seems that some colors are not being converted correctly or something, I'm still trying to figure this out.

$Function_Fore = _Rev('000090');Returns incorrect conversion - 3158064 / looks grey/black
$Function_Fore = _Rev('0x000090');Returns correct conversion - 9437184 / looks navy blue
$Function_Fore = _Rev(0x000090);Returns correct conversion - 9437184 / looks navy blue
$Function_Fore = 0x000090; Makes functions look maroon - 144
$Function_Fore = 0x090000; Makes functions look grey/black - 589824

Edit: I forgot to beg you for insight on correct usage, you always make statements like that and then disappear, leaving people baffled and disoriented.

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Ok, thanks everybody, after some good old fashioned humiliation, I've discovered the cause of this anomaly.

The culprit was the way I used trancexxs magical functions.

This seems to work fine.

Func _Rev($Color)
If IsString($Color) Then Return Dec(Hex(BinaryMid(Dec(StringReplace($Color,"0x","")), 1, 3)))
Return Dec(Hex(BinaryMid($Color, 1, 3)))
EndFunc ;==>_Rev

it is not black it is dark blue. And the one that bog-yellow - is wrong. The problem is " ( ) ? ( ) : ( ) " If we write the function as standard, it works.

Func _Rev($Color)
    If IsString($Color) Then $Color = Dec(StringReplace($Color, "0x", ""))
    Return Dec(Hex(BinaryMid($Color, 1, 3)))
EndFunc
Oh god, I don't know how I missed your post, only if I would have seen it earlier...

The IsString thing was what I was needing so badly.

My knowledge in binary and string conversions is limited.

Edited by ApudAngelorum

Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Edit: I forgot to beg you for insight on correct usage, you always make statements like that and then disappear, leaving people baffled and disoriented.

I do? Shit.

Can you point me to some alwayses? I would like to see that for my self.


♡♡♡

.

eMyvnE

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0