Ejemplo n.º 1
0
        public Present Evaluate(Present[] paramList)
        {
            Present result;

            try
            {
                TileAddress ta         = (TileAddress)paramList[0];
                string      renderPath = namingScheme.GetRenderPath(ta);
                if (File.Exists(renderPath))
                {
                    GDIBigLockedImage gDIBigLockedImage = GDIBigLockedImage.FromFile(renderPath);
                    gDIBigLockedImage.CopyPixels();
                    result = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
                }
                else
                {
                    result = new BeyondImageBounds();
                }
            }
            catch (Exception ex)
            {
                result = new PresentFailureCode(ex);
            }

            return(result);
        }
Ejemplo n.º 2
0
        internal Present Render(MapRectangle mapRect, Size size, bool useDocumentTransparency, bool exactColors)
        {
            Monitor.Enter(this);
            Present result;

            try
            {
                RectangleD rectangleD  = new RectangleD(mapRect.lon0 * (double)this.boundingBox.Width - 0.5, -mapRect.lat1 * (double)this.boundingBox.Height + (double)this.actualBoundingBox.Height - 0.5, (mapRect.lon1 - mapRect.lon0) * (double)this.boundingBox.Width + (double)this.hackRectangleAdjust, (mapRect.lat1 - mapRect.lat0) * (double)this.boundingBox.Height + (double)this.hackRectangleAdjust);
                RectangleD rectangleD2 = new RectangleD(0.0, 0.0, (double)size.Width, (double)size.Height);
                this.Reclip(this.actualBoundingBox, ref rectangleD, ref rectangleD2);
                D.Say(10, string.Format("Rendering {0} from {1}", mapRect, rectangleD));
                GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(size, "GDIVerb");
                if (exactColors)
                {
                    gDIBigLockedImage.SetInterpolationMode(InterpolationMode.NearestNeighbor);
                }
                else
                {
                    gDIBigLockedImage.SetInterpolationMode(InterpolationMode.HighQualityBicubic);
                }
                gDIBigLockedImage.DrawImageOntoThis(this.loadedImage, rectangleD2.ToRectangleF(), rectangleD.ToRectangleF());
                result = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
            }
            finally
            {
                Monitor.Exit(this);
            }
            return(result);
        }
Ejemplo n.º 3
0
        public Present Evaluate(Present[] paramList)
        {
            D.Assert(paramList.Length == 2);
            MapRectangle value        = ((MapRectangleParameter)paramList[0]).value;
            Size         value2       = ((SizeParameter)paramList[1]).value;
            MapRectangle mapRectangle = value.Transform(imageTransformer.getDestLatLonToSourceTransformer())
                                        .GrowFraction(0.05);
            Present present = warpedBoundsFuture.Realize("WarpImageVerb.Evaluate-bounds");

            if (present is BoundsPresent)
            {
                MapRectangle boundingBox = ((BoundsPresent)present).GetRenderRegion().GetBoundingBox();
                if (!boundingBox.intersects(value))
                {
                    return(new BeyondImageBounds());
                }
            }

            Present present2 = sourceMapSupplier.Curry(new ParamDict(new object[]
            {
                TermName.ImageBounds, new MapRectangleParameter(mapRectangle)
            })).Realize("WarpImageVerb.Evaluate");

            if (present2 is PresentFailureCode)
            {
                return(present2);
            }

            ImageRef          imageRef          = (ImageRef)present2;
            GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(value2, "WarpImageVerb");

            imageTransformer.doTransformImage(imageRef.image, mapRectangle, gDIBigLockedImage, value);
            imageRef.Dispose();
            return(new ImageRef(new ImageRefCounted(gDIBigLockedImage)));
        }
Ejemplo n.º 4
0
		internal Present Render(MapRectangle mapRect, Size size, bool useDocumentTransparency, bool exactColors)
		{
			Monitor.Enter(this);
			Present result;
			try
			{
				RectangleD rectangleD = new RectangleD(mapRect.lon0 * (double)this.boundingBox.Width - 0.5, -mapRect.lat1 * (double)this.boundingBox.Height + (double)this.actualBoundingBox.Height - 0.5, (mapRect.lon1 - mapRect.lon0) * (double)this.boundingBox.Width + (double)this.hackRectangleAdjust, (mapRect.lat1 - mapRect.lat0) * (double)this.boundingBox.Height + (double)this.hackRectangleAdjust);
				RectangleD rectangleD2 = new RectangleD(0.0, 0.0, (double)size.Width, (double)size.Height);
				this.Reclip(this.actualBoundingBox, ref rectangleD, ref rectangleD2);
				D.Say(10, string.Format("Rendering {0} from {1}", mapRect, rectangleD));
				GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(size, "GDIVerb");
				if (exactColors)
				{
					gDIBigLockedImage.SetInterpolationMode(InterpolationMode.NearestNeighbor);
				}
				else
				{
					gDIBigLockedImage.SetInterpolationMode(InterpolationMode.HighQualityBicubic);
				}
				gDIBigLockedImage.DrawImageOntoThis(this.loadedImage, rectangleD2.ToRectangleF(), rectangleD.ToRectangleF());
				result = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
			}
			finally
			{
				Monitor.Exit(this);
			}
			return result;
		}
Ejemplo n.º 5
0
		public Present Evaluate(Present[] paramList)
		{
			D.Assert(paramList.Length == 3);
			for (int i = 0; i < paramList.Length; i++)
			{
				Present present = paramList[i];
				if (present is PresentFailureCode)
				{
					return present;
				}
			}
			if (!(paramList[0] is ImageRef))
			{
				return paramList[0];
			}
			ImageRef imageRef = (ImageRef)paramList[0];
			TileAddress tileAddress = (TileAddress)paramList[1];
			BoundsPresent boundsPresent = (BoundsPresent)paramList[2];
			MapRectangle mapWindow = CoordinateSystemUtilities.TileAddressToMapRectangle(this.coordinateSystem, tileAddress);
			Region clipRegion = boundsPresent.GetRenderRegion().GetClipRegion(mapWindow, tileAddress.ZoomLevel, this.coordinateSystem);
			GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(imageRef.image.Size, "UserClipperVerb");
			gDIBigLockedImage.SetClip(clipRegion);
			gDIBigLockedImage.DrawImageOntoThis(imageRef.image, new RectangleF(0f, 0f, (float)gDIBigLockedImage.Size.Width, (float)gDIBigLockedImage.Size.Height), new RectangleF(0f, 0f, (float)imageRef.image.Size.Width, (float)imageRef.image.Size.Height));
			ImageRef result = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
			boundsPresent.Dispose();
			imageRef.Dispose();
			return result;
		}
