Beispiel #1
0
        /// <summary>
        /// Extract resource info
        /// </summary>
        /// <param name="d">PsbObject which contains "pixel"</param>
        /// <param name="r">Resource</param>
        /// <param name="duplicatePalette">When set to true, Pal.Data may not be set!</param>
        /// <returns></returns>
        internal static ImageMetadata GenerateImageMetadata(PsbDictionary d, PsbResource r = null,
                                                            bool duplicatePalette          = false)
        {
            if (r == null)
            {
                if (d.ContainsKey(Consts.ResourceKey) && d[Consts.ResourceKey] is PsbResource rr)
                {
                    r = rr;
                }
                else //this may find Pal
                {
                    r = d.Values.FirstOrDefault(v => v is PsbResource) as PsbResource;
                }
            }

            bool       is2D = false;
            var        part = GetPartName(d);
            var        name = d.GetName();
            RectangleF clip = RectangleF.Empty;

            if (d["clip"] is PsbDictionary clipDic && clipDic.Count > 0)
            {
                is2D = true;
                clip = RectangleF.FromLTRB(
                    left: clipDic["left"] == null ? 0f : (float)(PsbNumber)clipDic["left"],
                    top: clipDic["top"] == null ? 0f : (float)(PsbNumber)clipDic["top"],
                    right: clipDic["right"] == null ? 1f : (float)(PsbNumber)clipDic["right"],
                    bottom: clipDic["bottom"] == null ? 1f : (float)(PsbNumber)clipDic["bottom"]
                    );
            }

            var compress = PsbCompressType.None;

            if (d["compress"] is PsbString sc)
            {
                is2D = true;
                if (sc.Value.ToUpperInvariant() == "RL")
                {
                    compress = PsbCompressType.RL;
                }
            }

            int   width = 1, height = 1;
            float originX = 0, originY = 0;

            if (d["width"] is PsbNumber nw)
            {
                is2D  = true;
                width = (int)nw;
            }

            if (d["height"] is PsbNumber nh)
            {
                is2D   = true;
                height = (int)nh;
            }

            if (d["originX"] is PsbNumber nx)
            {
                is2D    = true;
                originX = (float)nx;
            }

            if (d["originY"] is PsbNumber ny)
            {
                is2D    = true;
                originY = (float)ny;
            }

            PsbString typeString = null;

            if (d["type"] is PsbString typeStr)
            {
                typeString = typeStr;
            }

            int top = 0, left = 0;

            if (d["top"] is PsbNumber nt)
            {
                is2D = true;
                top  = (int)nt;
            }

            if (d["left"] is PsbNumber nl)
            {
                is2D = true;
                left = (int)nl;
            }

            PsbResource palResource   = null;
            PsbString   palTypeString = null;

            if (d["pal"] is PsbResource palRes)
            {
                if (duplicatePalette)
                {
                    palResource = new PsbResource(palRes.Index);
                    d["pal"]    = palResource;
                }
                else
                {
                    palResource = palRes;
                }

                palTypeString = d["palType"] as PsbString;
            }

            var md = new ImageMetadata()
            {
                Index             = r.Index ?? int.MaxValue,
                Compress          = compress,
                Name              = name,
                Part              = part,
                Clip              = clip,
                Is2D              = is2D,
                OriginX           = originX,
                OriginY           = originY,
                Top               = top,
                Left              = left,
                Width             = width,
                Height            = height,
                TypeString        = typeString,
                Resource          = r,
                Palette           = palResource,
                PaletteTypeString = palTypeString
            };

            return(md);
        }
Beispiel #2
0
        /// <summary>
        /// Extract resource info
        /// </summary>
        /// <param name="d">PsbObject which contains "pixel"</param>
        /// <param name="r">Resource</param>
        /// <returns></returns>
        internal static ResourceMetadata GenerateMotionResMetadata(PsbDictionary d, PsbResource r = null)
        {
            if (r == null)
            {
                r = d.Values.FirstOrDefault(v => v is PsbResource) as PsbResource;
            }
            bool       is2D = false;
            var        part = d.GetPartName();
            var        name = d.GetName();
            RectangleF clip = RectangleF.Empty;

            if (d["clip"] is PsbDictionary clipDic && clipDic.Count > 0)
            {
                is2D = true;
                clip = RectangleF.FromLTRB(
                    left: clipDic["left"] == null ? 0f : (float)(PsbNumber)clipDic["left"],
                    top: clipDic["top"] == null ? 0f : (float)(PsbNumber)clipDic["top"],
                    right: clipDic["right"] == null ? 1f : (float)(PsbNumber)clipDic["right"],
                    bottom: clipDic["bottom"] == null ? 1f : (float)(PsbNumber)clipDic["bottom"]
                    );
            }
            var compress = PsbCompressType.None;

            if (d["compress"] is PsbString sc)
            {
                is2D = true;
                if (sc.Value.ToUpperInvariant() == "RL")
                {
                    compress = PsbCompressType.RL;
                }
            }
            int   width = 1, height = 1;
            float originX = 0, originY = 0;

            if (d["width"] is PsbNumber nw)
            {
                is2D  = true;
                width = (int)nw;
            }
            if (d["height"] is PsbNumber nh)
            {
                is2D   = true;
                height = (int)nh;
            }
            if (d["originX"] is PsbNumber nx)
            {
                is2D    = true;
                originX = (float)nx;
            }
            if (d["originY"] is PsbNumber ny)
            {
                is2D    = true;
                originY = (float)ny;
            }

            PsbString typeString = null;

            if (d["type"] is PsbString typeStr)
            {
                typeString = typeStr;
            }
            int top = 0, left = 0;

            if (d["top"] is PsbNumber nt)
            {
                is2D = true;
                top  = (int)nt;
            }
            if (d["left"] is PsbNumber nl)
            {
                is2D = true;
                left = (int)nl;
            }
            var md = new ResourceMetadata()
            {
                Index      = r.Index ?? int.MaxValue,
                Compress   = compress,
                Name       = name,
                Part       = part,
                Clip       = clip,
                Is2D       = is2D,
                OriginX    = originX,
                OriginY    = originY,
                Top        = top,
                Left       = left,
                Width      = width,
                Height     = height,
                TypeString = typeString,
                Resource   = r,
            };

            return(md);
        }