Пример #1
0
        public List <AdditionalLayerInformationBlock> Read(Stream stream, AdditionalLayerInformation additionalLayerInformation, FileVersion fileVersion)
        {
            var reader = new BigEndianBinaryReader(stream);

            stream.Position = additionalLayerInformation.Offset;
            var list = new List <AdditionalLayerInformationBlock>();

            while (stream.Position < additionalLayerInformation.Offset + additionalLayerInformation.Length)
            {
                var block = new AdditionalLayerInformationBlock();
                block.Signature = new string(reader.ReadChars(4));
                block.Key       = new string(reader.ReadChars(4));

                if (fileVersion == FileVersion.Psb && LongDataKeys.Contains(block.Key))
                {
                    block.Length = reader.ReadInt64();
                }
                else
                {
                    block.Length = reader.ReadInt32();
                }

                if ((block.Length % 2) != 0)
                {
                    block.Length += 3; // should be 1, but 3 works there for unknown reason
                }

                block.Offset     = stream.Position;
                stream.Position += block.Length;
                list.Add(block);
            }

            return(list);
        }
Пример #2
0
        public List <ImageResourceBlock> Read(Stream stream, ImageResourcesSection imageResourcesSection)
        {
            var list = new List <ImageResourceBlock>();

            var reader = new BigEndianBinaryReader(stream);

            stream.Position = imageResourcesSection.Offset;

            while (reader.BaseStream.Position < imageResourcesSection.Offset + imageResourcesSection.Length)
            {
                var imageResource = new ImageResourceBlock();

                imageResource.Signature = new string(reader.ReadChars(4));
                imageResource.Id        = (ImageResourceId)reader.ReadInt16();
                imageResource.Name      = reader.ReadPascalString();

                imageResource.Length = reader.ReadInt32();

                if ((imageResource.Length % 2) != 0)
                {
                    imageResource.Length++;
                }

                imageResource.Offset = stream.Position;
                stream.Position     += imageResource.Length;

                list.Add(imageResource);
            }

            return(list);
        }
Пример #3
0
        public FileHeader Read(Stream stream)
        {
            var header = new FileHeader();
            var reader = new BigEndianBinaryReader(stream);

            header.Signature      = new string(reader.ReadChars(4));
            header.Version        = (FileVersion)reader.ReadInt16();
            header.Reserved       = reader.ReadBytes(6);
            header.ChannelCount   = reader.ReadInt16();
            header.PixelHeight    = reader.ReadInt32();
            header.PixelWidth     = reader.ReadInt32();
            header.BitsPerChannel = reader.ReadInt16();
            header.ColorMode      = (ColorMode)reader.ReadInt16();


            return(header);
        }
Пример #4
0
        public List <LayerRecord> Read(Stream stream, LayersInformation layersInformation, FileVersion fileVersion)
        {
            var list = new List <LayerRecord>();

            var reader = new BigEndianBinaryReader(stream);

            stream.Position = layersInformation.Offset;

            for (int i = 0; i < layersInformation.LayerCount; i++)
            {
                var layerRecord = new LayerRecord();

                layerRecord.RectangleTop    = reader.ReadInt32();
                layerRecord.RectangleLeft   = reader.ReadInt32();
                layerRecord.RectangleBottom = reader.ReadInt32();
                layerRecord.RectangleRight  = reader.ReadInt32();

                layerRecord.ChannelCount = reader.ReadInt16();
                layerRecord.Channels     = new ChannelInformation[layerRecord.ChannelCount];
                for (int j = 0; j < layerRecord.ChannelCount; j++)
                {
                    layerRecord.Channels[j]        = new ChannelInformation();
                    layerRecord.Channels[j].Id     = reader.ReadInt16();
                    layerRecord.Channels[j].Length = fileVersion == FileVersion.Psd ? reader.ReadInt32() : reader.ReadInt64();
                }

                layerRecord.BlendModeSignature = new string(reader.ReadChars(4));
                layerRecord.BlendModeKey       = new string(reader.ReadChars(4));
                layerRecord.Opacity            = reader.ReadByte();
                layerRecord.Clipping           = (Clipping)reader.ReadByte();

                var flags = reader.ReadByte();
                layerRecord.IsTransparencyProtected = flags.GetBit(0);
                layerRecord.IsVisible  = flags.GetBit(1);
                layerRecord.IsObsolete = flags.GetBit(2);
                if (flags.GetBit(3))
                {
                    layerRecord.IsPixelIrrelevantToAppearance = flags.GetBit(4);
                }

                reader.ReadByte(); // filler

                layerRecord.Length = reader.ReadInt32();
                layerRecord.Offset = stream.Position;

                // TODO: Layer mask / adjustment layer data
                var maskLength = reader.ReadInt32();
                stream.Position += maskLength;

                // TODO: Layer blending ranges data
                var blendingLength = reader.ReadInt32();
                stream.Position += blendingLength;

                layerRecord.Name = reader.ReadPascalString();

                reader.ReadByte(); //???

                layerRecord.AdditionalLayerInformation        = new AdditionalLayerInformation();
                layerRecord.AdditionalLayerInformation.Offset = stream.Position;
                layerRecord.AdditionalLayerInformation.Length = (layerRecord.Offset + layerRecord.Length) - layerRecord.AdditionalLayerInformation.Offset;

                stream.Position = layerRecord.Offset + layerRecord.Length;

                list.Add(layerRecord);
            }

            return(list);
        }