Ejemplo n.º 6
0
 public unsafe static void ReplaceAlphaChannel(ImageRef target, ImageRef alphaOperand)
 {
     lock (target.image)
     {
         lock (alphaOperand.image)
         {
             Image        image      = target.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
             Image        image2     = alphaOperand.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
             Bitmap       bitmap     = (Bitmap)image;
             Bitmap       bitmap2    = (Bitmap)image2;
             BitmapData   bitmapdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
             BitmapData   data2      = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
             PixelStruct *structPtr  = (PixelStruct *)bitmapdata.Scan0;
             PixelStruct *structPtr3 = (PixelStruct *)data2.Scan0;
             int          width      = bitmapdata.Width;
             int          height     = bitmapdata.Height;
             int          num3       = bitmapdata.Stride / sizeof(PixelStruct);
             for (int i = 0; i < height; i++)
             {
                 int          num4       = 0;
                 PixelStruct *structPtr2 = structPtr + (i * num3);
                 for (PixelStruct *structPtr4 = structPtr3 + (i * num3); num4 < width; structPtr4++)
                 {
                     structPtr2->a = structPtr4->a;
                     num4++;
                     structPtr2++;
                 }
             }
             bitmap.UnlockBits(bitmapdata);
             bitmap2.UnlockBits(data2);
         }
     }
 }
Ejemplo n.º 7
0
        public Present Evaluate(Present[] paramList)
        {
            D.Assert(paramList.Length == 3);
            for (int i = 0; i < paramList.Length; i++)
            {
                Present present = paramList[i];
                if (present is PresentFailureCode)
                {
                    return(present);
                }
            }
            if (!(paramList[0] is ImageRef))
            {
                return(paramList[0]);
            }
            ImageRef          imageRef          = (ImageRef)paramList[0];
            TileAddress       tileAddress       = (TileAddress)paramList[1];
            BoundsPresent     boundsPresent     = (BoundsPresent)paramList[2];
            MapRectangle      mapWindow         = CoordinateSystemUtilities.TileAddressToMapRectangle(this.coordinateSystem, tileAddress);
            Region            clipRegion        = boundsPresent.GetRenderRegion().GetClipRegion(mapWindow, tileAddress.ZoomLevel, this.coordinateSystem);
            GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(imageRef.image.Size, "UserClipperVerb");

            gDIBigLockedImage.SetClip(clipRegion);
            gDIBigLockedImage.DrawImageOntoThis(imageRef.image, new RectangleF(0f, 0f, (float)gDIBigLockedImage.Size.Width, (float)gDIBigLockedImage.Size.Height), new RectangleF(0f, 0f, (float)imageRef.image.Size.Width, (float)imageRef.image.Size.Height));
            ImageRef result = new ImageRef(new ImageRefCounted(gDIBigLockedImage));

            boundsPresent.Dispose();
            imageRef.Dispose();
            return(result);
        }
Ejemplo n.º 8
0
        public Present Evaluate(Present[] paramList)
        {
            Size value = ((SizeParameter)paramList[0]).value;
            GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(value, "CompositeImageVerb");
            Present           result;

            try
            {
                GDIBigLockedImage obj;
                Monitor.Enter(obj = gDIBigLockedImage);
                try
                {
                    Graphics graphics = gDIBigLockedImage.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheGraphics();
                    using (graphics)
                    {
                        for (int i = 1; i < paramList.Length; i++)
                        {
                            Present present = paramList[i];
                            if (present is PresentFailureCode)
                            {
                                result = new PresentFailureCode((PresentFailureCode)present, "CompositeImageVerb");
                                return(result);
                            }
                            if (!(present is ImageRef))
                            {
                                result = new PresentFailureCode(new Exception("Unexpected result of child computation in CompositeImageVerb"));
                                return(result);
                            }
                            ImageRef          imageRef = (ImageRef)present;
                            GDIBigLockedImage image;
                            Monitor.Enter(image = imageRef.image);
                            try
                            {
                                graphics.DrawImage(imageRef.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage(), new Rectangle(0, 0, value.Width, value.Height));
                            }
                            finally
                            {
                                Monitor.Exit(image);
                            }
                        }
                    }
                }
                finally
                {
                    Monitor.Exit(obj);
                }
                ImageRef imageRef2 = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
                gDIBigLockedImage = null;
                result            = imageRef2;
            }
            finally
            {
                if (gDIBigLockedImage != null)
                {
                    gDIBigLockedImage.Dispose();
                }
            }
            return(result);
        }
Ejemplo n.º 9
0
		public Present Evaluate(Present[] paramList)
		{
			Size value = ((SizeParameter)paramList[0]).value;
			GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(value, "CompositeImageVerb");
			Present result;
			try
			{
				GDIBigLockedImage obj;
				Monitor.Enter(obj = gDIBigLockedImage);
				try
				{
					Graphics graphics = gDIBigLockedImage.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheGraphics();
					using (graphics)
					{
						for (int i = 1; i < paramList.Length; i++)
						{
							Present present = paramList[i];
							if (present is PresentFailureCode)
							{
								result = new PresentFailureCode((PresentFailureCode)present, "CompositeImageVerb");
								return result;
							}
							if (!(present is ImageRef))
							{
								result = new PresentFailureCode(new Exception("Unexpected result of child computation in CompositeImageVerb"));
								return result;
							}
							ImageRef imageRef = (ImageRef)present;
							GDIBigLockedImage image;
							Monitor.Enter(image = imageRef.image);
							try
							{
								graphics.DrawImage(imageRef.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage(), new Rectangle(0, 0, value.Width, value.Height));
							}
							finally
							{
								Monitor.Exit(image);
							}
						}
					}
				}
				finally
				{
					Monitor.Exit(obj);
				}
				ImageRef imageRef2 = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
				gDIBigLockedImage = null;
				result = imageRef2;
			}
			finally
			{
				if (gDIBigLockedImage != null)
				{
					gDIBigLockedImage.Dispose();
				}
			}
			return result;
		}
