Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 | 6 // TODO add support for a magnified scale factor |
| 7 var MAGNIFIER_SCALE_FACTOR = 2.0; | 7 var MAGNIFIER_SCALE_FACTOR = 2.0; |
| 8 | 8 |
| 9 angular.module('diff_viewer', []). | 9 angular.module('diff_viewer', []). |
| 10 directive('imgCompare', function() { | 10 directive('imgCompare', function() { |
| 11 // Custom directive for comparing (3-way) images | 11 // Custom directive for comparing (3-way) images |
| 12 return { | 12 return { |
| 13 restrict: 'E', // The directive can be used as an element name | 13 restrict: 'E', // The directive can be used as an element name |
| 14 replace: true, // The directive replaces itself with the template | 14 replace: true, // The directive replaces itself with the template |
| 15 template: '<canvas/>', | 15 template: '<canvas/>', |
| 16 scope: true, | 16 scope: true, |
| 17 link: function(scope, elm, attrs, ctrl) { | 17 link: function(scope, elm, attrs, ctrl) { |
| 18 var image = new Image(); | 18 var image = new Image(); |
| 19 var canvas = elm[0]; | 19 var canvas = elm[0]; |
| 20 var ctx = canvas.getContext('2d'); | 20 var ctx = canvas.getContext('2d'); |
| 21 | 21 |
| 22 var magnifyContent = false; | 22 var magnifyContent = 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 scope.setHWRatio4MaskCanvas(canvas.height / canvas.width); | |
|
djsollen
2013/12/09 16:40:12
I think you can remove this. The width and height
yunchao
2013/12/10 05:58:31
Agree!
| |
| 29 break; | 30 break; |
| 30 case "baseline": | 31 case "baseline": |
| 31 image.src = scope.record.baselinePath; | 32 image.src = scope.record.baselinePath; |
| 32 magnifyContent = true; | 33 magnifyContent = true; |
| 33 break; | 34 break; |
| 34 case "test": | 35 case "test": |
| 35 image.src = scope.record.testPath; | 36 image.src = scope.record.testPath; |
| 36 magnifyContent = true; | 37 magnifyContent = true; |
| 37 break; | 38 break; |
| 38 default: | 39 default: |
| 39 console.log("Unknown type attribute on <img-compare>: " + va lue); | 40 console.log("Unknown type attribute on <img-compare>: " + va lue); |
| 40 return; | 41 return; |
| 41 } | 42 } |
| 42 | 43 |
| 43 image.onload = function() { | 44 image.onload = function() { |
| 44 // compute the scaled image width/height for image and canvas | 45 // compute the scaled image width/height for image and canvas |
| 45 var divisor = 1; | 46 var divisor = 1; |
| 46 // Make it so the maximum size of an image is MAX_SWAP_IMG_SIZ E, | 47 // Make it so the maximum size of an image is MAX_SWAP_IMG_SIZ E, |
| 47 // and the images are scaled down in halves. | 48 // and the images are scaled down in halves. |
| 48 while ((image.width / divisor) > MAX_SWAP_IMG_SIZE) { | 49 while ((image.width / divisor) > MAX_SWAP_IMG_SIZE) { |
| 49 divisor *= 2; | 50 divisor *= 2; |
| 50 } | 51 } |
| 51 | 52 |
| 52 scope.setImgScaleFactor(1 / divisor); | 53 scope.setImgScaleFactor(1 / divisor); |
| 53 | 54 |
| 54 // Set canvas to correct size | 55 // Set canvas to correct size |
| 55 canvas.width = image.width * scope.imgScaleFactor; | 56 canvas.width = image.width * scope.imgScaleFactor; |
| 56 canvas.height = image.height * scope.imgScaleFactor; | 57 canvas.height = image.height * scope.imgScaleFactor; |
| 57 | 58 |
| 59 // Set the ratio of height / width for mask canvas according | |
| 60 // to baseline and test canvas | |
| 61 scope.setHWRatio4MaskCanvas(canvas.height / canvas.width); | |
|
djsollen
2013/12/09 16:40:12
it seems like we only want to do this for the non-
yunchao
2013/12/10 05:58:31
Done.
| |
| 62 | |
| 58 // render the image onto the canvas | 63 // render the image onto the canvas |
| 59 scope.renderImage(); | 64 scope.renderImage(); |
| 60 } | 65 } |
| 61 }); | 66 }); |
| 62 | 67 |
| 63 // When the magnify attribute changes, render the magnified rect at | 68 // When the magnify attribute changes, render the magnified rect at |
| 64 // the default zoom level. | 69 // the default zoom level. |
| 65 scope.$watch('magnifyCenter', function(magCenter) { | 70 scope.$watch('magnifyCenter', function(magCenter) { |
| 66 if (!magnifyContent) { | 71 if (!magnifyContent) { |
| 67 return; | 72 return; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 | 132 |
| 128 // event handler for mouse events that triggers the magnification | 133 // event handler for mouse events that triggers the magnification |
| 129 // effect across the 3 images being compared. | 134 // effect across the 3 images being compared. |
| 130 scope.MagnifyDraw = function(event, startMagnify) { | 135 scope.MagnifyDraw = function(event, startMagnify) { |
| 131 if (startMagnify) { | 136 if (startMagnify) { |
| 132 scope.setMagnifierState(true); | 137 scope.setMagnifierState(true); |
| 133 } else if (!scope.magnifierOn) { | 138 } else if (!scope.magnifierOn) { |
| 134 return; | 139 return; |
| 135 } | 140 } |
| 136 | 141 |
| 142 canvas.height = canvas.width * scope.HWRatio4MaskCanvas; | |
|
djsollen
2013/12/09 16:40:12
why does the canvas height need to be set each tim
yunchao
2013/12/10 05:58:31
Done, resize non-alphaMask canvas when loading ima
| |
| 137 scope.renderImage(); | 143 scope.renderImage(); |
| 138 | 144 |
| 139 // render the magnifier outline rect | 145 // render the magnifier outline rect |
| 140 var rect = scope.computeMagnifierOutline(event); | 146 var rect = scope.computeMagnifierOutline(event); |
| 141 ctx.save(); | 147 ctx.save(); |
| 142 ctx.beginPath(); | 148 ctx.beginPath(); |
| 143 ctx.rect(rect.x, rect.y, rect.width, rect.height); | 149 ctx.rect(rect.x, rect.y, rect.width, rect.height); |
| 144 ctx.lineWidth = 2; | 150 ctx.lineWidth = 2; |
| 145 ctx.strokeStyle = 'red'; | 151 ctx.strokeStyle = 'red'; |
| 146 ctx.stroke(); | 152 ctx.stroke(); |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 159 scope.setMagnifyCenter(undefined); | 165 scope.setMagnifyCenter(undefined); |
| 160 }; | 166 }; |
| 161 } | 167 } |
| 162 }; | 168 }; |
| 163 }); | 169 }); |
| 164 | 170 |
| 165 function ImageController($scope, $http, $location, $timeout, $parse) { | 171 function ImageController($scope, $http, $location, $timeout, $parse) { |
| 166 $scope.imgScaleFactor = 1.0; | 172 $scope.imgScaleFactor = 1.0; |
| 167 $scope.magnifierOn = false; | 173 $scope.magnifierOn = false; |
| 168 $scope.magnifyCenter = undefined; | 174 $scope.magnifyCenter = undefined; |
| 175 $scope.HWRatio4MaskCanvas = 0; | |
| 169 | 176 |
| 170 $scope.setImgScaleFactor = function(scaleFactor) { | 177 $scope.setImgScaleFactor = function(scaleFactor) { |
| 171 $scope.imgScaleFactor = scaleFactor; | 178 $scope.imgScaleFactor = scaleFactor; |
| 172 } | 179 } |
| 173 | 180 |
| 174 $scope.setMagnifierState = function(magnifierOn) { | 181 $scope.setMagnifierState = function(magnifierOn) { |
| 175 $scope.magnifierOn = magnifierOn; | 182 $scope.magnifierOn = magnifierOn; |
| 176 } | 183 } |
| 177 | 184 |
| 178 $scope.setMagnifyCenter = function(magnifyCenter) { | 185 $scope.setMagnifyCenter = function(magnifyCenter) { |
| 179 $scope.magnifyCenter = magnifyCenter; | 186 $scope.magnifyCenter = magnifyCenter; |
| 180 } | 187 } |
| 188 | |
| 189 $scope.setHWRatio4MaskCanvas = function(ratio) { | |
| 190 if (ratio > $scope.HWRatio4MaskCanvas) { | |
|
djsollen
2013/12/09 16:40:12
I don't see why the setter should be conditional.
yunchao
2013/12/10 05:58:31
Agree. have updated this patch accordingly.
| |
| 191 $scope.HWRatio4MaskCanvas = ratio; | |
| 192 } | |
| 193 } | |
| 181 } | 194 } |
| 182 | 195 |
| 183 function DiffListController($scope, $http, $location, $timeout, $parse) { | 196 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 | 197 // 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. | 198 // enable some extra functionality of the website for rebaselining. |
| 186 $scope.isDynamic = ($location.protocol() == "http" || $location.protocol() = = "https"); | 199 $scope.isDynamic = ($location.protocol() == "http" || $location.protocol() = = "https"); |
| 187 | 200 |
| 188 // Label each kind of differ for the sort buttons. | 201 // Label each kind of differ for the sort buttons. |
| 189 $scope.differs = [ | 202 $scope.differs = [ |
| 190 { | 203 { |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 267 } | 280 } |
| 268 $http.post("/commit_rebaselines", { | 281 $http.post("/commit_rebaselines", { |
| 269 "rebaselines": rebaselines | 282 "rebaselines": rebaselines |
| 270 }).success(function(data) { | 283 }).success(function(data) { |
| 271 $scope.flashStatus(data.success); | 284 $scope.flashStatus(data.success); |
| 272 }).error(function() { | 285 }).error(function() { |
| 273 $scope.flashStatus(false); | 286 $scope.flashStatus(false); |
| 274 }); | 287 }); |
| 275 }; | 288 }; |
| 276 } | 289 } |
| OLD | NEW |