Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
cc29c2e
scaffold built, ready to rock
Nords3x4 Feb 15, 2018
3d3888e
initial commit
Feb 15, 2018
dc5c942
constructor finished
Feb 15, 2018
f062dea
index.js file added
Feb 15, 2018
1471f50
Merge pull request #1 from Nordcoder0101/nicole-constructor
nicoleweese Feb 15, 2018
b5d9fb9
read and write file written
Nords3x4 Feb 16, 2018
43a6a18
Merge pull request #2 from Nordcoder0101/file-reader
nicoleweese Feb 16, 2018
f254ff2
read write
AhmedAli93 Feb 16, 2018
6439867
Merge pull request #3 from Nordcoder0101/ahmed/js/constructor
AhmedAli93 Feb 16, 2018
8d44621
turned picture white!!!!
Feb 16, 2018
f7b6a18
Merge pull request #4 from Nordcoder0101/nicole-constructor
nicoleweese Feb 16, 2018
35548eb
fixed constructor offsets
Feb 16, 2018
f03ee21
blue stripe
AhmedAli93 Feb 16, 2018
d9d04f5
Merge pull request #5 from Nordcoder0101/nicole-constructor
nicoleweese Feb 16, 2018
e2083be
Merge pull request #6 from Nordcoder0101/ahmed/js/transform
nicoleweese Feb 16, 2018
c7d1caa
blah
Feb 16, 2018
1fa99e0
Merge pull request #7 from Nordcoder0101/nicole-constructor
nicoleweese Feb 16, 2018
1b24276
line went down the middle of the screen
Feb 17, 2018
c58fb8b
Merge pull request #8 from Nordcoder0101/nicole-constructor
AhmedAli93 Feb 17, 2018
2415c5f
created cross function
Feb 17, 2018
5a51b3d
started on test file for cross-section.js
Nords3x4 Feb 17, 2018
7368fc4
Merge pull request #9 from Nordcoder0101/cross-section-test
Nordcoder0101 Feb 17, 2018
e13880b
Merge branch 'master' into nicole-constructor
nicoleweese Feb 17, 2018
897932f
Merge pull request #10 from Nordcoder0101/nicole-constructor
nicoleweese Feb 17, 2018
c6bb5f9
darkening of colors finished
Feb 17, 2018
5526956
darkened feature done
Feb 18, 2018
e11ca7f
random done
AhmedAli93 Feb 19, 2018
d8535f8
Merge pull request #11 from Nordcoder0101/ahmed/js/transformation
Nordcoder0101 Feb 19, 2018
cbfc674
Merge branch 'master' into nicole-constructor
Nordcoder0101 Feb 19, 2018
2d4f470
Merge pull request #12 from Nordcoder0101/nicole-constructor
nicoleweese Feb 19, 2018
84101ca
merged files
Feb 19, 2018
2f0f2cd
prepped for submission
Feb 19, 2018
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-greg-nicole-ahmed/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
27 changes: 27 additions & 0 deletions lab-greg-nicole-ahmed/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"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" ],
"linebreak-style": ["error", "unix"]
}
}
129 changes: 129 additions & 0 deletions lab-greg-nicole-ahmed/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@

# Created by https://www.gitignore.io/api/node,linux,macos,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,linux,macos,windows
35 changes: 35 additions & 0 deletions lab-greg-nicole-ahmed/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
##Lab-Bitmap

### Description

In these files we created a bitmap (.bmp) transformer which reads the bitmap from the disc, runs one or more raster or color transforms and writes it out to a new file.

#### constructor.js

The constructor file is where the Bitmap object constructor lives. This constructor takes in one parameter, the data returned by the file system readFile function. It then constructs an object and returns it.

#### read-write-file.js

This is where the file system reads and writes files with the use of Node.js. This function accepts three parameters, the filepath to the original .bmp file, the file path you want to be created, and the name of the function for the transformation you want to be performed.
The readFile portion retreives the binary data from the file system, sends it to the object constructor, then taks the constructed bitmap object and sends it to the transformation function. Once this is returned back, it then turns the received transformed string data and constructs a new bitmap string, which is then converted to a buffer and send to the write file function.
The write file function takes the buffer object and writes a bitmap file which is then saved into your computer using the file path you created.

