Reptillian Posted July 23, 2022 Share Posted July 23, 2022 (edited) It seems that HSV8 is not outputting the correct value. The second and third channel are fine. It is the first channel that is not correct. All I know is that last shade of red with mixture of blue is wrong. Spoiler // Name: Convert RGB-8 To HSV-8 // Submenu: Adjustments // Author: Reptorian. // Title: Convert RGB-8 To HSV-8 // Version: 1 // Desc: Convert RGB-8 To HSV-8 // Keywords: Color // URL: https://forums.getpaint.net/profile/85868-reptillian/ // Help: #region UICode #endregion void Render(Surface dst, Surface src, Rectangle rect) { // Delete any of these lines you don't need int R,G,B,M,C; float H,fR,fG,fB,fM,fC,S; ColorBgra currentPixel; for (int y = rect.Top; y < rect.Bottom; y++) { if (IsCancelRequested) return; for (int x = rect.Left; x < rect.Right; x++) { currentPixel = src[x,y]; R = currentPixel.R; G = currentPixel.G; B = currentPixel.B; M = Math.Max(Math.Max(R,G),B); C = M - Math.Min(Math.Min(R,G),B); fR=(float)(R); fG=(float)(G); fB=(float)(B); fM=(float)(M); fC=(float)(C); H=(float)(42.5*( C==0?0 :M==R?((fG-fB)/fC)%6 :M==G?(fB-fR)/fC+2 :(fR-fG)/fC+4 )); S=M==0?0:fC/fM; dst[x,y] = ColorBgra.FromBgraClamped(M,(float)(Math.Round(S*255)),(float)(Math.Round(H)),currentPixel.A); } } } Edited July 23, 2022 by Reptillian Quote G'MIC Filter Developer Link to comment Share on other sites More sharing options...
Reptillian Posted July 23, 2022 Author Share Posted July 23, 2022 I figured it out, I had to implement a mod operator again. Close this please. 1 Quote G'MIC Filter Developer Link to comment Share on other sites More sharing options...
Rick Brewster Posted July 25, 2022 Share Posted July 25, 2022 BTW, in the upcoming v4.4 release, this sort of thing will be very easy to accomplish when writing a GPU effect. You'll be able to use Direct2D's RgbToHueEffect and HueToRgbEffect to convert between RGB and HSV or HSL. So you could, for example, use RgbToHueEffect to convert from RGB to HSV or HSL, then write a pixel shader to do processing in HSV/HSL space, and then use HueToRgbEffect to convert back to RGB. Note that a "Direct2D effect" (IDeviceEffect) is not the same as a "Paint.NET effect" (Effect, GpuEffect, PropertyBasedEffect, etc.). The former (Direct2D effects) are used for rendering and can be chained/combined into something called an effect graph, while the latter (Paint.NET effects) includes rendering and UI, and do not (currently/natively) support chaining. Quote The Paint.NET Blog: https://blog.getpaint.net/ Donations are always appreciated! https://www.getpaint.net/donate.html Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.