Skip to content

Commit 4d83777

Browse files
committed
Use an OffscreenCanvas where applicable.
Resolves blueimp#104
1 parent 5969919 commit 4d83777

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

js/load-image-orientation.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ Exif orientation values to correctly display the letter F:
8484
// Check if the browser supports automatic image orientation:
8585
$.orientation = img.width === 2 && img.height === 3
8686
if ($.orientation) {
87-
var canvas = $.createCanvas(1, 1)
87+
var canvas = $.createCanvas(1, 1, true)
8888
var ctx = canvas.getContext('2d')
8989
ctx.drawImage(img, 1, 1, 1, 1, 0, 0, 1, 1)
9090
// Check if the source image coordinates (sX, sY, sWidth, sHeight) are

js/load-image-scale.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@
2727

2828
var originalTransform = loadImage.transform
2929

30-
loadImage.createCanvas = function (width, height) {
30+
loadImage.createCanvas = function (width, height, offscreen) {
31+
if (offscreen && window.OffscreenCanvas) {
32+
return new OffscreenCanvas(width, height)
33+
}
3134
var canvas = document.createElement('canvas')
3235
canvas.width = width
3336
canvas.height = height
@@ -247,7 +250,7 @@
247250
// Write the complete source image to an intermediate canvas first:
248251
tmp = img
249252
// eslint-disable-next-line no-param-reassign
250-
img = loadImage.createCanvas(width, height)
253+
img = loadImage.createCanvas(width, height, true)
251254
loadImage.drawImage(
252255
tmp,
253256
img,
@@ -270,7 +273,8 @@
270273
while (sourceWidth * downsamplingRatio > destWidth) {
271274
canvas = loadImage.createCanvas(
272275
sourceWidth * downsamplingRatio,
273-
sourceHeight * downsamplingRatio
276+
sourceHeight * downsamplingRatio,
277+
true
274278
)
275279
loadImage.drawImage(
276280
img,

0 commit comments

Comments
 (0)