Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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/*
26 changes: 26 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}
145 changes: 145 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# 401 JS
db
.env
temp
build

# Created by https://www.gitignore.io/api/vim,osx,node,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*

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

### 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/vim,osx,node,linux,windows
78 changes: 8 additions & 70 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,72 +1,10 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 04: Bitmap Transformer
===
## Lab 5 - Bitmap Converter

## Submission Instructions
* Work in a fork of this repository
* Work in a branch on your fork
* Write all of your code in a directory named `lab-` + `<your name>` **e.g.** `lab-susan`
* Open a pull request to this repository
* Submit on canvas a question and observation, how long you spent, and a link to your pull request
## Description of functionality
We have 4 modules that meet up at 'index.js'. Index goes to 'infile.js' which has an airity of 3 and connects with 'transforms.js'. 'transforms.js' contains modules that have the function to make the image become whiteout, blackout, manipulate noise, and turn the file inverted. The results are sent to the 'outfile.js' file which writes out the file and makes the new image with the new data. 'buffer.js' uses readUInt32LE to allow us the mechanism for reading and manipulating our streams of binary data.

## Resources
* [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format)
* [Buffer Docs](https://nodejs.org/api/buffer.html)

## Configuration
Configure the root of your repository with the following files and directories. Thoughfully name and organize any aditional configuration or module files.
* **README.md** - contains documentation
* **.gitignore** - contains a [robust](http://gitignore.io) `.gitignore` file
* **.eslintrc** - contains the course linter configuratoin
* **.eslintignore** - contains the course linter ignore configuration
* **package.json** - contains npm package config
* create a `lint` script for running eslint
* create a `test` script for running tests
* **lib/** - contains module definitions
* **\_\_test\_\_/asset/** - contains bitmaps for testing
* **\_\_test\_\_/** - contains unit tests

## Feature Tasks
For this assignment you will be building a bitmap (`.bmp`) transformer CLI. It will read a bitmap in from disk, run one or more color or raster transforms 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 solution should be composed of small tested modules that solve specific problems. Your modules should be thoughfuly named and well documented. The entry point to your CLI should be an index.js file in the root of your package, and all helper modules should be placed in your lib/ directory. Your bitmap transformer modules should not use any third party librarys.

#### Minimum Requirements
* The CLI should be architected using best modularization practices
* The CLI should require at least three arguments `input-file-path output-file-path transfrom-name`
* The CLI should support a minimum of four transforms
* The CLI should log useful Error messages if used incorrectly
* The CLI should log a success message on completion

## Testing
* Use BDD `describe` and `test` methods to define discriptive tests and increase readablity
* Each `test` callback should aim to test a small well defined feature of a function
* Write tests to ensure each function behaves correctly with valid and invalud inputs
* The CLI should be tested without using `child_process` or any equivilant third party librarys

## Documentation
In your README.md describe the exported values of each module you have defined. Every function description should include it's airty (expected number of paramiters), the expected data for each paramiter (data-type and limitations), and it's behavior (for both valid and invalued use). Feel free to write any additional information in your README.md.

## Tips
You will want to define a strategy for solving the problem before you begin to code. Once you have a strategy defined, you can break it into steps that can be split into helper modules. Each helper module should solve a small specific problem. The main module should utilize the helper modules to execute your original stratagy.

###### Example Stragegy
0. Gather user input (infile, outfile, and transform)
0. Read the input bitmap file using the fs module
0. Parse the bitmap's buffer into object represeting a bitmap (using a constructor)
0. Using metadata from the parsed bitmap object run a transform on the buffer directly (mutate the color or raster data)
0. Write the mutated buffer to the output file path

###### Transfrom Ideas
* Color Pallet Transforms
* Invert
* Randomize
* Black and White
* Darken or Lighten
* Add or Mutiply a Hue
* Add or Subtract Contrast

* Raster Data Transforms
* Pixilate
* Add a border
* Add a watermark
* Vertically or Horizontaly Filp
* Verticaly or Horizontaly Mirror
* Verticaly or Horizontaly Stretch
Example terminal commands:
node index.js ./__test__/asset/house.bmp ./__test__/asset/house_new.bmp whiteout
node index.js ./__test__/asset/house.bmp ./__test__/asset/house_new.bmp blackout
node index.js ./__test__/asset/house.bmp ./__test__/asset/house_new.bmp invert
node index.js ./__test__/asset/house.bmp ./__test__/asset/house_new.bmp noise
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added __test__/asset/house_new.bmp
Binary file not shown.
Binary file added __test__/asset/new_finger.bmp
Binary file not shown.
File renamed without changes.
5 changes: 5 additions & 0 deletions __test__/asset/test.bmp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
(err, data) => {
expect(err).toBeNull();
//expect.stringContaining('The file has been saved!')
done();
}
26 changes: 26 additions & 0 deletions __test__/buffer.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict'

const infile= require('../lib/infile.js');

describe('Buffer', () => {
test('buffer should return an object with correct data for house.bmp.', (done) => {
infile(`${__dirname}/asset/house.bmp`, (err, data) => {
expect(err).toBeNull();
expect(data.type).toEqual('BM');
expect(data.sizeInBytes).toEqual(66616);
expect(data.pixelArrayOffset).toEqual(1078);
expect(data.sizeOfHeader).toEqual(40);
expect(data.widthInPixels).toEqual(256);
expect(data.heightInPixels).toEqual(256);
expect(data.colorPlanes).toEqual(1);
expect(data.bitsPerPixel).toEqual(8);
expect(data.compressionMethod).toEqual(0);
expect(data.imageSize).toEqual(0);
expect(data.horizontalResolution).toEqual(2834);
expect(data.verticalResolution).toEqual(2834);
expect(data.numColorsInColorPalette).toEqual(0);
expect(data.numImportantColors).toEqual(0);
done();
});
});
});
21 changes: 21 additions & 0 deletions __test__/infile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const infile = require('../lib/infile.js')

describe('infile', () => {
test('an invalid path should reject an error', (done) => {
infile(`${__dirname}/asset/foo.bmp`, (err, data) => {
expect(err).not.toBeNull();
expect(data).toBeUndefined();
done();
})
})

test('a valid path should resolve data', (done) => {
infile(`${__dirname}/../__test__/asset/house.bmp`, (err, data) => {
expect(err).toBeNull();
expect(data).toBeDefined();
done();
})
})
})
21 changes: 21 additions & 0 deletions __test__/outfile.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
'use strict'

const outfile = require('../lib/outfile.js')

describe('outfile', () => {
test('an invalid path should reject an error', (done) => {
outfile(`${__dirname}/asset/foo.bmp`, (err, data) => {
expect(err).not.toBeNull();
expect(data).toBeUndefined();
done();
})
})

test('a valid path should resolve data', (done) => {
outfile(`${__dirname}/../asset/house.bmp`, (err, data) => {
expect(err).toBeNull();
expect(data).toEqual(null);
done();
})
})
})
19 changes: 19 additions & 0 deletions __test__/transforms.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict'

const fs = require('fs')

const transforms = require('../lib/transforms.js');

const bitmap_whiteout = fs.readFileSync(`${__dirname}/asset/house_new.bmp`);

describe('transform', () => {
test('whiteout', (done) => {
fs.readFile(`${__dirname}/asset/house.bmp`, function(err, data) {
if (err) throw err;
let old_colorTable = data.buffer.slice(41, 1065);
let new_colorTable = bitmap_whiteout.slice(41, 1065);
expect(old_colorTable).not.toEqual(new_colorTable);
done();
});
});
});
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict'

const infile = require('./lib/infile.js');
const transforms = require('./lib/transforms.js');

if (process.argv[2] && process.argv[3] && process.argv[4]) {
let infilename = process.argv[2];
let outfilename = process.argv[3];
let transform = process.argv[4];
infile(infilename, transforms[transform], outfilename);
} else {
console.log('USAGE ERROR: infile, outfile, and transform arguments required');
}
19 changes: 19 additions & 0 deletions lib/buffer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
'use strict';

module.exports = function(data) {
this.buffer = data;
this.type = data.toString('utf8', 0, 2);
this.sizeInBytes = data.readUInt32LE(2);
this.pixelArrayOffset = data.readUInt32LE(10);
this.sizeOfHeader = data.readUInt32LE(14);
this.widthInPixels = data.readUInt32LE(18);
this.heightInPixels = data.readUInt32LE(22);
this.colorPlanes = data.readUInt16LE(26);
this.bitsPerPixel = data.readUInt16LE(28);
this.compressionMethod = data.readUInt16LE(30);
this.imageSize = data.readUInt32LE(34);
this.horizontalResolution = data.readUInt32LE(38);
this.verticalResolution = data.readUInt32LE(42);
this.numColorsInColorPalette = data.readUInt32LE(46);
this.numImportantColors = data.readUInt32LE(50);
}
Loading