Exemple #1
0
        public static Color GetPixel(int x, int y, CustomImage fromim)
        {
            if (x >= fromim.Width || y >= fromim.Height)
            {
                return(new Color());
            }

            int rx = 0, gx = 0, bx = 0;

            GetPixelIndex(x, y, ref rx, ref gx, ref bx, fromim);
            return(Color.FromArgb(fromim.Array[rx], fromim.Array[gx], fromim.Array[bx]));
        }
Exemple #2
0
        private void SetPixel(int x, int y, Color newc, CustomImage to)
        {
            if (x >= to.Width || y >= to.Height)
            {
                return;
            }

            int rx = 0, gx = 0, bx = 0;

            GetPixelIndex(x, y, ref rx, ref gx, ref bx, to);
            to.Array[rx] = newc.R;
            to.Array[gx] = newc.G;
            to.Array[bx] = newc.B;
        }
		private void refreshimage()
		{
			histimage.BackgroundImage = null;
			var count = 0;
			if (redCB.Checked)
				count++;
			if (greenCB.Checked)
				count++;
			if (blueCB.Checked)
				count++;
			if (count == 0)
				return;
			
			width = 256 * count;
			var bit = new Bitmap(width, 256);
			bucket = new int[width];
			
			//image stuff here
			Calculations.SetImageLocations();
			//calculations.ImageLocations[]
			var i = baseform.ImagePanels[imageindex];
			//ICL i=
			var newim = new CustomImage(i);
			
			var max = 0;
			var maxval = 255*3;
			for (var x = 0; x < i.I.Width; x++) for (var y = 0; y < i.I.Height; y++)
				{
					var from = Calculations.GetPixel(x, y, newim);
					var col = 0;
					if (redCB.Checked)
						col += from.R;
					if (greenCB.Checked)
						col += from.G;
					if (blueCB.Checked)
						col += from.B;
					
				if ((col == maxval&&ignorePureWhiteToolStripMenuItem.Checked)||
						col==0&&ignorePureBlackToolStripMenuItem.Checked)
						continue;

					bucket[col]++;
				}

			for (var x = 0; x < width; x++)
			{
				if (bucket[x] > max)
					max = bucket[x];
			}

			if (max==0)
			{
				MessageBox.Show("Warning, image maybe entirely black and white, and the options may be removing them.");
				return;
			}

			for (var x = 0; x < width; x++)
			{
				bucket[x] = ((int)(((float)bucket[x]) / ((float)max) * 255.0));
			}

			for (var x = 0; x < width; x++)
			{
				var c = bucket[x];
				var j = (int)(((float)x / (float)width) * 255);
				
				var r = 0;
				if (redCB.Checked)
					r = j;

				var g = 0;
				if (greenCB.Checked)
					g = j;

				var b = 0;
				if (blueCB.Checked)
					b = j;

				for (var y = 0; y < c; y++)
				{
					bit.SetPixel(x, y, Color.FromArgb(r, g, b));
				}
			}

			//load to screen
			Image im = bit;
			im.RotateFlip(RotateFlipType.Rotate180FlipX);
			histimage.BackgroundImage = im;
			histimage.BackgroundImageLayout = ImageLayout.Stretch;
		}
