shaozilee / bmp-js

A pure javascript BMP encoder and decoder for node.js
MIT License
87 stars 46 forks source link

Image Size #21

Open hipstersmoothie opened 6 years ago

hipstersmoothie commented 6 years ago
const fs = require('fs')
const bmp = require('bmp-js');

const buffer = fs.readFileSync('./exampleImages/windows95.bmp')
const data = bmp.decode(buffer)

const outBuffer = bmp.encode(data)
fs.writeFileSync('test.bmp', outBuffer.data)

console.log(buffer.byteLength, data.data.byteLength, outBuffer.data.byteLength)

OUTPUT:

129078 512000 384054

almost a 3x increase!

shaozilee commented 6 years ago

@hipstersmoothie Yes,your bmp file encoding with 8bit maybe,due tobmp-js's default encoding is 24bit,so you get 3x increase of bytes

hipstersmoothie commented 6 years ago

Can i change the default encoding to match the original?

shaozilee commented 6 years ago

@hipstersmoothie sorry about it. I writed 24bit encoding as default encoding,not write other mode.but you can write other encoder for it.

hipstersmoothie commented 6 years ago

do you think the current encoder could be extended to do 8 and 16 bit? or is it pretty hard coded to 24?