Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
a0c909b
Created initial scaffold.
BatemanVO Dec 9, 2016
d41b72e
Created bitmap constructor module.
BatemanVO Dec 9, 2016
2489d1a
Added constructor test. Checked for passing.
BatemanVO Dec 9, 2016
38a98c2
Added a console.dir(bitmap) to show colorTable for testing purposes.
BatemanVO Dec 9, 2016
800ebba
Created lib directory, added placeholder files.
BatemanVO Dec 9, 2016
9e50f46
Added comments explaining the slice range in bitmap-constructor.js.
BatemanVO Dec 9, 2016
4a6a4de
Merge pull request #1 from BatemanVO/bitmap_constructor
BatemanVO Dec 9, 2016
c02b605
Started writing tests.
BatemanVO Dec 9, 2016
3275fcf
Added second it block that checks if the bitmap-constructor object's …
BatemanVO Dec 9, 2016
a7bb5ff
Added test to check if an inverted-palette.bmp image was successfully…
BatemanVO Dec 9, 2016
756b176
Properly imported chai. Ran tests, failed as expected.
BatemanVO Dec 9, 2016
3989a1e
Fixed formatting in test file. Wrote invertColorTable function.
BatemanVO Dec 9, 2016
aeb4fc4
Updated invertColorTable function to make a copy of the original bitm…
BatemanVO Dec 10, 2016
ab76ccf
Updated inverter test.
BatemanVO Dec 10, 2016
392c7e6
Fixed invertColorTable function.
BatemanVO Dec 10, 2016
9302765
Created createInvertedBitmap function. Changed test name to reflect.
BatemanVO Dec 10, 2016
5deef24
Fixed issues with last test.
BatemanVO Dec 10, 2016
9c1272a
Merge pull request #2 from BatemanVO/color_inverter
BatemanVO Dec 10, 2016
3bb8867
Created Gulp file. Disabled eslint on bitmap-constructor.
BatemanVO Dec 10, 2016
a1df353
Created cli-interpreter.js.
BatemanVO Dec 10, 2016
32f3f2f
Updated bitmap-transformer.js to call transforms based on CLI arguments.
BatemanVO Dec 10, 2016
d03e677
Created test for cli-interpreter.
BatemanVO Dec 10, 2016
a92458b
Merge pull request #3 from BatemanVO/cli_interface
BatemanVO Dec 10, 2016
749685e
Fixed grayscale transformer and finish tests.
abdih17 Dec 12, 2016
c3391fe
Added comments to personally-written modules.
BatemanVO Dec 12, 2016
32c2b11
Added README.md file for how to use the Node app.
BatemanVO Dec 12, 2016
fc1886d
add bluescale transform application
maschigokae Dec 12, 2016
664f075
add cli handler for bluescale transform app
maschigokae Dec 12, 2016
a2f1dac
Finished writing tests for the grayscale transformers, and edited the…
abdih17 Dec 12, 2016
7cf2b8b
Merge pull request #4 from BatemanVO/grayscale-testing
abdih17 Dec 12, 2016
5b2e204
adjusted color palatte offset
maschigokae Dec 12, 2016
480ca91
Amended the README to mention npm i.
BatemanVO Dec 12, 2016
0ab2204
Refactored bitmap-transformer.js to prevent anticipated merge conflict.
BatemanVO Dec 12, 2016
62c50c9
Merge pull request #5 from BatemanVO/bluescale
maschigokae Dec 12, 2016
7edb5dd
Merge pull request #6 from BatemanVO/comments_and_readme
maschigokae Dec 12, 2016
9e12bc6
added psychedelic transform, 0-out rgb values over 200
maschigokae Dec 13, 2016
f2c6cfd
update cli functionality with psychedelic transform tool
maschigokae Dec 13, 2016
9cfcb62
discard commented-out code
maschigokae Dec 13, 2016
290c7f7
add psychedelic test
maschigokae Dec 13, 2016
6aa8d77
refactor psychedelic transform to start at color table position
maschigokae Dec 13, 2016
6f57281
remove console.log
maschigokae Dec 13, 2016
a30035f
Merge pull request #7 from BatemanVO/psychedelic-transform
BatemanVO Dec 13, 2016
6d5d7f6
Update README.md
BatemanVO Dec 13, 2016
0ed29fc
Update README.md
BatemanVO Dec 13, 2016
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
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Bitmap Transformer
### Written by Hawa Abdi, Steven Bateman, and Caleb Sattgast

