-
Notifications
You must be signed in to change notification settings - Fork 5
Logan-Luis-Nick-Bitmap-Final #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
a1d47ef
283dd41
a37bf28
a4f70d5
7c36b70
2765d38
356d8ef
38c5360
8377617
0e3d1a2
daab686
33332ba
94679b5
5d5d5f3
d869848
c7f6d7b
4a90cd4
5e0da7a
19450b4
0b84713
4db0412
c370a73
0004ee3
917bcd5
fa7214a
7561d01
4451a51
787fc06
13386e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| **/node_modules/* | ||
| **/vendor/* | ||
| **/*.min.js | ||
| **/coverage/* | ||
| **/build/* |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| { | ||
| "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 | ||
| }, | ||
| "extends": "eslint:recommended" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| # Created by https://www.gitignore.io/api/osx,node,linux,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* | ||
|
|
||
| ### 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 | ||
|
|
||
| ### 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,node,linux,windows |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| 'use strict'; | ||
|
|
||
| const Bitmap = require(`${__dirname}/model/bitmap-constructor.js`); | ||
| const ColorTransform = require(`${__dirname}/model/color-constructor.js`); | ||
| const fileHelper = require(`${__dirname}/lib/bitmap-file-helper.js`); | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.invertBitmap = () => { | ||
| let onRead = (err, data) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems like an unnecessary wrapper. Would be more straight forward to have the file helper at top and then could define function. That would flow easier for later reading. |
||
| if (err) throw err; | ||
|
|
||
| let bitmap = new Bitmap(data); | ||
| let transform = new ColorTransform(); | ||
| let copied = new Buffer(data); | ||
|
|
||
| bitmap.colorTable = transform.invertColors(bitmap); | ||
|
|
||
| let startToColorTable = copied.slice(0, bitmap.headerSize + 14); | ||
| let subColorTableBuffer = new Buffer(bitmap.colorTable.join(''), 'hex'); | ||
| let colorTableToEnd = copied.slice(data.readInt32LE(10)); | ||
| let testcopy = Buffer.concat([startToColorTable, subColorTableBuffer, colorTableToEnd]); | ||
|
|
||
| fileHelper.writeNew(`${__dirname}/assets/palette-invert-bitmap.bmp`, testcopy, exports.writeNew); | ||
| }; | ||
| fileHelper.initFile(`${__dirname}/assets/palette-bitmap.bmp`, onRead); | ||
| }; | ||
|
|
||
| exports.colorShiftBitmap = () => { | ||
| let onRead = (err, data) => { | ||
| if (err) throw err; | ||
|
|
||
| let bitmap = new Bitmap(data); | ||
| let transform = new ColorTransform(); | ||
| let copied = new Buffer(data); | ||
|
|
||
| bitmap.colorTable = transform.blueShift(bitmap); | ||
|
|
||
| let startToColorTable = copied.slice(0, bitmap.headerSize + 14); | ||
| let subColorTableBuffer = new Buffer(bitmap.colorTable.join(''), 'hex'); | ||
| let colorTableToEnd = copied.slice(data.readInt32LE(10)); | ||
| let testcopy = Buffer.concat([startToColorTable, subColorTableBuffer, colorTableToEnd]); | ||
|
|
||
| fileHelper.writeNew(`${__dirname}/assets/palette-shift-bitmap.bmp`, testcopy, exports.writeNew); | ||
| }; | ||
| fileHelper.initFile(`${__dirname}/assets/palette-bitmap.bmp`, onRead); | ||
| }; | ||
|
|
||
| exports.rotateBitmap = () => { | ||
| let onRead = (err, data) => { | ||
| fileHelper.initFile(`${__dirname}/assets/palette-bitmap.bmp`, (err, data) => { | ||
| if (err) throw err; | ||
|
|
||
| let bitmap = new Bitmap(data); | ||
| let transform = new ColorTransform(); | ||
| let copied = new Buffer(data); | ||
|
|
||
| bitmap.pixelTable = transform.rotateImage(bitmap); | ||
|
|
||
| let startPixelTable = copied.slice(0, bitmap.pixelArrayStart); | ||
| let pixelArrBuffer = new Buffer(bitmap.pixelTable.join(''), 'hex'); | ||
| let testcopy = Buffer.concat([startPixelTable, pixelArrBuffer]); | ||
|
|
||
| fileHelper.writeNew(`${__dirname}/assets/palette-rotate-bitmap.bmp`, testcopy, exports.writeNew); | ||
| }); | ||
| }; | ||
| fileHelper.initFile(`${__dirname}/assets/palette-bitmap.bmp`, onRead); | ||
| }; | ||
|
|
||
| exports.colorShiftBitmap(); | ||
| exports.invertBitmap(); | ||
| exports.rotateBitmap(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| 'use strict'; | ||
|
|
||
| const fs = require('fs'); | ||
|
|
||
| module.exports = exports = {}; | ||
|
|
||
| exports.initFile = (path, callback) => { | ||
| fs.readFile(path, (err, data) => { | ||
| if(err) return callback(err); | ||
| return callback(null, data); | ||
| }); | ||
| }; | ||
|
|
||
| exports.writeNew = (path, data) => { | ||
| return fs.writeFile(path, data, (err, data) => { | ||
| if(err) return err; | ||
| return data; | ||
| }); | ||
| }; | ||
|
|
||
| exports.eraseFile = (path) => { | ||
| return fs.writeFile(path, '', (err, data) => { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this does change the contents of the file there is a better command from fs.unlink that would have erased the file entirely. Leaving it as an empty string can make it seem like there is still a relevant file. |
||
| if(err) return err; | ||
| return data; | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| 'use strict'; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bitmap constructor looks good. |
||
|
|
||
| module.exports = function Bitmap (data) { | ||
| this.type = data.toString('utf-8', 0, 2); | ||
| this.size = data.readInt32LE(2); | ||
| this.pixelArrayStart = data.readInt32LE(10); | ||
| this.headerSize = data.readInt32LE(14); | ||
| this.bitsPerPixel = data.readInt32LE(28); | ||
| this.width = data.readInt32LE(18); | ||
| this.height = data.readInt32LE(22); | ||
|
|
||
| this.colorTableStart = this.headerSize + 14; | ||
| this.colorTable = data.toString('hex', this.colorTableStart, this.pixelArrayStart).match(/.{1,8}/g); | ||
| this.rowWidth = Math.ceil(((this.bitsPerPixel * this.width + 31) / 32) * 4); | ||
| this.pixelTable = data.toString('hex', this.pixelArrayStart, this.size).match(/.{1,2}/g); | ||
|
|
||
| this.colorMap = this.pixelTable.map(function (pix) { | ||
| return parseInt(pix); | ||
| }); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| 'use strict'; | ||
|
|
||
| const ColorTransform = module.exports = function () {}; | ||
|
|
||
| ColorTransform.prototype.invertColors = function (bitmap) { | ||
| let colorTable = bitmap.colorTable; | ||
|
|
||
| return colorTable.map(function (hexColor) { | ||
| let hexArray = hexColor.match(/.{1,2}/g); | ||
|
|
||
| let r = parseInt(hexArray[0], 16); | ||
| let g = parseInt(hexArray[1], 16); | ||
| let b = parseInt(hexArray[2], 16); | ||
| let invertR = (255 - r).toString(16); | ||
| let invertG = (255 - g).toString(16); | ||
| let invertB = (255 - b).toString(16); | ||
|
|
||
| let invertArray = [invertR, invertG, invertB, '00']; | ||
|
|
||
| invertArray.forEach(function (val, i) { | ||
| if (val.length === 1) { | ||
| invertArray[i] = '0' + invertArray[i]; | ||
| } | ||
| }); | ||
| invertArray = invertArray.join(''); | ||
| return invertArray; | ||
| }); | ||
| }; | ||
|
|
||
| ColorTransform.prototype.blueShift = function (bitmap) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to be turning the bmp very red. |
||
| let colorTable = bitmap.colorTable; | ||
| return colorTable.map(function (hexColor) { | ||
| let hexArray = hexColor.match(/.{1,2}/g); | ||
|
|
||
| let r = parseInt(hexArray[0], 16); | ||
| let g = parseInt(hexArray[1], 16); | ||
| let b = parseInt(hexArray[2], 16); | ||
| let invertR = (Math.ceil(r * 0.1)).toString(16); | ||
| let invertG = (Math.ceil(g * 0.1)).toString(16); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't really an invert. A better var name would be shiftR. |
||
| let invertB = (b).toString(16); | ||
|
|
||
| let colorShiftArray = [invertR, invertG, invertB, '00']; | ||
| colorShiftArray.forEach(function (val, i) { | ||
| if (val.length === 1) { | ||
| colorShiftArray[i] = '0' + colorShiftArray[i]; | ||
| } | ||
| }); | ||
| colorShiftArray = colorShiftArray.join(''); | ||
| return colorShiftArray; | ||
| }); | ||
| }; | ||
|
|
||
| ColorTransform.prototype.rotateImage = function(bitmap) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will handle 180 transforms so a good name for it would be flip rather than rotate. |
||
| let pixelTable = bitmap.pixelTable; | ||
|
|
||
| return pixelTable.reverse(); | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| { | ||
| "name": "04-bitmap_transformer", | ||
| "version": "1.0.0", | ||
| "description": "this project changes a bitmap file into several variations", | ||
| "main": "index.js", | ||
| "directories": { | ||
| "test": "test" | ||
| }, | ||
| "scripts": { | ||
| "test": "mocha" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "git+https://github.com/loganabsher/04-bitmap_transformer.git" | ||
| }, | ||
| "keywords": [ | ||
| "bitmap" | ||
| ], | ||
| "author": "Logan Absher, Luis Manzo, Nick Asmussen", | ||
| "license": "MIT", | ||
| "bugs": { | ||
| "url": "https://github.com/loganabsher/04-bitmap_transformer/issues" | ||
| }, | ||
| "homepage": "https://github.com/loganabsher/04-bitmap_transformer#readme", | ||
| "devDependencies": { | ||
| "chai": "^4.1.0", | ||
| "mocha": "^3.4.2" | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not taking in a path from anywhere on this means that you only have access to one bitmap file and can't test multiple. It would be good to keep this modular in case you want to read other bitmap files.