System.Windows.Forms.ImageListStreamer.Get1bppMask C# (CSharp) Method

Get1bppMask() private method

private Get1bppMask ( Bitmap main ) : Bitmap
main Bitmap
return Bitmap
		unsafe Bitmap Get1bppMask (Bitmap main)
		{
			Rectangle rect = new Rectangle (0, 0, main.Width, main.Height);
			Bitmap result = new Bitmap (main.Width, main.Height, PixelFormat.Format1bppIndexed);
			BitmapData dresult = result.LockBits (rect, ImageLockMode.ReadWrite, PixelFormat.Format1bppIndexed);

			int w = images [0].Width;
			int h = images [0].Height;
			byte *scan = (byte *) dresult.Scan0.ToPointer ();
			int stride = dresult.Stride;
			Bitmap current = null;
			for (int idx = 0; idx < images.Length; idx++) {
				current = (Bitmap) images [idx];
				// Hack for newly added images.
				// Probably has to be done somewhere else.
				Color c1 = current.GetPixel (0, 0);
				if (c1.A != 0 && c1 == back_color)
					current.MakeTransparent (back_color);
				//
			}

			int yidx = 0;
			int imgidx = 0;
			int localy = 0;
			int localx = 0;
			int factor_y = 0;
			int factor_x = 0;
			for (int y = 0; y < main.Height; y++) {
				if (localy == h) {
					localy = 0;
					factor_y += 4;
				}
				factor_x = 0;
				localx = 0;
				for (int x = 0; x < main.Width; x++) {
					if (localx == w) {
						localx = 0;
						factor_x++;
					}
					imgidx = factor_y + factor_x;
					if (imgidx >= images.Length)
						break;
					current = (Bitmap) images [imgidx];
					Color color = current.GetPixel (localx, localy);
					if (color.A == 0) {
						int ptridx = yidx + (x >> 3);
						scan [ptridx] |= (byte) (0x80 >> (x & 7));
					}
					localx++;
				}
				if (imgidx >= images.Length)
					break;
				yidx += stride;
				localy++;
			}
			result.UnlockBits (dresult);

			return result;
		}