private static ResourceMetadata GenerateTachieResMetadata(PsbDictionary d, PsbResource r, string label = "") { int width = 1, height = 1; int top = 0, left = 0; var dd = d.Parent as PsbDictionary ?? d; if ((d["width"] ?? d["truncated_width"] ?? dd["width"]) is PsbNumber nw) { width = (int)nw; } if ((d["height"] ?? d["truncated_height"] ?? dd["height"]) is PsbNumber nh) { height = (int)nh; } if ((dd["top"] ?? d["top"]) is PsbNumber nx) { top = nx.AsInt; } if ((dd["left"] ?? d["left"]) is PsbNumber ny) { left = ny.AsInt; } var md = new ResourceMetadata() { Top = top, Left = left, TypeString = d["type"] as PsbString, Width = width, Height = height, Name = r.Index.ToString(), Part = label, Resource = r, }; return(md); }
/// <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); }