Пример #1
0
        public static DynVal ReadValue(BinaryPSDReader r, bool ignoreName)
        {
            DynVal vt = new DynVal();
            if (!ignoreName)
                vt.Name = GetMeaningOfFourCC(ReadSpecialString(r)); // r.ReadPascalString();
            //else
            //TODO: should be assigned a sequential number?
            string type = new string(r.ReadPSDChars(4));

            switch (type)
            {
                case "tdta":
                    vt.Value = Endogine.Serialization.ReadableBinary.CreateHexEditorString(r.ReadBytes(9));
                    vt.Children = new List<DynVal>();
                    while (true)
                    {
                        DynVal child = new DynVal();
                        vt.Children.Add(child);
                        if (child.ReadTdtaItem(r) == false)
                            break;
                    }

                    //r.BaseStream.Position += 9;
                    break;
                case "Objc": //Decriptor
                case "GlbO": //GlobalObject (same)
                    string uniName = r.ReadPSDUnicodeString();
                    //uint numSub = r.ReadUInt32();
                    //if (numSub > 1)
                    //{
                    //    //A unicode text here!? What does this have to do with numSub??
                    //    r.BaseStream.Position -= 4;
                    //    r.ReadPSDUnicodeString();
                    //    r.BaseStream.Position -= 2; //Ehh... What?!
                    //}
                    ////TODO: ah: 1 = 1 short = unknown...
                    //ushort unknown = r.ReadUInt16();
                    //vt.Children = ReadValues(r);
                    vt = new DynVal(r, false);
                    if (uniName.Length > 0)
                        vt.UnicodeName = uniName;
                    break;
                case "VlLs": //List
                    vt.Children = new List<DynVal>();
                    int numValues = (int)r.ReadUInt32();
                    for (int i = 0; i < numValues; i++)
                    {
                        DynVal ob = ReadValue(r, true);
                        if (ob != null)
                            vt.Children.Add(ob);
                    }
                    break;
                case "doub":
                    vt.Value = r.ReadPSDDouble();
                    break;
                case "UntF": //Unif float
                    //TODO: need a specific type for this, with a double and a type (percent/pixel)?
                    string tst = GetMeaningOfFourCC(new string(r.ReadPSDChars(4))); //#Prc #Pxl #Ang = percent / pixels / angle?
                    double d = r.ReadPSDDouble();
                    tst += ": " + d;
                    vt.Value = tst;
                    break;
                case "enum":
                    string namesp = ReadSpecialString(r);
                    string item = ReadSpecialString(r);
                    //vt.Value = namesp + "." + item; //TODO: cast to real enum
                    vt.Value = GetMeaningOfFourCC(namesp) + "." + GetMeaningOfFourCC(item);
                    break;
                case "long":
                    vt.Value = r.ReadInt32(); //64?
                    break;
                case "bool":
                    vt.Value = r.ReadBoolean();
                    break;
                //case "obj ": //reference
                //    break;
                case "TEXT":
                    vt.Value = r.ReadPSDUnicodeString();
                    break;
                //case "Enmr": //Enumerated
                //    break;
                //case "Clss": //Class
                //    break;
                //case "GlbC": //GlobalClass
                //    break;
                //case "alis": //Alias
                //    break;
                default:
                    throw new Exception("Unknown type: " + type);
            }
            if (vt.Value == null && vt.Children == null)
                return null;
            return vt;
        }
Пример #2
0
        public static DynVal ReadValue(BinaryPSDReader r, bool ignoreName)
        {
            DynVal vt = new DynVal();

            if (!ignoreName)
            {
                vt.Name = GetMeaningOfFourCC(ReadSpecialString(r)); // r.ReadPascalString();
            }
            //else
            //TODO: should be assigned a sequential number?
            string type = new string(r.ReadPSDChars(4));

            switch (type)
            {
            case "tdta":
                vt.Value    = Endogine.Serialization.ReadableBinary.CreateHexEditorString(r.ReadBytes(9));
                vt.Children = new List <DynVal>();
                while (true)
                {
                    DynVal child = new DynVal();
                    vt.Children.Add(child);
                    if (child.ReadTdtaItem(r) == false)
                    {
                        break;
                    }
                }

                //r.BaseStream.Position += 9;
                break;

            case "Objc":     //Decriptor
            case "GlbO":     //GlobalObject (same)
                string uniName = r.ReadPSDUnicodeString();
                //uint numSub = r.ReadUInt32();
                //if (numSub > 1)
                //{
                //    //A unicode text here!? What does this have to do with numSub??
                //    r.BaseStream.Position -= 4;
                //    r.ReadPSDUnicodeString();
                //    r.BaseStream.Position -= 2; //Ehh... What?!
                //}
                ////TODO: ah: 1 = 1 short = unknown...
                //ushort unknown = r.ReadUInt16();
                //vt.Children = ReadValues(r);
                vt = new DynVal(r, false);
                if (uniName.Length > 0)
                {
                    vt.UnicodeName = uniName;
                }
                break;

            case "VlLs":     //List
                vt.Children = new List <DynVal>();
                int numValues = (int)r.ReadUInt32();
                for (int i = 0; i < numValues; i++)
                {
                    DynVal ob = ReadValue(r, true);
                    if (ob != null)
                    {
                        vt.Children.Add(ob);
                    }
                }
                break;

            case "doub":
                vt.Value = r.ReadPSDDouble();
                break;

            case "UntF":                                                        //Unif float
                //TODO: need a specific type for this, with a double and a type (percent/pixel)?
                string tst = GetMeaningOfFourCC(new string(r.ReadPSDChars(4))); //#Prc #Pxl #Ang = percent / pixels / angle?
                double d   = r.ReadPSDDouble();
                tst     += ": " + d;
                vt.Value = tst;
                break;

            case "enum":
                string namesp = ReadSpecialString(r);
                string item   = ReadSpecialString(r);
                //vt.Value = namesp + "." + item; //TODO: cast to real enum
                vt.Value = GetMeaningOfFourCC(namesp) + "." + GetMeaningOfFourCC(item);
                break;

            case "long":
                vt.Value = r.ReadInt32();     //64?
                break;

            case "bool":
                vt.Value = r.ReadBoolean();
                break;

            //case "obj ": //reference
            //    break;
            case "TEXT":
                vt.Value = r.ReadPSDUnicodeString();
                break;

            //case "Enmr": //Enumerated
            //    break;
            //case "Clss": //Class
            //    break;
            //case "GlbC": //GlobalClass
            //    break;
            //case "alis": //Alias
            //    break;
            default:
                throw new Exception("Unknown type: " + type);
            }
            if (vt.Value == null && vt.Children == null)
            {
                return(null);
            }
            return(vt);
        }