How to use the bmp-js.encode function in bmp-js

To help you get started, we’ve selected a few bmp-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github retroplasma / earth-reverse-engineering / lib / decode-texture.js View on Github external
const bytes = tex.bytes
			const buf = new Buffer(bytes);
			const abuf = new Uint8Array(buf).buffer;
			const imageDataView = new DataView(abuf, 0, bytes.length);
			const rgbaData = decodeDXT(imageDataView, tex.width, tex.height, 'dxt1');
			const bmpData = [];

			// ABGR
			for (let i = 0; i < rgbaData.length; i += 4) {
				bmpData.push(255);
				bmpData.push(rgbaData[i + 2]);
				bmpData.push(rgbaData[i + 1]);
				bmpData.push(rgbaData[i + 0]);
			}

			const rawData = bmp.encode({
				data: bmpData, width: tex.width, height: tex.height,
			});
			
			return { extension: 'bmp', buffer: rawData.data }
		default:
			throw `unknown textureFormat ${tex.textureFormat}`
	}
}
github oliver-moran / jimp / index.js View on Github external
if (this._rgba) png.data = new Buffer(this.bitmap.data);
            else png.data = compositeBitmapOverBackground(this).data; // when PNG doesn't support alpha
            
            StreamToBuffer(png.pack(), function (err, buffer) {
                return cb.call(that, null, buffer);
            });
            break;

        case Jimp.MIME_JPEG:
            // composite onto a new image so that the background shows through alpha channels
            var jpeg = JPEG.encode(compositeBitmapOverBackground(this), this._quality);
            return cb.call(this, null, jpeg.data);

        case Jimp.MIME_BMP:
            // composite onto a new image so that the background shows through alpha channels
            var bmp = BMP.encode(compositeBitmapOverBackground(this));
            return cb.call(this, null, bmp.data);

        default:
            return cb.call(this, "Unsupported MIME type: " + mime);
    }

    return this;
};
github GridSpace / grid-host / src / image.js View on Github external
let ex = Math.round((x+1) * div + xoff);
                    let bidx = (y * th + x) * 4;
                    let pixval = png.averageBlock(dx,dy,ex,ey);
                    if (Math.abs(pixval[0] - pixval[1]) + Math.abs(pixval[2] - pixval[1]) < 5) {
                        pixval[0] = Math.round(pixval[0] * 0.8);
                        pixval[1] = Math.round(pixval[1] * 0.8);
                        pixval[2] = Math.round(pixval[2] * 0.8);
                        pixval[3] = Math.round(pixval[3] * 0.8);
                    }
                    buf[bidx+0] = pixval[0];
                    buf[bidx+1] = pixval[1];
                    buf[bidx+2] = pixval[2];
                    buf[bidx+3] = pixval[3];
                }
            }
            resolve(BMP.encode({data:buf, width:th, height:tw}));
        });
    });
github oliver-moran / jimp / packages / type-bmp / src / index.js View on Github external
const encode = image => BMP.encode(toAGBR(image)).data;

bmp-js

A pure javascript BMP encoder and decoder

MIT
Latest version published 7 years ago

Package Health Score

65 / 100
Full package analysis

Popular bmp-js functions