-
Notifications
You must be signed in to change notification settings - Fork 12
Lee-Peter Bitmap Transformer #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
b69d53f
c11dfaf
7f1b9b8
a574a1e
e47d98e
1562f7b
b097e77
12ad984
f8e48d8
0bcc8b9
27d8d7b
347c663
a6224ff
4921fc8
9727a26
cd96a31
e751f8e
b3edc92
2183cff
d3879c3
485f952
a777bed
7eb5c44
9cbb1de
bcde97b
6559475
2cfe0ab
95ef9d9
eacef6d
7a4a392
36ef765
aadc8d0
3a3f010
33e4e48
32ac899
0107a14
ae21bfc
8962e7d
f0b191f
d1abf9e
080b2de
357b5ae
f3e387f
30e4e35
bdb223e
afdc446
7d9a81c
a616b38
036c192
513957c
bc18b82
50e3ac3
337d068
aba3488
bd70f36
3476796
96b2e8b
510e122
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| **/node_modules/* | ||
| **/vendor/* | ||
| **/*.min.js |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| { | ||
| "rules": { | ||
| "comma-dangle": ["error", "always-multiline"], | ||
| "no-console": 0, | ||
| "indent": [ | ||
| 2, | ||
| 2 | ||
| ], | ||
| "quotes": [ | ||
| 2, | ||
| "single" | ||
| ], | ||
| "linebreak-style": [ | ||
| 2, | ||
| "unix" | ||
| ], | ||
| "semi": [ | ||
| 2, | ||
| "always" | ||
| ] | ||
| }, | ||
| "env": { | ||
| "es6": true, | ||
| "node": true, | ||
| "browser": true | ||
| }, | ||
| "globals": { | ||
| "describe": false, | ||
| "it": false, | ||
| "beforeEach": false, | ||
| "afterEach": false, | ||
| "before": false, | ||
| "after": false | ||
| }, | ||
| "ecmaFeatures": { | ||
| "modules": true, | ||
| "experimentalObjectRestSpread": true, | ||
| "impliedStrict": true | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| # 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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| ##Team Bitmap Destruction Force | ||
|
|
||
| **Collaborators:** | ||
|
|
||
| Lee Broxson, Peter Kim | ||
|
|
||
| ##How to use this application | ||
|
|
||
| **Original 8-bit color bitmap** | ||
|
|
||
|  | ||
|
|
||
| This application's intent is to easily transform an 8-bit color bitmap file to either greenscale, grayscale or an inverted version of the original bitmap being used. | ||
|
|
||
| **Convert a single 8-bit color bitmap to a greenscaled, grayscaled and inverted color version all at once** | ||
|
|
||
| In the 'bitmap-destruction-force' directory, in your terminal, run the following command: | ||
|
|
||
| node index.js | ||
|
|
||
| **Example of greenscaled bitmap** | ||
|
|
||
| In the primary repository, enter the following command: | ||
|
|
||
| node index.js bitmapFileHelper.turnGreen(Greenscaler.greenScale); | ||
|
|
||
|  | ||
|
|
||
| **Example of grayscaled bitmap** | ||
|
|
||
| In the primary repository, enter the following command: | ||
|
|
||
| node index.js bitmapFileHelper.grayScale(Grayscaler.grayScale); | ||
|
|
||
|  | ||
|
|
||
| **Example of invert-colored bitmap** | ||
|
|
||
| In the primary repository, enter the following command: | ||
|
|
||
| node index.js bitmapFileHelper.invertColor(Inverter.invert); | ||
|
|
||
|  | ||
|
|
||
| More features and different bitmap transformers to come! | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| 'use strict'; | ||
|
|
||
| const gulp = require('gulp'); | ||
| const eslint = require('gulp-eslint'); | ||
| const mocha = require('gulp-mocha'); | ||
|
|
||
| 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:'landing'})); | ||
| }); | ||
|
|
||
| gulp.task('default', ['test']); | ||
|
|
||
| gulp.task('dev', function() { | ||
| gulp.watch(['**/*.js', '!node_modules/**'], | ||
| ['lint', 'test']); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
|
|
||
| const bitmapFileHelper = require('./lib/bitmapFileHelper.js'); | ||
|
|
||
| const Greenscaler = require('./model/greenscale-constructor.js'); | ||
| const Inverter = require('./model/inverse-constructor.js'); | ||
| const Grayscaler = require('./model/grayscale-constructor.js'); | ||
|
|
||
| //Running node on index.js will produce three unique bitmaps with the function invocations below: | ||
| bitmapFileHelper.turnGreen(Greenscaler.greenScale); //Greenscales the bitmap | ||
| bitmapFileHelper.invertColor(Inverter.invert); //Inverts the colors of the bitmap | ||
| bitmapFileHelper.grayScale(Grayscaler.grayScale); //Grayscales the colors of the bitmap |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| var buf; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's unnecessary to create this variable; just pass data directly into your callbacks :) |
||
| module.exports = exports = {}; | ||
|
|
||
| exports.turnGreen = function(callback) { | ||
| fs.readFile(`${__dirname}/../../assets/bitmap.bmp`, function(err, data){ | ||
| if(err) throw new Error('bitmap buffer not acquired'); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of throwing errors, you should pass them to a callback and deal with them in that way. |
||
| buf = data; | ||
| callback(buf); | ||
| fs.writeFile(`${__dirname}/../transformed-assets/greenscale-bitmap.bmp`, buf); | ||
| }); | ||
| }; | ||
|
|
||
| exports.invertColor = function(callback) { | ||
| fs.readFile(`${__dirname}/../../assets/bitmap.bmp`, function(err, data){ | ||
| if(err) throw new Error('bitmap buffer not acquired'); | ||
| buf = data; | ||
| callback(buf); | ||
| fs.writeFile(`${__dirname}/../transformed-assets/inverted-bitmap.bmp`, buf); | ||
| }); | ||
| }; | ||
|
|
||
| exports.grayScale = function(callback) { | ||
| fs.readFile(`${__dirname}/../../assets/bitmap.bmp`, function(err, data){ | ||
| if(err) throw new Error('bitmap buffer not acquired'); | ||
| buf = data; | ||
| callback(buf); | ||
| fs.writeFile(`${__dirname}/../transformed-assets/grayscale-bitmap.bmp`, buf); | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.grayScale = function(buf, err){ | ||
| if (err) throw new Error('Error grayscaling bitmap'); | ||
| var duck = new exports.GrayScale(buf); | ||
| duck.grayScale(buf); | ||
| }; | ||
|
|
||
| exports.GrayScale = function(buf){ | ||
| this.filesize = buf.readUInt32LE(2); | ||
| this.offset = buf.readUInt32LE(10); | ||
| this.colorArray = buf.slice(54, 1078); | ||
| }; | ||
|
|
||
| exports.GrayScale.prototype.grayScale = function(){ | ||
| var currentColor; | ||
| for (var i = 0;i < 1024;i += 4){ | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of hard-coding in 1024, it would be a good idea to reference a property such as this.colorArray.length. |
||
| currentColor = this.colorArray.slice(i, i+4); | ||
| var currentColorAverage = ((currentColor[0] + currentColor[1] + currentColor[2])/3); | ||
| currentColor[0] = currentColorAverage; | ||
| currentColor[1] = currentColorAverage; | ||
| currentColor[2] = currentColorAverage; | ||
| currentColor[3] = 0; | ||
| } | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.greenScale = function(buf){ | ||
| var duck = new exports.GreenScaler(buf); | ||
| duck.turnGreen(buf); | ||
| }; | ||
|
|
||
| exports.GreenScaler = function(buf){ | ||
| this.filesize = buf.readUInt32LE(2); | ||
| this.offset = buf.readUInt32LE(10); | ||
| this.colorArray = buf.slice(54, 1078); | ||
| }; | ||
|
|
||
| exports.GreenScaler.prototype.turnGreen = function(){ | ||
| var currentColor; | ||
| for (var i = 0;i < 1024;i += 4){ | ||
| currentColor = this.colorArray.slice(i, i+4); | ||
| var currentColorAverage = ((currentColor[0] + currentColor[1] + currentColor[2])/3); | ||
| currentColor[0] = 0; | ||
| currentColor[1] = currentColorAverage; | ||
| currentColor[2] = 0; | ||
| currentColor[3] = 0; | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.invert = function(buf){ | ||
| var duck = new exports.Inverter(buf); | ||
| duck.invertColor(buf); | ||
| }; | ||
|
|
||
| exports.Inverter = function(buf){ | ||
| this.filesize = buf.readUInt32LE(2); | ||
| this.offset = buf.readUInt32LE(10); | ||
| this.colorArray = buf.slice(54, 1078); | ||
| }; | ||
|
|
||
| exports.Inverter.prototype.invertColor = function(){ | ||
| var currentColor; | ||
| for (var i = 0;i < 1024;i += 4){ | ||
| currentColor = this.colorArray.slice(i, i+4); | ||
| //console.log('B' + currentColor[0] + ' + ' + 'G' + currentColor[1] + ' + ' + 'R' + currentColor[2] + ' + ' + 'A' + currentColor[3]); | ||
| currentColor[0] = 255 - currentColor[0]; | ||
| currentColor[1] = 255 - currentColor[1]; | ||
| currentColor[2] = 255 - currentColor[2]; | ||
| currentColor[3] = 0; | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "bitmap-destruction-force", | ||
| "version": "1.0.0", | ||
| "description": "", | ||
| "main": "index.js", | ||
| "scripts": { | ||
| "test": "echo \"Error: no test specified\" && exit 1" | ||
| }, | ||
| "keywords": [], | ||
| "author": [ | ||
| "broxsonl@gmail.com", | ||
| "peterkim23@gmail.com" | ||
| ], | ||
| "license": "ISC", | ||
| "devDependencies": { | ||
| "eslint": "^3.5.0", | ||
| "gulp": "^3.9.1", | ||
| "gulp-eslint": "^3.0.1", | ||
| "gulp-mocha": "^3.0.1", | ||
| "mocha": "^3.0.2" | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 'use strict'; | ||
|
|
||
| const bitmapFileHelper = require('../lib/bitmapFileHelper.js'); | ||
| const assert = require('assert'); | ||
|
|
||
| describe('testing bitmapFileHelper', function(){ | ||
| describe('#turnGreen', function(){ | ||
| it('should return buffer data', function(done){ | ||
| bitmapFileHelper.turnGreen(function(buf){ | ||
| assert.ok(buf, 'is not buffer data'); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
| describe('#invertColor', function(){ | ||
| it('should return buffer data', function(done){ | ||
| bitmapFileHelper.invertColor(function(buf){ | ||
| assert.ok(buf, 'is not buffer data'); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); | ||
| describe('#grayScale', function(){ | ||
| it('should return buffer data', function(done){ | ||
| bitmapFileHelper.grayScale(function(buf){ | ||
| assert.ok(buf, 'is not buffer data'); | ||
| done(); | ||
| }); | ||
| }); | ||
| it('should be a valid filename', function() { | ||
| bitmapFileHelper.turnGreen([`${__dirname}/dont-exist.bmp`], function(err){ | ||
| assert.ifError(err); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const Grayscaler = require('../model/grayscale-constructor.js'); | ||
|
|
||
| describe('Grayscaler', function(){ | ||
| describe('#grayscale', function(){ | ||
| it('should ensure Grayscaler is running', function(done){ | ||
| assert.ok(Grayscaler); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome docs!