#### all-white.js

This function accepts one parameter, the bitmap object you created in object constructor. The file doesn't actually need the bitmap object, however, because it uses string concatination and for loops to add white as the only color on the color palette, and then the index of every pixel in the pixel array to point to the first number in the color palette.

#### cross.js

This function accepts one parameter, the bitmap object that was created. The code then finds the middle of the array containing pixel data, and using various algorithms, creates 4 lines intersecting the middle of the screen. The function then returns the string data back to the read-write-file to be written to a .bmp.

#### darken.js

This function accepts one parameter, the bitmap object that was created. The code then takes each color in the color palette array and maps it to a new value. It does this by breaking the string data up into chunks of 2 to find the decimal value of each hex value, reduce it by 40, and then turned back in to a hex value so it can inserted back into a string and because each hex value is lower, each color will be lower. The pixel array goes untouched and inserted back into the bitmap object.

#### neww.js

This function accepts one parameter, the bitmap object that was created. The code then takes every item in the pixel array and and randomizes the indexes that the items in the pixel array point to in order to create a random image from the colors in the color palette.

#### index.js

This file requires in all the files that contain all the helper functions and then uses them to create 4 new images.
36 changes: 36 additions & 0 deletions lab-greg-nicole-ahmed/__test__/cross-section.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const readFileHelper = require('../lib/cross-section.js');
require('jest');

describe('#cross-section', function() {
describe('with improper file paths', function() {
it('should return an error', function(done) {
readFileHelper([`${__dirname}/dont-exist.txt`], function(err) {
expect(err).toBeTruthy();
expect(err.code).toEqual('ENOENT');
done();
});
});
});
describe('with proper file paths', function() {
it('should return a proper file name', function() {
expect(err).toBe(false);
expect()
})
`${__dirname}/../data/pallette-bitmap.bmp`,
done();
});
it('should have the correct order of hex strings', done => {
var expectedResult = [];
readFileHelper(this.paths, function(err, data) {
console.log('data array', data);
expect(err).toEqual(null);
expect(data[0]).toEqual(expectedResult[0]);
expect(data[0]).toEqual(expectedResult[1]);
expect(data[0]).toEqual(expectedResult[2]);
done();
});
});
});
});
18 changes: 18 additions & 0 deletions lab-greg-nicole-ahmed/__test__/read-write-file.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const reader = require('../lib/read-write-file.js');
require('jest');


describe('Reader Module', function() {
describe('With an improper file path', function() {
it('should return an error', function(done) {
reader(`${__dirname}/notafile.js`, function(err) {
expect(err).toBeTruthy();
expect(typeof err).toBe('object');
expect(err.code).toBe('ENOENT');
})
done();
})
})
})
Binary file added lab-greg-nicole-ahmed/data/all-white.bmp
Binary file not shown.
Binary file added lab-greg-nicole-ahmed/data/crosses.bmp
Binary file not shown.
Binary file added lab-greg-nicole-ahmed/data/darkened.bmp
Binary file not shown.
Binary file added lab-greg-nicole-ahmed/data/neww.bmp
Binary file not shown.
Binary file added lab-greg-nicole-ahmed/data/palette-bitmap.bmp
Binary file not shown.
13 changes: 13 additions & 0 deletions lab-greg-nicole-ahmed/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';


const fileReader = require('./lib/read-write-file.js');
const allwhite = require('./lib/all-white.js');
const crosses = require('./lib/cross.js');
const darken = require('./lib/darken.js');
const random = require('./lib/neww.js');

fileReader('palette-bitmap.bmp', 'darkened.bmp', darken);
fileReader('palette-bitmap.bmp', 'neww.bmp', random);
fileReader('palette-bitmap.bmp', 'crosses.bmp', crosses);
fileReader('palette-bitmap.bmp', 'all-white.bmp', allwhite);
17 changes: 17 additions & 0 deletions lab-greg-nicole-ahmed/lib/all-white.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

