Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julian Frosch
BezLinApp
Commits
e3b9114b
Commit
e3b9114b
authored
Feb 01, 2016
by
Julian Frosch
Browse files
Tested bmp-js for reading a bitmap
parent
c8add2b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
e3b9114b
...
...
@@ -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>
...
...
js/script.js
View file @
e3b9114b
...
...
@@ -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!
"
);
});
};
});
js/test/bmpD.js
0 → 100644
View file @
e3b9114b
/**
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
;
js/test/bmpDTester.js
0 → 100644
View file @
e3b9114b
/**
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
;
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment