Commit e3b9114b authored by Julian Frosch's avatar Julian Frosch
Browse files

Tested bmp-js for reading a bitmap

parent c8add2b2
......@@ -14,6 +14,10 @@
Drag your svg-file here!
</div>
<div id="bmpHolder" class="holder">
Drag your bmp-file here!
</div>
<p class="output"></p>
<script>window.$ = window.jQuery = require('./js/jquery.min.js');</script>
......
......@@ -32,4 +32,34 @@ $(function(){
});
};
// We also have a portion in our GUI where the user can drop the BMP-file
var bmpHolder = document.getElementById('bmpHolder');
bmpHolder.ondragover = function () {
return false;
};
bmpHolder.ondragleave = bmpHolder.ondragend = function () {
return false;
};
// When the user drops the file
bmpHolder.ondrop = function (e) {
e.preventDefault();
var file = e.dataTransfer.files[0];
// TODO: check for filetype (maybe via regex)
var bmp = require("bmp-js"), fs = require('fs');
var bmpBuffer = fs.readFileSync(file.path);
var bmpData = bmp.decode(bmpBuffer);
//*** Note: bmpData={data:Buffer,width:Number,height:Height}
// create test-helper-classes and let them do their work
var BMPDTester = require("./js/test/bmpDTester.js");
var tester = new BMPDTester();
var BMPD = require("./js/test/bmpD.js");
var bmpD = new BMPD(bmpData);
tester.doSomething(bmpD, function(err) {
console.log("It did something!");
});
};
});
/**
Test for a class containing bmpData and providing a getPixel-function
*/
var method = BMPD.prototype;
// empty constructor
function BMPD(bmpData) {
this._bmpData = bmpData;
this._channels = bmpData.data.length / (bmpData.height * bmpData.width);
this._lineMul = bmpData.width * this._channels;
}
method.getPixel = function(x, y) {
return this._bmpData.data.readUInt8(x * this._channels + this._lineMul * y);
}
module.exports = BMPD;
/**
Tester: passing the bmpD around for further usage
*/
var method = BMPDTester.prototype;
// empty constructor
function BMPDTester() {
}
method.doSomething = function(data, callback) {
// getting some pixels
var bmpD = data;
console.log(bmpD.getPixel(277,30));
console.log(bmpD.getPixel(276,30));
console.log(bmpD.getPixel(277,29));
callback(null);
}
module.exports = BMPDTester;
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment