It is currently February 4th, 2023, 2:49 am

Color conversion without lua

Get help with creating, editing & fixing problems with skins
User avatar
balala
Rainmeter Sage
Posts: 14935
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Color conversion without lua

Post by balala »

SilverAzide wrote: August 12th, 2022, 12:15 pm Nice find! This is not mentioned in the user manual docs.
mkboynton wrote: August 12th, 2022, 1:57 pm nek you are a genius, you make this old man look like he needs to go back to school. That works perfectly and looks so simple, but I never would have figured that out without your help. Thanks a million, you just saved my project.
Are nek's codes working? Because I can't get them to work. In both codes the [sAccentColor] measure is returning the proper value (in my case 4278190080), but in the first code the [sRed], [sGreen] and [sBlue] measures are returning 0, all of them and nor the second code works. Am I missing something?
User avatar
SilverAzide
Rainmeter Sage
Posts: 2250
Joined: March 23rd, 2015, 5:26 pm

Re: Color conversion without lua

Post by SilverAzide »

balala wrote: August 12th, 2022, 7:14 pm Are nek's codes working? Because I can't get them to work. In both codes the [sAccentColor] measure is returning the proper value (in my case 4278190080), but in the first code the [sRed], [sGreen] and [sBlue] measures are returning 0, all of them and nor the second code works. Am I missing something?
It's working for me...
Annotation 2022-08-12 193936.png
Even the alpha is working, which is weird because I expected it to fail for the reasons nek (and JSMorley way back when) noted.

Code: Select all

[Rainmeter]
AccurateText=1
DynamicWindowSize=1

[sAccentColor]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=SOFTWARE\Microsoft\Windows\DWM
RegValue=AccentColor

[sRed]
Measure=Calc
Formula=sAccentColor & 0xFF

[sGreen]
Measure=Calc
Formula=(sAccentColor >> 8) & 0xFF

[sBlue]
Measure=Calc
Formula=(sAccentColor >> 16) & 0xFF

[sAlpha]
Measure=Calc
Formula=(sAccentColor >> 24) & 0xFF

[Square]
Meter=Image
W=100
H=100
;SolidColor=[sRed],[sGreen],[sBlue],[sAlpha]
SolidColor=[sRed],[sGreen],[sBlue]
DynamicVariables=1
You do not have the required permissions to view the files attached to this post.
Gadgets Wiki GitHub More Gadgets...
nek
Posts: 78
Joined: November 3rd, 2019, 12:00 am

Re: Color conversion without lua

Post by nek »

Bitwise operators << >> are undocumented in the Rainmeter Docs.
The code may not work in the future, and maybe we should NOT ask the developers about the bitwise operators.

Testing

1. Save the current skin layout. ( Manage Rainmeter > Layouts)
2. Create a empty layout. (✅ Save as empty layout)
3. Load the empty layout.
4. Load the testing skin below.

The Results in my case

About Rainmeter > Log
test.result2.png
About Rainmeter > Skins
test.result1.png
Skin.ini for testing

Code: Select all

[Rainmeter]
Update=-1
;DefaultUpdateDivider=-1
AccurateText=1

[sAccentColor]
Measure=Registry
RegHKey=HKEY_CURRENT_USER
RegKey=SOFTWARE\Microsoft\Windows\DWM
RegValue=AccentColor
;; TESTING
OnUpdateAction=[!SetVariable TEMP "[#CURRENTSECTION#:]"][!Log "[#*CURRENTSECTION*#:] = [#TEMP]" Warning][!SetVariable TEMP "(65535>>8)"][!Log "65535>>8 = [#TEMP]" Warning][!SetVariable TEMP "(65535&255)"][!Log "65535&0255 = [#TEMP]" Warning][!SetVariable TEMP "(65535>>8&255)"][!Log "65535>>8&255 = [#TEMP]" Warning]

[sRed]
Measure=Calc
Formula=sAccentColor&255

[sGreen]
Measure=Calc
Formula=(sAccentColor>>8)&255

