deno/ext/canvas/lib.rs
Nathan Whitaker 9379a74e08
Some checks are pending
ci / publish canary (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions
ci / build libs (push) Blocked by required conditions
chore: update to edition 2024 (#29923)
2025-07-02 17:59:39 -07:00

50 lines
1.6 KiB
Rust

// Copyright 2018-2025 the Deno authors. MIT license.
mod image_ops;
mod op_create_image_bitmap;
pub use image;
use image::ColorType;
use op_create_image_bitmap::op_create_image_bitmap;
#[derive(Debug, thiserror::Error, deno_error::JsError)]
pub enum CanvasError {
/// Image formats that is 32-bit depth are not supported currently due to the following reasons:
/// - e.g. OpenEXR, it's not covered by the spec.
/// - JPEG XL supported by WebKit, but it cannot be called a standard today.
/// https://github.com/whatwg/mimesniff/issues/143
///
#[class(type)]
#[error("Unsupported color type and bit depth: '{0:?}'")]
UnsupportedColorType(ColorType),
#[class("DOMExceptionInvalidStateError")]
#[error("Cannot decode image '{0}'")]
InvalidImage(image::ImageError),
#[class("DOMExceptionInvalidStateError")]
#[error(
"The chunk data is not big enough with the specified width: {0} and height: {1}"
)]
NotBigEnoughChunk(u32, u32),
#[class("DOMExceptionInvalidStateError")]
#[error("The width: {0} or height: {1} could not be zero")]
InvalidSizeZero(u32, u32),
#[class(generic)]
#[error(transparent)]
Lcms(#[from] lcms2::Error),
#[class(generic)]
#[error(transparent)]
Image(#[from] image::ImageError),
}
impl CanvasError {
/// Convert an [`image::ImageError`] to an [`CanvasError::InvalidImage`].
fn image_error_to_invalid_image(error: image::ImageError) -> Self {
CanvasError::InvalidImage(error)
}
}
deno_core::extension!(
deno_canvas,
deps = [deno_webidl, deno_web, deno_webgpu],
ops = [op_create_image_bitmap],
lazy_loaded_esm = ["01_image.js"],
);