Example #1
0
 internal virtual WzPngProperty ToPngProperty(WzPngProperty def)
 {
     /*if (this is WzPngProperty) return (WzPngProperty)this;
      * else if (this is WzCanvasProperty) return (WzPngProperty)WzValue;
      * else if (this is WzUOLProperty) return ToUOLLink(this).ToPngProperty(def);
      * else */return(def);
 }
        /// <summary>
        /// Loads spine texture from the specified WZ path
        /// </summary>
        /// <param name="page"></param>
        /// <param name="path"></param>
        public void Load(AtlasPage page, string path)
        {
            WzObject frameNode = this.ParentNode[path];

            if (frameNode == null)
            {
                return;
            }

            WzCanvasProperty canvasProperty = null;

            WzImageProperty imageChild = (WzImageProperty)ParentNode[path];

            if (imageChild is WzUOLProperty uolProperty)
            {
                WzObject uolLink = uolProperty.LinkValue;

                if (uolLink is WzCanvasProperty uolPropertyLink)
                {
                    canvasProperty = uolPropertyLink;
                }
                else
                {
                    // other unimplemented prop?
                }
            }
            else if (imageChild is WzCanvasProperty property)
            {
                canvasProperty = property;
            }

            if (canvasProperty != null && graphicsDevice != null)
            {
                WzCanvasProperty linkImgProperty = (WzCanvasProperty)canvasProperty.GetLinkedWzImageProperty();
                WzPngProperty    pngProperty     = linkImgProperty.PngProperty;

                Texture2D tex = new Texture2D(graphicsDevice, pngProperty.Width, pngProperty.Height, false, linkImgProperty.PngProperty.GetXNASurfaceFormat());

                pngProperty.ParsePng(true, tex);

                page.rendererObject = tex;
                page.width          = pngProperty.Width;
                page.height         = pngProperty.Height;
            }
        }
Example #3
0
 public WzPngProperty ToPngProperty(WzPngProperty def)
 {
     if (this is WzCanvasProperty)
     {
         return((WzPngProperty)WzValue);
     }
     else if (this is WzUOLProperty)
     {
         var tmp = ToUOLLink();
         if (tmp == null)
         {
             return(null);
         }
         return(tmp.ToPngProperty(def));
     }
     else
     {
         return(def);
     }
 }
