-
Notifications
You must be signed in to change notification settings - Fork 12
Sarah and Nassir's bitmap transform lab #14
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
piper88
wants to merge
45
commits into
codefellows-seattle-javascript-401d10:master
Choose a base branch
from
njisaf:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
2a70990
Building scaffold on master. YOLO
njisaf d288cfb
Trying again to eslint and gulpfile
njisaf dff9784
Trying again to push some untracked files
njisaf 824436a
Merge pull request #1 from njisaf/constructors
njisaf 9d88f70
Reading buffer from bitmap.bmp
njisaf 8a1d981
Merge pull request #2 from njisaf/constructors
njisaf 603a89a
writes test for reading buffer
piper88 4c7cd45
Merge pull request #3 from njisaf/initial-bitmap-read-test
njisaf f327bfd
eslint
njisaf 844ef23
Initial constructor functionality
njisaf 9a9e385
Fixed merge conflix
njisaf d69843c
Merge pull request #4 from njisaf/constructors
njisaf b0e7912
sliced color and pixel array from buffer
piper88 87f0069
Merge pull request #5 from njisaf/bitmap-constructor
njisaf 808cf57
changing colors, identified rgba values
njisaf b374835
test bmp file
njisaf dab5d13
Merge pull request #6 from njisaf/what-is-color-array
njisaf a4a5c99
add gray invert and rgb
piper88 1f4c6bd
Merge pull request #7 from njisaf/sarah-friday-experimenting
piper88 0974eae
refactored to control from index, grayscale transform
njisaf 64d3afb
Merge pull request #8 from njisaf/refactor
njisaf de8d466
Tests are not working
njisaf 85e4598
Merge pull request #9 from njisaf/testing-tests
njisaf fcbb566
adds useless tests that dont work
piper88 55cb262
Merge pull request #10 from njisaf/transform-test
njisaf 61b3feb
merge conflix
njisaf 777e47b
Merge pull request #11 from njisaf/testing-tests
njisaf eee5f29
conflix fix
njisaf 081e8cc
conflix
njisaf 3827eef
Bitmap constructor test working
njisaf 6197f0d
Merge pull request #12 from njisaf/new-test
njisaf c4cf634
Cleaning up test images
njisaf 3c44438
Merge pull request #13 from njisaf/new-test
njisaf e6ff831
small test fix
njisaf 4ab2f27
small test fix
njisaf b55ddf1
add read-me and clean up old commented code and consolelogs
piper88 f8e88b7
Merge pull request #14 from njisaf/read-me-clean-up
piper88 bab222d
Simple endianness check added to bitmap constructor
njisaf 917bc0f
Merge conflix
njisaf f9bb69a
More conflix
njisaf 3397a52
Merge pull request #15 from njisaf/endians
njisaf 6c4bbf7
non-palette bmps now handled
njisaf 20e5f6c
Merge pull request #16 from njisaf/non-palette
njisaf c8fb365
Now Can handle os/2 bmps as well
njisaf 4932451
Merge pull request #17 from njisaf/multibms
njisaf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,3 +63,6 @@ Session.vim | |
|
|
||
| # auto-generated tag files | ||
| tags | ||
|
|
||
| # new bitmaps | ||
| new*.bmp | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 111 |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "rules": { | ||
| "comma-dangle": ["error", "always-multiline"], | ||
| "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 | ||
| }, | ||
| "globals": { | ||
| }, | ||
| "ecmaFeatures": { | ||
| "modules": true, | ||
| "experimentalObjectRestSpread": true, | ||
| "impliedStrict": true | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| # 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 | ||
| *~ | ||
|
|
||
| ### Existential Dread ### | ||
| inevitable_death | ||
| ever_present_cowardice | ||
| pain_of_wakefulness | ||
|
|
||
| # auto-generated tag files | ||
| tags | ||
|
|
||
| # new bitmaps | ||
| new*.bmp |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # Sarah and Nassir's Bitmap Lab | ||
|
|
||
| ## Reads a bitmap file, performs 3 transforms, and outputs a new transformed bitmap | ||
|
|
||
| ### 3 Transforms: | ||
| 1. Invert Transform | ||
| 2. Gray Transform | ||
| 3. RGB Transform | ||
|
|
||
| ### Using our program: | ||
| 1. Run 'node index.js [bitmap filepath] [transform-method]' from main project directory | ||
| 2. Transform method flags: | ||
| a. invert | ||
| b. gray | ||
| c. rgb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| 'use strict'; | ||
|
|
||
| const gulp = require('gulp'); | ||
| const eslint = require('gulp-eslint'); | ||
| const mocha = require('gulp-mocha'); | ||
|
|
||
| gulp.task('hello', function(){ | ||
| console.log('hello'); | ||
| }); | ||
|
|
||
| gulp.watch('***/*.js', ['hello']); | ||
|
|
||
| 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: 'nyan'})); | ||
| }); | ||
|
|
||
| gulp.task('dev', function(){ | ||
| gulp.watch(['**/*.js','!node_modules/**'], ['test', 'lint']); | ||
| }); | ||
|
|
||
| gulp.task('default', ['dev']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| 'use strict'; | ||
|
|
||
| const bitmapReader = require('./lib/bitmap-read'); | ||
| const bitmapConstructor = require('./model/bitmap-constructor'); | ||
| const bitmapWriter = require('./lib/bitmap-write'); | ||
| const programSelect = process.argv[3]; | ||
| const fileSelect = process.argv[2]; | ||
|
|
||
|
|
||
| function runProgram(){ | ||
| if (!programSelect || !fileSelect) { | ||
| console.error('Error!! Program requires a filename and transform\nUse form \'node index.js filename.bmp transform\' \nThree transforms are available: invert, gray, rgb'); | ||
| } else { | ||
| bitmapReader(fileSelect, function(err, buffer){ | ||
| if (err) throw console.error('Error! Not a valid file.\nFiles much be in form filename.bmp, and must be in the assets directory.'); | ||
| bitmapConstructor(buffer, fileSelect, function(err, object){ | ||
| if (err) throw console.error('Error! bitmapConstructor is not receiving a valid buffer object.'); | ||
| var fileHeaders = ['BM', 'BA', 'CI', 'CP', 'IC', 'PT']; | ||
| if (fileHeaders.indexOf(object.isBitmap) === -1) throw console.error('Error! File does not appear to be a valid bitmap file.'); | ||
| bitmapWriter(object, programSelect, function(err, newFilePath){ | ||
| console.log('New file saved as ' + newFilePath + ' in assets.'); | ||
| }); | ||
| }); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| runProgram(); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
|
|
||
| module.exports = function bitmapRead(pathName, callback) { | ||
| fs.readFile(`${__dirname}/../../assets/${pathName}`, function(err, buffer) { | ||
| if (err) return callback(err); | ||
| callback(null, buffer); | ||
| }); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const EE = require('events'); | ||
| const myEE = new EE(); | ||
|
|
||
| const invertTransform = require('./invert-transform.js'); | ||
| const grayTransform = require('./gray-transform.js'); | ||
| const rgbTransform = require('./rgb-transform.js'); | ||
|
|
||
| module.exports = function bitmapWriter(object, programSelect, callback) { | ||
| var colorArray = object.colorArray; | ||
| var pathName = object.pathName; | ||
| var buffer = object.wholeBuffer; | ||
|
|
||
| myEE.on('first', function(){ | ||
| if (colorArray[0] === undefined) colorArray = object.pixelArray; | ||
|
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. Nitpicky, but undefined is a falsey value, so you could simply write: |
||
| myEE.emit('second'); | ||
| }); | ||
|
|
||
| myEE.on('second', function(){ | ||
| if (programSelect === 'invert') { | ||
| invertTransform(colorArray, function(){}); | ||
| } else if (programSelect === 'gray') { | ||
| grayTransform(colorArray, function(){}); | ||
| } else if (programSelect === 'rgb') { | ||
| rgbTransform(colorArray, function(){}); | ||
| } else { | ||
| console.error('Error! Transform if/else statement running to end'); | ||
| } | ||
| myEE.emit('third'); | ||
| }); | ||
|
|
||
| myEE.on('third', function(){ | ||
| var newPathName = `new${pathName}`; | ||
| fs.writeFile(`../assets/new${pathName}`, buffer, function() { | ||
| callback(null, newPathName); | ||
| }); | ||
| }); | ||
| myEE.emit('first'); | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
|
|
||
| module.exports = function grayscaleBitmap(colorArray, callback) { | ||
| for (var i = 0; i < colorArray.length; i += 4) { | ||
| var arrayChunk = colorArray.slice([i], [i+4]); | ||
| var avg = (arrayChunk[0] + arrayChunk[1] + arrayChunk[2] + arrayChunk[3])/4; | ||
| arrayChunk[0] = avg; //blue | ||
| arrayChunk[1] = avg; //green | ||
| arrayChunk[2] = avg; //red | ||
| arrayChunk[3] = avg; //alpha | ||
| } | ||
| callback(arrayChunk); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
|
|
||
|
|
||
| module.exports = function invertBitmap(colorArray, callback) { | ||
| for (var i = 0; i < colorArray.length; i += 4) { | ||
| var arrayChunk = colorArray.slice([i], [i+4]); | ||
| arrayChunk[0] = 255 - arrayChunk[0]; //blue | ||
| arrayChunk[1] = 255 - arrayChunk[1]; //green | ||
| arrayChunk[2] = 255 - arrayChunk[2]; //red | ||
| arrayChunk[3] = 255 - arrayChunk[3]; //alpha | ||
| } | ||
| callback(arrayChunk); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| 'use strict'; | ||
|
|
||
|
|
||
| module.exports = function rgbBitmap(colorArray, callback) { | ||
| for (var i = 0; i < colorArray.length; i += 4) { | ||
| var arrayChunk = colorArray.slice([i], [i+4]); | ||
| arrayChunk[0] = arrayChunk[0]; //blue | ||
| arrayChunk[1] = 255 * arrayChunk[1]; //green | ||
| arrayChunk[2] = arrayChunk[2]; //red | ||
| arrayChunk[3] = arrayChunk[3]; //alpha | ||
| } | ||
| callback(arrayChunk); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| 'use strict'; | ||
|
|
||
| const os = require('os'); | ||
|
|
||
| module.exports = function buildObject(bufferIn, pathName, callback) { | ||
| var bitmapObject = new Bitmap(bufferIn, pathName); | ||
| callback(null, bitmapObject); | ||
| }; | ||
|
|
||
| function Bitmap(buffer, pathName) { | ||
| this.pathName = pathName; | ||
| this.isBitmap = buffer.toString('utf8', 0, 2); | ||
| this.wholeBuffer = buffer; | ||
| this.header = buffer.toString('utf8', 0, 15); | ||
| this.headerLength = checkEndian(buffer, 14, 18) + 14; | ||
| this.endianness = os.endianness(); | ||
| this.fileSize = checkEndian(buffer, 2, 6); | ||
| this.offset = checkEndian(buffer, 10, 14); | ||
| this.colorArray = buffer.slice(this.headerLength, this.offset); | ||
| this.pixelArray = buffer.slice(this.offset); | ||
| } | ||
|
|
||
| function checkEndian(buffer, start, finish) { | ||
|
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. So cool! |
||
| if (os.endianness() === 'LE') { | ||
| return buffer.readUInt32LE(start, finish); | ||
| } else if (os.endianness() === 'BE') { | ||
| return buffer.readUInt32BE(start, finish); | ||
| } else { | ||
| console.error('Error!! checkEndian is not functioning'); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| { | ||
| "name": "bitmap-nassarah", | ||
| "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", | ||
| "mocha": "^3.0.2" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('assert'); | ||
| const bitmapReader = require('../lib/bitmap-read'); | ||
| const bitmapConstructor = require('../model/bitmap-constructor'); | ||
|
|
||
| describe('This tests whether bitmap-constructor is outputting a valid bitmap object', function() { | ||
| it('bitmap-constructor should return an object with a property .isBitmap with a value of \'BM\'', function(done){ | ||
| bitmapReader('testimage-actuallyjpg.bmp', function(err, buffer){ | ||
| bitmapConstructor(buffer, 'testimage-actuallyjpg.bmp', function(err, object){ | ||
| var testThis = object.isBitmap; | ||
| assert.ok(testThis !== 'BM', 'This property should not read BM'); | ||
| }); | ||
| done(); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nice command line functionality!