user0_x_0 Posted February 14, 2019 Posted February 14, 2019 Hello , sorry if can say this clearly , am new to forums and to autoit v3 to I tried running the code bet the hex calculation is not correct, anybody help show where the error is and a fix?? console log------------------- >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\User0x0\Desktop\hex inverters.au3" Line No 2 - {6} FFFFF1 ~ 416FFFFFE0000000 Line No 4 - {6} 000000 ~ 416FFFFFE0000000 Line No 7 - {6} 000000 ~ 416FFFFFE0000000 Line No 8 - {6} 000000 ~ 416FFFFFE0000000 Line No 9 - {6} 000000 ~ 416FFFFFE0000000 Line No 10 - {6} 000000 ~ 416FFFFFE0000000 Line No 11 - {6} 000000 ~ 416FFFFFE0000000 Line No 12 - {6} 000000 ~ 416FFFFFE0000000 colors.xml hex inverters.au3
FrancescoDiMuro Posted February 14, 2019 Posted February 14, 2019 @user0_x_0 What kind of calculation are you attempting to do? Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette
Malkey Posted February 14, 2019 Posted February 14, 2019 (edited) It appears you are trying to subtract a 32 bit colour in 0xAARRGGBB hex format away from fully opaque white, 0xFFFFFFFF. The 0xAARRGGBB hex colour format is made up of 4 channels - Alpha (transparency), Red, Green, and Blue. Each channel is 8 bits (0 to 0xFF or 0 to 255). 0x00RRGGBB colour is fully transparent (AA is zero) so it does not mater what the RGB channels values are. 0xFF000000 is fully opaque black. Note, there are no RGB colour values, which makes black, the darkest colour. 0xFFFFFFFF is fully opaque white. Note, all the RGB colour values are maxed out, making white the lightest colour. And, R=G=B values gives different shades of grey from black to white. Note: If any fully opaque ARGB colour is inverted, the A channel of 0xFF will become 0x00 and the colour will become completely invisible. #NoTrayIcon #include <File.au3> #include <Array.au3> #include <String.au3> $file = FileReadToArray("colors.xml") $e = _ArrayAdd($file, " ") _ArrayDisplay($file, "Total is " & $e) For $i = 0 To $e - 1 If (StringInStr($file[$i], '">#') <> 0) Then $col = _StringBetween($file[$i], '">#', '</color>') ; _ArrayDisplay($col) $col = StringRight($col[0], 8) ConsoleWrite($col & @TAB) $col = "0x" & StringUpper($col) ConsoleWrite($col & @TAB) ConsoleWrite("Line No " & $i & " - {" & (StringLen($col) - 2) * 4 & " bit} " & $col & " = 0xFFFFFFFF - " & "0x" & Hex(0xFFFFFFFF - Int($col), 8) & @CRLF) EndIf Next ;MsgBox(0, "Test", Hex(0xFFFFFF - 0x54a4cd, 6)) Edited February 14, 2019 by Malkey
user0_x_0 Posted February 14, 2019 Author Posted February 14, 2019 20 minutes ago, Malkey said: It appears you are trying to subtract a 32 bit colour in 0xAARRGGBB hex format away from fully opaque white, 0xFFFFFFFF. The 0xAARRGGBB hex colour format is made up of 4 channels - Alpha (transparency), Red, Green, and Blue. Each channel is 8 bits (0 to 0xFF or 0 to 255). 0x00RRGGBB colour is fully transparent (AA is zero) so it does not mater what the RGB channels values are. 0xFF000000 is fully opaque black. Note, there are no RGB colour values, which makes black, the darkest colour. 0xFFFFFFFF is fully opaque white. Note, all the RGB colour values are maxed out, making white the lightest colour. And, R=G=B values gives different shades of grey from black to white. Note: If any fully opaque ARGB colour is inverted, the A channel of 0xFF will become 0x00 and the colour will become completely invisible. #NoTrayIcon #include <File.au3> #include <Array.au3> #include <String.au3> $file = FileReadToArray("colors.xml") $e = _ArrayAdd($file, " ") _ArrayDisplay($file, "Total is " & $e) For $i = 0 To $e - 1 If (StringInStr($file[$i], '">#') <> 0) Then $col = _StringBetween($file[$i], '">#', '</color>') ; _ArrayDisplay($col) $col = StringRight($col[0], 8) ConsoleWrite($col & @TAB) $col = "0x" & StringUpper($col) ConsoleWrite($col & @TAB) ConsoleWrite("Line No " & $i & " - {" & (StringLen($col) - 2) * 4 & " bit} " & $col & " = 0xFFFFFFFF - " & "0x" & Hex(0xFFFFFFFF - Int($col), 8) & @CRLF) EndIf Next ;MsgBox(0, "Test", Hex(0xFFFFFF - 0x54a4cd, 6)) oh I see , so u r saying I must consider the alpha channel? can I let be as it is and invert the RGB only
Malkey Posted February 14, 2019 Posted February 14, 2019 (edited) @user0_x_0 Looking at your attached "colors.xml" file, there are references to varying degrees of transparency together with the word Alpha. It really depends on what the objective of inverting the colours is. As a general rule it would be more practical to invert only on the RGB channels. This example keeps the original Alpha channel and combines it to the invert of the RGB channels. #NoTrayIcon #include <File.au3> #include <Array.au3> #include <String.au3> $file = FileReadToArray("colors.xml") $e = _ArrayAdd($file, " ") ;_ArrayDisplay($file, "Total is " & $e) For $i = 0 To $e - 1 If (StringInStr($file[$i], '">#') <> 0) Then $col = _StringBetween($file[$i], '">#', '</color>') ; _ArrayDisplay($col) $Alp = StringUpper(StringLeft($col[0], 2)) ConsoleWrite($Alp & @TAB) $RGB = StringUpper(StringRight($col[0], 6)) ConsoleWrite($RGB & @TAB) ConsoleWrite("Line No " & $i & " ~ Alpha & (0xFFFFFF - 0x" & $RGB & ") = 0x" & $Alp & Hex(0xFFFFFF - Int("0x" & $RGB), 6) & @CRLF) EndIf Next ;MsgBox(0, "Test", Hex(0xFFFFFF - 0x54a4cd, 6)) Edited February 14, 2019 by Malkey
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now