Skip to content

Commit

Permalink
fix: TypeScript types for avif config
Browse files Browse the repository at this point in the history
  • Loading branch information
Brooooooklyn committed Aug 30, 2022
1 parent 3bd0393 commit 29b17f8
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
4 changes: 2 additions & 2 deletions benchmark/gradient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import b from 'benny'

import { createCanvas, Canvas } from 'canvas'
// @ts-expect-error
import { Canvas as SkiaCanvas } from 'skia-canvas'

import { createCanvas as skiaCreateCanvas } from '../index'
Expand All @@ -23,7 +22,7 @@ function drawGradient(factory: (width: number, height: number) => Canvas) {
ctx.fillRect(20, 20, 200, 100)

if (canvas instanceof SkiaCanvas) {
canvas.toBufferSync('image/png')
canvas.toBufferSync('png')
} else {
// @ts-expect-error
canvas.async = false
Expand All @@ -36,6 +35,7 @@ export function gradient() {
'Draw gradient',

b.add('skia-canvas', () => {
// @ts-expect-error
drawGradient((w, h) => new SkiaCanvas(w, h))
}),

Expand Down
49 changes: 49 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,58 @@ export interface SvgCanvas {
}

export interface AvifConfig {
/** 0-100 scale, 100 is lossless */
quality?: number
/** 0-100 scale */
alphaQuality?: number
/** rav1e preset 1 (slow) 10 (fast but crappy), default is 4 */
speed?: number
/** How many threads should be used (0 = match core count) */
threads?: number
/** set to '4:2:0' to use chroma subsampling, default '4:4:4' */
chromaSubsampling?: ChromaSubsampling
}
/**
* https://en.wikipedia.org/wiki/Chroma_subsampling#Types_of_sampling_and_subsampling
* https://developer.mozilla.org/en-US/docs/Web/Media/Formats/Video_concepts
*/
export enum ChromaSubsampling {
/**
* Each of the three Y'CbCr components has the same sample rate, thus there is no chroma subsampling. This scheme is sometimes used in high-end film scanners and cinematic post-production.
* Note that "4:4:4" may instead be wrongly referring to R'G'B' color space, which implicitly also does not have any chroma subsampling (except in JPEG R'G'B' can be subsampled).
* Formats such as HDCAM SR can record 4:4:4 R'G'B' over dual-link HD-SDI.
*/
Yuv444 = 0,
/**
* The two chroma components are sampled at half the horizontal sample rate of luma: the horizontal chroma resolution is halved. This reduces the bandwidth of an uncompressed video signal by one-third.
* Many high-end digital video formats and interfaces use this scheme:
* - [AVC-Intra 100](https://en.wikipedia.org/wiki/AVC-Intra)
* - [Digital Betacam](https://en.wikipedia.org/wiki/Betacam#Digital_Betacam)
* - [Betacam SX](https://en.wikipedia.org/wiki/Betacam#Betacam_SX)
* - [DVCPRO50](https://en.wikipedia.org/wiki/DV#DVCPRO) and [DVCPRO HD](https://en.wikipedia.org/wiki/DV#DVCPRO_HD)
* - [Digital-S](https://en.wikipedia.org/wiki/Digital-S)
* - [CCIR 601](https://en.wikipedia.org/wiki/Rec._601) / [Serial Digital Interface](https://en.wikipedia.org/wiki/Serial_digital_interface) / [D1](https://en.wikipedia.org/wiki/D-1_(Sony))
* - [ProRes (HQ, 422, LT, and Proxy)](https://en.wikipedia.org/wiki/Apple_ProRes)
* - [XDCAM HD422](https://en.wikipedia.org/wiki/XDCAM)
* - [Canon MXF HD422](https://en.wikipedia.org/wiki/Canon_XF-300)
*/
Yuv422 = 1,
/**
* n 4:2:0, the horizontal sampling is doubled compared to 4:1:1,
* but as the **Cb** and **Cr** channels are only sampled on each alternate line in this scheme, the vertical resolution is halved.
* The data rate is thus the same.
* This fits reasonably well with the PAL color encoding system, since this has only half the vertical chrominance resolution of [NTSC](https://en.wikipedia.org/wiki/NTSC).
* It would also fit extremely well with the [SECAM](https://en.wikipedia.org/wiki/SECAM) color encoding system,
* since like that format, 4:2:0 only stores and transmits one color channel per line (the other channel being recovered from the previous line).
* However, little equipment has actually been produced that outputs a SECAM analogue video signal.
* In general, SECAM territories either have to use a PAL-capable display or a [transcoder](https://en.wikipedia.org/wiki/Transcoding) to convert the PAL signal to SECAM for display.
*/
Yuv420 = 2,
/**
* What if the chroma subsampling model is 4:0:0?
* That says to use every pixel of luma data, but that each row has 0 chroma samples applied to it. The resulting image, then, is comprised solely of the luminance data—a greyscale image.
*/
Yuv400 = 3,
}

export class Canvas {
Expand Down

1 comment on commit 29b17f8

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmark

Benchmark suite Current: 29b17f8 Previous: 3bd0393 Ratio
Draw house#skia-canvas 20 ops/sec (±1.45%) 20 ops/sec (±0.45%) 1
Draw house#node-canvas 17 ops/sec (±1.27%) 22 ops/sec (±1.3%) 1.29
Draw house#@napi-rs/skia 18 ops/sec (±1.35%) 19 ops/sec (±0.74%) 1.06
Draw gradient#skia-canvas 20 ops/sec (±0.46%) 18.9 ops/sec (±1.55%) 0.94
Draw gradient#node-canvas 17 ops/sec (±0.28%) 20.4 ops/sec (±1.22%) 1.20
Draw gradient#@napi-rs/skia 18 ops/sec (±0.54%) 18.5 ops/sec (±0.5%) 1.03

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.