Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
95626c6
Created scaffolding for project
ejdelrio Jul 20, 2017
c489e10
Created scaffolding for project
ejdelrio Jul 20, 2017
286e45e
Created js bitmap object constructor using buffer from bitmap image :D
ejdelrio Jul 20, 2017
362287e
Modifying bitmap object constructor
ejdelrio Jul 20, 2017
b34a554
Modified Bitmap constructor to include color table
ejdelrio Jul 20, 2017
5641cc0
got it to print in red
Jamesbillard12 Jul 22, 2017
da4478d
added greyscale function
Jamesbillard12 Jul 22, 2017
5246449
...
ejdelrio Jul 23, 2017
b806b49
Refactoring james-branch
ejdelrio Jul 23, 2017
a92c830
Created color phases
ejdelrio Jul 23, 2017
8ac8a88
Created color phases
ejdelrio Jul 23, 2017
d1b9c6e
Made revisions to object constructors.
ejdelrio Jul 23, 2017
b91272a
required transformation functions
ejdelrio Jul 23, 2017
78cf5de
Added a blackout transformation
ejdelrio Jul 23, 2017
d7d83f7
Succesfully plugged in transformation module and completed 4 transfor…
ejdelrio Jul 23, 2017
085b64c
Merge pull request #1 from ejdelrio/eddie
ejdelrio Jul 23, 2017
b55268c
Succesfully plugged in transformation module and completed 4 transfor…
ejdelrio Jul 23, 2017
c10585e
Merge pull request #2 from ejdelrio/eddie
ejdelrio Jul 23, 2017
e8b2726
Added bitmap object and transformation requirments to index.js
ejdelrio Jul 23, 2017
28f6a99
Merge pull request #3 from ejdelrio/eddie-test
ejdelrio Jul 23, 2017
85a04a3
Added more transformations
ejdelrio Jul 23, 2017
6d85e0c
Merge pull request #4 from ejdelrio/eddie-test
ejdelrio Jul 23, 2017
75bf05f
Refactored transformer modify method
ejdelrio Jul 23, 2017
46c5eac
Created grey scale conversion
ejdelrio Jul 23, 2017
d2fd907
Refactored greyScale transformation :D
ejdelrio Jul 23, 2017
10401e4
Added inversion transformation
ejdelrio Jul 23, 2017
d0deb99
refactored constructor
ejdelrio Jul 23, 2017
7b64576
Refactored transformer and bitmap files. removed unneeded object cons…
ejdelrio Jul 23, 2017
7e3142d
Merge pull request #5 from ejdelrio/experiment
ejdelrio Jul 23, 2017
bceb6d4
Creates: Bitmap Constructor Test
Loaye Jul 24, 2017
9791a0d
adds contrusctor test
Loaye Jul 24, 2017
a1bcf05
Refactored helper function in modify method
ejdelrio Jul 24, 2017
300dd3e
Merge pull request #7 from ejdelrio/experiment
ejdelrio Jul 24, 2017
09a4145
adds test
Loaye Jul 24, 2017
b4cacda
fixes improper indents
Loaye Jul 24, 2017
55595d3
Refactored modify some more :D
ejdelrio Jul 24, 2017
f55f0a9
Merge pull request #6 from ejdelrio/jake
ejdelrio Jul 24, 2017
86cb6cc
Merge branch 'jake' of https://github.com/ejdelrio/04-bitmap_transfor…
ejdelrio Jul 24, 2017
4fe766d
Made bitmap exportable module with sub methods
ejdelrio Jul 24, 2017
56cdca5
Refactored test
ejdelrio Jul 24, 2017
5f8521b
Refactored test
ejdelrio Jul 24, 2017
b5e05ed
in bitmap-test.js I moved the done() in the function blocks
Jamesbillard12 Jul 24, 2017
0a6562e
fixed merge issues and the position of the done() in bitmap-test.js
Jamesbillard12 Jul 24, 2017
ebff65c
added gitignore eslintrc eslintignore
Jamesbillard12 Jul 24, 2017
f78a190
added eddy's changes to the bitmap file
Jamesbillard12 Jul 24, 2017
e44f95f
fixed spelling of strict
Jamesbillard12 Jul 24, 2017
617ea59
fixed testing issues
Jamesbillard12 Jul 24, 2017
e77e7dc
code is functioning how it should again
Jamesbillard12 Jul 24, 2017
db26c6e
Merge pull request #9 from ejdelrio/experiment
ejdelrio Jul 24, 2017
4b4a517
Merge branch 'day-four' into james-tests
ejdelrio Jul 24, 2017
20e03fb
Merge pull request #10 from ejdelrio/james-tests
ejdelrio Jul 24, 2017
1ee5555
Removed node_modules
ejdelrio Jul 24, 2017
f6f9cd1
Began working on transformer test
ejdelrio Jul 24, 2017
81a2cf2
Recreated the package.JSON file
ejdelrio Jul 24, 2017
a1c728d
Adding modify method tests
ejdelrio Jul 24, 2017
b9f02ca
Created modify method test that passed successfully
ejdelrio Jul 24, 2017
7226f0d
Restarted transformer test :(
ejdelrio Jul 24, 2017
a5ab5ec
completed transformer test
ejdelrio Jul 24, 2017
4419a8e
Adjusted whitespace of transformer test
ejdelrio Jul 24, 2017
4e3f3eb
Refactored transformer test
ejdelrio Jul 24, 2017
9fc33f0
Edited white space on transformer.js
ejdelrio Jul 24, 2017
f1681fb
Rewrote both tests :/
ejdelrio Jul 24, 2017
596ac82
Created readme
ejdelrio Jul 25, 2017
976b96d
Created readme
ejdelrio Jul 25, 2017
0c21dd1
Merge pull request #11 from ejdelrio/eddie-submission
ejdelrio Jul 25, 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
101 changes: 40 additions & 61 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,61 +1,40 @@
![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-` + `<team name>` **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

## Learning Objectives
* students will be able to manipulate binary data using the node.js `Buffer` class
* students will be able to architect modular solutions to solving problems

## Resources
* [Bitmap Specification](https://en.wikipedia.org/wiki/BMP_file_format)
* [NodeJS Buffer docs](https://nodejs.org/api/buffer.html)

#### Feature Tasks

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

#### Suggested Directory Structure (this is optional):
* suggested directory structure:
- **index.js**
- **lib**
- bitmap file helper
- **model**
- bitmap constructor
- color constructor
- **test**
- bitmap file helper test
- bitmap constructor test
- color constructor test

#### Rubric:
* **tests:** 3pts
* **package.json:** 2pts
* **read bitmap meta data:** 5pts
* **successfully apply transforms:** 5pts
* **project design and organization:** 5pts
-----Bitmap Transformer-----

Overview: Bitmap transformer reads a bitmap file and applies one of ten transformations to the file. The modified file is saved as a separate entity.
The project is separated into two major components and a test. Additionally, there is a directory of assets which contains the original bitmap image as well as the modified duplicates.

The directory branch is as follows:

bitmapper_ram-rod
|
|--assets
|
|--lib
|
|--model
|
|--node_modules
|
|--test

-----Directory Overview-----

---assets---

*Houses all bitmap originals and modified duplicates*

---model---

bitmap.js module: Exports the bitmapper object which models bitmaps as javaScript objects. The bitmapper objects properties are described below:

Bitmap : serves as an object constructor. All of bitmaps properties correspond to meta data that is interpreted from the bitmap image as buffer housing hexi-decimal values using node's native fs module. properties also hold information that indicates the start and end points of various sections of the file. The original buffer is stored as a property of the instantiated object.

Bitmap.newFile : method of the Bitmap constructor that takes a string as a parameter. The string will serve as the file name for a new image. The stored buffer in the object will be used to write the new file.

renderImage : Wrapper for node's native fs module. Takes a path, a callback and a file name as parameters. The path will be used with fs.readFile to retrieve a buffer from a bitmap file. The buffer will be instantiated as a new Bitmap object The callback will come from the transformer.js module. This dictates what type of transformation to apply to the buffer. Finally, the name will be passed to the instantiated Bitmap's newFile method.

---lib---

transformer.js module: exports the transform object which applies 1 of 10 different transformations to a Bitmap object that is passed as a parameter. The transform object properties are described below:

modify : Serves as the primary function in transformer.js. All other methods will serve as a wrapper for modify. Modify requires 4 parameters; a Bitmap object, and 3 callbacks. Each callback will be applied to one of the 3 portions of a hex color; red, green and blue. The Bitmap object is iterated over using the stored integers that represent the start and end position of the color palette. The iterations increment by 4. One for red, green, blue and the padding. The Bitmap's stored buffer uses it's readUInt8 method on i - 3, i - 2, and i - 1. to return a value between 0 and 255. Those values are then passed to the callbacks. The return of the call back is then written back into the buffer at it's relative position using Buffer.writeUint8.
5 changes: 5 additions & 0 deletions bitmap-ram-rod/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
**/node_modules/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
21 changes: 21 additions & 0 deletions bitmap-ram-rod/.eslintrc
Original file line number Diff line number Diff line change
@@ -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"
}
136 changes: 136 additions & 0 deletions bitmap-ram-rod/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
# Created by https://www.gitignore.io/api/osx,vim,node,macos,windows

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


### OSX ###

# Icon must end with two \r

# Thumbnails

# Files that might appear in the root of a volume

# Directories potentially created on remote AFP share

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

### 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,vim,node,macos,windows
Binary file added bitmap-ram-rod/assets/palette-bitmap-blackOut.bmp
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added bitmap-ram-rod/assets/palette-bitmap-invert.bmp
Binary file not shown.
Binary file added bitmap-ram-rod/assets/palette-bitmap-noBlue.bmp
Binary file not shown.
Binary file added bitmap-ram-rod/assets/palette-bitmap-noGreen.bmp
Binary file not shown.
Binary file added bitmap-ram-rod/assets/palette-bitmap-noRed.bmp
Binary file not shown.
Binary file added bitmap-ram-rod/assets/palette-bitmap-redShift.bmp
Binary file not shown.
Binary file added bitmap-ram-rod/assets/palette-bitmap-whiteOut.bmp
Binary file not shown.
File renamed without changes.
13 changes: 13 additions & 0 deletions bitmap-ram-rod/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

const bitmapper = require('./model/bitmap.js');
const transform = require('./lib/transformer.js');

let transformations = Object.keys(transform);
let fileName = 'palette-bitmap';

console.log(bitmapper);

for(let i = 1; i < transformations.length; i++) {
bitmapper(`./assets/${fileName}.bmp`, transform[transformations[i]], `${fileName}-${transformations[i]}`);
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 should be bitmap.renderImage() I believe as that allows it to create the files and bitmapper is just an object with properties not a function.

}
100 changes: 100 additions & 0 deletions bitmap-ram-rod/lib/transformer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
'use strict';

const transform = module.exports = {};

transform.modify = (parent, blueCallback, greenCallback, redCallback) => {

const helper = (bmp, position) => (callback) => (...ind) => {
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 is a very interesting construct on how to do this so props for creativity. You may want to be careful that you aren't adding in complexity just to be complex and show off what you can do. There are definitely simpler ways to do this that will work just as well and won't add as many calls to the stack and layer this so much.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I applied the helper to clean up the callback calls in the for loop. Originally it was a lot of content per line which made readability difficult. Now that I look at it, I definitely could consolidate the helper function into a single stack. That's how it was originally.

Copy link
Copy Markdown
Author

@ejdelrio ejdelrio Jul 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like this right?


  const helper = (bmp, position, callback, ...ind) => {
    let hexColors = ind.map(hex => bmp.readUInt8(hex));

    return bmp.writeUInt8(callback(...hexColors), position);
  };
  let start = parent.colorTableStartPoint, end = parent.colorTableEndPoint;

  for (let i = 3 + start; i < end; i+=4) {
    helper(parent.buffer, i - 3, blueCallback, i-3, i-2, i-1);
    helper(parent.buffer, i - 2, greenCallback, i-2, i-3, i-1);
    helper(parent.buffer, i - 1, redCallback, i-1, i-2, i-3);
  }
};```

let hexColors = [bmp.readUInt8(ind[0]), bmp.readUInt8(ind[1]), bmp.readUInt8(ind[2])];

return bmp.writeUInt8(callback(...hexColors), position);
};
let start = parent.colorTableStartPoint, end = parent.colorTableEndPoint;

for (let i = 3 + start; i < end; i+=4) {
helper(parent.buffer, i - 3)(blueCallback)(i-3, i-2, i-1);
helper(parent.buffer, i - 2)(greenCallback)(i-2, i-3, i-1);
helper(parent.buffer, i - 1)(redCallback)(i-1, i-2, i-3);
}
};