Ejemplo n.º 10
0
		public static void SaveImage(ImageRef imageRef, RenderOutputMethod renderOutput, string relativeDestPath, ImageFormat imageFormat)
		{
			Stream stream = renderOutput.CreateFile(relativeDestPath, ImageTypeMapper.ByImageFormat(imageFormat).mimeType);
			using (stream)
			{
				imageRef.image.Save(stream, imageFormat);
				stream.Close();
			}
		}
Ejemplo n.º 11
0
        public Present Evaluate(Present[] paramList)
        {
            Present result;

            try
            {
                TileAddress ta = (TileAddress)paramList[0];
                if (BuildConfig.theConfig.injectTemporaryTileFailures && new Random().Next() % 2 == 0)
                {
                    result = new InjectedTileFailure();
                }
                else
                {
                    HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(GetTileURL(ta));
                    httpWebRequest.Timeout = 9000;
                    HttpWebResponse httpWebResponse;
                    try
                    {
                        httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    }
                    catch (WebException ex)
                    {
                        if (ex.Response is HttpWebResponse)
                        {
                            HttpWebResponse httpWebResponse2 = (HttpWebResponse)ex.Response;
                            if (httpWebResponse2.StatusCode == HttpStatusCode.BadRequest ||
                                httpWebResponse2.StatusCode == HttpStatusCode.NotFound)
                            {
                                result = new UnretryableFailure(ex);
                                return(result);
                            }
                        }

                        result = new RetryableFailure(ex, "Timeout waiting for tile in WebTileFetch");
                        return(result);
                    }

                    if (httpWebResponse.StatusCode != HttpStatusCode.OK)
                    {
                        throw new Exception(string.Format("HTTP {0} from web source",
                                                          httpWebResponse.StatusCode.ToString()));
                    }

                    Stream            responseStream = httpWebResponse.GetResponseStream();
                    GDIBigLockedImage image          = GDIBigLockedImage.FromStream(responseStream);
                    httpWebResponse.Close();
                    result = new ImageRef(new ImageRefCounted(image));
                }
            }
            catch (Exception ex2)
            {
                result = new PresentFailureCode(ex2);
            }

            return(result);
        }
Ejemplo n.º 12
0
		public Present Evaluate(Present[] paramList)
		{
			Present result;
			try
			{
				TileAddress ta = (TileAddress)paramList[0];
				if (BuildConfig.theConfig.injectTemporaryTileFailures && new Random().Next() % 2 == 0)
				{
					result = new InjectedTileFailure();
				}
				else
				{
					HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(this.GetTileURL(ta));
					httpWebRequest.Timeout = 9000;
					HttpWebResponse httpWebResponse;
					try
					{
						httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
					}
					catch (WebException ex)
					{
						if (ex.Response is HttpWebResponse)
						{
							HttpWebResponse httpWebResponse2 = (HttpWebResponse)ex.Response;
							if (httpWebResponse2.StatusCode == HttpStatusCode.BadRequest || httpWebResponse2.StatusCode == HttpStatusCode.NotFound)
							{
								result = new UnretryableFailure(ex);
								return result;
							}
						}
						result = new RetryableFailure(ex, "Timeout waiting for tile in WebTileFetch");
						return result;
					}
					if (httpWebResponse.StatusCode != HttpStatusCode.OK)
					{
						throw new Exception(string.Format("HTTP {0} from web source", httpWebResponse.StatusCode.ToString()));
					}
					Stream responseStream = httpWebResponse.GetResponseStream();
					GDIBigLockedImage image = GDIBigLockedImage.FromStream(responseStream);
					httpWebResponse.Close();
					result = new ImageRef(new ImageRefCounted(image));
				}
			}
			catch (Exception ex2)
			{
				result = new PresentFailureCode(ex2);
			}
			return result;
		}
Ejemplo n.º 13
0
		public ImageRef Copy()
		{
			GDIBigLockedImage image;
			Monitor.Enter(image = this.image);
			ImageRef result;
			try
			{
				Image original = this.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
				result = new ImageRef(new ImageRefCounted(new GDIBigLockedImage(new Bitmap(original))));
			}
			finally
			{
				Monitor.Exit(image);
			}
			return result;
		}
Ejemplo n.º 14
0
        public ImageRef Copy()
        {
            GDIBigLockedImage image;

            Monitor.Enter(image = this.image);
            ImageRef result;

            try
            {
                Image original = this.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                result = new ImageRef(new ImageRefCounted(new GDIBigLockedImage(new Bitmap(original))));
            }
            finally
            {
                Monitor.Exit(image);
            }
            return(result);
        }
Ejemplo n.º 15
0
        private unsafe Present FadeTile(ImageRef sourceImage, double fadeFactor)
        {
            GDIBigLockedImage image = new GDIBigLockedImage(sourceImage.image.Size, "FadeVerb");

            lock (sourceImage.image)
            {
                Image image2 = sourceImage.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                lock (image)
                {
                    Image      image3     = image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                    Bitmap     bitmap     = (Bitmap)image2;
                    Bitmap     bitmap2    = (Bitmap)image3;
                    BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height),
                                                             ImageLockMode.WriteOnly,
                                                             PixelFormat.Format32bppArgb);
                    BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height),
                                                       ImageLockMode.ReadOnly,
                                                       PixelFormat.Format32bppArgb);
                    PixelStruct *structPtr  = (PixelStruct *)bitmapdata.Scan0;
                    PixelStruct *structPtr3 = (PixelStruct *)data2.Scan0;
                    int          width      = bitmapdata.Width;
                    int          height     = bitmapdata.Height;
                    int          num3       = bitmapdata.Stride / sizeof(PixelStruct);
                    for (int i = 0; i < height; i++)
                    {
                        int num4 = 0;
                        for (PixelStruct *structPtr2 = structPtr + i * num3; num4 < width; structPtr2++)
                        {
                            PixelStruct *structPtr4 = structPtr3 + i * num3 + num4;
                            structPtr2[0] = structPtr4[0];
                            structPtr2->a = (byte)(structPtr2->a * fadeFactor);
                            num4++;
                        }
                    }

                    bitmap2.UnlockBits(bitmapdata);
                    bitmap.UnlockBits(data2);
                }
            }

            sourceImage.Dispose();
            return(new ImageRef(new ImageRefCounted(image)));
        }