Exemple #4
0
        private void ApplyFormula()
        {
            if (Calculations.Threadfincount > 0)
            {
                MessageBox.Show("already performing an operation");
                return;
            }

            if (Formulas.Count == 0)
            {
                MessageBox.Show("no formulas are loaded");
                return;
            }

            //trim formulas
            TrimFormulas();

            //sanity checks
            var error = Calculations.FormulaChecks(Formulas, ImagePanels);

            if (string.IsNullOrEmpty(error) == false)
            {
                MessageBox.Show(error, "Formula Error!");
                return;
            }

            var imlist = new Dictionary <int, CustomImage>();

            int maxw = 0, maxh = 0;
            var az = 0;
            var pf = PixelFormat.DontCare;

            foreach (var ic in ImagePanels)
            {
                var newim = new CustomImage(ic.Value);
                if (newim.Width > maxw)
                {
                    maxw = newim.Width;
                }
                if (newim.Height > maxh)
                {
                    maxh = newim.Height;
                }
                pf = newim.Format;
                imlist.Add(az, newim);
                az++;
            }

            if (maxw == 0 || maxh == 0)
            {
                MessageBox.Show("The current formula requires more images to be loaded");
                return;
            }

            var outputBitmap     = new Bitmap(maxw, maxh, pf);
            var outputBitmapData = outputBitmap.LockBits(new Rectangle(0, 0, maxw, maxh), ImageLockMode.ReadOnly, outputBitmap.PixelFormat);

            var bys          = Math.Abs(outputBitmapData.Stride) * outputBitmap.Height;
            var outputvalues = new byte[bys];

            //var time = DateTime.Now;
            var pixelsto = new CustomImage
            {
                Array  = outputvalues,
                Format = outputBitmapData.PixelFormat,
                Height = outputBitmap.Height,
                Width  = outputBitmap.Width,
                Scan0  = outputBitmapData.Scan0,
                Stride = outputBitmapData.Stride
            };

            var i = new Information {
                imlist = imlist, pixelsTo = pixelsto, maxw = maxw, maxh = maxh
            };

            Calculations.Initcalculations(Formulas, ref i);

            //get the custom matricies
            if (Calculations.GetCustomMatricies(Formulas) == false)
            {
                return;
            }

            //link the variables to their array
            Calculations.SetImageLocations();

            //get max pass count
            var passcount = GetLargestNumber(Calculations.Passoperation, "", 0);

            //if there is no pass, then we just want 1
            if (passcount == -1)
            {
                passcount = 1;
            }

            //set this form
            Calculations.Baseform = this;

            //create threads
            int threads;

            int.TryParse(threadCB.Text, out threads);
            //make sure there arent more threads than width
            if (threads > maxw)
            {
                threads = maxw;
            }
            var pixeldistance = maxw / threads;

            //for each pass
            progressbar.Value   = 0;
            progressbar.Maximum = threads * passcount;

            for (var pass = 1; pass <= passcount; pass++)
            {
                //set the pass number
                Calculations.Thispassnumber = pass;
                var dist = 0;
                for (var a = 0; a < threads; a++)
                {
                    var ti = new ThreadInfo(dist, dist + pixeldistance, 0, maxh);

                    var t = new Thread(Calculations.ApplyMain);
                    dist += pixeldistance;
                    t.Start(ti);
                }

                var events = 0;
                while (Calculations.Threadfincount < threads)
                {
                    Thread.Sleep(100);
                    events++;
                    if (events >= 10)
                    {
                        events = 0;
                        Application.DoEvents();
                    }
                }
                Calculations.Threadfincount = 0;
            }

            Marshal.Copy(outputvalues, 0, outputBitmapData.Scan0, bys);
            outputBitmap.UnlockBits(outputBitmapData);

            Image ni = outputBitmap;

            LoadImageIntoTabPage("", ni);

            progressbar.Value = 0;

            //DateTime time2 = DateTime.Now;
            //var ts = time2 - time;
            //MessageBox.Show("seconds:" + TS.TotalSeconds);
            if (showPopupWhenAlgorithmsCompleteToolStripMenuItem.Checked)
            {
                ShowBalloon();
            }
        }
        private void SetPixel(int x, int y, Color newc, CustomImage to)
        {
            if (x >= to.Width || y >= to.Height)
                return;

            int rx = 0, gx = 0, bx = 0;
            GetPixelIndex(x, y, ref rx, ref gx, ref bx,to);
            to.Array[rx] = newc.R;
            to.Array[gx] = newc.G;
            to.Array[bx] = newc.B;
        }
 private static void GetPixelIndex(int x, int y, ref int rx, ref int gx, ref int bx,CustomImage imt)
 {
     int x2;
     switch (imt.Format)
     {
         case PixelFormat.Format24bppRgb:
             x2 = (y * imt.Stride) + (x * 3);
             rx = x2 + 2;
             gx = x2 + 1;
             bx = x2;
             break;
         case PixelFormat.Format32bppArgb:
             x2 = (y * imt.Stride) + (x * 4);
             rx = x2 + 2;
             gx = x2 + 1;
             bx = x2;
             break;
     }
 }
        public static Color GetPixel(int x, int y, CustomImage fromim)
        {
            if (x >= fromim.Width || y >= fromim.Height)
                return new Color();

            int rx = 0, gx = 0, bx = 0;
            GetPixelIndex(x, y, ref rx, ref gx, ref bx, fromim);
            return Color.FromArgb(fromim.Array[rx], fromim.Array[gx], fromim.Array[bx]);
        }
        private void refreshimage()
        {
            histimage.BackgroundImage = null;
            var count = 0;
            if (redCB.Checked)
                count++;
            if (greenCB.Checked)
                count++;
            if (blueCB.Checked)
                count++;
            if (count == 0)
                return;

            width = 256 * count;
            var bit = new Bitmap(width, 256);
            bucket = new int[width];

            //image stuff here
            Calculations.SetImageLocations();
            //calculations.ImageLocations[]
            var i = baseform.ImagePanels[imageindex];
            //ICL i=
            var newim = new CustomImage(i);

            var max = 0;
            var maxval = 255*3;
            for (var x = 0; x < i.I.Width; x++) for (var y = 0; y < i.I.Height; y++)
                {
                    var from = Calculations.GetPixel(x, y, newim);
                    var col = 0;
                    if (redCB.Checked)
                        col += from.R;
                    if (greenCB.Checked)
                        col += from.G;
                    if (blueCB.Checked)
                        col += from.B;

                if ((col == maxval&&ignorePureWhiteToolStripMenuItem.Checked)||
                        col==0&&ignorePureBlackToolStripMenuItem.Checked)
                        continue;

                    bucket[col]++;
                }

            for (var x = 0; x < width; x++)
            {
                if (bucket[x] > max)
                    max = bucket[x];
            }

            if (max==0)
            {
                MessageBox.Show("Warning, image maybe entirely black and white, and the options may be removing them.");
                return;
            }

            for (var x = 0; x < width; x++)
            {
                bucket[x] = ((int)(((float)bucket[x]) / ((float)max) * 255.0));
            }

            for (var x = 0; x < width; x++)
            {
                var c = bucket[x];
                var j = (int)(((float)x / (float)width) * 255);

                var r = 0;
                if (redCB.Checked)
                    r = j;

                var g = 0;
                if (greenCB.Checked)
                    g = j;

                var b = 0;
                if (blueCB.Checked)
                    b = j;

                for (var y = 0; y < c; y++)
                {
                    bit.SetPixel(x, y, Color.FromArgb(r, g, b));
                }
            }

            //load to screen
            Image im = bit;
            im.RotateFlip(RotateFlipType.Rotate180FlipX);
            histimage.BackgroundImage = im;
            histimage.BackgroundImageLayout = ImageLayout.Stretch;
        }
