From de6d887d0e0a53c8cc282e62b588495bf8f675ca Mon Sep 17 00:00:00 2001 From: Shiv Unadkat Date: Thu, 16 Feb 2017 15:03:16 -0800 Subject: [PATCH 1/7] lintrc and gitignore added --- .eslintrc | 21 ++++++++++ .gitignore | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100644 .eslintrc create mode 100644 .gitignore 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 From 9f995890ac5715e419a4c1470198b8542739ef4d Mon Sep 17 00:00:00 2001 From: Shiv Unadkat Date: Thu, 16 Feb 2017 15:09:46 -0800 Subject: [PATCH 2/7] project skeleton laid out --- bitmap-annashivwill/README.md | 41 ++++++++++++++++++ bitmap-annashivwill/img/palette-bitmap.bmp | Bin 0 -> 11078 bytes bitmap-annashivwill/index.js | 0 bitmap-annashivwill/lib/bitmap-file-helper.js | 0 .../model/bitmap-constructor.js | 12 +++++ .../model/color-constructor.js | 0 .../test/bitmap-constructor-test.js | 0 .../test/bitmap-file-helper-test.js | 0 .../test/color-constructor-test.js | 0 9 files changed, 53 insertions(+) create mode 100644 bitmap-annashivwill/README.md create mode 100644 bitmap-annashivwill/img/palette-bitmap.bmp create mode 100644 bitmap-annashivwill/index.js create mode 100644 bitmap-annashivwill/lib/bitmap-file-helper.js create mode 100644 bitmap-annashivwill/model/bitmap-constructor.js create mode 100644 bitmap-annashivwill/model/color-constructor.js create mode 100644 bitmap-annashivwill/test/bitmap-constructor-test.js create mode 100644 bitmap-annashivwill/test/bitmap-file-helper-test.js create mode 100644 bitmap-annashivwill/test/color-constructor-test.js 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/palette-bitmap.bmp b/bitmap-annashivwill/img/palette-bitmap.bmp new file mode 100644 index 0000000000000000000000000000000000000000..97ad0df321f8762c0bf9a7c50cf2f2177a19bd46 GIT binary patch literal 11078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dH zMe!5{228xcfVBRU{7zH2ajoyJ=B7n6(Lgr6qFptgL6 z2A_Tt``Uuvf^@_zeR20HEH%rGYqPBnGGUt+mP6^86B24ATx)QHL==7fFeoR1R+|Qo zSsDr+3Ro7Vmf*K)rj=+c;)!Mf<_`oeK{e5Wo^YyWbMnk$>S|g&ZDKiEfqQt-aGJk^ ziiL+sm01jbOYC+wnKdaD-91a#CBDQsz9L5Q|;*E@A5WJ-<5^fiO zoeBrf+bLp&2i;JPI}Gl#3^WT2*+uShkois*7#@s2ocL&bH~X9TVT1>$Y8T2TWRMRRL@YYwh?xu@7B$^a z<#3>P0d_*uW5aa7D6Nj-5WJZBPDVok5xATcK`yDDpyks%j~&--(=X$sLqB0o7374G zxw$C7wiJs9kr{KZYL^T%n|CUsup7GQ0p+56>}H+XG%E-VSg5kRY8hYEn)1Y`9_8F- zZJAi`C=^d&9T_q$0=BhSN8!UpvFrnhIu$-O@FX34ZHtg-XN+iY4HY1pRYWjC2^ra2VF1KvC zD9iL(weft?8q`u`Y9%eYu$?aKNQ;X3&EHhc>Lh^S(38_m$npw?(vf8Xk?${~7BvF0 zzT+muVwgBgqeDnsi%Axu6F2ckO7yc*km|ssFr8|_PGovfL`9KRZ ziygp4amy-wsz{D=Q;-o>;0IIS5a4`QZ3@jR?^>!nlkJ|I)|oP5<7vuP znMall?=Rsvgb>fG1nhi3gAB9v=BUY)?J?;gPZpIrF*5_qVs~iCBiEoK!Vf2-CnT1+k!q#}}jR4`Dm2$gsdvgsvRj0zm|{KI+ui(#}diBc?X>kQOc^kifi z)-Cf+!PYo7ZL{Ey`Y?{$=B)*rL%TNd)$sDyalMg=bz3r#8`;y&VL+8nMua(gBJgl& zZDTyQ~2i5&|3Fy{Xe=h$87~rCw literal 0 HcmV?d00001 diff --git a/bitmap-annashivwill/index.js b/bitmap-annashivwill/index.js new file mode 100644 index 0000000..e69de29 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/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/color-constructor.js b/bitmap-annashivwill/model/color-constructor.js new file mode 100644 index 0000000..e69de29 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..e69de29 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 From 3a85f2fbf69059b90756e9d91cb0da1acd72599d Mon Sep 17 00:00:00 2001 From: Shiv Unadkat Date: Thu, 16 Feb 2017 17:27:40 -0800 Subject: [PATCH 3/7] all logic sorted out, we chillin --- bitmap-annashivwill/index.js | 25 +++++++++++++++++++ bitmap-annashivwill/package.json | 19 ++++++++++++++ .../test/bitmap-file-helper-test.js | 9 +++++++ 3 files changed, 53 insertions(+) create mode 100644 bitmap-annashivwill/package.json diff --git a/bitmap-annashivwill/index.js b/bitmap-annashivwill/index.js index e69de29..7c0fb18 100644 --- a/bitmap-annashivwill/index.js +++ b/bitmap-annashivwill/index.js @@ -0,0 +1,25 @@ +'use strict'; + +const fs = require('fs'); + +console.log(something.length); + +fs.readFile(`${__dirname}/img/palette-bitmap.bmp`, function(err, data) { + //// ERROR + if (err) throw err; + + /// CORRECT FILE PATH + // Variable Defintions + const bitmap = data; + const bmp = {}; + bmp.bmphead = 14; + bmp.dibstart = bitmap.readInt32LE(14); + bmp.tablestart = bmp.bmphead + bmp.dibstart + 12; //12 is additional byte difference that we need to account for + + // Specific location Points + bmp.colorpalette = bitmap.toString('hex', 54, bmp.tablestart + 1024); + console.log(bmp.colorpalette); + // console.log(typeof(bitmap)); + + // console.log('buffer data bitmap', bitmap); +}); 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-file-helper-test.js b/bitmap-annashivwill/test/bitmap-file-helper-test.js index e69de29..95b6ac3 100644 --- a/bitmap-annashivwill/test/bitmap-file-helper-test.js +++ 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? +*/ From b531d8bbab0758d05bc5b8c50cc2e6434c114cdd Mon Sep 17 00:00:00 2001 From: Will Skelton Date: Fri, 17 Feb 2017 14:08:15 -0800 Subject: [PATCH 4/7] program can now export img. --- bitmap-annashivwill/img/transformed.bmp | Bin 0 -> 11078 bytes bitmap-annashivwill/index.js | 10 +++++----- bitmap-annashivwill/lib/transformations.js | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 bitmap-annashivwill/img/transformed.bmp create mode 100644 bitmap-annashivwill/lib/transformations.js diff --git a/bitmap-annashivwill/img/transformed.bmp b/bitmap-annashivwill/img/transformed.bmp new file mode 100644 index 0000000000000000000000000000000000000000..97ad0df321f8762c0bf9a7c50cf2f2177a19bd46 GIT binary patch literal 11078 zcmeI1vCC~o6~!lD;l%@2EN*oR5z&B!&xb^Ufj~eDgCHp)VxbTT97mSQczLIiCsY!#mCx7OZs=G^bgdv-Q&-u>pxnR8~Xz1E(YbMAeweD%wp z87?n;XpHC8`cC~lH$LqCkA8ZLk9{P6<2iNlr}Fuae`37!{Flb(UVL+W@%4Adr@r^s z@#e4IAHV#=KgSFI`uF(SKYlSD{Ql8+`)6MmpMC4q@yS!hAq{NKtMyECSXr0vd5;0VB$56kII6NMl(l} zu=~|5_d8w^(ps+L1T9KL2FuQ~x5EBG3g9jlMR3|GA_0PmIj57{g2q7PB{WWvyN!@+ zYxoXmT@&7Cx_muj4(UE=N}+|Cvyp_a2{D~XQfagy3Oa{&DQ82_YC(Y*gC~5OL{m(+ zz{QbhkAOQDnO0%(jI+EKM<_%xl_)8mRLMZ|R6Y{F>irYU+nNyM)LC=NEHF^CJPL~3 zWCd32-H$;kgm#O%oVS+Kc{?fbGHinhQ7}n@@t|v9jx+x#Ax1M97sg589P}AUCL;n> ztwL>o){#4I>O)etU?@=G3l?Oit&Y7GNroKq zyr5NOK|M<0EF1wZ2HOO@i|28*y(5c3F7a~H1Ug>8LS6yxoPs{+s4I!Qa8YBcawq|q zwaDOPhYj6+z9?u0j&_P;mGp2kyGcU!Fa#n8`eXKsq!kscqFk z$t}@T!q@@?72pOBD(du)C$PhfhEigAy6;Yz_*WH?2T5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Y)?J?;gPZpIrF*5_qVs~iCBiEoK!Vf2-CnT1+k!q#}}jR4`Dm2$gsdvgsvRj0zm|{KI+ui(#}diBc?X>kQOc^kifi z)-Cf+!PYo7ZL{Ey`Y?{$=B)*rL%TNd)$sDyalMg=bz3r#8`;y&VL+8nMua(gBJgl& zZDTyQ~2i5&|3Fy{Xe=h$87~rCw literal 0 HcmV?d00001 diff --git a/bitmap-annashivwill/index.js b/bitmap-annashivwill/index.js index 7c0fb18..13e8073 100644 --- a/bitmap-annashivwill/index.js +++ b/bitmap-annashivwill/index.js @@ -1,16 +1,19 @@ 'use strict'; const fs = require('fs'); +const transformations = require(`${__dirname}/lib/transformations.js`); -console.log(something.length); +// console.log(something.length); fs.readFile(`${__dirname}/img/palette-bitmap.bmp`, function(err, data) { //// ERROR if (err) throw err; - /// CORRECT FILE PATH // Variable Defintions const bitmap = data; + + transformations.turnOrange(data); + const bmp = {}; bmp.bmphead = 14; bmp.dibstart = bitmap.readInt32LE(14); @@ -18,8 +21,5 @@ fs.readFile(`${__dirname}/img/palette-bitmap.bmp`, function(err, data) { // Specific location Points bmp.colorpalette = bitmap.toString('hex', 54, bmp.tablestart + 1024); - console.log(bmp.colorpalette); - // console.log(typeof(bitmap)); - // console.log('buffer data bitmap', bitmap); }); diff --git a/bitmap-annashivwill/lib/transformations.js b/bitmap-annashivwill/lib/transformations.js new file mode 100644 index 0000000..1b0cf84 --- /dev/null +++ b/bitmap-annashivwill/lib/transformations.js @@ -0,0 +1,21 @@ +'use strict'; + +const fs = require('fs'); +const image = require(`${__dirname}/../index.js`); + +module.exports = exports = {}; + + +exports.exportImg = function(img) { + // console.log(typeof img); + fs.writeFile(`${__dirname}/../img/transformed.bmp`, img, function(err, data) { + if(err) throw err; + }); +} + +exports.turnOrange = function orange(img) { + // img.colorpalette + exports.exportImg(img); + +} +///f From cb06fa48aede0ec5aae061bb696748ffeba6a3b9 Mon Sep 17 00:00:00 2001 From: Will Skelton Date: Fri, 17 Feb 2017 15:07:59 -0800 Subject: [PATCH 5/7] now turning picture black --- bitmap-annashivwill/img/transformed.bmp | Bin 11078 -> 11078 bytes bitmap-annashivwill/index.js | 43 ++++++++++++++++++--- bitmap-annashivwill/lib/transformations.js | 10 +++-- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/bitmap-annashivwill/img/transformed.bmp b/bitmap-annashivwill/img/transformed.bmp index 97ad0df321f8762c0bf9a7c50cf2f2177a19bd46..ddc1f9afac41ee1343a0ba66ac3580a67a4731a2 100644 GIT binary patch delta 18 acmX>Wb}Vdy)yCub%o8v4ZZ=~PPzL~4Y6t%S delta 143 zcmV;A0C4}tR>oG4I)5}EA^$I*#NqG*8obFj{q=liU0rr0I@}V1G6>+5GR_#GeQ6W diff --git a/bitmap-annashivwill/index.js b/bitmap-annashivwill/index.js index 13e8073..cd6ea83 100644 --- a/bitmap-annashivwill/index.js +++ b/bitmap-annashivwill/index.js @@ -12,14 +12,45 @@ fs.readFile(`${__dirname}/img/palette-bitmap.bmp`, function(err, data) { // Variable Defintions const bitmap = data; - transformations.turnOrange(data); +// ========= Will's Work ============ + // Bitmap into string + var bitmapString = bitmap.toString('hex') - const bmp = {}; - bmp.bmphead = 14; - bmp.dibstart = bitmap.readInt32LE(14); - bmp.tablestart = bmp.bmphead + bmp.dibstart + 12; //12 is additional byte difference that we need to account for + // Grab color table + const colorpalette = bitmapString.slice(108, 2156); + + // Turn table black and save to Buffer String + bitmapString = bitmapString.replace(colorpalette, (transformations.turnBlack(colorpalette))); + + console.log(bitmapString.slice(108, 2156)); + + // Change back into Buffer + const newBuffer = Buffer.from(bitmapString, 'hex'); + + // Export new img + transformations.exportImg(newBuffer); + + +// ================================== + + + const start = 14 + bitmap.readInt32LE(14); + const stop = 1078; + // console.log((bitmap.toString('hex', start, stop)).length); + + // const bmp = {}; + // bmp.bmphead = 14; + // bmp.dibstart = bitmap.readInt32LE(14); + // bmp.tablestart = bmp.bmphead + bmp.dibstart + 12; //12 is additional byte difference that we need to account for // Specific location Points - bmp.colorpalette = bitmap.toString('hex', 54, bmp.tablestart + 1024); + // bmp.colorpalette = bitmap.toString('hex', 54, bmp.tablestart + 1024); }); + + + +// bitmapString = bitmap.toString +// colorpalette = bitmapString.slice(108, 2048); +// turnBlack(colorpalette); +// bitmapString.replace( colorpalette, turnBlack(colorpalette); diff --git a/bitmap-annashivwill/lib/transformations.js b/bitmap-annashivwill/lib/transformations.js index 1b0cf84..d2860b5 100644 --- a/bitmap-annashivwill/lib/transformations.js +++ b/bitmap-annashivwill/lib/transformations.js @@ -13,9 +13,11 @@ exports.exportImg = function(img) { }); } -exports.turnOrange = function orange(img) { - // img.colorpalette - exports.exportImg(img); +exports.turnBlack = function orange(tableString) { + // console.log(tableString); + // console.log('f'.repeat(2048)); + return '0'.repeat(2048); + // exports.exportImg(img); } -///f +// From 8f010adcac638ccbeb9134ef644ee140c10676f5 Mon Sep 17 00:00:00 2001 From: Will Skelton Date: Fri, 17 Feb 2017 16:37:16 -0800 Subject: [PATCH 6/7] invert is almost done --- bitmap-annashivwill/index.js | 6 ++--- bitmap-annashivwill/lib/transformations.js | 28 ++++++++++++++++++++-- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/bitmap-annashivwill/index.js b/bitmap-annashivwill/index.js index cd6ea83..675afa0 100644 --- a/bitmap-annashivwill/index.js +++ b/bitmap-annashivwill/index.js @@ -20,15 +20,15 @@ fs.readFile(`${__dirname}/img/palette-bitmap.bmp`, function(err, data) { const colorpalette = bitmapString.slice(108, 2156); // Turn table black and save to Buffer String - bitmapString = bitmapString.replace(colorpalette, (transformations.turnBlack(colorpalette))); + bitmapString = bitmapString.replace(colorpalette, (transformations.invert(colorpalette))); - console.log(bitmapString.slice(108, 2156)); + // console.log(bitmapString.slice(108, 2156)); // Change back into Buffer const newBuffer = Buffer.from(bitmapString, 'hex'); // Export new img - transformations.exportImg(newBuffer); + // transformations.exportImg(newBuffer); // ================================== diff --git a/bitmap-annashivwill/lib/transformations.js b/bitmap-annashivwill/lib/transformations.js index d2860b5..6a63478 100644 --- a/bitmap-annashivwill/lib/transformations.js +++ b/bitmap-annashivwill/lib/transformations.js @@ -13,11 +13,35 @@ exports.exportImg = function(img) { }); } -exports.turnBlack = function orange(tableString) { +exports.turnBlack = function(tableString) { // console.log(tableString); // console.log('f'.repeat(2048)); return '0'.repeat(2048); // exports.exportImg(img); } -// + +exports.invert = function(tableString) { + var invStr = ''; + // console.log(tableString.length); + for (var i = 0; i < tableString.length + 2; i += 2) { + var hexStr = tableString.substring(i, i + 2); + // console.log('hexStr:', hexStr); + + var intNum = parseInt('FF', 16) - parseInt(hexStr, 16); + // console.log('after parseInt:', intNum); + + var hexNum = intNum.toString(16) + // console.log('hexNum.tostr:', hexNum); + // console.log('=================='); + + invStr += hexNum; + // tableString. + + // console.log(i); + + } + // console.log(invStr.length); + + +} From 59a292e0d852141e44f477c57522300de3bc2906 Mon Sep 17 00:00:00 2001 From: Shiv Unadkat Date: Fri, 17 Feb 2017 16:45:06 -0800 Subject: [PATCH 7/7] iteration fixes --- bitmap-annashivwill/lib/transformations.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bitmap-annashivwill/lib/transformations.js b/bitmap-annashivwill/lib/transformations.js index 6a63478..86f00bf 100644 --- a/bitmap-annashivwill/lib/transformations.js +++ b/bitmap-annashivwill/lib/transformations.js @@ -24,8 +24,8 @@ exports.turnBlack = function(tableString) { exports.invert = function(tableString) { var invStr = ''; // console.log(tableString.length); - for (var i = 0; i < tableString.length + 2; i += 2) { - var hexStr = tableString.substring(i, i + 2); + for (var i = 0; i < tableString.length; i += 2) { + var hexStr = tableString.slice(i, i + 1); // console.log('hexStr:', hexStr); var intNum = parseInt('FF', 16) - parseInt(hexStr, 16); @@ -41,7 +41,7 @@ exports.invert = function(tableString) { // console.log(i); } - // console.log(invStr.length); + console.log(invStr.length); }