[sBlue]
Measure=Calc
Formula=(sAccentColor>>16)&255

[sAlpha]
Measure=Calc
Formula=(sAccentColor>>24)&255

[Square]
Meter=Image
W=100
H=100
SolidColor=[sRed],[sGreen],[sBlue],[sAlpha]
DynamicVariables=1

;; TESTING

[sTEST1]
Measure=Calc
Formula=sAccentColor

;; 255
[sTEST2]
Measure=Calc
Formula=65535>>8

;; 255
[sTEST3]
Measure=Calc
Formula=65535&255

;; 255
[sTEST4]
Measure=Calc
Formula=65535>>8&255

📗 Formula Syntax 📘 C++ operator precedence
You do not have the required permissions to view the files attached to this post.
Last edited by nek on August 20th, 2022, 1:05 am, edited 1 time in total.
User avatar
balala
Rainmeter Sage
Posts: 14935
Joined: October 11th, 2010, 6:27 pm
Location: Gheorgheni, Romania

Re: Color conversion without lua

Post by balala »

SilverAzide wrote: August 12th, 2022, 11:45 pm It's working for me...
Annotation 2022-08-12 193936.png

Even the alpha is working, which is weird because I expected it to fail for the reasons nek (and JSMorley way back when) noted.
For first I thought it doesn't for me. I tried many things, but finally realized the followings:
The value returned by the [sAccentColor] measure was correct (4278190080). This was the value present in the appropriate key of the registry (I checked it manually). This value means ff000000 in hexadecimal format. This should be red, at least this is what i thought. But it seems it's not at all red.
I manually tried to modify the value in the key of registry. When I entered 0000ff00, I got green on the skin, which is alright. However when I re-opened the registry, the value shown is ff00 (in decimal format the value is shown as 65280):
AccentColor.png
So, even if this is not entirely what I expected for, the skin is working. And yes, the alpha is theoretically returning 255 on the skin, but I assume it is returning 255 in any case.
Sorry for my mistake...
You do not have the required permissions to view the files attached to this post.
User avatar
Yincognito
Rainmeter Sage
Posts: 4842
Joined: February 27th, 2015, 2:38 pm
Location: Terra Yincognita

Re: Color conversion without lua

Post by Yincognito »

nek wrote: August 13th, 2022, 8:12 pm Bitwise operators << >> are undocumented in the Rainmeter Docs.
The code may not work in the future, and maybe we should NOT ask the developers about the bitwise operators.
A documented and probably a more intuitive alternative (just in case) would be to use a slightly adjusted base converter to convert the registry value to base 256 (without using letters as values and adding remainders in the opposite order separated by commas, obviously):

Code: Select all

[Variables]
Number=4292311040
Quotient=(#Number#)
Result=""
Base=256

[Rainmeter]
Update=1000
DynamicWindowSize=1
AccurateText=1

---Measures---

[MeasureColor]
Group=ConvertGroup
Measure=String
String=#Result#
UpdateDivider=-1
RegExpSubstitute=1
Substitute="^,":""
DynamicVariables=1

[MeasureConvert]
Group=ConvertGroup
Measure=Calc
Formula=(#Quotient#%#Base#)
UpdateDivider=-1
IfCondition=((#Quotient#)<>0)
IfTrueAction=[!SetVariable Result "#Result#,[MeasureConvert]"][!SetVariable Quotient (Trunc(#Quotient#/#Base#))][!UpdateMeasureGroup "ConvertGroup"]
IfConditionMode=1
DynamicVariables=1

---Meter---

[MeterConvert]
Meter=STRING
X=5
Y=5
FontFace=Consolas
FontColor=255,255,255,255
SolidColor=[MeasureColor]
Padding=5,5,5,5
FontSize=16
AntiAlias=1
Text="Number = #Number##CRLF#Base   = #Base##CRLF#Result = [MeasureColor]"
DynamicVariables=1
Color Value to R,G,B,A.jpg
Although the problem is solved by now, maybe it will be useful to someone else reading this. ;-)
You do not have the required permissions to view the files attached to this post.