[英]How to Set Luminance for HueModifier - Aforge.Net
I'm using Aforge.net HueModifier and SaturationCorrection filters to change image color. 我正在使用Aforge.net HueModifier和SaturationCorrection过滤器来更改图像颜色。 My problem is how to set Luminance alongside these filters to get the desired color?
我的问题是如何在这些滤镜旁边设置“亮度”以获得所需的颜色?
I was able to get this issue solved by writing a custom Aforge.net filter. 通过编写自定义Aforge.net过滤器,我能够解决此问题。 The filter takes HSL color value and apply color tint to the provided image.
滤镜获取HSL颜色值并将颜色应用于所提供的图像。
protected override unsafe void ProcessFilter(UnmanagedImage image, Rectangle rect)
{
int pixelSize = Bitmap.GetPixelFormatSize(image.PixelFormat)/8;
int startX = rect.Left;
int startY = rect.Top;
int stopX = startX + rect.Width;
int stopY = startY + rect.Height;
int offset = image.Stride - rect.Width*pixelSize;
var rgb = new RGB();
var hsl = new HSL();
// do the job
byte* ptr = (byte*) image.ImageData.ToPointer();
// allign pointer to the first pixel to process
ptr += (startY*image.Stride + startX*pixelSize);
// for each row
for (int y = startY; y < stopY; y++)
{
// for each pixel
for (int x = startX; x < stopX; x++, ptr += pixelSize)
{
rgb.Red = ptr[RGB.R];
rgb.Green = ptr[RGB.G];
rgb.Blue = ptr[RGB.B];
// convert to HSL
HSL.FromRGB(rgb, hsl);
// modify hsl values
hsl.Hue = hue;
hsl.Saturation = saturation;
hsl.Luminance = Math.Min(0.97f, hsl.Luminance * (120 * luminance / 65));
// convert back to RGB
HSL.ToRGB(hsl, rgb);
ptr[RGB.R] = (byte)rgb.Red;
ptr[RGB.G] = (byte)rgb.Green;
ptr[RGB.B] = (byte)rgb.Blue;
}
ptr += offset;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.