Beispiel #1
0
        private BrushData ParseSampledBrush(BigEndianBinaryReader reader, uint count)
        {
            BrushData data = new BrushData();

            for (uint i = 0; i < count; i++)
            {
                string key = ParseKey(reader);

                DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32();

#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format(
                                                       CultureInfo.CurrentCulture,
                                                       "sampledBrush item {0}: {1} ({2}) at 0x{3:X8}",
                                                       new object[] { i, key, type, reader.Position }));
#endif
                UnitFloat unitFloat;
                switch (key)
                {
                case "Dmtr":
                    unitFloat = ParseUnitFloat(reader);
                    if (unitFloat.type == UnitTypes.Pixel)
                    {
                        data.diameter = (int)unitFloat.value;
                    }
                    break;

                case "sampledData":
                    data.sampledDataTag = ParseString(reader);
                    break;

                default:
                    ParseType(reader, type);
                    break;
                }
            }

            return(data);
        }
Beispiel #2
0
        private static BrushSectionOffsets GetBrushSectionOffsets(BigEndianBinaryReader reader)
        {
            const uint PhotoshopSignature  = 0x3842494D; // 8BIM
            const uint SampleSectionId     = 0x73616D70; // samp
            const uint DescriptorSectionId = 0x64657363; // desc

            long sampleSectionOffset     = -1;
            long descriptorSectionOffset = -1;

            while (reader.Position < reader.Length)
            {
                uint sig = reader.ReadUInt32();

                if (sig != PhotoshopSignature)
                {
                    return(null);
                }

                uint sectionId = reader.ReadUInt32();

                switch (sectionId)
                {
                case SampleSectionId:
                    sampleSectionOffset = reader.Position;
                    break;

                case DescriptorSectionId:
                    descriptorSectionOffset = reader.Position;
                    break;
                }

                uint size = reader.ReadUInt32();

                reader.Position += size;
            }

            return(new BrushSectionOffsets(sampleSectionOffset, descriptorSectionOffset));
        }
Beispiel #3
0
        private BrushData ParseBrushDescriptor(BigEndianBinaryReader reader)
        {
            string name = ParseString(reader);

            string classId = ParseClassId(reader);

            uint count = reader.ReadUInt32();

#if DEBUG
            System.Diagnostics.Debug.WriteLine(string.Format(CultureInfo.CurrentCulture, "Parsing {0} ({1} items)", classId, count));
#endif

            BrushData data = null;

            if (classId.Equals("sampledBrush", StringComparison.Ordinal))
            {
                data = ParseSampledBrush(reader, count);
            }
            else
            {
                for (uint i = 0; i < count; i++)
                {
                    string          key  = ParseKey(reader);
                    DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32();

#if DEBUG
                    System.Diagnostics.Debug.WriteLine(string.Format(
                                                           CultureInfo.CurrentCulture,
                                                           "{0} item {1}: {2} ({3}) at 0x{4:X8}",
                                                           new object[] { classId, i, key, type, reader.Position }));
#endif
                    ParseType(reader, type);
                }
            }

            return(data);
        }
Beispiel #4
0
        private void ParseBrushDescriptorSection(BigEndianBinaryReader reader)
        {
            uint sectionSize = reader.ReadUInt32();

            long sectionEnd = reader.Position + sectionSize;

            // Skip the unknown data.
            reader.Position += 22L;

            if (reader.Position < sectionEnd)
            {
                string          key  = ParseKey(reader);
                DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32();

#if DEBUG
                System.Diagnostics.Debug.WriteLine(string.Format(
                                                       CultureInfo.CurrentCulture,
                                                       "Item: {0} ({1}) at {2:X8}",
                                                       new object[] { key, type, reader.Position }));
#endif

                ParseType(reader, type);
            }
        }
Beispiel #5
0
 private static double ParseFloat(BigEndianBinaryReader reader)
 {
     return(reader.ReadDouble());
 }
Beispiel #6
0
 private static uint ParseInteger(BigEndianBinaryReader reader)
 {
     return(reader.ReadUInt32());
 }
Beispiel #7
0
 private static bool ParseBoolean(BigEndianBinaryReader reader)
 {
     return(reader.ReadByte() != 0);
 }
Beispiel #8
0
 private static string ParseString(BigEndianBinaryReader reader)
 {
     return(reader.ReadUnicodeString());
 }