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
134fbf31
Commit
134fbf31
authored
Feb 01, 2016
by
Julian Frosch
Browse files
Changed from bmp to png-support via get-pixels
parent
e3b9114b
Changes
4
Hide whitespace changes
Inline
Side-by-side
index.html
View file @
134fbf31
...
...
@@ -14,7 +14,7 @@
Drag your svg-file here!
</div>
<div
id=
"
b
mpHolder"
class=
"holder"
>
<div
id=
"m
a
pHolder"
class=
"holder"
>
Drag your bmp-file here!
</div>
...
...
js/script.js
View file @
134fbf31
...
...
@@ -34,32 +34,29 @@ $(function(){
};
// We also have a portion in our GUI where the user can drop the BMP-file
var
b
mpHolder
=
document
.
getElementById
(
'
b
mpHolder
'
);
b
mpHolder
.
ondragover
=
function
()
{
var
m
a
pHolder
=
document
.
getElementById
(
'
m
a
pHolder
'
);
m
a
pHolder
.
ondragover
=
function
()
{
return
false
;
};
b
mpHolder
.
ondragleave
=
b
mpHolder
.
ondragend
=
function
()
{
m
a
pHolder
.
ondragleave
=
m
a
pHolder
.
ondragend
=
function
()
{
return
false
;
};
// When the user drops the file
b
mpHolder
.
ondrop
=
function
(
e
)
{
m
a
pHolder
.
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!
"
);
});
var
getPixels
=
require
(
"
get-pixels
"
);
getPixels
(
file
.
path
,
function
(
err
,
pixels
)
{
if
(
err
)
{
console
.
log
(
err
);
return
;
}
// NDArray Format: ((x),(y),(r,g,b,a))
// Access pixel with ....get(x,y,c)
console
.
log
(
"
Red
"
,
pixels
.
get
(
0
,
0
,
0
),
pixels
.
get
(
0
,
0
,
1
),
pixels
.
get
(
0
,
0
,
2
),
pixels
.
get
(
0
,
0
,
3
));
console
.
log
(
"
Blue
"
,
pixels
.
get
(
1
,
0
,
0
),
pixels
.
get
(
1
,
0
,
1
),
pixels
.
get
(
1
,
0
,
2
),
pixels
.
get
(
1
,
0
,
3
));
console
.
log
(
"
Black
"
,
pixels
.
get
(
2
,
0
,
0
),
pixels
.
get
(
2
,
0
,
1
),
pixels
.
get
(
2
,
0
,
2
),
pixels
.
get
(
2
,
0
,
3
));
})
};
});
js/test/bmpD.js
deleted
100644 → 0
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
deleted
100644 → 0
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