Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a1d47ef
basic files set up
loganabsher Jul 20, 2017
283dd41
renamed eslintrc to .eslintrc
loganabsher Jul 20, 2017
a37bf28
following directory structure
loganabsher Jul 20, 2017
a4f70d5
changing gh branch format
loganabsher Jul 20, 2017
7c36b70
data flow working
loganabsher Jul 20, 2017
2765d38
data flow working
loganabsher Jul 20, 2017
356d8ef
updates constructor func to get meta data from bitmap
nickjaz Jul 20, 2017
38c5360
adds color table to the bitmap constructor
nickjaz Jul 20, 2017
8377617
produces colorTable and pixelTable arrays, minor naming changes
prolifick1 Jul 21, 2017
0e3d1a2
added writeFile func, started tests
loganabsher Jul 21, 2017
daab686
modified constructor file to be more exportable
loganabsher Jul 21, 2017
33332ba
Merge pull request #1 from loganabsher/logan-friday
loganabsher Jul 21, 2017
94679b5
makes some incomplete progress in color transforming
prolifick1 Jul 21, 2017
5d5d5f3
logan-firday
loganabsher Jul 21, 2017
d869848
invert color transform and debugging
nickjaz Jul 21, 2017
c7f6d7b
adds a rotation transform
nickjaz Jul 22, 2017
4a90cd4
writes bitmap to a new file, also adds a color shift transform
prolifick1 Jul 22, 2017
5e0da7a
writes inverted image to bitmap
prolifick1 Jul 23, 2017
19450b4
merges nick and luis work
prolifick1 Jul 23, 2017
0b84713
adds red color shift transform
prolifick1 Jul 23, 2017
4db0412
writes the rotated image
nickjaz Jul 23, 2017
c370a73
fixed testing bug
loganabsher Jul 23, 2017
0004ee3
working on testing
loganabsher Jul 24, 2017
917bcd5
Merge branch 'logan-monday' into nick-sunday
loganabsher Jul 24, 2017
fa7214a
Merge pull request #2 from loganabsher/nick-sunday
loganabsher Jul 24, 2017
7561d01
basic testing done
loganabsher Jul 24, 2017
4451a51
Merge pull request #3 from loganabsher/logan-monday
loganabsher Jul 24, 2017
787fc06
added new test for constructor, cleaned up code
loganabsher Jul 24, 2017
13386e4
Merge pull request #4 from loganabsher/logan-monday
loganabsher Jul 24, 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 .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
16 changes: 16 additions & 0 deletions .eslintrc
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"
}
127 changes: 127 additions & 0 deletions .gitignore
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
Binary file added assets/palette-invert-bitmap.bmp
Binary file not shown.
Binary file added assets/palette-rotate-bitmap.bmp
Binary file not shown.
Binary file added assets/palette-shift-bitmap.bmp
Binary file not shown.
Binary file added assets/palette-write-bitmap.bmp
Binary file not shown.
72 changes: 72 additions & 0 deletions index.js
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 = () => {
Copy link
Copy Markdown

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.

let onRead = (err, data) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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();
26 changes: 26 additions & 0 deletions lib/bitmap-file-helper.js
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) => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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;
});
};
20 changes: 20 additions & 0 deletions model/bitmap-constructor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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);
});
};
57 changes: 57 additions & 0 deletions model/color-constructor.js
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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The 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();
};
29 changes: 29 additions & 0 deletions package.json
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"
}
}
Loading