Example #4
0
        public static void ExtractAnimation(WzSubProperty parent, string savePath, bool apng, bool apngFirstFrame)
        {
            List <Bitmap> bmpList                    = new List <Bitmap>(parent.WzProperties.Count);
            List <int>    delayList                  = new List <int>(parent.WzProperties.Count);
            Point         biggestPng                 = new Point(0, 0);
            Point         SmallestEmptySpace         = new Point(65535, 65535);
            Point         MaximumPngMappingEndingPts = new Point(0, 0);

            foreach (IWzImageProperty subprop in parent.WzProperties)
            {
                if (subprop is WzCanvasProperty)
                {
                    //WzVectorProperty origin = (WzVectorProperty)subprop["origin"];
                    WzPngProperty png = ((WzCanvasProperty)subprop).PngProperty;
                    if (png.Height > biggestPng.Y)
                    {
                        biggestPng.Y = png.Height;
                    }
                    if (png.Width > biggestPng.X)
                    {
                        biggestPng.X = png.Width;
                    }
                }
            }
            List <WzCanvasProperty> sortedProps = new List <WzCanvasProperty>();

            foreach (IWzImageProperty subprop in parent.WzProperties)
            {
                if (subprop is WzCanvasProperty)
                {
                    sortedProps.Add((WzCanvasProperty)subprop);
                    WzPngProperty    png                  = ((WzCanvasProperty)subprop).PngProperty;
                    WzVectorProperty origin               = (WzVectorProperty)subprop["origin"];
                    Point            StartPoints          = new Point(biggestPng.X - origin.X.Value, biggestPng.Y - origin.Y.Value);
                    Point            PngMapppingEndingPts = new Point(StartPoints.X + png.Width, StartPoints.Y + png.Height);
                    if (StartPoints.X < SmallestEmptySpace.X)
                    {
                        SmallestEmptySpace.X = StartPoints.X;
                    }
                    if (StartPoints.Y < SmallestEmptySpace.Y)
                    {
                        SmallestEmptySpace.Y = StartPoints.Y;
                    }
                    if (PngMapppingEndingPts.X > MaximumPngMappingEndingPts.X)
                    {
                        MaximumPngMappingEndingPts.X = PngMapppingEndingPts.X;
                    }
                    if (PngMapppingEndingPts.Y > MaximumPngMappingEndingPts.Y)
                    {
                        MaximumPngMappingEndingPts.Y = PngMapppingEndingPts.Y;
                    }
                }
            }
            sortedProps.Sort(new Comparison <WzCanvasProperty>(PropertySorter));

/*            foreach (IWzImageProperty subprop in parent.WzProperties)
 *          {
 *              if (subprop is WzCanvasProperty)
 *              {
 *                  WzCompressedIntProperty delayProp = (WzCompressedIntProperty)subprop["delay"];
 *                  if (delayProp != null) delay = delayProp.Value;
 *              }
 *          }*/
/*            Brush bgcolor = null;
 *          switch (toolStripComboBox2.SelectedIndex)
 *          {
 *              case 0:
 *                  bgcolor = Brushes.Widthhite;
 *                  break;
 *              case 1:
 *                  bgcolor = Brushes.Black;
 *                  break;
 *              default:
 *                  bgcolor = Brushes.Black;
 *                  break;
 *          }*/

            for (int i = 0; i < sortedProps.Count; i++)
            {
                WzCanvasProperty subprop = sortedProps[i];
                if (i.ToString() != subprop.Name)
                {
                    Warning.Error("Something f****d up at animation builder, frame " + i.ToString());
                    return;
                }
                Bitmap           bmp    = subprop.PngProperty.GetPNG(false);
                WzVectorProperty origin = (WzVectorProperty)subprop["origin"];
//                    if (apng)
                bmpList.Add(OptimizeBitmapTransparent(bmp, origin, biggestPng, SmallestEmptySpace, MaximumPngMappingEndingPts));

/*                    else
 *                      bmpList.Add(OptimizeBitmap(bmp, origin, biggestPng, SmallestEmptySpace, MaximumPngMappingEndingPts, bgcolor));*/
                WzCompressedIntProperty delayProp = (WzCompressedIntProperty)subprop["delay"];
                int delay = 100;
                if (delayProp != null)
                {
                    delay = delayProp.Value;
                }
                delayList.Add(delay);
                //}
            }
            if (apng)
            {
                //List<Frame> frameList = new List<Frame>();

                /*                List<int> delayList = new List<int>();
                 *              foreach (TreeNode subnode in parent.Nodes)
                 *              {
                 *                  if (subnode.Tag2 is PNG)
                 *                  {
                 *                      TreeNode delayNode = FindNodeInSubnodes(subnode, "delay");
                 *                      if (delayNode == null) delayList.Add(0);
                 *                      else delayList.Add((int)delayNode.Tag2);
                 *                  }
                 *              }
                 *              if (delayList.Count != bmp.Count)
                 *              {
                 *                  MessageBox.Show("Weird error, seems like there are more PNGs than delay values");
                 *                  return;
                 *              }*/
                Apng apngBuilder = new Apng();
                if (apngFirstFrame)
                {
                    apngBuilder.AddFrame(new Frame(CreateIncompatibilityFrame(new Size(bmpList[0].Width, bmpList[0].Height)), 1, 1));
                }
                for (int i = 0; i < bmpList.Count; i++)
                {
                    apngBuilder.AddFrame(new Frame(bmpList[i], getNumByDelay(delayList[i]), getDenByDelay(delayList[i])));
                }
                apngBuilder.WriteApng(savePath, apngFirstFrame, true);
                //createapng(frameList, savePath);
            }
            else
            {
                AnimatedGifEncoder gifEncoder = new AnimatedGifEncoder();
                for (int i = 0; i < bmpList.Count; i++)
                {
                    gifEncoder.AddFrame(new GifFrame(bmpList[i])
                    {
                        Delay = delayList[i] / 10
                    });
                }
                gifEncoder.WriteToFile(savePath);
            }
        }
        public static void ExtractAnimation(WzSubProperty parent, string savePath, bool apngFirstFrame)
        {
            List <Bitmap> bmpList                    = new List <Bitmap>(parent.WzProperties.Count);
            List <int>    delayList                  = new List <int>(parent.WzProperties.Count);
            Point         biggestPng                 = new Point(0, 0);
            Point         SmallestEmptySpace         = new Point(65535, 65535);
            Point         MaximumPngMappingEndingPts = new Point(0, 0);

            foreach (WzImageProperty subprop in parent.WzProperties)
            {
                if (subprop is WzCanvasProperty)
                {
                    //System.Drawing.PointF origin = ((WzCanvasProperty)subprop).GetCanvasOriginPosition();
                    WzPngProperty png = ((WzCanvasProperty)subprop).PngProperty;
                    if (png.Height > biggestPng.Y)
                    {
                        biggestPng.Y = png.Height;
                    }
                    if (png.Width > biggestPng.X)
                    {
                        biggestPng.X = png.Width;
                    }
                }
            }
            List <WzCanvasProperty> sortedProps = new List <WzCanvasProperty>();

            foreach (WzImageProperty subprop in parent.WzProperties)
            {
                if (subprop is WzCanvasProperty property)
                {
                    sortedProps.Add(property);
                    WzPngProperty         png    = property.PngProperty;
                    System.Drawing.PointF origin = property.GetCanvasOriginPosition();

                    Point StartPoints          = new Point(biggestPng.X - (int)origin.X, biggestPng.Y - (int)origin.Y);
                    Point PngMapppingEndingPts = new Point(StartPoints.X + png.Width, StartPoints.Y + png.Height);
                    if (StartPoints.X < SmallestEmptySpace.X)
                    {
                        SmallestEmptySpace.X = StartPoints.X;
                    }
                    if (StartPoints.Y < SmallestEmptySpace.Y)
                    {
                        SmallestEmptySpace.Y = StartPoints.Y;
                    }
                    if (PngMapppingEndingPts.X > MaximumPngMappingEndingPts.X)
                    {
                        MaximumPngMappingEndingPts.X = PngMapppingEndingPts.X;
                    }
                    if (PngMapppingEndingPts.Y > MaximumPngMappingEndingPts.Y)
                    {
                        MaximumPngMappingEndingPts.Y = PngMapppingEndingPts.Y;
                    }
                }
            }
            sortedProps.Sort(new Comparison <WzCanvasProperty>(PropertySorter));
            for (int i = 0; i < sortedProps.Count; i++)
            {
                WzCanvasProperty subprop = sortedProps[i];
                if (i.ToString() != subprop.Name)
                {
                    Warning.Error(string.Format(Properties.Resources.AnimError, i.ToString()));
                    return;
                }
                Bitmap bmp = subprop.PngProperty.GetImage(false);
                System.Drawing.PointF origin = subprop.GetCanvasOriginPosition();
                bmpList.Add(OptimizeBitmapTransparent(bmp, new WzVectorProperty("", origin.X, origin.Y), biggestPng, SmallestEmptySpace, MaximumPngMappingEndingPts));

                int?delay = subprop[WzCanvasProperty.AnimationDelayPropertyName]?.GetInt();
                if (delay == null)
                {
                    delay = 100;
                }

                delayList.Add((int)delay);
            }
            SharpApng apngBuilder = new SharpApng();

            if (apngFirstFrame)
            {
                apngBuilder.AddFrame(new SharpApngFrame(CreateIncompatibilityFrame(new Size(bmpList[0].Width, bmpList[0].Height)), 1, 1));
            }
            for (int i = 0; i < bmpList.Count; i++)
            {
                apngBuilder.AddFrame(new SharpApngFrame(bmpList[i], GetNumByDelay(delayList[i]), GetDenByDelay(delayList[i])));
            }
            apngBuilder.WriteApng(savePath, apngFirstFrame, true);
        }
