/// <summary> /// Turns the lines into a BlockLine /// </summary> private unsafe BlockLine GetBlockLine(byte *[] lines, LockBitsData data) { BlockLine blockLine = new BlockLine(_pData.Columns, LineFillMode.Default); // Advance one block width at a time int step = _elementWidth * data.BytesPerPixel; for (int offset = 0; offset < data.WidthInBytes; offset += step) { blockLine.Add(GetPixels(lines, offset, step, data.BytesPerPixel)); } return(blockLine); }
/// <summary> /// Locks the bitmap into memory and calls the EditAction /// </summary> public static void EditBitmap(Bitmap bmp, EditAction action) { if (bmp == null) { throw new ArgumentNullException("bmp"); } if (action == null) { throw new ArgumentNullException("action"); } Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height); PixelFormat format = bmp.PixelFormat; BitmapData bmpData = bmp.LockBits(rect, ImageLockMode.ReadWrite, format); LockBitsData data = new LockBitsData(bmpData, format); action(data); bmp.UnlockBits(bmpData); }
/// <summary> /// Gets the pixel colors from a bitmap /// </summary> private unsafe void GetPixelColors(LockBitsData data) { byte *ptr = (byte *)data.Scan0; for (int y = 0; y < data.HeightInPixels; y++) { byte *line = ptr + y * data.Stride; for (int x = 0; x < data.WidthInBytes; x += data.BytesPerPixel) { _red = line[x + 2]; _green = line[x + 1]; _blue = line[x + 0]; ApplySettings2(Settings.NegativeImage); ApplySettings3(Settings.GrayscaleImage); Color c = Color.FromArgb(_red, _green, _blue); _pixels[x / data.BytesPerPixel, y] = c; } } }
/// <summary> /// Turns the BlockLines into a bitmap /// </summary> private unsafe void BuildImage(LockBitsData data) { List <int> steps = Utility.GetSteps(data.HeightInPixels, _elementHeight); byte *ptr = (byte *)data.Scan0; Parallel.ForEach(steps, y => { // Get the appropriate number of lines byte *[] lines = new byte *[_elementHeight]; for (int i = 0; i < _elementHeight; i++) { lines[i] = ptr + (y + i) * data.Stride; } int index = y / _elementHeight; BuildBlockLine(lines, index, data.BytesPerPixel); _pData.Dialog.IncrementProgress(); }); }