Resizes a cavnas to match its CSS displayed size.
@param {Canvas} canvas canvas to resize.
@param {boolean?} useDevicePixelRatio if true canvas will be
created to match devicePixelRatio.
@memberOf module:Misc
545580
function(canvas, useDevicePixelRatio) {
    var mult = useDevicePixelRatio ? window.devicePixelRatio : 1;
    mult = mult || 1;
    var width  = Math.floor(canvas.clientWidth  * mult);
    var height = Math.floor(canvas.clientHeight * mult);
    if (canvas.width !== width ||
        canvas.height !== height) {
      canvas.width = width;
      canvas.height = height;
      return true;
    }
  }
1340113
public void setSize (int width, int height) {
    rootElement.getStyle().setWidth(width, Unit.PX);
    rootElement.getStyle().setHeight(height, Unit.PX);
    // the frame buffer may be larger (or smaller) than the logical size, depending on whether
    // we're on a HiDPI display, or how the game has configured things (maybe they're scaling down
    // from native resolution to improve performance)
    Scale fbScale = new Scale(frameBufferPixelRatio);
    canvas.setWidth(fbScale.scaledCeil(width));
    canvas.setHeight(fbScale.scaledCeil(height));
    // set the canvas's CSS size to the logical size; the browser works in logical pixels
    canvas.getStyle().setWidth(width, Style.Unit.PX);
    canvas.getStyle().setHeight(height, Style.Unit.PX);
    viewportChanged(canvas.getWidth(), canvas.getHeight());
  }
2453
private void fitImageToView() {
        Drawable drawable = getDrawable();
        if (drawable == null || drawable.getIntrinsicWidth() == 0 || drawable.getIntrinsicHeight() == 0) {
            return;
        }
        if (matrix == null || prevMatrix == null) {
            return;
        }

        int drawableWidth = drawable.getIntrinsicWidth();
        int drawableHeight = drawable.getIntrinsicHeight();

        //
        // Scale image for view
        //
        float scaleX = (float) viewWidth / drawableWidth;
        float scaleY = (float) viewHeight / drawableHeight;

        switch (mScaleType) {
            case CENTER:
                scaleX = scaleY = 1;
                break;

            case CENTER_CROP:
                scaleX = scaleY = Math.max(scaleX, scaleY);
                break;

            case CENTER_INSIDE:
                scaleX = scaleY = Math.min(1, Math.min(scaleX, scaleY));

            case FIT_CENTER:
                scaleX = scaleY = Math.min(scaleX, scaleY);
                break;

            case FIT_XY:
                break;

            default:
                //
                // FIT_START and FIT_END not supported
                //
                throw new UnsupportedOperationException("TouchImageView does not support FIT_START or FIT_END");

        }

        //
        // Center the image
        //
        float redundantXSpace = viewWidth - (scaleX * drawableWidth);
        float redundantYSpace = viewHeight - (scaleY * drawableHeight);
        matchViewWidth = viewWidth - redundantXSpace;
        matchViewHeight = viewHeight - redundantYSpace;
        if (!isZoomed() && !imageRenderedAtLeastOnce) {
            //
            // Stretch and center image to fit view
            //
            matrix.setScale(scaleX, scaleY);
            matrix.postTranslate(redundantXSpace / 2, redundantYSpace / 2);
            normalizedScale = 1;

        } else {
            //
            // These values should never be 0 or we will set viewWidth and viewHeight
            // to NaN in translateMatrixAfterRotate. To avoid this, call savePreviousImageValues
            // to set them equal to the current values.
            //
            if (prevMatchViewWidth == 0 || prevMatchViewHeight == 0) {
                savePreviousImageValues();
            }

            prevMatrix.getValues(m);

            //
            // Rescale Matrix after rotation
            //
            m[Matrix.MSCALE_X] = matchViewWidth / drawableWidth * normalizedScale;
            m[Matrix.MSCALE_Y] = matchViewHeight / drawableHeight * normalizedScale;

            //
            // TransX and TransY from previous matrix
            //
            float transX = m[Matrix.MTRANS_X];
            float transY = m[Matrix.MTRANS_Y];

            //
            // Width
            //
            float prevActualWidth = prevMatchViewWidth * normalizedScale;
            float actualWidth = getImageWidth();
            translateMatrixAfterRotate(Matrix.MTRANS_X, transX, prevActualWidth, actualWidth, prevViewWidth, viewWidth, drawableWidth);

            //
            // Height
            //
            float prevActualHeight = prevMatchViewHeight * normalizedScale;
            float actualHeight = getImageHeight();
            translateMatrixAfterRotate(Matrix.MTRANS_Y, transY, prevActualHeight, actualHeight, prevViewHeight, viewHeight, drawableHeight);

            //
            // Set the matrix to the adjusted scale and translate values.
            //
            matrix.setValues(m);
        }
        fixTrans();
        setImageMatrix(matrix);
    }
