Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
2a70990
Building scaffold on master. YOLO
njisaf Sep 15, 2016
d288cfb
Trying again to eslint and gulpfile
njisaf Sep 15, 2016
dff9784
Trying again to push some untracked files
njisaf Sep 15, 2016
824436a
Merge pull request #1 from njisaf/constructors
njisaf Sep 15, 2016
9d88f70
Reading buffer from bitmap.bmp
njisaf Sep 15, 2016
8a1d981
Merge pull request #2 from njisaf/constructors
njisaf Sep 15, 2016
603a89a
writes test for reading buffer
piper88 Sep 15, 2016
4c7cd45
Merge pull request #3 from njisaf/initial-bitmap-read-test
njisaf Sep 15, 2016
f327bfd
eslint
njisaf Sep 15, 2016
844ef23
Initial constructor functionality
njisaf Sep 15, 2016
9a9e385
Fixed merge conflix
njisaf Sep 15, 2016
d69843c
Merge pull request #4 from njisaf/constructors
njisaf Sep 15, 2016
b0e7912
sliced color and pixel array from buffer
piper88 Sep 15, 2016
87f0069
Merge pull request #5 from njisaf/bitmap-constructor
njisaf Sep 15, 2016
808cf57
changing colors, identified rgba values
njisaf Sep 16, 2016
b374835
test bmp file
njisaf Sep 16, 2016
dab5d13
Merge pull request #6 from njisaf/what-is-color-array
njisaf Sep 16, 2016
a4a5c99
add gray invert and rgb
piper88 Sep 16, 2016
1f4c6bd
Merge pull request #7 from njisaf/sarah-friday-experimenting
piper88 Sep 16, 2016
0974eae
refactored to control from index, grayscale transform
njisaf Sep 16, 2016
64d3afb
Merge pull request #8 from njisaf/refactor
njisaf Sep 16, 2016
de8d466
Tests are not working
njisaf Sep 18, 2016
85e4598
Merge pull request #9 from njisaf/testing-tests
njisaf Sep 18, 2016
fcbb566
adds useless tests that dont work
piper88 Sep 18, 2016
55cb262
Merge pull request #10 from njisaf/transform-test
njisaf Sep 18, 2016
61b3feb
merge conflix
njisaf Sep 18, 2016
777e47b
Merge pull request #11 from njisaf/testing-tests
njisaf Sep 18, 2016
eee5f29
conflix fix
njisaf Sep 18, 2016
081e8cc
conflix
njisaf Sep 18, 2016
3827eef
Bitmap constructor test working
njisaf Sep 18, 2016
6197f0d
Merge pull request #12 from njisaf/new-test
njisaf Sep 18, 2016
c4cf634
Cleaning up test images
njisaf Sep 18, 2016
3c44438
Merge pull request #13 from njisaf/new-test
njisaf Sep 18, 2016
e6ff831
small test fix
njisaf Sep 18, 2016
4ab2f27
small test fix
njisaf Sep 18, 2016
b55ddf1
add read-me and clean up old commented code and consolelogs
piper88 Sep 18, 2016
f8e88b7
Merge pull request #14 from njisaf/read-me-clean-up
piper88 Sep 18, 2016
bab222d
Simple endianness check added to bitmap constructor
njisaf Sep 19, 2016
917bc0f
Merge conflix
njisaf Sep 19, 2016
f9bb69a
More conflix
njisaf Sep 19, 2016
3397a52
Merge pull request #15 from njisaf/endians
njisaf Sep 19, 2016
6c4bbf7
non-palette bmps now handled
njisaf Sep 19, 2016
20e5f6c
Merge pull request #16 from njisaf/non-palette
njisaf Sep 19, 2016
c8fb365
Now Can handle os/2 bmps as well
njisaf Sep 19, 2016
4932451
Merge pull request #17 from njisaf/multibms
njisaf Sep 19, 2016
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
32 changes: 8 additions & 24 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,35 +1,19 @@
{
"rules": {
"no-console": 0,
"indent": [
2,
2
],
"quotes": [
2,
"single"
],
"linebreak-style": [
2,
"unix"
],
"semi": [
2,
"always"
]
"comma-dangle": ["error", "always-multiline"],
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": [ "error", "single" ],
"semi": ["error", "always"],
"linebreak-style": [ "error", "unix" ]
},
"env": {
"es6": true,
"node": true,
"browser": true
"mocha": true,
"jasmine": true
},
"globals": {
"describe": false,
"it": false,
"beforeEach": false,
"afterEach": false,
"before": false,
"after": false
},
"ecmaFeatures": {
"modules": true,
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,6 @@ Session.vim

# auto-generated tag files
tags

# new bitmaps
new*.bmp
Binary file added assets/marbles.bmp
Binary file not shown.
1 change: 1 addition & 0 deletions assets/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
111
Binary file added assets/testimage-actuallyjpg.bmp
Binary file not shown.
24 changes: 24 additions & 0 deletions bitmap-nassarah/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"rules": {
"comma-dangle": ["error", "always-multiline"],
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": [ "error", "single" ],
"semi": ["error", "always"],
"linebreak-style": [ "error", "unix" ]
},
"env": {
"es6": true,
"node": true,
"mocha": true,
"jasmine": true
},
"globals": {
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
73 changes: 73 additions & 0 deletions bitmap-nassarah/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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
*~

### Existential Dread ###
inevitable_death
ever_present_cowardice
pain_of_wakefulness

# auto-generated tag files
tags

# new bitmaps
new*.bmp
15 changes: 15 additions & 0 deletions bitmap-nassarah/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Sarah and Nassir's Bitmap Lab

## Reads a bitmap file, performs 3 transforms, and outputs a new transformed bitmap

### 3 Transforms:
1. Invert Transform
2. Gray Transform
3. RGB Transform

### Using our program:
1. Run 'node index.js [bitmap filepath] [transform-method]' from main project directory
2. Transform method flags:
a. invert
b. gray
c. rgb
29 changes: 29 additions & 0 deletions bitmap-nassarah/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const gulp = require('gulp');
const eslint = require('gulp-eslint');
const mocha = require('gulp-mocha');

gulp.task('hello', function(){
console.log('hello');
});

gulp.watch('***/*.js', ['hello']);

gulp.task('lint', function () {
return gulp.src(['**/*.js','!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format())
.pipe(eslint.failAfterError());
});

gulp.task('test', function(){
gulp.src('./test/*-test.js', {read: false})
.pipe(mocha({reporter: 'nyan'}));
});

gulp.task('dev', function(){
gulp.watch(['**/*.js','!node_modules/**'], ['test', 'lint']);
});

gulp.task('default', ['dev']);
28 changes: 28 additions & 0 deletions bitmap-nassarah/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const bitmapReader = require('./lib/bitmap-read');
const bitmapConstructor = require('./model/bitmap-constructor');
const bitmapWriter = require('./lib/bitmap-write');
const programSelect = process.argv[3];
const fileSelect = process.argv[2];


function runProgram(){
if (!programSelect || !fileSelect) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice command line functionality!

console.error('Error!! Program requires a filename and transform\nUse form \'node index.js filename.bmp transform\' \nThree transforms are available: invert, gray, rgb');
} else {
bitmapReader(fileSelect, function(err, buffer){
if (err) throw console.error('Error! Not a valid file.\nFiles much be in form filename.bmp, and must be in the assets directory.');
bitmapConstructor(buffer, fileSelect, function(err, object){
if (err) throw console.error('Error! bitmapConstructor is not receiving a valid buffer object.');
var fileHeaders = ['BM', 'BA', 'CI', 'CP', 'IC', 'PT'];
if (fileHeaders.indexOf(object.isBitmap) === -1) throw console.error('Error! File does not appear to be a valid bitmap file.');
bitmapWriter(object, programSelect, function(err, newFilePath){
console.log('New file saved as ' + newFilePath + ' in assets.');
});
});
});
}
}

runProgram();
10 changes: 10 additions & 0 deletions bitmap-nassarah/lib/bitmap-read.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const fs = require('fs');

module.exports = function bitmapRead(pathName, callback) {
fs.readFile(`${__dirname}/../../assets/${pathName}`, function(err, buffer) {
if (err) return callback(err);
callback(null, buffer);
});
};
41 changes: 41 additions & 0 deletions bitmap-nassarah/lib/bitmap-write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict';

const fs = require('fs');
const EE = require('events');
const myEE = new EE();

const invertTransform = require('./invert-transform.js');
const grayTransform = require('./gray-transform.js');
const rgbTransform = require('./rgb-transform.js');

module.exports = function bitmapWriter(object, programSelect, callback) {
var colorArray = object.colorArray;
var pathName = object.pathName;
var buffer = object.wholeBuffer;

myEE.on('first', function(){
if (colorArray[0] === undefined) colorArray = object.pixelArray;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpicky, but undefined is a falsey value, so you could simply write:

if (!colorArray[0]) colorArray = object.pixelArray;

myEE.emit('second');
});

myEE.on('second', function(){
if (programSelect === 'invert') {
invertTransform(colorArray, function(){});
} else if (programSelect === 'gray') {
grayTransform(colorArray, function(){});
} else if (programSelect === 'rgb') {
rgbTransform(colorArray, function(){});
} else {
console.error('Error! Transform if/else statement running to end');
}
myEE.emit('third');
});

myEE.on('third', function(){
var newPathName = `new${pathName}`;
fs.writeFile(`../assets/new${pathName}`, buffer, function() {
callback(null, newPathName);
});
});
myEE.emit('first');
};
13 changes: 13 additions & 0 deletions bitmap-nassarah/lib/gray-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

module.exports = function grayscaleBitmap(colorArray, callback) {
for (var i = 0; i < colorArray.length; i += 4) {
var arrayChunk = colorArray.slice([i], [i+4]);
var avg = (arrayChunk[0] + arrayChunk[1] + arrayChunk[2] + arrayChunk[3])/4;
arrayChunk[0] = avg; //blue
arrayChunk[1] = avg; //green
arrayChunk[2] = avg; //red
arrayChunk[3] = avg; //alpha
}
callback(arrayChunk);
};
13 changes: 13 additions & 0 deletions bitmap-nassarah/lib/invert-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';


module.exports = function invertBitmap(colorArray, callback) {
for (var i = 0; i < colorArray.length; i += 4) {
var arrayChunk = colorArray.slice([i], [i+4]);
arrayChunk[0] = 255 - arrayChunk[0]; //blue
arrayChunk[1] = 255 - arrayChunk[1]; //green
arrayChunk[2] = 255 - arrayChunk[2]; //red
arrayChunk[3] = 255 - arrayChunk[3]; //alpha
}
callback(arrayChunk);
};
13 changes: 13 additions & 0 deletions bitmap-nassarah/lib/rgb-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';


module.exports = function rgbBitmap(colorArray, callback) {
for (var i = 0; i < colorArray.length; i += 4) {
var arrayChunk = colorArray.slice([i], [i+4]);
arrayChunk[0] = arrayChunk[0]; //blue
arrayChunk[1] = 255 * arrayChunk[1]; //green
arrayChunk[2] = arrayChunk[2]; //red
arrayChunk[3] = arrayChunk[3]; //alpha
}
callback(arrayChunk);
};
31 changes: 31 additions & 0 deletions bitmap-nassarah/model/bitmap-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const os = require('os');

module.exports = function buildObject(bufferIn, pathName, callback) {
var bitmapObject = new Bitmap(bufferIn, pathName);
callback(null, bitmapObject);
};

function Bitmap(buffer, pathName) {
this.pathName = pathName;
this.isBitmap = buffer.toString('utf8', 0, 2);
this.wholeBuffer = buffer;
this.header = buffer.toString('utf8', 0, 15);
this.headerLength = checkEndian(buffer, 14, 18) + 14;
this.endianness = os.endianness();
this.fileSize = checkEndian(buffer, 2, 6);
this.offset = checkEndian(buffer, 10, 14);
this.colorArray = buffer.slice(this.headerLength, this.offset);
this.pixelArray = buffer.slice(this.offset);
}

function checkEndian(buffer, start, finish) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So cool!

if (os.endianness() === 'LE') {
return buffer.readUInt32LE(start, finish);
} else if (os.endianness() === 'BE') {
return buffer.readUInt32BE(start, finish);
} else {
console.error('Error!! checkEndian is not functioning');
}
}
22 changes: 22 additions & 0 deletions bitmap-nassarah/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "bitmap-nassarah",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"chai": "^3.5.0",
"gulp": "^3.9.1",
"gulp-eslint": "^3.0.1",
"gulp-mocha": "^3.0.1",
"mocha": "^3.0.2"
}
}
17 changes: 17 additions & 0 deletions bitmap-nassarah/test/bitmap-constructor-error-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const assert = require('assert');
const bitmapReader = require('../lib/bitmap-read');
const bitmapConstructor = require('../model/bitmap-constructor');

describe('This tests whether bitmap-constructor is outputting a valid bitmap object', function() {
it('bitmap-constructor should return an object with a property .isBitmap with a value of \'BM\'', function(done){
bitmapReader('testimage-actuallyjpg.bmp', function(err, buffer){
bitmapConstructor(buffer, 'testimage-actuallyjpg.bmp', function(err, object){
var testThis = object.isBitmap;
assert.ok(testThis !== 'BM', 'This property should not read BM');
});
done();
});
});
});
Loading