How to use the bmp-js.decode 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 DaanBroekhof / JoroDox / app / utils / IndexedBmp.js View on Github external
function parse(path) {
  const data = bmp.decode(jetpack.read(path, 'buffer'));

  const wrapX = true;
  const wrapY = false;

  const indexMap = {};
  const pixels = [];
  const colorNrs = [];
  let colorNr = 0;

  for (let i = 0; i < data.width * data.height; i += 1) {
    // Todo: color order can be RGB or BGR - need to fix so it always is RGB
    const colorName = data.data[i * 4] + ',' + data.data[(i * 4) + 1] + ',' + data.data[(i * 4) + 2];
    if (!indexMap[colorName]) {
      indexMap[colorName] = {
        nr: colorNr,
        color_name: colorName,
github oliver-moran / jimp / index.js View on Github external
that.bitmap = {
                    data: new Buffer(data.data),
                    width: data.width,
                    height: data.height
                };
                return cb.call(that, null, that);
            });
            break;

        case Jimp.MIME_JPEG:
            this.bitmap = JPEG.decode(data);
            exifRotate(this, data); // EXIF data
            return cb.call(this, null, this);

        case Jimp.MIME_BMP:
            this.bitmap = BMP.decode(data);
            return cb.call(this, null, this);

        default:
            return throwError.call(this, "Unsupported MIME type: " + mime, cb);
    }
}
github naptha / tesseract.js / src / worker-script / utils / setImage.js View on Github external
module.exports = (TessModule, api, image) => {
  const buf = Buffer.from(Array.from({ ...image, length: Object.keys(image).length }));
  const type = fileType(buf);
  let bytesPerPixel = 0;
  let data = null;
  let pix = null;
  let w = 0;
  let h = 0;

  /*
   * Although leptonica should support reading bmp, there is a bug of "compressed BMP files".
   * As there is no solution, we need to use bmp-js for now.
   * @see https://groups.google.com/forum/#!topic/tesseract-ocr/4mPD9zTxdxE
   */
  if (type && type.mime === 'image/bmp') {
    const bmpBuf = bmp.decode(buf);
    data = TessModule._malloc(bmpBuf.data.length * Uint8Array.BYTES_PER_ELEMENT);
    TessModule.HEAPU8.set(bmpBuf.data, data);
    w = bmpBuf.width;
    h = bmpBuf.height;
    bytesPerPixel = 4;
  } else {
    const ptr = TessModule._malloc(buf.length * Uint8Array.BYTES_PER_ELEMENT);
    TessModule.HEAPU8.set(buf, ptr);
    pix = TessModule._pixReadMem(ptr, buf.length);
    if (TessModule.getValue(pix + (7 * 4), 'i32') === 0) {
      /*
       * Set a yres default value to prevent warning from tesseract
       * See kMinCredibleResolution in tesseract/src/ccstruct/publictypes.h
       */
      TessModule.setValue(pix + (7 * 4), 300, 'i32');
    }
github oliver-moran / jimp / packages / type-bmp / src / index.js View on Github external
const decode = data => fromAGBR(BMP.decode(data));
const encode = image => BMP.encode(toAGBR(image)).data;

bmp-js

A pure javascript BMP encoder and decoder

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis

Popular bmp-js functions