lib/bitmap.js
function Bitmap(width, height, bytesPerPixel, endianness) {
  if (!(this instanceof Bitmap)) {
    return new Bitmap(width, height, bytesPerPixel, endianness);
  }

  // Validate bytes per pixel
  if (bytesPerPixel === undefined) {
    bytesPerPixel = 1;
  }
  if (bytesPerPixel !== 1 && bytesPerPixel !== 2 && bytesPerPixel !== 4) {
    throw new Error("Invalid number of bytes per pixel: " + bytesPerPixel);
  }

  this._width = width;
  this._height = height;
  this._bytesPerPixel = bytesPerPixel;
  this._endianness = endianness === undefined ? Endianness.BIG : endianness;
  this._palette = bytesPerPixel === 1 ? [].concat(DEFAULT_PALETTE) : [];
  this._data = new Buffer(width * height * bytesPerPixel);
  saveReadAndWriteFunction.call(this);

  // Initialize to white
  this.clear(0xFF);
}
function Bitmap(width, height, bytesPerPixel, endianness) {
  if (!(this instanceof Bitmap)) {
    return new Bitmap(width, height, bytesPerPixel, endianness);
  }

  // Validate bytes per pixel
  if (bytesPerPixel === undefined) {
    bytesPerPixel = 1;
  }
  if (bytesPerPixel !== 1 && bytesPerPixel !== 2 && bytesPerPixel !== 4) {
    throw new Error("Invalid number of bytes per pixel: " + bytesPerPixel);
  }

  this._width = width;
  this._height = height;
  this._bytesPerPixel = bytesPerPixel;
  this._endianness = endianness === undefined ? Endianness.BIG : endianness;
  this._palette = bytesPerPixel === 1 ? [].concat(DEFAULT_PALETTE) : [];
  this._data = new Buffer(width * height * bytesPerPixel);
  saveReadAndWriteFunction.call(this);

  // Initialize to white
  this.clear(0xFF);
}
function Bitmap ( width , height , bytesPerPixel , endianness ) { if ( ! ( this instanceof Bitmap ) ) { return new Bitmap ( width , height , bytesPerPixel , endianness ) ; } // Validate bytes per pixel if ( bytesPerPixel === undefined ) { bytesPerPixel = 1 ; } if ( bytesPerPixel !== 1 && bytesPerPixel !== 2 && bytesPerPixel !== 4 ) { throw new Error ( "Invalid number of bytes per pixel: " + bytesPerPixel ) ; } this . _width = width ; this . _height = height ; this . _bytesPerPixel = bytesPerPixel ; this . _endianness = endianness === undefined ? Endianness . BIG : endianness ; this . _palette = bytesPerPixel === 1 ? [ ] . concat ( DEFAULT_PALETTE ) : [ ] ; this . _data = new Buffer ( width * height * bytesPerPixel ) ; saveReadAndWriteFunction . call ( this ) ; // Initialize to white this . clear ( 0xFF ) ; }
Creates an in-memory bitmap. Bitmaps with 1 byte per pixel are handled in conjunction with a
palette.

@class
@param {number} width
@param {number} height
@param {number} [bytesPerPixel=1] Possible values: <code>1</code>, <code>2</code>,
<code>4</code>
@param {Endianness} [endianness=BIG] Use big- or little-endian when storing multiple bytes per
pixel
@constructor
Creates an in - memory bitmap . Bitmaps with 1 byte per pixel are handled in conjunction with a palette .