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

Side by Side Diff: ui/file_manager/gallery/js/image_editor/filter.js

Issue 1608143002: support animated GIF (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add assert to pass closure compiler Created 4 years, 11 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * A namespace for image filter utilities. 6 * A namespace for image filter utilities.
7 */ 7 */
8 var filter = {}; 8 var filter = {};
9 9
10 /** 10 /**
(...skipping 13 matching lines...) Expand all
24 ImageUtil.trace.report(name, Math.round(mPixPerSec * 10) / 10 + 'Mps'); 24 ImageUtil.trace.report(name, Math.round(mPixPerSec * 10) / 10 + 'Mps');
25 } 25 }
26 }; 26 };
27 27
28 /** 28 /**
29 * Apply a filter to a image by splitting it into strips. 29 * Apply a filter to a image by splitting it into strips.
30 * 30 *
31 * To be used with large images to avoid freezing up the UI. 31 * To be used with large images to avoid freezing up the UI.
32 * 32 *
33 * @param {!HTMLCanvasElement} dstCanvas Destination canvas. 33 * @param {!HTMLCanvasElement} dstCanvas Destination canvas.
34 * @param {!HTMLCanvasElement} srcCanvas Source canvas. 34 * @param {!HTMLCanvasElement|!HTMLImageElement} srcImage Source image.
35 * @param {function(!ImageData,!ImageData,number,number)} filterFunc Filter. 35 * @param {function(!ImageData,!ImageData,number,number)} filterFunc Filter.
36 * @param {function(number, number)} progressCallback Progress callback. 36 * @param {function(number, number)} progressCallback Progress callback.
37 * @param {number=} opt_maxPixelsPerStrip Pixel number to process at once. 37 * @param {number=} opt_maxPixelsPerStrip Pixel number to process at once.
38 */ 38 */
39 filter.applyByStrips = function( 39 filter.applyByStrips = function(
40 dstCanvas, srcCanvas, filterFunc, progressCallback, opt_maxPixelsPerStrip) { 40 dstCanvas, srcImage, filterFunc, progressCallback, opt_maxPixelsPerStrip) {
41 // 1 Mpix is a reasonable default. 41 // 1 Mpix is a reasonable default.
42 var maxPixelsPerStrip = opt_maxPixelsPerStrip || 1000000; 42 var maxPixelsPerStrip = opt_maxPixelsPerStrip || 1000000;
43 43
44 var dstContext = dstCanvas.getContext('2d'); 44 var dstContext = dstCanvas.getContext('2d');
45 var srcContext = srcCanvas.getContext('2d'); 45 var srcContext = ImageUtil.ensureCanvas(srcImage).getContext('2d');
46 var source = srcContext.getImageData(0, 0, srcCanvas.width, srcCanvas.height); 46 var source = srcContext.getImageData(0, 0, srcImage.width, srcImage.height);
47 47
48 var stripCount = Math.ceil(srcCanvas.width * srcCanvas.height / 48 var stripCount = Math.ceil(srcImage.width * srcImage.height /
49 maxPixelsPerStrip); 49 maxPixelsPerStrip);
50 50
51 var strip = srcContext.getImageData(0, 0, 51 var strip = srcContext.getImageData(0, 0,
52 srcCanvas.width, Math.ceil(srcCanvas.height / stripCount)); 52 srcImage.width, Math.ceil(srcImage.height / stripCount));
53 53
54 var offset = 0; 54 var offset = 0;
55 55
56 function filterStrip() { 56 function filterStrip() {
57 // If the strip overlaps the bottom of the source image we cannot shrink it 57 // If the strip overlaps the bottom of the source image we cannot shrink it
58 // and we cannot fill it partially (since canvas.putImageData always draws 58 // and we cannot fill it partially (since canvas.putImageData always draws
59 // the entire buffer). 59 // the entire buffer).
60 // Instead we move the strip up several lines (converting those lines 60 // Instead we move the strip up several lines (converting those lines
61 // twice is a small price to pay). 61 // twice is a small price to pay).
62 if (offset > source.height - strip.height) { 62 if (offset > source.height - strip.height) {
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
610 /** 610 /**
611 * @param {{r: !Array<number>, g: !Array<number>, b: !Array<number>}} 611 * @param {{r: !Array<number>, g: !Array<number>, b: !Array<number>}}
612 * histogram 612 * histogram
613 * @return {boolean} True if the autofix would make a visible difference. 613 * @return {boolean} True if the autofix would make a visible difference.
614 */ 614 */
615 filter.autofix.isApplicable = function(histogram) { 615 filter.autofix.isApplicable = function(histogram) {
616 return filter.autofix.needsStretching(histogram.r) || 616 return filter.autofix.needsStretching(histogram.r) ||
617 filter.autofix.needsStretching(histogram.g) || 617 filter.autofix.needsStretching(histogram.g) ||
618 filter.autofix.needsStretching(histogram.b); 618 filter.autofix.needsStretching(histogram.b);
619 }; 619 };
OLDNEW
« no previous file with comments | « ui/file_manager/gallery/js/image_editor/commands.js ('k') | ui/file_manager/gallery/js/image_editor/image_adjust.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698