#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public ImageInfo(FileInfo file, Bitmap bitmap) #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member : base(file) { if (file == null) { throw new ArgumentNullException("file"); } _exists = file.Exists; if (_exists) { _isReadOnly = file.IsReadOnly; _creationTime = file.CreationTime; _lastWriteTime = file.LastWriteTime; _attributes = file.Attributes; } if (bitmap == null) { FileType = ExtensionToFileType(Extension); return; } _width = bitmap.Width; _height = bitmap.Height; _horizontalResolution = bitmap.HorizontalResolution; _verticalResolution = bitmap.VerticalResolution; _pixelFormat = bitmap.PixelFormat; FileType = RawFormatToImageType(bitmap.RawFormat); _flags = bitmap.Flags; _hasAlpha = (bitmap.Flags & (int)(ImageFlags.HasAlpha)) != 0; _isIndexed = bitmap.PixelFormat.HasFlag(PixelFormat.Indexed); if ((bitmap.Flags & (int)(ImageFlags.ColorSpaceCmyk)) != 0) { _colorSpace = ColorSpaceType.Cmyk; } else if ((bitmap.Flags & (int)(ImageFlags.ColorSpaceYcbcr)) != 0) { _colorSpace = ColorSpaceType.Ycbcr; } else if ((bitmap.Flags & (int)(ImageFlags.ColorSpaceYcck)) != 0) { _colorSpace = ColorSpaceType.Ycck; } else if ((bitmap.Flags & (int)(ImageFlags.ColorSpaceRgb)) != 0) { _colorSpace = ColorSpaceType.Rgb; } else if ((bitmap.Flags & (int)(ImageFlags.ColorSpaceGray)) != 0) { _colorSpace = ColorSpaceType.Gray; } else { _colorSpace = ColorSpaceType.Unknown; } }
internal static bool IsSameSpace(ColorModel Model, ColorSpaceType Space) { if (Enum.GetName(typeof(ColorModel), Model).ToLower() == Enum.GetName(typeof(ColorSpaceType), Space).ToLower()) { return(true); } else { return(false); } }
/// <summary> /// Initializes a new instance of the <see cref="ColorCorrectionMaterial"/> class. /// </summary> /// <param name="lUTTexture">lUTTexture</param> public ColorCorrectionMaterial(string lUTTexture) : base(DefaultLayers.Opaque) { this.ColorSpace = ColorSpaceType.Default; this.lutTexturePath = lUTTexture; this.scale = (16f - 1f) / 16f; this.offset = 1.0f / (2.0f * 16f); this.shaderParameters = new ColorCorrectionEffectParameters(); this.shaderParameters.Scale = this.scale; this.shaderParameters.Offset = this.offset; this.Parameters = this.shaderParameters; this.InitializeTechniques(techniques); }
public GButtonColorAnimationPlayer(MonoBehaviour monoBehaviour, Image image, EaseType colorEaseType, ColorSpaceType colorSpaceType, bool useColorAnimationOnHover, Color colorOnHover, float colorDurationOnHover, bool useColorAnimationOnClick, Color colorOnClick, float colorDurationOnClick) { this.monoBehaviour = monoBehaviour; this.image = image; this.colorEaseType = colorEaseType; this.colorSpaceType = colorSpaceType; this.useColorAnimationOnHover = useColorAnimationOnHover; this.colorOnHover = colorOnHover; this.colorDurationOnHover = colorDurationOnHover; this.useColorAnimationOnClick = useColorAnimationOnClick; this.colorOnClick = colorOnClick; this.colorDurationOnClick = colorDurationOnClick; _defaultColor = image.color; }
/// <summary> /// Gets the type of a color from a given <see cref="ColorSpaceType"/> /// </summary> /// <param name="tp">The ColorSpaceType</param> /// <returns>The type of the color</returns> private static Type GetColorType(ColorSpaceType tp) { switch (tp) { case ColorSpaceType.CIEXYZ: return(typeof(ColorXYZ)); case ColorSpaceType.CIELAB: return(typeof(ColorLab)); case ColorSpaceType.CIELUV: return(typeof(ColorLuv)); case ColorSpaceType.YCbCr: return(typeof(ColorYCbCr)); case ColorSpaceType.CIEYxy: return(typeof(ColorYxy)); case ColorSpaceType.RGB: return(typeof(ColorRGB)); case ColorSpaceType.Gray: return(typeof(ColorGray)); case ColorSpaceType.HSV: return(typeof(ColorHSV)); case ColorSpaceType.HLS: return(typeof(ColorHSL)); case ColorSpaceType.CMYK: return(typeof(ColorCMYK)); case ColorSpaceType.CMY: return(typeof(ColorCMY)); case ColorSpaceType.Color2: case ColorSpaceType.Color3: case ColorSpaceType.Color4: case ColorSpaceType.Color5: case ColorSpaceType.Color6: case ColorSpaceType.Color7: case ColorSpaceType.Color8: case ColorSpaceType.Color9: case ColorSpaceType.Color10: case ColorSpaceType.Color11: case ColorSpaceType.Color12: case ColorSpaceType.Color13: case ColorSpaceType.Color14: case ColorSpaceType.Color15: return(typeof(ColorX)); default: throw new Exception($"Unsupported color type: {tp}"); } }
public YUV_Color(int r_c_y, int g_d_u, int b_e_v, ColorSpaceType type) { switch (type) { case ColorSpaceType.RGB: C = Convert.ToInt32((66 * r_c_y + 129 * g_d_u + 25 * b_e_v + 128) >> 8); D = Convert.ToInt32((-38 * r_c_y - 74 * g_d_u + 112 * b_e_v + 128) >> 8); E = Convert.ToInt32((112 * r_c_y - 94 * g_d_u - 18 * b_e_v + 128) >> 8); Y = Convert.ToByte(C + 16); U = Convert.ToByte(D + 128); V = Convert.ToByte(E + 128); R = Convert.ToByte(r_c_y); G = Convert.ToByte(g_d_u); B = Convert.ToByte(b_e_v); break; case ColorSpaceType.CDE: C = r_c_y; D = g_d_u; E = b_e_v; Y = Convert.ToByte(C + 16); U = Convert.ToByte(D + 128); V = Convert.ToByte(E + 128); R = Clip((298 * C + 409 * E + 128) >> 8); G = Clip((298 * C - 100 * D - 208 * E + 128) >> 8); B = Clip((298 * C + 516 * D + 128) >> 8); break; case ColorSpaceType.YUV: Y = Convert.ToByte(r_c_y); U = Convert.ToByte(g_d_u); V = Convert.ToByte(b_e_v); C = Convert.ToInt32(Y - 16); D = Convert.ToInt32(U - 128); E = Convert.ToInt32(V - 128); R = Clip((298 * C + 409 * E + 128) >> 8); G = Clip((298 * C - 100 * D - 208 * E + 128) >> 8); B = Clip((298 * C + 516 * D + 128) >> 8); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } }
public YuvColor(int r_c_y, int g_d_u, int b_e_v, ColorSpaceType type) { switch (type) { case ColorSpaceType.RGB: c = Convert.ToInt32((66 * r_c_y + 129 * g_d_u + 25 * b_e_v + 128) >> 8); d = Convert.ToInt32((-38 * r_c_y - 74 * g_d_u + 112 * b_e_v + 128) >> 8); e = Convert.ToInt32((112 * r_c_y - 94 * g_d_u - 18 * b_e_v + 128) >> 8); Y = Convert.ToByte(c + 16); U = Convert.ToByte(d + 128); V = Convert.ToByte(e + 128); Red = Convert.ToByte(r_c_y); Green = Convert.ToByte(g_d_u); Blue = Convert.ToByte(b_e_v); break; case ColorSpaceType.CDE: c = r_c_y; d = g_d_u; e = b_e_v; Y = Convert.ToByte(c + 16); U = Convert.ToByte(d + 128); V = Convert.ToByte(e + 128); Red = Clip((298 * c + 409 * e + 128) >> 8); Green = Clip((298 * c - 100 * d - 208 * e + 128) >> 8); Blue = Clip((298 * c + 516 * d + 128) >> 8); break; case ColorSpaceType.YUV: Y = Convert.ToByte(r_c_y); U = Convert.ToByte(g_d_u); V = Convert.ToByte(b_e_v); c = Convert.ToInt32(Y - 16); d = Convert.ToInt32(U - 128); e = Convert.ToInt32(V - 128); Red = Clip((298 * c + 409 * e + 128) >> 8); Green = Clip((298 * c - 100 * d - 208 * e + 128) >> 8); Blue = Clip((298 * c + 516 * d + 128) >> 8); break; } }
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member public ImageInfo(ImageInfo item) #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member : base(item) { if (item == null) { throw new ArgumentNullException("item"); } _exists = item._exists; _isReadOnly = item._isReadOnly; _creationTime = item._creationTime; _lastWriteTime = item._lastWriteTime; _attributes = item._attributes; _width = item._width; _height = item._height; _horizontalResolution = item._horizontalResolution; _verticalResolution = item._verticalResolution; _pixelFormat = item._pixelFormat; _flags = item._flags; _hasAlpha = item._hasAlpha; _isIndexed = item._isIndexed; _colorSpace = item._colorSpace; }
/// <summary> /// Checks for overlay color space support. /// </summary> /// <param name="format">A <see cref="Format"/> value for the color format.</param> /// <param name="colorSpace">A <see cref="ColorSpaceType"/> value that specifies color space type to check overlay support for.</param> /// <param name="concernedDevice">Instance of Direct3D device interface.</param> /// <returns>Overlay color space support flags.</returns> public OverlayColorSpaceSupportFlags CheckOverlayColorSpaceSupport(Format format, ColorSpaceType colorSpace, IUnknown concernedDevice) { if (PlatformDetection.IsUAP) { throw new NotSupportedException("IDXGIOutput4.CheckOverlayColorSpaceSupport is not supported on UAP platform"); } return(CheckOverlayColorSpaceSupport_(format, colorSpace, concernedDevice)); }
/// <summary> /// Checks for overlay color space support. /// </summary> /// <param name="format">A <see cref="Format"/> value for the color format.</param> /// <param name="colorSpace">A <see cref="ColorSpaceType"/> value that specifies color space type to check overlay support for.</param> /// <param name="concernedDevice">Instance of Direct3D device interface.</param> /// <returns>Overlay color space support flags.</returns> public OverlayColorSpaceSupportFlags CheckOverlayColorSpaceSupport(Format format, ColorSpaceType colorSpace, IUnknown concernedDevice) { return(CheckOverlayColorSpaceSupport_(format, colorSpace, concernedDevice)); }
/// <summary> /// Constructs a {@code LinearGradientPaint}. /// </summary> /// <param name="start"> the gradient axis start {@code Point2D} in user space </param> /// <param name="end"> the gradient axis end {@code Point2D} in user space </param> /// <param name="fractions"> numbers ranging from 0.0 to 1.0 specifying the /// distribution of colors along the gradient </param> /// <param name="colors"> array of colors corresponding to each fractional value </param> /// <param name="cycleMethod"> either {@code NO_CYCLE}, {@code REFLECT}, /// or {@code REPEAT} </param> /// <param name="colorSpace"> which color space to use for interpolation, /// either {@code SRGB} or {@code LINEAR_RGB} </param> /// <param name="gradientTransform"> transform to apply to the gradient /// </param> /// <exception cref="NullPointerException"> /// if one of the points is null, /// or {@code fractions} array is null, /// or {@code colors} array is null, /// or {@code cycleMethod} is null, /// or {@code colorSpace} is null, /// or {@code gradientTransform} is null </exception> /// <exception cref="IllegalArgumentException"> /// if start and end points are the same points, /// or {@code fractions.length != colors.length}, /// or {@code colors} is less than 2 in size, /// or a {@code fractions} value is less than 0.0 or greater than 1.0, /// or the {@code fractions} are not provided in strictly increasing order </exception> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ConstructorProperties({ "startPoint", "endPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" }) public LinearGradientPaint(java.awt.geom.Point2D start, java.awt.geom.Point2D end, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace, java.awt.geom.AffineTransform gradientTransform) public LinearGradientPaint(Point2D start, Point2D end, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace, AffineTransform gradientTransform) : base(fractions, colors, cycleMethod, colorSpace, gradientTransform) { // check input parameters if (start == null || end == null) { throw new NullPointerException("Start and end points must be" + "non-null"); } if (start.Equals(end)) { throw new IllegalArgumentException("Start point cannot equal" + "endpoint"); } // copy the points... this.Start = new Point2D.Double(start.X, start.Y); this.End = new Point2D.Double(end.X, end.Y); }
/// <summary> /// Constructor for LinearGradientPaintContext. /// </summary> /// <param name="paint"> the {@code LinearGradientPaint} from which this context /// is created </param> /// <param name="cm"> {@code ColorModel} that receives /// the <code>Paint</code> data. This is used only as a hint. </param> /// <param name="deviceBounds"> the device space bounding box of the /// graphics primitive being rendered </param> /// <param name="userBounds"> the user space bounding box of the /// graphics primitive being rendered </param> /// <param name="t"> the {@code AffineTransform} from user /// space into device space (gradientTransform should be /// concatenated with this) </param> /// <param name="hints"> the hints that the context object uses to choose /// between rendering alternatives </param> /// <param name="start"> gradient start point, in user space </param> /// <param name="end"> gradient end point, in user space </param> /// <param name="fractions"> the fractions specifying the gradient distribution </param> /// <param name="colors"> the gradient colors </param> /// <param name="cycleMethod"> either NO_CYCLE, REFLECT, or REPEAT </param> /// <param name="colorSpace"> which colorspace to use for interpolation, /// either SRGB or LINEAR_RGB </param> internal LinearGradientPaintContext(LinearGradientPaint paint, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, Point2D start, Point2D end, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace) : base(paint, cm, deviceBounds, userBounds, t, hints, fractions, colors, cycleMethod, colorSpace) { // A given point in the raster should take on the same color as its // projection onto the gradient vector. // Thus, we want the projection of the current position vector // onto the gradient vector, then normalized with respect to the // length of the gradient vector, giving a value which can be mapped // into the range 0-1. // projection = // currentVector dot gradientVector / length(gradientVector) // normalized = projection / length(gradientVector) float startx = (float)start.X; float starty = (float)start.Y; float endx = (float)end.X; float endy = (float)end.Y; float dx = endx - startx; // change in x from start to end float dy = endy - starty; // change in y from start to end float dSq = dx * dx + dy * dy; // total distance squared // avoid repeated calculations by doing these divides once float constX = dx / dSq; float constY = dy / dSq; // incremental change along gradient for +x DgdX = A00 * constX + A10 * constY; // incremental change along gradient for +y DgdY = A01 * constX + A11 * constY; // constant, incorporates the translation components from the matrix Gc = (A02 - startx) * constX + (A12 - starty) * constY; }
public static IEnumerator AnimateColor(this Image obj, Color to, float interval, EaseType ease, ColorSpaceType colorSpace) { if (!obj) { yield break; } Color col = obj.color; float timer = 0; while (timer <= interval) { if (interval == 0) { break; } obj.color = ColorEase.ColorLerpWithEase(col, to, timer / interval, ease, colorSpace); timer += Time.unscaledDeltaTime; yield return(null); } obj.color = to; }
private Color GetColor(bool useICC, ColorSpaceType type) { //TODO: Whitepoint can be different from D50 var wp = new WhitepointD50(); switch (type) { case ColorSpaceType.CIEXYZ: if (useICC) { return(new ColorXYZ(this)); } else { return(new ColorXYZ(wp)); } case ColorSpaceType.CIELAB: if (useICC) { return(new ColorLab(this)); } else { return(new ColorLab(wp)); } case ColorSpaceType.CIELUV: if (useICC) { return(new ColorLuv(this)); } else { return(new ColorLuv(wp)); } case ColorSpaceType.YCbCr: return(new ColorYCbCr(this)); case ColorSpaceType.CIEYxy: if (useICC) { return(new ColorYxy(this)); } else { return(new ColorYxy(wp)); } case ColorSpaceType.RGB: return(new ColorRGB(this)); case ColorSpaceType.Gray: return(new ColorGray(this)); case ColorSpaceType.HSV: return(new ColorHSV(this)); case ColorSpaceType.HLS: return(new ColorHSL(this)); case ColorSpaceType.CMYK: return(new ColorCMYK(this)); case ColorSpaceType.CMY: return(new ColorCMY(this)); case ColorSpaceType.Color2: return(new ColorX(this, 2)); case ColorSpaceType.Color3: return(new ColorX(this, 3)); case ColorSpaceType.Color4: return(new ColorX(this, 4)); case ColorSpaceType.Color5: return(new ColorX(this, 5)); case ColorSpaceType.Color6: return(new ColorX(this, 6)); case ColorSpaceType.Color7: return(new ColorX(this, 7)); case ColorSpaceType.Color8: return(new ColorX(this, 8)); case ColorSpaceType.Color9: return(new ColorX(this, 9)); case ColorSpaceType.Color10: return(new ColorX(this, 10)); case ColorSpaceType.Color11: return(new ColorX(this, 11)); case ColorSpaceType.Color12: return(new ColorX(this, 12)); case ColorSpaceType.Color13: return(new ColorX(this, 13)); case ColorSpaceType.Color14: return(new ColorX(this, 14)); case ColorSpaceType.Color15: return(new ColorX(this, 15)); default: throw new ArgumentException("Invalid color type. Could not create instance."); } }
//if direct from file. Alert: don`t recommended to use public static void ColorSpaceToFileDirectFromImage(Bitmap img, ColorSpaceType colorSpace) { string imgExtension = GetImageInfo.Imginfo(Imageinfo.Extension); string imgName = GetImageInfo.Imginfo(Imageinfo.FileName); string defPath = GetImageInfo.MyPath("ColorSpace"); Bitmap image = new Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb); //back result [0 .. 255] int[,] colorPlaneOne = new int[img.Height, img.Width]; int[,] colorPlaneTwo = new int[img.Height, img.Width]; int[,] colorPlaneThree = new int[img.Height, img.Width]; List <ArraysListInt> rgbResult = new List <ArraysListInt>(); string outName = String.Empty; if (Checks.RGBinput(img)) { switch (colorSpace.ToString()) { case "rgb2hsv": var hsvResult = RGBandHSV.RGB2HSV(img); colorPlaneOne = (hsvResult[0].Color).ArrayDivByConst(360).ImageDoubleToUint8(); colorPlaneTwo = (hsvResult[1].Color).ImageDoubleToUint8(); colorPlaneThree = (hsvResult[2].Color).ImageDoubleToUint8(); outName = defPath + imgName + "_rgb2hsv" + imgExtension; break; case "hsv2rgb": rgbResult = RGBandHSV.HSV2RGB(img); colorPlaneOne = rgbResult[0].Color; colorPlaneTwo = rgbResult[1].Color; colorPlaneThree = rgbResult[2].Color; outName = defPath + imgName + "_hsv2rgb" + imgExtension; break; case "rgb2ntsc": var ntscResult = RGBandNTSC.RGB2NTSC(img); colorPlaneOne = (ntscResult[0].Color).ArrayToUint8(); colorPlaneTwo = (ntscResult[1].Color).ArrayToUint8(); colorPlaneThree = (ntscResult[2].Color).ArrayToUint8(); //if we want to save rgb2ntsc result in file //approximate result in file, coz we lost negative values in I and Q outName = defPath + imgName + "_rgb2ntsc" + imgExtension; break; case "ntsc2rgb": rgbResult = RGBandNTSC.NTSC2RGB(img); colorPlaneOne = rgbResult[0].Color; colorPlaneTwo = rgbResult[1].Color; colorPlaneThree = rgbResult[2].Color; //when ntsc2rgb from file //approximate result in file, coz we lost negative values in I and Q when saving ntsc result in file [0..255] outName = defPath + imgName + "_ntsc2rgb" + imgExtension; break; case "rgb2cmy": var cmyResult = RGBandCMY.RGB2CMY(img); colorPlaneOne = (cmyResult[0].Color).ImageDoubleToUint8(); colorPlaneTwo = (cmyResult[1].Color).ImageDoubleToUint8(); colorPlaneThree = (cmyResult[2].Color).ImageDoubleToUint8(); outName = defPath + imgName + "_rgb2cmy" + imgExtension; break; case "cmy2rgb": rgbResult = RGBandCMY.CMY2RGB(img); colorPlaneOne = rgbResult[0].Color; colorPlaneTwo = rgbResult[1].Color; colorPlaneThree = rgbResult[2].Color; outName = defPath + imgName + "_cmy2rgb" + imgExtension; break; case "rgb2YCbCr": var YCbCrResult = RGBandYCbCr.RGB2YCbCr(img); colorPlaneOne = (YCbCrResult[0].Color).ArrayToUint8(); colorPlaneTwo = (YCbCrResult[1].Color).ArrayToUint8(); colorPlaneThree = (YCbCrResult[2].Color).ArrayToUint8(); outName = defPath + imgName + "_rgb2YCbCr" + imgExtension; break; case "YCbCr2rgb": rgbResult = RGBandYCbCr.YCbCr2RGB(img); colorPlaneOne = rgbResult[0].Color; colorPlaneTwo = rgbResult[1].Color; colorPlaneThree = rgbResult[2].Color; outName = defPath + imgName + "_YCbCr2rgb" + imgExtension; break; case "rgb2xyz": var xyzrgbResult = RGBandXYZ.RGB2XYZ(img); colorPlaneOne = (xyzrgbResult[0].Color).ArrayToUint8(); colorPlaneTwo = (xyzrgbResult[1].Color).ArrayToUint8(); colorPlaneThree = (xyzrgbResult[2].Color).ArrayToUint8(); //approximate result in file, coz we lost values after comma in saving ntsc result in file [0..255] and heavy round them outName = defPath + imgName + "_rgb2xyz" + imgExtension; break; case "xyz2rgb": rgbResult = RGBandXYZ.XYZ2RGB(img); colorPlaneOne = rgbResult[0].Color; colorPlaneTwo = rgbResult[1].Color; colorPlaneThree = rgbResult[2].Color; //bad when from file, coz using heavy rounded X Y Z values; when writing them to file outName = defPath + imgName + "_xyz2rgb" + imgExtension; break; case "xyz2lab": var xyzlabResult = XYZandLab.XYZ2Lab(img); colorPlaneOne = (xyzlabResult[0].Color).ArrayToUint8(); colorPlaneTwo = (xyzlabResult[1].Color).ArrayToUint8(); colorPlaneThree = (xyzlabResult[2].Color).ArrayToUint8(); //bad when from file, coz xyz values rounded; and lost negative value in a & b when saving in [0..255] range into file outName = defPath + imgName + "_xyz2lab" + imgExtension; break; case "lab2xyz": var labxyzResult = XYZandLab.Lab2XYZ(img); colorPlaneOne = (labxyzResult[0].Color).ArrayToUint8(); colorPlaneTwo = (labxyzResult[1].Color).ArrayToUint8(); colorPlaneThree = (labxyzResult[2].Color).ArrayToUint8(); //bad when from file, coz lost a and b negative value when save to file. And lost X Y Z values when round before save in [0..255] range into file outName = defPath + imgName + "_lab2xyz" + imgExtension; break; case "rgb2lab": var rgblabResult = RGBandLab.RGB2Lab(img); colorPlaneOne = (rgblabResult[0].Color).ArrayToUint8(); colorPlaneTwo = (rgblabResult[1].Color).ArrayToUint8(); colorPlaneThree = (rgblabResult[2].Color).ArrayToUint8(); //bad, coz lost negative value in a & b when saving in [0..255] range into file outName = defPath + imgName + "_rgb2lab" + imgExtension; break; case "rgb2lab1976": var rgblab1976Result = RGBandLab.RGB2Lab1976(img); colorPlaneOne = (rgblab1976Result[0].Color).ArrayToUint8(); colorPlaneTwo = (rgblab1976Result[1].Color).ArrayToUint8(); colorPlaneThree = (rgblab1976Result[2].Color).ArrayToUint8(); //bad, coz lost negative value in a & b when saving in [0..255] range into file outName = defPath + imgName + "_rgb2lab1976" + imgExtension; break; case "lab2rgb": rgbResult = RGBandLab.Lab2RGB(img); colorPlaneOne = rgbResult[0].Color; colorPlaneTwo = rgbResult[1].Color; colorPlaneThree = rgbResult[2].Color; //very bad, coz lost a lot in converting and round everywhere... outName = defPath + imgName + "_lab2rgb" + imgExtension; break; default: colorPlaneOne = Helpers.GetPixels(img)[0].Color; colorPlaneTwo = Helpers.GetPixels(img)[1].Color; colorPlaneThree = Helpers.GetPixels(img)[2].Color; outName = defPath + imgName + "_defaultNonColorSpace" + imgExtension; break; } image = Helpers.SetPixels(image, colorPlaneOne, colorPlaneTwo, colorPlaneThree); Helpers.SaveOptions(image, outName, imgExtension); } }
/// <summary> /// Constructor for MultipleGradientPaintContext superclass. /// </summary> protected internal MultipleGradientPaintContext(MultipleGradientPaint mgp, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace) { if (deviceBounds == null) { throw new NullPointerException("Device bounds cannot be null"); } if (userBounds == null) { throw new NullPointerException("User bounds cannot be null"); } if (t == null) { throw new NullPointerException("Transform cannot be null"); } if (hints == null) { throw new NullPointerException("RenderingHints cannot be null"); } // The inverse transform is needed to go from device to user space. // Get all the components of the inverse transform matrix. AffineTransform tInv; try { // the following assumes that the caller has copied the incoming // transform and is not concerned about it being modified t.Invert(); tInv = t; } catch (NoninvertibleTransformException) { // just use identity transform in this case; better to show // (incorrect) results than to throw an exception and/or no-op tInv = new AffineTransform(); } double[] m = new double[6]; tInv.GetMatrix(m); A00 = (float)m[0]; A10 = (float)m[1]; A01 = (float)m[2]; A11 = (float)m[3]; A02 = (float)m[4]; A12 = (float)m[5]; // copy some flags this.CycleMethod = cycleMethod; this.ColorSpace = colorSpace; // we can avoid copying this array since we do not modify its values this.Fractions = fractions; // note that only one of these values can ever be non-null (we either // store the fast gradient array or the slow one, but never both // at the same time) int[] gradient = (mgp.Gradient != null) ? mgp.Gradient.get() : null; int[][] gradients = (mgp.Gradients != null) ? mgp.Gradients.get() : null; if (gradient == null && gradients == null) { // we need to (re)create the appropriate values CalculateLookupData(colors); // now cache the calculated values in the // MultipleGradientPaint instance for future use mgp.Model = this.Model; mgp.NormalizedIntervals = this.NormalizedIntervals; mgp.IsSimpleLookup = this.IsSimpleLookup; if (IsSimpleLookup) { // only cache the fast array mgp.FastGradientArraySize = this.FastGradientArraySize; mgp.Gradient = new SoftReference <int[]>(this.Gradient); } else { // only cache the slow array mgp.Gradients = new SoftReference <int[][]>(this.Gradients); } } else { // use the values cached in the MultipleGradientPaint instance this.Model = mgp.Model; this.NormalizedIntervals = mgp.NormalizedIntervals; this.IsSimpleLookup = mgp.IsSimpleLookup; this.Gradient = gradient; this.FastGradientArraySize = mgp.FastGradientArraySize; this.Gradients = gradients; } }
/// <summary> /// Constructor for RadialGradientPaintContext. /// </summary> /// <param name="paint"> the {@code RadialGradientPaint} from which this context /// is created </param> /// <param name="cm"> the {@code ColorModel} that receives /// the {@code Paint} data (this is used only as a hint) </param> /// <param name="deviceBounds"> the device space bounding box of the /// graphics primitive being rendered </param> /// <param name="userBounds"> the user space bounding box of the /// graphics primitive being rendered </param> /// <param name="t"> the {@code AffineTransform} from user /// space into device space (gradientTransform should be /// concatenated with this) </param> /// <param name="hints"> the hints that the context object uses to choose /// between rendering alternatives </param> /// <param name="cx"> the center X coordinate in user space of the circle defining /// the gradient. The last color of the gradient is mapped to /// the perimeter of this circle. </param> /// <param name="cy"> the center Y coordinate in user space of the circle defining /// the gradient. The last color of the gradient is mapped to /// the perimeter of this circle. </param> /// <param name="r"> the radius of the circle defining the extents of the /// color gradient </param> /// <param name="fx"> the X coordinate in user space to which the first color /// is mapped </param> /// <param name="fy"> the Y coordinate in user space to which the first color /// is mapped </param> /// <param name="fractions"> the fractions specifying the gradient distribution </param> /// <param name="colors"> the gradient colors </param> /// <param name="cycleMethod"> either NO_CYCLE, REFLECT, or REPEAT </param> /// <param name="colorSpace"> which colorspace to use for interpolation, /// either SRGB or LINEAR_RGB </param> internal RadialGradientPaintContext(RadialGradientPaint paint, ColorModel cm, Rectangle deviceBounds, Rectangle2D userBounds, AffineTransform t, RenderingHints hints, float cx, float cy, float r, float fx, float fy, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace) : base(paint, cm, deviceBounds, userBounds, t, hints, fractions, colors, cycleMethod, colorSpace) { // copy some parameters CenterX = cx; CenterY = cy; FocusX = fx; FocusY = fy; Radius = r; this.IsSimpleFocus = (FocusX == CenterX) && (FocusY == CenterY); this.IsNonCyclic = (cycleMethod == CycleMethod.NO_CYCLE); // for use in the quadractic equation RadiusSq = Radius * Radius; float dX = FocusX - CenterX; float dY = FocusY - CenterY; double distSq = (dX * dX) + (dY * dY); // test if distance from focus to center is greater than the radius if (distSq > RadiusSq * SCALEBACK) { // clamp focus to radius float scalefactor = (float)System.Math.Sqrt(RadiusSq * SCALEBACK / distSq); dX = dX * scalefactor; dY = dY * scalefactor; FocusX = CenterX + dX; FocusY = CenterY + dY; } // calculate the solution to be used in the case where X == focusX // in cyclicCircularGradientFillRaster() Trivial = (float)System.Math.Sqrt(RadiusSq - (dX * dX)); // constant parts of X, Y user space coordinates ConstA = A02 - CenterX; ConstB = A12 - CenterY; // constant second order delta for simple loop GDeltaDelta = 2 * (A00 * A00 + A10 * A10) / RadiusSq; }
public static Color ColorLerpWithEase(Color from, Color to, float t, EaseType ease, ColorSpaceType colorSpace) { switch (colorSpace) { case ColorSpaceType.RGB: return(RGBColorLerp(from, to, t, ease)); case ColorSpaceType.HSV: return(HSVColorLerp(from, to, t, ease)); default: throw new ArgumentOutOfRangeException(nameof(colorSpace), colorSpace, null); } }
/// <summary> /// Package-private constructor. /// </summary> /// <param name="fractions"> numbers ranging from 0.0 to 1.0 specifying the /// distribution of colors along the gradient </param> /// <param name="colors"> array of colors corresponding to each fractional value </param> /// <param name="cycleMethod"> either {@code NO_CYCLE}, {@code REFLECT}, /// or {@code REPEAT} </param> /// <param name="colorSpace"> which color space to use for interpolation, /// either {@code SRGB} or {@code LINEAR_RGB} </param> /// <param name="gradientTransform"> transform to apply to the gradient /// </param> /// <exception cref="NullPointerException"> /// if {@code fractions} array is null, /// or {@code colors} array is null, /// or {@code gradientTransform} is null, /// or {@code cycleMethod} is null, /// or {@code colorSpace} is null </exception> /// <exception cref="IllegalArgumentException"> /// if {@code fractions.length != colors.length}, /// or {@code colors} is less than 2 in size, /// or a {@code fractions} value is less than 0.0 or greater than 1.0, /// or the {@code fractions} are not provided in strictly increasing order </exception> internal MultipleGradientPaint(float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace, AffineTransform gradientTransform) { if (fractions == null) { throw new NullPointerException("Fractions array cannot be null"); } if (colors == null) { throw new NullPointerException("Colors array cannot be null"); } if (cycleMethod == null) { throw new NullPointerException("Cycle method cannot be null"); } if (colorSpace == null) { throw new NullPointerException("Color space cannot be null"); } if (gradientTransform == null) { throw new NullPointerException("Gradient transform cannot be " + "null"); } if (fractions.Length != colors.Length) { throw new IllegalArgumentException("Colors and fractions must " + "have equal size"); } if (colors.Length < 2) { throw new IllegalArgumentException("User must specify at least " + "2 colors"); } // check that values are in the proper range and progress // in increasing order from 0 to 1 float previousFraction = -1.0f; foreach (float currentFraction in fractions) { if (currentFraction < 0f || currentFraction > 1f) { throw new IllegalArgumentException("Fraction values must " + "be in the range 0 to 1: " + currentFraction); } if (currentFraction <= previousFraction) { throw new IllegalArgumentException("Keyframe fractions " + "must be increasing: " + currentFraction); } previousFraction = currentFraction; } // We have to deal with the cases where the first gradient stop is not // equal to 0 and/or the last gradient stop is not equal to 1. // In both cases, create a new point and replicate the previous // extreme point's color. bool fixFirst = false; bool fixLast = false; int len = fractions.Length; int off = 0; if (fractions[0] != 0f) { // first stop is not equal to zero, fix this condition fixFirst = true; len++; off++; } if (fractions[fractions.Length - 1] != 1f) { // last stop is not equal to one, fix this condition fixLast = true; len++; } this.Fractions_Renamed = new float[len]; System.Array.Copy(fractions, 0, this.Fractions_Renamed, off, fractions.Length); this.Colors_Renamed = new Color[len]; System.Array.Copy(colors, 0, this.Colors_Renamed, off, colors.Length); if (fixFirst) { this.Fractions_Renamed[0] = 0f; this.Colors_Renamed[0] = colors[0]; } if (fixLast) { this.Fractions_Renamed[len - 1] = 1f; this.Colors_Renamed[len - 1] = colors[colors.Length - 1]; } // copy some flags this.ColorSpace_Renamed = colorSpace; this.CycleMethod_Renamed = cycleMethod; // copy the gradient transform this.GradientTransform = new AffineTransform(gradientTransform); // determine transparency bool opaque = true; for (int i = 0; i < colors.Length; i++) { opaque = opaque && (colors[i].Alpha == 0xff); } this.Transparency_Renamed = opaque ? Transparency_Fields.OPAQUE : Transparency_Fields.TRANSLUCENT; }
private Color ToColor(double[] inValues, ColorSpaceType outType) { switch (outType) { case ColorSpaceType.RGB: return new ColorRGB(Profile, inValues[0], inValues[1], inValues[2], false); case ColorSpaceType.HSV: return new ColorHSV(Profile, inValues[0], inValues[1], inValues[2]); case ColorSpaceType.HLS: return new ColorHSL(Profile, inValues[0], inValues[2], inValues[1]); case ColorSpaceType.CIEYxy: return new ColorYxy(Profile.ReferenceWhite, inValues[0], inValues[1], inValues[2]); case ColorSpaceType.CIEXYZ: return new ColorXYZ(Profile.ReferenceWhite, inValues[0], inValues[1], inValues[2]); case ColorSpaceType.CIELUV: return new ColorLuv(Profile.ReferenceWhite, inValues[0] * 100, inValues[1], inValues[2]); case ColorSpaceType.CIELAB: return new ColorLab(Profile.ReferenceWhite, inValues[0] * 100, inValues[1], inValues[2]); case ColorSpaceType.CMY: return new ColorCMY(Profile, inValues[0] * 100, inValues[1] * 100, inValues[2] * 100); case ColorSpaceType.CMYK: return new ColorCMYK(Profile, inValues[0] * 100, inValues[1] * 100, inValues[2] * 100, inValues[3] * 100); case ColorSpaceType.Gray: return new ColorGray(Profile, inValues[0]); case ColorSpaceType.YCbCr: return new ColorYCbCr(Profile, inValues[0], inValues[1], inValues[2]); case ColorSpaceType.Color2: return new ColorX(Profile, inValues); case ColorSpaceType.Color3: return new ColorX(Profile, inValues); case ColorSpaceType.Color4: return new ColorX(Profile, inValues); case ColorSpaceType.Color5: return new ColorX(Profile, inValues); case ColorSpaceType.Color6: return new ColorX(Profile, inValues); case ColorSpaceType.Color7: return new ColorX(Profile, inValues); case ColorSpaceType.Color8: return new ColorX(Profile, inValues); case ColorSpaceType.Color9: return new ColorX(Profile, inValues); case ColorSpaceType.Color10: return new ColorX(Profile, inValues); case ColorSpaceType.Color11: return new ColorX(Profile, inValues); case ColorSpaceType.Color12: return new ColorX(Profile, inValues); case ColorSpaceType.Color13: return new ColorX(Profile, inValues); case ColorSpaceType.Color14: return new ColorX(Profile, inValues); case ColorSpaceType.Color15: return new ColorX(Profile, inValues); default: throw new NotImplementedException(); } }
internal static bool IsSameSpace(ColorModel Model, ColorSpaceType Space) { if (Enum.GetName(typeof(ColorModel), Model).ToLower() == Enum.GetName(typeof(ColorSpaceType), Space).ToLower()) return true; else return false; }
/// <summary> /// Constructs a {@code RadialGradientPaint}. /// </summary> /// <param name="center"> the center point in user space of the circle defining the /// gradient. The last color of the gradient is mapped to /// the perimeter of this circle. </param> /// <param name="radius"> the radius of the circle defining the extents of the /// color gradient </param> /// <param name="focus"> the point in user space to which the first color is mapped </param> /// <param name="fractions"> numbers ranging from 0.0 to 1.0 specifying the /// distribution of colors along the gradient </param> /// <param name="colors"> array of colors to use in the gradient. The first color /// is used at the focus point, the last color around the /// perimeter of the circle. </param> /// <param name="cycleMethod"> either {@code NO_CYCLE}, {@code REFLECT}, /// or {@code REPEAT} </param> /// <param name="colorSpace"> which color space to use for interpolation, /// either {@code SRGB} or {@code LINEAR_RGB} </param> /// <param name="gradientTransform"> transform to apply to the gradient /// </param> /// <exception cref="NullPointerException"> /// if one of the points is null, /// or {@code fractions} array is null, /// or {@code colors} array is null, /// or {@code cycleMethod} is null, /// or {@code colorSpace} is null, /// or {@code gradientTransform} is null </exception> /// <exception cref="IllegalArgumentException"> /// if {@code radius} is non-positive, /// or {@code fractions.length != colors.length}, /// or {@code colors} is less than 2 in size, /// or a {@code fractions} value is less than 0.0 or greater than 1.0, /// or the {@code fractions} are not provided in strictly increasing order </exception> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @ConstructorProperties({ "centerPoint", "radius", "focusPoint", "fractions", "colors", "cycleMethod", "colorSpace", "transform" }) public RadialGradientPaint(java.awt.geom.Point2D center, float radius, java.awt.geom.Point2D focus, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace, java.awt.geom.AffineTransform gradientTransform) public RadialGradientPaint(Point2D center, float radius, Point2D focus, float[] fractions, Color[] colors, CycleMethod cycleMethod, ColorSpaceType colorSpace, AffineTransform gradientTransform) : base(fractions, colors, cycleMethod, colorSpace, gradientTransform) { // check input arguments if (center == null) { throw new NullPointerException("Center point must be non-null"); } if (focus == null) { throw new NullPointerException("Focus point must be non-null"); } if (radius <= 0) { throw new IllegalArgumentException("Radius must be greater " + "than zero"); } // copy parameters this.Center = new Point2D.Double(center.X, center.Y); this.Focus = new Point2D.Double(focus.X, focus.Y); this.Radius_Renamed = radius; }
private static extern bool GetStandardColorSpaceProfile(IntPtr pNull, ColorSpaceType dwSCS, StringBuilder pProfileName, out int pdwSize);
private Color ToColor(double[] inValues, ColorSpaceType outType) { switch (outType) { case ColorSpaceType.RGB: return(new ColorRGB(Profile, inValues[0], inValues[1], inValues[2], false)); case ColorSpaceType.HSV: return(new ColorHSV(Profile, inValues[0], inValues[1], inValues[2])); case ColorSpaceType.HLS: return(new ColorHSL(Profile, inValues[0], inValues[2], inValues[1])); case ColorSpaceType.CIEYxy: return(new ColorYxy(Profile.ReferenceWhite, inValues[0], inValues[1], inValues[2])); case ColorSpaceType.CIEXYZ: return(new ColorXYZ(Profile.ReferenceWhite, inValues[0], inValues[1], inValues[2])); case ColorSpaceType.CIELUV: return(new ColorLuv(Profile.ReferenceWhite, inValues[0] * 100, inValues[1], inValues[2])); case ColorSpaceType.CIELAB: return(new ColorLab(Profile.ReferenceWhite, inValues[0] * 100, inValues[1], inValues[2])); case ColorSpaceType.CMY: return(new ColorCMY(Profile, inValues[0] * 100, inValues[1] * 100, inValues[2] * 100)); case ColorSpaceType.CMYK: return(new ColorCMYK(Profile, inValues[0] * 100, inValues[1] * 100, inValues[2] * 100, inValues[3] * 100)); case ColorSpaceType.Gray: return(new ColorGray(Profile, inValues[0])); case ColorSpaceType.YCbCr: return(new ColorYCbCr(Profile, inValues[0], inValues[1], inValues[2])); case ColorSpaceType.Color2: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color3: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color4: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color5: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color6: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color7: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color8: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color9: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color10: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color11: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color12: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color13: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color14: return(new ColorX(Profile, inValues)); case ColorSpaceType.Color15: return(new ColorX(Profile, inValues)); default: throw new NotImplementedException(); } }