transform.blueShift = function(buffer) {
transform.modify(buffer,
hexBlue => hexBlue,
() => 0,
() => 0
);
};

transform.redShift = function(buffer) {
transform.modify(buffer,
() => 0,
() => 0,
hexRed => hexRed
);
};

transform.greenShift = function(buffer) {
transform.modify(buffer,
() => 0,
hexGreen => hexGreen,
() => 0
);
};

transform.noGreen = function(buffer) {
transform.modify(buffer,
(blue) => blue,
() => 0,
(red) => red
);
};

transform.noBlue = function(buffer) {
transform.modify(buffer,
() => 0,
(green) => green,
(red) => red
);
};

transform.noRed = function(buffer) {
transform.modify(buffer,
(blue) => blue,
(green) => green,
() => 0
);
};

transform.blackOut = function(buffer) {
transform.modify(buffer,
() => 0,
() => 0,
() => 0
);
};

transform.whiteOut = function(buffer) {
transform.modify(buffer,
() => 255,
() => 255,
() => 255
);
};

transform.greyScale = function(buffer) {
transform.modify(buffer,
(first, second, third) => (first + second + third) / 3,
(first, second) => second,
(first, second, third) => third
);
};

transform.invert = function(buffer) {
let helper = (val) => 255 - val;
transform.modify(buffer,
helper,
helper,
helper
);
};
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the transforms look good.

Loading