Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
cbb2a4b
basic directory structure and files established
Nov 30, 2017
6d1619a
index.js setup with modifyBmp function and requirements
Nov 30, 2017
9d894ca
finished reader test and functionality, able to read a file path.
AMKRobinson Dec 1, 2017
d6391ed
removed reader module and moved fs readfile to index.js
AMKRobinson Dec 1, 2017
0d2126f
parser is fucntioning, parsing metadata into an object
AMKRobinson Dec 1, 2017
cf09839
basic structure of transform functioning
Dec 1, 2017
fe6e338
first transform test passing
Dec 1, 2017
a31f82a
deleted old code from parser test
Dec 1, 2017
eeaca6a
parser module returns an object that contains filOffsets and metaData…
Dec 1, 2017
58919d3
we can copy a file now, wee
AMKRobinson Dec 2, 2017
7e56ef1
created invert and grayscale transforms
AMKRobinson Dec 2, 2017
59ceea6
CLI is now working
AMKRobinson Dec 2, 2017
30f1c2c
changed process.argv[4] to allow an array of arguments
AMKRobinson Dec 2, 2017
6bf48b1
changed template literals in the modifyBmp call, changed 'args' to tr…
AMKRobinson Dec 2, 2017
6ab99ea
added returns to our error messages
AMKRobinson Dec 2, 2017
7ac7fb2
Cleaned up error messages, added ternary to check for at least 1 tran…
Dec 2, 2017
981252e
removed old comments from transofrm.js
Dec 2, 2017
74a09bd
got some decent parser tests working
AMKRobinson Dec 3, 2017
a008031
buffer written by hand in testAsset. Building documented. Built in ex…
Dec 3, 2017
a374cbc
anthony's parse test and rob's bmpBuilder
Dec 3, 2017
00a2b48
refactored parse test to check for deep equals of object
Dec 3, 2017
daa33c8
fixed small pallette typo in transforms
Dec 3, 2017
a99f0e3
positive transform tests all passing
Dec 3, 2017
6c826be
transform tests passing
Dec 3, 2017
475bb29
removed old file tests
Dec 3, 2017
01b0c95
added lumosity transform
AMKRobinson Dec 3, 2017
d816548
fixed lumosity transform, third position starts with red
AMKRobinson Dec 3, 2017
8dfdd96
Merge branch 'anthony-playground' of https://github.com/RobertMcReed/…
Dec 3, 2017
58242fa
fixed out of date code
AMKRobinson Dec 3, 2017
97a7a46
added lumosity test
AMKRobinson Dec 3, 2017
47a2502
added lumosity test
AMKRobinson Dec 3, 2017
c9b434d
Merge branch 'anthony-rob-lab' of https://github.com/RobertMcReed/04-…
AMKRobinson Dec 3, 2017
8089d71
Merge branch 'anthony-rob-lab' of https://github.com/RobertMcReed/04-…
Dec 3, 2017
2d48f0b
added pixelArraySize property to parse, test passes, fixed luminosity…
Dec 3, 2017
685b24d
pixel array slice added to properties, test passes
Dec 3, 2017
fb1d7d9
finished readme
AMKRobinson Dec 3, 2017
1cc2501
added algorith source for grayscale
AMKRobinson Dec 3, 2017
2b8a315
added back ticks
AMKRobinson Dec 3, 2017
64c8b94
pixel array as buffer works, but not as array...hmmmmmm
Dec 3, 2017
254e10d
added back ticks
AMKRobinson Dec 3, 2017
acea9e6
fixed some small formatting and typos in readme
Dec 3, 2017
23482f7
cleaned file up for submit
Dec 3, 2017
7fe7243
Merge pull request #1 from RobertMcReed/anthony-rob-lab
Dec 3, 2017
64f038f
removed test file writer corpse
Dec 3, 2017
c3a52b8
removed .DS_Store
Dec 3, 2017
9ce49ef
grayscaleSoft working and passing
Dec 4, 2017
0f6eb22
red transform works and passes
Dec 4, 2017
6752fc7
added green and blue filters and tests, passing
Dec 4, 2017
b2e5cfc
updated readme with new transforms
Dec 4, 2017
e77b326
vertical flip is working
Dec 4, 2017
2d2e579
flip y tests pass
Dec 4, 2017
02eedc7
updated codebase with master base, all integrated and tests working w…
Dec 4, 2017
a3f0186
added recommended transforms to readme
Dec 4, 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 lab-anthony-rob/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
41 changes: 41 additions & 0 deletions lab-anthony-rob/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"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"
]
}
}
152 changes: 152 additions & 0 deletions lab-anthony-rob/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# Created by https://www.gitignore.io/api/osx,vim,node,linux,windows,visualstudiocode

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

