예제 #1
0
파일: TgaExporter.cs 프로젝트: rikky/Pinta
        // For now, we only export in uncompressed ARGB32 format. If someone requests this functionality,
        // we can always add more through an export dialog.
        public void Export(LayerManager layers, string fileName)
        {
            ImageSurface surf = layers.GetFlattenedImage (); // Assumes the surface is in ARGB32 format
            BinaryWriter writer = new BinaryWriter (new FileStream (fileName, FileMode.Create, FileAccess.Write));

            try {
                TgaHeader header = new TgaHeader();

                header.idLength = 0;
                header.cmapType = 0;
                header.imageType = 2; // uncompressed RGB
                header.cmapIndex = 0;
                header.cmapLength = 0;
                header.cmapEntrySize = 0;
                header.xOrigin = 0;
                header.yOrigin = 0;
                header.imageWidth = (ushort) surf.Width;
                header.imageHeight = (ushort) surf.Height;
                header.pixelDepth = 32;
                header.imageDesc = 8; // 32-bit, lower-left origin, which is weird but hey...
                header.WriteTo (writer);

                byte[] data = surf.Data;

                // It just so happens that the Cairo ARGB32 internal representation matches
                // the TGA format, except vertically-flipped. In little-endian, of course.
                for (int y = surf.Height - 1; y >= 0; y--)
                    writer.Write (data, surf.Stride * y, surf.Stride);
            } finally {
                (surf as IDisposable).Dispose ();
                writer.Close ();
            }
        }
예제 #2
0
파일: PintaCore.cs 프로젝트: asbjornu/Pinta
 static PintaCore()
 {
     Resources = new ResourceManager ();
     Actions = new ActionManager ();
     Workspace = new WorkspaceManager ();
     Layers = new LayerManager ();
     Tools = new ToolManager ();
     History = new HistoryManager ();
 }
예제 #3
0
        public void Export(LayerManager layers, string fileName)
        {
            Cairo.ImageSurface surf = layers.GetFlattenedImage ();

            Pixbuf pb = surf.ToPixbuf ();
            DoSave(pb, fileName, filetype);

            (pb as IDisposable).Dispose ();
            (surf as IDisposable).Dispose ();
        }
예제 #4
0
파일: PintaCore.cs 프로젝트: mrolappe/Pinta
 static PintaCore()
 {
     Resources = new ResourceManager ();
     Actions = new ActionManager ();
     Workspace = new WorkspaceManager ();
     Layers = new LayerManager ();
     Tools = new ToolManager ();
     History = new HistoryManager ();
     System = new SystemManager ();
     LivePreview = new LivePreviewManager ();
 }
예제 #5
0
파일: PintaCore.cs 프로젝트: RodH257/Pinta
 static PintaCore()
 {
     Resources = new ResourceManager ();
     Actions = new ActionManager ();
     Workspace = new WorkspaceManager ();
     Layers = new LayerManager ();
     PaintBrushes = new PaintBrushManager ();
     Tools = new ToolManager ();
     History = new HistoryManager ();
     System = new SystemManager ();
     LivePreview = new LivePreviewManager ();
     Palette = new PaletteManager ();
     Settings = new SettingsManager ();
     Chrome = new ChromeManager ();
 }
예제 #6
0
        public void Import(LayerManager layers, string fileName)
        {
            Pixbuf bg = new Pixbuf (fileName);
            Size imagesize = new Size (bg.Width, bg.Height);

            PintaCore.Workspace.CreateAndActivateDocument (fileName, imagesize);
            PintaCore.Workspace.ActiveDocument.HasFile = true;
            PintaCore.Workspace.ActiveDocument.ImageSize = imagesize;
            PintaCore.Workspace.ActiveWorkspace.CanvasSize = imagesize;

            Layer layer = layers.AddNewLayer (Path.GetFileName (fileName));

            using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                g.Paint ();
            }

            bg.Dispose ();
        }
예제 #7
0
        public void Import(LayerManager layers, string fileName)
        {
            Pixbuf bg = new Pixbuf (fileName);

            layers.Clear ();
            PintaCore.History.Clear ();
            layers.DestroySelectionLayer ();

            PintaCore.Workspace.ImageSize = new Size (bg.Width, bg.Height);
            PintaCore.Workspace.CanvasSize = new Gdk.Size (bg.Width, bg.Height);
            layers.ResetSelectionPath ();

            Layer layer = layers.AddNewLayer (Path.GetFileName (fileName));

            using (Cairo.Context g = new Cairo.Context (layer.Surface)) {
                CairoHelper.SetSourcePixbuf (g, bg, 0, 0);
                g.Paint ();
            }

            bg.Dispose ();
        }