The bitmap transformer is a simple Node-based app that will allow you to change the Code Fellows-provided palette-bitmap.bmp file's color table.

### Usage

Clone down this repository, then navigate to the bitmap-steven-hawa-caleb directory in your terminal and run `npm i`.

Transform the image by running `node bitmap-transformer.js` plus any of the four following arguments:
* `invert`
* `grayscale`
* `bluescale`
* `psychedelic`

Each argument passed in will create a copy of the original bitmap with the appropriate transform applied.

### Example

Running `node bitmap-transformer.js grayscale invert` will create a grayScaled-bitmap.bmp and an inverted-bitmap.bmp file in the img directory, found
in the root.
21 changes: 21 additions & 0 deletions bitmap-steven-hawa-caleb/.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"
}
113 changes: 113 additions & 0 deletions bitmap-steven-hawa-caleb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@

# Created by https://www.gitignore.io/api/windows,macos,linux,node

### 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


### 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


### 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*


### 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
34 changes: 34 additions & 0 deletions bitmap-steven-hawa-caleb/bitmap-transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const cliInterpreter = require('./lib/cli-interpreter.js');
const invert = require('./lib/invert-colors.js');
const grayscale = require('./lib/grayscale-colors.js');
const bluescale = require('./lib/bluescale-colors.js');
const psychedelic = require('./lib/psychedelic.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.

@maschigokae @BatemanVO @abdih17 require statements look good, along with the separation of your transform helpers by containing them in a lib directory


const transformArray = cliInterpreter(process.argv);

// Series of if statements checking for the words "invert," "grayscale," and "bluescale". If they were passed in, use the appropriate module method.
if (transformArray.some(function(element) { return element.toLowerCase() === 'invert'; })) {
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.

@maschigokae @BatemanVO @abdih17 great use of the some array method in conjunction with your command line arguments

invert.createInvertedBitmap(function() {
console.log('Inverted colors of palette-bitmap.bmp.');
});
}

if (transformArray.some(function(element) { return element.toLowerCase() === 'grayscale'; })) {
grayscale.createGrayscaleBitmap(function() {
console.log('Grayscale colors of palette-bitmap.bmp.');
});
}

if (transformArray.some(function(element) { return element.toLowerCase() === 'bluescale'; })) {
bluescale.createBlueScaleBMP(function() {
console.log('Blue-scaled the colors of palette-bitmap.bmp.');
});
}

if (transformArray.some(function(element) { return element.toLowerCase() === 'psychedelic'; })) {
psychedelic.createPsychedelicBMP(function() {
console.log('Psyched the colors of palette-bitmap.bmp.');
});
}
22 changes: 22 additions & 0 deletions bitmap-steven-hawa-caleb/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

const gulp = require('gulp');
const linter = 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(linter())
.pipe(linter.format())
.pipe(linter.failAfterError());
});

gulp.task('dev', function() {
gulp.watch(['**/*.js', '!node_modules/**'], ['lint', 'test']);
});

gulp.task('default', ['dev']);
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.

@maschigokae @BatemanVO @abdih17 gulpfile.js looks good

