Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b6b8b03
Adds scaffolding.
nharren Jul 20, 2017
2856aeb
Change license and update lint script.
nharren Jul 20, 2017
8078a06
Merge pull request #1 from nharren/features/scaffolding
nharren Jul 20, 2017
c765203
worked on the bitmap header
bretladenburg Jul 20, 2017
a35dd0d
got the file header to read to the console.
bretladenburg Jul 20, 2017
a6d2e20
wrote some logic to read the hex numbers of the color table
bretladenburg Jul 20, 2017
932c5f5
Reads pixel array.
nharren Jul 21, 2017
9f80a13
Adds DIB header and fixes pixel array and color table.
nharren Jul 21, 2017
be755da
Refactors module to export function which provides the constructed bi…
nharren Jul 21, 2017
4fc7628
BGRa to RGBa
nharren Jul 21, 2017
f0f87df
Merge pull request #8 from nharren/features/read-file-header
nharren Jul 21, 2017
0669a65
Merge pull request #9 from nharren/features/read-color-table
nharren Jul 21, 2017
52de6cb
Merge pull request #10 from nharren/features/read-pixel-array
nharren Jul 21, 2017
6ba2749
Merge pull request #11 from nharren/features/dib-header-and-fixes
nharren Jul 21, 2017
643a944
Merge pull request #12 from nharren/refactor/bitmap-callback
nharren Jul 21, 2017
fcc76f8
added get pixel function
sharmarkei Jul 21, 2017
af96041
Merge pull request #13 from nharren/features/get-pixel
nharren Jul 21, 2017
4d04aae
Adds event emitter.
nharren Jul 21, 2017
f186edc
Merge pull request #14 from nharren/features/event-emitter
nharren Jul 21, 2017
df8bf38
Removes redundant callbacks.
nharren Jul 22, 2017
f895cb6
Adds bitmap transformer.
nharren Jul 22, 2017
bc0516c
Adds more transforms and color conversions to and from hsl.
nharren Jul 22, 2017
644bceb
Adds bitmap tests.
nharren Jul 23, 2017
328408e
Adds color test.
nharren Jul 23, 2017
4ba4512
Adds bitmap transformer test.
nharren Jul 23, 2017
f5ede66
Moves color transforms to separate module and reads all bitmap headers.
nharren Jul 24, 2017
d3253af
Adds chroma transforms and updated documentation.
nharren Jul 24, 2017
2af5726
Merge pull request #15 from nharren/features/bitmap-transformer
nharren Jul 24, 2017
b1d6084
Merge pull request #16 from nharren/features/more-transforms
nharren Jul 24, 2017
5f0b97d
Merge pull request #17 from nharren/features/tests
nharren Jul 24, 2017
b8eeb0e
Merge pull request #18 from nharren/features/bitmap-headers
nharren Jul 24, 2017
6de4f46
Merge pull request #19 from nharren/features/transforms-and-docs
nharren Jul 24, 2017
db444ba
Update README.md
nharren Jul 24, 2017
116b47d
Adds cli.
nharren Jul 24, 2017
83f8846
Merge branch 'master' into features/cli
nharren Jul 24, 2017
733e989
Merge pull request #20 from nharren/features/cli
nharren Jul 24, 2017
f7d1b5d
Makes reading bitmaps endian agnostic.
nharren Jul 25, 2017
b0bd547
Merge pull request #21 from nharren/features/endianness
nharren Jul 25, 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
6 changes: 6 additions & 0 deletions bitmap-autobots/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
**/assets/*
23 changes: 23 additions & 0 deletions bitmap-autobots/.eslintrc
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"
}
138 changes: 138 additions & 0 deletions bitmap-autobots/.gitignore
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
49 changes: 49 additions & 0 deletions bitmap-autobots/README.md
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.
134 changes: 134 additions & 0 deletions bitmap-autobots/index.js
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(':');

Copy link
Copy Markdown

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.

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);
Loading