Skip to content
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

lab-04-allan-andy-jonah #10

Open
wants to merge 40 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
7cfa3c3
Adds Process Files
ohjonah Jul 20, 2017
b67cdc4
Adds Package.JSON
ohjonah Jul 20, 2017
ac5cb3f
Adds Tree Structure and Files
ohjonah Jul 20, 2017
a0e90ce
Merge pull request #1 from ohjonah/features/scaffold
ohjonah Jul 20, 2017
ce2f436
Adds Tests
ohjonah Jul 21, 2017
4e948de
Adds BM File Reader Tests and Reader
ohjonah Jul 21, 2017
ade922f
Merge pull request #2 from ohjonah/features/tests
ohjonah Jul 21, 2017
980738b
added mocha to package.json script
allanliebold Jul 21, 2017
417af66
creates bitmap object constructor
allanliebold Jul 21, 2017
07e8ef6
added transformer files, tribute lou reed, input is 'colorArrayText'
andyfiveeleven Jul 21, 2017
a7d3ebb
adds properties to bitmap object constructor for color and pixel arrays.
allanliebold Jul 21, 2017
782eb6e
Merge pull request #3 from ohjonah/features/transformers
ohjonah Jul 21, 2017
ffa378e
Merge pull request #4 from ohjonah/features/constructor-test
ohjonah Jul 21, 2017
671ce8b
By The Power of GreySkale
ohjonah Jul 22, 2017
9b7c6ee
ITS WORKINGGGGGGG ITS WORKINGGGGG
ohjonah Jul 22, 2017
11a672d
it may be working
ohjonah Jul 22, 2017
7d54446
I'll Try Inverting, that's a good trick
ohjonah Jul 22, 2017
2231748
Cleans up Code
ohjonah Jul 22, 2017
e4191ca
Merge pull request #5 from ohjonah/features/bitmap-transform-add-in
ohjonah Jul 23, 2017
98a680c
Mob Programming to Write File
ohjonah Jul 23, 2017
8cff556
Troubleshooting Writing
ohjonah Jul 23, 2017
60927da
Merge pull request #6 from ohjonah/features/write-to-bmp
andyfiveeleven Jul 23, 2017
064c717
Buffer.From
ohjonah Jul 23, 2017
e10e4e2
Troubleshoots Transformers: Soln
ohjonah Jul 24, 2017
f8d7f7c
Removes Corpse Code
ohjonah Jul 24, 2017
2823012
Cleans up Code
ohjonah Jul 24, 2017
a55b2b0
Merge pull request #7 from ohjonah/features/write-to-bmp
allanliebold Jul 24, 2017
1077764
adds red transform
allanliebold Jul 24, 2017
53779aa
Merge pull request #8 from ohjonah/features/extra
ohjonah Jul 24, 2017
a13b719
real readme present, instructions on how to run our file
andyfiveeleven Jul 24, 2017
887b9c5
i made a color test
andyfiveeleven Jul 24, 2017
b0d3fe2
adds greyscale transform test
allanliebold Jul 24, 2017
372649d
reverse test
andyfiveeleven Jul 24, 2017
1bd033d
Refactors Constructor and Helper Tests for Test Cases
ohjonah Jul 24, 2017
535aa05
Merge pull request #9 from ohjonah/features/allans-test
ohjonah Jul 24, 2017
7aa5f64
Merge branch 'master' into features/transform-tests
ohjonah Jul 24, 2017
38bb1cb
Merge pull request #11 from ohjonah/andys-tests
ohjonah Jul 24, 2017
c304491
Merge branch 'master' into features/transform-tests
ohjonah Jul 24, 2017
c78fdd0
Cleans Up Code
ohjonah Jul 24, 2017
3288fff
Merge pull request #10 from ohjonah/features/transform-tests
allanliebold Jul 24, 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
5 changes: 5 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
23 changes: 23 additions & 0 deletions .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"
}
128 changes: 128 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@

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

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

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


### 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/node,macos,linux,windows
68 changes: 11 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,15 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 04: Bitmap Transformer
===
# Bitmap Transformer

