Пример #1
0
ImageData* ImageData::create(const IntSize& size,
                             DOMUint8ClampedArray* byteArray) {
  CheckedNumeric<int> dataSize = 4;
  dataSize *= size.width();
  dataSize *= size.height();
  if (!dataSize.IsValid())
    return nullptr;

  if (dataSize.ValueOrDie() < 0 ||
      static_cast<unsigned>(dataSize.ValueOrDie()) > byteArray->length())
    return nullptr;

  return new ImageData(size, byteArray);
}
Пример #2
0
ImageData* ImageData::create(const IntSize& size) {
  CheckedNumeric<int> dataSize = 4;
  dataSize *= size.width();
  dataSize *= size.height();
  if (!dataSize.IsValid() || dataSize.ValueOrDie() < 0)
    return nullptr;

  DOMUint8ClampedArray* byteArray =
      DOMUint8ClampedArray::createOrNull(dataSize.ValueOrDie());
  if (!byteArray)
    return nullptr;

  return new ImageData(size, byteArray);
}
Пример #3
0
ImageData* ImageData::create(unsigned width,
                             unsigned height,
                             ExceptionState& exceptionState) {
  if (!width || !height) {
    exceptionState.throwDOMException(
        IndexSizeError, String::format("The source %s is zero or not a number.",
                                       width ? "height" : "width"));
    return nullptr;
  }

  CheckedNumeric<unsigned> dataSize = 4;
  dataSize *= width;
  dataSize *= height;
  if (!dataSize.IsValid() || static_cast<int>(width) < 0 ||
      static_cast<int>(height) < 0) {
    exceptionState.throwDOMException(
        IndexSizeError,
        "The requested image size exceeds the supported range.");
    return nullptr;
  }

  DOMUint8ClampedArray* byteArray =
      DOMUint8ClampedArray::createOrNull(dataSize.ValueOrDie());
  if (!byteArray) {
    exceptionState.throwDOMException(V8Error,
                                     "Out of memory at ImageData creation");
    return nullptr;
  }

  return new ImageData(IntSize(width, height), byteArray);
}