From dfda6656cd48cd1a1e486d940befa68b33476190 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Mon, 7 Dec 2015 01:32:17 +0200 Subject: [PATCH] added resolution dimmer support --- motioneye/handlers.py | 3 +++ motioneye/mediafiles.py | 5 +++++ motioneye/prefs.py | 3 ++- motioneye/static/js/main.js | 25 ++++++++++++++++++------- motioneye/templates/main.html | 13 +++++++++++-- 5 files changed, 39 insertions(+), 10 deletions(-) diff --git a/motioneye/handlers.py b/motioneye/handlers.py index fec73cb..51e7a43 100644 --- a/motioneye/handlers.py +++ b/motioneye/handlers.py @@ -847,6 +847,9 @@ class PictureHandler(BaseHandler): width = self.get_argument('width', None) height = self.get_argument('height', None) + width = width and float(width) + height = height and float(height) + camera_config = config.get_camera(camera_id) if utils.local_motion_camera(camera_config): picture = mediafiles.get_current_picture(camera_config, diff --git a/motioneye/mediafiles.py b/motioneye/mediafiles.py index d008ad6..bd8bbbe 100644 --- a/motioneye/mediafiles.py +++ b/motioneye/mediafiles.py @@ -741,6 +741,11 @@ def get_current_picture(camera_config, width, height): sio = StringIO.StringIO(jpg) image = Image.open(sio) + if width and width < 1: # given as percent + width = int(width * image.size[0]) + if height and height < 1: # given as percent + height = int(height * image.size[1]) + width = width and int(width) or image.size[0] height = height and int(height) or image.size[1] diff --git a/motioneye/prefs.py b/motioneye/prefs.py index 6d6c004..e94ed7d 100644 --- a/motioneye/prefs.py +++ b/motioneye/prefs.py @@ -25,7 +25,8 @@ import settings _PREFS_FILE_NAME = 'prefs.json' _DEFAULT_PREFS = { 'layout_columns': 3, - 'refresh_factor': 1 + 'framerate_factor': 1, + 'resolution_factor': 1 } _prefs = None diff --git a/motioneye/static/js/main.js b/motioneye/static/js/main.js index 22f5493..40ead73 100644 --- a/motioneye/static/js/main.js +++ b/motioneye/static/js/main.js @@ -5,7 +5,8 @@ var refreshDisabled = {}; /* dictionary indexed by cameraId, tells if refresh is var fullScreenCameraId = null; var inProgress = false; var refreshInterval = 15; /* milliseconds */ -var refreshFactor = 1; +var framerateFactor = 1; +var resolutionFactor = 1; var username = ''; var password = ''; var basePath = null; @@ -701,7 +702,11 @@ function initUI() { savePrefs(); }); $('#framerateDimmerSlider').change(function () { - refreshFactor = parseInt(this.value) / 100; + framerateFactor = parseInt(this.value) / 100; + savePrefs(); + }); + $('#resolutionDimmerSlider').change(function () { + resolutionFactor = parseInt(this.value) / 100; savePrefs(); }); @@ -1262,7 +1267,8 @@ function configUiValid() { function prefsUi2Dict() { var dict = { 'layout_columns': $('#layoutColumnsSlider').val(), - 'refresh_factor': $('#framerateDimmerSlider').val() / 100 + 'framerate_factor': $('#framerateDimmerSlider').val() / 100, + 'resolution_factor': $('#resolutionDimmerSlider').val() / 100 }; return dict; @@ -1270,14 +1276,16 @@ function prefsUi2Dict() { function dict2PrefsUi(dict) { $('#layoutColumnsSlider').val(dict['layout_columns']); - $('#framerateDimmerSlider').val(dict['refresh_factor'] * 100); + $('#framerateDimmerSlider').val(dict['framerate_factor'] * 100); + $('#resolutionDimmerSlider').val(dict['resolution_factor'] * 100); updateConfigUI(); } function applyPrefs(dict) { setLayoutColumns(dict['layout_columns']); - refreshFactor = dict['refresh_factor']; + framerateFactor = dict['framerate_factor']; + resolutionFactor = dict['resolution_factor']; } function savePrefs() { @@ -4246,7 +4254,10 @@ function refreshCameraFrames() { } var path = basePath + 'picture/' + cameraId + '/current/?_=' + timestamp; - if (serverSideResize) { + if (resolutionFactor != 1) { + path += '&width=' + resolutionFactor; + } + else if (serverSideResize) { path += '&width=' + img.width; } @@ -4280,7 +4291,7 @@ function refreshCameraFrames() { var count = parseInt(1000 / (refreshInterval * this.config['streaming_framerate'])); var serverSideResize = this.config['streaming_server_resize']; - count /= refreshFactor; + count /= framerateFactor; if (this.img.error) { /* in case of error, decrease the refresh rate to 1 fps */ diff --git a/motioneye/templates/main.html b/motioneye/templates/main.html index dd501a9..50612e2 100644 --- a/motioneye/templates/main.html +++ b/motioneye/templates/main.html @@ -107,15 +107,24 @@ Layout Columns - ? + ? Frame Rate Dimmer - ? + ? + + + Resolution Dimmer + + ? + +
+ +
? -- 2.39.5