Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lab-closure-group/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
26 changes: 26 additions & 0 deletions lab-closure-group/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}
68 changes: 68 additions & 0 deletions lab-closure-group/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Created by https://www.gitignore.io/api/osx,linux,node,vim

### OSX ###
.DS_Store
.AppleDouble
.LSOverride

### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*


### Node ###
# Logs
logs
*.log
npm-debug.log*

# Runtime data
pids
*.pid
*.seed

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules
jspm_packages

# Optional npm cache directory
.npm

# Optional REPL history
.node_repl_history

### Vim ###
# swap
[._]*.s[a-w][a-z]
[._]s[a-w][a-z]
# session
Session.vim
# temporary
.netrwhist
*~

# auto-generated tag files
tags

###### Personal
.tern-project
Empty file added lab-closure-group/README.md
Empty file.
46 changes: 46 additions & 0 deletions lab-closure-group/__test__/BitMapImage.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const reader = require('../lib/reader.js');
const parser = require('../lib/parser.js');
const BitMapImage = require('../lib/BitMapImage.js');

describe('BitMapImage', () => {

test('BitMapImage should return a BitMapImage object with correct data for house.bmp.', (done) => {
reader(`${__dirname}/../../asset/house.bmp`, (err, data) => {
let parsedData = parser(data);
let result = new BitMapImage(parsedData);
expect(err).toBeNull();
expect(result.header).toEqual('BM');
expect(result.size).toEqual(66616);
expect(result.imageWidth).toEqual(256);
expect(result.imageHeight).toEqual(256);
expect(result.bitsPerPix).toEqual(8);
expect(result.sizeOfHeader).toEqual(40);
expect(result.pixelArrayOffset).toEqual(1078);
expect(result.pixelArraySize).toEqual(65536);
expect(result.colorTableSize).toEqual(1024);
expect(result.colorTableOffset).toEqual(54);
done();
});
});

test('BitMapImage should return a BitMapImage object with correct data for bitmap.bmp.', (done) => {
reader(`${__dirname}/../../asset/bitmap.bmp`, (err, data) => {
let parsedData = parser(data);
let result = new BitMapImage(parsedData);
expect(err).toBeNull();
expect(result.header).toEqual('BM');
expect(result.size).toEqual(11078);
expect(result.imageWidth).toEqual(100);
expect(result.imageHeight).toEqual(100);
expect(result.bitsPerPix).toEqual(8);
expect(result.sizeOfHeader).toEqual(40);
expect(result.pixelArrayOffset).toEqual(1078);
expect(result.pixelArraySize).toEqual(10000);
expect(result.colorTableSize).toEqual(1024);
expect(result.colorTableOffset).toEqual(54);
done();
});
});
});
5 changes: 5 additions & 0 deletions lab-closure-group/__test__/transform.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
'use strict';

const transform = require('../lib/transform.js');

// Test each transformation... either in here, or separate test.js???? IDK again... lol
Binary file added lab-closure-group/data/fingerBlue.bmp
Binary file not shown.
Binary file added lab-closure-group/data/fingerFlipUp.bmp
Binary file not shown.
Binary file added lab-closure-group/data/fingerGreen.bmp
Binary file not shown.
Binary file added lab-closure-group/data/fingerMirror.bmp
Binary file not shown.
Binary file added lab-closure-group/data/fingerNoise.bmp
Binary file not shown.
Binary file added lab-closure-group/data/fingerRainbow.bmp
Binary file not shown.
Binary file added lab-closure-group/data/fingerRed.bmp
Binary file not shown.
Binary file added lab-closure-group/data/newbitmap.bmp
Binary file not shown.
22 changes: 22 additions & 0 deletions lab-closure-group/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const fs = require('fs');
const BitMapImage = require('./lib/BitMapImage.js');
const transform = require('./lib/transform.js');

const inputFile = process.argv[2];
const outputFile = process.argv[3];
const option = process.argv[4];


fs.readFile(`${__dirname}/../asset/${inputFile}`, (err, data) => {
if(err)
throw new Error('Usage: node index.js <input filename> <output filename> <transformation>');
let bitMapObj = new BitMapImage(data);
transform(bitMapObj, option);
fs.writeFile(`${__dirname}/data/${outputFile}`, bitMapObj.buffer, (err) => {
if(err)
throw new Error('Usage: node index.js <input filename> <output filename> <transformation>');
console.log('Bitmap created!');
});
});
18 changes: 18 additions & 0 deletions lab-closure-group/lib/BitMapImage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

// BitMapImage constructor
module.exports = function BitMapImage(data) {
this.buffer = Buffer.from(data);
this.header = this.buffer.toString('utf8', 0, 2);
this.size = this.buffer.readUInt32LE(2);
this.imageWidth = this.buffer.readUInt32LE(18);
this.imageHeight = this.buffer.readUInt32LE(22);
this.bitsPerPix = this.buffer.readUInt16LE(28);
this.sizeOfHeader = this.buffer.readUInt32LE(14);
this.colorTableOffset = 54; // Header(14) + DIB(40) size is the offset
this.colorTableSize = 1024;
this.pixelArrayOffset = this.buffer.readUInt32LE(10);
this.pixelArraySize = this.imageWidth * this.imageHeight;
this.colorTable = this.buffer.slice(54, 1024+54);
this.pixelArray = this.buffer.slice(this.pixelArrayOffset, this.pixelArrayOffset + this.pixelArraySize);
};
52 changes: 52 additions & 0 deletions lab-closure-group/lib/transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';

// Require each transform modules here...
const invert = require(`./transformations/invert.js`);
const grayscale = require(`./transformations/grayscale.js`);
const rainbow = require(`./transformations/rainbow.js`);
const noise = require('./transformations/noise.js');
const red = require('./transformations/red.js');
const blue = require('./transformations/blue.js');
const green = require('./transformations/green.js');
const flipUp = require('./transformations/flipUp.js');
const mirror = require('./transformations/mirror.js');

