Beispiel #1
0
        private protected override Bitmap Process(Bitmap bmp, Rectangle region)
        {
            if (bmp.PixelFormat != PixelFormat.Format32bppArgb)
            {
                bmp = bmp.ToARGB32();
            }

            Bitmap       result = new(bmp.Width, bmp.Height, PixelFormat.Format32bppArgb);
            BitmapLocker src    = bmp;
            BitmapLocker dst    = result;

            src.LockRGBAPixels((ps, ws, hs) => dst.LockRGBAPixels((pd, wd, hd) =>
            {
                Process(bmp, ps, pd, region);

                Parallel.For(0, ws * hs, i =>
                {
                    if (!region.Contains(i % ws, i / ws))
                    {
                        pd[i] = ps[i];
                    }
                });
            }));

            return(result);
        }
Beispiel #2
0
        internal protected override unsafe void Process(Bitmap bmp, RGBAColor *p_top, RGBAColor *p_dest, Rectangle region)
        {
            if (bmp.Size != BaseLayer.Size)
            {
                throw new ArgumentException($"The top layer ('{nameof(bmp)}') must have the same dimensions as the base layer. The required dimensions are: {BaseLayer.Width}x{BaseLayer.Height}.", nameof(bmp));
            }

            int[]        indices = GetIndices(BaseLayer, region);
            BitmapLocker lck     = BaseLayer;
            BlendMode    mode    = Mode;

            lck.LockRGBAPixels((p_base, w, h) => Parallel.For(0, indices.Length, i =>
            {
                int idx = indices[i];

                p_dest[idx] = RGBAColor.Blend(p_base[idx], p_top[idx], mode);
            }));
        }