Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ext/canvas): OffscreenCanvas #23773

Draft
wants to merge 14 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
fix
  • Loading branch information
crowlKats committed May 11, 2024
commit f4fe67a322364045cad5d3cb904abc4cb4ca64c2
2 changes: 0 additions & 2 deletions cli/tsc/dts/lib.deno_webgpu.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1789,8 +1789,6 @@ declare interface GPUCanvasConfiguration {
viewFormats?: GPUTextureFormat[];
colorSpace?: "srgb" | "display-p3";
alphaMode?: GPUCanvasAlphaMode;
width: number;
height: number;
}
/**
* @category GPU
Expand Down
1 change: 1 addition & 0 deletions ext/canvas/01_image.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ webidl.converters["ImageBitmapOptions"] = webidl.createDictionaryConverter(
],
);

/** images are stored as RGBA8 */
const _bitmapData = Symbol("[[bitmapData]]");
const _detached = Symbol("[[detached]]");
class ImageBitmap {
Expand Down
14 changes: 6 additions & 8 deletions ext/canvas/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.

use deno_core::error::type_error;
use deno_core::error::AnyError;
use deno_core::op2;
use deno_core::ToJsBuffer;
use image::imageops::FilterType;
use image::ColorType;
use image::GenericImageView;
use image::ImageDecoder;
use image::ImageEncoder;
use image::Pixel;
use image::RgbImage;
use image::RgbaImage;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -47,14 +44,15 @@ fn op_image_process(
#[buffer] buf: &[u8],
#[serde] args: ImageProcessArgs,
) -> Result<ToJsBuffer, AnyError> {
let view = RgbImage::from_vec(args.width, args.height, buf.to_vec()).unwrap();
let view =
RgbaImage::from_vec(args.width, args.height, buf.to_vec()).unwrap();

let surface = if !(args.width == args.surface_width
&& args.height == args.surface_height
&& args.input_x == 0
&& args.input_y == 0)
{
let mut surface = RgbImage::new(args.surface_width, args.surface_height);
let mut surface = RgbaImage::new(args.surface_width, args.surface_height);

image::imageops::overlay(&mut surface, &view, args.input_x, args.input_y);

Expand Down Expand Up @@ -107,7 +105,7 @@ fn op_image_process(
}
}

Ok(image_out.to_vec().into())
Ok(image_out.into_raw().into())
}

#[derive(Debug, Serialize)]
Expand All @@ -126,7 +124,7 @@ fn op_image_decode_png(#[buffer] buf: &[u8]) -> Result<DecodedPng, AnyError> {
let (width, height) = image.dimensions();

Ok(DecodedPng {
data: image.to_rgb8().into_raw().into(),
data: image.into_rgba8().into_raw().into(),
width,
height,
})
Expand All @@ -142,7 +140,7 @@ fn op_image_encode_png(
let mut out = vec![];
let png = image::codecs::png::PngEncoder::new(&mut out);
if png
.write_image(buf, width, height, ColorType::Rgb8)
.write_image(buf, width, height, ColorType::Rgba8)
.is_err()
{
return Ok(None);
Expand Down
1 change: 1 addition & 0 deletions ext/web/16_image_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ webidl.converters["ImageDataSettings"] = webidl.createDictionaryConverter(
],
);

/** images are stored as RGBA8 */
const _data = Symbol("[[data]]");
const _width = Symbol("[[width]]");
const _height = Symbol("[[height]]");
Expand Down