Esempio n. 1
0
            public void LoadLayer(object context)
            {
                var layer = ImageDecoderPdn.DecodeImage(psdLayer);

                layer.Name    = psdLayer.Name;
                layer.Opacity = psdLayer.Opacity;
                layer.Visible = psdLayer.Visible;
                layer.SetBlendOp(blendOp);

                layersList[idxLayersList] = layer;
            }
Esempio n. 2
0
        private void DecodeMaskAlphaRow32(NativeArray <byte> Alpha, int dstStart, int dstStops, NativeArray <byte> Mask, int maskStart)
        {
            NativeArray <float> floatArray = Mask.Reinterpret <float>(1);

            while (dstStart < dstStops)
            {
                Alpha[dstStart] = ImageDecoderPdn.RGBByteFromHDRFloat(floatArray[maskStart / 4]);

                dstStart++;
                maskStart += 4;
            }
        }
Esempio n. 3
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));
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        // Case 1:
        private void SetPDNRowGrayscale32(int dstStart, int dstStops, int idxSrc)
        {
            NativeArray <float> channel = Data.ColorChannel0.Reinterpret <float>(1);
            var c = Data.DecodedImage[dstStart];

            while (dstStart < dstStops)
            {
                byte rgbValue = ImageDecoderPdn.RGBByteFromHDRFloat(channel[idxSrc / 4]);
                c.r = rgbValue;
                c.g = rgbValue;
                c.b = rgbValue;
                Data.DecodedImage[dstStart] = c;

                dstStart++;
                idxSrc += 4;
            }
        }
Esempio n. 6
0
        // Case 0:
        private void SetPDNRowRgb32(int dstStart, int dstStops, int idxSrc)
        {
            NativeArray <float> cR = Data.ColorChannel0.Reinterpret <float>(1);
            NativeArray <float> cG = Data.ColorChannel1.Reinterpret <float>(1);
            NativeArray <float> cB = Data.ColorChannel2.Reinterpret <float>(1);
            var c = Data.DecodedImage[dstStart];

            while (dstStart < dstStops)
            {
                c.r = ImageDecoderPdn.RGBByteFromHDRFloat(cR[idxSrc / 4]);
                c.g = ImageDecoderPdn.RGBByteFromHDRFloat(cG[idxSrc / 4]);
                c.b = ImageDecoderPdn.RGBByteFromHDRFloat(cB[idxSrc / 4]);
                Data.DecodedImage[dstStart] = c;

                dstStart++;
                idxSrc += 4;
            }
        }
Esempio n. 7
0
        protected override Document OnLoad(System.IO.Stream input)
        {
            PsdFile psdFile = new PsdFile();

            psdFile.Load(input);

            Document document = new Document(psdFile.Columns, psdFile.Rows);

            if (psdFile.Resolution != null)
            {
                document.DpuUnit = MeasurementUnit.Inch;
                document.DpuX    = psdFile.Resolution.HRes;
                document.DpuY    = psdFile.Resolution.VRes;
            }

            if (psdFile.Layers.Count == 0)
            {
                BitmapLayer layer = ImageDecoderPdn.DecodeImage(psdFile);
                document.Layers.Add(layer);
            }
            else
            {
                PaintDotNet.Threading.PrivateThreadPool threadPool = new PaintDotNet.Threading.PrivateThreadPool();
                var layersList = new List <Layer>();
                foreach (PhotoshopFile.Layer l in psdFile.Layers)
                {
                    if (!l.Rect.IsEmpty)
                    {
                        layersList.Add(null);
                        LoadLayerContext llc          = new LoadLayerContext(l, document, BlendModeKeyToBlendOp(l), layersList, layersList.Count - 1);
                        WaitCallback     waitCallback = new WaitCallback(llc.LoadLayer);
                        threadPool.QueueUserWorkItem(waitCallback);
                    }
                }
                threadPool.Drain();

                foreach (var layer in layersList)
                {
                    document.Layers.Add(layer);
                }
            }
            return(document);
        }
Esempio n. 8
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. 9
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. 10
0
        private void SetPDNAlphaRow(int dstStart, int dstStops, int idxSrc)
        {
            // Set alpha to fully-opaque if there is no alpha channel
            if (0 == Data.HasAlphaChannel)
            {
                while (dstStart < dstStops)
                {
                    var c = Data.DecodedImage[dstStart];
                    c.a = 255;
                    Data.DecodedImage[dstStart] = c;
                    dstStart++;
                }
            }
            // Set the alpha channel data
            else
            {
                NativeArray <float> srcAlphaChannel = Data.AlphaChannel0.Reinterpret <float>(1);
                {
                    while (dstStart < dstStops)
                    {
                        var c = Data.DecodedImage[dstStart];
                        c.a = (Data.SurfaceByteDepth < 4) ? Data.AlphaChannel0[idxSrc] : ImageDecoderPdn.RGBByteFromHDRFloat(srcAlphaChannel[idxSrc / 4]);

                        Data.DecodedImage[dstStart] = c;
                        dstStart++;
                        idxSrc += Data.SurfaceByteDepth;
                    }
                }
            }
        }