private static Func<int, int, byte> GetTransitionAlphaFunc(EdgeTransition edgeTransition, CornerTransition cornerTransition, int tileSize, float innerRadius, float outerRadius, float _255OverRadiusDiff)
 {
     if (edgeTransition != EdgeTransition.None)
     {
         return GetEdgeOpacityAlphaFunc((byte)edgeTransition, tileSize, innerRadius, outerRadius, _255OverRadiusDiff);
     }
     if (cornerTransition != CornerTransition.None)
     {
         return GetCornerOpacityAlphaFunc((byte)cornerTransition, tileSize, innerRadius, outerRadius, _255OverRadiusDiff);
     }
     return (x, y) => 1;
 }
        public static Image CreateAutoTransitionImage(Image img, int tileSize, EdgeTransition edgeTransition, CornerTransition cornerTransition, float innerRadius, float outerRadius)
        {
            var alphaFunc = GetTransitionAlphaFunc(edgeTransition, cornerTransition, tileSize, innerRadius, outerRadius, (float)(255.0 / (outerRadius - innerRadius)));

            using (var sourceBmp = new Bitmap(img))
            {
                var bitLock = sourceBmp.LockBits(new Rectangle(0, 0, img.Width, img.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb);
                try
                {
                    float _255OverRadiusDiff = 255.0f / (outerRadius - innerRadius);
                    unsafe
                    {
                        byte* srcImg = (byte*)bitLock.Scan0.ToPointer();
                        byte[] destData = new byte[img.Width * img.Height * 4];
                        int offset = 0;
                        fixed (byte* dstImg = &destData[0])
                        {
                            for (var y = 0; y < img.Height; ++y)
                            {
                                for (var x = 0; x < img.Width; ++x, offset += 4)
                                {
                                    dstImg[offset + 0] = srcImg[offset + 0];
                                    dstImg[offset + 1] = srcImg[offset + 1];
                                    dstImg[offset + 2] = srcImg[offset + 2];
                                    dstImg[offset + 3] = alphaFunc(x, y);
                                }
                            }
                            return new Bitmap(img.Width, img.Height, img.Width * 4, PixelFormat.Format32bppArgb, (IntPtr)dstImg);
                        }
                    }
                }
                finally
                {
                    sourceBmp.UnlockBits(bitLock);
                }
            }

        }
Example #3
0
 private TileInfo CreateTileInfo(TileSet sourceTileSet, string path, EdgeTransition edgeTransition, CornerTransition cornerTransition)
 {
     if (path == null)
     {
         return new TileInfo { Path = sourceTileSet.BaseTilePath, CornerTransition = cornerTransition, EdgeTransition = edgeTransition, AutoTransition = true };
     }
     bool flipHorizontal = false;
     bool flipVertical = false;
     if (path.Contains("{hflip}"))
     {
         path = path.Replace("{hflip}", "");
         flipHorizontal = true;
     }
     if (path.Contains("{vflip}"))
     {
         path = path.Replace("{vflip}", "");
         flipVertical = true;
     }
     return new TileInfo { Path = path, FlipHorizontal = flipHorizontal, FlipVertical = flipVertical, CornerTransition = cornerTransition, EdgeTransition = edgeTransition, AutoTransition = false };
 }
Example #4
0
 public void SetCornerTilePath(CornerTransition transition, string path)
 {
     CornerTilePaths[(int)transition] = path;
 }