-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f0b279
commit a4cc89b
Showing
10 changed files
with
458 additions
and
222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Drawing; | ||
using System.Drawing.Imaging; | ||
|
||
namespace MagicPaint | ||
{ | ||
// Thanks to: http://www.vcskicks.com/fast-image-processing2.php | ||
unsafe public class FastBitmap | ||
{ | ||
private struct PixelData | ||
{ | ||
public byte blue; | ||
public byte green; | ||
public byte red; | ||
public byte alpha; | ||
|
||
public override string ToString() | ||
{ | ||
return "(" + alpha.ToString() + ", " + red.ToString() + ", " + green.ToString() + ", " + blue.ToString() + ")"; | ||
} | ||
} | ||
|
||
private Bitmap workingBitmap = null; | ||
private int width = 0; | ||
private BitmapData bitmapData = null; | ||
private Byte* pBase = null; | ||
|
||
public FastBitmap(Bitmap inputBitmap) | ||
{ | ||
workingBitmap = inputBitmap; | ||
} | ||
|
||
public void LockImage() | ||
{ | ||
Rectangle bounds = new Rectangle(Point.Empty, workingBitmap.Size); | ||
|
||
width = (int)(bounds.Width * sizeof(PixelData)); | ||
if (width % 4 != 0) width = 4 * (width / 4 + 1); | ||
|
||
//Lock Image | ||
bitmapData = workingBitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); | ||
pBase = (Byte*)bitmapData.Scan0.ToPointer(); | ||
} | ||
|
||
private PixelData* pixelData = null; | ||
|
||
public Color GetPixel(int x, int y) | ||
{ | ||
pixelData = (PixelData*)(pBase + y * width + x * sizeof(PixelData)); | ||
return Color.FromArgb(pixelData->alpha, pixelData->red, pixelData->green, pixelData->blue); | ||
} | ||
|
||
public Color GetPixelNext() | ||
{ | ||
pixelData++; | ||
return Color.FromArgb(pixelData->alpha, pixelData->red, pixelData->green, pixelData->blue); | ||
} | ||
|
||
public void SetPixel(int x, int y, Color color) | ||
{ | ||
PixelData* data = (PixelData*)(pBase + y * width + x * sizeof(PixelData)); | ||
data->alpha = color.A; | ||
data->red = color.R; | ||
data->green = color.G; | ||
data->blue = color.B; | ||
} | ||
|
||
public void UnlockImage() | ||
{ | ||
workingBitmap.UnlockBits(bitmapData); | ||
bitmapData = null; | ||
pBase = null; | ||
} | ||
} | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.