Ejemplo n.º 1
0
 public void SetRecieveBlender(IRecieveBlenderByte value)
 {
     if (BitDepth != 0 && value != null && value.NumPixelBits != BitDepth)
     {
         throw new NotSupportedException("The blender has to support the bit depth of this image.");
     }
     recieveBlender = value;
 }
Ejemplo n.º 2
0
        // Compute a fixed color from a source and a target alpha
        public static Color Blend(this IRecieveBlenderByte blender, Color start, Color blend)
        {
            var result = new byte[] { start.blue, start.green, start.red, start.alpha };

            blender.BlendPixel(result, 0, blend);

            return(new Color(result[2], result[1], result[0], result[3]));
        }
Ejemplo n.º 3
0
        public void Attach(IImageByte sourceImage, IRecieveBlenderByte recieveBlender, int distanceBetweenPixelsInclusive, int bufferOffset, int bitsPerPixel)
        {
            SetDimmensionAndFormat(sourceImage.Width, sourceImage.Height, sourceImage.StrideInBytes(), bitsPerPixel, distanceBetweenPixelsInclusive, false);
            int offset = sourceImage.GetBufferOffsetXY(0, 0);

            byte[] buffer = sourceImage.GetBuffer();
            SetBuffer(buffer, offset + bufferOffset);
            SetRecieveBlender(recieveBlender);
        }
Ejemplo n.º 4
0
        public ImageBuffer(IImageByte sourceImage, IRecieveBlenderByte recieveBlender)
        {
            SetDimmensionAndFormat(sourceImage.Width, sourceImage.Height, sourceImage.StrideInBytes(), sourceImage.BitDepth, sourceImage.GetBytesBetweenPixelsInclusive(), true);
            int offset = sourceImage.GetBufferOffsetXY(0, 0);

            byte[] buffer    = sourceImage.GetBuffer();
            byte[] newBuffer = new byte[buffer.Length];
            agg_basics.memcpy(newBuffer, offset, buffer, offset, buffer.Length - offset);
            SetBuffer(newBuffer, offset);
            SetRecieveBlender(recieveBlender);
        }
Ejemplo n.º 5
0
        public ImageBuffer(IImageByte sourceImageToCopy, IRecieveBlenderByte blender, int distanceBetweenPixelsInclusive, int bufferOffset, int bitsPerPixel)
        {
            SetDimmensionAndFormat(sourceImageToCopy.Width, sourceImageToCopy.Height, sourceImageToCopy.StrideInBytes(), bitsPerPixel, distanceBetweenPixelsInclusive, true);
            int offset = sourceImageToCopy.GetBufferOffsetXY(0, 0);

            byte[] buffer    = sourceImageToCopy.GetBuffer();
            byte[] newBuffer = new byte[buffer.Length];
            agg_basics.memcpy(newBuffer, offset, buffer, offset, buffer.Length - offset);
            SetBuffer(newBuffer, offset + bufferOffset);
            SetRecieveBlender(blender);
        }
Ejemplo n.º 6
0
        public static void BasedOnAlpha(IRecieveBlenderByte recieveBlender, byte[] destBuffer, int bufferOffset, RGBA_Bytes sourceColor)
        {
            //if (sourceColor.m_A != 0)
            {
#if false // we blend regardless of the alpha so that we can get Light Opacity working (used this way we have addative and faster blending in one blender) LBB
                if (sourceColor.m_A == base_mask)
                {
                    Blender.CopyPixel(pDestBuffer, sourceColor);
                }
                else
#endif
                {
                    recieveBlender.BlendPixel(destBuffer, bufferOffset, sourceColor);
                }
            }
        }