예제 #8
0
        public void Export(LayerManager layers, string fileName)
        {
            ZipOutputStream stream = new ZipOutputStream (new FileStream (fileName, FileMode.Create));
            ZipEntry mimetype = new ZipEntry ("mimetype");
            mimetype.CompressionMethod = CompressionMethod.Stored;
            stream.PutNextEntry (mimetype);

            byte[] databytes = System.Text.Encoding.ASCII.GetBytes ("image/openraster");
            stream.Write (databytes, 0, databytes.Length);

            for (int i = 0; i < layers.Count; i++) {
                Pixbuf pb = layers[i].Surface.ToPixbuf ();
                byte[] buf = pb.SaveToBuffer ("png");
                (pb as IDisposable).Dispose ();

                stream.PutNextEntry (new ZipEntry ("data/layer" + i.ToString () + ".png"));
                stream.Write (buf, 0, buf.Length);
            }

            stream.PutNextEntry (new ZipEntry ("stack.xml"));
            databytes = GetLayerXmlData (layers);
            stream.Write (databytes, 0, databytes.Length);

            ImageSurface flattened = layers.GetFlattenedImage();
            Pixbuf flattenedPb = flattened.ToPixbuf ();
            Size newSize = GetThumbDimensions (flattenedPb.Width, flattenedPb.Height);
            Pixbuf thumb = flattenedPb.ScaleSimple (newSize.Width, newSize.Height, InterpType.Bilinear);

            stream.PutNextEntry (new ZipEntry ("Thumbnails/thumbnail.png"));
            databytes = thumb.SaveToBuffer ("png");
            stream.Write (databytes, 0, databytes.Length);

            (flattened as IDisposable).Dispose();
            (flattenedPb as IDisposable).Dispose();
            (thumb as IDisposable).Dispose();

            stream.Close ();
        }
예제 #9
0
        public void Import(LayerManager layers, string fileName)
        {
            ZipFile file = new ZipFile (fileName);
            XmlDocument stackXml = new XmlDocument ();
            stackXml.Load (file.GetInputStream (file.GetEntry ("stack.xml")));

            XmlElement imageElement = stackXml.DocumentElement;
            int width = int.Parse (imageElement.GetAttribute ("w"));
            int height = int.Parse (imageElement.GetAttribute ("h"));

            XmlElement stackElement = (XmlElement) stackXml.GetElementsByTagName ("stack")[0];
            XmlNodeList layerElements = stackElement.GetElementsByTagName ("layer");

            if (layerElements.Count == 0)
                throw new XmlException ("No layers found in OpenRaster file");

            layers.Clear ();
            PintaCore.History.Clear ();
            layers.DestroySelectionLayer ();
            PintaCore.Workspace.ImageSize = new Size (width, height);
            PintaCore.Workspace.CanvasSize = new Gdk.Size (width, height);

            for (int i = 0; i < layerElements.Count; i++) {
                XmlElement layerElement = (XmlElement) layerElements[i];
                int x = int.Parse (GetAttribute (layerElement, "x", "0"));
                int y = int.Parse (GetAttribute (layerElement, "y", "0"));
                string name = GetAttribute (layerElement, "name", string.Format ("Layer {0}", i));

                try {
                    // Write the file to a temporary file first
                    // Fixes a bug when running on .Net
                    ZipEntry zf = file.GetEntry (layerElement.GetAttribute ("src"));
                    Stream s = file.GetInputStream (zf);
                    string tmp_file = System.IO.Path.GetTempFileName ();

                    using (Stream stream_out = File.Open (tmp_file, FileMode.OpenOrCreate)) {
                        byte[] buffer = new byte[2048];

                        while (true) {
                            int len = s.Read (buffer, 0, buffer.Length);

                            if (len > 0)
                                stream_out.Write (buffer, 0, len);
                            else
                                break;
                        }
                    }

                    Layer layer = layers.CreateLayer (name, width, height);
                    layers.Insert (layer, 0);
                    layer.Opacity = double.Parse (GetAttribute (layerElement, "opacity", "1"), GetFormat ());

                    using (Pixbuf pb = new Pixbuf (tmp_file)) {
                        using (Context g = new Context (layer.Surface)) {
                            CairoHelper.SetSourcePixbuf (g, pb, x, y);
                            g.Paint ();
                        }
                    }

                    try {
                        File.Delete (tmp_file);
                    } catch { }
                } catch {
                    MessageDialog md = new MessageDialog (PintaCore.Chrome.MainWindow, DialogFlags.Modal, MessageType.Error, ButtonsType.Ok, "Could not import layer \"{0}\" from {0}", name, file);
                    md.Title = "Error";

                    md.Run ();
                    md.Destroy ();
                }
            }

            file.Close ();
        }
예제 #10
0
        private byte[] GetLayerXmlData(LayerManager layers)
        {
            MemoryStream ms = new MemoryStream ();
            XmlTextWriter writer = new XmlTextWriter (ms, System.Text.Encoding.UTF8);
            writer.Formatting = Formatting.Indented;

            writer.WriteStartElement ("image");
            writer.WriteAttributeString ("w", layers[0].Surface.Width.ToString ());
            writer.WriteAttributeString ("h", layers[0].Surface.Height.ToString ());

            writer.WriteStartElement ("stack");
            writer.WriteAttributeString ("opacity", "1");
            writer.WriteAttributeString ("name", "root");

            // ORA stores layers top to bottom
            for (int i = layers.Count - 1; i >= 0; i--) {
                writer.WriteStartElement ("layer");
                writer.WriteAttributeString ("opacity", layers[i].Hidden ? "0" : string.Format (GetFormat (), "{0:0.00}", layers[i].Opacity));
                writer.WriteAttributeString ("name", layers[i].Name);
                writer.WriteAttributeString ("src", "data/layer" + i.ToString () + ".png");
                writer.WriteEndElement ();
            }

            writer.WriteEndElement (); // stack
            writer.WriteEndElement (); // image

            writer.Close ();
            return ms.ToArray ();
        }