module.exports = (object, option) => {
// Parse the transform flags/options and call their respective modules for transformation of the object.
// Maybe a switch statement? IDK..

switch(option)
case 'invert':
invert(object);
break;
case 'invert':
invert(object);
break;
case 'rainbow':
rainbow(object);
break;
case 'noise':
noise(object);
break;
case 'red':
red(object);
break;
case 'blue':
blue(object);
break;
case 'green':
green(object);
break;
case 'flipUp':
flipUp(object);
break;
case 'mirror':
mirror(object);
break;
default:
break;
}

// object.colorTable.fill(150);

};
13 changes: 13 additions & 0 deletions lab-closure-group/lib/transformations/blue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = (object) => {
for(let i = 0; i < object.colorTable.length; i+=4) {
let blue = object.colorTable.readUInt8(i);
let green = object.colorTable.readUInt8(i+1);
let red = object.colorTable.readUInt8(i+2);

object.colorTable.writeUInt8(255, i);
object.colorTable.writeUInt8(green, i+1);
object.colorTable.writeUInt8(red, i+2);
}
};
11 changes: 11 additions & 0 deletions lab-closure-group/lib/transformations/flipUp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = (object) => {
let length = object.pixelArray.length/2;
for(let i = 0; i < length; i++) {
let change = object.pixelArray.readUInt8(object.pixelArray.length-1-i);
let temp = object.pixelArray.readUInt8(i);
object.pixelArray.writeUInt8(change, i);
object.pixelArray.writeUInt8(temp, object.pixelArray.length-1-i);
}
};
15 changes: 15 additions & 0 deletions lab-closure-group/lib/transformations/grayscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
'use strict';

module.exports = (object) => {
for(let i = 0; i < object.colorTable.length; i+=4) {
let blue = object.colorTable.readUInt8(i);
let green = object.colorTable.readUInt8(i+1);
let red = object.colorTable.readUInt8(i+2);

let average = (blue + green + red) / 3;

object.colorTable.writeUInt8(average, i);
object.colorTable.writeUInt8(average, i+1);
object.colorTable.writeUInt8(average, i+2);
}
};
13 changes: 13 additions & 0 deletions lab-closure-group/lib/transformations/green.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = (object) => {
for(let i = 0; i < object.colorTable.length; i+=4) {
let blue = object.colorTable.readUInt8(i);
let green = object.colorTable.readUInt8(i+1);
let red = object.colorTable.readUInt8(i+2);

object.colorTable.writeUInt8(blue, i);
object.colorTable.writeUInt8(255, i+1);
object.colorTable.writeUInt8(red, i+2);
}
};
7 changes: 7 additions & 0 deletions lab-closure-group/lib/transformations/invert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

module.exports = (object) => {
for (var i = 0; i < object.pixelArray.length; i++) {
object.pixelArray[i] = 255 - object.pixelArray[i];
}
};
9 changes: 9 additions & 0 deletions lab-closure-group/lib/transformations/mirror.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict';

module.exports = (object) => {
let length = object.pixelArray.length;
for(let i = 0; i < length; i++) {
let change = object.pixelArray.readUInt8(object.pixelArray.length-1-i);
object.pixelArray.writeUInt8(change, i);
}
};
11 changes: 11 additions & 0 deletions lab-closure-group/lib/transformations/noise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

module.exports = (object) => {
for(let i = 0; i < object.pixelArray.length; i++) {
let min = Math.ceil(0);
let max = Math.floor(256);
let random = Math.floor(Math.random() * (max - min)) + min;

object.pixelArray.writeUInt8(random, i);
}
};
26 changes: 26 additions & 0 deletions lab-closure-group/lib/transformations/rainbow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';

module.exports = (object) => {
for(let i = 0; i < object.colorTable.length; i+=4) {
let min = Math.ceil(0);
let max = Math.floor(256);
let random1 = Math.floor(Math.random() * (max - min)) + min;
let random2 = Math.floor(Math.random() * (max - min)) + min;
let random3 = Math.floor(Math.random() * (max - min)) + min;
let random4 = Math.floor(Math.random() * (max - min)) + min;

object.colorTable.writeUInt8(random1, i);
object.colorTable.writeUInt8(random2, i+1);
object.colorTable.writeUInt8(random3, i+2);
object.colorTable.writeUInt8(random4, i+3);
}

for(let i = 0; i < object.pixelArray.length; i++) {
let min = Math.ceil(0);
let max = Math.floor(256);
let random = Math.floor(Math.random() * (max - min)) + min;

object.pixelArray.writeUInt8(random, i);
}

};
13 changes: 13 additions & 0 deletions lab-closure-group/lib/transformations/red.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = (object) => {
for(let i = 0; i < object.colorTable.length; i+=4) {
let blue = object.colorTable.readUInt8(i);
let green = object.colorTable.readUInt8(i+1);
let red = object.colorTable.readUInt8(i+2);

object.colorTable.writeUInt8(blue, i);
object.colorTable.writeUInt8(green, i+1);
object.colorTable.writeUInt8(255, i+2);
}
};
19 changes: 19 additions & 0 deletions lab-closure-group/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "lab-closure-group",
"version": "0.0.1",
"description": "Lab 4 of 401, Bitmap Transformer. Mark, Christina, Ron, Anthony",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"eslint": "^4.6.1",
"jest": "^21.0.2"
},
"scripts": {
"lint": "eslint .",
"test": "jest --coverage -i",
"test-watch": "jest --watch -i"
},
"keywords": [],
"author": "",
"license": "MIT"
}