# 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

### VisualStudioCode ###
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
.history

### 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,linux,windows,visualstudiocode

node_modules/*
coverage/*
63 changes: 63 additions & 0 deletions lab-anthony-rob/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Code Fellows: Code 401d19: Full-Stack JavaScript
## Lab 04: Bitmap Transformer
#### 12/3/17 - Anthony Robinson & Robert Reed


## Usage:
run in terminal `node index.js <input file name> <output file name> <transformation 1>...<transformation n>`

`<input file name>` must exist in the __test__/assets folder
`<output file name>` will be generated in the __test__/assets folder
`<transformation>` must exist in the below Transformations list.

## Transformations:
grayscaleSoft
- This is the best of the grayscale transformations, and can be used to take the noise out of a picture (although it does make it gray). Try running this first and then the red, green, or blue transforms.
grayscaleAvg
grayscaleLum
invert
red
green
blue
flipY

example: `node index.js bitmap.bmp bitmap-output.bmp grayscaleAvg`

The user also has the ability to run multiple transforms

example: `node index.js bitmap.bmp bitmap-output.bmp grayscaleAvg invert grayscaleLum flipY`

Try chaining together multiple color transforms to get interesting compounding effects.

## Recommended Test Transforms

`node index.js house.bmp house-grey-flip.bmp grayscaleSoft flipY`

`node index.js house.bmp house-soft-red.bmp grayscaleSoft red`

`node index.js house.bmp house-neon.bmp red`

`node index.js house.bmp house-green-blue.bmp red invert`

`node index.js house.bmp house-spooky-red.bmp grayscaleSoft blue green blue invert`

`node index.js finger-print.bmp finger-print-pink.bmp blue green grayscaleAvg blue red`

`node index.js finger-print.bmp finger-print-aquamarine.bmp blue green grayscaleAvg blue red invert red invert blue flipY`

## Modules:

parser.js - exports a function that returns an object based off of buffer data which is read from index.js.

It has an arity of one and it accepts a buffer as it's argument. The parser will not return an object if incomplete buffer data is used.

transform.js - exports a function that modifies the buffer data based on the transforms used. It has an arity of two and it accepts any number of valid transform strings wrapped in an array, otherwise it throws an error when the transform string does not exist.

index.js - utilizes fs.readFile to read a buffer from a file which parser.js uses. When the buffer is passed back to index from transform.js it performs the requested transforms and writes the file based on the CLI input from the user.

## Grayscale algorithm source:
https://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/

## Limitations

BMP files must have 8bit color, and all color transforms require bmp to use a color palette.
Binary file added lab-anthony-rob/__test__/assets/bitmap.bmp
Binary file not shown.
Binary file added lab-anthony-rob/__test__/assets/finger-print.bmp
Binary file not shown.
Binary file added lab-anthony-rob/__test__/assets/house.bmp
Binary file not shown.
Binary file not shown.
71 changes: 71 additions & 0 deletions lab-anthony-rob/__test__/assets/testAsset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
'use strict';

// export the module so we can use it to test with
const asset = module.exports = {};
const parse = require('../../lib/parser');

// I think the only thing you need to change in this one is the offset to the pixel table. See last row of entries to figure out how to calculate it
let bmpHeader = [
66, 77, // 42 4D -> BM File header field: Type BM // LEAVE ALONE
218, 58, 0, 0, // DA 3A 00 00 -> File Size: 15066 bytes // BMP Header + DIB Header + (widthInPixels * heightInPixels) + (numColorsInPalette * 4) // Don't know where this is used?
0, 0, 0, 0, // 00 00 00 00 reserved 4 bytes // LEAVE ALONE
66, 0, 0, 0, // 42 00 00 00 -> Offset to the pixel table: 66 = BMP Header(always 14) + DIB Header(always 40) + colorPalateBytes(4bytes*numColors) = 14 + 40 + 4 * 3 = 66
];

// The values you would want to change here would be the width and the height
let dibHeader = [
40, 0, 0, 0, // 28 00 00 00 -> DIB header size: 40 // LEAVE ALONE
100, 0, 0, 0, // 64 00 00 00 -> Width (signed): 100 // must determine what this number is in hex
150, 0, 0, 0, // 96 00 00 00 -> Height (signed): 150 // must determine what this number is in hex
1, 0, // 01 00 -> number of color planes must be 1 // LEAVE ALONE
8, 0, // 10 00 -> number of bits per pixel: 8 // LEAVE ALONE
0, 0, 0, 0, // 00 00 00 00 -> compression method: 0, none // LEAVE ALONE
0, 0, 0, 0, // 00 00 00 00 -> size of the raw bitmap data // Don't know where this is used?
0, 0, 0, 0, // 00 00 00 00 -> horizontal resolution, pixels per meter, signed: // Don't know where this is used?
0, 0, 0, 0, //00 00 00 00 -> vertical resolution, pixels per meter, signed: // Don't know where this is used?
3, 0, 0, 0, // 03 00 00 00 -> number of colors in the color palette: 3 // Don't know where this is used?
0, 0, 0, 0, // 00 00 00 00 -> number of important colors: 0, meaning all are important // LEAVE ALONE
];

// This is where you will define all of your colors. You can have up to 256 unique colors.
// Color values are composed of 4 numbers in the order blue, green, red, and are followed by a number that apparently doesn't do anything, but that I thought was an index. Apparently the index is determined automatically.
let colorPalette = [
255, 0, 0, 0, // 02 00 00 FF -> color 0: blue, index 0
0, 255, 0, 0, // 00 FF 00 00 -> color 1: green, index 1
0, 0, 255, 0, // 01 00 FF 00 -> color 2: red, index 2
];

// here we define the pixel array. each pixel is stored as a reference back to one of the colors in the color palette, as indicated by their index. You should have the same number of pixels here as your width * height. Numbers go in row by bow, bottom left to bottom right, then up.
let pixelArray = [];
//this for loop is adding the color indices to the pixel array, a third of each color together
for(let row = 0; row < 150; row++) {
for(let col = 0; col < 100; col++) {
if(row < 50)
pixelArray.push(0);
else if(row < 100)
pixelArray.push(1);
else
pixelArray.push(2);
}
}

// Combine all of these arrays into a single array.
let bmpArray = bmpHeader.concat(dibHeader).concat(colorPalette).concat(pixelArray);
let bmpArrayFLipY = bmpHeader.concat(dibHeader).concat(colorPalette).concat(pixelArray.reverse());

// Make a buffer from the array, so we can write it to a file.
let bmpBuffer = Buffer.from(bmpArray);
let bmpBufferFlipY = Buffer.from(bmpArrayFLipY);

// export the buffer so we can test with it.
asset.testBuffer = bmpBuffer;
asset.testBufferColorPalette = Buffer.from(colorPalette);
asset.testData1 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testData2 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testData3 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testData4 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testData5 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testData6 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testData7 = {colorPaletteBuffer: Buffer.from(colorPalette)};
asset.testBufferFlipY = bmpBufferFlipY;
asset.testDataFlipY = parse(bmpBufferFlipY);
34 changes: 34 additions & 0 deletions lab-anthony-rob/__test__/parser.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const asset = require('./assets/testAsset');
const parser = require('../lib/parser');

describe('parser.js', () => {
let testPixelArray = [];
for (let row = 0; row < 150; row++) {
for (let col = 0; col < 100; col++) {
if (row < 50)
testPixelArray.push(0);
else if (row < 100)
testPixelArray.push(1);
else
testPixelArray.push(2);
}
}

test('Parser should return an object containing the metadata from a buffer.', () => {
let testData = {
buffer: asset.testBuffer,
type: 'BM',
fileSize: 15066,
pixelArrayOffset: 66,
width: 100,
height: 150,
colorPaletteBuffer: Buffer.from(asset.testBufferColorPalette),
pixelArrayRowLength: 100,
pixelArraySize: 15000,
pixelArrayBuffer: Buffer.from(testPixelArray),
};
expect(parser(asset.testBuffer)).toEqual(testData);
});
});
Loading