-
Notifications
You must be signed in to change notification settings - Fork 7
Bhavya, Kyler, Shawn bitmap transform! #27
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
b2bad7a
f93489f
764c607
9624f20
aa56f3a
106de38
4adb5df
02da4df
b1fe26f
cdf88b4
910b34c
9065794
1023a57
9497542
beb1e2b
07c9b4b
febb183
45a7585
e944433
c156aa4
9d5ccf2
e0e7ffd
5239f20
5c6c296
b538601
a62bf56
5554df7
8d010df
afbd2b2
99395bb
5e5ba03
d62ed94
d5e11ee
499c163
388b590
a68cd78
9d8df05
99a19f5
1cb9632
3840e47
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,127 @@ | ||
| Created by https://www.gitignore.io/api/macos,node,vim,windows,linux | ||
|
|
||
| out.bmp | ||
| ### macOS ### | ||
| *.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 | ||
|
|
||
|
|
||
| ### Node ### | ||
| node_modules | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.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 | ||
|
|
||
| # 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 eslint cache | ||
| .eslintcache | ||
|
|
||
| # Optional REPL history | ||
| .node_repl_history | ||
|
|
||
| # Output of 'npm pack' | ||
| *.tgz | ||
|
|
||
| # Yarn Integrity file | ||
| .yarn-integrity | ||
|
|
||
|
|
||
|
|
||
| ### Vim ### | ||
| # swap | ||
| [._]*.s[a-w][a-z] | ||
| [._]s[a-w][a-z] | ||
| # session | ||
| Session.vim | ||
| # temporary | ||
| .netrwhist | ||
| *~ | ||
| # auto-generated tag files | ||
| tags | ||
|
|
||
|
|
||
| ### Windows ### | ||
| # Windows image file caches | ||
| Thumbs.db | ||
| ehthumbs.db | ||
|
|
||
| # Folder config file | ||
| Desktop.ini | ||
|
|
||
| # Recycle Bin used on file shares | ||
| $RECYCLE.BIN/ | ||
|
|
||
| # Windows Installer files | ||
| *.cab | ||
| *.msi | ||
| *.msm | ||
| *.msp | ||
|
|
||
| # Windows shortcuts | ||
| *.lnk | ||
|
|
||
|
|
||
| ### 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* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| # Bitmap Transformer | ||
|
|
||
| [](https://nodesource.com/products/nsolid) | ||
|
|
||
| ### Description | ||
| This bitmap 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. | ||
|
|
||
| ### Summary | ||
| To run the command line interface: | ||
| - navigate to bitmap-team0 directory | ||
| - Enter 'node index.js' | ||
|
|
||
| It can do transforms: | ||
| - Invert the colors | ||
| - Grayscale the colors | ||
| - (red|green|blue)scale the colors | ||
|
|
||
| It can can also: | ||
| - handle various sized bitmap | ||
| - handle palette and non-palette bitmaps | ||
| - handle multiple types of bitmaps (not just BM) | ||
| - handle LE and BE computers with a single if statement | ||
| - utilizes a command line interface (CLI) | ||
| - CLI can select the transforms | ||
|
|
||
| To run the gulp automated tests and linter: | ||
| - navigate to bitmap-team0 directory | ||
| - Enter 'gulp' | ||
|
|
||
| ### Dependencies | ||
|
|
||
| - chai | ||
| - gulp | ||
| - gulp-eslint | ||
| - gulp-mocha |
| 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" | ||
| } |
| 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() { | ||
| return gulp.src('./test/*-test.js', {read: false}) | ||
| .pipe(mocha({reporter: 'spec'})); | ||
| }); | ||
|
|
||
| gulp.task('lint', function() { | ||
| return gulp.src(['**/*.js', '!node_modules']) | ||
| .pipe(eslint()) | ||
| .pipe(eslint.format()) | ||
| .pipe(eslint.failAfterError()); | ||
| }); | ||
|
|
||
| gulp.task('default', ['lint', 'test']); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| 'use strict'; | ||
| const TB = require('./lib/TransformableBitmap.js'); | ||
| var ourTB = new TB('../img/palette-bitmap.bmp'); | ||
|
|
||
| ourTB.invert().grayscale().colorScale(1, 1.3, 0.8).write('out.bmp'); | ||
| console.log('chained transform written to out.bmp'); | ||
|
|
||
| const chooseTransform = require('./lib/cli.js'); | ||
|
Contributor
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. @bazacko @bhavyaab @ShaAllFar good inclusion of the |
||
|
|
||
|
|
||
| chooseTransform(); | ||
| // ourTB.invert().grayscale().colorScale(1,1.3,1).write('out.bmp'); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
|
|
||
| module.exports = TransformableBitmap; | ||
|
|
||
| function TransformableBitmap(path) { | ||
| this.bitmap = fs.readFileSync(path); | ||
| this.colorTableOffset = 14 + this.bitmap.readUInt32LE(14); | ||
| //this.width = this.bitmap.readUInt32LE(18); | ||
| //this.height = this.bitmap.readUInt32LE(22); | ||
|
Contributor
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. @bazacko @bhavyaab @ShaAllFar best practice is to remove these comment blocks from the |
||
| } | ||
|
|
||
| TransformableBitmap.prototype.invert = function() { | ||
| for (var i = 0; i <= 255; i++) { | ||
| for (var j = 0; j <= 2; j++) { | ||
| this.bitmap[this.colorTableOffset + i * 4 + j] = 255 - this.bitmap[this.colorTableOffset + i * 4 + j]; | ||
| } | ||
| } | ||
| this.write('../img/invert-palette-bitmap.bmp'); | ||
| return this; | ||
| }; | ||
|
|
||
| TransformableBitmap.prototype.grayscale = function() { | ||
| for (var i = 0; i <= 255; i++) { | ||
| var baseOffset = this.colorTableOffset + i * 4; | ||
| var avg = (this.bitmap[baseOffset + 0] + this.bitmap[baseOffset + 1] + this.bitmap[baseOffset + 2])/3; | ||
| for (var j = 0; j <= 2; j++) { | ||
| this.bitmap[baseOffset + j] = avg; | ||
| } | ||
| } | ||
| this.write('../img/grayscale-palette-bitmap.bmp'); | ||
| return this; | ||
| }; | ||
|
|
||
| TransformableBitmap.prototype.colorScale = function(redFactor, greenFactor, blueFactor) { | ||
| for (var i = 0; i <= 255; i++) { | ||
| var baseOffset = this.colorTableOffset + i * 4; | ||
| this.bitmap[baseOffset] = Math.min(Math.max(blueFactor * this.bitmap[baseOffset], 0), 255); | ||
| this.bitmap[baseOffset + 1] = Math.min(Math.max(greenFactor * this.bitmap[baseOffset + 1], 0), 255); | ||
| this.bitmap[baseOffset + 2] = Math.min(Math.max(redFactor * this.bitmap[baseOffset + 2], 0), 255); | ||
| } | ||
| this.write('../img/colorScale-palette-bitmap.bmp'); | ||
| return this; | ||
| }; | ||
|
|
||
|
|
||
| TransformableBitmap.prototype.write = function(path) { | ||
|
Contributor
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. @bazacko @bhavyaab @ShaAllFar transform methods look good! |
||
| fs.writeFileSync(path, this.bitmap); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| 'use strict'; | ||
|
|
||
| const readline = require('readline'); | ||
| const TB = require('./TransformableBitmap.js'); | ||
| var ourTB = new TB('../img/palette-bitmap.bmp'); | ||
|
|
||
| const rl = readline.createInterface({ | ||
| input: process.stdin, | ||
| output: process.stdout | ||
| }); | ||
|
|
||
| module.exports = function chooseTransform(){ | ||
|
|
||
| rl.question('\nDo you want to choose transformation? y/n or exit - ', (answer) => { | ||
| answer = answer.toLowerCase(); | ||
| switch (answer) { | ||
|
|
||
| case 'y': | ||
| console.log('\nChoose method by pressing specified key!'); | ||
| CLI(); | ||
| break; | ||
|
|
||
| case 'n': | ||
| console.log('\nRunnig all three transformation!'); | ||
| ourTB.invert().grayscale().colorScale(1,1.3,1); | ||
| console.log('\nAll three files are generated!!'); | ||
| rl.close(); | ||
| break; | ||
|
|
||
| case 'exit': | ||
| console.log('\nFunction Exit!!'); | ||
| rl.close(); | ||
| break; | ||
|
|
||
| default: console.log('\nNot right key!!\n', chooseTransform()); | ||
| } | ||
| }); | ||
| function CLI(){ | ||
| rl.question('\ninvert: enter \'i\' \ngrayscale: enter \'g\' \ncolorScale: enter \'c\' \nredGreenBleu: enter \'rgb\' \ntype \'exit\' and enter to quit. - ', (answer) => { | ||
| answer = answer.toLowerCase(); | ||
| switch (answer) { | ||
| case 'i': ourTB.invert(); | ||
| console.log('\ninvert-palette-bitmap.bmp file is generatd!!'); | ||
| CLI(); | ||
| break; | ||
| case 'g':ourTB.grayscale(); | ||
| console.log('\ngrayscale-palette-bitmap.bpm file is generated!'); | ||
| CLI(); | ||
| break; | ||
| case 'c':ourTB.colorScale(); | ||
| console.log('\ncolorScale-palette-bitmap.bmp file is been generated!'); | ||
| CLI(); | ||
| break; | ||
| case 'rgb': | ||
| rl.question('\nChoose BLUE (b) GREEN(g) RED(r) - ', (answer) => { | ||
| answer = answer.toLowerCase(); | ||
| switch (answer) { | ||
| case 'b': | ||
| ourTB.colorScale(2,1,1); | ||
| console.log('\nBlue-palette-bitmap.bmp file is generatd!!'); | ||
| CLI(); | ||
| break; | ||
| case 'g': | ||
| ourTB.colorScale(1,2,1); | ||
| console.log('\nGreen-palette-bitmap.bmp file is generatd!!'); | ||
| CLI(); | ||
| break; | ||
| case 'r': | ||
| ourTB.colorScale(1,1,2); | ||
| console.log('\nRed-palette-bitmap.bmp file is generatd!!'); | ||
| CLI(); | ||
| break; | ||
| default: chooseTransform(); | ||
| } | ||
| }); | ||
| break; | ||
| case 'exit': | ||
| console.log('\nFunction Exit!! \n'); | ||
| rl.close(); | ||
| break; | ||
| default : console.log('\nNot the right key \n '); CLI(); | ||
| } | ||
| }); | ||
| } | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| { | ||
| "name": "bitmap-team0", | ||
| "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" | ||
| } | ||
| } |
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.
@bazacko @bhavyaab @ShaAllFar
gulpfile.jslooks good!