Ejemplo n.º 16
0
        public Present Evaluate(Present[] paramList)
        {
            D.Assert(paramList.Length == 2);
            if (!(paramList[0] is ImageRef))
            {
                return(paramList[0]);
            }
            if (!(paramList[1] is TileAddress))
            {
                return(paramList[1]);
            }
            ImageRef    imageRef         = (ImageRef)paramList[0];
            TileAddress tileAddress      = (TileAddress)paramList[1];
            double      fadeForZoomLevel = this.fadeOptions.GetFadeForZoomLevel(tileAddress.ZoomLevel);

            if (fadeForZoomLevel == 1.0)
            {
                return(imageRef);
            }
            return(this.FadeTile(imageRef, fadeForZoomLevel));
        }
Ejemplo n.º 17
0
        public static void HaloTransparency(ImageRef source, int haloSize)
        {
            D.Assert(haloSize > 0 && haloSize < 100);
            ImageRef          imageRef = source.Copy();
            GDIBigLockedImage image;

            Monitor.Enter(image = source.image);
            try
            {
                Image image2 = source.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                for (int i = -haloSize; i < haloSize + 1; i++)
                {
                    for (int j = -haloSize; j < haloSize + 1; j++)
                    {
                        if (i != 0 || j != 0)
                        {
                            Bitmap    bitmap   = new Bitmap(source.image.Width, source.image.Height);
                            Graphics  graphics = Graphics.FromImage(bitmap);
                            Rectangle destRect = new Rectangle(0, 0, image2.Width, image2.Height);
                            Rectangle srcRect  = new Rectangle(i, j, image2.Width, image2.Height);
                            graphics.DrawImage(image2, destRect, srcRect, GraphicsUnit.Pixel);
                            graphics.Dispose();
                            ImageRef imageRef2 = new ImageRef(new ImageRefCounted(new GDIBigLockedImage(bitmap)));
                            MaxInPlace(imageRef, imageRef2);
                            imageRef2.Dispose();
                        }
                    }
                }

                ReplaceAlphaChannel(source, imageRef);
            }
            finally
            {
                Monitor.Exit(image);
            }

            imageRef.Dispose();
        }
Ejemplo n.º 18
0
		private unsafe Present FadeTile(ImageRef sourceImage, double fadeFactor)
		{
            GDIBigLockedImage image = new GDIBigLockedImage(sourceImage.image.Size, "FadeVerb");
            lock (sourceImage.image)
            {
                Image image2 = sourceImage.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                lock (image)
                {
                    Image image3 = image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                    Bitmap bitmap = (Bitmap)image2;
                    Bitmap bitmap2 = (Bitmap)image3;
                    BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                    BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    PixelStruct* structPtr = (PixelStruct*)bitmapdata.Scan0;
                    PixelStruct* structPtr3 = (PixelStruct*)data2.Scan0;
                    int width = bitmapdata.Width;
                    int height = bitmapdata.Height;
                    int num3 = bitmapdata.Stride / sizeof(PixelStruct);
                    for (int i = 0; i < height; i++)
                    {
                        int num4 = 0;
                        for (PixelStruct* structPtr2 = structPtr + (i * num3); num4 < width; structPtr2++)
                        {
                            PixelStruct* structPtr4 = (structPtr3 + (i * num3)) + num4;
                            structPtr2[0] = structPtr4[0];
                            structPtr2->a = (byte)(structPtr2->a * fadeFactor);
                            num4++;
                        }
                    }
                    bitmap2.UnlockBits(bitmapdata);
                    bitmap.UnlockBits(data2);
                }
            }
            sourceImage.Dispose();
            return new ImageRef(new ImageRefCounted(image));
		}
Ejemplo n.º 19
0
		public Present Evaluate(Present[] paramList)
		{
			Present result;
			try
			{
				TileAddress ta = (TileAddress)paramList[0];
				string renderPath = this.namingScheme.GetRenderPath(ta);
				if (File.Exists(renderPath))
				{
					GDIBigLockedImage gDIBigLockedImage = GDIBigLockedImage.FromFile(renderPath);
					gDIBigLockedImage.CopyPixels();
					result = new ImageRef(new ImageRefCounted(gDIBigLockedImage));
				}
				else
				{
					result = new BeyondImageBounds();
				}
			}
			catch (Exception ex)
			{
				result = new PresentFailureCode(ex);
			}
			return result;
		}
Ejemplo n.º 20
0
		private void SaveTile(GDIBigLockedImage compositeImage)
		{
			try
			{
				ImageRef imageRef = new ImageRef(new ImageRefCounted(compositeImage));
				GDIBigLockedImage.Transparentness transparentness = imageRef.image.GetTransparentness();
				if (transparentness == GDIBigLockedImage.Transparentness.EntirelyTransparent)
				{
					D.Sayf(0, "skipping blank tile.", new object[0]);
				}
				else
				{
					if (this.outputTileType == OutputTileType.IPIC)
					{
						if (transparentness == GDIBigLockedImage.Transparentness.EntirelyOpaque)
						{
							this.outputTileType = OutputTileType.JPG;
						}
						else
						{
							this.outputTileType = OutputTileType.PNG;
						}
					}
					RenderOutputUtil.SaveImage(imageRef, this.renderOutput, this.outputFilename, this.outputTileType.imageFormat);
				}
				this.feedback.PostImageResult(imageRef, this.layer, "(composite)", this.address);
				imageRef.Dispose();
			}
			catch (Exception arg)
			{
				this.feedback.PostMessage(string.Format("Can't create {0}: {1}", this.outputFilename, arg));
			}
		}
