@@ -15,9 +15,6 @@ import { availableThreads } from './util/threads.ts';
1515
1616// (worker threads: the processors available, at most 8)
1717const defaultThreads = ( ) : number => Math . max ( 1 , Math . min ( availableThreads ( ) , 8 ) ) ;
18- const checkThreads = ( threads : number ) : void => {
19- if ( ! Number . isInteger ( threads ) || threads < 1 ) throw new RangeError ( `threads must be a positive integer, not ${ threads } ` ) ;
20- } ;
2118import * as jxl from './codecs/jxl.ts' ;
2219import type { ToneMapping } from './codecs/hdr.ts' ;
2320import * as quantize from './codecs/quantize.ts' ;
@@ -32,7 +29,7 @@ import { encode as utf8 } from './util/utf8.ts';
3229import { resample , BOX , TRIANGLE , CUBIC , type Region } from './util/resample.ts' ;
3330import { gaussianBlur , boxBlurRGBA , premultiply , unpremultiply } from './util/blur.ts' ;
3431import { Colors , wrapHue , hue2rgb } from './colors.ts' ;
35- import { isOptions , checkOptions , finite , oneOf , color as checkColor , quality as checkQuality , effort as checkEffort , compressionLevel } from './util/options.ts' ;
32+ import { isOptions , checkOptions , finite , oneOf , pixelLimit , checkThreads , color as checkColor , quality as checkQuality , effort as checkEffort , compressionLevel } from './util/options.ts' ;
3633import { MAX_PIXELS , LimitError , decoding } from './util/limits.ts' ;
3734import { GainMap } from './gainmap.ts' ;
3835import * as gain from './util/gain.ts' ;
@@ -2629,7 +2626,7 @@ export class Image {
26292626 checkOptions ( options , 'Image.decode(data, { maxPixels: 1e8 })' ) ;
26302627 const { applyOrientation = true , applyColorProfile = true , maxPixels = MAX_PIXELS , toneMapping = 'reinhard' , threads = defaultThreads ( ) , gainMap = true } = options ;
26312628 checkThreads ( threads ) ;
2632- if ( ! ( Number ( maxPixels ) > 0 ) ) throw new RangeError ( `maxPixels must be a positive number, not ${ maxPixels } ` ) ;
2629+ pixelLimit ( maxPixels ) ;
26332630 oneOf ( toneMapping , TONE_MAPPINGS , 'toneMapping' ) ;
26342631 const data = view ( input ) ;
26352632 const dataView = new DataView ( data . buffer , data . byteOffset , data . byteLength ) ;
@@ -2763,10 +2760,10 @@ export class Image {
27632760 static async renderSVG ( svg : string | BinaryData , options : RenderSVGOptions = { } ) : Promise < Image > {
27642761 checkOptions ( options , 'renderSVG(svg, { width: 512 })' ) ;
27652762 const { width : givenWidth , height : givenHeight , scale, maxPixels = MAX_PIXELS , font : fonts = [ ] , images : givenImages = { } } = options ;
2766- if ( ! ( Number ( maxPixels ) > 0 ) ) throw new RangeError ( `maxPixels must be a positive number, not ${ maxPixels } ` ) ;
2763+ pixelLimit ( maxPixels ) ;
27672764 const { maxLayerPixels = 4 * Number ( maxPixels ) , maxImagePixels = Number ( maxPixels ) } = options ;
2768- if ( ! ( Number ( maxLayerPixels ) > 0 ) ) throw new RangeError ( `maxLayerPixels must be a positive number, not ${ maxLayerPixels } ` ) ;
2769- if ( ! ( Number ( maxImagePixels ) > 0 ) ) throw new RangeError ( `maxImagePixels must be a positive number, not ${ maxImagePixels } ` ) ;
2765+ pixelLimit ( maxLayerPixels , ' maxLayerPixels' ) ;
2766+ pixelLimit ( maxImagePixels , ' maxImagePixels' ) ;
27702767 const sizes = [ givenWidth , givenHeight , scale ] . filter ( value => value !== undefined ) . length ;
27712768 if ( sizes > 1 ) throw new TypeError ( 'renderSVG() takes one of width, height and scale' ) ;
27722769 const mode = givenWidth !== undefined ? 'width' : givenHeight !== undefined ? 'height' : 'scale' ;
@@ -2841,7 +2838,7 @@ export class Image {
28412838 if ( typeof text !== 'string' || ! isOptions ( options ) ) throw new TypeError ( 'renderText() takes the text and an options object, like renderText(\'Hello\', { font, size: 32 })' ) ;
28422839 if ( options . font === undefined ) throw new TypeError ( 'renderText(text, options) needs the font in the options' ) ;
28432840 const { font, color = 0xffffffff , strokeWidth = 0 , strokeColor = 0x000000ff , hinting = true , features = { } , variations = { } , maxPixels = MAX_PIXELS } = options ;
2844- if ( ! ( Number ( maxPixels ) > 0 ) ) throw new RangeError ( `maxPixels must be a positive number, not ${ maxPixels } ` ) ;
2841+ pixelLimit ( maxPixels ) ;
28452842 const { width : boxWidth , height : boxHeight , wrapStyle, horizontalAlign, verticalAlign } = options ;
28462843 const layout = textLayout ( { width : boxWidth , height : boxHeight , wrapStyle, horizontalAlign, verticalAlign } ) ;
28472844 const axes = textRenderer . axisValues ( variations ) ;
0 commit comments