How to use bmp-js - 8 common examples

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 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 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;
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 6 years ago

Package Health Score

67 / 100
Full package analysis

Popular bmp-js functions