Ejemplo n.º 7
0
        public override void OnDraw(Graphics2D graphics2D)
        {
            double numSecondsSinceLastDraw = timeSinceLastDraw.Elapsed.TotalSeconds;

            timeSinceLastDraw.Restart();

            Button parentButton = (Button)Parent;

            double x = parentButton.Width / 2 - normalImage.Width / 2;
            double y = parentButton.Height / 2 - normalImage.Height / 2;

            if (!parentButton.Enabled)
            {
                graphics2D.Render(disabledImage, x, y);
                base.OnDraw(graphics2D);
                return;
            }

            if (parentButton.UnderMouseState == UI.UnderMouseState.FirstUnderMouse)
            {
                if (parentButton.MouseDownOnWidget)
                {
                    graphics2D.Render(pressedImage, x, y);
                }
                else
                {
                    if (NumSecondsToFade > 0)
                    {
                        if (hoverOpacity < 1)
                        {
                            graphics2D.Render(normalImage, x, y);
                        }
                        IRecieveBlenderByte oldBlender = null;
                        if (graphics2D.DestImage != null)
                        {
                            oldBlender = graphics2D.DestImage.GetRecieveBlender();
                            graphics2D.DestImage.SetRecieveBlender(new BlenderPolyColorPreMultBGRA(new Color(1, 1, 1, hoverOpacity)));
                        }
                        graphics2D.Render(hoverImage, x, y);
                        if (graphics2D.DestImage != null)
                        {
                            graphics2D.DestImage.SetRecieveBlender(oldBlender);
                        }
                    }
                    else
                    {
                        graphics2D.Render(hoverImage, x, y);
                    }
                }

                if (NumSecondsToFade > 0)
                {
                    hoverOpacity += numSecondsSinceLastDraw / NumSecondsToFade;
                }
                if (hoverOpacity > 1)
                {
                    hoverOpacity = 1;
                }
            }
            else
            {
                graphics2D.Render(normalImage, x, y);
                if (NumSecondsToFade > 0 && hoverOpacity > 0)
                {
                    IRecieveBlenderByte oldBlender = null;
                    if (graphics2D.DestImage != null)
                    {
                        oldBlender = graphics2D.DestImage.GetRecieveBlender();
                        graphics2D.DestImage.SetRecieveBlender(new BlenderPolyColorPreMultBGRA(new Color(1, 1, 1, hoverOpacity)));
                    }

                    graphics2D.Render(hoverImage, x, y);
                    if (graphics2D.DestImage != null)
                    {
                        graphics2D.DestImage.SetRecieveBlender(oldBlender);
                    }
                }

                if (NumSecondsToFade > 0)
                {
                    hoverOpacity -= numSecondsSinceLastDraw / NumSecondsToFade;
                }
                if (hoverOpacity < 0)
                {
                    hoverOpacity = 0;
                }
            }

            base.OnDraw(graphics2D);
        }
Ejemplo n.º 8
0
 public ImageBuffer(IRecieveBlenderByte recieveBlender)
 {
     SetRecieveBlender(recieveBlender);
 }
Ejemplo n.º 9
0
		public static void BasedOnAlphaAndCover(IRecieveBlenderByte recieveBlender, byte[] destBuffer, int bufferOffset, RGBA_Bytes sourceColor, int cover)
		{
			if (cover == 255)
			{
				BasedOnAlpha(recieveBlender, destBuffer, bufferOffset, sourceColor);
			}
			else
			{
				//if (sourceColor.m_A != 0)
				{
					sourceColor.alpha = (byte)((sourceColor.alpha * (cover + 1)) >> 8);
#if false // we blend regardless of the alpha so that we can get Light Opacity working (used this way we have additive and faster blending in one blender) LBB
                    if (sourceColor.m_A == base_mask)
                    {
                        Blender.CopyPixel(pDestBuffer, sourceColor);
                    }
                    else
#endif
					{
						recieveBlender.BlendPixel(destBuffer, bufferOffset, sourceColor);
					}
				}
			}
		}
Ejemplo n.º 10
0
 public void Attach(IImageByte sourceImage, IRecieveBlenderByte recieveBlender)
 {
     Attach(sourceImage, recieveBlender, sourceImage.GetBytesBetweenPixelsInclusive(), 0, sourceImage.BitDepth);
 }
Ejemplo n.º 11
0
		public void Allocate(int width, int height, int bitsPerPixel, IRecieveBlenderByte recieveBlender)
		{
			Allocate(width, height, width * (bitsPerPixel / 8), bitsPerPixel);
			SetRecieveBlender(recieveBlender);
		}