Ejemplo n.º 21
0
		internal Present Render(MapRectangle mapRect, System.Drawing.Size size, bool useDocumentTransparency, bool exactColors)
		{
			Monitor.Enter(this);
			Present result;
			try
			{
				RectangleD rectangleD = new RectangleD(mapRect.lon0 * (double)this.boundingBox.Width - 0.5, -mapRect.lat1 * (double)this.boundingBox.Height + (double)this.actualBoundingBox.Height - 0.5, (mapRect.lon1 - mapRect.lon0) * (double)this.boundingBox.Width + (double)this.hackRectangleAdjust, (mapRect.lat1 - mapRect.lat0) * (double)this.boundingBox.Height + (double)this.hackRectangleAdjust);
				RectangleD rectangleD2 = rectangleD.Grow(2.0);
				RectangleD r = new RectangleD((double)this.actualBoundingBox.X, (double)this.actualBoundingBox.Y, (double)this.actualBoundingBox.Width, (double)this.actualBoundingBox.Height);
				RectangleD dest = new RectangleD(0.0, 0.0, (double)size.Width, (double)size.Height);
				ScaleAndTranslate scaleAndTranslate = new ScaleAndTranslate(rectangleD, dest);
				RectangleD rectangleD3 = rectangleD2.Intersect(r).Round();
				RectangleD rectangleD4 = scaleAndTranslate.Apply(rectangleD.Intersect(r));
				RectangleD rectangleD5 = scaleAndTranslate.Apply(rectangleD3);
				ScaleAndTranslate scaleAndTranslate2 = new ScaleAndTranslate(-rectangleD5.X, -rectangleD5.Y);
				RectangleD rectangleD6 = scaleAndTranslate2.Apply(rectangleD4);
				GDIBigLockedImage gDIBigLockedImage = new GDIBigLockedImage(size, "WPFVerb");
				GDIBigLockedImage image = gDIBigLockedImage;
				if (!rectangleD3.IntIsEmpty() && !rectangleD6.IntIsEmpty())
				{
					try
					{
						GDIBigLockedImage obj;
						Monitor.Enter(obj = gDIBigLockedImage);
						try
						{
							Bitmap bitmap = (Bitmap)gDIBigLockedImage.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
							BitmapSource source = new CroppedBitmap(this.primarySource, rectangleD3.ToInt32Rect());
							BitmapSource source2 = new TransformedBitmap(source, scaleAndTranslate.ToScaleTransform());
							BitmapSource bitmapSource = new CroppedBitmap(source2, rectangleD6.ToInt32Rect());
							Int32Rect int32Rect = rectangleD4.ToInt32Rect();
							BitmapData bitmapData = bitmap.LockBits(new Rectangle(0, 0, size.Width, size.Height), ImageLockMode.WriteOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb);
							try
							{
								IntPtr buffer = new IntPtr(bitmapData.Scan0.ToInt32() + int32Rect.Y * bitmapData.Stride + int32Rect.X * 4);
								bitmapSource.CopyPixels(new Int32Rect(0, 0, bitmapSource.PixelWidth, bitmapSource.PixelHeight), buffer, bitmapData.Stride * bitmapData.Height, bitmapData.Stride);
							}
							finally
							{
								bitmap.UnlockBits(bitmapData);
							}
						}
						finally
						{
							Monitor.Exit(obj);
						}
					}
					catch (Exception ex)
					{
						if (BigDebugKnob.theKnob.debugFeaturesEnabled)
						{
							this.LabelThisImage(gDIBigLockedImage, ex.ToString());
						}
					}
					if (useDocumentTransparency)
					{
						image = gDIBigLockedImage;
					}
					else
					{
						GDIBigLockedImage gDIBigLockedImage2 = new GDIBigLockedImage(size, "WPFVerb-untransparent");
						GDIBigLockedImage obj2;
						Monitor.Enter(obj2 = gDIBigLockedImage2);
						try
						{
							Graphics graphics = gDIBigLockedImage2.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheGraphics();
							graphics.FillRectangle(new SolidBrush(System.Drawing.Color.White), 0, 0, size.Width, size.Height);
							graphics.DrawImage(gDIBigLockedImage.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage(), 0, 0);
							graphics.Dispose();
							image = gDIBigLockedImage2;
							gDIBigLockedImage.Dispose();
						}
						finally
						{
							Monitor.Exit(obj2);
						}
					}
				}
				result = new ImageRef(new ImageRefCounted(image));
			}
			finally
			{
				Monitor.Exit(this);
			}
			return result;
		}
Ejemplo n.º 22
0
        public Present Evaluate(Present[] paramList)
        {
            D.Assert(paramList.Length == 4);
            MapRectangleParameter parameter  = (MapRectangleParameter)paramList[0];
            SizeParameter         parameter2 = (SizeParameter)paramList[1];
            Present present  = paramList[2];
            Present present2 = paramList[3];
            double  num      = Math.Min(parameter.value.LonExtent, parameter.value.LatExtent);
            int     num2     = Math.Max(parameter2.value.Width, parameter2.value.Height);

            if ((num > 1.0) && (num2 <= 0x400))
            {
                IFuture    future = this.prototype.Curry(new ParamDict(new object[] { TermName.ImageBounds, new MapRectangleParameter(this.unitRectangle), TermName.OutputSize, new SizeParameter(this.memoizedSize), TermName.UseDocumentTransparency, present, TermName.ExactColors, present2 }));
                StrongHash hash   = new StrongHash();
                future.AccumulateRobustHash(hash);
                D.Sayf(0, "Future {0} hashes to {1}", new object[] { RobustHashTools.DebugString(future), hash.ToString() });
                Present present3 = future.Realize("sourceImageDownsampler-memo");
                if (present3 is ImageRef)
                {
                    try
                    {
                        ImageRef          ref2  = (ImageRef)present3;
                        GDIBigLockedImage image = new GDIBigLockedImage(parameter2.value, "sourceImageDownsampler-downsample");
                        lock (ref2.image)
                        {
                            lock (image)
                            {
                                Graphics     graphics = image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheGraphics();
                                MapRectangle region   = parameter.value.Intersect(this.unitRectangle);
                                if (!region.IsEmpty())
                                {
                                    RectangleF srcRect  = this.SelectSubRectangle(this.unitRectangle, region, this.memoizedSize);
                                    RectangleF destRect = this.SelectSubRectangle(parameter.value, region, parameter2.value);
                                    Image      image2   = ref2.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                                    graphics.InterpolationMode = InterpolationMode.HighQualityBilinear;
                                    graphics.DrawImage(image2, destRect, srcRect, GraphicsUnit.Pixel);
                                }
                                graphics.Dispose();
                                return(new ImageRef(new ImageRefCounted(image)));
                            }
                        }
                    }
                    catch (ArgumentException)
                    {
                        return(new PresentFailureCode("Image processing overflow"));
                    }
                    catch (OverflowException)
                    {
                        return(new PresentFailureCode("Image processing overflow"));
                    }
                    catch (Exception exception)
                    {
                        return(new PresentFailureCode(exception));
                    }
                    finally
                    {
                        present3.Dispose();
                    }
                }
                return(present3);
            }
            return(this.prototype.Curry(new ParamDict(new object[] { TermName.ImageBounds, parameter, TermName.OutputSize, parameter2, TermName.UseDocumentTransparency, present, TermName.ExactColors, present2 })).Realize("sourceImageDownsampler-passthru"));
        }
