Skip to content

Commit

Permalink
Merge release v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mster committed Jul 5, 2020
2 parents 3240ee4 + 3dceadb commit 8c7b432
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 12 deletions.
36 changes: 36 additions & 0 deletions lib/modes/vana.js
Original file line number Diff line number Diff line change
@@ -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
}
47 changes: 47 additions & 0 deletions lib/modes/veneneux.js
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 11 additions & 9 deletions lib/mosh.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.'))
Expand All @@ -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}`)

Expand Down Expand Up @@ -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')
}
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>",
"license": "MIT",
"repository": {
Expand Down

0 comments on commit 8c7b432

Please sign in to comment.