private void Render(Surface src, Surface dst, Rectangle rect, ArgusColor bgColor)
        {
            HsvColorF hsvBg = bgColor;

            for (int y = rect.Top; y < rect.Bottom; y++)
            {
                for (int x = rect.Left; x < rect.Right; x++)
                {
                    ArgusColor px = src[x, y];
                    if (Math.Abs(px.R - bgColor.R) < this._tolRGB && Math.Abs(px.G - bgColor.G) < this._tolRGB && Math.Abs(px.B - bgColor.B) < this._tolRGB)
                    {
                        dst[x, y] = ColorBgra.FromUInt32(0);
                    }
                    else
                    {
                        HsvColorF hsv  = px;
                        double    dHue = Math.Abs(hsv.Hue - hsvBg.Hue);
                        if (dHue > 180)
                        {
                            dHue = 360 - dHue;
                        }

                        if (dHue < this._tolHue && Math.Abs(hsv.Saturation - hsvBg.Saturation) < this._tolSat && Math.Abs(hsv.Value - hsvBg.Value) < this._tolVal)
                        {
                            dst[x, y] = ColorBgra.FromUInt32(0);
                        }
                        else
                        {
                            dst[x, y] = px.ReverseBlend(bgColor);
                        }
                    }
                }
            }
        }
        public override ColorBgra Apply(ColorBgra lhs, ColorBgra rhs)
        {
            int lhsA; { lhsA = ((lhs).A); }; int rhsA; { rhsA = ((rhs).A); }; int y; { y = ((lhsA) * (255 - rhsA) + 0x80); y = ((((y) >> 8) + (y)) >> 8); }; int totalA = y + rhsA; uint ret; if (totalA == 0)

            {
                ret = 0;
            }
            else
            {
                int fB; int fG; int fR; { if (((rhs).B) == 0)
                                          {
                                              fB = 0;
                                          }
                                          else
                                          {
                                              { int i = (((rhs).B)) * 3; uint M = masTable[i]; uint A = masTable[i + 1]; uint S = masTable[i + 2]; fB = (int)(((((255 - ((lhs).B)) * 255) * M) + A) >> (int)S); }; fB = 255 - fB; fB = Math.Max(0, fB);
                                          } }; { if (((rhs).G) == 0)
                                                 {
                                                     fG = 0;
                                                 }
                                                 else
                                                 {
                                                     { int i = (((rhs).G)) * 3; uint M = masTable[i]; uint A = masTable[i + 1]; uint S = masTable[i + 2]; fG = (int)(((((255 - ((lhs).G)) * 255) * M) + A) >> (int)S); }; fG = 255 - fG; fG = Math.Max(0, fG);
                                                 } }; { if (((rhs).R) == 0)
                                                        {
                                                            fR = 0;
                                                        }
                                                        else
                                                        {
                                                            { int i = (((rhs).R)) * 3; uint M = masTable[i]; uint A = masTable[i + 1]; uint S = masTable[i + 2]; fR = (int)(((((255 - ((lhs).R)) * 255) * M) + A) >> (int)S); }; fR = 255 - fR; fR = Math.Max(0, fR);
                                                        } }; int x; { x = ((lhsA) * (rhsA) + 0x80); x = ((((x) >> 8) + (x)) >> 8); }; int z = rhsA - x; int masIndex = totalA * 3; uint taM = masTable[masIndex]; uint taA = masTable[masIndex + 1]; uint taS = masTable[masIndex + 2]; uint b = (uint)(((((long)((((lhs).B * y) + ((rhs).B * z) + (fB * x)))) * taM) + taA) >> (int)taS); uint g = (uint)(((((long)((((lhs).G * y) + ((rhs).G * z) + (fG * x)))) * taM) + taA) >> (int)taS); uint r = (uint)(((((long)((((lhs).R * y) + ((rhs).R * z) + (fR * x)))) * taM) + taA) >> (int)taS); int a; { { a = ((lhsA) * (255 - (rhsA)) + 0x80); a = ((((a) >> 8) + (a)) >> 8); }; a += (rhsA); }; ret = b + (g << 8) + (r << 16) + ((uint)a << 24);
            }; return(ColorBgra.FromUInt32(ret));
        }
        public static ColorBgra ApplyStatic(ColorBgra lhs, ColorBgra rhs)
        {
            int lhsA; { lhsA = ((lhs).A); }; int rhsA; { rhsA = ((rhs).A); }; int y; { y = ((lhsA) * (255 - rhsA) + 0x80); y = ((((y) >> 8) + (y)) >> 8); }; int totalA = y + rhsA; uint ret; if (totalA == 0)

            {
                ret = 0;
            }
            else
            {
                int fB; int fG; int fR; { if (((lhs).B) < 128)
                                          {
                                              { fB = ((2 * ((lhs).B)) * (((rhs).B)) + 0x80); fB = ((((fB) >> 8) + (fB)) >> 8); };
                                          }
                                          else
                                          {
                                              { fB = ((2 * (255 - ((lhs).B))) * (255 - ((rhs).B)) + 0x80); fB = ((((fB) >> 8) + (fB)) >> 8); }; fB = 255 - fB;
                                          } }; { if (((lhs).G) < 128)
                                                 {
                                                     { fG = ((2 * ((lhs).G)) * (((rhs).G)) + 0x80); fG = ((((fG) >> 8) + (fG)) >> 8); };
                                                 }
                                                 else
                                                 {
                                                     { fG = ((2 * (255 - ((lhs).G))) * (255 - ((rhs).G)) + 0x80); fG = ((((fG) >> 8) + (fG)) >> 8); }; fG = 255 - fG;
                                                 } }; { if (((lhs).R) < 128)
                                                        {
                                                            { fR = ((2 * ((lhs).R)) * (((rhs).R)) + 0x80); fR = ((((fR) >> 8) + (fR)) >> 8); };
                                                        }
                                                        else
                                                        {
                                                            { fR = ((2 * (255 - ((lhs).R))) * (255 - ((rhs).R)) + 0x80); fR = ((((fR) >> 8) + (fR)) >> 8); }; fR = 255 - fR;
                                                        } }; int x; { x = ((lhsA) * (rhsA) + 0x80); x = ((((x) >> 8) + (x)) >> 8); }; int z = rhsA - x; int masIndex = totalA * 3; uint taM = masTable[masIndex]; uint taA = masTable[masIndex + 1]; uint taS = masTable[masIndex + 2]; uint b = (uint)(((((long)((((lhs).B * y) + ((rhs).B * z) + (fB * x)))) * taM) + taA) >> (int)taS); uint g = (uint)(((((long)((((lhs).G * y) + ((rhs).G * z) + (fG * x)))) * taM) + taA) >> (int)taS); uint r = (uint)(((((long)((((lhs).R * y) + ((rhs).R * z) + (fR * x)))) * taM) + taA) >> (int)taS); int a; { { a = ((lhsA) * (255 - (rhsA)) + 0x80); a = ((((a) >> 8) + (a)) >> 8); }; a += (rhsA); }; ret = b + (g << 8) + (r << 16) + ((uint)a << 24);
            }; return(ColorBgra.FromUInt32(ret));
        }
