diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0992345 --- /dev/null +++ b/.gitignore @@ -0,0 +1,117 @@ +# Created by https://www.gitignore.io/api/node,vim,osx,macos,linux + +*node_modules + +### Node ### +# Logs +logs +*.log +npm-debug.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 + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# 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 + + + +### 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 + + +### 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 + + +### macOS ### +# Icon must end with two \r +# Thumbnails +# Files that might appear in the root of a volume +# Directories potentially created on remote AFP share + + +### 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* + +# End of https://www.gitignore.io/api/node,vim,osx,macos,linux diff --git a/bitmap-annashivwill/.eslintrc b/bitmap-annashivwill/.eslintrc new file mode 100644 index 0000000..8dc6807 --- /dev/null +++ b/bitmap-annashivwill/.eslintrc @@ -0,0 +1,21 @@ +{ + "rules": { + "no-console": "off", + "indent": [ "error", 2 ], + "quotes": [ "error", "single" ], + "semi": ["error", "always"], + "linebreak-style": [ "error", "unix" ] + }, + "env": { + "es6": true, + "node": true, + "mocha": true, + "jasmine": true + }, + "ecmaFeatures": { + "modules": true, + "experimentalObjectRestSpread": true, + "impliedStrict": true + }, + "extends": "eslint:recommended" +} diff --git a/bitmap-annashivwill/.gitignore b/bitmap-annashivwill/.gitignore new file mode 100644 index 0000000..0992345 --- /dev/null +++ b/bitmap-annashivwill/.gitignore @@ -0,0 +1,117 @@ +# Created by https://www.gitignore.io/api/node,vim,osx,macos,linux + +*node_modules + +### Node ### +# Logs +logs +*.log +npm-debug.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 + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (http://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules +jspm_packages + +# 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 + + + +### 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 + + +### 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 + + +### macOS ### +# Icon must end with two \r +# Thumbnails +# Files that might appear in the root of a volume +# Directories potentially created on remote AFP share + + +### 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* + +# End of https://www.gitignore.io/api/node,vim,osx,macos,linux diff --git a/bitmap-annashivwill/README.md b/bitmap-annashivwill/README.md new file mode 100644 index 0000000..fd37a07 --- /dev/null +++ b/bitmap-annashivwill/README.md @@ -0,0 +1,41 @@ +![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 04: Bitmap Transformer +=== + +## To Submit this Assignment +* have team leader fork this repository +* have team leader add team members as collaborators to the team fork +* team members should clone team fork +* write all of your code in a directory name `bitmap-` + `` **e.g.** `bitmap-weasels` +* submit a pull request to this repository when done +* each person will submit a link to their own PR in canvas +* each person write a question and observation on canvas + +#### Rubric: +* **tests:** 3pts +* **gulpfile/package.json:** 2pts +* **read bitmap meta data:** 5pts +* **successfully apply transforms:** 5pts +* **project design and organization:** 5pts + +## Description + +For this assignment you will be building a bitmap (`.bmp`) reader and transformer. It will read a bitmap in from disk, run one or more color transforms on the bitmap 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 project should include tests, as well as a `gulpfile.js`, `package.json`, `.eslintrc`, `README.md`, and a `.gitignore`. Make sure to run all your code through eslint. The process will look something like this: + +1. open the original bitmap file using fs and read it into a buffer +2. convert the buffer header data into a Javascript Object (using constructors) +3. run a transform on the buffer directly +4. write the buffer to a new file + +The wikipedia article found here [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format) describes the byte specification of a "windows bitmap file." We'll be working with the simplest version, meaning no compression. + +* your project should have three ***(or more)*** transforms +* invert the colors (***hint:*** subtract every color value from the max color value which is 255), +* grayscale the colors (***hint:*** multiply each color value by a constant, just make sure your values don't go over 255) +* (red|green|blue)scale the colors (***hint:*** same as above but only multiply one of the colors) + +## Bonus: + +* ability to handle various sized bitmap +* ability to handle LE and BE computers with a single if statement +* utilizes a command line interface (CLI) +* CLI can select the transforms diff --git a/bitmap-annashivwill/img/black.bmp b/bitmap-annashivwill/img/black.bmp new file mode 100644 index 0000000..248db67 Binary files /dev/null and b/bitmap-annashivwill/img/black.bmp differ diff --git a/bitmap-annashivwill/img/grey.bmp b/bitmap-annashivwill/img/grey.bmp new file mode 100644 index 0000000..7d7e1f8 Binary files /dev/null and b/bitmap-annashivwill/img/grey.bmp differ diff --git a/bitmap-annashivwill/img/inverted.bmp b/bitmap-annashivwill/img/inverted.bmp new file mode 100644 index 0000000..5cfbdac Binary files /dev/null and b/bitmap-annashivwill/img/inverted.bmp differ diff --git a/bitmap-annashivwill/img/palette-bitmap.bmp b/bitmap-annashivwill/img/palette-bitmap.bmp new file mode 100644 index 0000000..97ad0df Binary files /dev/null and b/bitmap-annashivwill/img/palette-bitmap.bmp differ diff --git a/bitmap-annashivwill/img/red.bmp b/bitmap-annashivwill/img/red.bmp new file mode 100644 index 0000000..823860d Binary files /dev/null and b/bitmap-annashivwill/img/red.bmp differ diff --git a/bitmap-annashivwill/index.js b/bitmap-annashivwill/index.js new file mode 100644 index 0000000..d480770 --- /dev/null +++ b/bitmap-annashivwill/index.js @@ -0,0 +1,5 @@ +'use strict'; + +const maps = require(`${__dirname}/model/read-write.js`); + +maps.readWrite(); diff --git a/bitmap-annashivwill/lib/bitmap-file-helper.js b/bitmap-annashivwill/lib/bitmap-file-helper.js new file mode 100644 index 0000000..e69de29 diff --git a/bitmap-annashivwill/lib/transforms.js b/bitmap-annashivwill/lib/transforms.js new file mode 100644 index 0000000..091f9af --- /dev/null +++ b/bitmap-annashivwill/lib/transforms.js @@ -0,0 +1,37 @@ +'use strict'; + +const fs = require('fs'); +const image = require(`${__dirname}/../index.js`); + +module.exports = exports = {}; + +exports.turnBlack = function(bitmap) { + const blackBuf = new Buffer(bitmap); + return blackBuf.fill('00', 54, 1078); +}; + +exports.invert = function(bitmap) { + const invertBuf = new Buffer(bitmap); + for (var i = 54; i < 1078; i ++) { + invertBuf.fill(255-bitmap[i], i, i+1); + }; + return invertBuf; +}; + +exports.redScale = function(bitmap) { + const redBuf = new Buffer(bitmap); + for(var i = 56; i < 1078; i += 4) { + redBuf.fill(255, i, i+1); + }; + return redBuf; +}; + +exports.greyScale = function(bitmap) { + const greyBuf = new Buffer(bitmap); + for(var i = 54; i < 1078; i += 4) { + greyBuf.fill(greyBuf[i+1], i, i+1); + greyBuf.fill(greyBuf[i+1], i+1, i+2); + greyBuf.fill(greyBuf[i+1], i+2, i+3); + }; + return greyBuf; +} diff --git a/bitmap-annashivwill/model/bitmap-constructor.js b/bitmap-annashivwill/model/bitmap-constructor.js new file mode 100644 index 0000000..ca8fc5f --- /dev/null +++ b/bitmap-annashivwill/model/bitmap-constructor.js @@ -0,0 +1,12 @@ +'use strict'; + +const fs = require('fs'); +const bitmap = fs.readFileSync(`${__dirname}/assets/palette-bitmap.bmp`); + +const bmp = {}; + +bmp.type = bitmap.toString('utf-8',0,2); +bmp.size = bitmap.readInt32LE(2); +bmp.width = bitmap.readInt32LE(18); +bmp.height = bitmap.readInt32LE(22); +bmp.startLoc = bitmap.readInt32LE(10); diff --git a/bitmap-annashivwill/model/read-write.js b/bitmap-annashivwill/model/read-write.js new file mode 100644 index 0000000..daa2122 --- /dev/null +++ b/bitmap-annashivwill/model/read-write.js @@ -0,0 +1,36 @@ +'use strict'; + +const fs = require('fs'); +const transforms = require(`${__dirname}/../lib/transforms.js`); + +module.exports = exports = {}; +// +// const file1 = `${__dirname}/../img/palette-bitmap.bmp`; +// const file2 = `${__dirname}/../img/inverted.bmp`; +// const file3 = `${__dirname}/../img/black.bmp`; +// const file4 = `${__dirname}/../img/red.bmp`; +// const file5 = `${__dirname}/../img/grey.bmp`; + +exports.readWrite = function() { + + fs.readFile(`${__dirname}/../img/palette-bitmap.bmp`, function(err, data) { + if (err) throw err; + const bitmap = data; + + fs.writeFile(`${__dirname}/../img/inverted.bmp`, transforms.invert(bitmap), function(err, data) { + if (err) throw err; + }); + + fs.writeFile(`${__dirname}/../img/black.bmp`, transforms.turnBlack(bitmap), function(err, data) { + if (err) throw err; + }); + + fs.writeFile(`${__dirname}/../img/red.bmp`, transforms.redScale(bitmap), function(err, data) { + if (err) throw err; + }); + + fs.writeFile(`${__dirname}/../img/grey.bmp`, transforms.greyScale(bitmap), function(err, data) { + if (err) throw err; + }); + }); +}; diff --git a/bitmap-annashivwill/package.json b/bitmap-annashivwill/package.json new file mode 100644 index 0000000..b20e00c --- /dev/null +++ b/bitmap-annashivwill/package.json @@ -0,0 +1,19 @@ +{ + "name": "bitmap-annashivwill", + "version": "1.0.0", + "description": "![CF](https://camo.githubusercontent.com/70edab54bba80edb7493cad3135e9606781cbb6b/687474703a2f2f692e696d6775722e636f6d2f377635415363382e706e67) Lab 04: Bitmap Transformer\r ===", + "main": "index.js", + "directories": { + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "devDependencies": { + "chai": "^3.5.0", + "mocha": "^3.2.0" + } +} diff --git a/bitmap-annashivwill/test/bitmap-constructor-test.js b/bitmap-annashivwill/test/bitmap-constructor-test.js new file mode 100644 index 0000000..e69de29 diff --git a/bitmap-annashivwill/test/bitmap-file-helper-test.js b/bitmap-annashivwill/test/bitmap-file-helper-test.js new file mode 100644 index 0000000..95b6ac3 --- /dev/null +++ b/bitmap-annashivwill/test/bitmap-file-helper-test.js @@ -0,0 +1,9 @@ +/* +TESTS. TESTS. TESTS. [EACH ONE WITH TWO PIECES, ONE FOR ERROR, AND ONE FOR A PASSING TEST] + +- Are we able to access and read the bitmap image itself? +- Are we able to change the slice of information that pertains to the bitmap? +- Are we then changing that slice of information to the designated constant of the green|red|blue scale? +- Are we changing the slice of information that relates to the image to the grey scale? +- Are we changing the slice of information that relate to the image to an inverted color scheme? +*/ diff --git a/bitmap-annashivwill/test/color-constructor-test.js b/bitmap-annashivwill/test/color-constructor-test.js new file mode 100644 index 0000000..e69de29