Skip to content

bitmap-megatron-dana #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f03ac9f
updated file structure
reganoneill Feb 16, 2017
b8786bb
rearranged file structure
reganoneill Feb 16, 2017
6705d41
Merge pull request #1 from reganoneill/file_structure_setup
reganoneill Feb 16, 2017
799ab06
working with bmp
reganoneill Feb 16, 2017
487be12
before pull
reganoneill Feb 16, 2017
b9bb4e8
Test to isolate pixel array, change it and rewrite it.
dkulp23 Feb 16, 2017
01b4b10
Still testing original script to isolate and manipulate color table i…
dkulp23 Feb 17, 2017
57b1a0b
changed all R values
reganoneill Feb 18, 2017
4760c17
Added on and emit events. Trying to add a method to manipulate color …
dkulp23 Feb 18, 2017
f26996c
combined group work
reganoneill Feb 18, 2017
7501e5c
Merge pull request #2 from reganoneill/work_with_colors
reganoneill Feb 18, 2017
84292c3
Starting to attempt image transformation.
dkulp23 Feb 18, 2017
483319e
Working on manipulating buffer to transform image.
dkulp23 Feb 18, 2017
da2b789
Refactoring transform methods.
dkulp23 Feb 18, 2017
66990ff
Reduce method seems to be working well.
dkulp23 Feb 18, 2017
9dd5dc2
removed extraneous code. moving on to other transforms.
dkulp23 Feb 18, 2017
08f1818
Merge pull request #3 from reganoneill/transformImage
reganoneill Feb 18, 2017
0fe73de
Function for manipulating parts of the color array is working. Need t…
dkulp23 Feb 19, 2017
313cbd5
Commit before creatingnew branch.
dkulp23 Feb 19, 2017
e47ce0f
Errors with file writing.
dkulp23 Feb 20, 2017
e7c5c64
Grayscale...woohooo.
dkulp23 Feb 20, 2017
52724bb
Merge pull request #4 from dkulp23/transform-modules
reganoneill Feb 20, 2017
a64bc61
updated with master and new test
reganoneill Feb 20, 2017
5c9182f
updated dev dependencies
reganoneill Feb 20, 2017
7bc1d94
Merge pull request #5 from reganoneill/newTest
reganoneill Feb 20, 2017
7bbb5c4
ready to submit
reganoneill Feb 20, 2017
ab93a66
Merge pull request #6 from reganoneill/testsAndStretches
reganoneill Feb 20, 2017
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
21 changes: 21 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"rules": {
"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
},
"ecmaFeatures": {
"modules": true,
"experimentalObjectRestSpread": true,
"impliedStrict": true
},
"extends": "eslint:recommended"
}
129 changes: 129 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

# Created by https://www.gitignore.io/api/osx,node,linux,windows

### 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-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

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

# Runtime data
pids
*.pid
*.seed
*.pid.lock

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

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

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

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


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

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/osx,node,linux,windows
87 changes: 46 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,46 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 04: Bitmap Transformer
===

## To Submit this Assignment
* have team leader fork this repository
* have team leader add team members as collaborators to the team fork
* team members should clone team fork
* write all of your code in a directory name `bitmap-` + `<team name>` **e.g.** `bitmap-weasels`
* submit a pull request to this repository when done
* each person will submit a link to their own PR in canvas
* each person write a question and observation on canvas

#### Rubric:
* **tests:** 3pts
* **gulpfile/package.json:** 2pts
* **read bitmap meta data:** 5pts
* **successfully apply transforms:** 5pts
* **project design and organization:** 5pts

## Description

For this assignment you will be building a bitmap (`.bmp`) reader and transformer. It will read a bitmap in from disk, run one or more color transforms on the bitmap and then write it out to a new file. This project will require the use of node buffers in order to manipulate binary data. Your project should include tests, as well as a `gulpfile.js`, `package.json`, `.eslintrc`, `README.md`, and a `.gitignore`. Make sure to run all your code through eslint. The process will look something like this:

1. open the original bitmap file using fs and read it into a buffer
2. convert the buffer header data into a Javascript Object (using constructors)
3. run a transform on the buffer directly
4. write the buffer to a new file

The wikipedia article found here [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format) describes the byte specification of a "windows bitmap file." We'll be working with the simplest version, meaning no compression.

