Esempio n. 1
0
        public static Document Load(System.IO.Stream input)
        {
            // Load and decompress Photoshop file structures
            var loadContext = new DocumentLoadContext();
            var psdFile     = new PsdFile(input, loadContext);

            // Multichannel images are loaded by processing each channel as a
            // grayscale layer.
            if (psdFile.ColorMode == PsdColorMode.Multichannel)
            {
                CreateLayersFromChannels(psdFile);
                psdFile.ColorMode = PsdColorMode.Grayscale;
            }

            // Convert into Paint.NET internal representation
            var document = new Document(psdFile.ColumnCount, psdFile.RowCount);

            if (psdFile.Layers.Count == 0)
            {
                psdFile.BaseLayer.CreateMissingChannels();
                var layer = Layer.CreateBackgroundLayer(psdFile.ColumnCount, psdFile.RowCount);
                ImageDecoderPdn.DecodeImage(layer, psdFile.BaseLayer);
                document.Layers.Add(layer);
            }
            else
            {
                psdFile.VerifyLayerSections();
                ApplyLayerSections(psdFile.Layers);

                var pdnLayers = psdFile.Layers.AsParallel().AsOrdered()
                                .Select(psdLayer => psdLayer.DecodeToPdnLayer())
                                .ToList();
                document.Layers.AddRange(pdnLayers);
            }

            SetPdnResolutionInfo(psdFile, document);

            return(document);
        }
Esempio n. 2
0
        public static Document Load(System.IO.Stream input)
        {
            // Load and decompress Photoshop file structures
            var loadContext = new DocumentLoadContext();
            var psdFile     = new PsdFile(input, loadContext);

            // Multichannel images are loaded by processing each channel as a
            // grayscale layer.
            if (psdFile.ColorMode == PsdColorMode.Multichannel)
            {
                CreateLayersFromChannels(psdFile);
                psdFile.ColorMode = PsdColorMode.Grayscale;
            }

            // Convert into Paint.NET internal representation
            var document = new Document(psdFile.ColumnCount, psdFile.RowCount);

            if (psdFile.Layers.Count == 0)
            {
                psdFile.BaseLayer.CreateMissingChannels();
                var layer = PDNWrapper.Layer.CreateBackgroundLayer(psdFile.ColumnCount, psdFile.RowCount);
                ImageDecoderPdn.DecodeImage(layer, psdFile.BaseLayer);
                layer.Name      = String.IsNullOrEmpty(psdFile.BaseLayer.Name)? "Background" : psdFile.BaseLayer.Name;
                layer.Opacity   = psdFile.BaseLayer.Opacity;
                layer.Visible   = psdFile.BaseLayer.Visible;
                layer.IsGroup   = psdFile.BaseLayer.IsGroup;
                layer.LayerID   = psdFile.BaseLayer.LayerID;
                layer.BlendMode = BlendModeMapping.FromPsdBlendMode(psdFile.BaseLayer.BlendModeKey);
                document.Layers.Add(layer);
            }
            else
            {
                psdFile.VerifyLayerSections();
                ApplyLayerSections(psdFile.Layers);

                //var pdnLayers = psdFile.Layers.AsParallel().AsOrdered()
                //  .Select(psdLayer => psdLayer.DecodeToPdnLayer())
                //  .ToList();
                //document.Layers.AddRange(pdnLayers);

                /*
                 *      foreach (var l in psdFile.Layers)
                 * {
                 *  document.Layers.Add(l.DecodeToPdnLayer());
                 * }
                 */
                BitmapLayer parent = null;
                foreach (var l in Enumerable.Reverse(psdFile.Layers))
                {
                    if (l.IsEndGroupMarker)
                    {
                        parent = parent != null ? parent.ParentLayer : null;
                        continue;
                    }
                    var b = l.DecodeToPdnLayer();
                    b.ParentLayer = parent;
                    if (parent != null)
                    {
                        parent.ChildLayer.Add(b);
                    }
                    else
                    {
                        document.Layers.Add(b);
                    }

                    if (b.IsGroup)
                    {
                        parent = b;
                    }
                }
            }
            SetPdnResolutionInfo(psdFile, document);

            return(document);
        }
Esempio n. 3
0
        public static PsdFile Load(System.IO.Stream input, ELoadFlag loadFlag)
        {
            var loadContext = new DocumentLoadContext();

            return(new PsdFile(input, loadContext, loadFlag));
        }