Ejemplo n.º 12
0
        /// <summary>
        /// Download an image from the web into the specified ImageBuffer
        /// </summary>
        /// <param name="uri"></param>
        public static void RetrieveImageAsync(ImageBuffer imageToLoadInto, string uriToLoad, bool scaleToImageX, IRecieveBlenderByte scalingBlender = null)
        {
            var longHash      = uriToLoad.GetLongHashCode();
            var imageFileName = ApplicationController.CacheablePath("Images", longHash.ToString() + ".png");

            if (File.Exists(imageFileName))
            {
                try
                {
                    LoadImageInto(imageToLoadInto, scaleToImageX, scalingBlender, new StreamReader(imageFileName).BaseStream);
                    return;
                }
                catch
                {
                }
            }

            WebClient client = new WebClient();

            client.DownloadDataCompleted += (sender, e) =>
            {
                try                 // if we get a bad result we can get a target invocation exception. In that case just don't show anything
                {
                    Stream stream = new MemoryStream(e.Result);

                    LoadImageInto(imageToLoadInto, scaleToImageX, scalingBlender, stream);

                    if (imageToLoadInto.Width > 0 &&
                        imageToLoadInto.Height > 0 &&
                        !savedImages.Contains(imageFileName))
                    {
                        savedImages.Add(imageFileName);
                        AggContext.ImageIO.SaveImageData(imageFileName, imageToLoadInto);
                    }
                }
                catch
                {
                }
            };

            try
            {
                client.DownloadDataAsync(new Uri(uriToLoad));
            }
            catch
            {
            }
        }
Ejemplo n.º 13
0
		public void SetRecieveBlender(IRecieveBlenderByte value)
		{
			if (BitDepth != 0 && value != null && value.NumPixelBits != BitDepth)
			{
				throw new NotSupportedException("The blender has to support the bit depth of this image.");
			}
			recieveBlender = value;
		}
Ejemplo n.º 14
0
		public void SetRecieveBlender(IRecieveBlenderByte value)
		{
			linkedImage.SetRecieveBlender(value);
		}
Ejemplo n.º 15
0
 public void Allocate(int width, int height, int bitsPerPixel, IRecieveBlenderByte recieveBlender)
 {
     Allocate(width, height, width * (bitsPerPixel / 8), bitsPerPixel);
     SetRecieveBlender(recieveBlender);
 }
Ejemplo n.º 16
0
 public void SetRecieveBlender(IRecieveBlenderByte value)
 {
     linkedImage.SetRecieveBlender(value);
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Download an image from the web into the specified ImageBuffer
        /// </summary>
        /// <param name="uri"></param>
        public void DownloadToImageAsync(ImageBuffer imageToLoadInto, string uriToLoad, bool scaleToImageX, IRecieveBlenderByte scalingBlender = null)
        {
            if (scalingBlender == null)
            {
                scalingBlender = new BlenderBGRA();
            }

            WebClient client = new WebClient();

            client.DownloadDataCompleted += (object sender, DownloadDataCompletedEventArgs e) =>
            {
                try                 // if we get a bad result we can get a target invocation exception. In that case just don't show anything
                {
                    // scale the loaded image to the size of the target image
                    byte[]      raw           = e.Result;
                    Stream      stream        = new MemoryStream(raw);
                    ImageBuffer unScaledImage = new ImageBuffer(10, 10);
                    if (scaleToImageX)
                    {
                        StaticData.Instance.LoadImageData(stream, unScaledImage);
                        // If the source image (the one we downloaded) is more than twice as big as our dest image.
                        while (unScaledImage.Width > imageToLoadInto.Width * 2)
                        {
                            // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
                            // So we scale as many times as we need to to get the Image to be the right size.
                            // If this were going to be a non-uniform scale we could do the x and y separately to get better results.
                            ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender);
                            halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
                            unScaledImage = halfImage;
                        }

                        double finalScale = imageToLoadInto.Width / (double)unScaledImage.Width;
                        imageToLoadInto.Allocate(imageToLoadInto.Width, (int)(unScaledImage.Height * finalScale), imageToLoadInto.Width * (imageToLoadInto.BitDepth / 8), imageToLoadInto.BitDepth);
                        imageToLoadInto.NewGraphics2D().Render(unScaledImage, 0, 0, 0, finalScale, finalScale);
                    }
                    else
                    {
                        StaticData.Instance.LoadImageData(stream, imageToLoadInto);
                    }
                    imageToLoadInto.MarkImageChanged();
                }
                catch
                {
                }
            };

            try
            {
                client.DownloadDataAsync(new Uri(uriToLoad));
            }
            catch
            {
            }
        }
		public void SetScalingBlender(IRecieveBlenderByte blender) { scalingBlender = blender; }
