Fixed image decoding

This commit is contained in:
Andrew Stephens
2023-01-15 16:39:49 -05:00
parent bd9f5773d5
commit 382b192aca

View File

@@ -162,22 +162,27 @@ class ASDitheredImage extends HTMLElement {
if (this.image_loading_ == true) {
return
}
this.image_loading_ = true
const image = new Image()
image.onload = (() => {
this.image_loading_ = false
image.src = this.getAttribute("src")
// image.onerror is old and (literally) busted - it does not file on decode errors (ie if the src does not point to a valid image)
// The new way is promise based - possibly better
image.decode().then((() => {
this.original_image_ = image
this.ignore_next_resize_ = true
this.canvas_.style.aspectRatio = this.original_image_.width + "/" + this.original_image_.height
console.log("Setting Aspect Ratio to ", this.style.aspectRatio)
this.force_refresh_ = true
this.requestUpdate()
}).bind(this)
image.onerror = (() => {
this.image_loading_ == false
}).bind(this))
.catch(((decodeError) => {
console.log("Error decoding image: ", decodeError)
this.original_image_ = undefined
}).bind(this)
this.image_loading_ = true
image.src = this.getAttribute("src")
}).bind(this))
.finally((() => {
this.image_loading_ = false
}).bind(this))
}
repaintImage() {