1229876
function scaleCanvas(scaleX, scaleY) {
         var w = this.canvas.width * scaleX;
         var h = this.canvas.height * scaleY; // adjust CSS style for High-DPI devices

         if (me.device.devicePixelRatio > 1) {
           this.canvas.style.width = w / me.device.devicePixelRatio + "px";
           this.canvas.style.height = h / me.device.devicePixelRatio + "px";
         } else {
           this.canvas.style.width = w + "px";
           this.canvas.style.height = h + "px";
         }

         this.compositor.setProjection(this.canvas.width, this.canvas.height);
       }
637554
function(size) {
      var t = this,
          css = _.clone(t.get('css')),
          parsedCss = $.parseStyleString(css['.nm-cv-viewport'] || '');
      if (!parsedCss.height && !parsedCss.width) {
        parsedCss.height = size.height + 'px';
        parsedCss.width = size.width + 'px';
        css['.nm-cv-viewport'] = $.makeStyleString(parsedCss);
        t.set({css: css});
      }
    }
1014190
function (size) {
        this.canvasContext.canvas.width = size.w;
        this.canvasContext.canvas.height = size.h;

        this.size = size;
    }
1173708
function(image, position, options) {
        this._drawOnCanvasContext(options, function(g) {
            this._setImageStyles(g, options);
            g.drawImage(image, position[0], position[1]);
            return true;
        });
    }
240558
function () {
            var levels = [{
                    url: this._image.src,
                    /* IE8 fix since it has no naturalWidth and naturalHeight */
                    width: Object.prototype.hasOwnProperty.call(this._image, 'naturalWidth') ? this._image.naturalWidth : this._image.width,
                    height:  Object.prototype.hasOwnProperty.call(this._image, 'naturalHeight') ? this._image.naturalHeight : this._image.height
                }];

            if (!this.buildPyramid || !$.supportsCanvas || !this.useCanvas) {
                // We don't need the image anymore. Allows it to be GC.
                delete this._image;
                return levels;
            }

            /* IE8 fix since it has no naturalWidth and naturalHeight */
            var currentWidth = Object.prototype.hasOwnProperty.call(this._image, 'naturalWidth') ? this._image.naturalWidth : this._image.width;
            var currentHeight = Object.prototype.hasOwnProperty.call(this._image, 'naturalHeight') ? this._image.naturalHeight : this._image.height;


            var bigCanvas = document.createElement("canvas");
            var bigContext = bigCanvas.getContext("2d");

            bigCanvas.width = currentWidth;
            bigCanvas.height = currentHeight;
            bigContext.drawImage(this._image, 0, 0, currentWidth, currentHeight);
            // We cache the context of the highest level because the browser
            // is a lot faster at downsampling something it already has
            // downsampled before.
            levels[0].context2D = bigContext;
            // We don't need the image anymore. Allows it to be GC.
            delete this._image;

            if ($.isCanvasTainted(bigCanvas)) {
                // If the canvas is tainted, we can't compute the pyramid.
                return levels;
            }

            // We build smaller levels until either width or height becomes
            // 1 pixel wide.
            while (currentWidth >= 2 && currentHeight >= 2) {
                currentWidth = Math.floor(currentWidth / 2);
                currentHeight = Math.floor(currentHeight / 2);
                var smallCanvas = document.createElement("canvas");
                var smallContext = smallCanvas.getContext("2d");
                smallCanvas.width = currentWidth;
                smallCanvas.height = currentHeight;
                smallContext.drawImage(bigCanvas, 0, 0, currentWidth, currentHeight);

                levels.splice(0, 0, {
                    context2D: smallContext,
                    width: currentWidth,
                    height: currentHeight
                });

                bigCanvas = smallCanvas;
                bigContext = smallContext;
            }
            return levels;
        }
