public object ReplaceColoursWithPatterns(object p, BackgroundWorker w, DoWorkEventArgs e)
{
if (mPatterns == null) { e.Cancel = true; return this; }
int pScale = PatternEditor.PATTERN_WIDTH;
Bitmap orig = mOutput;
Bitmap b = new Bitmap(orig.Width * pScale, orig.Height * pScale, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(b);
//AdriansLib.ProgressBarForm prog = new AdriansLib.ProgressBarForm("Replacing Colours With Patterns...", orig.Width * orig.Height);
//prog.Show();
int co = 0;
for (int x = 0; x < orig.Width; x++)
for (int y = 0; y < orig.Height; y++)
{
if (w.CancellationPending) { e.Cancel = true; return this; }
Color c = orig.GetPixel(x, y);
Bitmap i = mPatterns[c];
g.DrawImage(i, x * pScale, y * pScale);
if (x % 5 == 0)
g.DrawLine(Pens.Gray, x * pScale - 1, y * pScale - 1, (x) * pScale - 1, (y + 1) * pScale - 1);
if (y % 5 == 0)
g.DrawLine(Pens.Gray, x * pScale - 1, y * pScale - 1, (x + 1) * pScale - 1, (y) * pScale - 1);
w.ReportProgress((co++) * 100 / (b.Width * b.Height));
}
g.Dispose();
mOutput = b;
return this;
}