Jump to content

Something wrong with Hue Part (RGB2HSV8)


Recommended Posts

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 by Reptillian

G'MIC Filter Developer

Link to comment
Share on other sites

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.

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...