Github user robpaveza commented on a diff in the pull request:
https://github.com/apache/cordova-plugin-camera/pull/111#discussion_r36199186
--- Diff: src/windows/CameraProxy.js ---
@@ -696,21 +696,22 @@ function
takePictureFromCameraWindows(successCallback, errorCallback, args) {
// decide which max pixels should be supported by targetWidth or
targetHeight.
var maxRes = null;
var UIMaxRes = WMCapture.CameraCaptureUIMaxPhotoResolution;
+ var totalPixels = targetWidth * targetHeight;
switch (true) {
- case (targetWidth >= 1280 || targetHeight >= 960) :
- cameraCaptureUI.photoSettings.maxResolution = UIMaxRes.large3M;
+ case (totalPixels <= 320 * 240):
+ cameraCaptureUI.photoSettings.maxResolution =
UIMaxRes.verySmallQvga;
break;
- case (targetWidth >= 1024 || targetHeight >= 768) :
- maxRes = UIMaxRes.mediumXga;
+ case (totalPixels <= 640 * 480):
+ maxRes = UIMaxRes.smallVga;
break;
- case (targetWidth >= 800 || targetHeight >= 600) :
+ case (totalPixels <= 1024 * 768):
maxRes = UIMaxRes.mediumXga;
break;
- case (targetWidth >= 640 || targetHeight >= 480) :
- maxRes = UIMaxRes.smallVga;
+ case (totalPixels <= 3 * 1000 * 1000):
+ maxRes = UIMaxRes.large3M;
break;
- case (targetWidth >= 320 || targetHeight >= 240) :
- maxRes = UIMaxRes.verySmallQvga;
+ case (totalPixels <= 5 * 1000 * 1000):
+ maxRes = UIMaxRes.veryLarge5M;
break;
default :
maxRes = UIMaxRes.highestAvailable;
--- End diff --
switch(true) would only be faster in the event that your cases were
constants and you were doing explicit equality checks (e.g., `case 10:`).
They're not, though, and because you're using greater-than comparisons, you
lose the ability of the runtime compiler to optimize using jump-tables. If
we're really concerned about perf, I'd suggest adding profiling code to order
the most-common to the least-common cases; but I think this code will run so
infrequently, it's not a perf-critical path.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]