module.exports = function(bitmapObj) {
let colorString = '';
let colorPalette = '';
let numOfZeros = bitmapObj.pixelArray.length * 8;

for(var i = 0; i < numOfZeros; i++) {
colorString += '0';
}

for(var j = 0; j < bitmapObj.colorPalette.length; j++) {
colorPalette += 'f';
}

return {colorString: colorString, colorPalette: colorPalette};
}
18 changes: 18 additions & 0 deletions lab-greg-nicole-ahmed/lib/constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

module.exports = function(data) {
function Bitmap (data) {
this.size = data.readInt32LE(34);
this.width = data.readInt32LE(18);
this.height = data.readInt32LE(22);
this.pixelAddress = data.readInt32LE(10);
this.pixels = data.toString('hex', this.pixelAddress);
this.header = data.slice(0, 54).toString('hex');
this.colorPalette = data.toString('hex', 54, this.pixelAddress);
this.colorPaletteArray = this.colorPalette.match((/.{1,8}/g));
this.pixelArray = this.pixels.match((/.{1,2}/g));
this.end = data.slice(this.pixelAddress + this.size, data.length).toString('hex');
}

return new Bitmap(data);
}
42 changes: 42 additions & 0 deletions lab-greg-nicole-ahmed/lib/cross.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
'use strict';

module.exports = function(bitmapObj){
let middleX = Math.floor(bitmapObj.width/2);
console.log('pixel array length', bitmapObj.pixelArray.length);


for(var k = 0; k < bitmapObj.pixelArray.length - 3; k+= 101) {
bitmapObj.pixelArray[k] = '3f';
bitmapObj.pixelArray[k+1] = '3f';
bitmapObj.pixelArray[k+2] = '3f';
bitmapObj.pixelArray[k-1] = '3f';
bitmapObj.pixelArray[k-2] = '3f';
}

for(var l = 99; l < bitmapObj.pixelArray.length - 2; l+= 99) {
bitmapObj.pixelArray[l] = '3f';
bitmapObj.pixelArray[l-1] = '3f';
bitmapObj.pixelArray[l-2] = '3f';
bitmapObj.pixelArray[l+2] = '3f';
bitmapObj.pixelArray[l+1] = '3f';
}


for(var i = middleX; i < bitmapObj.pixelArray.length; i += bitmapObj.width){
bitmapObj.pixelArray[i] = '1c';
bitmapObj.pixelArray[i+1] = '1c';
bitmapObj.pixelArray[i+2] = '1c';
bitmapObj.pixelArray[i-1] = '1c';
bitmapObj.pixelArray[i-2] = '1c';
}

let crossStart = ((Math.floor(bitmapObj.height/2) * bitmapObj.width) - 200);
let crossEnd = ((Math.floor(bitmapObj.height/2) * bitmapObj.width) + 200);

for(var j = crossStart; j < crossEnd; j++) {
bitmapObj.pixelArray[j] = '1c';
}

return {colorString: bitmapObj.pixelArray.join(''), colorPalette: bitmapObj.colorPalette}

}
27 changes: 27 additions & 0 deletions lab-greg-nicole-ahmed/lib/darken.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
'use strict';

module.exports = function(bitmapObj) {
let newPalette = bitmapObj.colorPaletteArray.map((x) => {
let colorArr = x.match((/.{1,2}/g));
for(var j = 0; j < colorArr.length; j++) {
colorArr[j] = parseInt(colorArr[j], 16);
if (colorArr[j] >= 40) {
colorArr[j] = colorArr[j] - 40;
} else {
colorArr[j] = 0;
}
colorArr[j] = colorArr[j].toString(16);
if(colorArr[j].split('').length === 1) {
let str = '0';
str += colorArr[j];
colorArr[j] = str;
}
}
let hexString = colorArr.join('');
return hexString;
})

console.log(newPalette);

return {colorString: bitmapObj.pixelArray.join(''), colorPalette: newPalette.join('')}
}
Loading