/// <summary>Creates a high quality rounded corner color-map.</summary> /// <param name="innerRadius">The inner radius.</param> /// <param name="outerRadius">The outer radius.</param> /// <param name="innerColor">Color of the inner.</param> /// <param name="outerColor">Color of the outer.</param> /// <returns>A color-map with a high quality rounded corner inside.</returns> private static ColorMap CreateHighQualityRoundedCornerColorMap(int innerRadius, int outerRadius, GUIColor innerColor, GUIColor outerColor) { int x; int y; const int GrowFactor = 4; int width = outerRadius * GrowFactor; int height = outerRadius * GrowFactor; // create a grown round corner var array = new ColorMap(width, height); for (x = 0; x < +width; x++) { for (y = 0; y < +height; y++) { // get the distance to x,y var r = Math.Sqrt((x * x) + (y * y)); if (r < innerRadius * GrowFactor) { array.Set(x, y, innerColor); } else if (r >= innerRadius * GrowFactor && r < outerRadius * GrowFactor) { array.Set(x, y, outerColor); } } } // and shrink it array = ResizeImage(array, outerRadius, outerRadius); return(array); }
private static ColorMap CreateRoundedCornerColorMap(int innerRadius, int outerRadius, GUIColor innerColor, GUIColor outerColor) { int x; int y; int width = outerRadius; int height = outerRadius; var array = new ColorMap(width, height); for (x = 0; x < +width; x++) { for (y = 0; y < +height; y++) { // get the distance to x,y var r = Math.Sqrt((x * x) + (y * y)); if (r < innerRadius) { array.Set(x, y, innerColor); } else if (r >= innerRadius && r < outerRadius) { array.Set(x, y, outerColor); } } } return(array); }
/// <summary> /// Draws the vertical line on the given color-map. /// </summary> /// <param name="colorMap">The color map to draw into.</param> /// <param name="x">The x position to draw the line.</param> /// <param name="startY">The start y to draw the line.</param> /// <param name="endY">The end y to draw the line.</param> /// <param name="colorToUse">The color to use.</param> private static void DrawVerticalLineOnColorMap(ref ColorMap colorMap, int x, int startY, int endY, GUIColor colorToUse) { for (int y = startY; y < endY; y++) { colorMap.Set(x, y, colorToUse); } }
/// <summary> /// Draws a horizontal line on the given color-map. /// </summary> /// <param name="colorMap">The color map to draw into.</param> /// <param name="y">The y position to draw the line.</param> /// <param name="startX">The start x to draw the line.</param> /// <param name="endX">The end x to draw the line.</param> /// <param name="colorToUse">The color to use.</param> private static void DrawHorizontalLineOnColorMap(ref ColorMap colorMap, int y, int startX, int endX, GUIColor colorToUse) { for (var x = startX; x < endX; x++) { colorMap.Set(x, y, colorToUse); } }
private static void SetPixel(ref ColorMap colorMap, int imageWidth, int imageHeight, float x, float y, GUIColor colorToUse) { // all is centered , so shift it back t bitmap coordinates // shift x to bitmap location var tempX = (imageWidth / 2) + (int)x; if (tempX >= imageWidth) { return; } if (tempX <= 0) { return; } // shift y to bitmap location var tempY = (imageHeight / 2) + (int)y; if (tempY >= imageHeight) { return; } if (tempY <= 0) { return; } // get the location into my array colorMap.Set(tempX, tempY, colorToUse); }
/// <summary>Creates the a texture with a rectangle with given color and border.</summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="borderWidth">Width of the border.</param> /// <param name="color">The color.</param> /// <param name="borderColor">Color of the border.</param> /// <returns>A color map with a rectangle image in the colorMap.</returns> public static ColorMap CreateRectangleColorMap(int width, int height, int borderWidth, GUIColor color, GUIColor borderColor) { var colorMap = new ColorMap(width, height); var left = borderWidth; var right = width - borderWidth; var top = borderWidth; var bottom = height - borderWidth; GUIColor colorToUse; for (var wY = 0; wY < height; wY++) { for (var wX = 0; wX < width; wX++) { colorToUse = color; if (wX < left || wX >= right) { colorToUse = borderColor; } if (wY < top || wY >= bottom) { colorToUse = borderColor; } colorMap.Set(wX, wY, colorToUse); } } return(colorMap); }
private static void CreateEmptyRectangleColorMap(ref ColorMap colorMap, int imageWidth, int imageHeight, GUIColor colorToUse) { for (var wY = 0; wY < imageHeight; wY++) { for (var wX = 0; wX < imageWidth; wX++) { colorMap.Set(wX, wY, colorToUse); } } }
/// <summary> /// Draws a color filled rectangle on given color-map. /// </summary> /// <param name="colorMap">The color map.</param> /// <param name="startX">The start x.</param> /// <param name="startY">The start y.</param> /// <param name="endX">The end x.</param> /// <param name="endY">The end y.</param> /// <param name="colorToUse">The color to use.</param> private static void DrawRectangleOnColorMap(ref ColorMap colorMap, int startX, int startY, int endX, int endY, GUIColor colorToUse) { for (var x = startX; x < endX; x++) { for (var y = startY; y < endY; y++) { colorMap.Set(x, y, colorToUse); } } }
/// <summary>Create a new color-map with a vertical flip of given color-map.</summary> /// <param name="source">The source.</param> /// <returns>A vertical flipped color-map.</returns> private static ColorMap FlipColorMapHVertical(ColorMap source) { var target = new ColorMap(source.Width, source.Height); for (int x = 0; x < source.Width; x++) { for (int y = 0; y < source.Height; y++) { var sourcePixel = source.Get(x, y); target.Set(x, (source.Height - 1) - y, sourcePixel); } } return(target); }
private static ColorMap CreateRoundedCornerColorMap(int innerRadius, int outerRadius, GUIColor innerColor, GUIColor outerColor) { int x; int y; int width = outerRadius; int height = outerRadius; var array = new ColorMap(width, height); for (x = 0; x < +width; x++) { for (y = 0; y < +height; y++) { // get the distance to x,y var r = Math.Sqrt((x * x) + (y * y)); if (r < innerRadius) { array.Set(x, y, innerColor); } else if (r >= innerRadius && r < outerRadius) { array.Set(x, y, outerColor); } } } return array; }
/// <summary>Resizes the color-map to the given target size.</summary> /// <param name="sourceArray">The source array.</param> /// <param name="targetWidth">Width of the target.</param> /// <param name="targetHeight">Height of the target.</param> /// <returns>A color-map with given target size.</returns> private static ColorMap ResizeImage(ColorMap sourceArray, int targetWidth, int targetHeight) { var targetArray = new ColorMap(targetWidth, targetHeight); // walk trough every pixel on the target // find out the area that the a pixel on target is covering on the source // average the source area into one pixel to be used on the target // // the way i am looking at it is that you have a target (emitting) rectangle standing on a table // and somewhere further in the distance you have a larger source (receiving) rectangle standing on a table // we are shooting beams trough the target (emitting) rectangle // those hit the source (receiving) rectangle at a given position // we use those hit-points to calculate what the color will be in the target rectangle for (int targetX = 0; targetX < targetWidth; targetX++) { for (int targetY = 0; targetY < targetHeight; targetY++) { // we walk trough every point in the target rectangle // find out, how big the source rectangle is var sourceAreaWidth = (float)sourceArray.Width / targetWidth; var sourceAreaHeight = (float)sourceArray.Height / targetHeight; // find the center of the source rectangle (receiver) on the table var percentageTargetX = (float)targetX / targetWidth; var percentageTargetY = (float)targetY / targetHeight; var sourceCentreX = Lerp(0, sourceArray.Width, percentageTargetX); var sourceCentreY = Lerp(0, sourceArray.Height, percentageTargetY); // get the array of pixels on the source rectangle , that we will use for averaging my location on the target rectangle var sourceLeft = Math.Floor(sourceCentreX - (sourceAreaWidth * 0.5f)); var sourceRight = Math.Ceiling(sourceCentreX + (sourceAreaWidth * 0.5f)); var sourceTop = Math.Floor(sourceCentreY - (sourceAreaHeight * 0.5f)); var sourceBottom = Math.Ceiling(sourceCentreY + (sourceAreaHeight * 0.5f)); // get all the colors in the source rectangle that are targeted var colorToAverage = new List<GUIColor>(); for (var parseX = (int)sourceLeft; parseX < sourceRight; parseX++) { for (var parseY = (int)sourceTop; parseY < sourceBottom; parseY++) { if (parseX < 0 || parseX > sourceArray.Width || parseY < 0 || parseY > sourceArray.Height) { continue; } var sourceColor = sourceArray.Get(parseX, parseY); colorToAverage.Add(sourceColor); } } // average those colors into the color that will be used in the target rectangle float r = 0; float g = 0; float b = 0; float a = 0; for (var index = 0; index < colorToAverage.Count; index++) { var clr = colorToAverage[index]; r = r + clr.R; g = g + clr.G; b = b + clr.B; a = a + clr.A; } r = r / colorToAverage.Count; g = g / colorToAverage.Count; b = b / colorToAverage.Count; a = a / colorToAverage.Count; targetArray.Set(targetX, targetY, new GUIColor((byte)r, (byte)g, (byte)b, (byte)a)); } } return targetArray; }
/// <summary>Creates the a texture with a rectangle with given color and border.</summary> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="borderWidth">Width of the border.</param> /// <param name="color">The color.</param> /// <param name="borderColor">Color of the border.</param> /// <returns>A color map with a rectangle image in the colorMap.</returns> public static ColorMap CreateRectangleColorMap(int width, int height, int borderWidth, GUIColor color, GUIColor borderColor) { var colorMap = new ColorMap(width, height); var left = borderWidth; var right = width - borderWidth; var top = borderWidth; var bottom = height - borderWidth; GUIColor colorToUse; for (var wY = 0; wY < height; wY++) { for (var wX = 0; wX < width; wX++) { colorToUse = color; if (wX < left || wX >= right) { colorToUse = borderColor; } if (wY < top || wY >= bottom) { colorToUse = borderColor; } colorMap.Set(wX, wY, colorToUse); } } return colorMap; }
/// <summary>Resizes the color-map to the given target size.</summary> /// <param name="sourceArray">The source array.</param> /// <param name="targetWidth">Width of the target.</param> /// <param name="targetHeight">Height of the target.</param> /// <returns>A color-map with given target size.</returns> private static ColorMap ResizeImage(ColorMap sourceArray, int targetWidth, int targetHeight) { var targetArray = new ColorMap(targetWidth, targetHeight); // walk trough every pixel on the target // find out the area that the a pixel on target is covering on the source // average the source area into one pixel to be used on the target // // the way i am looking at it is that you have a target (emitting) rectangle standing on a table // and somewhere further in the distance you have a larger source (receiving) rectangle standing on a table // we are shooting beams trough the target (emitting) rectangle // those hit the source (receiving) rectangle at a given position // we use those hit-points to calculate what the color will be in the target rectangle for (int targetX = 0; targetX < targetWidth; targetX++) { for (int targetY = 0; targetY < targetHeight; targetY++) { // we walk trough every point in the target rectangle // find out, how big the source rectangle is var sourceAreaWidth = (float)sourceArray.Width / targetWidth; var sourceAreaHeight = (float)sourceArray.Height / targetHeight; // find the center of the source rectangle (receiver) on the table var percentageTargetX = (float)targetX / targetWidth; var percentageTargetY = (float)targetY / targetHeight; var sourceCentreX = Lerp(0, sourceArray.Width, percentageTargetX); var sourceCentreY = Lerp(0, sourceArray.Height, percentageTargetY); // get the array of pixels on the source rectangle , that we will use for averaging my location on the target rectangle var sourceLeft = Math.Floor(sourceCentreX - (sourceAreaWidth * 0.5f)); var sourceRight = Math.Ceiling(sourceCentreX + (sourceAreaWidth * 0.5f)); var sourceTop = Math.Floor(sourceCentreY - (sourceAreaHeight * 0.5f)); var sourceBottom = Math.Ceiling(sourceCentreY + (sourceAreaHeight * 0.5f)); // get all the colors in the source rectangle that are targeted var colorToAverage = new List <GUIColor>(); for (var parseX = (int)sourceLeft; parseX < sourceRight; parseX++) { for (var parseY = (int)sourceTop; parseY < sourceBottom; parseY++) { if (parseX < 0 || parseX > sourceArray.Width || parseY < 0 || parseY > sourceArray.Height) { continue; } var sourceColor = sourceArray.Get(parseX, parseY); colorToAverage.Add(sourceColor); } } // average those colors into the color that will be used in the target rectangle float r = 0; float g = 0; float b = 0; float a = 0; for (var index = 0; index < colorToAverage.Count; index++) { var clr = colorToAverage[index]; r = r + clr.R; g = g + clr.G; b = b + clr.B; a = a + clr.A; } r = r / colorToAverage.Count; g = g / colorToAverage.Count; b = b / colorToAverage.Count; a = a / colorToAverage.Count; targetArray.Set(targetX, targetY, new GUIColor((byte)r, (byte)g, (byte)b, (byte)a)); } } return(targetArray); }
/// <summary>Fills in the content of the control showing all values of Luminance (0 to 100%) for the given /// Hue and Saturation.</summary> /// <param name="map">The map to update.</param> private void DrawStyleLuminance(ref ColorMap map) { // Use the H and S values of the current color (m_hsl) var colorToConvert = new HSL { H = this.hsl.H, S = this.hsl.S }; // i represents the current line of pixels we want to draw horizontally for (var i = 0; i < map.Height; i++) { // L (Luminance) is based on the current vertical position colorToConvert.L = 1.0 - ((double)i / map.Height); // Get the Color for this line var rgb = AdobeColors.HSLToRGB(colorToConvert); for (var l = 0; l < map.Width; l++) { map.Set(l, i, rgb); } } }
/// <summary>Create a new color-map with a vertical flip of given color-map.</summary> /// <param name="source">The source.</param> /// <returns>A vertical flipped color-map.</returns> private static ColorMap FlipColorMapHVertical(ColorMap source) { var target = new ColorMap(source.Width, source.Height); for (int x = 0; x < source.Width; x++) { for (int y = 0; y < source.Height; y++) { var sourcePixel = source.Get(x, y); target.Set(x, (source.Height - 1) - y, sourcePixel); } } return target; }
/// <summary>Creates a high quality rounded corner color-map.</summary> /// <param name="innerRadius">The inner radius.</param> /// <param name="outerRadius">The outer radius.</param> /// <param name="innerColor">Color of the inner.</param> /// <param name="outerColor">Color of the outer.</param> /// <returns>A color-map with a high quality rounded corner inside.</returns> private static ColorMap CreateHighQualityRoundedCornerColorMap(int innerRadius, int outerRadius, GUIColor innerColor, GUIColor outerColor) { int x; int y; const int GrowFactor = 4; int width = outerRadius * GrowFactor; int height = outerRadius * GrowFactor; // create a grown round corner var array = new ColorMap(width, height); for (x = 0; x < +width; x++) { for (y = 0; y < +height; y++) { // get the distance to x,y var r = Math.Sqrt((x * x) + (y * y)); if (r < innerRadius * GrowFactor) { array.Set(x, y, innerColor); } else if (r >= innerRadius * GrowFactor && r < outerRadius * GrowFactor) { array.Set(x, y, outerColor); } } } // and shrink it array = ResizeImage(array, outerRadius, outerRadius); return array; }
/// <summary> /// Draws this control in the style blue. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleBlue(ref ColorMap map) { var blue = this.rgba.B; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { // red = x, green = y , blue is constant var red = Round((x / map.Width) * 255); var green = Round(255 - (255 * (double)y / (map.Height - 4))); map.Set(x, y, new GUIColor((byte)red, (byte)green, blue)); } } }
/// <summary> /// Draws this control in the style red. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleRed(ref ColorMap map) { var red = this.rgba.G; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { // red = constant, green = x , blue = y var green = Round((x / map.Width) * 255); var blue = Round(255 - (255 * (double)y / (map.Height - 4))); map.Set(x, y, new GUIColor(red, (byte)green, (byte)blue)); } } }
/// <summary> /// Fills in the content of the control showing all values of Hue (from 0 to 360) , a rainbow /// </summary> /// <param name="map">The map to update.</param> private static void DrawStyleHue(ref ColorMap map) { // S and L will both be at 100% for this DrawStyle var hsl = new HSL { S = 1.0, L = 1.0 }; // i represents the current line of pixels we want to draw horizontally for (var i = 0; i < map.Height; i++) { // H (hue) is based on the current vertical position hsl.H = 1.0 - ((double)i / map.Height); // Get the Color for this line var rgb = AdobeColors.HSLToRGB(hsl); for (var l = 0; l < map.Width; l++) { map.Set(l, i, rgb); } } }
/// <summary> /// Draws this control in the style saturation. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleSaturation(ref ColorMap map) { var hslStart = new HSL(); var hslEnd = new HSL(); hslStart.S = this.hsl.S; hslEnd.S = this.hsl.S; hslStart.L = 1.0; hslEnd.L = 0.0; for (var x = 0; x < map.Width; x++) { for (var y = 0; y < map.Height; y++) { // Calculate Hue at this line (Saturation and Luminance are constant) hslStart.H = (double)x / map.Width; hslEnd.H = hslStart.H; var rgbStart = AdobeColors.HSLToRGB(hslStart); var rgbEnd = AdobeColors.HSLToRGB(hslEnd); var lerpValue = y / map.Height; var rgbValue = AdobeColors.Lerp(rgbStart, rgbEnd, lerpValue); map.Set(x, y, rgbValue); } } }
/// <summary>Fills in the content of the control showing all values of Blue (0 to 255) for the given /// Red and Green.</summary> /// <param name="map">The map to update.</param> private void DrawStyleBlue(ref ColorMap map) { // i represents the current line of pixels we want to draw horizontally for (var i = 0; i < map.Height; i++) { // red is based on the current vertical position var blue = 255 - Round(255 * (double)i / map.Height); // Get the Color for this line var rgb = GUIColor.FromARGB(this.rgba.R, this.rgba.G, blue); for (var l = 0; l < map.Width; l++) { map.Set(l, i, rgb); } } }
/// <summary> /// Draws this control in the style hue. /// </summary> /// <param name="map">The map to update.</param> private void DrawStyleHue(ref ColorMap map) { var hslStart = new HSL(); var hslEnd = new HSL(); hslStart.H = this.hsl.H; hslEnd.H = this.hsl.H; hslStart.S = 0; hslEnd.S = 1; for (var y = 0; y < map.Height; y++) { hslStart.L = (float)y / map.Height; hslEnd.L = hslStart.L; var rgbStart = AdobeColors.HSLToRGB(hslStart); var rgbEnd = AdobeColors.HSLToRGB(hslEnd); for (var x = 0; x < map.Width; x++) { var lerpValue = 1 - (x / (float)map.Width); // System.Diagnostics.Debug.WriteLine(lerpValue); var rgbValue = AdobeColors.Lerp(rgbStart, rgbEnd, lerpValue); map.Set(x, y, rgbValue); } } }