Example #6
0
 internal virtual WzPngProperty ToPngProperty(WzPngProperty def = null)
 {
     return(def);
 }
        /// <summary>
        /// Loads spine texture from the specified WZ path
        /// </summary>
        /// <param name="page"></param>
        /// <param name="path"></param>
        public void Load(AtlasPage page, string path)
        {
            WzObject frameNode = this.ParentNode[path];

            if (frameNode == null)
            {
                return;
            }

            WzCanvasProperty canvasProperty = null;

            WzImageProperty imageChild = (WzImageProperty)ParentNode[path];

            if (imageChild is WzUOLProperty uolProperty)
            {
                WzObject uolLink = uolProperty.LinkValue;

                if (uolLink is WzCanvasProperty uolPropertyLink)
                {
                    canvasProperty = uolPropertyLink;
                }
                else
                {
                    // other unimplemented prop?
                }
            }
            else if (imageChild is WzCanvasProperty property)
            {
                canvasProperty = property;
            }

            if (canvasProperty != null)
            {
                WzCanvasProperty linkImgProperty = (WzCanvasProperty)canvasProperty.GetLinkedWzImageProperty();

                WzPngProperty pngProperty   = linkImgProperty.PngProperty;
                SurfaceFormat surfaceFormat = linkImgProperty.PngProperty.GetXNASurfaceFormat();

                if (graphicsDevice != null)
                {
                    Texture2D tex;
                    tex = new Texture2D(graphicsDevice,
                                        pngProperty.Width, pngProperty.Height,
                                        false, surfaceFormat);

                    /*switch (surfaceFormat)
                     * {
                     *  case SurfaceFormat.Bgra4444:
                     *      tex = new Texture2D(graphicsDevice,
                     *          pngProperty.Width * 2, pngProperty.Height * 2,
                     *          false, surfaceFormat);
                     *      break;
                     *  case SurfaceFormat.Bgra32:
                     *      tex = new Texture2D(graphicsDevice,
                     *          pngProperty.Width * 4, pngProperty.Height * 4,
                     *          false, surfaceFormat);
                     *      break;
                     *  case SurfaceFormat.Bgr565:
                     *      tex = new Texture2D(graphicsDevice,
                     *          pngProperty.Width * 2, pngProperty.Height * 2,
                     *          false, surfaceFormat);
                     *      break;
                     *  case SurfaceFormat.Dxt3:
                     *      tex = new Texture2D(graphicsDevice,
                     *          pngProperty.Width * 4, pngProperty.Height * 4,
                     *          false, surfaceFormat);
                     *      break;
                     *  case SurfaceFormat.Dxt5:
                     *      tex = new Texture2D(graphicsDevice,
                     *          pngProperty.Width * 4, pngProperty.Height * 4,
                     *          false, surfaceFormat);
                     *      break;
                     *  default:
                     *      tex = new Texture2D(graphicsDevice,
                     *          pngProperty.Width, pngProperty.Height,
                     *          false, surfaceFormat);
                     *      break;
                     * }
                     */
                    pngProperty.ParsePng(true, tex);


                    page.rendererObject = tex;
                    page.width          = pngProperty.Width;
                    page.height         = pngProperty.Height;
                }
            }
        }