'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.createImage = createImage;
exports.getImageFromContext = getImageFromContext;
exports.getImagePixelData = getImagePixelData;
// TODO - only works in browser
/* global document */

function createImage(width, height) {
  var image = document.createElement('img');
  image.width = width;
  image.height = height;
  image.style.position = 'absolute';
  image.style.top = 0;
  image.style.left = 0;
  return image;
}

function getImageFromContext(gl) {
  var image = createImage(gl.drawingBufferWidth, gl.drawingBufferHeight);
  return new Promise(function (resolve) {
    image.onload = function () {
      resolve(image);
    };
    image.src = gl.canvas.toDataURL();
  });
}

function getImagePixelData(image) {
  var width = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
  var height = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;

  width = width || image.width;
  height = height || image.height;

  var canvas = document.createElement('canvas');
  canvas.width = width;
  canvas.height = height;
  var ctx = canvas.getContext('2d');
  ctx.drawImage(image, 0, 0, width, height);
  return ctx.getImageData(0, 0, width, height);
}
//# sourceMappingURL=browser-image-utils.js.map