mirror of
https://github.com/CesiumGS/obj2gltf.git
synced 2024-12-02 13:00:29 -05:00
45 lines
1000 B
JavaScript
45 lines
1000 B
JavaScript
|
"use strict";
|
||
|
var fs = require('fs');
|
||
|
var path = require('path');
|
||
|
|
||
|
module.exports = imageInfo;
|
||
|
|
||
|
function getChannels(colorType) {
|
||
|
switch (colorType) {
|
||
|
case 0: // greyscale
|
||
|
return 1;
|
||
|
case 2: // RGB
|
||
|
return 3;
|
||
|
case 4: // greyscale + alpha
|
||
|
return 2;
|
||
|
case 6: // RGB + alpha
|
||
|
return 4;
|
||
|
default:
|
||
|
return 3;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function imageInfo(imagePath, done) {
|
||
|
fs.readFile(imagePath, function(err, data) {
|
||
|
if (err) {
|
||
|
throw(err);
|
||
|
}
|
||
|
|
||
|
var info = {
|
||
|
transparent : false,
|
||
|
channels : 3,
|
||
|
data : data
|
||
|
};
|
||
|
|
||
|
if (path.extname(imagePath) === '.png') {
|
||
|
// Color type is encoded in the 25th bit of the png
|
||
|
var colorType = data[25];
|
||
|
var channels = getChannels(colorType);
|
||
|
info.channels = channels;
|
||
|
info.transparent = (channels === 4);
|
||
|
}
|
||
|
|
||
|
done(info);
|
||
|
});
|
||
|
}
|