Exemple #9
0
        private static void GetPixelIndex(int x, int y, ref int rx, ref int gx, ref int bx, CustomImage imt)
        {
            int x2;

            switch (imt.Format)
            {
            case PixelFormat.Format24bppRgb:
                x2 = (y * imt.Stride) + (x * 3);
                rx = x2 + 2;
                gx = x2 + 1;
                bx = x2;
                break;

            case PixelFormat.Format32bppArgb:
                x2 = (y * imt.Stride) + (x * 4);
                rx = x2 + 2;
                gx = x2 + 1;
                bx = x2;
                break;
            }
        }
Exemple #10
0
        private void ApplyFormula()
        {
            if (Calculations.Threadfincount > 0)
            {
                MessageBox.Show("already performing an operation");
                return;
            }

            if (Formulas.Count == 0)
            {
                MessageBox.Show("no formulas are loaded");
                return;
            }

            //trim formulas
            TrimFormulas();

            //sanity checks
            var error = Calculations.FormulaChecks(Formulas, ImagePanels);
            if (string.IsNullOrEmpty(error) == false)
            {
                MessageBox.Show(error, "Formula Error!");
                return;
            }

            var imlist = new Dictionary<int, CustomImage>();

            int maxw = 0, maxh = 0;
            var az = 0;
            var pf = PixelFormat.DontCare;
            foreach (var ic in ImagePanels)
            {
                var newim = new CustomImage(ic.Value);
                if (newim.Width > maxw)
                    maxw = newim.Width;
                if (newim.Height > maxh)
                    maxh = newim.Height;
                pf = newim.Format;
                imlist.Add(az, newim);
                az++;
            }

            if (maxw == 0 || maxh == 0)
            {
                MessageBox.Show("The current formula requires more images to be loaded");
                return;
            }

            var outputBitmap = new Bitmap(maxw, maxh, pf);
            var outputBitmapData = outputBitmap.LockBits(new Rectangle(0, 0, maxw, maxh), ImageLockMode.ReadOnly, outputBitmap.PixelFormat);

            var bys = Math.Abs(outputBitmapData.Stride) * outputBitmap.Height;
            var outputvalues = new byte[bys];

            //var time = DateTime.Now;
            var pixelsto = new CustomImage
            {
                Array = outputvalues,
                Format = outputBitmapData.PixelFormat,
                Height = outputBitmap.Height,
                Width = outputBitmap.Width,
                Scan0 = outputBitmapData.Scan0,
                Stride = outputBitmapData.Stride
            };

            var i = new Information { imlist = imlist, pixelsTo = pixelsto, maxw = maxw, maxh = maxh };

            Calculations.Initcalculations(Formulas, ref i);

            //get the custom matricies
            if (Calculations.GetCustomMatricies(Formulas) == false)
                return;

            //link the variables to their array
            Calculations.SetImageLocations();

            //get max pass count
            var passcount = GetLargestNumber(Calculations.Passoperation, "", 0);
            //if there is no pass, then we just want 1
            if (passcount == -1)
                passcount = 1;

            //set this form
            Calculations.Baseform = this;

            //create threads
            int threads;
            int.TryParse(threadCB.Text, out threads);
            //make sure there arent more threads than width
            if (threads > maxw)
                threads = maxw;
            var pixeldistance = maxw / threads;

            //for each pass
            progressbar.Value = 0;
            progressbar.Maximum = threads * passcount;

            for (var pass = 1; pass <= passcount; pass++)
            {
                //set the pass number
                Calculations.Thispassnumber = pass;
                var dist = 0;
                for (var a = 0; a < threads; a++)
                {
                    var ti = new ThreadInfo(dist, dist + pixeldistance, 0, maxh);

                    var t = new Thread(Calculations.ApplyMain);
                    dist += pixeldistance;
                    t.Start(ti);
                }

                var events = 0;
                while (Calculations.Threadfincount < threads)
                {
                    Thread.Sleep(100);
                    events++;
                    if (events >= 10)
                    {
                        events = 0;
                        Application.DoEvents();
                    }
                }
                Calculations.Threadfincount = 0;
            }

            Marshal.Copy(outputvalues, 0, outputBitmapData.Scan0, bys);
            outputBitmap.UnlockBits(outputBitmapData);

            Image ni = outputBitmap;

            LoadImageIntoTabPage("", ni);

            progressbar.Value = 0;

            //DateTime time2 = DateTime.Now;
            //var ts = time2 - time;
            //MessageBox.Show("seconds:" + TS.TotalSeconds);
            if (showPopupWhenAlgorithmsCompleteToolStripMenuItem.Checked)
            {
                ShowBalloon();
            }
        }