Пример #4
0
        private ColorBgra ReadColor(Stream input, int pixelDepth, ColorBgra[] palette)
        {
            int num3;

            if (pixelDepth <= 15)
            {
                if (pixelDepth == 8)
                {
                    int index = input.ReadByte();
                    if (index == -1)
                    {
                        throw new EndOfStreamException();
                    }
                    if (index >= palette.Length)
                    {
                        throw new FormatException("color index was outside the bounds of the palette");
                    }
                    return(palette[index]);
                }
                if (pixelDepth == 15)
                {
                    goto Label_006D;
                }
                goto Label_00D6;
            }
            if (pixelDepth != 0x10)
            {
                if (pixelDepth == 0x18)
                {
                    int num2 = input.ReadUInt24();
                    if (num2 == -1)
                    {
                        throw new EndOfStreamException();
                    }
                    ColorBgra bgra = ColorBgra.FromUInt32((uint)num2);
                    bgra.A = 0xff;
                    return(bgra);
                }
                if (pixelDepth == 0x20)
                {
                    long num = input.ReadUInt32();
                    if (num == -1L)
                    {
                        throw new EndOfStreamException();
                    }
                    return(ColorBgra.FromUInt32((uint)num));
                }
                goto Label_00D6;
            }
Label_006D:
            num3 = input.ReadUInt16();
            if (num3 == -1)
            {
                throw new EndOfStreamException();
            }
            return(ColorBgra.FromBgra((byte)((num3 & 0x1f) * 8), (byte)((num3 >> 2) & 0xf8), (byte)((num3 >> 7) & 0xf8), 0xff));

Label_00D6:
            throw new FormatException("colorDepth was not one of {8, 15, 16, 24, 32}");
        }
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken newToken, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            margin  = newToken.GetProperty <Int32Property>(PropertyNames.Margin).Value;
            spread  = newToken.GetProperty <Int32Property>(PropertyNames.Spread).Value;
            blur    = newToken.GetProperty <Int32Property>(PropertyNames.Blur).Value;
            color   = ColorBgra.FromUInt32(unchecked ((uint)newToken.GetProperty <Int32Property>(PropertyNames.Color).Value));
            offsetX = newToken.GetProperty <Int32Property>(PropertyNames.OffsetX).Value;
            offsetY = newToken.GetProperty <Int32Property>(PropertyNames.OffsetY).Value;

            if (shadowSurface == null)
            {
                shadowSurface = new Surface(srcArgs.Surface.Size);
            }
            else
            {
                shadowSurface.Clear(Color.Transparent);
            }

            // Setup for calling the Gaussian Blur effect
            PropertyCollection             blurProps      = blurEffect.CreatePropertyCollection();
            PropertyBasedEffectConfigToken BlurParameters = new PropertyBasedEffectConfigToken(blurProps);

            BlurParameters.SetPropertyValue(GaussianBlurEffect.PropertyNames.Radius, blur);
            blurEffect.SetRenderInfo(BlurParameters, dstArgs, new RenderArgs(shadowSurface));

            Rectangle selection = EnvironmentParameters.GetSelection(srcArgs.Surface.Bounds).GetBoundsInt();

            PointF topStart    = new PointF(selection.Left, selection.Top + (margin + spread + offsetY) / 2f);
            PointF topEnd      = new PointF(selection.Right, selection.Top + (margin + spread + offsetY) / 2f);
            PointF rightStart  = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Top);
            PointF rightEnd    = new PointF(selection.Right - (margin + spread - offsetX) / 2f, selection.Bottom);
            PointF bottomStart = new PointF(selection.Left, selection.Bottom - (margin + spread - offsetY) / 2f);
            PointF bottomEnd   = new PointF(selection.Right, selection.Bottom - (margin + spread - offsetY) / 2f);
            PointF leftStart   = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Top);
            PointF leftEnd     = new PointF(selection.Left + (margin + spread + offsetX) / 2f, selection.Bottom);

            using (Graphics shadow = new RenderArgs(shadowSurface).Graphics)
                using (Pen shadowPen = new Pen(color))
                {
                    shadowPen.Width = margin + spread + offsetX;
                    shadow.DrawLine(shadowPen, leftStart, leftEnd);

                    shadowPen.Width = margin + spread - offsetX;
                    shadow.DrawLine(shadowPen, rightStart, rightEnd);

                    shadowPen.Width = margin + spread + offsetY;
                    shadow.DrawLine(shadowPen, topStart, topEnd);

                    shadowPen.Width = margin + spread - offsetY;
                    shadow.DrawLine(shadowPen, bottomStart, bottomEnd);
                }

            base.OnSetRenderInfo(newToken, dstArgs, srcArgs);
        }
            public override ColorBgra Apply(ColorBgra lhs, ColorBgra rhs)
            {
                int lhsA; { lhsA = ((lhs).A); }; int rhsA; { rhsA = ApplyOpacity((rhs).A); }; int y; { y = ((lhsA) * (255 - rhsA) + 0x80); y = ((((y) >> 8) + (y)) >> 8); }; int totalA = y + rhsA; uint ret; if (totalA == 0)

                {
                    ret = 0;
                }
                else
                {
                    int fB; int fG; int fR; { fB = Math.Min(255, ((lhs).B) + ((rhs).B)); }; { fG = Math.Min(255, ((lhs).G) + ((rhs).G)); }; { fR = Math.Min(255, ((lhs).R) + ((rhs).R)); }; int x; { x = ((lhsA) * (rhsA) + 0x80); x = ((((x) >> 8) + (x)) >> 8); }; int z = rhsA - x; int masIndex = totalA * 3; uint taM = masTable[masIndex]; uint taA = masTable[masIndex + 1]; uint taS = masTable[masIndex + 2]; uint b = (uint)(((((long)((((lhs).B * y) + ((rhs).B * z) + (fB * x)))) * taM) + taA) >> (int)taS); uint g = (uint)(((((long)((((lhs).G * y) + ((rhs).G * z) + (fG * x)))) * taM) + taA) >> (int)taS); uint r = (uint)(((((long)((((lhs).R * y) + ((rhs).R * z) + (fR * x)))) * taM) + taA) >> (int)taS); int a; { { a = ((lhsA) * (255 - (rhsA)) + 0x80); a = ((((a) >> 8) + (a)) >> 8); }; a += (rhsA); }; ret = b + (g << 8) + (r << 16) + ((uint)a << 24);
                }; return(ColorBgra.FromUInt32(ret));
            }