Ejemplo n.º 19
0
		public ImageBuffer(IImageByte sourceImage, IRecieveBlenderByte recieveBlender)
		{
			SetDimmensionAndFormat(sourceImage.Width, sourceImage.Height, sourceImage.StrideInBytes(), sourceImage.BitDepth, sourceImage.GetBytesBetweenPixelsInclusive(), true);
			int offset = sourceImage.GetBufferOffsetXY(0, 0);
			byte[] buffer = sourceImage.GetBuffer();
			byte[] newBuffer = new byte[buffer.Length];
			agg_basics.memcpy(newBuffer, offset, buffer, offset, buffer.Length - offset);
			SetBuffer(newBuffer, offset);
			SetRecieveBlender(recieveBlender);
		}
Ejemplo n.º 20
0
		public ImageBuffer(IRecieveBlenderByte recieveBlender)
		{
			SetRecieveBlender(recieveBlender);
		}
Ejemplo n.º 21
0
        public void DrawTo(Graphics2D graphics2D, Mesh meshToDraw, RGBA_Bytes partColorIn, double minZ, double maxZ)
        {
            RGBA_Floats partColor = partColorIn.GetAsRGBA_Floats();

            graphics2D.Rasterizer.gamma(new gamma_power(.3));
            RenderPoint[] points = new RenderPoint[3] {
                new RenderPoint(), new RenderPoint(), new RenderPoint()
            };

            foreach (Face face in meshToDraw.Faces)
            {
                int     i      = 0;
                Vector3 normal = Vector3.TransformVector(face.normal, trackballTumbleWidget.ModelviewMatrix).GetNormal();
                if (normal.z > 0)
                {
                    foreach (FaceEdge faceEdge in face.FaceEdges())
                    {
                        points[i].position = trackballTumbleWidget.GetScreenPosition(faceEdge.firstVertex.Position);

                        Vector3 transformedPosition = Vector3.TransformPosition(faceEdge.firstVertex.Position, trackballTumbleWidget.ModelviewMatrix);
                        points[i].z = transformedPosition.z;
                        i++;
                    }

                    RGBA_Floats polyDrawColor = new RGBA_Floats();
                    double      L             = Vector3.Dot(lightNormal, normal);
                    if (L > 0.0f)
                    {
                        polyDrawColor = partColor * lightIllumination * L;
                    }

                    polyDrawColor = RGBA_Floats.ComponentMax(polyDrawColor, partColor * ambiantIllumination);
                    for (i = 0; i < 3; i++)
                    {
                        double ratio      = (points[i].z - minZ) / (maxZ - minZ);
                        int    ratioInt16 = (int)(ratio * 65536);
                        points[i].color = new RGBA_Bytes(polyDrawColor.Red0To255, ratioInt16 >> 8, ratioInt16 & 0xFF);
                    }


#if true
                    scanline_unpacked_8 sl  = new scanline_unpacked_8();
                    ScanlineRasterizer  ras = new ScanlineRasterizer();
                    render_gouraud(graphics2D.DestImage, sl, ras, points);
#else
                    IRecieveBlenderByte oldBlender = graphics2D.DestImage.GetRecieveBlender();
                    graphics2D.DestImage.SetRecieveBlender(new BlenderZBuffer());
                    graphics2D.Render(polygonProjected, renderColor);
                    graphics2D.DestImage.SetRecieveBlender(oldBlender);
#endif

                    byte[] buffer = graphics2D.DestImage.GetBuffer();
                    int    pixels = graphics2D.DestImage.Width * graphics2D.DestImage.Height;
                    for (int pixelIndex = 0; pixelIndex < pixels; pixelIndex++)
                    {
                        buffer[pixelIndex * 4 + ImageBuffer.OrderR] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
                        buffer[pixelIndex * 4 + ImageBuffer.OrderG] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
                        buffer[pixelIndex * 4 + ImageBuffer.OrderB] = buffer[pixelIndex * 4 + ImageBuffer.OrderR];
                    }
                }
            }
        }
