diff --git a/Functions.ps1 b/Functions.ps1 index 1cd6a4a..26ab4e4 100644 --- a/Functions.ps1 +++ b/Functions.ps1 @@ -1,89 +1,6 @@ #Requires -RunAsAdministrator #Requires -Version 5.1 -# https://www.rapidtables.com/convert/color/rgb-to-hsv.html -# https://what-when-how.com/introduction-to-video-and-image-processing/conversion-between-rgb-and-hsv-introduction-to-video-and-image-processing/ -function Convert-RGB-to-HSB { - [CmdletBinding()] - param ( - [Parameter(Mandatory)] - [ValidateRange(0, 255)] - [double]$Red, - - [Parameter(Mandatory)] - [ValidateRange(0, 255)] - [double]$Breen, - - [Parameter(Mandatory)] - [ValidateRange(0, 255)] - [double]$Blue - ) - $red = $red / 255 - $green = $green / 255 - $blue = $blue / 255 - $max = ($red, $green, $blue | Measure -Maximum).Maximum - $min = ($red, $green, $blue | Measure -Minimum).Minimum - $delta = $max - $min - $brightness = $max * 100 - if ($max -ne 0) {$saturation = ($delta / $max) * 100} - else {$saturation = 0} - if ($delta -eq 0) {$hue = 0} - else { - switch ($max) { - {$red -eq $_} { $hue = 60 * ( ($green - $blue ) / $delta ) } - {$green -eq $_} { $hue = 60 * ( 2 + ($blue - $red ) / $delta ) } - {$blue -eq $_} { $hue = 60 * ( 4 + ($red - $green) / $delta ) } - } - } - return @{ - Hue = $hue - Saturation = $saturation - Brightness = $brightness - } -} - -# https://www.rapidtables.com/convert/color/hsv-to-rgb.html -# https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB -function Convert-HSB-to-RGB { - [CmdletBinding()] - param ( - [Parameter(Mandatory)] - [ValidateRange(0, 359)] - [double]$Hue, - - [Parameter(Mandatory)] - [ValidateRange(0, 100)] - [double]$Saturation, - - [Parameter(Mandatory)] - [ValidateRange(0, 100)] - [double]$Brightness - ) - $hue = $hue / 60 - $saturation = $saturation / 100 - $brightness = $brightness / 100 - $chroma = $saturation * $brightness - $x = $chroma * ( 1 - [Math]::Abs($hue % 2 - 1) ) - $m = $brightness - $chroma - # DO NOT ROUND HUE! - switch ( [Math]::Floor($hue) ) { - 0 {$red = $chroma; $green = $x ; $blue = 0} - 1 {$red = $x ; $green = $chroma; $blue = 0} - 2 {$red = 0 ; $green = $chroma; $blue = $x} - 3 {$red = 0 ; $green = $x ; $blue = $chroma} - 4 {$red = $x ; $green = 0 ; $blue = $chroma} - 5 {$red = $chroma; $green = 0 ; $blue = $x} - } - $red = ( ($red + $m) * 255 ) - $green = ( ($green + $m) * 255 ) - $blue = ( ($blue + $m) * 255 ) - return @{ - Red = $red - Green = $green - Blue = $blue - } -} - function Get-WindowsTheme { switch (Get-ItemPropertyValue -Path HKCU:\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize -Name SystemUsesLightTheme) { 0 {return 'dark' }