1284913
function(width, height) {
      this.getPos(true);
      this.translateOffsetX = this.translateOffsetY = 0;
      this.scaleOffsetX = this.scaleOffsetY = 1;
      for(var i=0, l=this.canvases.length; i<l; i++) {
        this.canvases[i].resize(width, height);
      }
      var style = this.element.style;
      style.width = width + 'px';
      style.height = height + 'px';
      if(this.labelContainer)
        this.labelContainer.style.width = width + 'px';
    }
448231
@Override protected void resize() {
        width  = clock.getWidth() - clock.getInsets().getLeft() - clock.getInsets().getRight();
        height = clock.getHeight() - clock.getInsets().getTop() - clock.getInsets().getBottom();

        if (aspectRatio * width > height) {
            width = 1 / (aspectRatio / height);
        } else if (1 / (aspectRatio / height) > width) {
            height = aspectRatio * width;
        }

        if (width > 0 && height > 0) {
            pane.setMaxSize(width, height);
            pane.relocate((clock.getWidth() - height) * 0.5, (clock.getHeight() - height) * 0.5);

            canvas.setWidth(width);
            canvas.setHeight(height);

            dotSize     = height * 0.045455;
            spacer      = height * 0.022727;
            digitWidth  = 8 * dotSize + 7 * spacer;
            digitHeight = 15 * dotSize + 14 * spacer;
            digitSpacer = height * 0.09090909;
        }
    }
890443
function recolorImageWithCanvasContext(context, img, colorFunc) {
  if (!defined(context)) {
    throw new DeveloperError("No context for image recoloring.");
  }

  // Copy the image contents to the canvas
  context.clearRect(0, 0, context.canvas.width, context.canvas.height);
  context.drawImage(img, 0, 0);
  var image = context.getImageData(
    0,
    0,
    context.canvas.width,
    context.canvas.height
  );
  image = ImageryProviderHooks.recolorImage(image, colorFunc);
  return image;
}
761927
function bracketDevicePixelRatio() {
      var i, scale,
        brackets = [ 1, 1.3, 1.5, 2, 2.6, 3 ],
        baseRatio = window.devicePixelRatio || 1;

      for ( i = 0; i < brackets.length; i++ ) {
        scale = brackets[ i ];

        if ( scale >= baseRatio || ( baseRatio - scale ) < 0.1 ) {
          return scale;
        }
      }
      return brackets[ brackets.length - 1 ];
    }
266809
function() {
        canvasWidth = $(window).width();
        canvasHeight = $(window).height();
        if (supportsCanvas) {
          $canvas[0].width = canvasWidth;
          $canvas[0].height = canvasHeight;
        }
        $container.width(canvasWidth);
        $container.height(canvasHeight);
      }
492046
function() {
        var context;
        if (this.cacheImageRecord) {
            context = this.cacheImageRecord.getRenderedContext();
        } else if (this.context2D) {
            context = this.context2D;
        } else {
            $.console.warn(
                '[Tile.drawCanvas] attempting to get tile scale %s when tile\'s not cached',
                this.toString());
            return 1;
        }
        return context.canvas.width / (this.size.x * $.pixelDensityRatio);
    }
1112296
function startCameraDefaultResolution () {
  let facingMode = facingModeSelectElement.value;
  cameraPhoto.startCamera(FACING_MODES[facingMode])
    .then(() => {
      let log =
          `Camera started with default resolution and ` +
          `prefered facingMode : ${facingMode}`;
      console.log(log);
    })
    .catch((error) => {
      console.error('Camera not started!', error);
    });
}
420902
function mergeCanvasRect(rect, result) {
            if (rect) {
                if (rect.hasOwnProperty("width")) {
                    result.canvasWidth = rect.width;
                }
                
                if (rect.hasOwnProperty("height")) {
                    result.canvasHeight = rect.height;
                }

                if (rect.hasOwnProperty("x")) {
                    result.canvasOffsetX = rect.x;
                }

                if (rect.hasOwnProperty("y")) {
                    result.canvasOffsetY = rect.y;
                }
            }
        }
1182945
function resize(img, width=0, height=0, type='png', quality=0.75) {
    let mime
    switch(type.toLowerCase()) {
    case 'jpg':
    case 'jpeg':
    case 'image/jpeg':
        mime = 'image/jpeg'
        break
    case 'png':
    case 'image/png':
    default:
        mime = 'image/png'
    }
    return resizePromise(img, width, height).then(
        canvas => canvas2Blob(canvas, { type: mime, quality })
        //canvas => canvas2DataUrl(canvas, { type: mime, quality })
    )
}