Ejemplo n.º 23
0
		private void ReplacePreviewImage(ImageRef newImage)
		{
			if (this.previewImage != null)
			{
				this.previewImage.Dispose();
			}
			this.previewImage = newImage;
		}
Ejemplo n.º 24
0
        private unsafe Present Evaluate(params Present[] paramList)
        {
            D.Assert(paramList.Length == 2);
            if (!(paramList[0] is ImageRef))
            {
                return(paramList[0]);
            }
            if (!(paramList[1] is ImageRef))
            {
                return(paramList[1]);
            }
            ImageRef          ref2  = (ImageRef)paramList[0];
            ImageRef          ref3  = (ImageRef)paramList[1];
            GDIBigLockedImage image = new GDIBigLockedImage(ref2.image.Size, "TransparencyFuture");

            lock (ref2.image)
            {
                Image image2 = ref2.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                lock (ref3.image)
                {
                    Image image3 = ref3.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                    lock (image)
                    {
                        BitmapData data3;
                        Image      image4     = image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                        Bitmap     bitmap     = (Bitmap)image2;
                        Bitmap     bitmap2    = (Bitmap)image4;
                        Bitmap     bitmap3    = (Bitmap)image3;
                        BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                        BitmapData data2      = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        if (bitmap3 == bitmap)
                        {
                            data3 = data2;
                        }
                        else
                        {
                            data3 = bitmap3.LockBits(new Rectangle(0, 0, bitmap3.Width, bitmap3.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        }
                        PixelStruct *structPtr  = (PixelStruct *)bitmapdata.Scan0;
                        PixelStruct *structPtr3 = (PixelStruct *)data2.Scan0;
                        PixelStruct *structPtr5 = (PixelStruct *)data3.Scan0;
                        int          width      = bitmapdata.Width;
                        int          height     = bitmapdata.Height;
                        int          num3       = bitmapdata.Stride / sizeof(PixelStruct);
                        for (int i = 0; i < height; i++)
                        {
                            int num4 = 0;
                            for (PixelStruct *structPtr2 = structPtr + (i * num3); num4 < width; structPtr2++)
                            {
                                PixelStruct *structPtr4 = (structPtr3 + (i * num3)) + num4;
                                PixelStruct *structPtr6 = (structPtr5 + (i * num3)) + num4;
                                structPtr2[0] = structPtr4[0];
                                if (this.transparencyOptions.ShouldBeTransparent(structPtr6->r, structPtr6->g, structPtr6->b))
                                {
                                    structPtr2->a = 0;
                                }
                                num4++;
                            }
                        }
                        bitmap2.UnlockBits(bitmapdata);
                        bitmap.UnlockBits(data2);
                        if (bitmap3 != bitmap)
                        {
                            bitmap3.UnlockBits(data3);
                        }
                    }
                }
            }
            ref2.Dispose();
            ref3.Dispose();
            ImageRef source = new ImageRef(new ImageRefCounted(image));
            int      num6   = 0;

            foreach (TransparencyColor color in this.transparencyOptions.colorList)
            {
                num6 = Math.Max(num6, color.halo);
            }
            if (num6 > 0)
            {
                HaloTransparency(source, num6);
            }
            return(source);
        }
Ejemplo n.º 25
0
 public ImagePainter(ImageRef imageRef, Region clipRegion)
 {
     this.imageRef = imageRef;
     this.clipRegion = clipRegion;
 }
Ejemplo n.º 26
0
        internal Present Render(MapRectangle mapRect, System.Drawing.Size size, bool useDocumentTransparency,
                                bool exactColors)
        {
            Monitor.Enter(this);
            Present result;

            try
            {
                RectangleD rectangleD = new RectangleD(mapRect.lon0 * boundingBox.Width - 0.5,
                                                       -mapRect.lat1 * boundingBox.Height + actualBoundingBox.Height - 0.5,
                                                       (mapRect.lon1 - mapRect.lon0) * boundingBox.Width + hackRectangleAdjust,
                                                       (mapRect.lat1 - mapRect.lat0) * boundingBox.Height + hackRectangleAdjust);
                RectangleD rectangleD2 = rectangleD.Grow(2.0);
                RectangleD r           = new RectangleD(actualBoundingBox.X,
                                                        actualBoundingBox.Y,
                                                        actualBoundingBox.Width,
                                                        actualBoundingBox.Height);
                RectangleD        dest = new RectangleD(0.0, 0.0, size.Width, size.Height);
                ScaleAndTranslate scaleAndTranslate  = new ScaleAndTranslate(rectangleD, dest);
                RectangleD        rectangleD3        = rectangleD2.Intersect(r).Round();
                RectangleD        rectangleD4        = scaleAndTranslate.Apply(rectangleD.Intersect(r));
                RectangleD        rectangleD5        = scaleAndTranslate.Apply(rectangleD3);
                ScaleAndTranslate scaleAndTranslate2 = new ScaleAndTranslate(-rectangleD5.X, -rectangleD5.Y);
                RectangleD        rectangleD6        = scaleAndTranslate2.Apply(rectangleD4);
                GDIBigLockedImage gDIBigLockedImage  = new GDIBigLockedImage(size, "WPFVerb");
                GDIBigLockedImage image = gDIBigLockedImage;
                if (!rectangleD3.IntIsEmpty() && !rectangleD6.IntIsEmpty())
                {
                    try
                    {
                        GDIBigLockedImage obj;
                        Monitor.Enter(obj = gDIBigLockedImage);
                        try
                        {
                            Bitmap bitmap =
                                (Bitmap)gDIBigLockedImage.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                            BitmapSource source       = new CroppedBitmap(primarySource, rectangleD3.ToInt32Rect());
                            BitmapSource source2      = new TransformedBitmap(source, scaleAndTranslate.ToScaleTransform());
                            BitmapSource bitmapSource = new CroppedBitmap(source2, rectangleD6.ToInt32Rect());
                            Int32Rect    int32Rect    = rectangleD4.ToInt32Rect();
                            BitmapData   bitmapData   = bitmap.LockBits(new Rectangle(0, 0, size.Width, size.Height),
                                                                        ImageLockMode.WriteOnly,
                                                                        System.Drawing.Imaging.PixelFormat.Format32bppArgb);
                            try
                            {
                                IntPtr buffer = new IntPtr(bitmapData.Scan0.ToInt32() +
                                                           int32Rect.Y * bitmapData.Stride + int32Rect.X * 4);
                                bitmapSource.CopyPixels(
                                    new Int32Rect(0, 0, bitmapSource.PixelWidth, bitmapSource.PixelHeight),
                                    buffer,
                                    bitmapData.Stride * bitmapData.Height,
                                    bitmapData.Stride);
                            }
                            finally
                            {
                                bitmap.UnlockBits(bitmapData);
                            }
                        }
                        finally
                        {
                            Monitor.Exit(obj);
                        }
                    }
                    catch (Exception ex)
                    {
                        if (BigDebugKnob.theKnob.debugFeaturesEnabled)
                        {
                            LabelThisImage(gDIBigLockedImage, ex.ToString());
                        }
                    }

                    if (useDocumentTransparency)
                    {
                        image = gDIBigLockedImage;
                    }
                    else
                    {
                        GDIBigLockedImage gDIBigLockedImage2 = new GDIBigLockedImage(size, "WPFVerb-untransparent");
                        GDIBigLockedImage obj2;
                        Monitor.Enter(obj2 = gDIBigLockedImage2);
                        try
                        {
                            Graphics graphics =
                                gDIBigLockedImage2.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheGraphics();
                            graphics.FillRectangle(new SolidBrush(System.Drawing.Color.White),
                                                   0,
                                                   0,
                                                   size.Width,
                                                   size.Height);
                            graphics.DrawImage(gDIBigLockedImage.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage(),
                                               0,
                                               0);
                            graphics.Dispose();
                            image = gDIBigLockedImage2;
                            gDIBigLockedImage.Dispose();
                        }
                        finally
                        {
                            Monitor.Exit(obj2);
                        }
                    }
                }

                result = new ImageRef(new ImageRefCounted(image));
            }
            finally
            {
                Monitor.Exit(this);
            }

            return(result);
        }
Ejemplo n.º 27
0
		private void UpdatePreviewImage(ImageRef imageRef)
		{
			Monitor.Enter(this);
			try
			{
				if (this.previewImage != null)
				{
					this.previewImage.Dispose();
					this.previewImage = null;
				}
				if (imageRef != null)
				{
					this.previewImage = (ImageRef)imageRef.Duplicate("LegendOptionsPanel.UpdatePreviewImage");
				}
			}
			finally
			{
				Monitor.Exit(this);
			}
			base.Invalidate();
		}
Ejemplo n.º 28
0
		public static void HaloTransparency(ImageRef source, int haloSize)
		{
			D.Assert(haloSize > 0 && haloSize < 100);
			ImageRef imageRef = source.Copy();
			GDIBigLockedImage image;
			Monitor.Enter(image = source.image);
			try
			{
				Image image2 = source.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
				for (int i = -haloSize; i < haloSize + 1; i++)
				{
					for (int j = -haloSize; j < haloSize + 1; j++)
					{
						if (i != 0 || j != 0)
						{
							Bitmap bitmap = new Bitmap(source.image.Width, source.image.Height);
							Graphics graphics = Graphics.FromImage(bitmap);
							Rectangle destRect = new Rectangle(0, 0, image2.Width, image2.Height);
							Rectangle srcRect = new Rectangle(i, j, image2.Width, image2.Height);
							graphics.DrawImage(image2, destRect, srcRect, GraphicsUnit.Pixel);
							graphics.Dispose();
							ImageRef imageRef2 = new ImageRef(new ImageRefCounted(new GDIBigLockedImage(bitmap)));
							TransparencyFuture.MaxInPlace(imageRef, imageRef2);
							imageRef2.Dispose();
						}
					}
				}
				TransparencyFuture.ReplaceAlphaChannel(source, imageRef);
			}
			finally
			{
				Monitor.Exit(image);
			}
			imageRef.Dispose();
		}
Ejemplo n.º 29
0
        public Present Evaluate(Present[] paramList)
        {
            TileAddress tileAddress = (TileAddress)paramList[0];

            if (tileAddress.ZoomLevel <= 19)
            {
                return(veTileFetch.Curry(new ParamDict(new object[] { TermName.TileAddress, tileAddress }))
                       .Realize("VETileUpsamplerVerb"));
            }

            int         num          = tileAddress.ZoomLevel - 19;
            int         num2         = (1 << num) - 1;
            int         num3         = tileAddress.TileX & num2;
            int         num4         = tileAddress.TileY & num2;
            TileAddress tileAddress2 = new TileAddress(tileAddress.TileX >> num,
                                                       tileAddress.TileY >> num,
                                                       tileAddress.ZoomLevel - num);
            Size       size     = new Size(256, 256);
            Bitmap     image    = new Bitmap(size.Width * 3, size.Height * 3);
            Graphics   graphics = Graphics.FromImage(image);
            float      num5     = 1 << num;
            RectangleF srcRect  = new RectangleF(num3 * size.Width / num5 - 0.5f + size.Width,
                                                 num4 * size.Height / num5 - 0.5f + size.Height,
                                                 size.Width / num5,
                                                 size.Height / num5);

            for (int i = -1; i <= 1; i++)
            {
                bool flag = true;
                if (i == -1 && srcRect.X >= size.Width || i == 1 && srcRect.Right < 2 * size.Width - 1)
                {
                    flag = false;
                }

                for (int j = -1; j <= 1; j++)
                {
                    bool flag2 = true;
                    if (j == -1 && srcRect.Y >= size.Height ||
                        j == 1 && srcRect.Bottom < 2 * size.Height - 1)
                    {
                        flag2 = false;
                    }

                    if (flag && flag2)
                    {
                        TileAddress tileAddress3 = new TileAddress(tileAddress2.TileX + i,
                                                                   tileAddress2.TileY + j,
                                                                   tileAddress2.ZoomLevel);
                        Present present = veTileFetch
                                          .Curry(new ParamDict(new object[] { TermName.TileAddress, tileAddress3 }))
                                          .Realize("VETileUpsamplerVerb");
                        try
                        {
                            if (present is ImageRef)
                            {
                                ImageRef          imageRef = (ImageRef)present;
                                GDIBigLockedImage image2;
                                Monitor.Enter(image2 = imageRef.image);
                                try
                                {
                                    Rectangle srcRect2 = new Rectangle(0, 0, size.Width, size.Height);
                                    Rectangle destRect = new Rectangle(size.Width * (i + 1),
                                                                       size.Height * (j + 1),
                                                                       size.Width,
                                                                       size.Height);
                                    graphics.DrawImage(
                                        imageRef.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage(),
                                        destRect,
                                        srcRect2,
                                        GraphicsUnit.Pixel);
                                    goto IL_2B8;
                                }
                                finally
                                {
                                    Monitor.Exit(image2);
                                }
                            }

                            if (present is PresentFailureCode && i == 0 && j == 0)
                            {
                                return(new PresentFailureCode((PresentFailureCode)present, "TileWebDownloader"));
                            }

                            IL_2B8 :;
                        }
                        finally
                        {
                            present.Dispose();
                        }
                    }
                }
            }

            Bitmap   bitmap    = new Bitmap(size.Width, size.Height);
            Graphics graphics2 = Graphics.FromImage(bitmap);

            graphics2.InterpolationMode = InterpolationMode.HighQualityBicubic;
            RectangleF destRect2 = new RectangleF(0f, 0f, size.Width, size.Height);

            graphics2.DrawImage(image, destRect2, srcRect, GraphicsUnit.Pixel);
            graphics2.Dispose();
            GDIBigLockedImage image3 = new GDIBigLockedImage(bitmap);

            return(new ImageRef(new ImageRefCounted(image3)));
        }
Ejemplo n.º 30
0
		private unsafe Present Evaluate(params Present[] paramList)
		{
            D.Assert(paramList.Length == 2);
            if (!(paramList[0] is ImageRef))
            {
                return paramList[0];
            }
            if (!(paramList[1] is ImageRef))
            {
                return paramList[1];
            }
            ImageRef ref2 = (ImageRef)paramList[0];
            ImageRef ref3 = (ImageRef)paramList[1];
            GDIBigLockedImage image = new GDIBigLockedImage(ref2.image.Size, "TransparencyFuture");
            lock (ref2.image)
            {
                Image image2 = ref2.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                lock (ref3.image)
                {
                    Image image3 = ref3.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                    lock (image)
                    {
                        BitmapData data3;
                        Image image4 = image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                        Bitmap bitmap = (Bitmap)image2;
                        Bitmap bitmap2 = (Bitmap)image4;
                        Bitmap bitmap3 = (Bitmap)image3;
                        BitmapData bitmapdata = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                        BitmapData data2 = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        if (bitmap3 == bitmap)
                        {
                            data3 = data2;
                        }
                        else
                        {
                            data3 = bitmap3.LockBits(new Rectangle(0, 0, bitmap3.Width, bitmap3.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                        }
                        PixelStruct* structPtr = (PixelStruct*)bitmapdata.Scan0;
                        PixelStruct* structPtr3 = (PixelStruct*)data2.Scan0;
                        PixelStruct* structPtr5 = (PixelStruct*)data3.Scan0;
                        int width = bitmapdata.Width;
                        int height = bitmapdata.Height;
                        int num3 = bitmapdata.Stride / sizeof(PixelStruct);
                        for (int i = 0; i < height; i++)
                        {
                            int num4 = 0;
                            for (PixelStruct* structPtr2 = structPtr + (i * num3); num4 < width; structPtr2++)
                            {
                                PixelStruct* structPtr4 = (structPtr3 + (i * num3)) + num4;
                                PixelStruct* structPtr6 = (structPtr5 + (i * num3)) + num4;
                                structPtr2[0] = structPtr4[0];
                                if (this.transparencyOptions.ShouldBeTransparent(structPtr6->r, structPtr6->g, structPtr6->b))
                                {
                                    structPtr2->a = 0;
                                }
                                num4++;
                            }
                        }
                        bitmap2.UnlockBits(bitmapdata);
                        bitmap.UnlockBits(data2);
                        if (bitmap3 != bitmap)
                        {
                            bitmap3.UnlockBits(data3);
                        }
                    }
                }
            }
            ref2.Dispose();
            ref3.Dispose();
            ImageRef source = new ImageRef(new ImageRefCounted(image));
            int num6 = 0;
            foreach (TransparencyColor color in this.transparencyOptions.colorList)
            {
                num6 = Math.Max(num6, color.halo);
            }
            if (num6 > 0)
            {
                HaloTransparency(source, num6);
            }
            return source;
		}
Ejemplo n.º 31
0
		public unsafe static void ReplaceAlphaChannel(ImageRef target, ImageRef alphaOperand)
		{
            lock (target.image)
            {
                lock (alphaOperand.image)
                {
                    Image image = target.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                    Image image2 = alphaOperand.image.IPromiseIAmHoldingGDISLockSoPleaseGiveMeTheImage();
                    Bitmap bitmap = (Bitmap)image;
                    Bitmap bitmap2 = (Bitmap)image2;
                    BitmapData bitmapdata = bitmap.LockBits(new Rectangle(0, 0, bitmap.Width, bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb);
                    BitmapData data2 = bitmap2.LockBits(new Rectangle(0, 0, bitmap2.Width, bitmap2.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                    PixelStruct* structPtr = (PixelStruct*)bitmapdata.Scan0;
                    PixelStruct* structPtr3 = (PixelStruct*)data2.Scan0;
                    int width = bitmapdata.Width;
                    int height = bitmapdata.Height;
                    int num3 = bitmapdata.Stride / sizeof(PixelStruct);
                    for (int i = 0; i < height; i++)
                    {
                        int num4 = 0;
                        PixelStruct* structPtr2 = structPtr + (i * num3);
                        for (PixelStruct* structPtr4 = structPtr3 + (i * num3); num4 < width; structPtr4++)
                        {
                            structPtr2->a = structPtr4->a;
                            num4++;
                            structPtr2++;
                        }
                    }
                    bitmap.UnlockBits(bitmapdata);
                    bitmap2.UnlockBits(data2);
                }
            }
		}