private void ExtendEdge(IPixelCollection <ushort> pixels, int width, int height) { ushort[]? brushXLeft = pixels.GetArea(Settings.PaddingX, 0, 1, height); ushort[]? brushXRight = pixels.GetArea(width - 1 - Settings.PaddingX, 0, 1, height); for (int i = 0; i < Settings.PaddingX; i++) { pixels.SetArea(i, 0, 1, height, brushXLeft); pixels.SetArea(width - 1 - i, 0, 1, height, brushXRight); } ushort[]? brushYLeft = pixels.GetArea(0, Settings.PaddingY, width, 1); ushort[]? brushYRight = pixels.GetArea(0, height - 1 - Settings.PaddingY, width, 1); for (int i = 0; i < Settings.PaddingY; i++) { pixels.SetArea(0, i, width, 1, brushYLeft); pixels.SetArea(0, height - 1 - i, width, 1, brushYRight); } }
private static void ThrowsNoException(int x, int y, int width, int height) { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.GetArea(x, y, width, height); } } }
private static void ThrowsOverflowExceptionWhen32Bit(int x, int y, int width, int height) { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { if (Is64Bit) { pixels.GetArea(x, y, width, height); } else { ExceptionAssert.Throws <OverflowException>(() => { pixels.GetArea(x, y, width, height); }); } } } }
public void ShouldReturnNullWhenGeometryIsNull() { using (IMagickImage image = new MagickImage(Files.RedPNG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { var area = pixels.GetArea(null); Assert.IsNull(area); } } }
public void ShouldThrowExceptionWhenWidthZero() { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { ExceptionAssert.Throws <InvalidOperationException>(() => { pixels.GetArea(0, 0, 0, 1); }); } } }
public void ShouldThrowExceptionWhenWidthTooLow() { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { ExceptionAssert.Throws <OverflowException>(() => { pixels.GetArea(0, 0, -1, 1); }); } } }
public void ShouldThrowExceptionWhenHeightZero() { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { ExceptionAssert.Throws <MagickCacheErrorException>(() => { pixels.GetArea(0, 0, 1, 0); }); } } }
private static void ThrowsArgumentException(string paramName, int x, int y, int width, int height) { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentOutOfRangeException(paramName, () => { pixels.GetArea(x, y, width, height); }); } } }
public void ShouldThrowExceptionWhenGeometryIsNull() { using (IMagickImage image = new MagickImage(Files.RedPNG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("geometry", () => { pixels.GetArea(null); }); } } }
public void GetArea_HeightZero_ThrowsException() { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { ExceptionAssert.Throws<InvalidOperationException>(() => { pixels.GetArea(0, 0, 1, 0); }); } } }
public void ShouldThrowExceptionWhenHeightTooLow() { using (IMagickImage image = new MagickImage(MagickColors.Red, 5, 10)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { if (Is64Bit) { ExceptionAssert.Throws <MagickResourceLimitErrorException>(() => { pixels.GetArea(0, 0, 1, -1); }); } else { ExceptionAssert.Throws <OverflowException>(() => { pixels.GetArea(0, 0, 1, -1); }); } } } }
static float[] GetLinearPixel(IPixelCollection p, long offset, int width) { int y = (int)(offset / width); int x = (int)(offset % width); float[] pixel = p.GetArea(x, y, 1, 1); //Debug.WriteLine("get "+offset+"\t["+x+","+y+"]" // +"\t"+BitConverter.ToString(BitConverter.GetBytes(pixel[0]),0) // +"\t"+BitConverter.ToString(BitConverter.GetBytes(pixel[1]),0) // +"\t"+BitConverter.ToString(BitConverter.GetBytes(pixel[2]),0) // +"\t"+BitConverter.ToString(BitConverter.GetBytes(pixel[3]),0) //); return(pixel); }
public void ShouldReturnAreaWhenGeometryIsValid() { using (IMagickImage image = new MagickImage(Files.RedPNG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { var area = pixels.GetArea(new MagickGeometry(0, 0, 6, 5)); int length = 6 * 5 * 4; // width * height * channelCount MagickColor color = new MagickColor(area[0], area[1], area[2], area[3]); Assert.AreEqual(length, area.Length); ColorAssert.AreEqual(MagickColors.Red, color); } } }
public void ShouldReturnAreaWhenAreaIsValid() { using (IMagickImage image = new MagickImage(Files.CirclePNG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { var area = pixels.GetArea(28, 28, 2, 3); int length = 2 * 3 * 4; // width * height * channelCount MagickColor color = new MagickColor(area[0], area[1], area[2], area[3]); Assert.AreEqual(length, area.Length); ColorAssert.AreEqual(new MagickColor("#ffffff9f"), color); } } }
public Image CreateCompleteMap(Descr_Strat ds, Descr_Region dr, SMFactions smf) { MagickImage regionMap = new MagickImage(dr.FilePathRegions); //use region map to map out regions MagickImage fullFactionMap = new MagickImage(radarMapLocation); // use radar map as a base var mag = new MagickGeometry(fullFactionMap.Width, fullFactionMap.Height); mag.FillArea = true; mag.IgnoreAspectRatio = true; regionMap.Alpha(AlphaOption.Remove); regionMap.AdaptiveResize(mag); var rpixels = regionMap.GetPixels(); foreach (Faction f in ds.factions) // loop through faction { var fpixels = fullFactionMap.GetPixels(); //set up both maps MagickImage factionMap = new MagickImage(radarMapLocation); factionMap.Alpha(AlphaOption.Remove); factionMap.AdaptiveResize(mag); using (IPixelCollection fmPixels = factionMap.GetPixels()) { foreach (Settlement s in f.settlements) //loop through settlements to get the regions { int[] regColour = dr.GetRGBValue(s.region); //get the colour of a region MagickColor regCol = MagickColor.FromRgb((byte)regColour[0], (byte)regColour[1], (byte)regColour[2]); Color facCol1 = smf.GetFactionColour(f.name, 0); //get the faction colour primary Color facCol2 = smf.GetFactionColour(f.name, 1); // secondary colour MagickColor priCol = MagickColor.FromRgb(facCol1.R, facCol1.G, facCol1.B); //convert the colours to magickcolour MagickColor secCol = MagickColor.FromRgb(facCol2.R, facCol2.G, facCol2.B); int channelsCount = fmPixels.Channels; for (int y = 0; y < factionMap.Height; y++) { List <ushort[]> regVert = new List <ushort[]>(); //create lists to store each pixel along the width of the image List <ushort[]> facVert = new List <ushort[]>(); if (y - 1 >= 0) { regVert.Add(rpixels.GetArea(0, y - 1, regionMap.Width, 1)); // get string of pixels across the image at current y value facVert.Add(fmPixels.GetArea(0, y - 1, factionMap.Width, 1)); } regVert.Add(rpixels.GetArea(0, y, regionMap.Width, 1)); facVert.Add(fmPixels.GetArea(0, y, factionMap.Width, 1)); if (y + 1 < regionMap.Height) { facVert.Add(fmPixels.GetArea(0, y + 1, factionMap.Width, 1)); regVert.Add(rpixels.GetArea(0, y + 1, regionMap.Width, 1)); } int i = 0; if (regVert.Count == 2) { i = 0; } else { i = 1; } for (int x = 0; x < regVert[i].Length; x += channelsCount) // traverse each pixel across the image at the current y value { MagickColor pixCol = new MagickColor(regVert[i][x], regVert[i][x + 1], regVert[i][x + 2]); //create magickcolour using MagickColor fCol = new MagickColor(facVert[i][x], facVert[i][x + 1], facVert[i][x + 2]); if (pixCol == regCol) //compare region colour { int bc = BorderCheck(x, i, regVert, regCol); //check if region is a border if (bc > 1 && bc < 4) { fpixels.SetPixel(x == 0 ? x : x / 3, y, Blend(secCol, fCol, 0.6)); ///divide x by 3 to account for the other channels fmPixels.SetPixel(x == 0 ? x : x / 3, y, Blend(secCol, fCol, 0.6)); } else { fpixels.SetPixel(x == 0 ? x : x / 3, y, Blend(priCol, fCol, 0.6)); fmPixels.SetPixel(x == 0 ? x : x / 3, y, Blend(priCol, fCol, 0.6)); } } } } } } Save(factionMap, f.name, saveLocation); } full_map = fullFactionMap; return(fullFactionMap.ToBitmap()); }
public MagickImage CreateDiplomacyMap(Descr_Strat ds, Descr_Region dr, SMFactions smf, string factionName, string savepath) { MagickImage regionMap = new MagickImage(dr.FilePathRegions); //use region map to map out regions var rpixels = regionMap.GetPixels(); //colours MagickColor fac1 = new MagickColor(Color.Gold); //get the faction colour primary MagickColor facCol2 = new MagickColor(Color.White); // secondary colour MagickColor allied = new MagickColor(Color.Green); MagickColor suspicous = new MagickColor(Color.Blue); MagickColor neutral = new MagickColor(Color.Aqua); MagickColor hostile = new MagickColor(Color.MediumVioletRed); MagickColor war = new MagickColor(Color.DarkRed); MagickColor currentColour1 = fac1; MagickColor currentColour2 = facCol2; MagickImage factionMap = new MagickImage(radarMapLocation); foreach (Faction f in ds.factions) // loop through faction { int relationval = (int)ds.factionRelationships.DoesFactionHaveRelations(factionName, f.name); if (f.name == factionName) { currentColour1 = fac1; currentColour2 = facCol2; } else if (relationval > -1) { DiplomaticPosition dp = ds.factionRelationships.GetDiplomaticPosition(relationval); if (dp == DiplomaticPosition.Allied) { currentColour1 = allied; } else if (dp == DiplomaticPosition.Hostile) { currentColour1 = hostile; } else if (dp == DiplomaticPosition.Neutral) { currentColour1 = neutral; } else if (dp == DiplomaticPosition.Suspicous) { currentColour1 = suspicous; } else if (dp == DiplomaticPosition.War) { currentColour1 = war; } } else { continue; } using (IPixelCollection fmPixels = factionMap.GetPixels()) { foreach (Settlement s in f.settlements) //loop through settlements to get the regions { int[] regColour = dr.GetRGBValue(s.region); //get the colour of a region MagickColor regCol = MagickColor.FromRgb((byte)regColour[0], (byte)regColour[1], (byte)regColour[2]); int channelsCount = fmPixels.Channels; for (int y = 0; y < factionMap.Height; y++) { List <ushort[]> regVert = new List <ushort[]>(); //create lists to store each pixel along the width of the image List <ushort[]> facVert = new List <ushort[]>(); if (y - 1 >= 0) { regVert.Add(rpixels.GetArea(0, y - 1, regionMap.Width, 1)); // get string of pixels across the image at current y value facVert.Add(fmPixels.GetArea(0, y - 1, factionMap.Width, 1)); } regVert.Add(rpixels.GetArea(0, y, regionMap.Width, 1)); facVert.Add(fmPixels.GetArea(0, y, factionMap.Width, 1)); if (y + 1 < regionMap.Height) { facVert.Add(fmPixels.GetArea(0, y + 1, factionMap.Width, 1)); regVert.Add(rpixels.GetArea(0, y + 1, regionMap.Width, 1)); } int i = 0; if (regVert.Count == 2) { i = 0; } else { i = 1; } for (int x = 0; x < regVert[i].Length; x += channelsCount) // traverse each pixel across the image at the current y value { MagickColor pixCol = new MagickColor(regVert[i][x], regVert[i][x + 1], regVert[i][x + 2]); //create magickcolour using MagickColor fCol = new MagickColor(facVert[i][x], facVert[i][x + 1], facVert[i][x + 2]); if (pixCol == regCol) //compare region colour { int bc = BorderCheck(x, i, regVert, regCol); //check if region is a border if (bc > 1 && bc < 4) { fmPixels.SetPixel(x == 0 ? x : x / 3, y, Blend(currentColour2, fCol, 0.6)); } else { fmPixels.SetPixel(x == 0 ? x : x / 3, y, Blend(currentColour1, fCol, 0.6)); } } } } } } } return(factionMap); }