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

Side by Side Diff: tools/skpdiff/diff_viewer.js

Issue 105823010: resize mask canvas for viewer.html in skpdiff tool (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: resize non-alphaMask canvas according to baseline canvas Created 7 years 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 var MAX_SWAP_IMG_SIZE = 400; 1 var MAX_SWAP_IMG_SIZE = 400;
2 var MAGNIFIER_WIDTH = 200; 2 var MAGNIFIER_WIDTH = 200;
3 var MAGNIFIER_HEIGHT = 200; 3 var MAGNIFIER_HEIGHT = 200;
4 var MAGNIFIER_HALF_WIDTH = MAGNIFIER_WIDTH * 0.5; 4 var MAGNIFIER_HALF_WIDTH = MAGNIFIER_WIDTH * 0.5;
5 var MAGNIFIER_HALF_HEIGHT = MAGNIFIER_HEIGHT * 0.5; 5 var MAGNIFIER_HALF_HEIGHT = MAGNIFIER_HEIGHT * 0.5;
6 // TODO add support for a magnified scale factor
djsollen 2013/12/10 14:18:15 this TODO was to track making the strength of the
7 var MAGNIFIER_SCALE_FACTOR = 2.0; 6 var MAGNIFIER_SCALE_FACTOR = 2.0;
8 7
9 angular.module('diff_viewer', []). 8 angular.module('diff_viewer', []).
10 directive('imgCompare', function() { 9 directive('imgCompare', function() {
11 // Custom directive for comparing (3-way) images 10 // Custom directive for comparing (3-way) images
12 return { 11 return {
13 restrict: 'E', // The directive can be used as an element name 12 restrict: 'E', // The directive can be used as an element name
14 replace: true, // The directive replaces itself with the template 13 replace: true, // The directive replaces itself with the template
15 template: '<canvas/>', 14 template: '<canvas/>',
16 scope: true, 15 scope: true,
17 link: function(scope, elm, attrs, ctrl) { 16 link: function(scope, elm, attrs, ctrl) {
18 var image = new Image(); 17 var image = new Image();
19 var canvas = elm[0]; 18 var canvas = elm[0];
20 var ctx = canvas.getContext('2d'); 19 var ctx = canvas.getContext('2d');
21 20
22 var magnifyContent = false; 21 var magnifyContent = false;
22 var maskCanvas = false;
23 23
24 // When the type attribute changes, load the image and then render 24 // When the type attribute changes, load the image and then render
25 attrs.$observe('type', function(value) { 25 attrs.$observe('type', function(value) {
26 switch(value) { 26 switch(value) {
27 case "alphaMask": 27 case "alphaMask":
28 image.src = scope.record.differencePath; 28 image.src = scope.record.differencePath;
29 maskCanvas = true;
30 // need to change size for non-alphaMask canvas
31 if (image.name == "") {
djsollen 2013/12/10 14:18:15 This if check is unnecessary. I don't think the a
yunchao 2013/12/10 14:35:00 Hey derek, how to depart a non-alphaMask element f
djsollen 2013/12/10 14:44:21 You need to run the skpdiff tool with the --alphaD
yunchao 2013/12/11 03:02:21 Yes. Then I found this CL is a corner case, becaus
32 scope.setNeedChangeMaskCanvasSize(true);
33 }
29 break; 34 break;
30 case "baseline": 35 case "baseline":
31 image.src = scope.record.baselinePath; 36 image.src = scope.record.baselinePath;
32 magnifyContent = true; 37 magnifyContent = true;
33 break; 38 break;
34 case "test": 39 case "test":
35 image.src = scope.record.testPath; 40 image.src = scope.record.testPath;
36 magnifyContent = true; 41 magnifyContent = true;
37 break; 42 break;
38 default: 43 default:
39 console.log("Unknown type attribute on <img-compare>: " + va lue); 44 console.log("Unknown type attribute on <img-compare>: " + va lue);
40 return; 45 return;
41 } 46 }
42 47
43 image.onload = function() { 48 image.onload = function() {
44 // compute the scaled image width/height for image and canvas 49 // compute the scaled image width/height for image and canvas
45 var divisor = 1; 50 var divisor = 1;
46 // Make it so the maximum size of an image is MAX_SWAP_IMG_SIZ E, 51 // Make it so the maximum size of an image is MAX_SWAP_IMG_SIZ E,
47 // and the images are scaled down in halves. 52 // and the images are scaled down in halves.
48 while ((image.width / divisor) > MAX_SWAP_IMG_SIZE) { 53 while ((image.width / divisor) > MAX_SWAP_IMG_SIZE) {
49 divisor *= 2; 54 divisor *= 2;
50 } 55 }
51 56
52 scope.setImgScaleFactor(1 / divisor); 57 scope.setImgScaleFactor(1 / divisor);
53 58
54 // Set canvas to correct size 59 // Set canvas to correct size
55 canvas.width = image.width * scope.imgScaleFactor; 60 canvas.width = image.width * scope.imgScaleFactor;
56 canvas.height = image.height * scope.imgScaleFactor; 61 canvas.height = image.height * scope.imgScaleFactor;
57 62
63 // resize non-alphaMask canvas according to baseline canvas
64 if (scope.needChangeMaskCanvasSize) {
65 scope.resizeMaskCanvas({width: canvas.width, height: canva s.height});
66 scope.setNeedChangeMaskCanvasSize(false);
djsollen 2013/12/10 14:18:15 you should be passing true if you really only want
yunchao 2013/12/10 14:35:00 I suppose line 31-33 can pass true. And update can
djsollen 2013/12/10 14:44:21 I don't think 31-33 needs to exist as the scope ob
yunchao 2013/12/11 03:02:21 Yes, the original patch line 31-33 is unnecessary.
67 }
68
58 // render the image onto the canvas 69 // render the image onto the canvas
59 scope.renderImage(); 70 scope.renderImage();
60 } 71 }
61 }); 72 });
62 73
74 // when newMaskCanvas changes, resize mask canvas size.
75 scope.$watch('newMaskCanvas', function(newCanvas) {
76 if (!maskCanvas) {
77 return;
78 }
79
80 canvas.width = newCanvas.width;
81 canvas.height = newCanvas.height;
82 })
djsollen 2013/12/10 14:18:15 this should be });
yunchao 2013/12/11 03:02:21 Done.
83
63 // When the magnify attribute changes, render the magnified rect at 84 // When the magnify attribute changes, render the magnified rect at
64 // the default zoom level. 85 // the default zoom level.
65 scope.$watch('magnifyCenter', function(magCenter) { 86 scope.$watch('magnifyCenter', function(magCenter) {
66 if (!magnifyContent) { 87 if (!magnifyContent) {
67 return; 88 return;
68 } 89 }
69 90
70 scope.renderImage(); 91 scope.renderImage();
71 92
72 if (!magCenter) { 93 if (!magCenter) {
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 scope.setMagnifyCenter(undefined); 180 scope.setMagnifyCenter(undefined);
160 }; 181 };
161 } 182 }
162 }; 183 };
163 }); 184 });
164 185
165 function ImageController($scope, $http, $location, $timeout, $parse) { 186 function ImageController($scope, $http, $location, $timeout, $parse) {
166 $scope.imgScaleFactor = 1.0; 187 $scope.imgScaleFactor = 1.0;
167 $scope.magnifierOn = false; 188 $scope.magnifierOn = false;
168 $scope.magnifyCenter = undefined; 189 $scope.magnifyCenter = undefined;
190 $scope.newMaskCanvas = undefined;
191 $scope.needChangeMaskCanvasSize = false;
djsollen 2013/12/10 14:18:15 I think it may be more clear to use names like $s
yunchao 2013/12/11 03:02:21 Agree, the original variable names are not good. T
169 192
170 $scope.setImgScaleFactor = function(scaleFactor) { 193 $scope.setImgScaleFactor = function(scaleFactor) {
171 $scope.imgScaleFactor = scaleFactor; 194 $scope.imgScaleFactor = scaleFactor;
172 } 195 }
173 196
174 $scope.setMagnifierState = function(magnifierOn) { 197 $scope.setMagnifierState = function(magnifierOn) {
175 $scope.magnifierOn = magnifierOn; 198 $scope.magnifierOn = magnifierOn;
176 } 199 }
177 200
178 $scope.setMagnifyCenter = function(magnifyCenter) { 201 $scope.setMagnifyCenter = function(magnifyCenter) {
179 $scope.magnifyCenter = magnifyCenter; 202 $scope.magnifyCenter = magnifyCenter;
180 } 203 }
204
205 $scope.resizeMaskCanvas = function(newMaskCanvas) {
djsollen 2013/12/10 14:18:15 function(updatedSize)
206 $scope.newMaskCanvas = newMaskCanvas;
207 }
208
209 $scope.setNeedChangeMaskCanvasSize = function(flag) {
210 $scope.needChangeMaskCanvasSize = flag;
211 }
181 } 212 }
182 213
183 function DiffListController($scope, $http, $location, $timeout, $parse) { 214 function DiffListController($scope, $http, $location, $timeout, $parse) {
184 // Detect if we are running the web server version of the viewer. If so, we set a flag and 215 // Detect if we are running the web server version of the viewer. If so, we set a flag and
185 // enable some extra functionality of the website for rebaselining. 216 // enable some extra functionality of the website for rebaselining.
186 $scope.isDynamic = ($location.protocol() == "http" || $location.protocol() = = "https"); 217 $scope.isDynamic = ($location.protocol() == "http" || $location.protocol() = = "https");
187 218
188 // Label each kind of differ for the sort buttons. 219 // Label each kind of differ for the sort buttons.
189 $scope.differs = [ 220 $scope.differs = [
190 { 221 {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
267 } 298 }
268 $http.post("/commit_rebaselines", { 299 $http.post("/commit_rebaselines", {
269 "rebaselines": rebaselines 300 "rebaselines": rebaselines
270 }).success(function(data) { 301 }).success(function(data) {
271 $scope.flashStatus(data.success); 302 $scope.flashStatus(data.success);
272 }).error(function() { 303 }).error(function() {
273 $scope.flashStatus(false); 304 $scope.flashStatus(false);
274 }); 305 });
275 }; 306 };
276 } 307 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698