Jump to content

RGB-8 To HSV-8


Recommended Posts

A simple plugin to convert images from RGB-8 to HSV-8 (0-255 Range). There's no parameter. Just click it after installation.

 

After installation, you will find this under Effect->Color.

 

Download Link - RGB2HSV8.zip

 

Preview:

 

unknown.png

 

Code License: CC0 (Free to use, no credits or permission required)

Codelab Source (Too simple to figure out, but here it goes):

Spoiler
// Name: RGB-8 To HSV-8
// Submenu: Color
// Author: Reptorian
// Title: 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

float mod(float x, float m) {
    return (x%m + m)%m;
}

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 = 42.618f*(
                C==0?0
                :M==R?mod((fG - fB)/fC,6)
                :M==G?(fB - fR)/fC + 2f
                :(fR - fG)/fC + 4f
            );
            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
  • Like 1
  • Upvote 2

G'MIC Filter Developer

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.

 Share

×
×
  • Create New...