Skip to content

Commit

Permalink
Add mergedimage.png to ORA files
Browse files Browse the repository at this point in the history
This is required as of version 0.0.2 of the ORA spec

Also did some minor refactoring to add 'using' statements.

Bug: #1377566
  • Loading branch information
cameronwhite committed Jan 8, 2022
1 parent 8b1bcd8 commit 632c566
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions Pinta.Core/ImageFormats/OraFormat.cs
Expand Up @@ -203,9 +203,8 @@ public void Export (Document document, string fileName, Gtk.Window parent)
stream.Write (databytes, 0, databytes.Length);

for (int i = 0; i < document.Layers.UserLayers.Count; i++) {
Pixbuf pb = document.Layers.UserLayers[i].Surface.ToPixbuf ();
using Pixbuf pb = document.Layers.UserLayers[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);
Expand All @@ -215,19 +214,21 @@ public void Export (Document document, string fileName, Gtk.Window parent)
databytes = GetLayerXmlData (document.Layers.UserLayers);
stream.Write (databytes, 0, databytes.Length);

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

// Add merged image.
stream.PutNextEntry (new ZipEntry ("mergedimage.png"));
databytes = flattenedPb.SaveToBuffer ("png");
stream.Write (databytes, 0, databytes.Length);

// Add thumbnail.
Size newSize = GetThumbDimensions (flattenedPb.Width, flattenedPb.Height);
using 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 ();
}

Expand Down

0 comments on commit 632c566

Please sign in to comment.