-
Notifications
You must be signed in to change notification settings - Fork 8
Nikko Bitmap Transformer Submission #24
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
d592378
ea84d48
f7da3b8
7699037
f0dc71e
0fe450c
339ec68
43dc59e
c3223c1
1125ba0
e9eb491
8062078
a9547d8
3168afa
28bbbe7
c77c30f
a686c80
155cbd2
bb3baca
2d9723c
502cded
7cb428b
ced7e3d
85e7588
c8ae7c4
370430d
8a16455
11066a1
90bb32e
d17a4db
4e661df
d07ac2d
c06b944
48fe73e
fcd8289
3f8b6c4
76ef542
65be057
581456f
f388951
14974e7
feb500c
6f6b8a3
37574ae
53a3521
84b5c76
2394bd5
8a57344
61d4a4b
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,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,117 @@ | ||
# Created by https://www.gitignore.io/api/node,vim,osx,macos,linux | ||
|
||
*node_modules | ||
|
||
### Node ### | ||
# 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-v][a-z] | ||
[._]*.sw[a-p] | ||
[._]s[a-v][a-z] | ||
[._]sw[a-p] | ||
# session | ||
Session.vim | ||
# temporary | ||
.netrwhist | ||
*~ | ||
# auto-generated tag files | ||
tags | ||
|
||
|
||
### 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 | ||
|
||
|
||
### macOS ### | ||
# Icon must end with two \r | ||
# Thumbnails | ||
# Files that might appear in the root of a volume | ||
# Directories potentially created on remote AFP share | ||
|
||
|
||
### 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* | ||
|
||
# End of https://www.gitignore.io/api/node,vim,osx,macos,linux | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
## Bitmap Transformer | ||
|
||
The Bitmap Transformer allows you to change any shape and size 8-bit palette bitmap file (extension .bmp) using your terminal command line and node.js. | ||
|
||
*** | ||
## How to Use | ||
|
||
* Install node.js if you do not have it (if you are not sure how, here is a [tutorial](https://docs.npmjs.com/getting-started/installing-node)). | ||
* Clone the Bitmap Transformer. | ||
|
||
``` | ||
$ git clone https://github.com/radenska/04-bitmap_transformer.git | ||
``` | ||
* Navigate to the bitmap-team-TeamName directory and run the transformer. | ||
|
||
``` | ||
$ node index <filename> <transformation> | ||
``` | ||
* You can view available files in the img directory, which is also where the new transformed files will appear (old filename + 'new'). | ||
|
||
``` | ||
$ ls img | ||
``` | ||
|
||
* The following transformations are available: red, green, blue, yellow, purple, invert, grayscale | ||
* Examples | ||
``` | ||
$ node index butterfly.bmp invert | ||
``` | ||
#### Original | ||
 | ||
#### Inverted | ||
 | ||
|
||
|
||
*** | ||
*** | ||
|
||
#### *Created by* | ||
|
||
|Darcy McCabe|Nikko Pisciotti|Yana Radenska | ||
|:---:|:---:|:---:| | ||
[GitHub Repos](https://github.com/darms) |[GitHub Repos](https://github.com/npisciotti1)| [GitHub Repos](https://github.com/radenska)| | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
'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' })); | ||
}); | ||
|
||
gulp.task('lint', function() { | ||
return gulp.src(['./**/*.js', '!node_modules/**']).pipe(eslint()).pipe(eslint.format()).pipe(eslint.failAfterError()); | ||
}); | ||
|
||
gulp.task('dev', function() { | ||
gulp.watch(['**/*.js', '!node_modules/**'], ['lint', 'test']); | ||
}); | ||
|
||
gulp.task('default', ['dev']); | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
'use strict'; | ||
|
||
const fileReadHelper = require(`${__dirname}/lib/bmp-file-helper.js`); | ||
const bmpCon = require(`${__dirname}/model/bmp-constructor.js`); | ||
const makeBitMap = bmpCon.makeBitMap; | ||
|
||
|
||
if (!process.argv[2] || !process.argv[3]) { | ||
console.error('Please enter two parameters: file name and transformation type (grayscale, invert, blue, green, red, yellow, purple)'); | ||
console.log('Format: node index <filename> <transformation type> Example: node index color-palette.bmp invert'); | ||
throw('error'); | ||
} | ||
fileReadHelper.getBitMap(makeBitMap); | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms great job checking command line arguments and handling any errors if the proper filename/transformation type were not provided additionally, great job creating and including a side note: no need to use |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const fs = require('fs'); | ||
module.exports = exports = {}; | ||
const filepath = `${__dirname}/../img/${process.argv[2]}`; | ||
const filepathNewfile = `${filepath.slice(0,filepath.length-4)}-new.bmp`; | ||
const testFilePath = `${filepath.slice(0,filepath.length-4)}-test.txt`; | ||
|
||
exports.getBitMap = function(cb) { | ||
fs.readFile(filepath, function(err, data) { | ||
if (err) throw err; | ||
cb(data); | ||
}); | ||
}; | ||
|
||
exports.newBitMap = function(data) { | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms i like the modularity and separate methods in this file but you may want to consider passing the file path into your |
||
fs.writeFile(filepathNewfile, data, function(err) { | ||
if (err) throw err; | ||
console.log('your new file can be found here: ', filepathNewfile); | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms - this looks fine with the exception of the commented line below and the comment block for your |
||
// makeTestData(testFilePath, data); | ||
}); | ||
}; | ||
|
||
|
||
//::this will write a buffer as a string to a new file for testing purposes:: | ||
|
||
// var makeTestData = function(testFilePath, data) { | ||
// var buffer = Buffer.from(data); | ||
// var testData = buffer.toString('hex'); | ||
// fs.writeFile(testFilePath, testData, function() { | ||
// console.log('Done writing test file!'); | ||
// }); | ||
// }; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
'use strict'; | ||
|
||
const fileReadHelper = require(`${__dirname}/../lib/bmp-file-helper.js`); | ||
module.exports = exports = {}; | ||
|
||
var bmObj = {}; | ||
|
||
exports.makeBitMap = function(data) { | ||
bmObj = new BitMap(data); | ||
bmObj.prepareArray(); | ||
selectTransformation(); | ||
bmObj.packageArray(); | ||
fileReadHelper.newBitMap(bmObj.buffer); | ||
}; | ||
|
||
function BitMap(data) { | ||
this.type = data.toString('utf-8', 0, 2); | ||
this.totalFileSize = data.readInt32LE(2); | ||
this.arrayLoc = data.readInt32LE(10); | ||
this.width = data.readInt32LE(18); | ||
this.height = data.readInt32LE(22); | ||
this.numColorPanes = data.readInt32LE(26); | ||
this.bitsPerPixel = data.readInt32LE(28); | ||
this.horizRes = data.readInt32LE(38); | ||
this.verticRes = data.readInt32LE(42); | ||
this.singles = data.toString('hex', 66, 1090).split(''); | ||
this.buffer = data; | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms great job including the raw buffer as part of your constructor!! generally speaking, this constructor looks great - lots of good and usable metadata extracted from the bitmap. i also really like the |
||
this.pairs = []; | ||
this.packaged = []; | ||
this.transformed = []; | ||
} | ||
|
||
BitMap.prototype.prepareArray = function() { | ||
for (let i = 0; i <= this.singles.length - 2; i += 2) { | ||
this.pairs.push(this.singles[i] + this.singles[i+1]); | ||
} | ||
}; | ||
|
||
BitMap.prototype.packageArray = function() { | ||
for (let i = 0; i <= this.transformed.length - 4; i += 4) { | ||
this.packaged.push(this.transformed[i] + this.transformed[i+1] + this.transformed[i+2]); | ||
} | ||
var offset = 66; | ||
for (let i = 0; i < this.packaged.length; i++) { | ||
this.buffer.write(this.packaged[i], offset, 'hex'); | ||
offset += 4; | ||
} | ||
}; | ||
|
||
BitMap.prototype.invert = function(){ | ||
this.transformed = this.pairs.map(val => { //invert colors | ||
val = (255 - parseInt(val, 16)).toString(16); | ||
if (val.length === 1) val = '0' + val; | ||
return val; | ||
}); | ||
}; | ||
|
||
BitMap.prototype.greyscale = function() { | ||
//a grayscale formula: 0.2989*red + 0.5870*green + 0.1140*blue, then each value (R, G, and B) is assigned the weighted average | ||
var grayArray = this.pairs.map(val => parseInt(val, 16)); | ||
for (let i = 0; i < grayArray.length - 4; i += 4) { | ||
let sumRGB = Math.floor(grayArray[i]*0.114 + grayArray[i+1]*0.587 + grayArray[i+2]*0.2989); //calculate weighted average | ||
grayArray[i] = grayArray[i+1] = grayArray[i+2] = sumRGB; //each value equals the sum | ||
} | ||
this.transformed = grayArray.map(val => { //turn into string and assign to transformed | ||
val = val.toString(16); | ||
if (val.length === 1) val = '0' + val; | ||
return val; | ||
}); | ||
}; | ||
|
||
BitMap.prototype.colorify = function(colorIndex, i2, i3) { | ||
this.transformColor(colorIndex, 0.7); | ||
this.transformColor(i2, 0); //set non chosen values to 0 | ||
this.transformColor(i3, 0); | ||
this.transformed = this.pairs; | ||
}; | ||
|
||
BitMap.prototype.transformColor = function(start, colorVal) { | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms transform prototype methods look good but there is a bit too much going on in this file - a better approach would be to simply create the constructor, add the prototype methods, and export the constructor (which will have access to the prototype methods after instantiation in another file) example:
|
||
// position 0: blue 1: green 2: red 3: padding | ||
for (let i = start; i <= this.pairs.length - 4; i += 4) { //change blue values | ||
this.pairs[i] = Math.floor((parseInt(this.pairs[i], 16))*colorVal); | ||
if (this.pairs[i] > 255) this.pairs[i] = 255; | ||
this.pairs[i] = this.pairs[i].toString(16); | ||
if (this.pairs[i].length === 1) this.pairs[i] = '0' + this.pairs[i]; | ||
} | ||
}; | ||
|
||
function selectTransformation() { | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms great transform selector - this could be refactored to be a bit more DRY but i love the addition of it! |
||
let userChoice = process.argv[3].toLowerCase(); | ||
if (userChoice === 'blue') bmObj.colorify(0, 1, 2); | ||
if (userChoice === 'red') bmObj.colorify(2, 0, 1); | ||
if (userChoice === 'green') bmObj.colorify(1, 0, 2); | ||
if (userChoice === 'invert') bmObj.invert(); | ||
if (userChoice === 'purple') { | ||
bmObj.colorify(0, 1, 1); | ||
bmObj.colorify(2, 1, 1); | ||
} | ||
if (userChoice === 'yellow') { | ||
bmObj.colorify(1, 0, 0); | ||
bmObj.colorify(2, 0, 0); | ||
} | ||
if (userChoice === 'grayscale' || userChoice === 'greyscale') bmObj.greyscale(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"name": "bitmap-team-TeamName", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"gulp": "^3.9.1", | ||
"gulp-eslint": "^3.0.1", | ||
"gulp-mocha": "^3.0.1", | ||
"mocha": "^3.2.0" | ||
}, | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC" | ||
} | ||
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. @npisciotti1 @radenska @sneakyneeks2 @darms |
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.
@npisciotti1 @radenska @sneakyneeks2 @darms
.eslintrc
looks good