public static FromBgra ( byte b, byte g, byte r, byte a ) : |
||
b | byte | |
g | byte | |
r | byte | |
a | byte | |
return |
public unsafe void RenderColorDifferenceEffect(double[][] weights, ImageSurface src, ImageSurface dest, Gdk.Rectangle[] rois) { Gdk.Rectangle src_rect = src.GetBounds(); // Cache these for a massive performance boost int src_width = src.Width; ColorBgra *src_data_ptr = (ColorBgra *)src.DataPtr; foreach (Gdk.Rectangle rect in rois) { // loop through each line of target rectangle for (int y = rect.Y; y < rect.Y + rect.Height; ++y) { int fyStart = 0; int fyEnd = 3; if (y == src_rect.Y) { fyStart = 1; } if (y == src_rect.Y + src_rect.Height - 1) { fyEnd = 2; } // loop through each point in the line ColorBgra *dstPtr = dest.GetPointAddressUnchecked(rect.X, y); for (int x = rect.X; x < rect.X + rect.Width; ++x) { int fxStart = 0; int fxEnd = 3; if (x == src_rect.X) { fxStart = 1; } if (x == src_rect.X + src_rect.Width - 1) { fxEnd = 2; } // loop through each weight double rSum = 0.0; double gSum = 0.0; double bSum = 0.0; for (int fy = fyStart; fy < fyEnd; ++fy) { for (int fx = fxStart; fx < fxEnd; ++fx) { double weight = weights[fy][fx]; ColorBgra c = src.GetPointUnchecked(src_data_ptr, src_width, x - 1 + fx, y - 1 + fy); rSum += weight * (double)c.R; gSum += weight * (double)c.G; bSum += weight * (double)c.B; } } int iRsum = (int)rSum; int iGsum = (int)gSum; int iBsum = (int)bSum; if (iRsum > 255) { iRsum = 255; } if (iGsum > 255) { iGsum = 255; } if (iBsum > 255) { iBsum = 255; } if (iRsum < 0) { iRsum = 0; } if (iGsum < 0) { iGsum = 0; } if (iBsum < 0) { iBsum = 0; } *dstPtr = ColorBgra.FromBgra((byte)iBsum, (byte)iGsum, (byte)iRsum, 255); ++dstPtr; } } } }
/// <summary> /// Gets the equivalent GDI+ PixelFormat. /// </summary> /// <remarks> /// This property always returns PixelFormat.Format32bppArgb. /// </remarks> // public static PixelFormat PixelFormat // { // get // { // return PixelFormat.Format32bppArgb; // } // } /// <summary> /// Returns a new ColorBgra with the same color values but with a new alpha component value. /// </summary> public ColorBgra NewAlpha(byte newA) { return(ColorBgra.FromBgra(B, G, R, newA)); }
public override ColorBgra Apply(ColorBgra color) { return(ColorBgra.FromBgra(CurveB[color.B], CurveG[color.G], CurveR[color.R], color.A)); }
public override ColorBgra Apply(ColorBgra color) { return(ColorBgra.FromBgra(blueLevels[color.B], greenLevels[color.G], redLevels[color.R], color.A)); }
public override ColorBgra Apply(ColorBgra color) { byte i = color.GetIntensityByte(); return(ColorBgra.FromBgra(i, i, i, color.A)); }
public override ColorBgra Apply(ColorBgra color) { byte average = (byte)(((int)color.R + (int)color.G + (int)color.B) / 3); return(ColorBgra.FromBgra(average, average, average, color.A)); }
public override ColorBgra Apply(ColorBgra color) { return(ColorBgra.FromBgra((byte)(255 - color.B), (byte)(255 - color.G), (byte)(255 - color.R), (byte)(255 - color.A))); }
/// <summary> /// Brings the color channels from straight alpha in premultiplied alpha form. /// This is required for direct memory manipulation when writing on Cairo surfaces /// as it internally uses the premultiplied alpha form. /// See: /// https://en.wikipedia.org/wiki/Alpha_compositing /// http://cairographics.org/manual/cairo-Image-Surfaces.html#cairo-format-t /// </summary> /// <returns>A ColorBgra value in premultiplied alpha form</returns> public ColorBgra ToPremultipliedAlpha() { return(ColorBgra.FromBgra((byte)(B * A / 255), (byte)(G * A / 255), (byte)(R * A / 255), A)); }
public static unsafe ColorBgra GetPercentile(int percentile, int area, int *hb, int *hg, int *hr, int *ha) { int minCount = area * percentile / 100; int b = 0; int bCount = 0; while (b < 255 && hb[b] == 0) { ++b; } while (b < 255 && bCount < minCount) { bCount += hb[b]; ++b; } int g = 0; int gCount = 0; while (g < 255 && hg[g] == 0) { ++g; } while (g < 255 && gCount < minCount) { gCount += hg[g]; ++g; } int r = 0; int rCount = 0; while (r < 255 && hr[r] == 0) { ++r; } while (r < 255 && rCount < minCount) { rCount += hr[r]; ++r; } int a = 0; int aCount = 0; while (a < 255 && ha[a] == 0) { ++a; } while (a < 255 && aCount < minCount) { aCount += ha[a]; ++a; } return(ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a)); }