public static FromUInt32 ( |
||
bgra | ||
return |
/// <summary> /// Blends the colors based on the given weight values. /// </summary> /// <param name="c">The array of color values.</param> /// <param name="w">The array of weight values.</param> /// <returns> /// Each color will be blended in proportionally to its weight value respective to /// the total summation of the weight values. /// </returns> /// <remarks> /// "WAIP" stands for "weights, floating-point"</remarks> public static ColorBgra BlendColorsWFP(ColorBgra[] c, double[] w) { if (c.Length != w.Length) { throw new ArgumentException("c.Length != w.Length"); } if (c.Length == 0) { return(ColorBgra.FromUInt32(0)); } double wsum = 0; double asum = 0; for (int i = 0; i < w.Length; ++i) { wsum += w[i]; asum += (double)c[i].A * w[i]; } double a = asum / wsum; double aMultWsum = a * wsum; double b; double g; double r; if (asum == 0) { b = 0; g = 0; r = 0; } else { b = 0; g = 0; r = 0; for (int i = 0; i < c.Length; ++i) { b += (double)c[i].A * c[i].B * w[i]; g += (double)c[i].A * c[i].G * w[i]; r += (double)c[i].A * c[i].R * w[i]; } b /= aMultWsum; g /= aMultWsum; r /= aMultWsum; } return(ColorBgra.FromBgra((byte)b, (byte)g, (byte)r, (byte)a)); }
/// <summary> /// Blends the colors based on the given weight values. /// </summary> /// <param name="c">The array of color values.</param> /// <param name="w">The array of weight values.</param> /// <returns> /// The weights should be fixed point numbers. /// The total summation of the weight values will be treated as "1.0". /// Each color will be blended in proportionally to its weight value respective to /// the total summation of the weight values. /// </returns> /// <remarks> /// "WAIP" stands for "weights, arbitrary integer precision"</remarks> public static ColorBgra BlendColorsWAIP(ColorBgra[] c, uint[] w) { if (c.Length != w.Length) { throw new ArgumentException("c.Length != w.Length"); } if (c.Length == 0) { return(ColorBgra.FromUInt32(0)); } long wsum = 0; long asum = 0; for (int i = 0; i < w.Length; ++i) { wsum += w[i]; asum += c[i].A * w[i]; } uint a = (uint)((asum + (wsum >> 1)) / wsum); long b; long g; long r; if (a == 0) { b = 0; g = 0; r = 0; } else { b = 0; g = 0; r = 0; for (int i = 0; i < c.Length; ++i) { b += (long)c[i].A * c[i].B * w[i]; g += (long)c[i].A * c[i].G * w[i]; r += (long)c[i].A * c[i].R * w[i]; } b /= asum; g /= asum; r /= asum; } return(ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24))); }
public ColorBgra Apply(ColorBgra color, int checkerX, int checkerY) { int b = color.B; int g = color.G; int r = color.R; int a = ApplyOpacity(color.A); int v = ((checkerX ^ checkerY) & 8) * 8 + 191; a = a + (a >> 7); int vmia = v * (256 - a); r = ((r * a) + vmia) >> 8; g = ((g * a) + vmia) >> 8; b = ((b * a) + vmia) >> 8; return(ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + 0xff000000)); }
public static ColorBgra ParseHexString(string hexString) { uint value = Convert.ToUInt32(hexString, 16); return(ColorBgra.FromUInt32(value)); }
public override ColorBgra Apply(ColorBgra color) { return(ColorBgra.FromUInt32(color.Bgra | 0xff000000)); }
public override ColorBgra Apply(ColorBgra color) { return(ColorBgra.FromUInt32((color.Bgra & 0x00ffffff) + addValue)); }
public static unsafe ColorBgra GetBilinearSample(this ImageSurface src, ColorBgra *srcDataPtr, int srcWidth, int srcHeight, float x, float y) { if (!Utility.IsNumber(x) || !Utility.IsNumber(y)) { return(ColorBgra.Transparent); } float u = x; float v = y; if (u >= 0 && v >= 0 && u < srcWidth && v < srcHeight) { unchecked { int iu = (int)Math.Floor(u); uint sxfrac = (uint)(256 * (u - (float)iu)); uint sxfracinv = 256 - sxfrac; int iv = (int)Math.Floor(v); uint syfrac = (uint)(256 * (v - (float)iv)); uint syfracinv = 256 - syfrac; uint wul = (uint)(sxfracinv * syfracinv); uint wur = (uint)(sxfrac * syfracinv); uint wll = (uint)(sxfracinv * syfrac); uint wlr = (uint)(sxfrac * syfrac); int sx = iu; int sy = iv; int sleft = sx; int sright; if (sleft == (srcWidth - 1)) { sright = sleft; } else { sright = sleft + 1; } int stop = sy; int sbottom; if (stop == (srcHeight - 1)) { sbottom = stop; } else { sbottom = stop + 1; } ColorBgra *cul = src.GetPointAddressUnchecked(srcDataPtr, srcWidth, sleft, stop); ColorBgra *cur = cul + (sright - sleft); ColorBgra *cll = src.GetPointAddressUnchecked(srcDataPtr, srcWidth, sleft, sbottom); ColorBgra *clr = cll + (sright - sleft); ColorBgra c = ColorBgra.BlendColors4W16IP(*cul, wul, *cur, wur, *cll, wll, *clr, wlr); return(c); } } else { return(ColorBgra.FromUInt32(0)); } }