protected override void CustomRenderSingleScanLine(IBitmapBlender destImage, Scanline scanline, Color color) { int y = scanline.Y; int num_spans = scanline.SpanCount; byte[] covers = scanline.GetCovers(); int spanCount = scanline.SpanCount; var ras = _gfx.ScanlineRasterizer; var rasToBmp = _gfx.BitmapRasterizer; for (int i = 1; i <= num_spans; ++i) { var span2 = scanline.GetSpan(i); int x = span2.x; int num_pix = span2.len; int coverIndex = span2.cover_index; do { int a = (covers[coverIndex++] * color.Alpha0To255) >> 8; _square.Draw(rasToBmp, ras, _sl, destImage, Color.FromArgb(a, color), x, y); ++x; }while (--num_pix > 0); } }
private static Scanline[] GetRegionScanlines(Rectangle[] region) { int num = 0; for (int i = 0; i < region.Length; i++) { num += region[i].Height; } if (num == 0) { return(Array.Empty <Scanline>()); } Scanline[] scanlineArray = new Scanline[num]; int index = 0; foreach (Rectangle rectangle in region) { for (int j = 0; j < rectangle.Height; j++) { scanlineArray[index] = new Scanline(rectangle.X, rectangle.Y + j, rectangle.Width); index++; } } return(scanlineArray); }
public void Initialize(Scan scanRef, Scanline scanlineRef, HoldNote holdNote) { this.scanlineRef = scanlineRef; noteType = holdNote.type; float startX = GetComponent <RectTransform>() .anchoredPosition.x; float endX = scanRef.FloatPulseToXPosition( holdNote.pulse + holdNote.duration, positionEndOfScanOutOfBounds: false, positionAfterScanOutOfBounds: true); trailExtendsLeft = endX < startX; durationTrailInitialWidth = Mathf.Abs(startX - endX); durationTrail.sizeDelta = new Vector2( durationTrailInitialWidth, durationTrail.sizeDelta.y); if (trailExtendsLeft) { durationTrail.localRotation = Quaternion.Euler(0f, 0f, 180f); if (ongoingTrail != null) { ongoingTrail.localRotation = Quaternion.Euler(0f, 0f, 180f); } } if (ongoingTrail != null) { ongoingTrail.sizeDelta = new Vector2(0f, ongoingTrail.sizeDelta.y); } }
private static Scanline[] GetRegionScanlines(Rectangle[] region) { int scanCount = 0; for (int i = 0; i < region.Length; ++i) { scanCount += region[i].Height; } if (scanCount == 0) { return(Array.Empty <Scanline>()); } Scanline[] scans = new Scanline[scanCount]; int scanIndex = 0; foreach (Rectangle rect in region) { for (int y = 0; y < rect.Height; ++y) { scans[scanIndex] = new Scanline(rect.X, rect.Y + y, rect.Width); ++scanIndex; } } return(scans); }
public virtual void EmptyMap() { lines = new Scanline[Lightmap.BaseHeight]; for ( int i=0; i<Lightmap.BaseHeight; ++i ) { lines[i] = new Scanline( ZeroID ); } }
/** * Outputs displayable image of image channel to be corrected. * @param layer the channel corrected * @return true if successful **/ private void outputDisplayableBase(int layer) { float[] array; int width = base_dimensions[0]; int height = base_dimensions[1]; float value, value16bpp; string image_name = (string)dropdown_imageLayer.Items[layer]; array = new float[width * height]; Array.Copy(base_data, width * height * layer, array, 0, width * height); FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; FREE_IMAGE_TYPE type = FREE_IMAGE_TYPE.FIT_FLOAT; FREE_IMAGE_SAVE_FLAGS save_flags = FREE_IMAGE_SAVE_FLAGS.TIFF_NONE; FreeImageBitmap image = new FreeImageBitmap(width, height, type); float maxValue = Enumerable.Range(0, array.Length).Max(m => array[m]); float minValue = Enumerable.Range(0, array.Length).Min(m => array[m]); for (int j = 0; j < height; ++j) { Scanline <float> scanline = image.GetScanline <float>(j); for (int k = 0; k < width; ++k) { value = array[width * j + k]; value16bpp = (1.0f / (maxValue - minValue) * (value - minValue)); scanline.SetValue(value16bpp, k); } } image.RotateFlip(base_orientation); image.Save("./Workspace/" + image_name + "_base_displayable.tiff", format, save_flags); }
/** * Outputs .tiff file to be read into Argo Solution as input parameter * @param layer the channel corrected * @return true if successful **/ private bool outputBase(int layer) { float[] array; int width = base_dimensions[0]; int height = base_dimensions[1]; float value; if (layer == -1) { return(false); } string image_name = (string)dropdown_imageLayer.Items[layer]; array = new float[width * height]; Array.Copy(base_data, width * height * layer, array, 0, width * height); FREE_IMAGE_FORMAT format = FREE_IMAGE_FORMAT.FIF_TIFF; FREE_IMAGE_TYPE type = FREE_IMAGE_TYPE.FIT_FLOAT; FREE_IMAGE_SAVE_FLAGS save_flags = FREE_IMAGE_SAVE_FLAGS.TIFF_NONE; FreeImageBitmap image = new FreeImageBitmap(width, height, type); for (int j = 0; j < height; ++j) { Scanline <float> scanline = image.GetScanline <float>(j); for (int k = 0; k < width; ++k) { value = array[width * j + k]; scanline.SetValue(value, k); } } image.RotateFlip(base_orientation); image.Save("./Workspace/" + image_name + "_base.tiff", format, save_flags); return(true); }
public static void EnableScanline(Material material, Scanline type) { for (int a = 0; a < SCANLINE.Length; ++a) { material.DisableKeyword(SCANLINE[a]); } material.EnableKeyword(SCANLINE[(int)type]); }
private void Start() { Scanline scanline = Camera.main.GetComponent <Scanline>(); if (scanline) { scanline.SetAlpha(alphaScan); } }
public void UnsafeSet(Scanline scan, bool newValue) { int x = scan.X; while (x < scan.X + scan.Length) { UnsafeSet(x, scan.Y, newValue); ++x; } }
public void UnsafeInvert(Scanline scan) { int x = scan.X; while (x < scan.X + scan.Length) { UnsafeInvert(x, scan.Y); ++x; } }
public void Example02() { dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); // Check whether loading succeeded if (dib.IsNull) { Console.WriteLine("Sample.jpg could not be loaded. Aborting."); return; } // Check whether the bitmap has 24 bpp color depth to ensure // using RGBTRIPPLE is correct. if (FreeImage.GetBPP(dib) != 24) { Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); FreeImage.UnloadEx(ref dib); return; } // Iterate over all scanlines for (int i = 0; i < FreeImage.GetHeight(dib); i++) { // Get scanline Scanline <RGBTRIPLE> scanline = new Scanline <RGBTRIPLE>(dib, i); // Get pixeldata from scanline RGBTRIPLE[] rgbt = scanline.Data; // Iterate over each pixel reducing the colors intensity to 3/4 which // will darken the bitmap. for (int j = 0; j < rgbt.Length; j++) { rgbt[j].rgbtBlue = (byte)((int)rgbt[j].rgbtBlue * 3 / 4); rgbt[j].rgbtGreen = (byte)((int)rgbt[j].rgbtGreen * 3 / 4); rgbt[j].rgbtRed = (byte)((int)rgbt[j].rgbtRed * 3 / 4); // In case no direct access to the data is implemented // the following way is equivalent: // // Color color = rgbt[j].color; // rgbt[j].color = Color.FromArgb(color.R * 3 / 4, color.G * 3 / 4, color.B * 3 / 4); } // Write the darkened scanline back to memory scanline.Data = rgbt; } // Store the bitmap to disk if (!FreeImage.SaveEx(ref dib, "SampleOut02.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) { Console.WriteLine("Error while saving 'SampleOut02.jpg'"); FreeImage.UnloadEx(ref dib); } }
private void Start() { Scanline scanline = Camera.main.GetComponent <Scanline>(); if (scanline) { scanline.SetAlpha(alphaScan); } AkSoundEngine.PostEvent("menu", gameObject); }
public override bool Equals(object obj) { if (obj is Scanline) { Scanline rhs = (Scanline)obj; return(x == rhs.x && y == rhs.y && length == rhs.length); } else { return(false); } }
public override bool Equals(object obj) { if (obj is Scanline) { Scanline rhs = (Scanline)obj; return(X == rhs.X && Y == rhs.Y && Length == rhs.Length); } else { return(false); } }
public void Example01() { // Load sample file dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); // Check whether loading succeeded if (dib.IsNull) { Console.WriteLine("Sample.jpg could not be loaded. Aborting."); return; } // Check whether the bitmap has 24 bpp color depth to ensure // using RGBTRIPPLE is correct. if (FreeImage.GetBPP(dib) != 24) { Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); FreeImage.UnloadEx(ref dib); return; } // Store height of the bitmap int height = (int)FreeImage.GetHeight(dib); // Iterate over half of the bitmaps scanlines and swap // line[1] with line[height], line[2] with line[height-1] etc which will // flip the image. for (int i = 0; i < (height / 2); i++) { // Get scanline from the bottom part of the bitmap Scanline <RGBTRIPLE> scanlineBottom = new Scanline <RGBTRIPLE>(dib, i); // Get scanline from the top part of the bitmap Scanline <RGBTRIPLE> scanlineTop = new Scanline <RGBTRIPLE>(dib, height - 1 - i); // Get arrays of RGBTRIPPLEs that contain the bitmaps real pixel data // of the two scanlines. RGBTRIPLE[] rgbtBottom = scanlineBottom.Data; RGBTRIPLE[] rgbtTop = scanlineTop.Data; // Restore the scanline across to switch the bitmaps lines. scanlineBottom.Data = rgbtTop; scanlineTop.Data = rgbtBottom; } // Store the bitmap to disk if (!FreeImage.SaveEx(ref dib, "SampleOut01.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) { Console.WriteLine("Error while saving 'SampleOut01.jpg'"); FreeImage.UnloadEx(ref dib); } }
public void Example01() { // Load sample file dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); // Check whether loading succeeded if (dib.IsNull) { Console.WriteLine("Sample.jpg could not be loaded. Aborting."); return; } // Check whether the bitmap has 24 bpp color depth to ensure // using RGBTRIPPLE is correct. if (FreeImage.GetBPP(dib) != 24) { Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); FreeImage.UnloadEx(ref dib); return; } // Store height of the bitmap int height = (int)FreeImage.GetHeight(dib); // Iterate over half of the bitmaps scanlines and swap // line[1] with line[height], line[2] with line[height-1] etc which will // flip the image. for (int i = 0; i < (height / 2); i++) { // Get scanline from the bottom part of the bitmap Scanline<RGBTRIPLE> scanlineBottom = new Scanline<RGBTRIPLE>(dib, i); // Get scanline from the top part of the bitmap Scanline<RGBTRIPLE> scanlineTop = new Scanline<RGBTRIPLE>(dib, height - 1 - i); // Get arrays of RGBTRIPPLEs that contain the bitmaps real pixel data // of the two scanlines. RGBTRIPLE[] rgbtBottom = scanlineBottom.Data; RGBTRIPLE[] rgbtTop = scanlineTop.Data; // Restore the scanline across to switch the bitmaps lines. scanlineBottom.Data = rgbtTop; scanlineTop.Data = rgbtBottom; } // Store the bitmap to disk if (!FreeImage.SaveEx(ref dib, "SampleOut01.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) { Console.WriteLine("Error while saving 'SampleOut01.jpg'"); FreeImage.UnloadEx(ref dib); } }
private static Rectangle[] ScanlinesToRectangles(Scanline[] scans, int startIndex, int length) { if (length == 0) { return(Array.Empty <Rectangle>()); } Rectangle[] rectangleArray = new Rectangle[length]; for (int i = 0; i < length; i++) { Scanline scanline = scans[i + startIndex]; rectangleArray[i] = new Rectangle(scanline.X, scanline.Y, scanline.Length, 1); } return(rectangleArray); }
public void Draw( ScanlineRasToDestBitmapRenderer sclineRasToBmp, ScanlineRasterizer ras, Scanline sl, IImageReaderWriter destImage, ColorRGBA color, double x, double y) { ras.Reset(); ras.MoveTo(x * m_size, y * m_size); ras.LineTo(x * m_size + m_size, y * m_size); ras.LineTo(x * m_size + m_size, y * m_size + m_size); ras.LineTo(x * m_size, y * m_size + m_size); sclineRasToBmp.RenderWithColor(destImage, ras, sl, color); }
public void Draw( DestBitmapRasterizer bmpRast, ScanlineRasterizer ras, Scanline sl, PixelProcessing.IBitmapBlender destImage, Color color, double x, double y) { ras.Reset(); ras.MoveTo(x * _size, y * _size); ras.LineTo(x * _size + _size, y * _size); ras.LineTo(x * _size + _size, y * _size + _size); ras.LineTo(x * _size, y * _size + _size); bmpRast.RenderWithColor(destImage, ras, sl, color); }
/// <summary> /// Calls <paramref name="plot"/> for points in the trapezoid spanned by two scanlines. /// The points with maximal X or Y coordinates are left out. /// </summary> public static void InterpolatePlot(PointPlotDelegate plot, Scanline scan1, Scanline scan2) { int divisor = scan2._y - scan1._y; if (divisor == 0) divisor = 1; int x1Step = scan2._x1 - scan1._x1; int x2Step = scan2._x2 - scan1._x2; for (var scanline = new Scanline { _y = scan1._y, _x1 = scan1._x1 * divisor, _x2 = scan1._x2 * divisor }; scanline._y < scan2._y; ++scanline._y, scanline._x1 += x1Step, scanline._x2 += x2Step) { int x1 = scanline._x1.DivRound(divisor); int x2 = scanline._x2.DivRound(divisor); for (int x = x1; x < x2; ++x) plot(x, scanline._y); } }
public static void RenderSolidAllPaths(this ScanlineRasToDestBitmapRenderer sclineRasToBmp, IImageReaderWriter destImage, ScanlineRasterizer sclineRas, Scanline scline, VertexStore vxs, Drawing.Color[] colors, int[] path_id, int num_paths) { for (int i = 0; i < num_paths; ++i) { sclineRas.Reset(); sclineRas.AddPath(new VertexStoreSnap(vxs, path_id[i])); sclineRasToBmp.RenderWithColor(destImage, sclineRas, scline, colors[i]); } }
public void ScaleZ(float scale) { // scale heights for (uint i = 0; i < FreeImage.GetHeight(dib); i++) { Scanline <ushort> line = new Scanline <ushort>(dib, (int)i); ushort[] data = line.Data; for (int k = 0; k < data.Length; k++) { ushort v = data[k]; ushort adj = (ushort)(v * scale); data[k] = adj; } line.Data = data; } }
public static Vector2 GetHeightRange(this FIBITMAP dib) { Vector2 range; range.X = ushort.MaxValue; range.Y = ushort.MinValue; for (uint y = 0; y < FreeImage.GetHeight(dib); y++) { Scanline <ushort> line = new Scanline <ushort>(dib, (int)y); for (int i = 0; i < line.Count; i++) { range.X = Math.Min(line[i], range.X); range.Y = Math.Max(line[i], range.Y); } } return(range); }
public void Draw( DestBitmapRasterizer bmpRast, ScanlineRasterizer ras, Scanline sl, PixelProcessing.IBitmapBlender destImage, Color color, double x, double y) { #if DEBUG //low-level scanline rasterizer example ras.Reset(); ras.dbugDevMoveTo(x * _size, y * _size); ras.dbugDevLineTo(x * _size + _size, y * _size); ras.dbugDevLineTo(x * _size + _size, y * _size + _size); ras.dbugDevLineTo(x * _size, y * _size + _size); bmpRast.RenderWithColor(destImage, ras, sl, color); #endif }
public void Initialize() { Game.ScanChanged += OnScanChanged; Game.ScanAboutToChange += OnScanAboutToChange; Rect rect = GetComponent <RectTransform>().rect; screenWidth = rect.width; scanHeight = rect.height; laneHeight = scanHeight * 0.25f; noteAppearances = new List <NoteAppearance>(); holdExtensions = new List <HoldExtension>(); repeatPathExtensions = new List <RepeatPathExtension>(); scanline = GetComponentInChildren <Scanline>(); scanline.scanNumber = scanNumber; scanline.Initialize(this, scanHeight); }
public static ushort GetHeight(this FIBITMAP dib, Vector2 p) { uint ImageHeight = FreeImage.GetHeight(dib); uint ImageWidth = FreeImage.GetWidth(dib); int scanline = (int)(ImageHeight - 1 - p.Y); if (scanline < 0 || scanline >= ImageHeight) { throw new Exception($"Invalid Y coordinate {p.Y}"); } if (p.X < 0 || p.X >= ImageWidth) { throw new Exception($"Invalid X coordinate {p.X}"); } Scanline <ushort> line = new Scanline <ushort>(dib, scanline); return(line.Data[(int)p.X]); }
public static List <Scanline> ScanlineList(List <Vector3> edge) { var list = new List <Scanline>(edge.Count); for (int i = 0; i < edge.Count; i += 2) { Vector3 line = edge[i]; Vector3 nextPoint = edge[i + 1]; //Debug.Log( "ScanlineList : " + TexEditor.FrameCount + " : " + line.y ); //Debug.Assert( line.y == nextPoint.y , "linex = " + line.y + "nextPointx = " + nextPoint.y); var scan = new Scanline() { X = (int)line.x, Y = (int)line.y, W = (int)nextPoint.x - (int)line.x, }; list.Add(scan); } return(list); }
public void GetScanline() { FreeImageBitmap fib; fib = new FreeImageBitmap(10, 10, PixelFormat.Format1bppIndexed); Scanline <FI1BIT> scanline1 = (Scanline <FI1BIT>)fib.GetScanline(0); fib.Dispose(); fib = new FreeImageBitmap(10, 10, PixelFormat.Format4bppIndexed); Scanline <FI4BIT> scanline2 = (Scanline <FI4BIT>)fib.GetScanline(0); fib.Dispose(); fib = new FreeImageBitmap(10, 10, PixelFormat.Format8bppIndexed); Scanline <Byte> scanline3 = (Scanline <Byte>)fib.GetScanline(0); fib.Dispose(); fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb555); Scanline <FI16RGB555> scanline4 = (Scanline <FI16RGB555>)fib.GetScanline(0); fib.Dispose(); fib = new FreeImageBitmap(10, 10, PixelFormat.Format16bppRgb565); Scanline <FI16RGB565> scanline5 = (Scanline <FI16RGB565>)fib.GetScanline(0); fib.Dispose(); fib = new FreeImageBitmap(10, 10, PixelFormat.Format24bppRgb); Scanline <RGBTRIPLE> scanline6 = (Scanline <RGBTRIPLE>)fib.GetScanline(0); fib.Dispose(); fib = new FreeImageBitmap(10, 10, PixelFormat.Format32bppArgb); Scanline <RGBQUAD> scanline7 = (Scanline <RGBQUAD>)fib.GetScanline(0); fib.Dispose(); }
public static void SetHeight(this FIBITMAP dib, Vector2 p, ushort height) { uint ImageHeight = FreeImage.GetHeight(dib); uint ImageWidth = FreeImage.GetWidth(dib); int scanline = (int)(ImageHeight - 1 - p.Y); if (scanline < 0 || scanline >= ImageHeight) { //throw new Exception($"Invalid Y coordinate {p.Y}"); return; } if (p.X < 0 || p.X >= ImageWidth) { //throw new Exception($"Invalid X coordinate {p.X}"); return; } Scanline <ushort> line = new Scanline <ushort>(dib, scanline); ushort[] pixels = line.Data; pixels[(int)p.X] = height; line.Data = pixels; }
public override void OnInitialize() { IPixelFormat screenPixelFormat; FormatClippingProxy screenClippingProxy; AntiAliasedScanlineRasterizer rasterizer = new AntiAliasedScanlineRasterizer(); Scanline scanlinePacked = new Scanline(); if (RenderBufferWindow.BitsPerPixel == 24) { screenPixelFormat = new FormatRGB(RenderBufferWindow, new BlenderBGR()); } else { screenPixelFormat = new FormatRGBA(RenderBufferWindow, new BlenderBGRA()); } screenClippingProxy = new FormatClippingProxy(screenPixelFormat); m_ScreenRenderer = new Renderer(screenClippingProxy, rasterizer, scanlinePacked); m_ScreenRenderer.Rasterizer.SetVectorClipBox(0, 0, Width, Height); base.OnInitialize(); }
public void FreeImage_GetUniqueColors() { Palette palette; // // 1bpp // dib = FreeImage.Allocate(10, 1, 1, 0, 0, 0); Assert.IsFalse(dib.IsNull); palette = new Palette(dib); palette[0] = Color.FromArgb(43, 255, 255, 255); palette[1] = Color.FromArgb(222, 0, 0, 0); Scanline<FI1BIT> sl1bit = new Scanline<FI1BIT>(dib, 0); for (int x = 0; x < sl1bit.Length; x++) { sl1bit[x] = 0; } Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); sl1bit[5] = 1; Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); palette[1] = Color.FromArgb(222, 255, 255, 255); Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); sl1bit[5] = 0; Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); FreeImage.UnloadEx(ref dib); // // 4bpp // dib = FreeImage.Allocate(10, 1, 4, 0, 0, 0); Assert.IsFalse(dib.IsNull); palette = new Palette(dib); palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255)); palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211)); palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52)); palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178)); palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199)); palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221)); Scanline<FI4BIT> sl4bit = new Scanline<FI4BIT>(dib, 0); for (int x = 0; x < sl4bit.Length; x++) { sl4bit[x] = 0; } Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); sl4bit[1] = 1; Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); sl4bit[2] = 1; Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); sl4bit[3] = 2; Assert.AreEqual(3, FreeImage.GetUniqueColors(dib)); sl4bit[4] = 3; Assert.AreEqual(4, FreeImage.GetUniqueColors(dib)); sl4bit[5] = 4; Assert.AreEqual(5, FreeImage.GetUniqueColors(dib)); sl4bit[6] = 5; Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); sl4bit[7] = 6; Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); sl4bit[8] = 7; Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); sl4bit[9] = 7; Assert.AreEqual(7, FreeImage.GetUniqueColors(dib)); FreeImage.UnloadEx(ref dib); // // 8bpp // dib = FreeImage.Allocate(10, 1, 8, 0, 0, 0); Assert.IsFalse(dib.IsNull); palette = new Palette(dib); palette[0] = new RGBQUAD(Color.FromArgb(43, 255, 255, 255)); palette[1] = new RGBQUAD(Color.FromArgb(222, 51, 2, 211)); palette[2] = new RGBQUAD(Color.FromArgb(29, 25, 31, 52)); palette[3] = new RGBQUAD(Color.FromArgb(173, 142, 61, 178)); palette[4] = new RGBQUAD(Color.FromArgb(143, 41, 67, 199)); palette[5] = new RGBQUAD(Color.FromArgb(2, 0, 2, 221)); Scanline<byte> sl8bit = new Scanline<byte>(dib, 0); for (int x = 0; x < sl8bit.Length; x++) { sl8bit[x] = 0; } Assert.AreEqual(1, FreeImage.GetUniqueColors(dib)); sl8bit[1] = 1; Assert.AreEqual(2, FreeImage.GetUniqueColors(dib)); sl8bit[2] = 2; Assert.AreEqual(3, FreeImage.GetUniqueColors(dib)); sl8bit[3] = 3; Assert.AreEqual(4, FreeImage.GetUniqueColors(dib)); sl8bit[4] = 4; Assert.AreEqual(5, FreeImage.GetUniqueColors(dib)); sl8bit[5] = 6; Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); sl8bit[5] = 7; Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); sl8bit[5] = 8; Assert.AreEqual(6, FreeImage.GetUniqueColors(dib)); FreeImage.UnloadEx(ref dib); }
private void FreeImage_ApplyColorMapping2(FIBITMAP dib) { Assert.IsFalse(dib.IsNull); Scanline<RGBQUAD> rgbqa = new Scanline<RGBQUAD>(dib, 0); RGBQUAD[] src = new RGBQUAD[1]; RGBQUAD[] dst = new RGBQUAD[1]; src[0] = rgbqa[0]; dst[0].Color = src[0].Color == Color.White ? Color.Thistle : Color.White; uint count = FreeImage.ApplyColorMapping(dib, src, dst, 1, true, false); // Memory Assert.That(count > 0); FreeImage.UnloadEx(ref dib); }
/// <summary> /// Includes X coordinates interpolated from the endpoints of two other scanlines /// at this scanline's Y coordinate. /// </summary> public void IncludeInterpolated(Scanline scan1, Scanline scan3) { Include((scan3._x1 * (_y - scan1._y) + scan1._x1 * (scan3._y - _y)).DivRound(scan3._y - scan1._y)); Include((scan3._x2 * (_y - scan1._y) + scan1._x2 * (scan3._y - _y)).DivRound(scan3._y - scan1._y)); }
public void Example02() { dib = FreeImage.LoadEx("Sample.jpg", FREE_IMAGE_LOAD_FLAGS.JPEG_ACCURATE); // Check whether loading succeeded if (dib.IsNull) { Console.WriteLine("Sample.jpg could not be loaded. Aborting."); return; } // Check whether the bitmap has 24 bpp color depth to ensure // using RGBTRIPPLE is correct. if (FreeImage.GetBPP(dib) != 24) { Console.WriteLine("Sample.jpg is no 24 bpp bitmap. Aborting."); FreeImage.UnloadEx(ref dib); return; } // Iterate over all scanlines for (int i = 0; i < FreeImage.GetHeight(dib); i++) { // Get scanline Scanline<RGBTRIPLE> scanline = new Scanline<RGBTRIPLE>(dib, i); // Get pixeldata from scanline RGBTRIPLE[] rgbt = scanline.Data; // Iterate over each pixel reducing the colors intensity to 3/4 which // will darken the bitmap. for (int j = 0; j < rgbt.Length; j++) { rgbt[j].rgbtBlue = (byte)((int)rgbt[j].rgbtBlue * 3 / 4); rgbt[j].rgbtGreen = (byte)((int)rgbt[j].rgbtGreen * 3 / 4); rgbt[j].rgbtRed = (byte)((int)rgbt[j].rgbtRed * 3 / 4); // In case no direct access to the data is implemented // the following way is equivalent: // // Color color = rgbt[j].color; // rgbt[j].color = Color.FromArgb(color.R * 3 / 4, color.G * 3 / 4, color.B * 3 / 4); } // Write the darkened scanline back to memory scanline.Data = rgbt; } // Store the bitmap to disk if (!FreeImage.SaveEx(ref dib, "SampleOut02.jpg", FREE_IMAGE_SAVE_FLAGS.JPEG_QUALITYGOOD, true)) { Console.WriteLine("Error while saving 'SampleOut02.jpg'"); FreeImage.UnloadEx(ref dib); } }
private static unsafe Scanline<FI4BIT>[] Get04BitScanlines(FIBITMAP dib) { int height = (int)GetHeight(dib); Scanline<FI4BIT>[] array = new Scanline<FI4BIT>[height]; for (int i = 0; i < height; i++) { array[i] = new Scanline<FI4BIT>(dib, i); } return array; }
/// <summary> /// Calls <paramref name="plot"/> once for each integer point in a filled triangle. /// The points of the triangle that are maximal in X or Y coordinate are /// not plotted to allow plotting two triangles that share a side without /// the points of the two triangles overlapping each other. /// </summary> public static void FillTriangle(Point point1, Point point2, Point point3, PointPlotDelegate plot) { // Sort points by increasing Y if (point2.Y < point1.Y) Swap(ref point1, ref point2); if (point3.Y < point2.Y) { Swap(ref point2, ref point3); if (point2.Y < point1.Y) Swap(ref point1, ref point2); } // Find master scanlines var scan1 = new Scanline(point1.Y, point1.X); if (point2.Y == point1.Y) scan1.Include(point2.X); if (point3.Y == point1.Y) scan1.Include(point3.X); var scan2 = scan1; if (point2.Y > scan1.Y) { scan2 = new Scanline(point2.Y, point2.X); if (point3.Y == point2.Y) scan2.Include(point3.X); } else if (point3.Y > scan1.Y) { scan2 = new Scanline(point3.Y, point3.X); } var scan3 = scan2; if (point3.Y > scan2.Y) { scan3 = new Scanline(point3.Y, point3.X); scan2.IncludeInterpolated(scan3, scan1); } // Loop through Y, interpolating between master scanlines Scanline.InterpolatePlot(plot, scan1, scan2); Scanline.InterpolatePlot(plot, scan2, scan3); }
public void Initialize() { //---------------------------------------------------------------- // グラフィックス設定 GraphicsSettings = LoadAsset <GraphicsSettings>("title:Resources/GraphicsSettings.json"); //---------------------------------------------------------------- // シーン設定 // TODO: ワールド設定としてどうするか再検討。 // いずれにせよ、SceneSettings はワールド設定と一対一。 SceneSettings = LoadAsset <SceneSettings>("title:Resources/SceneSettings.json"); //---------------------------------------------------------------- // シーン マネージャ設定 // TODO: リソースから取得する。 SceneManagerSettings = new SceneManager.Settings(); //---------------------------------------------------------------- // シーン マネージャ SceneManager = new SceneManager(SceneManagerSettings, GraphicsDevice); // 太陽と月をディレクショナル ライトとして登録。 SceneManager.DirectionalLights.Add(SceneSettings.Sunlight); SceneManager.DirectionalLights.Add(SceneSettings.Moonlight); // シャドウ マップ if (GraphicsSettings.ShadowMapEnabled) { var shadowMapEffect = LoadAsset <Effect>("content:Effects/ShadowMap"); var blurEffect = LoadAsset <Effect>("content:Effects/GaussianBlur"); ShadowMap = new ShadowMap(GraphicsDevice, GraphicsSettings.ShadowMap, spriteBatch, shadowMapEffect, blurEffect); SceneManager.ShadowMap = ShadowMap; } // レンズ フレア if (GraphicsSettings.LensFlareEnabled) { var glowSpite = LoadAsset <Texture2D>("content:Textures/LensFlare/Glow"); Texture2D[] flareSprites = { LoadAsset <Texture2D>("content:Textures/LensFlare/Flare1"), LoadAsset <Texture2D>("content:Textures/LensFlare/Flare2"), LoadAsset <Texture2D>("content:Textures/LensFlare/Flare3") }; LensFlare = new LensFlare(GraphicsDevice, spriteBatch, glowSpite, flareSprites); SceneManager.LensFlare = LensFlare; } // スクリーン スペース シャドウ マッピング if (GraphicsSettings.SssmEnabled) { // スクリーン スペース シャドウ マッピング モジュール var shadowSceneEffect = LoadAsset <Effect>("content:Effects/ShadowScene"); var sssmEffect = LoadAsset <Effect>("content:Effects/Sssm"); var blurEffect = LoadAsset <Effect>("content:Effects/GaussianBlur"); Sssm = new Sssm(spriteBatch, GraphicsSettings.ShadowMap, GraphicsSettings.Sssm, shadowSceneEffect, sssmEffect, blurEffect); Sssm.ShadowColor = SceneSettings.ShadowColor; SceneManager.PostProcessors.Add(Sssm); // SSSM は直接的なシャドウ描画を回避しなければならないため明示。 SceneManager.SssmEnabled = true; } // スクリーン スペース アンビエント オクルージョン if (GraphicsSettings.SsaoEnabled) { var normalDepthMapEffect = LoadAsset <Effect>("content:Effects/NormalDepthMap"); var ssaoMapEffect = LoadAsset <Effect>("content:Effects/SsaoMap"); var blurEffect = LoadAsset <Effect>("content:Effects/SsaoMapBlur"); var ssaoEffect = LoadAsset <Effect>("content:Effects/Ssao"); var randomNormalMap = LoadAsset <Texture2D>("content:Textures/RandomNormal"); Ssao = new Ssao(spriteBatch, GraphicsSettings.Ssao, normalDepthMapEffect, ssaoMapEffect, blurEffect, ssaoEffect, randomNormalMap); SceneManager.PostProcessors.Add(Ssao); } // エッジ強調 if (GraphicsSettings.EdgeEnabled) { var normalDepthMapEffect = LoadAsset <Effect>("content:Effects/NormalDepthMap"); var edgeEffect = LoadAsset <Effect>("content:Effects/Edge"); Edge = new Edge(spriteBatch, GraphicsSettings.Edge, normalDepthMapEffect, edgeEffect); SceneManager.PostProcessors.Add(Edge); } // ブルーム if (GraphicsSettings.BloomEnabled) { var bloomExtractEffect = LoadAsset <Effect>("content:Effects/BloomExtract"); var bloomEffect = LoadAsset <Effect>("content:Effects/Bloom"); var blurEffect = LoadAsset <Effect>("content:Effects/GaussianBlur"); Bloom = new Bloom(spriteBatch, GraphicsSettings.Bloom, bloomExtractEffect, bloomEffect, blurEffect); SceneManager.PostProcessors.Add(Bloom); } // 被写界深度 if (GraphicsSettings.DofEnabled) { var depthMapEffect = LoadAsset <Effect>("content:Effects/DepthMap"); var dofEffect = LoadAsset <Effect>("content:Effects/Dof"); var blurEffect = LoadAsset <Effect>("content:Effects/GaussianBlur"); Dof = new Dof(spriteBatch, GraphicsSettings.Dof, depthMapEffect, dofEffect, blurEffect); SceneManager.PostProcessors.Add(Dof); } // カラー オーバラップ if (GraphicsSettings.ColorOverlapEnabled) { ColorOverlap = new ColorOverlap(spriteBatch); SceneManager.PostProcessors.Add(ColorOverlap); } // モノクローム if (GraphicsSettings.MonochromeEnabled) { var monochromeEffect = LoadAsset <Effect>("content:Effects/Monochrome"); Monochrome = new Monochrome(spriteBatch, monochromeEffect); SceneManager.PostProcessors.Add(Monochrome); } // 走査線 if (GraphicsSettings.ScanlineEnabled) { var effect = LoadAsset <Effect>("content:Effects/Scanline"); Scanline = new Scanline(spriteBatch, effect); SceneManager.PostProcessors.Add(Scanline); } //---------------------------------------------------------------- // リージョン マネージャ RegionManager = new RegionManager(serviceProvider, SceneManager); RegionManager.Initialize(SceneSettings); // イベント ハンドラ // シャドウ マップ更新にあわせて、リージョン マネージャで管理しているエフェクトを準備する。 SceneManager.ShadowMapUpdated += RegionManager.OnShadowMapUpdated; //---------------------------------------------------------------- // チャンク マネージャ var chunkSettings = LoadAsset <ChunkSettings>("title:Resources/ChunkSettings.json"); ChunkManager = new ChunkManager(chunkSettings, GraphicsDevice, RegionManager, SceneManager); //---------------------------------------------------------------- // デフォルト カメラ //camera.View.Position = new Vector3(0, 16 * 18, 0); defaultCamera.View.Position = new Vector3(0, 16 * 16, 0); //camera.View.Position = new Vector3(0, 16 * 3, 0); //camera.View.Position = new Vector3(0, 16 * 2, 0); //defaultCamera.Projection.Fov = MathHelper.ToRadians(90); defaultCamera.Projection.AspectRatio = GraphicsDevice.Viewport.AspectRatio; // 最大アクティブ範囲を超えない位置へ FarPlaneDistance を設定。 // パーティション (チャンク) のサイズを掛けておく。 var minChunkSize = Math.Min(chunkSettings.ChunkSize.X, chunkSettings.ChunkSize.Y); minChunkSize = Math.Min(minChunkSize, chunkSettings.ChunkSize.Z); defaultCamera.Projection.FarPlaneDistance = (chunkSettings.MaxActiveVolume - 1) * minChunkSize; // 念のためここで一度更新。 defaultCamera.Update(); // シーン マネージャへ登録してアクティブ化。 SceneManager.Cameras.Add(defaultCamera); SceneManager.ActiveCameraName = defaultCamera.Name; }
public void Apply(Surface surface, Scanline scan) { Apply(surface.GetPointAddress(scan.X, scan.Y), scan.Length); }
public void Example03() { dib = FreeImage.LoadEx("Sample.tif"); // Check whether loading succeeded if (dib.IsNull) { Console.WriteLine("Sample.tif could not be loaded. Aborting."); return; } // Check whether the bitmap has 4 bpp color depth to ensure // using FI4B is correct. if (FreeImage.GetBPP(dib) != 4) { Console.WriteLine("Sample.tif is no 4 bpp bitmap. Aborting."); FreeImage.UnloadEx(ref dib); return; } // Get the bitmaps palette Palette palette = FreeImage.GetPaletteEx(dib); int size = (int)palette.Length; // Check whether the palette has a color (is valid) if (size == 0) { Console.WriteLine("Sample.tif has no valid palette. Aborting."); FreeImage.UnloadEx(ref dib); return; } // Swapping the palette for (int i = 0; i < size / 2; i++) { RGBQUAD temp = palette[i]; palette[i] = palette[size - 1 - i]; palette[size - 1 - i] = temp; } // Iterate over each scanline for (int i = 0; i < FreeImage.GetHeight(dib); i++) { // Get scanline Scanline<FI4BIT> scanline = new Scanline<FI4BIT>(dib, i); // Iterate over all pixels swapping the palette index // so that the color will stay the same for (int j = 0; j < scanline.Length; j++) { scanline[j] = (byte)(size - 1 - scanline[j]); } } // Save the bitmap to disk if (!FreeImage.SaveEx(ref dib, "SampleOut03.tif", FREE_IMAGE_SAVE_FLAGS.TIFF_LZW, true)) { Console.WriteLine("Error while saving 'SampleOut03.tif'"); FreeImage.UnloadEx(ref dib); } }