29 changes: 29 additions & 0 deletions bitmap-steven-hawa-caleb/lib/bluescale-colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const fs = require('fs');
const bmp = require(`${__dirname}/../model/bitmap-constructor.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.

@maschigokae @BatemanVO @abdih17 - no need to use __dirname for absolute paths when requiring in a custom module - for custom module require imports, just use the relative path


module.exports = exports = {};

exports.blueScaleColorTable = function(callback) {
fs.readFile(`${__dirname}/../../img/palette-bitmap.bmp`, function(err, data) {
var blueScaleBuffer = Buffer.from(data);
bmp(function(err, data) {
for (var index = 0; index < data.colorTable.length; index += 4) {
var blueAvg = parseInt(blueScaleBuffer[54 + index] + blueScaleBuffer[55 + index] + blueScaleBuffer[56 + index] / 3);
if (blueAvg > 255) blueAvg = 255;
blueScaleBuffer[54 + index] = blueAvg;
}
callback(null, blueScaleBuffer);
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.

@maschigokae @BatemanVO @abdih17 great use of the NodeJS (err, result) callback pattern along with passing in a null value as the error parameter

});
});
};

exports.createBlueScaleBMP = function(callback) {
exports.blueScaleColorTable(function(err, blueScaleBuffer) {
fs.writeFile(`${__dirname}/../../img/bluescale-bitmap.bmp`, blueScaleBuffer, function(err) {
if (err) throw err;
if (callback) callback();
});
});
};
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.

@maschigokae @BatemanVO @abdih17 blueScale module looks good!

8 changes: 8 additions & 0 deletions bitmap-steven-hawa-caleb/lib/cli-interpreter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

// Slices out all elements of the process.argv array that gets passed in after the 1st index, effectively storing all parameters passed in to running
// node bitmap-transformer.js <transforms>
const cliArguments = module.exports = function(args) { //eslint-disable-line
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.

@maschigokae @BatemanVO @abdih17 awesome command line arguments module!

if (args.length < 3) throw new Error('No arguments passed in.');
return args.slice(2, args.length);
};
29 changes: 29 additions & 0 deletions bitmap-steven-hawa-caleb/lib/grayscale-colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const fs = require('fs');

module.exports = exports = {};

//Reading the bitmap image file, and storing the data collected in hex decimal values into the transformedBuffer variable. There are 4 bytes per pixel (RGBA). The transformerBuffer variable is collecting the raw buffer data from each set. In order to find the grayscale value, I looped through every 4 bytes of RGBA set and found the average of the RGB values only- excluding the alpha because it deals with transparency, and storing that into the grayscale variable. Then, I am using the writeUInt8 method ( writeUInt8(value, offset) ) to store the grayscale values and each set (4 bytes) of the collected buffer data. Lastly, we are writing the new values into the bitmap image file I created called ../img/grayscale-bitmap.bmp.
exports.grayscaleTransform = function(callback) {
fs.readFile(`${__dirname}/../../img/palette-bitmap.bmp`, function(err, data) {
var transformedBuffer = Buffer.from(data);
var grayValue;
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.

@maschigokae @BatemanVO @abdih17 good use of a var declaration for later assignment

for (var i = 54; i < 1078; i+=4) {
grayValue = (transformedBuffer.readUInt8(i) + transformedBuffer.readUInt8(i+1) + transformedBuffer.readUInt8(i+2))/3;
transformedBuffer.writeUInt8(grayValue, i);
transformedBuffer.writeUInt8(grayValue, i+1);
transformedBuffer.writeUInt8(grayValue, i+2);
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.

@maschigokae @BatemanVO @abdih17 great use of the readUInt8 and writeUInt8 buffer methods

}
callback(null, transformedBuffer);
});
};

exports.createGrayscaleBitmap = function(callback) {
exports.grayscaleTransform(function(err, transformedBuffer) {
fs.writeFile(`${__dirname}/../../img/grayscale-bitmap.bmp`, transformedBuffer, function(err) {
if (err) throw err;
if (callback) callback();
});
});
};
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.

@maschigokae @BatemanVO @abdih17 grayscale module looks good - good use of the module.exports = exports = {} pattern for multiple method exports

31 changes: 31 additions & 0 deletions bitmap-steven-hawa-caleb/lib/invert-colors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const fs = require('fs');
const bmp = require(`${__dirname}/../model/bitmap-constructor.js`);

module.exports = exports = {};

// Reads the buffer from the original image, stores a copy of it as invertedBuffer, then changes each value in the color table to be 255 minus
// its original value. It then calls the callback function passed in, returning null for errors and the new, rewritten buffer.
exports.invertColorTable = function(callback) {
fs.readFile(`${__dirname}/../../img/palette-bitmap.bmp`, function(err, data) {
if (err) throw err;
var invertedBuffer = Buffer.from(data);
bmp(function(err, data) {
for (var i = 0; i < data.colorTable.length; i++) {
invertedBuffer[54 + i] = 255 - data.colorTable[i];
}
callback(null, invertedBuffer);
});
});
};
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.

@maschigokae @BatemanVO @abdih17 invertColorTable methods looks good


// Performs a writeFile, creating a file called inverted-bitmap.bmp, using the invertedBuffer created from the invertColorTable method.
exports.createInvertedBitmap = function(callback) {
exports.invertColorTable(function(err, invertedBuffer) {
fs.writeFile(`${__dirname}/../../img/inverted-bitmap.bmp`, invertedBuffer, function(err) {
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.

@maschigokae @BatemanVO @abdih17 nice use of passing your invertedBuffer, as a variable, into the writeFile method

if (err) throw err;
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.

@maschigokae @BatemanVO @abdih17 good error handling

if (callback) callback();
});
});
};
29 changes: 29 additions & 0 deletions bitmap-steven-hawa-caleb/lib/psychedelic.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const fs = require('fs');
const bmp = require(`${__dirname}/../model/bitmap-constructor.js`);

module.exports = exports = {};

exports.psychedelicTransform = function(callback) {
fs.readFile(`${__dirname}/../../img/palette-bitmap.bmp`, function(err, data) {
var psychedelicBuffer = Buffer.from(data);
bmp(function(err, data) {
for (var index = 0; index < data.colorTable.length; index += 1) {
if (psychedelicBuffer[54 + index] > 200) {
psychedelicBuffer[54 + index] = 0;
}
}
callback(null, psychedelicBuffer);
});
});
};

exports.createPsychedelicBMP = function(callback) {
exports.psychedelicTransform(function(err, psychedelicBuffer) {
fs.writeFile(`${__dirname}/../../img/psychedelic-bitmap.bmp`, psychedelicBuffer, function(err) {
if (err) throw err;
if (callback) callback();
});
});
};
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.

@maschigokae @BatemanVO @abdih17 psychedlic transform module looks good

27 changes: 27 additions & 0 deletions bitmap-steven-hawa-caleb/model/bitmap-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

const fs = require('fs');

// CreateBmp will read the palette-bitmap.bmp file, then create a colorTable array of the 1024 bytes that represent the bitmap file's color table.
// The color table is found by starting the offset after the bitmap file header and the DIB header.
// The bitmap file header is always 14 bytes.
// This particular bitmap file header identifies the file type as BM, which means the DIB header corresponds to Windows 3.1x, 95, NT, etc.
// This makes it a DIB Header with the name BITMAPINFOHEADER, which has a size of 40 bytes.
// We can double check our DIB Header size using the buffer method readInt32LE(14), which will read the signed integer 14 bytes in (where the DIB header starts).
// So, the bitmap file header and the DIB header are a combined total of 54 bytes, so our color table should start at the 54th position of our buffer.
// We know where the color table ends because the pixel array immediately follows the color table, and the pixel array can be found 10 bytes in to
// the bitmap file header using the buffer method readInt32LE(10), which will read the signed integer 10 bytes in.
// We get back the value 1078, so we know the pixel array begins at the 1078th location.
// We can double check that our colorTable is the correct size by checking how many colors this bitmap file is expected to have.
// The DIB BITMAPINFOHEADER contains this information at an offset of 46 bytes, so if we use the buffer method readInt32LE(46), we get back a value
// of 256, meaning this bitmap file has 256 colors.
// Since each color is 4 bytes, we would expect a color table to be (256 x 4 = 1024) bytes in size. This matches our expected range of 54 bytes to 1078
// bytes (1078 - 54 = 1024), so we can be sure we have correctly selected the color table from our buffer.
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.

@maschigokae @BatemanVO @abdih17 - fantastic comments!

const createBmp = module.exports = function(callback) { //eslint-disable-line
const bmp = {};
fs.readFile(`${__dirname}/../../img/palette-bitmap.bmp`, function(err, data) {
if (err) throw err;
bmp.colorTable = data.slice(54, 1078);
return callback(null, bmp);
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.

@maschigokae @BatemanVO @abdih17 good callback pattern here

});
};
Loading