Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
b2bad7a
initial commit
bazacko Dec 9, 2016
f93489f
test
bazacko Dec 9, 2016
764c607
rearranged into team folder, added placeholder gulpfile
bazacko Dec 9, 2016
9624f20
Merge pull request #1 from bazacko/kyler
bazacko Dec 9, 2016
aa56f3a
Merge remote-tracking branch 'upstream/master'
bazacko Dec 9, 2016
106de38
Merge branch 'master' of https://github.com/bazacko/04-bitmap-transfo…
bazacko Dec 9, 2016
4adb5df
bit more initial cleanup
bazacko Dec 9, 2016
02da4df
more cleanup
bazacko Dec 9, 2016
b1fe26f
remove DS store
bazacko Dec 9, 2016
cdf88b4
Create readMe.md
bhavyaab Dec 9, 2016
910b34c
Update readMe.md
bhavyaab Dec 9, 2016
9065794
Update readMe.md
bhavyaab Dec 9, 2016
1023a57
Rename readMe.md to README.md
bhavyaab Dec 9, 2016
9497542
Update README.md
bhavyaab Dec 9, 2016
beb1e2b
basic framework of bitmap transformer library, gulpfile, package.json
bazacko Dec 10, 2016
07c9b4b
Merge pull request #2 from bazacko/kyler
bazacko Dec 10, 2016
febb183
wrote basic write method
bazacko Dec 10, 2016
45a7585
Merge branch 'kyler'
bazacko Dec 10, 2016
e944433
testing
bazacko Dec 12, 2016
c156aa4
redid the entire thing
bazacko Dec 12, 2016
9d5ccf2
redid the entire thing
bazacko Dec 13, 2016
e0e7ffd
Merge branch 'kyler'
bazacko Dec 13, 2016
5239f20
added eslintrc and un-hardcoded color table offset
bazacko Dec 13, 2016
5c6c296
offset to palette is now determined by header data
bazacko Dec 13, 2016
b538601
added last two transforms and modified index.js to use them.
bazacko Dec 13, 2016
a62bf56
Merge branch 'kyler'
bazacko Dec 13, 2016
5554df7
initial 2 tests
ShaAllFar Dec 13, 2016
8d010df
try this again
ShaAllFar Dec 13, 2016
afbd2b2
Merge branch 'master' of https://github.com/bazacko/04-bitmap-transfo…
ShaAllFar Dec 13, 2016
99395bb
added another test
ShaAllFar Dec 13, 2016
5e5ba03
cmd interface
bhavyaab Dec 13, 2016
d62ed94
cli interface and rgb functionality
bhavyaab Dec 13, 2016
d5e11ee
error fixed
bhavyaab Dec 13, 2016
499c163
thanks for awesome CLI interface Bhavya
bazacko Dec 13, 2016
388b590
added demo of chained transforms above CLI routine
bazacko Dec 13, 2016
a68cd78
Merge branch 'lab-bhavya'
bazacko Dec 13, 2016
9d8df05
keep all changes
bhavyaab Dec 14, 2016
99a19f5
if sentences changed to switch
bhavyaab Mar 31, 2017
1cb9632
linter fix and running gulp and command line process explained
bhavyaab Mar 31, 2017
3840e47
Merge pull request #3 from bazacko/lab-bhavya
bhavyaab Mar 31, 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
127 changes: 127 additions & 0 deletions .gitignore
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*
35 changes: 35 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Bitmap Transformer

[![N|Solid](http://www.brackeen.com/vga/images/img00023.gif)](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
21 changes: 21 additions & 0 deletions bitmap-team0/.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"
}
19 changes: 19 additions & 0 deletions bitmap-team0/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() {
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']);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bazacko @bhavyaab @ShaAllFar gulpfile.js looks good!

12 changes: 12 additions & 0 deletions bitmap-team0/index.js
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');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bazacko @bhavyaab @ShaAllFar good inclusion of the chooseTransform module in your index file - that said, not sure if you should include the ourTB module in this file, with the associated transforms - this should be abstracted out and the user should be able to perform transforms through the CLI or by simply running the app and the appropriate methods being called (just not in the index file)



chooseTransform();
// ourTB.invert().grayscale().colorScale(1,1.3,1).write('out.bmp');
50 changes: 50 additions & 0 deletions bitmap-team0/lib/TransformableBitmap.js
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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 master branch

}

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bazacko @bhavyaab @ShaAllFar transform methods look good!

fs.writeFileSync(path, this.bitmap);
};
85 changes: 85 additions & 0 deletions bitmap-team0/lib/cli.js
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();
}
});
}
};
21 changes: 21 additions & 0 deletions bitmap-team0/package.json
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"
}
}
Binary file added bitmap-team0/palette-bitmap.bmp
Binary file not shown.
Loading