public static ImageResource CreateImageResource(PsdBinaryReader reader)
        {
            Debug.Print("ImageResource started at {0}", reader.BaseStream.Position);

            var signature     = reader.ReadAsciiChars(4);
            var resourceIdInt = reader.ReadUInt16();
            var name          = reader.ReadPascalString(2);
            var dataLength    = (int)reader.ReadUInt32();

            var dataPaddedLength = Util.RoundUp(dataLength, 2);
            var endPosition      = reader.BaseStream.Position + dataPaddedLength;

            ImageResource resource   = null;
            var           resourceId = (ResourceID)resourceIdInt;

            switch (resourceId)
            {
            case ResourceID.ResolutionInfo:
                resource = new ResolutionInfo(reader, name);
                break;

            case ResourceID.ThumbnailRgb:
            case ResourceID.ThumbnailBgr:
                resource = new Thumbnail(reader, resourceId, name, dataLength);
                break;

            case ResourceID.AlphaChannelNames:
                resource = new AlphaChannelNames(reader, name, dataLength);
                break;

            case ResourceID.UnicodeAlphaNames:
                resource = new UnicodeAlphaNames(reader, name, dataLength);
                break;

            case ResourceID.VersionInfo:
                resource = new VersionInfo(reader, name);
                break;

            default:
                resource = new RawImageResource(reader, signature, resourceId, name, dataLength);
                break;
            }

            // Reposition the reader if we do not consume the full resource block.
            // This takes care of the even-padding, and also preserves forward-
            // compatibility in case a resource block is later extended with
            // additional properties.
            if (reader.BaseStream.Position < endPosition)
            {
                reader.BaseStream.Position = endPosition;
            }

            // However, overruns are definitely an error.
            if (reader.BaseStream.Position > endPosition)
            {
                throw new PsdInvalidException("Corruption detected in resource.");
            }

            return(resource);
        }
Beispiel #2
0
        private void LoadImageResources(BinaryReverseReader reader)
        {
            _imageResources.Clear();
            uint num = reader.ReadUInt32();

            if (num <= 0U)
            {
                return;
            }

            long position = reader.BaseStream.Position;

            while (reader.BaseStream.Position - position < num)
            {
                ImageResource imgRes = new ImageResource(reader);

                switch ((ResourceIDs)imgRes.ID)
                {
                case ResourceIDs.XMLInfo:
                    _metaData = XDocument.Load(XmlReader.Create(new MemoryStream(imgRes.Data)));
                    IEnumerable <XElement> source = _metaData.Descendants(XName.Get("Category", "http://ns.adobe.com/photoshop/1.0/"));
                    if (source.Any())
                    {
                        _category = source.First().Value;
                    }
                    break;

                case ResourceIDs.ResolutionInfo:
                    imgRes = new ResolutionInfo(imgRes);
                    break;

                case ResourceIDs.AlphaChannelNames:
                    imgRes = new AlphaChannels(imgRes);
                    break;

                case ResourceIDs.PsCCOrignPathInfo:
                    imgRes = new AlphaChannels(imgRes);
                    break;

                case ResourceIDs.PsCCPathSelectionState:
                    imgRes = new AlphaChannels(imgRes);
                    break;

                case ResourceIDs.TransparencyIndex:
                    Debug.Log("have transparent ");
                    break;
                }

                _imageResources.Add(imgRes);
            }

            reader.BaseStream.Position = position + num;
        }
Beispiel #3
0
        ///////////////////////////////////////////////////////////////////////////

        private void LoadImageResources(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadImageResources started at " + reader.BaseStream.Position.ToString());

            m_imageResources.Clear();

            uint imgResLength = reader.ReadUInt32();

            if (imgResLength <= 0)
            {
                return;
            }

            long startPosition = reader.BaseStream.Position;

            while ((reader.BaseStream.Position - startPosition) < imgResLength)
            {
                ImageResource imgRes = new ImageResource(reader);

                ResourceIDs resID = (ResourceIDs)imgRes.ID;
                switch (resID)
                {
                case ResourceIDs.ResolutionInfo:
                    imgRes = new ResolutionInfo(imgRes);
                    break;

                case ResourceIDs.Thumbnail1:
                case ResourceIDs.Thumbnail2:
                    imgRes = new Thumbnail(imgRes);
                    break;

                case ResourceIDs.AlphaChannelNames:
                    imgRes = new AlphaChannels(imgRes);
                    break;
                }

                m_imageResources.Add(imgRes);
            }

            //-----------------------------------------------------------------------
            // make sure we are not on a wrong offset, so set the stream position
            // manually
            reader.BaseStream.Position = startPosition + imgResLength;
        }
Beispiel #4
0
        ///////////////////////////////////////////////////////////////////////////

        private void LoadImageResources(BinaryReverseReader reader)
        {
            Debug.WriteLine("LoadImageResources started at " + reader.BaseStream.Position);

            m_imageResources.Clear();

            uint imgResLength = reader.ReadUInt32();
            if (imgResLength <= 0)
                return;

            long startPosition = reader.BaseStream.Position;

            while ((reader.BaseStream.Position - startPosition) < imgResLength)
            {
                var imgRes = new ImageResource(reader);

                var resID = (ResourceIDs)imgRes.ID;
                switch (resID)
                {
                    case ResourceIDs.ResolutionInfo:
                        imgRes = new ResolutionInfo(imgRes);
                        break;
                    case ResourceIDs.Thumbnail1:
                    case ResourceIDs.Thumbnail2:
                        imgRes = new Thumbnail(imgRes);
                        break;
                    case ResourceIDs.AlphaChannelNames:
                        imgRes = new AlphaChannels(imgRes);
                        break;
                }

                m_imageResources.Add(imgRes);
            }

            //-----------------------------------------------------------------------
            // make shure we are not on a wrong offset, so set the stream position 
            // manually
            reader.BaseStream.Position = startPosition + imgResLength;
        }
        /// <summary>
        /// Reads the image resources from the reader.
        /// </summary>
        /// <param name="reader">The reader to use to read the image resources.</param>
        private void LoadImageResources(BinaryReverseReader reader)
        {
            ImageResources.Clear();
            uint num = reader.ReadUInt32();
            if (num <= 0U)
            {
                return;
            }

            long position = reader.BaseStream.Position;
            while (reader.BaseStream.Position - position < num)
            {
                ImageResource imgRes = new ImageResource(reader);
                switch ((ResourceIDs)imgRes.ID)
                {
                    case ResourceIDs.XMLInfo:
                        MetaData = XDocument.Load(XmlReader.Create(new MemoryStream(imgRes.Data)));
                        IEnumerable<XElement> source = MetaData.Descendants(XName.Get("Category", "http://ns.adobe.com/photoshop/1.0/"));
                        if (source.Any())
                        {
                            Category = source.First().Value;
                        }

                        break;

                    case ResourceIDs.ResolutionInfo:
                        imgRes = new ResolutionInfo(imgRes);
                        break;

                    case ResourceIDs.AlphaChannelNames:
                        imgRes = new AlphaChannels(imgRes);
                        break;
                }

                ImageResources.Add(imgRes);
            }

            reader.BaseStream.Position = position + num;
        }