diff options
author | hirono <hirono@chromium.org> | 2015-02-24 01:02:03 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-24 09:02:56 +0000 |
commit | 0a99c64e6420858bcb14b5accfc5ee1c608adfd6 (patch) | |
tree | 33c8f5d2787e7516af24091a4111fb9043029971 | |
parent | 2ca19cc7c0dcc020e5faa88c3c1e09f8fa4fa157 (diff) | |
download | chromium_src-0a99c64e6420858bcb14b5accfc5ee1c608adfd6.zip chromium_src-0a99c64e6420858bcb14b5accfc5ee1c608adfd6.tar.gz chromium_src-0a99c64e6420858bcb14b5accfc5ee1c608adfd6.tar.bz2 |
Gallery: Stop to create EXIF thumbanil if the original images are enough small.
Previously Gallery.app generates thumbnails always and its size is limited to
1/4 of orignal size. Then Files.app tries to show the small thumbnail. It looks
bluer.
BUG=458025
TEST=None
Review URL: https://codereview.chromium.org/948233003
Cr-Commit-Position: refs/heads/master@{#317770}
-rw-r--r-- | ui/file_manager/gallery/js/image_editor/exif_encoder.js | 3 | ||||
-rw-r--r-- | ui/file_manager/gallery/js/image_editor/image_encoder.js | 39 |
2 files changed, 27 insertions, 15 deletions
diff --git a/ui/file_manager/gallery/js/image_editor/exif_encoder.js b/ui/file_manager/gallery/js/image_editor/exif_encoder.js index f6c47d2..43f88da 100644 --- a/ui/file_manager/gallery/js/image_editor/exif_encoder.js +++ b/ui/file_manager/gallery/js/image_editor/exif_encoder.js @@ -108,7 +108,7 @@ ExifEncoder.prototype.setThumbnailData = function(canvas, quality) { break; } - if (this.metadata_.thumbnailURL.length <= maxDataURLLength) { + if (canvas && this.metadata_.thumbnailURL.length <= maxDataURLLength) { var thumbnail = this.ifd_.thumbnail; if (!thumbnail) thumbnail = this.ifd_.thumbnail = {}; @@ -138,7 +138,6 @@ ExifEncoder.prototype.setThumbnailData = function(canvas, quality) { delete this.ifd_.thumbnail; } } - delete this.metadata_.thumbnailTransform; }; /** diff --git a/ui/file_manager/gallery/js/image_editor/image_encoder.js b/ui/file_manager/gallery/js/image_editor/image_encoder.js index 7131d4b..f7b900c 100644 --- a/ui/file_manager/gallery/js/image_editor/image_encoder.js +++ b/ui/file_manager/gallery/js/image_editor/image_encoder.js @@ -8,6 +8,19 @@ function ImageEncoder() {} /** + * The value 360 px is enough in Files.app grid view for HiDPI devices. + * @const {number} + */ +ImageEncoder.MAX_THUMBNAIL_DIMENSION = 360; + +/** + * Tries to create thumbnail if the image width or height longer than the size. + * @const {number} + */ +ImageEncoder.MIN_IMAGE_DIMENSION_FOR_THUMBNAIL = + ImageEncoder.MAX_THUMBNAIL_DIMENSION * 4; + +/** * Metadata encoders. * @type {!Object.<string,function(new:ImageEncoder.MetadataEncoder,!Object)>} * @const @@ -123,21 +136,20 @@ ImageEncoder.decodeDataURL = function(dataURL) { /** * Return a thumbnail for an image. * @param {!HTMLCanvasElement} canvas Original image. - * @param {number=} opt_shrinkage Thumbnail should be at least this much smaller - * than the original image (in each dimension). - * @return {!HTMLCanvasElement} Thumbnail canvas. + * @return {HTMLCanvasElement} Thumbnail canvas. */ -ImageEncoder.createThumbnail = function(canvas, opt_shrinkage) { - var MAX_THUMBNAIL_DIMENSION = 320; - - opt_shrinkage = Math.max(opt_shrinkage || 4, - canvas.width / MAX_THUMBNAIL_DIMENSION, - canvas.height / MAX_THUMBNAIL_DIMENSION); +ImageEncoder.createThumbnail = function(canvas) { + if (canvas.width < ImageEncoder.MIN_IMAGE_DIMENSION_FOR_THUMBNAIL && + canvas.height < ImageEncoder.MIN_IMAGE_DIMENSION_FOR_THUMBNAIL) { + return null; + } + var ratio = Math.min(ImageEncoder.MAX_THUMBNAIL_DIMENSION / canvas.width, + ImageEncoder.MAX_THUMBNAIL_DIMENSION / canvas.height); var thumbnailCanvas = assertInstanceof( canvas.ownerDocument.createElement('canvas'), HTMLCanvasElement); - thumbnailCanvas.width = Math.round(canvas.width / opt_shrinkage); - thumbnailCanvas.height = Math.round(canvas.height / opt_shrinkage); + thumbnailCanvas.width = Math.round(canvas.width * ratio); + thumbnailCanvas.height = Math.round(canvas.height * ratio); var context = thumbnailCanvas.getContext('2d'); context.drawImage(canvas, @@ -229,13 +241,14 @@ ImageEncoder.MetadataEncoder.prototype.setImageData = }; /** - * @param {!HTMLCanvasElement} canvas Canvas to use as thumbnail. + * @param {HTMLCanvasElement} canvas Canvas to use as thumbnail. Note that it + * can be null. * @param {number} quality Thumbnail quality. */ ImageEncoder.MetadataEncoder.prototype.setThumbnailData = function(canvas, quality) { this.metadata_.thumbnailURL = - canvas.toDataURL(this.metadata_.media.mimeType, quality); + canvas ? canvas.toDataURL(this.metadata_.media.mimeType, quality) : ''; delete this.metadata_.thumbnailTransform; }; |