/// <summary> /// Get the WPF color from a CMKY color definition /// </summary> private (Color, GraphicColorPrecision) GetColor(ColorCMYK cmykColor) { Color color; GraphicColorPrecision colorPrecision; if (isProfileAvailable) { float[] colorValues = { (float)(cmykColor.C / 100.0), (float)(cmykColor.M / 100.0), (float)(cmykColor.Y / 100.0), (float)(cmykColor.K / 100.0) }; var uri = GetProfileUri(); colorPrecision = GraphicColorPrecision.Precise; color = Color.FromValues(colorValues, uri); } else { colorPrecision = GraphicColorPrecision.Estimated; color = ColorSpaceConverter.ConvertCmykToRgb(cmykColor.C / 100.0, cmykColor.M / 100.0, cmykColor.Y / 100.0, cmykColor.K / 100.0); } return(color, colorPrecision); }
/// <summary> /// Constructor. /// </summary> /// <param name="bitmap">Source image</param> /// <param name="converter">Converter to use</param> public unsafe ColorImage(BitmapSource bitmap, ColorSpaceConverter converter) { float o1, o2, o3; int rows = bitmap.PixelHeight; int columns = bitmap.PixelWidth; _handler = new FloatArrayHandler(rows, columns, 3); FormatConvertedBitmap bmp = new FormatConvertedBitmap(); bmp.BeginInit(); bmp.Source = bitmap; bmp.DestinationFormat = PixelFormats.Rgb24; bmp.EndInit(); byte[] pixels = new byte[rows * columns * 3]; bmp.CopyPixels(pixels, columns * 3, 0); fixed(byte *src = pixels) { fixed(float *dst = _handler.RawArray) { byte * srcPtr = src; float *dstPtr = dst; int length = rows * columns; while (length-- > 0) { float i1 = *srcPtr++; float i2 = *srcPtr++; float i3 = *srcPtr++; o1 = o2 = o3 = 0; converter(i1, i2, i3, ref o1, ref o2, ref o3); *dstPtr++ = o1; *dstPtr++ = o2; *dstPtr++ = o3; } } } pixels = null; }
public PixelData GetPixelData() { if (!IsColor) { byte[] pixelData = PixelData ?? new byte[Rows * Columns * BitsAllocated / 8]; return(new GrayscalePixelData(Rows, Columns, BitsAllocated, BitsStored, HighBit, PixelRepresentation != 0, pixelData)); } else { if (PixelData == null) { return(new ColorPixelData(Rows, Columns, new byte[Rows * Columns * 4])); } else { byte[] original = PixelData; byte[] argb = new byte[Rows * Columns * 4]; ColorSpaceConverter.ToArgb(InternalPhotometricInterpretation, PlanarConfiguration, original, argb); return(new ColorPixelData(Rows, Columns, argb)); } } }
/// <summary> /// Constructor. /// </summary> /// <param name="bitmap">Source image</param> /// <param name="converter">Converter to use</param> public unsafe ColorImage(System.Drawing.Bitmap bitmap, ColorSpaceConverter converter) { int r, c; float o1, o2, o3; byte * srcPtr, srcScan; float *dstPtr; int rows = bitmap.Height; int columns = bitmap.Width; _handler = new FloatArrayHandler(rows, columns, 3); System.Drawing.Imaging.BitmapData srcBuf = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format24bppRgb); srcPtr = (byte *)srcBuf.Scan0; int srcStride = srcBuf.Stride; fixed(float *dstBuf = _handler.RawArray) { dstPtr = dstBuf; for (r = 0; r < rows; r++, srcPtr += srcStride) { for (c = 0, srcScan = srcPtr; c < columns; c++) { float i3 = *srcScan++; float i2 = *srcScan++; float i1 = *srcScan++; o1 = o2 = o3 = 0; converter(i1, i2, i3, ref o1, ref o2, ref o3); *dstPtr++ = o1; *dstPtr++ = o2; *dstPtr++ = o3; } } } bitmap.UnlockBits(srcBuf); }
/// <summary> /// Convert <see cref="Color"/> to <see cref="Rgb"/>. /// </summary> /// <param name="converter">Converter.</param> /// <param name="color">Source <see cref="Color"/>.</param> /// <returns>Converted <see cref="Rgb"/>.</returns> public static Rgb ToRgb(this ColorSpaceConverter converter, Color color) { return(ToRgb(color)); }
public GradientService(RenderOptions options) { _options = options; _colourSpaceConverter = new ColorSpaceConverter(); }
/// <summary> /// Convert <see cref="Hsv"/> to <see cref="Color"/>. /// </summary> /// <param name="converter">Converter.</param> /// <param name="hsv">Source <see cref="Hsv"/>.</param> /// <returns>Converted <see cref="Color"/>.</returns> public static Color ToColor(this ColorSpaceConverter converter, Hsv hsv) { return(ToColor(converter.ToRgb(hsv))); }
/// <summary> /// Convert <see cref="Color"/> to <see cref="Hsv"/>. /// </summary> /// <param name="converter">Converter.</param> /// <param name="color">Source <see cref="Color"/>.</param> /// <returns>Converted <see cref="Hsv"/>.</returns> public static Hsv ToHsv(this ColorSpaceConverter converter, Color color) { return(converter.ToHsv(ToRgb(color))); }
public ClutService(IGradientService gradientService, RenderOptions options) { _gradientService = gradientService; _options = options; _converter = new ColorSpaceConverter(); }
/// <summary> /// Convert <see cref="Rgb"/> to <see cref="Color"/>. /// </summary> /// <param name="converter">Converter.</param> /// <param name="rgb">Source <see cref="Rgb"/>.</param> /// <returns>Converted <see cref="Color"/>.</returns> public static Color ToColor(this ColorSpaceConverter converter, Rgb rgb) { return(ToColor(rgb)); }
/// <summary> /// Constructor. /// </summary> /// <param name="filename">Path to source image</param> /// <param name="converter">Converter to use</param> public ColorImage(string filename, ColorSpaceConverter converter) : this(new BitmapImage(new Uri(filename)), converter) { }
public ColorFromDepthCalculation(VisualTopoModel model) { _maxDepth = model.Graph.AllNodes.Min(n => n.Model.VectorLocal.Z); _colorConverter = new ColorSpaceConverter(); }
static ColorHelper() { _colorConverter = new ColorSpaceConverter(); }
/// <summary> // Try to parse a color given in different flavours (hex, rgb, name) /// </summary> public static bool TryParseColor(string strVal, double alpha, out Color color) { // 1: color is specified in rgb values if (strVal.StartsWith("rgb(", StringComparison.OrdinalIgnoreCase)) { var str = strVal.Substring(4, strVal.Length - 5); string[] parts = str.Split(','); if (parts.Length != 3) { color = Colors.Black; return(false); } try { string redStr = parts[0].Trim(); string greenStr = parts[1].Trim(); string blueStr = parts[2].Trim(); byte red; byte green; byte blue; if (string.IsNullOrWhiteSpace(redStr) || string.IsNullOrWhiteSpace(greenStr) || string.IsNullOrWhiteSpace(blueStr)) { red = 0; green = 0; blue = 0; } else { red = (byte)ParseColorValue(redStr); green = (byte)ParseColorValue(greenStr); blue = (byte)ParseColorValue(blueStr); } color = Color.FromArgb((byte)(alpha * 255), red, green, blue); return(true); } catch { } color = Colors.Black; return(false); } // 2: color is specified in rgba values if (strVal.StartsWith("rgba(", StringComparison.OrdinalIgnoreCase)) { var str = strVal.Substring(5, strVal.Length - 6); string[] parts = str.Split(','); if (parts.Length != 4) { color = Colors.Black; return(false); } try { string redStr = parts[0].Trim(); string greenStr = parts[1].Trim(); string blueStr = parts[2].Trim(); string alphaStr = parts[3].Trim(); byte red; byte green; byte blue; double alphaD; if (string.IsNullOrWhiteSpace(alphaStr) || string.IsNullOrWhiteSpace(redStr) || string.IsNullOrWhiteSpace(greenStr) || string.IsNullOrWhiteSpace(blueStr)) { alphaD = 1; red = 0; green = 0; blue = 0; } else { red = (byte)ParseColorValue(redStr); green = (byte)ParseColorValue(greenStr); blue = (byte)ParseColorValue(blueStr); (_, alphaD) = DoubleParser.GetNumberPercent(alphaStr); } color = Color.FromArgb((byte)(alpha * alphaD * 255), red, green, blue); return(true); } catch { } color = Colors.Black; return(false); } // 3: color is specified in hsl values if (strVal.StartsWith("hsl(", StringComparison.OrdinalIgnoreCase)) { var str = strVal.Substring(4, strVal.Length - 5); string[] parts = str.Split(','); if (parts.Length != 3) { color = Colors.Black; return(false); } try { string hueStr = parts[0].Trim(); string saturationStr = parts[1].Trim(); string luminosityStr = parts[2].Trim(); if (string.IsNullOrWhiteSpace(hueStr) || string.IsNullOrWhiteSpace(saturationStr) || string.IsNullOrWhiteSpace(luminosityStr)) { color = Colors.Black; return(true); } else { var hue = DoubleParser.GetNumber(hueStr); var(_, saturation) = DoubleParser.GetNumberPercent(saturationStr); var(_, luminosity) = DoubleParser.GetNumberPercent(luminosityStr); color = ColorSpaceConverter.ConvertHlsToRgb(alpha, hue, saturation, luminosity); return(true); } } catch { } color = Colors.Black; return(false); } // 4: color is either given as name or hex values try { if (strVal == "grey") { strVal = "gray"; } var color2 = (Color)ColorConverter.ConvertFromString(strVal); color = Color.FromArgb((byte)(alpha * 255), color2.R, color2.G, color2.B); return(true); } catch { } color = Colors.Black; return(false); }
public RGBChannels HorizontalSubsampling(RGBChannels image) { return(ColorSpaceConverter.Instance().HorizontalSubsampling(image)); }
public RGBChannels ConvertYCrCbToRGB(YCBCRNode[,] image) { return(ColorSpaceConverter.Instance().ConvertYCbCrToRGB(image)); }
public YCBCRNode[,] ConvertRGBtoYCbCr(RGBChannels image) { return(ColorSpaceConverter.Instance().ConvertRGBToYCbCr(image)); }
public void PrepareRivenFromFullscreenImage(string imagePath, string outputPath) { var converter = new ColorSpaceConverter(); using (Image <Rgba32> outputImage = new Image <Rgba32>(null, 500, 765, Rgba32.White)) { using (Image <Rgba32> image = SixLabors.ImageSharp.Image.Load(imagePath)) { //Copy title/modis for (int x = 1800; x < 2300; x++) { for (int y = 525; y < 1155; y++) { if (image[x, y].R == 172 && image[x, y].G == 131 && image[x, y].B == 213) { outputImage[x - 1800, y - 525] = Rgba32.Black; } else { outputImage[x - 1800, y - 525] = Rgba32.White; } } } //Copy Drain for (int x = 2225; x < 2285; x++) { for (int y = 465; y < 510; y++) { if (image[x, y].R == 172 && image[x, y].G == 131 && image[x, y].B == 213) { outputImage[x - 2225, y - 510 + 630 + 45] = Rgba32.Black; } else { outputImage[x - 2225, y - 510 + 630 + 45] = Rgba32.White; } } } //Copy MR & rerolls for (int x = 1820; x < 2270; x++) { for (int y = 1165; y < 1210; y++) { if (image[x, y].R == 172 && image[x, y].G == 131 && image[x, y].B == 213) { outputImage[x - 1820, y - 1165 + 630 + 45] = Rgba32.Black; } else { outputImage[x - 1820, y - 1165 + 630 + 45] = Rgba32.White; } } } ////Copy rerolls //for (int x = 2212; x < 2270; x++) //{ // for (int y = 1166; y < 1211; y++) // { // if (image[x, y].R == 172 && image[x, y].G == 131 && image[x, y].B == 213) // outputImage[x - 2212, y - 1166 + 630 + 45 + 45] = Rgba32.Black; // else // outputImage[x - 2212, y - 1166 + 630 + 45 + 45] = Rgba32.White; // } //} } outputImage.Save(outputPath); } }
public ColorCalculator() { _converter = new ColorSpaceConverter(); }
/// <summary> /// GetColor /// </summary> public Color GetColor(List <double> values) { return(ColorSpaceConverter.ConvertCmykToRgb(values[0], values[1], values[2], values[3])); }
static Color GetPunchPrim(Color color) { var converter = new ColorSpaceConverter(); return(converter.TranslateHsv(color, static hsv => new Hsv(hsv.H, (hsv.S / 5f) * 4f, hsv.V))); }