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 lab-catherine-kerry/.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 lab-catherine-kerry/.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" ]
}
}
92 changes: 92 additions & 0 deletions lab-catherine-kerry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@

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

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

# End of https://www.gitignore.io/api/osx,node
30 changes: 30 additions & 0 deletions lab-catherine-kerry/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Lab 4 Bitmap Transformer
## Catherine Looper and Kerry Nordstrom

# Overview

## We created an application to take in command-line arguments (CLI) from the user consisting of node program reference, starter file, an existing .bmp file, the new file name, and one of three established transformations.

### Example
```node index.js house.bmp testhouse.bmp grayscale```

# Exported Modules

## Module: Transform

In the transform module, we exported three functions: grayscale, invert, and randomize. These take in values from the parsedBitmap object, which includes the color header indices, which are specifically referenced in each calculation.

### Grayscale
The grayscale function looks at each index and resets all of the RGB values to match the first value which turns the image to grayscale.

### Invert
The invert function looks at each index and subtracts the RGB value from 255 (white) which provides the inverted value.

### Randomize
The randomize function looks at each index and and subtracts the original index value from a randomly generated number multiplied by 255. This creates an image with entirely random pixel values.

## Module: Bitmap
In this bitmap module, we are parsing our bitmap via buffer to assign various offset values to our exported object. With this, we can pass these "bitmap road maps" to other functionality to change specific values.

### Parse Bitmap
The parse bitmap function does exactly as described above and takes in buffer information to place specific offset values of our selected bitmap in order to pass this into our functions.
Binary file added lab-catherine-kerry/__test__/asset/bitmap.bmp
Binary file not shown.
Binary file added lab-catherine-kerry/__test__/asset/bitmaptest.bmp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lab-catherine-kerry/__test__/asset/house.bmp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added lab-catherine-kerry/__test__/asset/testhouse.bmp
Binary file not shown.
29 changes: 29 additions & 0 deletions lab-catherine-kerry/__test__/bitmap.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const bitmap = require('../lib/bitmap');
const fs = require('fs');

describe('lib/bitmap.js', () => {

describe('testing for valid bitmap details', () => {
test('testing to see that we are receiving expected file paths ', done => {
fs.readFile(`${__dirname}/asset/house.bmp`, (error, data) => {
let parsedBitmap = bitmap.parseBitmap(data);
expect(error).toBeNull();
expect(parsedBitmap).not.toBeNull();
done();
});
});
test('testing to see that bitmap offsets are correct ', done => {
fs.readFile(`${__dirname}/asset/house.bmp`, (error, data) => {
let parsedBitmap = bitmap.parseBitmap(data);
expect(error).toBeNull();
expect(parsedBitmap.fileSize).toEqual(66616);
expect(parsedBitmap.type).toEqual('BM');
expect(parsedBitmap.pixelTableOffset).toEqual(1078);
expect(parsedBitmap.height).toEqual(256);
done();
});
});
});
});
39 changes: 39 additions & 0 deletions lab-catherine-kerry/__test__/transformMods.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
'use strict';

const transformsMods = require('../lib/transformMods');

describe('lib/transformMods.js', () => {

describe('testing transforms.grayscale to return grayscale values', () => {
test('function should return expected values', () => {
const sampleArray = {};
sampleArray.buffer = new Buffer ([0, 56, 80, 70]);
sampleArray.colorTable = sampleArray.buffer.slice(0);
const newArray = transformsMods.grayscale(sampleArray);
expect(newArray.buffer.readUInt8(1)).toBe(0);
expect(newArray.buffer.readUInt8(2)).toBe(0);
});
});

describe('testing transforms.invert to return inverted values', () => {
test('function should return expected values', () => {
const sampleArray = {};
sampleArray.buffer = new Buffer ([0, 0, 80, 70]);
sampleArray.colorTable = sampleArray.buffer.slice(0);
const newArray = transformsMods.invert(sampleArray);
expect(newArray.buffer.readUInt8(1)).toBe(255);
expect(newArray.buffer.readUInt8(2)).toBe(175);
});
});

describe('testing transforms.random to return random values', () => {
test('function should return expected values', () => {
const sampleArray = {};
sampleArray.buffer = new Buffer ([0, 0, 80, 70]);
sampleArray.colorTable = sampleArray.buffer.slice(0);
const newArray = transformsMods.random(sampleArray);
expect(newArray.buffer.readUInt8(1)).not.toBe(0);
expect(newArray.buffer.readUInt8(2)).not.toBe(80);
});
});
});
46 changes: 46 additions & 0 deletions lab-catherine-kerry/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
'use strict';

