Ejemplo n.º 1
0
        internal static JobHandle DecodeToPdnLayer(this PhotoshopFile.Layer psdLayer, JobHandle inputDeps, out BitmapLayer pdnLayer)
        {
            var psdFile = psdLayer.PsdFile;

            psdLayer.CreateMissingChannels();

            pdnLayer           = new BitmapLayer(psdFile.ColumnCount, psdFile.RowCount);
            pdnLayer.Name      = psdLayer.Name;
            pdnLayer.Opacity   = psdLayer.Opacity;
            pdnLayer.Visible   = psdLayer.Visible;
            pdnLayer.IsGroup   = psdLayer.IsGroup;
            pdnLayer.LayerID   = psdLayer.LayerID;
            pdnLayer.BlendMode = BlendModeMapping.FromPsdBlendMode(psdLayer.BlendModeKey);
            return(ImageDecoderPdn.DecodeImage(pdnLayer, psdLayer, inputDeps));
        }
Ejemplo n.º 2
0
        internal static BitmapLayer DecodeToPdnLayer(
            this PhotoshopFile.Layer psdLayer)
        {
            var psdFile = psdLayer.PsdFile;

            psdLayer.CreateMissingChannels();

            var pdnLayer = new BitmapLayer(psdFile.ColumnCount, psdFile.RowCount);

            pdnLayer.Name      = psdLayer.Name;
            pdnLayer.Opacity   = psdLayer.Opacity;
            pdnLayer.Visible   = psdLayer.Visible;
            pdnLayer.BlendMode = BlendModeMapping.FromPsdBlendMode(psdLayer.BlendModeKey);
            ImageDecoderPdn.DecodeImage(pdnLayer, psdLayer);

            return(pdnLayer);
        }
Ejemplo n.º 3
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);
        }