summaryrefslogtreecommitdiff
path: root/src/page.vala
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2017-12-14 11:36:54 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2017-12-14 11:36:54 +0100
commitcebf725978b32756700671a646aaed9677f6f219 (patch)
tree8aad7e2e09ba66c6ab36da556f7b8265b31898a6 /src/page.vala
parent13eec502b99e47e9910b5610869236698e1a8a13 (diff)
parenta632195d632be90e0da0ed0eef4b0987ed4bea6c (diff)
Merge branch 'release/3.26.2-1'3.26.2-1
Diffstat (limited to 'src/page.vala')
-rw-r--r--src/page.vala71
1 files changed, 18 insertions, 53 deletions
diff --git a/src/page.vala b/src/page.vala
index 9636d0d..582aef8 100644
--- a/src/page.vala
+++ b/src/page.vala
@@ -624,13 +624,16 @@ public class Page
return image;
}
- private string? get_icc_data_encoded (string icc_profile_filename)
+ public string? get_icc_data_encoded ()
{
+ if (color_profile == null)
+ return null;
+
/* Get binary data */
string contents;
try
{
- FileUtils.get_contents (icc_profile_filename, out contents);
+ FileUtils.get_contents (color_profile, out contents);
}
catch (Error e)
{
@@ -641,71 +644,33 @@ public class Page
/* Encode into base64 */
return Base64.encode ((uchar[]) contents.to_utf8 ());
}
-
+
public void copy_to_clipboard (Gtk.Window window)
- {
+ {
var display = window.get_display ();
var clipboard = Gtk.Clipboard.get_for_display (display, Gdk.SELECTION_CLIPBOARD);
var image = get_image (true);
clipboard.set_image (image);
}
- public void save (string type, int quality, File file) throws Error
+ public void save_png (File file) throws Error
{
var stream = file.replace (null, false, FileCreateFlags.NONE, null);
- var writer = new PixbufWriter (stream);
var image = get_image (true);
string? icc_profile_data = null;
if (color_profile != null)
- icc_profile_data = get_icc_data_encoded (color_profile);
+ icc_profile_data = get_icc_data_encoded ();
- if (strcmp (type, "jpeg") == 0)
- {
- string[] keys = { "x-dpi", "y-dpi", "quality", "icc-profile", null };
- string[] values = { "%d".printf (dpi), "%d".printf (dpi), "%d".printf (quality), icc_profile_data, null };
- if (icc_profile_data == null)
- keys[3] = null;
- writer.save (image, "jpeg", keys, values);
- }
- else if (strcmp (type, "png") == 0)
- {
- string[] keys = { "x-dpi", "y-dpi", "icc-profile", null };
- string[] values = { "%d".printf (dpi), "%d".printf (dpi), icc_profile_data, null };
- if (icc_profile_data == null)
- keys[2] = null;
- writer.save (image, "png", keys, values);
- }
- else if (strcmp (type, "tiff") == 0)
- {
- string[] keys = { "x-dpi", "y-dpi", "compression", "icc-profile", null };
- string[] values = { "%d".printf (dpi), "%d".printf (dpi), "8" /* Deflate compression */, icc_profile_data, null };
- if (icc_profile_data == null)
- keys[3] = null;
- writer.save (image, "tiff", keys, values);
- }
- else
- throw new FileError.INVAL ("Unknown file type: %s".printf (type));
- }
-}
-
-public class PixbufWriter
-{
- public FileOutputStream stream;
-
- public PixbufWriter (FileOutputStream stream)
- {
- this.stream = stream;
- }
+ string[] keys = { "x-dpi", "y-dpi", "icc-profile", null };
+ string[] values = { "%d".printf (dpi), "%d".printf (dpi), icc_profile_data, null };
+ if (icc_profile_data == null)
+ keys[2] = null;
- public void save (Gdk.Pixbuf image, string type, string[] option_keys, string[] option_values) throws Error
- {
- image.save_to_callbackv (write_pixbuf_data, type, option_keys, option_values);
- }
-
- private bool write_pixbuf_data (uint8[] buf) throws Error
- {
- stream.write_all (buf, null, null);
- return true;
+ image.save_to_callbackv ((buf) =>
+ {
+ stream.write_all (buf, null, null);
+ return true;
+ }, "png", keys, values);
}
}