Пример #7
0
        static CheckerboardCanvasLayer()
        {
            ColorBgra white = ColorBgra.White;
            ColorBgra color = ColorBgra.FromUInt32(0xffbfbfbf);

            checkerboardSurface = new Surface(0x10, 0x10);
            checkerboardSurface.Clear(white);
            checkerboardSurface.Clear(new RectInt32(0, 0, 8, 8), color);
            checkerboardSurface.Clear(new RectInt32(8, 8, 8, 8), color);
            checkerboardBitmap                   = checkerboardSurface.CreateAliasedImagingBitmap(PixelFormats.Bgr32);
            checkerboardDeviceBitmap             = new DeviceBitmap(checkerboardBitmap);
            checkerboardDeviceBitmap.IsShareable = true;
            checkerboardDeviceBitmap.Freeze();
        }
Пример #8
0
        public override ColorBgra Apply(ColorBgra lhs, ColorBgra rhs)
        {
            int lhsA = lhs.A;
            int rhsA = rhs.A;

            int y = lhsA * (255 - rhsA) + 0x80;

            y = ((y >> 8) + y) >> 8;

            int  totalA = y + rhsA;
            uint ret;

            if (totalA == 0)
            {
                return(ColorBgra.FromUInt32(0));
            }

            int fB = rhs.B;
            int fG = rhs.G;
            int fR = rhs.R;

            int x = lhsA * rhsA + 0x80;

            x = ((x >> 8) + x) >> 8;

            int z        = rhsA - x;
            int masIndex = totalA * 3;

            uint taM = masTable[masIndex];
            uint taA = masTable[masIndex + 1];
            uint taS = masTable[masIndex + 2];

            uint b = (uint)((((long)((lhs.B * y) + (rhs.B * z) + (fB * x))) * taM) + taA) >> (int)taS;
            uint g = (uint)((((long)((lhs.G * y) + (rhs.G * z) + (fG * x))) * taM) + taA) >> (int)taS;
            uint r = (uint)((((long)((lhs.R * y) + (rhs.R * z) + (fR * x))) * taM) + taA) >> (int)taS;

            int a = (lhsA * (255 - rhsA) + 0x80);

            a  = (((a >> 8) + a) >> 8);
            a += rhsA;

            ret = b + (g << 8) + (r << 16) + ((uint)a << 24);

            return(ColorBgra.FromUInt32(ret));
        }
Пример #9
0
 public override ColorBgra Apply(ColorBgra color)
 {
     return(ColorBgra.FromUInt32((color.Bgra & 0x00ffffff) + addValue));
 }
