public void SetPixel_PixelIsNull_ThrowsNoException() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.SetPixel((Pixel)null); } } }
public static void ModifyPixelThreadSafe(MagickImage img, int x, int y, MagickColor col) { lock (_lockObject) { using (IPixelCollection pixels = img.GetPixels()) { pixels.SetPixel(x, y, new ushort[] { col.R, col.G, col.B }); } } }
public void SetPixelWithOffset_ArrayIsEmpty_ThrowsNoException() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.SetPixel(0, 0, new QuantumType[] { }); } } }
public void ShouldThrowExceptionWhenArrayIsEmpty() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.SetPixel(0, 0, new QuantumType[] { }); } } }
public void ShouldNotThrowExceptionWhenPixelIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.SetPixel((Pixel)null); } } }
public void SetPixelWithOffset_CorrectNumberOfChannels_ChangesPixel() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { pixels.SetPixel(0, 0, new QuantumType[] { 0, 0, 0 }); ColorAssert.AreEqual(MagickColors.Black, image, 0, 0); } } }
public void SetPixelWithOffset_OneChannel_ChangesPixel() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.SetPixel(0, 0, new QuantumType[] { 0 }); ColorAssert.AreEqual(MagickColors.Cyan, image, 0, 0); } } }
public void ShouldChangePixelsWhenOneChannelAndOffsetAreSupplied() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { pixels.SetPixel(0, 0, new QuantumType[] { 0 }); ColorAssert.AreEqual(MagickColors.Cyan, image, 0, 0); } } }
public void ShouldChangePixelsWhenCorrectNumberOfChannelsAndOffsetAreSupplied() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { pixels.SetPixel(0, 0, new QuantumType[] { 0, 0, 0 }); ColorAssert.AreEqual(MagickColors.Black, image, 0, 0); } } }
public void ShouldThrowExceptionWhenArrayIsEmpty() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentException("value", () => { pixels.SetPixel(0, 0, new QuantumType[] { }); }); } } }
public void ShouldThrowExceptionWhenPixelWidthIsOutsideImage() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.Throws <ArgumentOutOfRangeException>("x", () => { pixels.SetPixel(new Pixel(image.Width + 1, 0, 3)); }); } } }
public void ShouldThrowExceptionWhenOffsetHeightIsOutsideImage() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.Throws <ArgumentOutOfRangeException>("y", () => { pixels.SetPixel(0, image.Height + 1, new QuantumType[] { 0 }); }); } } }
public void ShouldThrowExceptionWhenPixelHeightIsOutsideImage() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentOutOfRangeException("y", () => { pixels.SetPixel(new Pixel(0, image.Height + 1, 3)); }); } } }
public void SetPixelWithOffset_ArrayIsNull_ThrowsException() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("value", () => { pixels.SetPixel(0, 0, null); }); } } }
public void SetPixel_IEnumerablePixelIsNull_ThrowsException() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("pixels", () => { pixels.SetPixel((IEnumerable <Pixel>)null); }); } } }
public void SetPixel_CompletePixel_ChangesPixel() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { Pixel pixel = new Pixel(0, 0, new QuantumType[] { 0, 0, 0 }); pixels.SetPixel(pixel); ColorAssert.AreEqual(MagickColors.Black, image, 0, 0); } } }
public void ShouldThrowExceptionWhenPixelIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentNullException("pixel", () => { pixels.SetPixel((Pixel)null); }); } } }
public void ShouldThrowExceptionWhenArrayIsNull() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.Throws <ArgumentNullException>("value", () => { pixels.SetPixel(0, 0, null); }); } } }
public void ShouldChangePixelWhenCompletePixelIsSupplied() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { Pixel pixel = new Pixel(0, 0, new QuantumType[] { 0, Quantum.Max, 0 }); pixels.SetPixel(pixel); ColorAssert.AreEqual(MagickColors.Lime, image, 0, 0); } } }
public void ShouldThrowExceptionWhenOffsetWidthIsOutsideImage() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentOutOfRangeException("x", () => { pixels.SetPixel(image.Width + 1, 0, new QuantumType[] { 0 }); }); } } }
public void SetPixelWithOffset_OutSideImage_ThrowsException() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { ExceptionAssert.ThrowsArgumentException <ArgumentOutOfRangeException>("x", () => { pixels.SetPixel(image.Width + 1, 0, new QuantumType[] { 0 }); }); } } }
public void ShouldChangePixelWhenTooManyChannelsAreSupplied() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { Pixel pixel = new Pixel(0, 0, new QuantumType[] { 0, 0, 0, 0 }); pixels.SetPixel(pixel); ColorAssert.AreEqual(MagickColors.Black, image, 0, 0); } } }
public void ShouldThrowExceptionWhenPixelHeightIsOutsideImage() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { ExceptionAssert.Throws <MagickCacheErrorException>(() => { pixels.SetPixel(new Pixel(0, image.Height + 1, 3)); }); } } }
public void ShouldThrowExceptionWhenOffsetWidthIsOutsideImage() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { ExceptionAssert.Throws <MagickCacheErrorException>(() => { pixels.SetPixel(image.Width + 1, 0, new QuantumType[] { 0 }); }); } } }
private void GenerateHeightmap() { if (this.heightmapGenerated) { return; } MainForm.ProgressStart("Processing heightmap ..."); using (MagickImage offsetmap = zoneConfiguration.GetOffsetMap()) { using (MagickImage terrainmap = zoneConfiguration.GetTerrainMap()) { m_heightmap = new MagickImage(Color.Black, offsetmap.Width, offsetmap.Height); using (IPixelCollection heightmapPixels = m_heightmap.GetPixels()) { IPixelCollection terrainPixels = terrainmap.GetPixels(); IPixelCollection offsetPixels = offsetmap.GetPixels(); for (int x = 0; x < offsetmap.Width; x++) { for (int y = 0; y < offsetmap.Height; y++) { ushort terrainPixelValue = (ushort)(terrainPixels[x, y].GetChannel(0) / 256); ushort offsetPixelValue = (ushort)(offsetPixels[x, y].GetChannel(0) / 256); ushort heightmapPixelValue = (ushort)(terrainPixelValue * m_terrainfactor + offsetPixelValue * m_offsetfactor); heightmapPixels.SetPixel(x, y, new ushort[] { heightmapPixelValue, heightmapPixelValue, heightmapPixelValue }); } int percent = 100 * x / offsetmap.Width; MainForm.ProgressUpdate(percent); } //heightmapPixels.Write(); } MainForm.ProgressStartMarquee("Merging ..."); m_heightmap.Quality = 100; m_heightmap.Write(m_heightmapFile.FullName); // Scale to target size m_heightmapScaled = new MagickImage(m_heightmap); m_heightmapScaled.Resize(zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize); } } this.heightmapGenerated = true; MainForm.ProgressReset(); }
public void SetPixel_MultipleCompletePixels_ChangesPixels() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixels()) { Pixel pixelA = new Pixel(0, 0, new QuantumType[] { Quantum.Max, 0, 0 }); Pixel pixelB = new Pixel(1, 0, new QuantumType[] { 0, Quantum.Max, 0 }); pixels.SetPixel(new Pixel[] { pixelA, pixelB }); ColorAssert.AreEqual(MagickColors.Red, image, 0, 0); ColorAssert.AreEqual(MagickColors.Lime, image, 1, 0); } } }
public void ShouldChangePixelsWhenMultipleCompletePixelsAreSupplied() { using (IMagickImage image = new MagickImage(Files.ImageMagickJPG)) { using (IPixelCollection pixels = image.GetPixelsUnsafe()) { Pixel pixelA = new Pixel(0, 0, new QuantumType[] { Quantum.Max, 0, 0 }); Pixel pixelB = new Pixel(1, 0, new QuantumType[] { 0, 0, Quantum.Max }); pixels.SetPixel(new Pixel[] { pixelA, pixelB }); ColorAssert.AreEqual(MagickColors.Red, image, 0, 0); ColorAssert.AreEqual(MagickColors.Blue, image, 1, 0); } } }
public void ShouldUseWriteMask() { using (IMagickImage image = new MagickImage(MagickColors.Black, 2, 1)) { using (IMagickImage mask = new MagickImage(MagickColors.White, 2, 1)) { using (IPixelCollection pixels = mask.GetPixelsUnsafe()) { pixels.SetPixel(0, 0, new QuantumType[] { 0, 0, 0 }); } image.SetWriteMask(mask); image.Evaluate(Channels.Red, EvaluateOperator.Set, Quantum.Max); ColorAssert.AreEqual(MagickColors.Red, image, 0, 0); ColorAssert.AreEqual(MagickColors.Black, image, 1, 0); } } }
private static void RemoveDots(string zValue, Dictionary<string, int[]> box, List<string> laserImages) { byte[] pixelValue = BitConverter.GetBytes(0); foreach (string laserImage in laserImages) { if (GetImageZValue(laserImage) == zValue) { HelixImage image = new HelixImage(laserImage); IPixelCollection<byte> pixels = image.Magick.GetPixels(); for (int x = box["bl"][0]; x <= box["tr"][0]; x++) { for (int y = box["tr"][1]; y <= box["bl"][1]; y++) { pixels.SetPixel(x, y, pixelValue); } } image.SaveImage(true); image.Magick.Dispose(); pixels.Dispose(); } } }
public void Draw(MagickImage map) { MainForm.ProgressStart("Rendering water ..."); using (IPixelCollection heightmapPixels = zoneConfiguration.Heightmap.HeightmapScaled.GetPixels()) { using (MagickImage water = new MagickImage(MagickColors.Transparent, zoneConfiguration.TargetMapSize, zoneConfiguration.TargetMapSize)) { int progressCounter = 0; foreach (WaterConfiguration river in m_waterAreas) { MainForm.Log(river.Name + "...", MainForm.LogLevel.notice); MagickColor fillColor; if (m_useClientColors) { fillColor = river.Color; } else { fillColor = m_waterColor; } //water.FillColor = fillColor; // Get the river coordinates and scale them to the targets size List <PointD> riverCoordinates = river.GetCoordinates().Select(c => new PointD(c.X * zoneConfiguration.MapScale, c.Y * zoneConfiguration.MapScale)).ToList(); // Texture using (MagickImage texture = new MagickImage((river.Type.ToLower() == "lava") ? GetLavaTexture() : GetWateryTexture())) { using (MagickImage pattern = new MagickImage(fillColor, texture.Width, texture.Height)) { texture.Composite(pattern, 0, 0, CompositeOperator.DstIn); texture.Composite(pattern, 0, 0, CompositeOperator.ColorDodge); water.Settings.FillPattern = texture; DrawablePolygon poly = new DrawablePolygon(riverCoordinates); water.Draw(poly); } } // get the min/max and just process them int minX = Convert.ToInt32(riverCoordinates.Min(m => m.X)) - 10; int maxX = Convert.ToInt32(riverCoordinates.Max(m => m.X)) + 10; int minY = Convert.ToInt32(riverCoordinates.Min(m => m.Y)) - 10; int maxY = Convert.ToInt32(riverCoordinates.Max(m => m.Y)) + 10; using (IPixelCollection riverPixelCollection = water.GetPixels()) { for (int x = minX; x < maxX; x++) { if (x < 0) { continue; } if (x >= zoneConfiguration.TargetMapSize) { continue; } for (int y = minY; y < maxY; y++) { if (y < 0) { continue; } if (y >= zoneConfiguration.TargetMapSize) { continue; } ushort pixelHeight = heightmapPixels.GetPixel(x, y).GetChannel(0); if (pixelHeight > river.Height) { Pixel newPixel = new Pixel(x, y, new ushort[] { 0, 0, 0, ushort.MinValue }); riverPixelCollection.SetPixel(newPixel); } } } } if (debug) { DebugRiver(progressCounter, river, riverCoordinates); } int percent = 100 * progressCounter / m_waterAreas.Count(); MainForm.ProgressUpdate(percent); progressCounter++; } MainForm.ProgressStartMarquee("Merging..."); if (WaterTransparency != 0) { water.Alpha(AlphaOption.Set); double divideValue = 100.0 / (100.0 - WaterTransparency); water.Evaluate(Channels.Alpha, EvaluateOperator.Divide, divideValue); } water.Blur(); map.Composite(water, 0, 0, CompositeOperator.SrcOver); } } MainForm.ProgressReset(); }