diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-05-01 14:43:08 +0200 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2018-05-01 14:43:08 +0200 |
commit | 2b3f22361da0c1d8e6ce70d71352821758186db7 (patch) | |
tree | 5d10633b47369b3aa52a05bf889ede0dbe5ee108 /src/Photo.vala | |
parent | 211da5fc3048ca2b6ccee2166b0aaaade55cb84f (diff) | |
parent | dc6c76eb04dfe3d4262a1806808f0bc0bf523238 (diff) |
Merge branch 'feature/upstream' into develop
Diffstat (limited to 'src/Photo.vala')
-rw-r--r-- | src/Photo.vala | 51 |
1 files changed, 35 insertions, 16 deletions
diff --git a/src/Photo.vala b/src/Photo.vala index c768017..f089d79 100644 --- a/src/Photo.vala +++ b/src/Photo.vala @@ -628,12 +628,14 @@ public abstract class Photo : PhotoSource, Dateable { // Reads info on a backing photo and adds it. // Note: this function was created for importing new photos. It will not // notify of changes to the developments. - public void add_backing_photo_for_development(RawDeveloper d, BackingPhotoRow bpr) throws Error { + public void add_backing_photo_for_development(RawDeveloper d, BackingPhotoRow bpr, bool notify = true) throws Error { import_developed_backing_photo(row, d, bpr); lock (developments) { developments.set(d, bpr); } - notify_altered(new Alteration("image", "developer")); + + if (notify) + notify_altered(new Alteration("image", "developer")); } public static void import_developed_backing_photo(PhotoRow row, RawDeveloper d, @@ -667,7 +669,7 @@ public abstract class Photo : PhotoSource, Dateable { // "Develops" a raw photo // Not thread-safe. - private void develop_photo(RawDeveloper d) { + private void develop_photo(RawDeveloper d, bool notify) { bool wrote_img_to_disk = false; BackingPhotoRow bps = null; @@ -714,7 +716,7 @@ public abstract class Photo : PhotoSource, Dateable { if (wrote_img_to_disk) { try { // Read in backing photo info, add to DB. - add_backing_photo_for_development(d, bps); + add_backing_photo_for_development(d, bps, notify); notify_raw_development_modified(); } catch (Error e) { @@ -743,17 +745,33 @@ public abstract class Photo : PhotoSource, Dateable { return; } - Gdk.Pixbuf? pix = prev.get_pixbuf(); + var pix = prev.flatten(); if (pix == null) { debug("Could not get preview pixbuf"); return; } - + // Write out file. bps = d.create_backing_row_for_development(row.master.filepath); - PhotoFileWriter writer = PhotoFileFormat.JFIF.create_writer(bps.filepath); - writer.write(pix, Jpeg.Quality.HIGH); - + + // Peek at data. If we really have a JPEG image, just use it, + // otherwise do GdkPixbuf roundtrip + if (Jpeg.is_jpeg_bytes(pix)) { + var outfile = File.new_for_path(bps.filepath); + outfile.replace_contents(pix.get_data(), null, + false, FileCreateFlags.NONE, null); + } else { + var pixbuf = prev.get_pixbuf(); + if (pixbuf == null) { + debug("Could not get preview pixbuf"); + return; + } + + var writer = PhotoFileFormat.JFIF.create_writer(bps.filepath); + writer.write(pixbuf, Jpeg.Quality.HIGH); + } + + // Remember that we wrote it (see above // case for why this is necessary). wrote_img_to_disk = true; @@ -768,7 +786,7 @@ public abstract class Photo : PhotoSource, Dateable { if (wrote_img_to_disk) { try { // Read in backing photo info, add to DB. - add_backing_photo_for_development(d, bps); + add_backing_photo_for_development(d, bps, notify); notify_raw_development_modified(); } catch (Error e) { @@ -792,7 +810,7 @@ public abstract class Photo : PhotoSource, Dateable { } // Sets the developer and develops the photo. - public void set_raw_developer(RawDeveloper d) { + public void set_raw_developer(RawDeveloper d, bool notify = true) { if (get_master_file_format() != PhotoFileFormat.RAW) return; @@ -804,7 +822,7 @@ public abstract class Photo : PhotoSource, Dateable { // If the embedded preview is too small to be used in the PhotoPage, don't // allow EMBEDDED to be chosen. - if (!is_raw_developer_available(RawDeveloper.EMBEDDED)) + if (!is_raw_developer_available(RawDeveloper.EMBEDDED) && d != RawDeveloper.CAMERA) d = RawDeveloper.SHOTWELL; lock (developments) { @@ -812,7 +830,7 @@ public abstract class Photo : PhotoSource, Dateable { // Perform development, bail out if it doesn't work. if (!is_raw_developer_complete(d)) { - develop_photo(d); + develop_photo(d, notify); } if (!developments.has_key(d)) return; // we tried! @@ -855,14 +873,15 @@ public abstract class Photo : PhotoSource, Dateable { // and is to be preserved. } - notify_altered(new Alteration("image", "developer")); + if (notify) + notify_altered(new Alteration("image", "developer")); discard_prefetched(); } - + public RawDeveloper get_raw_developer() { return row.developer; } - + // Removes a development from the database, filesystem, etc. // Returns true if a development was removed, otherwise false. private bool delete_raw_development(RawDeveloper d) { |