Пример #10
0
        private ImageResource CreateImageResource(int width, int height, double borderSize)
        {
            ImageResource resource2;
            double        x = borderSize / 2.0;

            using (ISurface <ColorBgra> surface = SurfaceAllocator.Bgra.Allocate(width, height, AllocationOptions.ZeroFillNotRequired))
            {
                using (IDrawingContext context = DrawingContext.FromSurface(surface, AlphaMode.Premultiplied, FactorySource.PerThread))
                {
                    RectDouble num4;
                    context.Clear(null);
                    RectDouble num2        = new RectDouble(x, x, width - borderSize, height - borderSize);
                    double     aspectRatio = this.AspectRatio;
                    if (aspectRatio > 1.0)
                    {
                        double num5 = num2.Height / aspectRatio;
                        num4 = new RectDouble(num2.X, num2.Y + ((num2.Height - num5) / 2.0), num2.Width, num5);
                    }
                    else if (aspectRatio < 1.0)
                    {
                        double num6 = num2.Width * aspectRatio;
                        num4 = new RectDouble(num2.X + ((num2.Width - num6) / 2.0), num2.Y, num6, num2.Height);
                    }
                    else
                    {
                        num4 = num2;
                    }
                    IDictionary <string, object> settingValues = (from p in this.RenderSettingPaths select KeyValuePairUtil.Create <string, object>(p, AppSettings.Instance[ConvertToolsPathToToolDefaultsPath(p)].Value)).ToDictionary <string, object>();
                    ShapeRenderParameters        renderParams  = new ShapeRenderParameters(num4.TopLeft, num4.BottomRight, new VectorDouble(1.0, 1.0), settingValues, null);
                    PropertyCollection           properties    = this.CreatePropertyCollection(renderParams);
                    this.OnSetImagePropertyCollectionValues(renderParams, properties);
                    IDictionary <object, object> propertyValues = (from p in properties select KeyValuePairUtil.Create <object, object>(p.GetOriginalNameValue(), p.Value)).ToDictionary <object, object>();
                    ShapeRenderParameters        parameters2    = new ShapeRenderParameters(num4.TopLeft, num4.BottomRight, new VectorDouble(1.0, 1.0), settingValues, propertyValues);
                    ShapeRenderData            data             = this.CreateImageRenderData(parameters2);
                    PaintDotNet.UI.Media.Brush brush            = SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.FromUInt32(0xff5894c1));
                    if (data.InteriorFill != null)
                    {
                        context.FillGeometry(data.InteriorFill.Geometry, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White), null);
                        LinearGradientBrush brush2 = new LinearGradientBrush {
                            StartPoint = num4.TopLeft,
                            EndPoint   = num4.BottomRight
                        };
                        brush2.GradientStops.Add(new GradientStop((ColorRgba128Float)ColorBgra32.FromUInt32(0xffc0e1f3), 0.0));
                        brush2.GradientStops.Add(new GradientStop((ColorRgba128Float)ColorBgra32.FromUInt32(0xffe0eff8), 1.0));
                        context.FillGeometry(data.InteriorFill.Geometry, brush2, null);
                    }
                    if ((data.InteriorFill != null) && (data.OutlineDraw != null))
                    {
                        RenderLayer layer = RenderLayerCache.Get();
                        using (context.UseLayer(layer, null, data.InteriorFill.Geometry, AntialiasMode.PerPrimitive, null, 1.0, null, LayerOptions.None))
                        {
                            context.DrawGeometry(data.OutlineDraw.Geometry, SolidColorBrushCache.Get((ColorRgba128Float)Colors.White), 3.0);
                        }
                        RenderLayerCache.Return(layer);
                    }
                    if (data.OutlineDraw != null)
                    {
                        context.DrawGeometry(data.OutlineDraw.Geometry, brush, 1.0);
                    }
                    if (data.OutlineFill != null)
                    {
                        context.FillGeometry(data.OutlineFill.Geometry, brush, null);
                    }
                    string imageStringOverlay = this.ImageStringOverlay;
                    if (imageStringOverlay != string.Empty)
                    {
                        double     num7       = (width * 7.0) / 16.0;
                        double     fontSize   = UIUtil.ScaleWidth(num7);
                        TextLayout textLayout = new TextLayout(imageStringOverlay, "Arial", FontWeight.Normal, PaintDotNet.DirectWrite.FontStyle.Normal, FontStretch.Normal, fontSize)
                        {
                            ParagraphAlignment = ParagraphAlignment.Center,
                            TextAlignment      = PaintDotNet.DirectWrite.TextAlignment.Center,
                            MaxWidth           = width - 2,
                            MaxHeight          = height - 2
                        };
                        context.DrawTextLayout(new PointDouble(1.0, 1.0), textLayout, SolidColorBrushCache.Get((ColorRgba128Float)ColorBgra.FromUInt32(0xff5894c1)), DrawTextOptions.None);
                    }
                }
                surface.ConvertFromPremultipliedAlpha();
                using (System.Drawing.Bitmap bitmap = surface.CreateAliasedGdipBitmap())
                {
                    System.Drawing.Bitmap image = new System.Drawing.Bitmap(bitmap);
                    resource2 = ImageResource.FromImage(image);
                }
            }
            return(resource2);
        }
