Example #1
0
        private unsafe void Adjust(Bitmap bitmap, double factor, ApplyToPixel applyToPixel)
        {
            LockedBitmap lockedBitmap = new LockedBitmap(bitmap);

            Parallel.For(0, lockedBitmap.HeightInPixels, iY =>
            {
                byte *pixel = lockedBitmap.FirstByte + (iY * lockedBitmap.Stride);
                for (int iX = 0; iX < lockedBitmap.WidthInBytes; iX += lockedBitmap.BytesPerPixel)
                {
                    applyToPixel(pixel, factor);
                    pixel += lockedBitmap.BytesPerPixel;
                }
            });

            lockedBitmap.Unlock(bitmap);
        }
Example #2
0
        private unsafe byte[] GetRgbComponentNeighborhood(LockedBitmap lockedBitmapData, byte *rgbComponent)
        {
            byte[] neighborhood = InitializePixelNeighborhood();
            byte * neighbor     = rgbComponent - gap * lockedBitmapData.Stride - gapInBytes;
            int    offset       = lockedBitmapData.Stride - size * bytesPerPixel;

            for (int iY = 0; iY < size; ++iY)
            {
                for (int iX = 0; iX < size; ++iX)
                {
                    neighborhood[iY * size + iX] = *neighbor;
                    neighbor += bytesPerPixel;
                }

                neighbor += offset;
            }

            return(neighborhood);
        }
Example #3
0
        private unsafe void Adjust(Bitmap bitmap, List <Adjustment> adjustmentsPack)
        {
            LockedBitmap lockedBitmap = new LockedBitmap(bitmap);

            Parallel.For(0, lockedBitmap.HeightInPixels, iY =>
            {
                byte *pixel = lockedBitmap.FirstByte + (iY * lockedBitmap.Stride);
                for (int iX = 0; iX < lockedBitmap.WidthInBytes; iX += lockedBitmap.BytesPerPixel)
                {
                    foreach (Adjustment adjustment in adjustmentsPack)
                    {
                        adjustment.adjustment(pixel, adjustment.factor);
                    }

                    pixel += lockedBitmap.BytesPerPixel;
                }
            });

            lockedBitmap.Unlock(bitmap);
        }
Example #4
0
        protected void Apply(Bitmap input, Bitmap output)
        {
            if (!IsValid())
            {
                return;
            }

            bytesPerPixel = Bitmap.GetPixelFormatSize(input.PixelFormat) / (int)Bits.bitsInByte;
            gapInBytes    = gap * bytesPerPixel;

            IntermediateImage intermediate = new IntermediateImage(input, gap);

            intermediate.FillIn();

            LockedBitmap lockedBitmap       = new LockedBitmap(output);
            LockedBitmap lockedIntermediate = new LockedBitmap(intermediate.OutputImage);

            ApplyFilterToBitmap(lockedIntermediate, lockedBitmap);

            lockedBitmap.Unlock(output);
            lockedIntermediate.Unlock(intermediate.OutputImage);
        }
Example #5
0
        private unsafe void ApplyFilterToBitmap(LockedBitmap intermediate, LockedBitmap bitmap)
        {
            Parallel.For(0, bitmap.HeightInPixels, iY =>
            {
                byte *outputCurrentByte       = bitmap.FirstByte + (iY * bitmap.Stride);
                byte *intermediateCurrentByte = intermediate.FirstByte + ((iY + gap) * intermediate.Stride) + gapInBytes;

                for (int i = 0; i < bitmap.WidthInBytes; i += bytesPerPixel)
                {
                    for (Argb j = Argb.blue; j <= Argb.red; ++j)
                    {
                        *(outputCurrentByte + (byte)j) =
                            ComputeNewRgbComponentValue(GetRgbComponentNeighborhood(intermediate, intermediateCurrentByte + (byte)j));
                    }

                    *(outputCurrentByte + (byte)Argb.alfa) = *(intermediateCurrentByte + (byte)Argb.alfa);

                    outputCurrentByte       += bytesPerPixel;
                    intermediateCurrentByte += bytesPerPixel;
                }
            });
        }
Example #6
0
 private void LockArea(Rectangle sourceLockedArea, Rectangle intermediateLockedArea)
 {
     sourceData       = new LockedBitmap(sourceImage, sourceLockedArea);
     intermediateData = new LockedBitmap(intermediateImage, intermediateLockedArea);
 }