From 3dceadba02fc109a822550c21276301f11124597 Mon Sep 17 00:00:00 2001 From: mster Date: Sat, 4 Jul 2020 18:48:39 -0700 Subject: [PATCH] v1.2.0 --- lib/modes/vana.js | 36 +++++++++++++++++++++++++++++++++ lib/modes/veneneux.js | 47 +++++++++++++++++++++++++++++++++++++++++++ lib/mosh.js | 20 +++++++++--------- package-lock.json | 2 +- package.json | 10 +++++++-- 5 files changed, 103 insertions(+), 12 deletions(-) create mode 100644 lib/modes/vana.js create mode 100644 lib/modes/veneneux.js diff --git a/lib/modes/vana.js b/lib/modes/vana.js new file mode 100644 index 0000000..6181526 --- /dev/null +++ b/lib/modes/vana.js @@ -0,0 +1,36 @@ +'use strict' + +module.exports = function (original) { + const rand = Math.random + const max = Math.max + const min = Math.min + + const bitmapData = original.bitmap.data + const data = Buffer.from(bitmapData) + + function giveSeed () { + const seed = [0, 0, 0] + + const ind1 = Math.floor(rand() * 3) + const ind2 = Math.floor(rand() * 3) + + seed[ind1] = max(rand(), 0.3) + if (rand() > 0.5) seed[ind2] = max(rand(), 0.3) + + return seed + } + + const seed = giveSeed() + + for (let i = 0; i < data.length; i += 4) { + /* RED = */ + data[i + 0] = min(data[i] * seed[0] + 100 * seed[2], 255) + /* GREEN = */ + data[i + 1] = min(data[i + 1] * seed[1] + 100 * seed[0], 255) + /* BLUE = */ + data[i + 2] = min(data[i + 2] * seed[2] + 100 * seed[1], 255) + } + + original.bitmap.data = data + return original +} diff --git a/lib/modes/veneneux.js b/lib/modes/veneneux.js new file mode 100644 index 0000000..533262c --- /dev/null +++ b/lib/modes/veneneux.js @@ -0,0 +1,47 @@ +'use strict' + +module.exports = function (original) { + const rand = Math.random + const max = Math.max + + const bitmapData = original.bitmap.data + const data = Buffer.from(bitmapData) + + const { width, height } = original.bitmap + + function giveSeed () { + const seed = [0, 0, 0] + + const ind1 = Math.floor(rand() * 3) + const ind2 = Math.floor(rand() * 3) + + seed[ind1] = max(rand(), 0.1) + if (rand() > 0.5) seed[ind2] = max(rand(), 0.1) + + return seed + } + + let pixel = 0 + let seed = giveSeed() + let seedChange = 2 + + for (let i = 0; i < data.length; i += 4) { + if (pixel % (width * 4) === 0) { + seedChange-- + if (seedChange === 0) { + seed = giveSeed() + seedChange = Math.floor((rand() * height) / 4) + } + } + + data[i + 0] = data[i + 0] * seed[0] + 1000 * seed[2] + data[i + 1] = data[i + 1] * seed[1] + 1000 * seed[1] + data[i + 2] = data[i + 2] * seed[2] + 1000 * seed[0] + data[i + 3] = 1 + + pixel++ + } + + original.bitmap.data = data + return original +} diff --git a/lib/mosh.js b/lib/mosh.js index ee3beba..72faa53 100644 --- a/lib/mosh.js +++ b/lib/mosh.js @@ -24,12 +24,12 @@ function mosh (options, cb) { if ( !( filename.length < 256 && - (/^[a-zA-Z0-9]*.jpg$/.test(filename) || - /^[a-zA-Z0-9]*.jpeg$/.test(filename) || - /^[a-zA-Z0-9]*.png$/.test(filename) || - /^[a-zA-Z0-9]*.bmp$/.test(filename) || - /^[a-zA-Z0-9]*.tiff$/.test(filename) || - /^[a-zA-Z0-9]*.gif$/.test(filename)) + (/^[\w\-. ]+.jpg$/.test(filename) || + /^[\w\-. ]+.jpeg$/.test(filename) || + /^[\w\-. ]+.png$/.test(filename) || + /^[\w\-. ]+.bmp$/.test(filename) || + /^[\w\-. ]+*.tiff$/.test(filename) || + /^[\w\-. ]+.gif$/.test(filename)) ) ) { cb(new MoshError('Only *.jpg OR *.jpeg file formats are supported.')) @@ -40,8 +40,8 @@ function mosh (options, cb) { const _mode = mode == null ? Object.keys(mosh.MODES)[ - Math.floor(Math.random() * Object.keys(mosh.MODES).length) - ] + Math.floor(Math.random() * Object.keys(mosh.MODES).length) + ] : mode debug(`Mode selected: ${_mode}`) @@ -73,5 +73,7 @@ function mosh (options, cb) { mosh.MODES = { blurbobb: require('./modes/blurbobb'), - schifty: require('./modes/schifty') + schifty: require('./modes/schifty'), + veneneux: require('./modes/veneneux'), + vana: require('./modes/vana') } diff --git a/package-lock.json b/package-lock.json index 6757a39..8a25cb3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "datamosh", - "version": "1.1.0", + "version": "1.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 7b99ac2..7ed13d9 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,14 @@ { "name": "datamosh", - "version": "1.1.0", + "version": "1.2.0", "description": "Datamosh images", - "keywords": ["datamost", "mosh", "jpg", "png", "glitch"], + "keywords": [ + "datamost", + "mosh", + "jpg", + "png", + "glitch" + ], "author": "Michael Sterpka ", "license": "MIT", "repository": {