Пример #11
0
        private unsafe void CopyScaledZoomOut(Cairo.ImageSurface src, Cairo.ImageSurface dst, Rectangle roi)
        {
            // Tell Cairo we need the latest raw data
            dst.Flush();

            const int fpShift  = 12;
            const int fpFactor = (1 << fpShift);

            var source_size = src.GetBounds().Size;

            // Find destination bounds
            var dst_left   = (int)(((long)roi.X * fpFactor * (long)source_size.Width) / (long)destination_size.Width);
            var dst_top    = (int)(((long)roi.Y * fpFactor * (long)source_size.Height) / (long)destination_size.Height);
            var dst_right  = (int)(((long)(roi.X + dst.Width) * fpFactor * (long)source_size.Width) / (long)destination_size.Width);
            var dst_bottom = (int)(((long)(roi.Y + dst.Height) * fpFactor * (long)source_size.Height) / (long)destination_size.Height);
            var dx         = (dst_right - dst_left) / dst.Width;
            var dy         = (dst_bottom - dst_top) / dst.Height;

            // Cache pointers to surface raw data and sizes
            var src_ptr    = (ColorBgra *)src.DataPtr;
            var dst_ptr    = (ColorBgra *)dst.DataPtr;
            var src_width  = src.Width;
            var dst_width  = dst.Width;
            var dst_height = dst.Height;

            for (int dstRow = 0, fDstY = dst_top; dstRow < dst_height && fDstY < dst_bottom; ++dstRow, fDstY += dy)
            {
                var srcY1 = fDstY >> fpShift;                                            // y
                var srcY2 = (fDstY + (dy >> 2)) >> fpShift;                              // y + 0.25
                var srcY3 = (fDstY + (dy >> 1)) >> fpShift;                              // y + 0.50
                var srcY4 = (fDstY + (dy >> 1) + (dy >> 2)) >> fpShift;                  // y + 0.75

                var src1   = src.GetRowAddressUnchecked(src_ptr, src_width, srcY1);
                var src2   = src.GetRowAddressUnchecked(src_ptr, src_width, srcY2);
                var src3   = src.GetRowAddressUnchecked(src_ptr, src_width, srcY3);
                var src4   = src.GetRowAddressUnchecked(src_ptr, src_width, srcY4);
                var dstPtr = dst.GetRowAddressUnchecked(dst_ptr, dst_width, dstRow);

                var checkerY    = dstRow + roi.Y;
                var checkerX    = roi.X;
                var maxCheckerX = checkerX + dst.Width;

                for (var fDstX = dst_left; checkerX < maxCheckerX && fDstX < dst_right; ++checkerX, fDstX += dx)
                {
                    var srcX1 = (fDstX + (dx >> 2)) >> fpShift;                                 // x + 0.25
                    var srcX2 = (fDstX + (dx >> 1) + (dx >> 2)) >> fpShift;                     // x + 0.75
                    var srcX3 = fDstX >> fpShift;                                               // x
                    var srcX4 = (fDstX + (dx >> 1)) >> fpShift;                                 // x + 0.50

                    var p1 = src1 + srcX1;
                    var p2 = src2 + srcX2;
                    var p3 = src3 + srcX3;
                    var p4 = src4 + srcX4;

                    var r = (2 + p1->R + p2->R + p3->R + p4->R) >> 2;
                    var g = (2 + p1->G + p2->G + p3->G + p4->G) >> 2;
                    var b = (2 + p1->B + p2->B + p3->B + p4->B) >> 2;
                    var a = (2 + p1->A + p2->A + p3->A + p4->A) >> 2;

                    // Copy color to destination
                    *dstPtr++ = ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24));
                }
            }

            // Tell Cairo we changed the raw data
            dst.MarkDirty();
        }
Пример #12
0
        private ColorBgra ReadColor(Stream input, int pixelDepth, ColorBgra[] palette)
        {
            ColorBgra color;

            switch (pixelDepth)
            {
            case 32:
            {
                long colorInt = Utility.ReadUInt32(input);

                if (colorInt == -1)
                {
                    throw new EndOfStreamException();
                }

                color = ColorBgra.FromUInt32((uint)colorInt);
                break;
            }

            case 24:
            {
                int colorInt = Utility.ReadUInt24(input);

                if (colorInt == -1)
                {
                    throw new EndOfStreamException();
                }

                color   = ColorBgra.FromUInt32((uint)colorInt);
                color.A = 255;
                break;
            }

            case 15:
            case 16:
            {
                int colorWord = Utility.ReadUInt16(input);

                if (colorWord == -1)
                {
                    throw new EndOfStreamException();
                }

                color = ColorBgra.FromBgra(
                    (byte)((colorWord >> 7) & 0xf8),
                    (byte)((colorWord >> 2) & 0xf8),
                    (byte)((colorWord & 0x1f) * 8),
                    255);

                break;
            }

            case 8:
            {
                int colorByte = input.ReadByte();

                if (colorByte == -1)
                {
                    throw new EndOfStreamException();
                }

                if (colorByte >= palette.Length)
                {
                    throw new FormatException("color index was outside the bounds of the palette");
                }

                color = palette[colorByte];
                break;
            }

            default:
                throw new FormatException("colorDepth was not one of {8, 15, 16, 24, 32}");
            }

            return(color);
        }
