Skip to content

Commit

Permalink
Dynamic Lineart
Browse files Browse the repository at this point in the history
  • Loading branch information
sbs20 committed Sep 23, 2019
1 parent cd0a819 commit 8bc0171
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 53 deletions.
6 changes: 4 additions & 2 deletions classes/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ module.exports = function () {
return convert.execute()
.then(function () {
var fileInfo = new FileInfo(options.target);
if (!fileInfo.exists()) throw new Error("File does not exist");
if (!fileInfo.exists()) {
throw new Error("File does not exist");
}
return fileInfo;
});
};
Expand All @@ -67,7 +69,7 @@ module.exports = function () {
mode: req.mode,
brightness: req.brightness,
contrast: req.contrast,
disableDynamicLineart: req.disableDynamicLineart,
dynamicLineart: req.dynamicLineart,
outputFilepath: Config.PreviewDirectory + 'preview.tif',
resolution: Config.PreviewResolution
});
Expand Down
4 changes: 1 addition & 3 deletions classes/Device.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,7 @@ module.exports = function () {
};

_this.isFeatureSupported = function (feature) {
if (_this.data &&
_this.data.features &&
feature in _this.data.features) {
if (_this.data && _this.data.features && feature in _this.data.features) {
return _this.data.features[feature].default !== 'inactive';
}

Expand Down
6 changes: 1 addition & 5 deletions classes/ScanRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ var ScanRequest = function (def) {
errors.push('Invalid format type');
}

if (_this.disableDynamicLineart && !device.isFeatureSupported('--disable-dynamic-lineart')) {
errors.push('disableDynamicLineart set to true, but unsupported by device');
}

return errors;
};
};
Expand All @@ -75,7 +71,7 @@ ScanRequest.default = {
brightness: 0,
contrast: 0,
convertFormat: 'tif',
disableDynamicLineart: false
dynamicLineart: true
};

module.exports = ScanRequest;
6 changes: 2 additions & 4 deletions classes/Scanimage.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ module.exports = function () {
cmd += ' --contrast ' + scanRequest.contrast;
}

if (scanRequest.mode === 'Lineart' && scanRequest.disableDynamicLineart) {
if (scanRequest.mode === 'Lineart' && !scanRequest.dynamicLineart &&
device.isFeatureSupported('--disable-dynamic-lineart')) {
cmd += ' --disable-dynamic-lineart=yes ';
}

Expand All @@ -50,7 +51,6 @@ module.exports = function () {
};

_this.execute = function (scanRequest) {

if (!exists()) {
return Q.reject(new Error('Unable to find Scanimage at "' + Config.Scanimage + '"'));
}
Expand All @@ -70,11 +70,9 @@ module.exports = function () {
};

System.trace('Scanimage.execute:start');

response.errors = scanRequest.validate(device);

if (response.errors.length === 0) {

response.cmdline = commandLine(scanRequest, device);

return System.execute(response.cmdline)
Expand Down
17 changes: 7 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@

<script type="text/template" id="page">
<div class="row">
<!-- Padding for larger screens -->
<div class="col-lg-2 col-md-1"></div>

<!-- Fields and buttons -->
<div id="fields" class="col-lg-4 col-md-5 col-sm-12">
<div id="fields" class="col-lg-6 col-md-6 col-sm-12">

<div class="row">
<div id="col1" class="col">
Expand Down Expand Up @@ -69,9 +66,12 @@
</select>
</div>

<div class="form-check" id="formGroupDisableDynamicLineart">
<label for="disableDynamicLineart" class="form-check-label">Disable dynamic lineart</label>
<input id="disableDynamicLineart" type="checkbox" class="form-check-input" />
<div class="form-group" id="formGroupDynamicLineart" style="display: none">
<label for="mode">Dynamic lineart</label>
<select id="dynamicLineart" class="form-control">
<option value="false">disabled</option>
<option value="true">enabled</option>
</select>
</div>

<label for="brightness">Brightness</label>
Expand Down Expand Up @@ -108,9 +108,6 @@
<!-- Preview pane -->
<div id="previewPane" class="col-lg-4 col-md-5 col-sm-12">
</div>

<!-- Padding for larger screens -->
<div class="xcol-lg-2 col-md-1"></div>
</div>

<div class="row">
Expand Down
43 changes: 14 additions & 29 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,7 @@ require("jquery-jcrop");
require('backbone.localstorage');
require("bootstrap");

function updateDynamicLineartVisibility(mode, device) {
var $div = $("#formGroupDisableDynamicLineart");
var features = device.attributes.features;
// this function might be called before fetching the device model, which might result in this variable
// being potentially erroneously set to false at that time : however, since deviceSync() calls render(),
// an update to the correct value will eventually happen once the device model is fetched.
var disableSupported = (features !== undefined && '--disable-dynamic-lineart' in features);
if (mode === 'Lineart' && disableSupported) {
$div.show();
} else {
$div.hide();
}
}

$(document).ready(function () {

// Set up toastr how we want it
toastr.options = {
"positionClass": "toast-bottom-right"
Expand All @@ -50,7 +35,6 @@ $(document).ready(function () {
// ScanRequest is what gets sent to the scanner and contains
// the various fields which define what the scanner will do
var ScanRequest = Backbone.Model.extend({

defaults: function () {
return {
// LocalStorage requires an id in order to
Expand All @@ -65,7 +49,7 @@ $(document).ready(function () {
brightness: 0,
contrast: 0,
convertFormat: 'tif',
disableDynamicLineart: false
dynamicLineart: true
};
},

Expand All @@ -76,7 +60,6 @@ $(document).ready(function () {

// Views
var FileView = Backbone.View.extend({

tagName: 'tr',
template: _.template($('#file-row').html()),
events: {
Expand Down Expand Up @@ -171,8 +154,8 @@ $(document).ready(function () {
$slider.slider("value", val);
break;

case 'disableDynamicLineart':
data[field.id] = field.checked;
case 'dynamicLineart':
data[field.id] = field.value === 'true';
break;

default:
Expand Down Expand Up @@ -324,7 +307,7 @@ $(document).ready(function () {

render: function (ev) {
var attrs = (ev && ev.changed) || this.model.attributes;
var dev = this.device;
var device = this.device;
_.each(attrs, function (val, id) {
var $e = this.$('#' + id);
if ($e) {
Expand All @@ -334,12 +317,16 @@ $(document).ready(function () {
if (id === 'contrast' || id === 'brightness') {
$e = this.$('#' + id + '_slider');
$e.slider('value', val);
}
else if (id === 'mode') {
updateDynamicLineartVisibility(val, dev);
}
else if (id === 'disableDynamicLineart') {
$e.prop("checked", val);
} else if (id === 'mode' && device) {
// This might be called before fetching the device model, in which case
// `features` might be incorrect. This will self-correct once the device
// model is fetched.
var features = device.attributes.features;
var isDisableSupported = features && '--disable-dynamic-lineart' in features;
var visible = val === 'Lineart' && isDisableSupported;
$("#formGroupDynamicLineart").toggle(visible);
} else if (id === 'dynamicLineart') {
$e.val(String(val));
}
});
},
Expand All @@ -352,7 +339,6 @@ $(document).ready(function () {
});

var JcropManager = function (model) {

var _this = this;

_this.dotsToMm = function (dots) {
Expand Down Expand Up @@ -463,7 +449,6 @@ $(document).ready(function () {
page.convert();

var jcrop = new JcropManager(page.model);

});


0 comments on commit 8bc0171

Please sign in to comment.