| 701 | // RGBA buffer resize |
| 702 | // |
| 703 | async resizeBuffer (options: ResizeBufferOptions): Promise<Uint8Array> { |
| 704 | const opts = Object.assign({}, DEFAULT_RESIZE_OPTS, options) |
| 705 | |
| 706 | // Legacy `.quality` option |
| 707 | if (Object.prototype.hasOwnProperty.call(opts, 'quality')) { |
| 708 | const quality = opts.quality |
| 709 | if (typeof quality !== 'number' || quality < 0 || quality > 3) { |
| 710 | throw new Error(`Pica: .quality should be [0..3], got ${quality}`) |
| 711 | } |
| 712 | opts.filter = utils.cib_quality_filter(quality) |
| 713 | } |
| 714 | |
| 715 | await this.init() |
| 716 | if (!this.__mathlib) throw new Error('Pica: math library is not initialized') |
| 717 | |
| 718 | const mathOpts: MathResizeAndUnsharpOptions = { |
| 719 | src: opts.src, |
| 720 | width: opts.width, |
| 721 | height: opts.height, |
| 722 | toWidth: opts.toWidth, |
| 723 | toHeight: opts.toHeight, |
| 724 | dest: opts.dest, |
| 725 | scaleX: opts.toWidth / opts.width, |
| 726 | scaleY: opts.toHeight / opts.height, |
| 727 | offsetX: 0, |
| 728 | offsetY: 0, |
| 729 | filter: opts.filter, |
| 730 | unsharpAmount: opts.unsharpAmount, |
| 731 | unsharpRadius: opts.unsharpRadius, |
| 732 | unsharpThreshold: opts.unsharpThreshold |
| 733 | } |
| 734 | |
| 735 | return this.__mathlib.resizeAndUnsharp(mathOpts) |
| 736 | } |
| 737 | |
| 738 | async toBlob (canvas: HTMLCanvasElement | OffscreenCanvas, mimeType?: string, quality?: number): Promise<Blob> { |
| 739 | mimeType = mimeType || 'image/png' |