Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the "W" in this RGBAW color space matrix #10784

Open
Joachim-Otahal opened this issue Dec 23, 2024 · 2 comments
Open

What is the "W" in this RGBAW color space matrix #10784

Joachim-Otahal opened this issue Dec 23, 2024 · 2 comments
Labels
area-System.Drawing untriaged New issue has not been triaged by the area owner

Comments

@Joachim-Otahal
Copy link

Type of issue

Missing information

Description

That article helped me a lot to massively speed up an image invert and color change in powershell.
But what is the "W" in the color space here? I tried to find anything, but all search results link back to this article.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.colormatrix?view=windowsdesktop-9.0

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Drawing.Imaging/ColorMatrix.xml

Document Version Independent Id

965b4c7a-083d-b594-f75d-e4f63b71e2e0

Article author

@dotnet-bot

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label Dec 23, 2024
@gfoidl
Copy link
Member

gfoidl commented Dec 24, 2024

White.

@Joachim-Otahal
Copy link
Author

White.

Thank you for your response in the 24th of December! I suspected too, but...
How or when is it applied? I changed the fifth value to 0, 0.5, 1, 1000, -1000 in each row. And the outcome is no different, pixel exact the same transformation as the rest of that colormatrix says.
Is it applied only when a specific colorspace is used? The source and destination picture it is applied to is: [System.Drawing.Imaging.PixelFormat]::Format24bppRgb. Or is there something else how this value is used?

The whole powershell code used is this, to invert a white background diagram into dark color scheme and then gamma up the lower values to be better visible as a non-intrusive regularly updated windows wallpaper. $bmp is the original to be transformed. (Code to update the currently shown wallpaper is left out)

# https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.colormatrix
$ColorMatrix = [System.Drawing.Imaging.ColorMatrix]::new( [float[][]] @(
        [float[]](-0.2, 0, 0, 0, 0), # Invert R
        [float[]](0, -0.2, 0, 0, 0), # Invert G
        [float[]](0, 0, -0.2, 0, 0), # Invert B
        [float[]](0, 0, 0, 1, 0),  # Alpha: Do nothing
        [float[]](0.2, 0.2, 0.2, 0, 1)   # Translate/Offset RGBA
    )
)
# https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.imageattributes
$ImageAttributes = [System.Drawing.Imaging.ImageAttributes]::new()
$ImageAttributes.SetColorMatrix($ColorMatrix)
# https://learn.microsoft.com/en-us/dotnet/api/system.drawing.imaging.imageattributes.setgamma
$ImageAttributes.SetGamma(0.6)
$bmpinv = [System.Drawing.Bitmap]::new($bmp.Width,$bmp.Height,[System.Drawing.Imaging.PixelFormat]::Format24bppRgb)
$pictinv = [System.Drawing.Graphics]::FromImage($bmpinv)
$pictinv.DrawImage($bmp, # Source image
    [System.Drawing.Rectangle]::new(0,0,$bmp.Width,$bmp.Height), # Destination rectangle, here same as source
    0,0,$bmp.Width,$bmp.Height, # Source rectangle.
    [System.Drawing.GraphicsUnit]::Pixel, # We want 1:1 not inch or whatever
    $ImageAttributes # Finally the matrix
)
$bmpinv.Save("$DataBaseDir\today-inv.png",[System.Drawing.Imaging.ImageFormat]::Png)
$pictinv.Dispose()
$bmpinv.Dispose()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-System.Drawing untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

2 participants