Skip to content

Commit

Permalink
feat(calculatescale) added scale override
Browse files Browse the repository at this point in the history
feat(commandline) added scale override
  • Loading branch information
Bob620 committed May 28, 2019
1 parent bdcafee commit 3b2a3c1
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 5 deletions.
4 changes: 3 additions & 1 deletion calculations.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function sumPixelLuminosity(pixels) {
}, 0) / pixels.length)/255;
}

async function calculateScale(startImage, magnification, scaleType, belowColor=constants.scale.colors.AUTO) {
async function calculateScale(startImage, magnification, scaleType, belowColor=constants.scale.colors.AUTO, scaleSize=constants.scale.AUTOSIZE) {
let scale = {
x: 0,
y: 0,
Expand All @@ -96,6 +96,8 @@ async function calculateScale(startImage, magnification, scaleType, belowColor=c
[scale.visualScale, scale.scaleLength, scale.pixelSize, scale.scaleSize] = estimateVisualScale(magnification, startImage.bitmap.width);
scale.height = Jimp.measureTextHeight(await Jimp.loadFont(fonts[scale.scaleSize]), '0', 10);

scale.scaleLength = scaleSize > 0 ? Math.round(scaleSize / scale.pixelSize) : scale.scaleLength;
scale.visualScale = scaleSize > 0 ? scaleSize : scale.visualScale;
scale.height = scale.height % 2 === 0 ? scale.height : scale.height + 1;

// Figure out how long the scale bar needs to be
Expand Down
1 change: 1 addition & 0 deletions constants.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"MAGNIFICATIONKEY": "magcam"
},
"scale": {
"AUTOSIZE": 0,
"types": {
"BELOW": 0,
"LOWERLEFT": 1,
Expand Down
12 changes: 10 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function help() {
console.log('-p [pos], --position [pos] \tPosition to print the scale');
console.log('-c [color], --color [color] \tScale color');
console.log('-b [color], --background [color]\tIf \'Below\', background color');
console.log('-s [µm], --scale [µm] \tScale to display, < 1 for auto');
console.log();
console.log('Colors (Scale and Background):');
console.log('a, auto \tSelects the color automatically');
Expand All @@ -32,7 +33,8 @@ require('./pointshoot')().then(async Pointshoot => {
version: false,
position: constants.scale.types.BELOW,
scaleColor: constants.scale.colors.AUTO,
background: constants.scale.colors.AUTO
background: constants.scale.colors.AUTO,
scaleSize: constants.scale.AUTOSIZE
};

let dirUri = '';
Expand All @@ -46,6 +48,9 @@ require('./pointshoot')().then(async Pointshoot => {
case '--help':
options.help = true;
break;
case '--scale':
options.scaleSize = process.argv[++i];
break;
case '--color':
switch (process.argv[++i]) {
case 'a':
Expand Down Expand Up @@ -112,6 +117,9 @@ require('./pointshoot')().then(async Pointshoot => {
}
} else if (process.argv[i].startsWith('-')) {
switch (process.argv[i]) {
case '-s':
options.scaleSize = process.argv[++i];
break;
case '-c':
switch (process.argv[++i]) {
case 'a':
Expand Down Expand Up @@ -219,7 +227,7 @@ require('./pointshoot')().then(async Pointshoot => {
}).filter(i => i);

for (const point of ps)
await point.addScaleAndWrite(options.position, {scaleColor: options.scaleColor, belowColor: options.background});
await point.addScaleAndWrite(options.position, {scaleColor: options.scaleColor, belowColor: options.background, scaleSize: options.scaleSize});

console.log('All images written');
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "thermo-reimager",
"version": "1.0.1",
"version": "1.1.0",
"main": "module.js",
"bin": {
"thermo-reimager": "index.js"
Expand Down
3 changes: 2 additions & 1 deletion pointshoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ module.exports = async () => {
async addScale(type=constants.scale.types.BELOW, settings={}) {
settings.belowColor = settings.belowColor ? settings.belowColor : constants.scale.colors.AUTO;
settings.scaleColor = settings.scaleColor ? settings.scaleColor : constants.scale.colors.AUTO;
settings.scaleSize = settings.scaleSize ? settings.scaleSize : constants.scale.AUTOSIZE;

const initialImage = await Jimp.read(this.data.files.image);

const [scale, image] = await calculations.calculateScale(initialImage, this.data.magnification, type, settings.belowColor);
const [scale, image] = await calculations.calculateScale(initialImage, this.data.magnification, type, settings.belowColor, settings.scaleSize);

let isBlack = settings.scaleColor === constants.scale.colors.WHITE;
if (settings.scaleColor === constants.scale.colors.AUTO) {
Expand Down

0 comments on commit 3b2a3c1

Please sign in to comment.