Пример #13
0
        private void DrawGradient(Graphics g)
        {
            Rectangle gradientRect;

            // draw gradient
            gradientRect = ClientRectangle;
            gradientRect.Inflate(-triangleHalfLength, -triangleSize + 3);

            if (this.gradient != null && gradientRect.Width > 1 && gradientRect.Height > 1)
            {
                Surface gradientSurface = new Surface(gradientRect.Size);

                using (RenderArgs ra = new RenderArgs(gradientSurface))
                {
                    for (int y = 0; y < gradientSurface.Height; ++y)
                    {
                        for (int x = 0; x < gradientSurface.Width; ++x)
                        {
                            float     f       = x * (gradient.Length - 1) / (float)gradientRect.Width;
                            int       i       = (int)f;
                            byte      v       = (byte)((((x ^ y) & 4) * 16) + 191);
                            ColorBgra checker = ColorBgra.FromUInt32((uint)v | (uint)(v << 8) | (uint)(v << 16) | 0xff000000);
                            ColorBgra c       = ColorBgra.Lerp(gradient[i], gradient[i + 1], f - i);

                            gradientSurface[x, y] = UserBlendOps.NormalBlendOp.ApplyStatic(checker, c);
                        }
                    }

                    g.DrawImage(ra.Bitmap, gradientRect, ra.Bounds, GraphicsUnit.Pixel);
                }

                gradientSurface.Dispose();
            }

            // draw value triangles
            Brush brush;
            Pen   pen;

            if (highlight)
            {
                brush = Brushes.Blue;
                pen   = Pens.White;
            }
            else
            {
                brush = this.Enabled ? Brushes.Black : Brushes.Gray;
                pen   = Pens.Gray;
            }

            g.SmoothingMode = SmoothingMode.AntiAlias;

            Point a1;
            Point b1;
            Point c1;

            Point a2;
            Point b2;
            Point c2;

            int pos = gradientRect.Left + (int)(gradientRect.Width * value + 0.5);

            a1 = new Point(pos - triangleHalfLength, 0);
            b1 = new Point(pos, triangleSize - 1);
            c1 = new Point(pos + triangleHalfLength, 0);

            a2 = new Point(a1.X, Height - 1 - a1.Y);
            b2 = new Point(b1.X, Height - 1 - b1.Y);
            c2 = new Point(c1.X, Height - 1 - c1.Y);

            if (this.drawNearNub)
            {
                g.FillPolygon(brush, new Point[] { a1, b1, c1, a1 });
            }

            if (this.drawFarNub)
            {
                g.FillPolygon(brush, new Point[] { a2, b2, c2, a2 });
            }

            if (this.drawNearNub)
            {
                g.DrawPolygon(pen, new Point[] { a1, b1, c1, a1 });
            }

            if (this.drawFarNub)
            {
                g.DrawPolygon(pen, new Point[] { a2, b2, c2, a2 });
            }
        }