const bitmap = require('./lib/bitmap');
const transform = require('./lib/transformMods');
const fs = require('fs');
const infile = process.argv[2];
const outfile = process.argv[3];
const myArgs = process.argv.slice(4);


fs.readFile(`${__dirname}/__test__/asset/${infile}`, (error,data) => {
if(error)
{
console.error(error);
return;
}

let parsedBitmap = bitmap.parseBitmap(data);

switch (myArgs[0]) {
case 'grayscale':
transform.grayscale(parsedBitmap);
console.log(`a grayscale image has been created at ${outfile}.`);
break;
case 'invert':
transform.invert(parsedBitmap);
console.log(`an inverted image has been created at ${outfile}.`);
break;
case 'random':
transform.random(parsedBitmap);
console.log(`a randomized image has been created at ${outfile}.`);
break;
default:
console.log('Sorry, you did not list a valid transform method');
}

fs.writeFile(`${__dirname}/__test__/asset/${outfile}`, parsedBitmap.buffer, error => {
if(error)
{
console.error(error);
return;
}
console.log('Congratulations, your photo file has been written!');
});
});

22 changes: 22 additions & 0 deletions lab-catherine-kerry/lib/bitmap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

'use strict';

const bitmap = module.exports = {};

bitmap.parseBitmap = (buffer) => {
let parsedBitmap = {};

const HEIGHT_OFFSET = 22;
const PIXEL_TABLE_OFFSET = 10;
const FILE_SIZE_OFFSET = 2;

parsedBitmap.buffer = buffer;
parsedBitmap.type = buffer.toString('utf-8',0,2);
parsedBitmap.fileSize = buffer.readInt32LE(FILE_SIZE_OFFSET);
parsedBitmap.pixelTableOffset = buffer.readInt32LE(PIXEL_TABLE_OFFSET);
parsedBitmap.height = buffer.readInt32LE(HEIGHT_OFFSET);
parsedBitmap.colorTable = buffer.slice(54, parsedBitmap.pixelTableOffset);

return parsedBitmap;

};
54 changes: 54 additions & 0 deletions lab-catherine-kerry/lib/transformMods.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';

const transforms = module.exports = {};

transforms.grayscale = (parsedBitmap) => {

parsedBitmap.colorTable.forEach((value, position, array) => {

if (position % 4 === 1) {
parsedBitmap.colorTable.writeUInt8(array[position - 1], position);
}
if (position % 4 === 2) {
parsedBitmap.colorTable.writeUInt8(array[position - 2], position);
}
if (position % 4 === 3) {
parsedBitmap.colorTable.writeUInt8(array[position - 3], position);
}
});
return parsedBitmap;
};

transforms.invert = (parsedBitmap) => {

parsedBitmap.colorTable.forEach((value, position, array) => {

if (position % 4 === 1) {
parsedBitmap.colorTable.writeUInt8(255 - array[position], position);
}
if (position % 4 === 2) {
parsedBitmap.colorTable.writeUInt8(255 - array[position], position);
}
if (position % 4 === 3) {
parsedBitmap.colorTable.writeUInt8(255 - array[position], position);
}
});
return parsedBitmap;
};

transforms.random = (parsedBitmap) => {

parsedBitmap.colorTable.forEach((value, position, array) => {
if (position % 4 === 1) {
parsedBitmap.colorTable.writeUInt8(Math.abs((Math.random() * 255) - array[position]), position);
}
if (position % 4 === 2) {
parsedBitmap.colorTable.writeUInt8(Math.abs((Math.random() * 255) - array[position]), position);
}
if (position % 4 === 3) {
parsedBitmap.colorTable.writeUInt8(Math.abs((Math.random() * 255) - array[position]), position);
}
});
return parsedBitmap;
};

Loading