Esempio n. 1
0
        public Bitmap Render(Stream s, out IList<IPsdLayer> layers, out Size size,ShowLayerDelegate showLayerCallback, ComposeLayerDelegate composeLayer)
        {
            PsdFile file = new PsdFile();
            file.Load(s);
            //Start with a transparent bitmap (not all PSD files have background layers)
            size = new Size(file.Columns, file.Rows);
            Bitmap b = new Bitmap(file.Columns, file.Rows);

            //ImageDecoder.DecodeImage(file.Layers[0]); //Layers collection doesn't include the composed layer

            Graphics g = Graphics.FromImage(b);
            using (g){
                g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                g.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceOver;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

                for (int i = 0; i < file.Layers.Count; i++)
                {
                    if (showLayerCallback(i,file.Layers[i].Name,file.Layers[i].Visible)){
                        using (Bitmap frame = ImageDecoder.DecodeImage(file.Layers[i])){
                            composeLayer(g, frame, file.Layers[i]);
                        }
                    }
                }
            }
            layers = getLayers(file);
            return b;
        }
Esempio n. 2
0
 public IList<IPsdLayer> GetLayersAndSize(Stream s, out Size size)
 {
     PsdFile file = new PsdFile();
     file.Load(s);
     size = new Size(file.Columns,file.Rows);
     return getLayers(file);
 }
Esempio n. 3
0
        public Bitmap Decode(Stream s)
        {
            //Bitmap we will render to
            System.Drawing.Bitmap b = null;

            //Time just the parsing/rendering
            Stopwatch swRender = new Stopwatch();
            swRender.Start();

            PsdFile psdFile = new PsdFile();
            psdFile.Load(s);
            //Load background layer
            b = ImageDecoder.DecodeImage(psdFile); //Layers collection doesn't include the composed layer

            //How fast?
            swRender.Stop();
            trace("Parsing and rendering PSD to a Bitmap instance took " + swRender.ElapsedMilliseconds.ToString(NumberFormatInfo.InvariantInfo) + "ms");

            return b;
        }
Esempio n. 4
0
        private void Main_Load(object sender, EventArgs ev)
        {
            #region Form location

            Location = Settings.Default.StartLocation;

            FormClosing += (s, e) =>
            {
                Settings.Default.StartLocation = Location;
                Settings.Default.Save();
            };

            #endregion

            DragEventHandler enter = (s, e) =>
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    string[] files = e.Data.GetData(DataFormats.FileDrop, false) as string[];
                    if (files.FirstOrDefault<string>().EndsWith(".psd", StringComparison.OrdinalIgnoreCase))
                    {
                        e.Effect = DragDropEffects.Copy;
                    }
                }
            };
            DragEventHandler drop = (s, e) =>
            {
                if (e.Data.GetDataPresent(DataFormats.FileDrop))
                {
                    string file = (e.Data.GetData(DataFormats.FileDrop, false) as string[]).FirstOrDefault<string>();
                    PsdFile ps = new PsdFile();
                    ps.Load(file);
                    MapLayers(ps);
                }
            };

            base.DragEnter += enter;
            base.DragDrop += drop;
        }
Esempio n. 5
0
        private void OnOpenClick(object sender, EventArgs e)
        {
            string fileName = m_fileName.Text;
              if (File.Exists(fileName))
              {
            UpdateFileLst(fileName);

            PsdFile pt = new PsdFile();

            this.Cursor = Cursors.WaitCursor;
            pt.Load(fileName);

            m_fileStructure.Nodes.Clear();

            TreeNode fileNode = new TreeNode("PSD File");
            fileNode.Tag = pt;

            m_fileStructure.Nodes.Add(fileNode);

            foreach (Layer layer in pt.Layers)
            {
              TreeNode layerNode = new TreeNode("Layer Name=" + layer.Name);
              layerNode.Tag = layer;
              fileNode.Nodes.Add(layerNode);

              foreach (Layer.Channel ch in layer.Channels)
              {
            TreeNode chNode = new TreeNode("Channel ID=" + ch.ID.ToString());
            chNode.Tag = ch;
            layerNode.Nodes.Add(chNode);
              }

              TreeNode maskNode = new TreeNode("Mask");
              maskNode.Tag = layer.MaskData;
              layerNode.Nodes.Add(maskNode);

              TreeNode blendingNode = new TreeNode("BlendingRangesData");
              blendingNode.Tag = layer.BlendingRangesData;
              layerNode.Nodes.Add(blendingNode);

              foreach (Layer.AdjustmentLayerInfo adjInfo in layer.AdjustmentInfo)
              {
            TreeNode node = new TreeNode(adjInfo.Key);
            node.Tag = adjInfo;
            layerNode.Nodes.Add(node);
              }
            }

            m_fileStructure.SelectedNode = fileNode;

            this.Cursor = Cursors.Default;

            //pt.Save(Path.Combine(Path.GetDirectoryName(m_fileName.Text), Path.GetFileNameWithoutExtension(m_fileName.Text) + "-s.psd"));
              }
        }
Esempio n. 6
0
        private static Texture LoadSpriteSheetAbsolute(string title, string file_name)
        {
            // Load and decompress Photoshop file structures
            var psdFile = new PsdFile ();
            psdFile.Load (file_name, Encoding.Default);

            if (psdFile.Layers.Count == 0) {
                psdFile.BaseLayer.CreateMissingChannels ();
            }
            var layer = psdFile.BaseLayer;
            using (Bitmap bmp = new Bitmap(psdFile.ColumnCount, psdFile.RowCount)) {
                using (Graphics gfx = Graphics.FromImage(bmp)) {
                    gfx.Clear (Color.Transparent);
                    var bmp_data = bmp.LockBits (layer.Rect, ImageLockMode.WriteOnly, PixelFormat.Format32bppArgb);
                    int pixel_size = 4 * sizeof(byte);
                    int idx = 0;
                    for (int i = 0; i < bmp_data.Height; i++) {
                        for (int j = 0; j < bmp_data.Width; j++) {
                            Marshal.Copy (new byte[]{
                            layer.Channels [2].ImageData [idx],
                            layer.Channels [1].ImageData [idx],
                            layer.Channels [0].ImageData [idx],
                            layer.Channels [3].ImageData [idx],
                        }, 0, new IntPtr ((long)bmp_data.Scan0 + i * bmp_data.Stride + j * pixel_size), pixel_size);
                            idx++;
                        }
                    }
                    bmp.UnlockBits (bmp_data);
                }
                var texture = Texture.LoadTexture (title, bmp);
                psdFile.SlicesToTextureRegionInfo (ref texture);
                return texture;
            }
        }
Esempio n. 7
0
 public IList<IPsdLayer> GetLayers(Stream s)
 {
     PsdFile file = new PsdFile();
     file.Load(s);
     return getLayers(file);
 }