resizeImage method

dynamic resizeImage(
  1. dynamic image,
  2. dynamic needsPowerOfTwo,
  3. dynamic needsNewCanvas,
  4. dynamic maxSize,
)

Implementation

resizeImage(image, needsPowerOfTwo, needsNewCanvas, maxSize) {
  var scale = 1;

  // handle case if texture exceeds max size

  if (image.width > maxSize || image.height > maxSize) {
    scale = maxSize / Math.max<num>(image.width, image.height);
  }

  // only perform resize if necessary

  // if ( scale < 1 || needsPowerOfTwo == true ) {

  // 	// only perform resize for certain image types

  // 	if ( ( typeof HTMLImageElement != 'null' && image instanceof HTMLImageElement ) ||
  // 		( typeof HTMLCanvasElement != 'null' && image instanceof HTMLCanvasElement ) ||
  // 		( typeof ImageBitmap != 'null' && image instanceof ImageBitmap ) ) {

  // 		var floor = needsPowerOfTwo ? MathUtils.floorPowerOfTwo : Math.floor;

  // 		var width = floor( scale * image.width );
  // 		var height = floor( scale * image.height );

  // 		if ( _canvas == null ) _canvas = createCanvas( width, height );

  // 		// cube textures can't reuse the same canvas

  // 		var canvas = needsNewCanvas ? createCanvas( width, height ) : _canvas;

  // 		canvas.width = width;
  // 		canvas.height = height;

  // 		var context = canvas.getContext( '2d' );
  // 		context.drawImage( image, 0, 0, width, height );

  // 		print( 'THREE.WebGLRenderer: Texture has been resized from (' + image.width + 'x' + image.height + ') to (' + width + 'x' + height + ').' );

  // 		return canvas;

  // 	} else {

  // 		if ( 'data' in image ) {

  // 			print( 'THREE.WebGLRenderer: Image in DataTexture is too big (' + image.width + 'x' + image.height + ').' );

  // 		}

  // 		return image;

  // 	}

  // }

  return image;
}