Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
a5afca8
scaffolding
ncarignan Nov 30, 2017
d9e0ad6
rescaffolded
ncarignan Nov 30, 2017
2db831b
finished scaffolding
ncarignan Nov 30, 2017
0399af6
parser test green
ncarignan Dec 1, 2017
7f5c6f1
wrote test for chaos
ncarignan Dec 1, 2017
9739152
Merge pull request #1 from ncarignan/nicholas-seth
ncarignan Dec 1, 2017
adb28b9
found color table?!
SethDonohue Dec 1, 2017
b887241
Merge pull request #2 from ncarignan/seth-nicholas
ncarignan Dec 1, 2017
1acdcdd
stuff
ncarignan Dec 1, 2017
f8ef779
closer...
SethDonohue Dec 2, 2017
7bfe115
colors write
ncarignan Dec 2, 2017
a4d2465
greyscale works
ncarignan Dec 2, 2017
80426a9
more filepaths
ncarignan Dec 2, 2017
104b900
greyscale is working recursively
ncarignan Dec 2, 2017
83eb06f
Merge pull request #3 from ncarignan/nicholas-seth
ncarignan Dec 2, 2017
9d5c011
chaos works
ncarignan Dec 2, 2017
7454011
can now pass in paths, names etc
ncarignan Dec 2, 2017
a16a94b
added invert function
SethDonohue Dec 2, 2017
60f904e
Merge pull request #4 from ncarignan/seth-nicholas
ncarignan Dec 2, 2017
a39a540
deletions
ncarignan Dec 2, 2017
e7ec735
Delete bitmap-test.bmp
ncarignan Dec 2, 2017
f0faa3c
Delete house-test.bmp
ncarignan Dec 2, 2017
7a43563
Delete finger-print-test.bmp
ncarignan Dec 2, 2017
ddf7dbc
Delete non-palette-bitmap-test.bmp
ncarignan Dec 2, 2017
f0fb13e
Merge branch 'master' into nicholas-seth2
ncarignan Dec 2, 2017
8b6ffdf
Merge pull request #6 from ncarignan/nicholas-seth2
ncarignan Dec 2, 2017
e33d783
first test working
SethDonohue Dec 3, 2017
6efe76d
node test removed
ncarignan Dec 3, 2017
2edfb35
four descriptive, beautiful, green, sexcessful tests
ncarignan Dec 3, 2017
2e1eb3e
moved all files to lab-nicholas-seth folder
SethDonohue Dec 3, 2017
e44a36e
added readmme and deleted duplicat readme
SethDonohue Dec 3, 2017
45d99c0
changed file order, added Readme, merged branches for proper PR
SethDonohue Dec 3, 2017
a831b03
three new error tests added
ncarignan Dec 4, 2017
8364ebf
three new error tests added
ncarignan Dec 4, 2017
8e6c632
deleted dump folder
ncarignan Dec 4, 2017
be4a2a2
deleted bmps
ncarignan Dec 4, 2017
834e60a
Merge pull request #8 from ncarignan/nicholas-seth5
ncarignan Dec 4, 2017
5a3693c
added CLI interface with process.argv
SethDonohue Dec 5, 2017
55e5a8c
added CLI interface with process.argv
SethDonohue Dec 5, 2017
7266f71
added CLI interface with process.argv with merge
SethDonohue Dec 5, 2017
f29f87a
code cleanup
SethDonohue Dec 5, 2017
d9f64ac
updated README with commands to run in CLI for proper image transform
SethDonohue Dec 6, 2017
39fa022
removed ghost codes
SethDonohue Dec 6, 2017
ab6cad3
removed a comment or two
ncarignan Dec 6, 2017
12228ab
removed line 53 indedx
ncarignan Dec 20, 2017
e92c407
deleting line 53 again?
ncarignan Dec 20, 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/*
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" ]
}
}
82 changes: 82 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@

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

### Linux ###
*~

#bitmpa tests
__test__/dump/
# 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


# End of https://www.gitignore.io/api/node,linux
96 changes: 41 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,66 +1,52 @@
![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 04: Bitmap Transformer
===
In your README.md describe the exported values of each module you have defined. Every function description should include it's arity (expected number of paramiters), the expected data for each parameter (data-type and limitations), and it's behavior (for both valid and invalid use). Feel free to write any additional information in your README.md.

## 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
## Commands to run to convert images
In the terminal run the following command to convert an image:
```
node index.js <input path> <output path> <transform name>
```

## Resources
* [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format)
* [Buffer Docs](https://nodejs.org/api/buffer.html)
Examples:
```
node index.js __test__/assets/bitmap.bmp __test__/dump/bitmap-chaos.bmp chaos

## 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.json** - 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\_\_/assets/** - contains bitmaps for testing
* **\_\_test\_\_/** - contains unit tests
node index.js __test__/assets/bitmap.bmp __test__/dump/bitmap-invert.bmp invert

## Feature Tasks
For this assignment you will be building a bitmap (`.bmp`) transformer CLI. It will read a bitmap in from the hardrive(assets folder), run one or more color 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 thoughtfully 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 libraries.
node index.js __test__/assets/bitmap.bmp __test__/dump/bitmap-greyscale.bmp greyscale
```

#### 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 three transforms
* The CLI should log useful Error messages if used incorrectly
* The CLI should log a success message on completion

## Testing
* Use TDD `describe` and `test` methods to define descriptive 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 invalid inputs
* The CLI should be tested without using `child_process` or any equivilant third party libraries
## bitmapper:
airity: 4, inputPaths(array), outputPaths(array), transformName(string), callback
## Contains:
## writer:
A recursive function that takes in file paths for file locations, file paths for the where the files should be ouput and the type of transformation the user wants to complete on the bmp image.

## Documentation
In your README.md describe the exported values of each module you have defined. Every function description should include it's arity (expected number of paramiters), the expected data for each parameter (data-type and limitations), and it's behavior (for both valid and invalid use). Feel free to write any additional information in your README.md.
### limitations:
only useful in the CLI, but filepaths and transform name have to be changed in the JS file.Does not work with a bmp image that does not have a color table yet :/

### behavior:
throws general built in errors to the fs modules, but also makes sure that filepaths are not bad paths.

### Writer calls:
1. parseFilesRecursively which uses fs.readFile, which uses bitmap.parsedBitmap to parses the bmp images to create buffers for proper editing. These are then pushed into a results array.
2. Once the inputpaths array is empty the transform function is called and uses the results array and outputPaths to modify the buffer for each file.
3. Each transform writes it's own files to the outputh path that is passed to it.

## parseFilesRecursively:
airity 0

## fs.readFile:
airity 2, filepaths (string), callback

## 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 down 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 strategy.
## bitmap.parsedBitmap:
airity 1, data(buffer), constructor, return object

###### Example Strategy
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 representing a bitmap (using a constructor)
0. Using metadata from the parsed bitmap object to run a transform on the buffer directly (mutate the colors)
0. Write the mutated buffer to the output file path
## invert.invert:
airity 3, objectArray(array), outputPaths(array), callback

###### Transfrom Ideas
* Color Palette Transforms
* Invert
* Randomize
* Greyscale
* Black and White
* Darken or Lighten
* Add or Mutiply a Hue
* Add or Subtract Contrast
## greyscale.greyscale:
airity 3, objectArray(array), outputPaths(array), callback

## chaos.chaosp:
airity 3, objectArray(array), outputPaths(array), callback
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
154 changes: 154 additions & 0 deletions __test__/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
'use strict';

const bitmapper = require('../index');
const chaos = require('../lib/chaos');

describe('index.js', () =>{
describe('bitmapper.writer', () => {
test('chaos.chaos should create 3 files with transformations and changed file name', done => {
let inputPaths = [
`${__dirname}/assets/bitmap.bmp`,
`${__dirname}/assets/finger-print.bmp`,
`${__dirname}/assets/house.bmp`,
];
let transformName = 'chaos';

let outputPaths = [
`${__dirname}/../__test__/dump/bitmap-${transformName}.bmp`,
`${__dirname}/../__test__//dump/finger-print-${transformName}.bmp`,
`${__dirname}/../__test__/dump/house-${transformName}.bmp`,
`${__dirname}/../__test__/dump/non-palette-bitmap-${transformName}.bmp`,
];

bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(data[0].buffer).not.toBeNull();
expect(data[1].buffer).not.toBeNull();
expect(data[2].buffer).not.toBeNull();
done();
});
});
test('greyscale.greyscale should create 3 files with transformations and changed file name', done => {
let inputPaths = [
`${__dirname}/assets/bitmap.bmp`,
`${__dirname}/assets/finger-print.bmp`,
`${__dirname}/assets/house.bmp`,
];

let transformName = 'greyscale';
let outputPaths = [
`${__dirname}/../__test__/dump/bitmap-${transformName}.bmp`,
`${__dirname}/../__test__//dump/finger-print-${transformName}.bmp`,
`${__dirname}/../__test__/dump/house-${transformName}.bmp`,
`${__dirname}/../__test__/dump/non-palette-bitmap-${transformName}.bmp`,
];

bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(data[0].buffer).not.toBeNull();
expect(data[1].buffer).not.toBeNull();
expect(data[2].buffer).not.toBeNull();
done();
});
});
test('invert.invert should create 3 files with transformations and changed file name', done => {
let inputPaths = [
`${__dirname}/assets/bitmap.bmp`,
`${__dirname}/assets/finger-print.bmp`,
`${__dirname}/assets/house.bmp`,
];

let transformName = 'invert';
let outputPaths = [
`${__dirname}/../__test__/dump/bitmap-${transformName}.bmp`,
`${__dirname}/../__test__//dump/finger-print-${transformName}.bmp`,
`${__dirname}/../__test__/dump/house-${transformName}.bmp`,
`${__dirname}/../__test__/dump/non-palette-bitmap-${transformName}.bmp`,
];

bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(data[0].buffer).not.toBeNull();
expect(data[1].buffer).not.toBeNull();
expect(data[2].buffer).not.toBeNull();
done();
});
});
test('should return error callback if a filepath is bad', done => {
let inputPaths = [
`${__dirname}/assets/bitmapp.bmp`,
`${__dirname}/assets/finger-print.bmp`,
`${__dirname}/assets/house.bmp`,
];

let transformName = 'invert';
let outputPaths = [
`${__dirname}/../__test__/dump/bitmap-${transformName}.bmp`,
`${__dirname}/../__test__//dump/finger-print-${transformName}.bmp`,
`${__dirname}/../__test__/dump/house-${transformName}.bmp`,
`${__dirname}/../__test__/dump/non-palette-bitmap-${transformName}.bmp`,
];

bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(error).not.toBeNull();
done();
});
});

test('should throw error if inputPats is not array', done => {
let inputPaths = 'incorrect inputPaths';

let transformName = 'invert';
let outputPaths = [
`${__dirname}/../__test__/dump/bitmap-${transformName}.bmp`,
`${__dirname}/../__test__//dump/finger-print-${transformName}.bmp`,
`${__dirname}/../__test__/dump/house-${transformName}.bmp`,
`${__dirname}/../__test__/dump/non-palette-bitmap-${transformName}.bmp`,
];

expect(() => {bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(error).toBe('inputPaths must be an array of strings');
expect(data).toBe('incorrect inputPaths');
done();
});}).toThrow();
});

test('should throw error if outputPats is not array', done => {
let inputPaths = [
`${__dirname}/assets/bitmapp.bmp`,
`${__dirname}/assets/finger-print.bmp`,
`${__dirname}/assets/house.bmp`,
];

let transformName = 'invert';
let outputPaths = 'incorrect outputPaths';

expect(() => {bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(error).toBe('outputPaths must be an array of strings');
expect(data).toBe('incorrect outputPaths');
done();
});}).toThrow();
});

test('should throw error if transformName is not a string', done => {
let inputPaths = [
`${__dirname}/assets/bitmapp.bmp`,
`${__dirname}/assets/finger-print.bmp`,
`${__dirname}/assets/house.bmp`,
];

let transformName = () => {
console.log('i am not a string');
};
let outputPaths = [
`${__dirname}/../__test__/dump/bitmap-${transformName}.bmp`,
`${__dirname}/../__test__//dump/finger-print-${transformName}.bmp`,
`${__dirname}/../__test__/dump/house-${transformName}.bmp`,
`${__dirname}/../__test__/dump/non-palette-bitmap-${transformName}.bmp`,
];

expect(() => {bitmapper.writer(inputPaths, outputPaths, transformName, (error,data) => {
expect(error).toBe('transformName must be a string');
done();
});}).toThrow();
});

});
});
Loading