-
Notifications
You must be signed in to change notification settings - Fork 5
nathan-sharmarke-bret #11
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
nharren
wants to merge
38
commits into
codefellows-javascript-401d17:master
Choose a base branch
from
nharren: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
38 commits
Select commit
Hold shift + click to select a range
b6b8b03
Adds scaffolding.
nharren 2856aeb
Change license and update lint script.
nharren 8078a06
Merge pull request #1 from nharren/features/scaffolding
nharren c765203
worked on the bitmap header
bretladenburg a35dd0d
got the file header to read to the console.
bretladenburg a6d2e20
wrote some logic to read the hex numbers of the color table
bretladenburg 932c5f5
Reads pixel array.
nharren 9f80a13
Adds DIB header and fixes pixel array and color table.
nharren be755da
Refactors module to export function which provides the constructed bi…
nharren 4fc7628
BGRa to RGBa
nharren f0f87df
Merge pull request #8 from nharren/features/read-file-header
nharren 0669a65
Merge pull request #9 from nharren/features/read-color-table
nharren 52de6cb
Merge pull request #10 from nharren/features/read-pixel-array
nharren 6ba2749
Merge pull request #11 from nharren/features/dib-header-and-fixes
nharren 643a944
Merge pull request #12 from nharren/refactor/bitmap-callback
nharren fcc76f8
added get pixel function
sharmarkei af96041
Merge pull request #13 from nharren/features/get-pixel
nharren 4d04aae
Adds event emitter.
nharren f186edc
Merge pull request #14 from nharren/features/event-emitter
nharren df8bf38
Removes redundant callbacks.
nharren f895cb6
Adds bitmap transformer.
nharren bc0516c
Adds more transforms and color conversions to and from hsl.
nharren 644bceb
Adds bitmap tests.
nharren 328408e
Adds color test.
nharren 4ba4512
Adds bitmap transformer test.
nharren f5ede66
Moves color transforms to separate module and reads all bitmap headers.
nharren d3253af
Adds chroma transforms and updated documentation.
nharren 2af5726
Merge pull request #15 from nharren/features/bitmap-transformer
nharren b1d6084
Merge pull request #16 from nharren/features/more-transforms
nharren 5f0b97d
Merge pull request #17 from nharren/features/tests
nharren b8eeb0e
Merge pull request #18 from nharren/features/bitmap-headers
nharren 6de4f46
Merge pull request #19 from nharren/features/transforms-and-docs
nharren db444ba
Update README.md
nharren 116b47d
Adds cli.
nharren 83f8846
Merge branch 'master' into features/cli
nharren 733e989
Merge pull request #20 from nharren/features/cli
nharren f7d1b5d
Makes reading bitmaps endian agnostic.
nharren b0bd547
Merge pull request #21 from nharren/features/endianness
nharren 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| **/node_modules/* | ||
| **/vendor/* | ||
| **/*.min.js | ||
| **/coverage/* | ||
| **/build/* | ||
| **/assets/* |
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,23 @@ | ||
| { | ||
| "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 | ||
| }, | ||
| "parserOptions": { | ||
| "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,138 @@ | ||
| # Created by https://www.gitignore.io/api/osx,vim,node,macos,windows | ||
|
|
||
| ### 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 ### | ||
| # Logs | ||
| logs | ||
| *.log | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.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 | ||
|
|
||
| # Bower dependency directory (https://bower.io/) | ||
| bower_components | ||
|
|
||
| # node-waf configuration | ||
| .lock-wscript | ||
|
|
||
| # Compiled binary addons (http://nodejs.org/api/addons.html) | ||
| build/Release | ||
|
|
||
| # Dependency directories | ||
| node_modules/ | ||
| jspm_packages/ | ||
|
|
||
| # Typescript v1 declaration files | ||
| typings/ | ||
|
|
||
| # 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 | ||
|
|
||
| # dotenv environment variables file | ||
| .env | ||
|
|
||
|
|
||
| ### OSX ### | ||
|
|
||
| # Icon must end with two \r | ||
|
|
||
| # Thumbnails | ||
|
|
||
| # Files that might appear in the root of a volume | ||
|
|
||
| # Directories potentially created on remote AFP share | ||
|
|
||
| ### 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 | ||
|
|
||
| ### Windows ### | ||
| # Windows thumbnail cache files | ||
| Thumbs.db | ||
| ehthumbs.db | ||
| ehthumbs_vista.db | ||
|
|
||
| # Folder config file | ||
| Desktop.ini | ||
|
|
||
| # Recycle Bin used on file shares | ||
| $RECYCLE.BIN/ | ||
|
|
||
| # Windows Installer files | ||
| *.cab | ||
| *.msi | ||
| *.msm | ||
| *.msp | ||
|
|
||
| # Windows shortcuts | ||
| *.lnk | ||
|
|
||
| # End of https://www.gitignore.io/api/osx,vim,node,macos,windows | ||
|
|
||
| output |
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,49 @@ | ||
| # Bitmap Transformer | ||
|
|
||
| This project contains five modules which facilitate the transformation of bitmap files: | ||
|
|
||
| * **Color**: Handles color calcuations, parsing, and stringifying. | ||
| * **Color Transforms**: Attaches various color transformations to the Color prototype. | ||
| * **Bitmap**: Handles parsing of bitmap files. | ||
| * **Bitmap Transformer**: Exposes methods for manipulating bitmaps. | ||
| * **Bitmap Transforms**: Attaches various bitmap transformations to the Bitmap prototype. | ||
|
|
||
| The available transformations are: | ||
| * Black and White | ||
| * Grayscale | ||
| * Sepia | ||
| * Horizontal Flip | ||
| * Vertical Flip | ||
| * Color Inversion | ||
| * Clockwise Rotation | ||
| * Counterclockwise Rotation | ||
| * Hue Shift | ||
| * Lightness Shift | ||
| * Saturation Shift | ||
| * Redness Shift | ||
| * Greenness Shift | ||
| * Blueness Shift | ||
|
|
||
| ## CLI | ||
|
|
||
| To use the CLI, type `node index.js [filename] [transformation[:parameter]] [transformation[:parameter]] [transformation[:parameter]]` etc. | ||
|
|
||
| The transformation arguments are: | ||
| * `bw` -- Black and White | ||
| * `gray` -- Grayscale | ||
| * `sepia` -- Sepia | ||
| * `hflip` -- Horizontal Flip | ||
| * `vflip` -- Vertical Flip | ||
| * `invert` -- Color Inversion | ||
| * `rotc` -- Clockwise Rotation | ||
| * `rotcc` -- Counterclockwise Rotation | ||
| * `hshift:degree` -- Hue Shift | ||
| * `lshift:percentage` -- Lightness Shift | ||
| * `sshift:percentage` -- Saturation Shift | ||
| * `rshift:magnitude` -- Redness Shift | ||
| * `gshift:magnitude` -- Greenness Shift | ||
| * `bshift:magnitude` -- Blueness Shift | ||
|
|
||
| The output will be located at `./output/custom.bmp`. | ||
|
|
||
| Running the cli without arguments will produce a sample of all transformations. |
File renamed without changes.
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,134 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
| const Bitmap = require('./lib/bitmap.js'); | ||
| require('./lib/bitmap-transforms.js'); | ||
|
|
||
| let checkOutputDirectoryExists = function() { | ||
| return new Promise(function(resolve, reject) { | ||
| fs.exists('./output/', function(exists) { | ||
| if (exists) { | ||
| resolve(); | ||
| } | ||
| else { | ||
| reject(); | ||
| } | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| let createOutputDirectory = function() { | ||
| return new Promise(function(resolve, reject) { | ||
| fs.mkdir('./output', function(err) { | ||
| if (err) reject(err); | ||
| resolve(); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| let loadBitmap = function(filename) { | ||
| return new Promise(function(resolve, reject) { | ||
| fs.readFile(filename, function(err, buffer) { | ||
| if (err) reject(err); | ||
| resolve(new Bitmap(buffer)); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| let createOutput = function(fileName, bitmap, func) { | ||
| return new Promise(function(resolve, reject) { | ||
| let transformedBitmap = func(); | ||
|
|
||
| fs.writeFile(`./output/${fileName}.bmp`, transformedBitmap.buffer, 'binary', function(err) { | ||
| if (err) reject(err); | ||
| resolve(bitmap); | ||
| }); | ||
| }); | ||
| }; | ||
|
|
||
| let filePath = process.argv[2]; | ||
| let transforms = process.argv.slice(3); | ||
|
|
||
| if (filePath && transforms) { | ||
| checkOutputDirectoryExists() | ||
| .catch(createOutputDirectory) | ||
| .then(() => loadBitmap(filePath)) | ||
| .then(bitmap => { | ||
| while (transforms.length > 0) { | ||
| let transform = transforms.shift(); | ||
| let transformParts = transform.split(':'); | ||
|
|
||
| switch (transformParts[0]) { | ||
| case 'bw': | ||
| bitmap = bitmap.toBlackAndWhite(); | ||
| break; | ||
| case 'hflip': | ||
| bitmap = bitmap.flipHorizontally(); | ||
| break; | ||
| case 'vflip': | ||
| bitmap = bitmap.flipVertically(); | ||
| break; | ||
| case 'gray': | ||
| bitmap = bitmap.toGrayscale(); | ||
| break; | ||
| case 'invert': | ||
| bitmap = bitmap.invertColors(); | ||
| break; | ||
| case 'rotc': | ||
| bitmap = bitmap.rotateClockwise(); | ||
| break; | ||
| case 'rotcc': | ||
| bitmap = bitmap.rotateCounterclockwise(); | ||
| break; | ||
| case 'sepia': | ||
| bitmap = bitmap.toSepia(); | ||
| break; | ||
| case 'bshift': | ||
| bitmap = bitmap.shiftBlueness(Number(transformParts[1])); | ||
| break; | ||
| case 'gshift': | ||
| bitmap = bitmap.shiftGreenness(Number(transformParts[1])); | ||
| break; | ||
| case 'rshift': | ||
| bitmap = bitmap.shiftRedness(Number(transformParts[1])); | ||
| break; | ||
| case 'sshift': | ||
| bitmap = bitmap.shiftSaturation(Number(transformParts[1])); | ||
| break; | ||
| case 'hshift': | ||
| bitmap = bitmap.shiftHue(Number(transformParts[1])); | ||
| break; | ||
| case 'lshift': | ||
| bitmap = bitmap.shiftLightness(Number(transformParts[1])); | ||
| break; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| createOutput('custom', bitmap, () => bitmap); | ||
|
|
||
| }) | ||
| .catch(err => console.error(err)); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
|
|
||
| checkOutputDirectoryExists() | ||
| .catch(createOutputDirectory) | ||
| .then(() => loadBitmap(`${__dirname}/assets/palette-bitmap.bmp`), console.error) | ||
| .then(bitmap => createOutput('black-and-white', bitmap, () => bitmap.toBlackAndWhite()), console.error) | ||
| .then(bitmap => createOutput('grayscale', bitmap, () => bitmap.toGrayscale()), console.error) | ||
| .then(bitmap => createOutput('sepia', bitmap, () => bitmap.toSepia()), console.error) | ||
| .then(bitmap => createOutput('inverted-colors', bitmap, () => bitmap.invertColors()), console.error) | ||
| .then(bitmap => createOutput('flipped-horizontally', bitmap, () => bitmap.flipHorizontally()), console.error) | ||
| .then(bitmap => createOutput('flipped-vertically', bitmap, () => bitmap.flipVertically()), console.error) | ||
| .then(bitmap => createOutput('rotate-clockwise', bitmap, () => bitmap.rotateClockwise()), console.error) | ||
| .then(bitmap => createOutput('rotate-counterclockwise', bitmap, () => bitmap.rotateCounterclockwise()), console.error) | ||
| .then(bitmap => createOutput('shift-hue', bitmap, () => bitmap.shiftHue(60)), console.error) | ||
| .then(bitmap => createOutput('shift-saturation', bitmap, () => bitmap.shiftSaturation(-30)), console.error) | ||
| .then(bitmap => createOutput('shift-lightness', bitmap, () => bitmap.shiftLightness(20)), console.error) | ||
| .then(bitmap => createOutput('shift-redness', bitmap, () => bitmap.shiftRedness(5)), console.error) | ||
| .then(bitmap => createOutput('shift-greenness', bitmap, () => bitmap.shiftGreenness(5)), console.error) | ||
| .then(bitmap => createOutput('shift-blueness', bitmap, () => bitmap.shiftBlueness(5)), console.error); | ||
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.
while this switch statement works for what you are accomplishing another way to handle this that would only take up a single line of code and would keep it from growing out of control if you had 100+ transformations would be to access the property of the object. So instead of passing in a string of bw or hflip you could pass in the name of the property and just access the bitmapproperty. For the items with parameters you can have another variable you pass in to bitmapproperty and on the ones that don't need the parameter you can ignore it as they won't accept a parameter anyway.