* your project should have three ***(or more)*** transforms
* invert the colors (***hint:*** subtract every color value from the max color value which is 255),
* grayscale the colors (***hint:*** multiply each color value by a constant, just make sure your values don't go over 255)
* (red|green|blue)scale the colors (***hint:*** same as above but only multiply one of the colors)

## Bonus:

* ability to handle various sized bitmap
* ability to handle LE and BE computers with a single if statement
* utilizes a command line interface (CLI)
* CLI can select the transforms
# BITMAP TRANSFORMER
Built by TEAM MEGATRON - Khalid Mohamud, Dana Kulp, Regan O'Neill

This program utilizes node.js to read a bitmap data stream, manipulate the stream, and create a new bitmap image to the filesystem.

# Features Include:

- Read bitmap data stream from operating system
- copy data as Buffer object and transform into different data structures in order to transform image.
- use object constructor to allow metadata to persist and be reused within application
- utilize three methods to transform the original file:
1) INVERT COLORS
[Imgur](http://i.imgur.com/GPZ8S8J.png)
2) GREENSCALE IMAGE
[Imgur](http://i.imgur.com/vQXy11e.png)
3) GRAYSCALE IMAGE
[Imgur](http://i.imgur.com/W2Tu028.png)

You can also:
- Run individual methods directly from the CLI to create one (or more) new bitmap files.
- run automation testing tools with gulp

### Tech

* [node.js] - evented I/O for the backend
* [Gulp] - the streaming build system

### Installation

Bitmap Transformer requires [Node.js](https://nodejs.org/) v6+ to run.

Install the dependencies and devDependencies and start the server.

```sh
$ cd bitmap-megatron
$ npm i
$ node index
[optional single commands include: 'invert', 'grayscale', 'greenscale']
```
License
----

MIT


**Free Software, Hell Yeah!**
File renamed without changes.
19 changes: 19 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

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

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

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

gulp.task('default', ['test', 'lint']);
37 changes: 37 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

'use strict';

const EE = require('events');
const ee = new EE();
const fs = require('fs');
const objConstructor = require(`${__dirname}/models/bitmap-object.js`).ImageObj;
const invert = require(`${__dirname}/lib/bitmap-transform.js`);
const greenScale = require(`${__dirname}/lib/bitmap-greenscale.js`);
const grayScale = require(`${__dirname}/lib/bitmap-grayscale.js`);

ee.on('getFile', function() {
fs.readFile(`${__dirname}/assets/palette-bitmap.bmp`, function(err, data) {
if (err) throw err;
ee.emit('objCreate', data);
});
});

ee.on('objCreate', function(data) {
let testObj = new objConstructor(data);
ee.emit('transformObj', data);
});

ee.on('transformObj', function(obj) {
for(var i = 2; i < process.argv.length; i++){
if (process.argv[i] === 'invert' ) invert(obj);
if (process.argv[i] === 'grayscale') grayScale(obj);
if (process.argv[i] === 'greenscale') greenScale(obj);
}
if (!process.argv[2]) {
invert(obj);
grayScale(obj);
greenScale(obj);
}
});

ee.emit('getFile');
35 changes: 35 additions & 0 deletions lib/bitmap-grayscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'use strict';

const fs = require('fs');

module.exports = function grayScale(obj) {
let bufferArray = new Int32Array(obj);
let metaData = bufferArray.slice(0, 54);
let colorTable = bufferArray.slice(54, 1078);
let pixelArray = bufferArray.slice(1078);

let manipulateTable = function(arr, cb) {
for (let i = 0; i < arr.length; i += 4) {
let scale = colorTable[i];
colorTable[i + 1] = scale;
colorTable[i + 2] = scale;
}
cb();
};

let createBuffer = function() {
let meta = Buffer.from(metaData);
let pixel = Buffer.from(pixelArray);
let redScale = Buffer.from(colorTable);
let newBuffer = Buffer.concat([meta, redScale, pixel]);
writeGrayFile(newBuffer);
};

let writeGrayFile = function(obj) {
console.log('gray');
fs.writeFile(`${__dirname}/../assets/gray-scale.bmp`, obj, function(err) {
if (err) throw err;
});
};
manipulateTable(colorTable, createBuffer);
};
34 changes: 34 additions & 0 deletions lib/bitmap-greenscale.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const fs = require('fs');

module.exports = function greenScale(obj) {
let bufferArray = new Int32Array(obj);
let metaData = bufferArray.slice(0, 54);
let colorTable = bufferArray.slice(54, 1078);
let pixelArray = bufferArray.slice(1078);

let manipulateTable = function(arr) {
for (var i = 1; i < arr.length; i += 4) {
colorTable[i] = 255;
}
createBuffer();
};

let createBuffer = function() {
let meta = Buffer.from(metaData);
let pixel = Buffer.from(pixelArray);
let redScale = Buffer.from(colorTable);
let newBuffer = Buffer.concat([meta, redScale, pixel]);
fileHelper(newBuffer);
};


let fileHelper = function(obj) {
console.log('green');
fs.writeFile(`${__dirname}/../assets/green.bmp`, obj, function(err) {
if (err) throw err;
});
};
manipulateTable(colorTable);
};
28 changes: 28 additions & 0 deletions lib/bitmap-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

const fs = require('fs');

module.exports = function invertColors(obj) {
let bufferArray = new Int32Array(obj);

let invertTransform = bufferArray.reduce(function(acc, ele, index) {
if (index < 54) acc.push(ele);
if (index >= 54 && index < 1078) {
let inverted = 255 - ele;
acc.push(inverted);
}
if (index >= 1078) acc.push(ele);
return acc;
}, []);

let newBuffer = Buffer.from(invertTransform);


let invertFileHelper = function(obj) {
console.log('invert');
fs.writeFile(`${__dirname}/../assets/dana-bitmap.bmp`, obj, function(err) {
if (err) throw err;
});
};
invertFileHelper(newBuffer);
};
Loading