Exemplo n.º 1
0
        private void ParseDescriptor(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 descriptor '{0}' ({1} items)", classId, count));
#endif
            if (classId.Equals("brushPreset", StringComparison.Ordinal))
            {
                ParseBrushPreset(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,
                                                           "Item {0}: {1} ({2}) at 0x{3:X8}",
                                                           new object[] { i, key, type, reader.Position }));
#endif
                    ParseType(reader, type);
                }
            }
        }
Exemplo n.º 2
0
        private void ParseList(BigEndianBinaryReader reader)
        {
            uint count = reader.ReadUInt32();

            for (int i = 0; i < count; i++)
            {
                DescriptorTypes type = (DescriptorTypes)reader.ReadUInt32();

                ParseType(reader, type);
            }
        }
Exemplo n.º 3
0
        private void ParseBrushPreset(BigEndianBinaryReader reader, uint count)
        {
            string    presetName = null;
            BrushData brushData  = null;

            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,
                                                       "brushPreset item {0}: {1} ({2}) at 0x{3:X8}",
                                                       new object[] { i, key, type, reader.Position }));
#endif
                if (key.Equals("Nm  ", StringComparison.Ordinal))
                {
                    presetName = ParseString(reader);
                }
                else if (key.Equals("Brsh", StringComparison.Ordinal) && type == DescriptorTypes.Descriptor)
                {
                    brushData = ParseBrushDescriptor(reader);
                }
                else
                {
                    ParseType(reader, type);
                }
            }

            if (brushData != null && !string.IsNullOrEmpty(brushData.sampledDataTag))
            {
                sampledBrushes.Add(new SampledBrush(presetName, brushData.sampledDataTag, brushData.diameter));
            }
        }
Exemplo n.º 4
0
 private static UnitFloat ParseUnitFloat(BigEndianBinaryReader reader)
 {
     return(new UnitFloat()
     {
         type = (UnitTypes)reader.ReadUInt32(),
         value = reader.ReadDouble()
     });
 }
Exemplo n.º 5
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));
        }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
0
 private static uint ParseInteger(BigEndianBinaryReader reader)
 {
     return(reader.ReadUInt32());
 }