Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(174)

Unified Diff: ui/file_manager/gallery/js/gallery_item.js

Issue 936143003: Start to use new metadata item in ImageEncoder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/file_manager/gallery/js/gallery_item.js
diff --git a/ui/file_manager/gallery/js/gallery_item.js b/ui/file_manager/gallery/js/gallery_item.js
index 088da41af9359de0d73416de9de9d9925d509d73..922c07bed1b0a6de7a210dea35aede91f9587a92 100644
--- a/ui/file_manager/gallery/js/gallery_item.js
+++ b/ui/file_manager/gallery/js/gallery_item.js
@@ -282,33 +282,36 @@ Gallery.Item.prototype.saveToFile = function(
};
var doSave = function(newFile, fileEntry) {
- fileEntry.createWriter(function(fileWriter) {
- var writeContent = function() {
- fileWriter.onwriteend = onSuccess.bind(null, fileEntry);
- // TODO(hirono): Remove the quality 1 for thumbanils. The code path is
- // no longer used.
- var metadataEncoder = ImageEncoder.encodeMetadata(
- this.metadata_, canvas, 1 /* quality */);
- // Contrary to what one might think 1.0 is not a good default. Opening
- // and saving an typical photo taken with consumer camera increases its
- // file size by 50-100%. Experiments show that 0.9 is much better. It
- // shrinks some photos a bit, keeps others about the same size, but does
- // not visibly lower the quality.
- fileWriter.write(ImageEncoder.getBlob(canvas, metadataEncoder, 0.9));
- }.bind(this);
- fileWriter.onerror = function(error) {
- onError(error);
- // Disable all callbacks on the first error.
- fileWriter.onerror = null;
- fileWriter.onwriteend = null;
- };
- if (newFile) {
- writeContent();
- } else {
- fileWriter.onwriteend = writeContent;
- fileWriter.truncate(0);
- }
- }.bind(this), onError);
+ var metadataPromise = this.fileSystemMetadata_.get(
+ [fileEntry],
+ ['mediaMimeType', 'contentMimeType', 'ifd', 'exifLittleEndian']);
+ metadataPromise.then(function(metadataItems) {
+ fileEntry.createWriter(function(fileWriter) {
+ var writeContent = function() {
+ fileWriter.onwriteend = onSuccess.bind(null, fileEntry);
+ var metadataEncoder = ImageEncoder.encodeMetadata(
+ metadataItems[0], canvas, /* quality for thumbnail*/ 0.8);
+ // Contrary to what one might think 1.0 is not a good default. Opening
+ // and saving an typical photo taken with consumer camera increases
+ // its file size by 50-100%. Experiments show that 0.9 is much better.
+ // It shrinks some photos a bit, keeps others about the same size, but
+ // does not visibly lower the quality.
+ fileWriter.write(ImageEncoder.getBlob(canvas, metadataEncoder, 0.9));
+ }.bind(this);
+ fileWriter.onerror = function(error) {
+ onError(error);
+ // Disable all callbacks on the first error.
+ fileWriter.onerror = null;
+ fileWriter.onwriteend = null;
+ };
+ if (newFile) {
+ writeContent();
+ } else {
+ fileWriter.onwriteend = writeContent;
+ fileWriter.truncate(0);
+ }
+ }.bind(this), onError);
+ }.bind(this));
}.bind(this);
var getFile = function(dir, newFile) {

Powered by Google App Engine
This is Rietveld 408576698