Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FastNoise Lite: PreviewApp #39

Merged
merged 4 commits into from
Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions PreviewApp/FastBitmap.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Adapted from https://stackoverflow.com/a/34801225
// This fixes the SetPixel speed issue.
using System;
using Eto.Drawing;

public class FastBitmap
{
public Int32[] Bits { get; private set; }
public int Height { get; private set; }
public int Width { get; private set; }

public FastBitmap(int width, int height)
{
Width = width;
Height = height;
Bits = new Int32[width * height];
}

public void SetPixel(int x, int y, Color colour)
{
int index = x + (y * Width);
int col = colour.ToArgb();

Bits[index] = col;
}

public Color GetPixel(int x, int y)
{
int index = x + (y * Width);
int col = Bits[index];
Color result = Color.FromArgb(col);

return result;
}

public Bitmap CreateBitmap() {
return new Bitmap(Width, Height, PixelFormat.Format32bppRgba, Bits);
}
}
13 changes: 13 additions & 0 deletions PreviewApp/FastNoiseLite.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Eto.Forms" Version="2.5.2"/>
<PackageReference Include="Eto.Platform.Wpf" Version="2.5.2"/>
</ItemGroup>
<ItemGroup>
<!--<Compile Include="..\CSharp\FastNoise.cs" Link="FastNoise.cs" />-->
</ItemGroup>
</Project>
Loading