## To Submit this Assignment
* have team leader fork this repository
* have team leader add team members as collaborators to the team fork
* team members should clone team fork
* write all of your code in a directory name `bitmap-` + `<team name>` **e.g.** `bitmap-weasels`
* submit a pull request to this repository when done
* each person will submit a link to their own PR in canvas
* each person write a question and observation on canvas
This application takes a bit map image and applies four transformations to it, creating four additional files in the assets directory.

## Learning Objectives
* students will be able to manipulate binary data using the node.js `Buffer` class
* students will be able to architect modular solutions to solving problems
- Greyscale
- Infared
- Inverted Color
- Reversed (a flipped image)

## Resources
* [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format)
* [NodeJS Buffer docs](https://nodejs.org/api/buffer.html)
# Run it!

#### Feature Tasks

For this assignment you will be building a bitmap (`.bmp`) reader and transformer. It will read a bitmap in from disk, run one or more color transforms on the bitmap and then write it out to a new file. This project will require the use of node buffers in order to manipulate binary data. Your project should include tests, as well as a `package.json`, `.eslintrc`, `README.md`, and a `.gitignore`. Make sure to run all your code through eslint. The process will look something like this:

1. open the original bitmap file using fs and read it into a buffer
2. convert the buffer header data into a Javascript Object (using constructors)
3. run a transform on the buffer directly
4. write the buffer to a new file

The wikipedia article found here [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format) describes the byte specification of a "windows bitmap file." We'll be working with the simplest version, meaning no compression.

* your project should have three ***(or more)*** transforms
* invert the colors (***hint:*** subtract every color value from the max color value which is 255),
* grayscale the colors (***hint:*** multiply each color value by a constant, just make sure your values don't go over 255)
* (red|green|blue)scale the colors (***hint:*** same as above but only multiply one of the colors)

#### Bonus:
* ability to handle various sized bitmap
* ability to handle LE and BE computers with a single if statement
* utilizes a command line interface (CLI)
* CLI can select the transforms

#### Suggested Directory Structure (this is optional):
* suggested directory structure:
- **index.js**
- **lib**
- bitmap file helper
- **model**
- bitmap constructor
- color constructor
- **test**
- bitmap file helper test
- bitmap constructor test
- color constructor test

#### Rubric:
* **tests:** 3pts
* **package.json:** 2pts
* **read bitmap meta data:** 5pts
* **successfully apply transforms:** 5pts
* **project design and organization:** 5pts
- open the file in the terminal
- navigate to the Lib directory
- run the command node bitmap-file-helper.js
- At this point you'll have 4 new files in your assets directory.
Binary file added assets/greyscaled.bmp
Binary file not shown.
Binary file added assets/infrared.bmp
Binary file not shown.
Binary file added assets/inverted.bmp
Binary file not shown.
Binary file added assets/reversed.bmp
Binary file not shown.
42 changes: 42 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

const bitmapFileHelper = require(`${__dirname}/lib/bitmap-file-helper.js`);
const bitmapConstructor = require(`${__dirname}/model/bitmap-constructor.js`);
const greyScaleTransform = require(`${__dirname}/lib/grey-scale-transform.js`);
const reverseTransform = require(`${__dirname}/lib/reverse-transform.js`);
const invertTransform = require(`${__dirname}/lib/invert-transform.js`);
const infraredTransform = require(`${__dirname}/lib/infrared-transform.js`);


bitmapFileHelper(`${__dirname}/assets/palette-bitmap.bmp`, function(err, data) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These function calls could be handled modularly in fileHelper. That would allow you to test your whole writing file path easier.

if(err) throw err;
let bmp = new bitmapConstructor.Bitmap(data);

bmp.colorArr = greyScaleTransform(bmp.colorArr);
bmp.newFile('greyscaled');
});

bitmapFileHelper(`${__dirname}/assets/palette-bitmap.bmp`, function(err, data) {
if(err) throw err;
let bmp = new bitmapConstructor.Bitmap(data);

bmp.pixelArr = reverseTransform(bmp.pixelArr);
bmp.newFile('reversed');
});


bitmapFileHelper(`${__dirname}/assets/palette-bitmap.bmp`, function(err, data) {
if(err) throw err;
let bmp = new bitmapConstructor.Bitmap(data);

bmp.colorArr = invertTransform(bmp.colorArr);
bmp.newFile('inverted');
});

bitmapFileHelper(`${__dirname}/assets/palette-bitmap.bmp`, function(err, data) {
if(err) throw err;
let bmp = new bitmapConstructor.Bitmap(data);

bmp.colorArr = infraredTransform(bmp.colorArr);
bmp.newFile('infrared');
});
10 changes: 10 additions & 0 deletions lib/bitmap-file-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use strict';

const fs = require('fs');

const bitmapFileHelper = module.exports = function(file, callback) {
fs.readFile(file, function(err, data) {
if (err) return callback(err);
return callback(null, data);
});
};
27 changes: 27 additions & 0 deletions lib/grey-scale-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

module.exports = exports = function greyScale(colorArrayText) {
let colorArray = colorArrayText.match(/.{1,8}/g);
let greyArray = [];

colorArray.forEach(function(n) {
let pairsArray = n.match(/.{1,2}/g);
let b = parseInt(pairsArray[0],16); //hex value to decimal value;
let g = parseInt(pairsArray[1],16);
let r = parseInt(pairsArray[2],16);
var avg = Math.floor((Math.max(r,g,b) + Math.min(r,g,b)) / 2);
pairsArray[0] = avg.toString(16);
pairsArray[1] = avg.toString(16);
pairsArray[2] = avg.toString(16);
pairsArray.forEach(function(value, i){
if(value.length === 1){
pairsArray[i] = '0' + pairsArray[i];
}
});
let greyHex = pairsArray.join('');
greyArray.push(greyHex);
});

let greyColorArrayText = greyArray.join('');
return greyColorArrayText;
};
27 changes: 27 additions & 0 deletions lib/infrared-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

module.exports = exports = function greyScale(colorArrayText) {
let colorArray = colorArrayText.match(/.{1,8}/g);
let greyArray = [];

colorArray.forEach(function(n) {
let pairsArray = n.match(/.{1,2}/g);
let b = parseInt(pairsArray[0],16); //hex value to decimal value;
let g = parseInt(pairsArray[1],16);
let r = parseInt(pairsArray[2],16);
var avg = Math.floor((Math.max(r,g,b) + Math.min(r,g,b)) / 2);
pairsArray[0] = avg.toString(16);
pairsArray[1] = avg.toString(16);
pairsArray[2] = (255).toString(16);
pairsArray.forEach(function(value, i){
if(value.length === 1){
pairsArray[i] = '0' + pairsArray[i];
}
});
let greyHex = pairsArray.join('');
greyArray.push(greyHex);
});

let greyColorArrayText = greyArray.join('');
return greyColorArrayText;
};
28 changes: 28 additions & 0 deletions lib/invert-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
'use strict';

module.exports = exports = function invertColor(colorArrayText){
let colorArray = colorArrayText.match(/.{1,8}/g);
let invertedColorArray = [];

colorArray.forEach(function(n) {
let invertArray = [];
let pairsArray = n.match(/.{1,2}/g);
let b = parseInt(pairsArray[0],16); //hex value to decimal value;
let g = parseInt(pairsArray[1],16);
let r = parseInt(pairsArray[2],16);
let bInvert = (255-b).toString(16); // invert ;
let gInvert = (255-g).toString(16);
let rInvert = (255-r).toString(16);

invertArray.push(bInvert, gInvert, rInvert, '00');
invertArray.forEach(function(value, i){
if(value.length === 1){
invertArray[i] = '0'+invertArray[i];
}
});
invertedColorArray.push(invertArray.join(''));
});

let invertedColorString = invertedColorArray.join('');
return invertedColorString;
};
8 changes: 8 additions & 0 deletions lib/reverse-transform.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';

module.exports = exports = function reverser(pixelArrayText) {
let pixelArray = pixelArrayText.match(/.{1,2}/g);
let reversed = pixelArray.reverse().join('');

return reversed;
};
Loading