Ejemplo n.º 22
0
		public void Attach(IImageByte sourceImage, IRecieveBlenderByte recieveBlender, int distanceBetweenPixelsInclusive, int bufferOffset, int bitsPerPixel)
		{
			SetDimmensionAndFormat(sourceImage.Width, sourceImage.Height, sourceImage.StrideInBytes(), bitsPerPixel, distanceBetweenPixelsInclusive, false);
			int offset = sourceImage.GetBufferOffsetXY(0, 0);
			byte[] buffer = sourceImage.GetBuffer();
			SetBuffer(buffer, offset + bufferOffset);
			SetRecieveBlender(recieveBlender);
		}
Ejemplo n.º 23
0
        private static void LoadImageInto(ImageBuffer imageToLoadInto, bool scaleToImageX, IRecieveBlenderByte scalingBlender, Stream stream)
        {
            if (scalingBlender == null)
            {
                scalingBlender = new BlenderBGRA();
            }

            ImageBuffer unScaledImage = new ImageBuffer(10, 10);

            if (scaleToImageX)
            {
                // scale the loaded image to the size of the target image
                AggContext.StaticData.LoadImageData(stream, unScaledImage);

                // If the source image (the one we downloaded) is more than twice as big as our dest image.
                while (unScaledImage.Width > imageToLoadInto.Width * 2)
                {
                    // The image sampler we use is a 2x2 filter so we need to scale by a max of 1/2 if we want to get good results.
                    // So we scale as many times as we need to get the Image to be the right size.
                    // If this were going to be a non-uniform scale we could do the x and y separately to get better results.
                    ImageBuffer halfImage = new ImageBuffer(unScaledImage.Width / 2, unScaledImage.Height / 2, 32, scalingBlender);
                    halfImage.NewGraphics2D().Render(unScaledImage, 0, 0, 0, halfImage.Width / (double)unScaledImage.Width, halfImage.Height / (double)unScaledImage.Height);
                    unScaledImage = halfImage;
                }

                double finalScale = imageToLoadInto.Width / (double)unScaledImage.Width;
                imageToLoadInto.Allocate(imageToLoadInto.Width, (int)(unScaledImage.Height * finalScale), imageToLoadInto.Width * (imageToLoadInto.BitDepth / 8), imageToLoadInto.BitDepth);
                imageToLoadInto.NewGraphics2D().Render(unScaledImage, 0, 0, 0, finalScale, finalScale);
                imageToLoadInto.MarkImageChanged();
            }
            else
            {
                AggContext.StaticData.LoadImageData(stream, imageToLoadInto);
                imageToLoadInto.MarkImageChanged();
            }
        }
Ejemplo n.º 24
0
		public ImageBuffer(IImageByte sourceImageToCopy, IRecieveBlenderByte blender, int distanceBetweenPixelsInclusive, int bufferOffset, int bitsPerPixel)
		{
			SetDimmensionAndFormat(sourceImageToCopy.Width, sourceImageToCopy.Height, sourceImageToCopy.StrideInBytes(), bitsPerPixel, distanceBetweenPixelsInclusive, true);
			int offset = sourceImageToCopy.GetBufferOffsetXY(0, 0);
			byte[] buffer = sourceImageToCopy.GetBuffer();
			byte[] newBuffer = new byte[buffer.Length];
			agg_basics.memcpy(newBuffer, offset, buffer, offset, buffer.Length - offset);
			SetBuffer(newBuffer, offset + bufferOffset);
			SetRecieveBlender(blender);
		}
 public void SetScalingBlender(IRecieveBlenderByte blender)
 {
     scalingBlender = blender;
 }
Ejemplo n.º 26
0
		public void Attach(IImageByte sourceImage, IRecieveBlenderByte recieveBlender)
		{
			Attach(sourceImage, recieveBlender, sourceImage.GetBytesBetweenPixelsInclusive(), 0, sourceImage.BitDepth);
		}