Пример #14
0
        public unsafe override void Render(
            Surface src,
            Surface dst,
            PixelFarm.Drawing.Rectangle[] rois,
            int startIndex, int length)
        {
            RotateZoomEffectConfigToken token = (RotateZoomEffectConfigToken)Parameters;

            RotateZoomEffectConfigToken.RzInfo rzInfo = token.ComputedOnce;
            //Rectangle bounds = this.EnvironmentParameters.GetSelection(dstArgs.Bounds).GetBoundsInt();

            Rectangle bounds = SelectionBounds;

            bounds.Intersect(dst.Bounds);


            //PdnRegion selection = this.EnvironmentParameters.GetSelection(src.Bounds);
            Rectangle srcBounds = src.Bounds;
            int       srcMaxX   = srcBounds.Width - 1;
            int       srcMaxY   = srcBounds.Height - 1;

            float dsxdx   = rzInfo.dsxdx;
            float dsydx   = rzInfo.dsydx;
            float dszdx   = rzInfo.dszdx;
            float dsxdy   = rzInfo.dsxdy;
            float dsydy   = rzInfo.dsydy;
            float dszdy   = rzInfo.dszdy;
            float zoom    = token.Zoom;
            uint  srcMask = token.SourceAsBackground ? 0xffffffff : 0;

            bool  tile    = token.Tile;
            float divZ    = 0.5f * (float)Math.Sqrt(dst.Width * dst.Width + dst.Height * dst.Height);
            float centerX = (float)dst.Width / 2.0f;
            float centerY = (float)dst.Height / 2.0f;
            float tx      = (token.Offset.X) * dst.Width / 2.0f;
            float ty      = (token.Offset.Y) * dst.Height / 2.0f;

            uint tilingMask = tile ? 0xffffffff : 0;

            for (int i = startIndex; i < startIndex + length; ++i)
            {
                Rectangle rect = rois[i];

                float cx = rzInfo.startX;
                float cy = rzInfo.startY;
                float cz = rzInfo.startZ;

                float mcl = ((rect.Left - tx) - dst.Width / 2.0f);
                cx += dsxdx * mcl;
                cy += dsydx * mcl;
                cz += dszdx * mcl;

                float mct = ((rect.Top - ty) - dst.Height / 2.0f);
                cx += dsxdy * mct;
                cy += dsydy * mct;
                cz += dszdy * mct;

                for (int y = rect.Top; y < rect.Bottom; ++y)
                {
                    ColorBgra *dstPtr = dst.GetPointAddressUnchecked(rect.Left, y);
                    ColorBgra *srcPtr = src.GetPointAddressUnchecked(rect.Left, y);

                    float rx = cx;
                    float ry = cy;
                    float rz = cz;

                    for (int x = rect.Left; x < rect.Right; ++x)
                    {
                        if (rz > -divZ)
                        {
                            float div = divZ / (zoom * (divZ + rz));
                            float u   = (rx * div) + centerX;
                            float v   = (ry * div) + centerY;

                            if (tile || (u >= -1 && v >= -1 && u <= srcBounds.Width && v <= srcBounds.Height))
                            {
                                unchecked
                                {
                                    int  iu        = (int)Math.Floor(u);
                                    uint sxfrac    = (uint)(256 * (u - (float)iu));
                                    uint sxfracinv = 256 - sxfrac;

                                    int  iv        = (int)Math.Floor(v);
                                    uint syfrac    = (uint)(256 * (v - (float)iv));
                                    uint syfracinv = 256 - syfrac;

                                    uint wul = (uint)(sxfracinv * syfracinv);
                                    uint wur = (uint)(sxfrac * syfracinv);
                                    uint wll = (uint)(sxfracinv * syfrac);
                                    uint wlr = (uint)(sxfrac * syfrac);

                                    uint inBoundsMaskLeft   = tilingMask;
                                    uint inBoundsMaskTop    = tilingMask;
                                    uint inBoundsMaskRight  = tilingMask;
                                    uint inBoundsMaskBottom = tilingMask;

                                    int sx = iu;
                                    if (sx < 0)
                                    {
                                        sx = srcMaxX + ((sx + 1) % srcBounds.Width);
                                    }
                                    else if (sx > srcMaxX)
                                    {
                                        sx = sx % srcBounds.Width;
                                    }
                                    else
                                    {
                                        inBoundsMaskLeft = 0xffffffff;
                                    }

                                    int sy = iv;
                                    if (sy < 0)
                                    {
                                        sy = srcMaxY + ((sy + 1) % srcBounds.Height);
                                    }
                                    else if (sy > srcMaxY)
                                    {
                                        sy = sy % srcBounds.Height;
                                    }
                                    else
                                    {
                                        inBoundsMaskTop = 0xffffffff;
                                    }

                                    int sleft = sx;
                                    int sright;

                                    if (sleft == srcMaxX)
                                    {
                                        sright            = 0;
                                        inBoundsMaskRight = (iu == -1) ? 0xffffffff : tilingMask;
                                    }
                                    else
                                    {
                                        sright            = sleft + 1;
                                        inBoundsMaskRight = inBoundsMaskLeft & 0xffffffff;
                                    }

                                    int stop = sy;
                                    int sbottom;

                                    if (stop == srcMaxY)
                                    {
                                        sbottom            = 0;
                                        inBoundsMaskBottom = (iv == -1) ? 0xffffffff : tilingMask;
                                    }
                                    else
                                    {
                                        sbottom            = stop + 1;
                                        inBoundsMaskBottom = inBoundsMaskTop & 0xffffffff;
                                    }

                                    uint      maskUL = inBoundsMaskLeft & inBoundsMaskTop;
                                    ColorBgra cul    = ColorBgra.FromUInt32(src.GetPointUnchecked(sleft, stop).Bgra & maskUL);

                                    uint      maskUR = inBoundsMaskRight & inBoundsMaskTop;
                                    ColorBgra cur    = ColorBgra.FromUInt32(src.GetPointUnchecked(sright, stop).Bgra & maskUR);

                                    uint      maskLL = inBoundsMaskLeft & inBoundsMaskBottom;
                                    ColorBgra cll    = ColorBgra.FromUInt32(src.GetPointUnchecked(sleft, sbottom).Bgra & maskLL);

                                    uint      maskLR = inBoundsMaskRight & inBoundsMaskBottom;
                                    ColorBgra clr    = ColorBgra.FromUInt32(src.GetPointUnchecked(sright, sbottom).Bgra & maskLR);

                                    ColorBgra c = ColorBgra.BlendColors4W16IP(cul, wul, cur, wur, cll, wll, clr, wlr);

                                    if (c.A == 255 || !token.SourceAsBackground)
                                    {
                                        dstPtr->Bgra = c.Bgra;
                                    }
                                    else
                                    {
                                        *dstPtr = PaintFx.UserBlendOps.NormalBlendOp.ApplyStatic(*srcPtr, c);
                                    }
                                }
                            }
                            else
                            {
                                if (srcMask != 0)
                                {
                                    dstPtr->Bgra = srcPtr->Bgra;
                                }
                                else
                                {
                                    dstPtr->Bgra = 0;
                                }
                            }
                        }
                        else
                        {
                            if (srcMask != 0)
                            {
                                dstPtr->Bgra = srcPtr->Bgra;
                            }
                            else
                            {
                                dstPtr->Bgra = 0;
                            }
                        }

                        rx += dsxdx;
                        ry += dsydx;
                        rz += dszdx;

                        ++dstPtr;
                        ++srcPtr;
                    }

                    cx += dsxdy;
                    cy += dsydy;
                    cz += dszdy;
                }
            }
        }
 public override ColorBgra Apply(ColorBgra color)
 {
     return(ColorBgra.FromUInt32(color.Bgra | 0xff000000));
 }
