/// <summary> /// Sorts the image by the selected RGB value (either Red, Green, or Blue) /// </summary> /// <param name="toSort">Image that is to be sorted</param> /// <param name="colorChecked">The color that is selected</param> /// <param name="addOps">Additional operations that are selected</param> /// <param name="selectedSort">The selected sorting method</param> /// <returns>Returns the image that is sorted by Reds, Greens, or Blues</returns> private Bitmap SortByRGB(Bitmap toSort, RGBEnum colorChecked, AdditionalOptionsEnum addOps, SortingMethodsEnum selectedSort, double lower, double upper) { // If spiral wasn't selected, then run the following code if (addOps != AdditionalOptionsEnum.Spiral) { for (int i = 0; i < toSort.Height; ++i) { pixels.Clear(); for (int j = 0; j < toSort.Width; ++j) { pixels.Add(toSort.GetPixel(j, i)); } pixels = RGBSortWithBounds(pixels, lower, upper, colorChecked); for (int j = 0; j < pixels.Count; ++j) { toSort.SetPixel(j, i, pixels[j]); } } } // if spiral was selected, then run SortBySpiral else { toSort = SortBySpiral(toSort, selectedSort, lower, upper, colorChecked); } // returns the sorted image //toSort.SetResolution(72.0F, 72.0F); return(toSort); }
public void AddColor(RGBEnum addColor) { // TODO: Update to match design decision if ((addColor | EnemyColor) == RGBEnum.Composite) { return; } else { EnemyColor = addColor | EnemyColor; } }
/// <summary> /// Sorts the passed in list by RGB values with respect to boundaries /// </summary> /// <param name="pixelList">List of pixels to be sorted</param> /// <param name="lower">Lower boundary</param> /// <param name="upper">Upper boundary</param> /// <returns>Sorted list of pixels</returns> private List <Color> RGBSortWithBounds(List <Color> pixelList, double lower, double upper, RGBEnum sortBy) { if (upper < lower) { double mid = upper; upper = lower; lower = mid; } if (upper > 255.0) { upper = 255.0; } if (lower < 0.0) { lower = 0.0; } int a = 0; bool first = false; int b = 0; if (sortBy == RGBEnum.Blue) { for (int j = 0; j < pixelList.Count; ++j) { double color = pixelList[j].B; if (color <= upper && color >= lower) { if (!first) { a = j; first = true; continue; } b = j; } else { if (b > a) { temp = new List <Color>(pixelList.GetRange(a, b - a + 1)); temp.Sort(new BlueSort()); for (int c = 0; c < temp.Count; ++c) { pixelList[a] = temp[c]; ++a; } } b = 0; a = 0; first = false; } } if (b > a) { temp = new List <Color>(pixelList.GetRange(a, b - a + 1)); temp.Sort(new BlueSort()); int d = b - a; for (int c = 0; c < d; ++c) { pixelList[a] = temp[c]; ++a; } } } else if (sortBy == RGBEnum.Green) { for (int j = 0; j < pixelList.Count; ++j) { double color = pixelList[j].G; if (color <= upper && color >= lower) { if (!first) { a = j; first = true; continue; } b = j; } else { if (b > a) { temp = new List <Color>(pixelList.GetRange(a, b - a + 1)); temp.Sort(new GreenSort()); for (int c = 0; c < temp.Count; ++c) { pixelList[a] = temp[c]; ++a; } } b = 0; a = 0; first = false; } } if (b > a) { temp = new List <Color>(pixelList.GetRange(a, b - a + 1)); temp.Sort(new GreenSort()); int d = b - a; for (int c = 0; c < d; ++c) { pixelList[a] = temp[c]; ++a; } } } else { for (int j = 0; j < pixelList.Count; ++j) { double color = pixelList[j].R; if (color <= upper && color >= lower) { if (!first) { a = j; first = true; continue; } b = j; } else { if (b > a) { temp = new List <Color>(pixelList.GetRange(a, b - a + 1)); temp.Sort(new RedSort()); for (int c = 0; c < temp.Count; ++c) { pixelList[a] = temp[c]; ++a; } } b = 0; a = 0; first = false; } } if (b > a) { temp = new List <Color>(pixelList.GetRange(a, b - a + 1)); temp.Sort(new RedSort()); int d = b - a; for (int c = 0; c < d; ++c) { pixelList[a] = temp[c]; ++a; } } } return(pixelList); }
/// <summary> /// This will sort the passed in image by moving from the exterior perimeter to the interior and sorting the perimeter as though it was one singular line /// </summary> /// <param name="image">The image to be sorted</param> /// <param name="selectedSort">The selected sorting method</param> /// <param name="lower">The lower bound (used for brightness sorting)</param> /// <param name="upper">The upper bound (used for brightness sorting)</param> /// <param name="color">The selected color (used for RGB sorting)</param> /// <returns>Returns a sorted image</returns> private Bitmap SortBySpiral(Bitmap image, SortingMethodsEnum selectedSort, double lower, double upper, RGBEnum color) { //Sets the intial boundaries for the min and max values of Width and Height int endWidth = image.Width - 1; int endHeight = image.Height - 1; int startWidth = 0; int startHeight = 0; // Iteratively moves in from the exterior to the center and sorts the collected pixels from the perimeter while (endWidth >= startWidth && endHeight >= startHeight) { // Clear pixels and add the pixels from the perimeter to it pixels.Clear(); for (int i = startWidth; i < endWidth; ++i) { pixels.Add(image.GetPixel(i, startHeight)); } for (int i = startHeight; i < endHeight; ++i) { pixels.Add(image.GetPixel(endWidth, i)); } for (int i = endWidth; i > startWidth; --i) { pixels.Add(image.GetPixel(i, endHeight)); } for (int i = endHeight; i > startHeight; --i) { pixels.Add(image.GetPixel(startWidth, i)); } // Sort pixels with respect to bounds by Brightness if (selectedSort == SortingMethodsEnum.Brightness) { pixels = BrightSortWithBounds(pixels, lower, upper); } // Sort pixels by Hue if (selectedSort == SortingMethodsEnum.Hue) { pixels = HueSortWithBounds(pixels, lower, upper); } // Sort pixels by Saturation if (selectedSort == SortingMethodsEnum.Saturation) { pixels = SaturationSortWithBounds(pixels, lower, upper); } // Sort pixels with respect to RGB if (selectedSort == SortingMethodsEnum.RGB) { pixels = RGBSortWithBounds(pixels, lower, upper, color); } // Put the pixels that were sorted back into the perimeter of the image int count = 0; for (int i = startWidth; i < endWidth; ++i) { image.SetPixel(i, startHeight, pixels[count]); count++; } for (int i = startHeight; i < endHeight; ++i) { pixels.Add(image.GetPixel(endWidth, i)); image.SetPixel(endWidth, i, pixels[count]); count++; } for (int i = endWidth; i > startWidth; --i) { image.SetPixel(i, endHeight, pixels[count]); count++; } for (int i = endHeight; i > startHeight; --i) { pixels.Add(image.GetPixel(startWidth, i)); image.SetPixel(startWidth, i, pixels[count]); count++; } ++startWidth; ++startHeight; --endWidth; --endHeight; } // image is returned return(image); }
/// <summary> /// Default method to be used for a new sorting instance /// </summary> /// <param name="path">Path of the image that will be processed</param> /// <param name="selectedSort">Enum of the selected sorting method to be used</param> /// <param name="lower">lower bounds for the brightness sort</param> /// <param name="upper">upper bounds for the brightness sort</param> /// <returns></returns> public Bitmap Sort(string path, SortingMethodsEnum selectedSort, double lower, double upper, int hP, int vP, RGBEnum colorChecked, AdditionalOptionsEnum addOps, DirectionEnum directionChecked) { // if path is null or "", return null if (path == null || path.Equals("")) { return(null); } // creates two Bitmaps of the same image, handy for keeping the original width/height // and other data Bitmap image = new Bitmap(@path); Bitmap origImage = new Bitmap(@path); image = RotateImage(image, directionChecked); origImage = RotateImage(origImage, directionChecked); // if Extend is clicked, ExtendSort the image if (addOps == AdditionalOptionsEnum.Extend) { image = ExtendSort(image); } // If the number of horizontal or vertical partitions is greater than or equal to the // width or height of the image, don't partition the image and sort with the whole image instead if (hP >= image.Width || vP >= image.Height) { // Switch statement for using the correct sort based on the selected method switch (selectedSort) { case SortingMethodsEnum.Brightness: image = SortByBrightness(image, lower, upper, addOps, selectedSort); break; case SortingMethodsEnum.Hue: image = SortByHue(image, addOps, selectedSort, lower, upper); break; case SortingMethodsEnum.Saturation: image = SortBySaturation(image, addOps, selectedSort, lower, upper); break; case SortingMethodsEnum.RGB: image = SortByRGB(image, colorChecked, addOps, selectedSort, lower, upper); break; default: break; } } // If the number of partitions wanted is within the image's width/height, split the // image into (horizontal partitions + 1) * (vertical partitions + 1), sort the // paritions, and then stitch them back together else { int modx = image.Width % (1 + hP); int mody = image.Height % (1 + vP); image = RotateImageBack(image, directionChecked); List <Bitmap> partitions = PartitionImage(image, hP, vP, modx, mody); for (int i = 0; i < partitions.Count; ++i) { partitions[i] = RotateImage(partitions[i], directionChecked); switch (selectedSort) { case SortingMethodsEnum.Brightness: partitions[i] = SortByBrightness(partitions[i], lower, upper, addOps, selectedSort); partitions[i] = RotateImageBack(partitions[i], directionChecked); continue; case SortingMethodsEnum.Hue: partitions[i] = SortByHue(partitions[i], addOps, selectedSort, lower, upper); partitions[i] = RotateImageBack(partitions[i], directionChecked); continue; case SortingMethodsEnum.Saturation: partitions[i] = SortBySaturation(partitions[i], addOps, selectedSort, lower, upper); partitions[i] = RotateImageBack(partitions[i], directionChecked); continue; case SortingMethodsEnum.RGB: partitions[i] = SortByRGB(partitions[i], colorChecked, addOps, selectedSort, lower, upper); partitions[i] = RotateImageBack(partitions[i], directionChecked); continue; default: partitions[i] = RotateImageBack(partitions[i], directionChecked); continue; } } image = Recombine(partitions, hP + 1); image = RotateImage(image, directionChecked); } // if Extending was selected, then put the image back together so it's no longer a single line of pixels if (addOps == AdditionalOptionsEnum.Extend) { image = UnExtendSort(image, origImage); } image = RotateImageBack(image, directionChecked); // return the image to the user return(image); }
// TODO: Update to design decision public Bullet(RGBEnum color = RGBEnum.Composite) { BulletColor = color; }