Пример #16
0
        private unsafe void RenderZoomOut(List <Layer> layers, Cairo.ImageSurface dst, Gdk.Point offset, Gdk.Size destinationSize)
        {
            // The first layer should be blended with the transparent checkerboard
            var checker = true;
            CheckerBoardOperation checker_op = null;

            for (int i = 0; i < layers.Count; i++)
            {
                var layer = layers[i];

                // If we're in LivePreview, substitute current layer with the preview layer
                if (layer == PintaCore.Layers.CurrentLayer && PintaCore.LivePreview.IsEnabled)
                {
                    layer = CreateLivePreviewLayer(layer);
                }

                // If the layer is offset, handle it here
                if (!layer.Offset.IsEmpty())
                {
                    layer = CreateOffsetLayer(layer);
                }

                var src = layer.Surface;

                // Get the blend mode for this layer and opacity
                var blend_op = UserBlendOps.GetBlendOp(layer.BlendMode, layer.Opacity);

                if (checker)
                {
                    checker_op = new CheckerBoardOperation(layer.Opacity);
                }

                const int fpShift  = 12;
                const int fpFactor = (1 << fpShift);

                Gdk.Size sourceSize     = src.GetBounds().Size;
                long     fDstLeftLong   = ((long)offset.X * fpFactor * (long)sourceSize.Width) / (long)destinationSize.Width;
                long     fDstTopLong    = ((long)offset.Y * fpFactor * (long)sourceSize.Height) / (long)destinationSize.Height;
                long     fDstRightLong  = ((long)(offset.X + dst.Width) * fpFactor * (long)sourceSize.Width) / (long)destinationSize.Width;
                long     fDstBottomLong = ((long)(offset.Y + dst.Height) * fpFactor * (long)sourceSize.Height) / (long)destinationSize.Height;
                int      fDstLeft       = (int)fDstLeftLong;
                int      fDstTop        = (int)fDstTopLong;
                int      fDstRight      = (int)fDstRightLong;
                int      fDstBottom     = (int)fDstBottomLong;
                int      dx             = (fDstRight - fDstLeft) / dst.Width;
                int      dy             = (fDstBottom - fDstTop) / dst.Height;

                ColorBgra *src_ptr   = (ColorBgra *)src.DataPtr;
                ColorBgra *dst_ptr   = (ColorBgra *)dst.DataPtr;
                int        src_width = src.Width;
                int        dst_width = dst.Width;

                for (int dstRow = 0, fDstY = fDstTop; dstRow < dst.Height && fDstY < fDstBottom; ++dstRow, fDstY += dy)
                {
                    int srcY1 = fDstY >> fpShift;                                                // y
                    int srcY2 = (fDstY + (dy >> 2)) >> fpShift;                                  // y + 0.25
                    int srcY3 = (fDstY + (dy >> 1)) >> fpShift;                                  // y + 0.50
                    int srcY4 = (fDstY + (dy >> 1) + (dy >> 2)) >> fpShift;                      // y + 0.75

                    ColorBgra *src1        = src.GetRowAddressUnchecked(src_ptr, src_width, srcY1);
                    ColorBgra *src2        = src.GetRowAddressUnchecked(src_ptr, src_width, srcY2);
                    ColorBgra *src3        = src.GetRowAddressUnchecked(src_ptr, src_width, srcY3);
                    ColorBgra *src4        = src.GetRowAddressUnchecked(src_ptr, src_width, srcY4);
                    ColorBgra *dstPtr      = dst.GetRowAddressUnchecked(dst_ptr, dst_width, dstRow);
                    int        checkerY    = dstRow + offset.Y;
                    int        checkerX    = offset.X;
                    int        maxCheckerX = checkerX + dst.Width;

                    for (int fDstX = fDstLeft; checkerX < maxCheckerX && fDstX < fDstRight; ++checkerX, fDstX += dx)
                    {
                        int        srcX1 = (fDstX + (dx >> 2)) >> fpShift;                              // x + 0.25
                        int        srcX2 = (fDstX + (dx >> 1) + (dx >> 2)) >> fpShift;                  // x + 0.75
                        int        srcX3 = fDstX >> fpShift;                                            // x
                        int        srcX4 = (fDstX + (dx >> 1)) >> fpShift;                              // x + 0.50
                        ColorBgra *p1    = src1 + srcX1;
                        ColorBgra *p2    = src2 + srcX2;
                        ColorBgra *p3    = src3 + srcX3;
                        ColorBgra *p4    = src4 + srcX4;

                        int r = (2 + p1->R + p2->R + p3->R + p4->R) >> 2;
                        int g = (2 + p1->G + p2->G + p3->G + p4->G) >> 2;
                        int b = (2 + p1->B + p2->B + p3->B + p4->B) >> 2;
                        int a = (2 + p1->A + p2->A + p3->A + p4->A) >> 2;

                        // Blend it over the checkerboard background
                        if (checker)
                        {
                            *dstPtr = checker_op.Apply(ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24)), checkerX, checkerY);
                        }
                        else
                        {
                            *dstPtr = blend_op.Apply(*dstPtr, ColorBgra.FromUInt32((uint)b + ((uint)g << 8) + ((uint)r << 16) + ((uint)a << 24)));
                        }

                        ++dstPtr;
                    }
                }

                // Only checker the first layer
                checker = false;
            }
        }
Пример #17
0
        /// <summary>
        /// Sets global effect parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <param name="dstArgs">The destination picture arguments.</param>
        /// <param name="srcArgs">The source picture arguments.</param>
        protected override void OnSetRenderInfo(PropertyBasedEffectConfigToken parameters, RenderArgs dstArgs, RenderArgs srcArgs)
        {
            int color = parameters.GetProperty <Int32Property>("Color").Value;

            _selectedColor = YCbCrColor.FromRgb(ColorBgra.FromUInt32((UInt32)color));
        }