dwv. utils

Classes

ListenerHandler
ThreadPool
WorkerTask
WorkerThread

Namespaces

logger

Members

(static) d65

CIE Standard Illuminant D65, standard 2° observer.

Methods

(static) MultiProgressHandler(callback)

Multiple progresses handler. Stores a multi dimensional list of progresses to allow to calculate a global progress.

Parameters:
NameTypeDescription
callbackfunction

The function to pass the global progress to.

(static) arrayEquals(arr0, arr1) → {boolean}

Check for array equality.

Parameters:
NameTypeDescription
arr0Array

First array.

arr1*

Second array.

Returns:

True if both array are defined and contain same values.

Type: 
boolean

(static) arraySortEquals(arr0, arr1) → {boolean}

Check for array equality after sorting.

Parameters:
NameTypeDescription
arr0Array

First array.

arr1*

Second array.

Returns:

True if both array are defined and contain same values.

Type: 
boolean

(static) buildMultipart(parts, boundary) → {Uint8Array}

Build a multipart message. See: https://en.wikipedia.org/wiki/MIME#Multipart_messages See: https://hg.orthanc-server.com/orthanc-dicomweb/file/tip/Resources/Samples/JavaScript/stow-rs.js

Parameters:
NameTypeDescription
partsArray

The message parts as an array of object containing content headers and messages as the data property (as returned by parse).

boundarystring

The message boundary.

Returns:

The full multipart message.

Type: 
Uint8Array

(static) capitaliseFirstLetter(string) → {string}

Capitalise the first letter of a string.

Parameters:
NameTypeDescription
stringstring

The string to capitalise the first letter.

Returns:

The new string.

Type: 
string

(static) cielabToCiexyz(triplet) → {object}

Convert CIE LAB to CIE XYZ (standard illuminant D65, 2degree 1931).

Parameters:
NameTypeDescription
tripletobject

CIE LAB triplet as {l,a,b}.

Returns:

CIE XYZ triplet as {x,y,z}.

Type: 
object

(static) cielabToSrgb(triplet) → {object}

Convert CIE LAB to sRGB (standard illuminant D65).

Parameters:
NameTypeDescription
tripletobject

CIE LAB triplet as {l,a,b}.

Returns:

sRGB triplet as {r,g,b}.

Type: 
object

(static) ciexyzToCielab(triplet) → {object}

Convert CIE XYZ to CIE LAB (standard illuminant D65, 2degree 1931).

Parameters:
NameTypeDescription
tripletobject

CIE XYZ triplet as {x,y,z}.

Returns:

CIE LAB triplet as {l,a,b}.

Type: 
object

(static) ciexyzToSrgb(triplet) → {object}

Convert CIE XYZ to sRGB.

Parameters:
NameTypeDescription
tripletobject

CIE XYZ triplet as {x,y,z}.

Returns:

sRGB triplet as {r,g,b}.

Type: 
object

(static) colourNameToHex(name) → {string}

Get the hex code of a string colour for a colour used in pre dwv v0.17.

Parameters:
NameTypeDescription
namestring

The name of a colour.

Returns:

The hex representing the colour.

Type: 
string

(static) decodeKeyValueUri(uri, replaceMode) → {Array}

Decode a Key/Value pair URI. If a key is repeated, the result be an array of base + each key.

Parameters:
NameTypeDescription
uristring

The URI to decode.

replaceModestring

The key replace more. replaceMode can be:

  • key (default): keep the key
  • other than key: do not use the key 'file' is a special case where the '?' of the query is not kept.
Returns:

The list of input file urls.

Type: 
Array

(static) decodeManifest(manifest, nslices) → {Array}

Decode an XML manifest.

Parameters:
NameTypeDescription
manifestobject

The manifest to decode.

nslicesnumber

The number of slices to load.

Returns:

The decoded manifest.

Type: 
Array

(static) decodeQuery(query, callback, options)

Generic URI query decoder. Supports manifest: [dwv root]?input=encodeURIComponent('[manifest file]')&type=manifest or encoded URI with base and key value/pairs: [dwv root]?input=encodeURIComponent([root]?key0=value0&key1=value1)

Parameters:
NameTypeDescription
querystring

The query part to the input URI.

callbackfunction

The function to call with the decoded file urls.

optionsobject

Optional url request options.

(static) endsWith(str, search) → {boolean}

Check if a string ends with the input element.

Parameters:
NameTypeDescription
strstring

The input string.

searchstring

The searched ending.

Returns:

True if the input string ends with the searched string.

Type: 
boolean

(static) findInArraySubset(arr, callbackFn, start, end) → {number|undefined}

Array find in a subset of the input array. Equivalent to: arr.slice(start, end).find(callbackFn)

Parameters:
NameTypeDescription
arrArray

The input array to search.

callbackFnfunction

The find function.

startnumber

The array start index.

endnumber

The array end index.

Returns:

The index where the element was found.

Type: 
number | undefined

(static) getBrightness(rgbTriplet) → {number}

Get the brightness of a RGB colour: calculates the luma (Y) of the YIQ colour space.

Parameters:
NameTypeDescription
rgbTripletobject

RGB triplet.

Returns:

The brightness ([0,1]).

Type: 
number

(static) getFileExtension(filePath) → {string}

Get a file extension: anything after the last dot. File name starting with a dot are discarded. Extensions are expected to contain at least one letter.

Parameters:
NameTypeDescription
filePathstring

The file path containing the file name.

Returns:

The lower case file extension or null for none.

Type: 
string

(static) getFindArrayInArrayCallback(arr1) → {function}

Get a find in array callback.

Parameters:
NameTypeDescription
arr1Array

The array to find.

Returns:

The find callback function.

Type: 
function

(static) getFlags(inputStr) → {Array}

Get flags from an input string. Flags are words surrounded with curly braces.

Parameters:
NameTypeDescription
inputStrstring

The input string.

Returns:

An array of found flags.

Type: 
Array

(static) getRootPath(path) → {string}

Get the root of an input path. Splits using / as separator.

Parameters:
NameTypeDescription
pathstring

The input path

Returns:

The input path without its last part.

Type: 
string

(static) getShadowColour(hexColour) → {string}

Get the shadow colour of an input colour.

Parameters:
NameTypeDescription
hexColourstring

The colour (as '#ab01ef').

Returns:

The shadow colour (white or black).

Type: 
string

(static) getUriQuery(uri) → {object}

Get the query part, split into an array, of an input URI. The URI scheme is: 'base?query#fragment'

Parameters:
NameTypeDescription
uristring

The input URI.

Returns:

The query part, split into an array, of the input URI.

Type: 
object

(static) getUrlFromUri(uri) → {URL}

Get an object URL from a string uri.

Parameters:
NameTypeDescription
uristring

A string representing the url.

Returns:

A URL object (full or simple depending upon platform). WANRING: returns an official URL or a simple URL depending on platform, see https://caniuse.com/#feat=url

Type: 
URL

(static) getUrlFromUriFull(uri) → {URL}

Get an full object URL from a string uri.

Parameters:
NameTypeDescription
uristring

A string representing the url.

Returns:

A URL object. WARNING: platform support dependent, see https://caniuse.com/#feat=url

Type: 
URL

(static) getUrlFromUriSimple(uri) → {URL}

Get an simple object URL from a string uri.

Parameters:
NameTypeDescription
uristring

A string representing the url.

Returns:

A simple URL object that exposes 'pathname' and 'searchParams.get()' WARNING: limited functionality, simple nmock of the URL object.

Type: 
URL

(static) hexToRgb(hexStr) → {object}

Convert a hex color into RGB.

Parameters:
NameTypeDescription
hexStrstring

The hex color as '#ab01ef'.

Returns:

The RGB values as {r,g,b}.

Type: 
object

(static) isArray(unknown) → {boolean}

Check if the input is an array.

Parameters:
NameTypeDescription
unknown*

The input to check.

Returns:

True if the input is an array. ref: https://github.com/jashkenas/underscore/blob/1.9.1/underscore.js#L1313-L1317

Type: 
boolean

(static) isDarkColour(hexColour) → {boolean}

Check if a colour given in hexadecimal format is dark.

Parameters:
NameTypeDescription
hexColourstring

The colour (as '#ab01ef').

Returns:

True if the colour is dark (brightness < 0.5).

Type: 
boolean

(static) isEqualRgb(c1, c2) → {boolean}

Check if two rgb objects are equal.

Parameters:
NameTypeDescription
c1object

The first colour.

c2object

The second colour.

Returns:

True if both colour are equal.

Type: 
boolean

(static) isObject(unknown) → {boolean}

Check if the input is a generic object, including arrays.

Parameters:
NameTypeDescription
unknown*

The input to check.

Returns:

True if the input is an object. ref: https://github.com/jashkenas/underscore/blob/1.9.1/underscore.js#L1319-L1323

Type: 
boolean

(static) labToUintLab(triplet) → {object}

CIE LAB value (L: [0, 100], a: [-128, 127], b: [-128, 127]) to unsigned int CIE LAB ([0, 65535]).

Parameters:
NameTypeDescription
tripletobject

CIE XYZ triplet as {x,y,z} with CIE LAB range.

Returns:

CIE LAB triplet as {l,a,b} with unsigned range.

Type: 
object

(static) loadFromQuery(query, app, options)

Load from an input query

Parameters:
NameTypeDescription
queryobject

A query derived from an uri.

appobject

The associated app that handles the load.

optionsobject

Optional url request options.

(static) loadFromUri(uri, app, options)

Load from an input uri

Parameters:
NameTypeDescription
uristring

The input uri, for example: 'window.location.href'.

appdwv.App

The associated app that handles the load.

optionsobject

Optional url request options.

(static) mergeObjects(obj1, obj2, idKey, valueKey) → {object}

Merge two similar objects. Objects need to be in the form of: { idKey: {valueKey: 0}, key0: {valueKey: "abc"}, key1: {valueKey: 33} } Merged objects will be in the form of: { idKey: {valueKey: [0,1,2], merged: true}, key0: {valueKey: { 0: {valueKey: "abc"}, 1: {valueKey: "def"}, 2: {valueKey: "ghi"} }}, key1: {valueKey: { 0: {valueKey: 33}, 1: {valueKey: 44}, 2: {valueKey: 55} }} }

Parameters:
NameTypeDescription
obj1object

The first object, can be the result of a previous merge.

obj2object

The second object.

idKeystring

The key to use as index for duplicate values.

valueKeystring

The key to use to access object values.

Returns:

The merged object.

Type: 
object

(static) objectToArray(obj) → {Array}

Dump an object to an array.

Parameters:
NameTypeDescription
objobject

The input object as: {key0: {}, key1: {}}

Returns:

The corresponding array: [{name: key0, {}}, {name: key1, {}}]

Type: 
Array

(static) parseMultipart(arr) → {Array}

Extract each element of a multipart ArrayBuffer. https://en.wikipedia.org/wiki/MIME#Multipart_messages

Parameters:
NameTypeDescription
arrArrayBuffer

The multipart array.

Returns:

The multipart parts as an array of object as {'Content-Type', ..., data} (depending on header tags)

Type: 
Array

(static) precisionRound(number, precision) → {number}

Round a float number to a given precision. Inspired from https://stackoverflow.com/a/49729715/3639892. Can be a solution to not have trailing zero as when using toFixed or toPrecision. '+number.toFixed(precision)' does not pass all the tests...

Parameters:
NameTypeDescription
numbernumber

The number to round.

precisionnumber

The rounding precision.

Returns:

The rounded number.

Type: 
number

(static) replaceFlags(inputStr, values) → {string}

Replace flags in a input string. Flags are keywords surrounded with curly braces.

Parameters:
NameTypeDescription
inputStrstring

The input string.

valuesobject

A object of {value, unit}.

Returns:

The result string.

Type: 
string
Example
var values = {"length": { "value": 33, "unit": "cm" } };
   var str = "The length is: {length}.";
   var res = dwv.utils.replaceFlags(str, values); // "The length is: 33 cm."

(static) replaceFlags2(inputStr, values) → {string}

Replace flags in a input string. Flags are keywords surrounded with curly braces.

Parameters:
NameTypeDescription
inputStrstring

The input string.

valuesArray

An array of strings.

Returns:

The result string.

Type: 
string
Example
var values = ["a", "b"];
   var str = "The length is: {v0}. The size is: {v1}";
   var res = dwv.utils.replaceFlags2(str, values);
   // "The length is: a. The size is: b"

(static) rgbToHex(rgb) → {string}

Convert RGB to its hex equivalent.

Parameters:
NameTypeDescription
rgbobject

The RGB object as {r,g,b}.

Returns:

A string representing the hex color as '#ab01ef'.

Type: 
string

(static) splitKeyValueString(inputStr) → {object}

Split key/value string: key0=val00&key0=val01&key1=val10 returns { key0 : [val00, val01], key1 : val1 }

Parameters:
NameTypeDescription
inputStrstring

The string to split.

Returns:

The split string.

Type: 
object

(static) splitUri(uri) → {object}

Split an input URI: 'root?key0=val00&key0=val01&key1=val10' returns { base : root, query : [ key0 : [val00, val01], key1 : val1 ] } Returns an empty object if the input string is not correct (null, empty...) or if it is not a query string (no question mark).

Parameters:
NameTypeDescription
uristring

The string to split.

Returns:

The split string.

Type: 
object

(static) srgbToCielab(triplet) → {object}

Convert sRGB to CIE LAB (standard illuminant D65).

Parameters:
NameTypeDescription
tripletobject

sRGB triplet as {r,g,b}.

Returns:

CIE LAB triplet as {l,a,b}.

Type: 
object

(static) srgbToCiexyz(triplet) → {object}

Convert sRGB to CIE XYZ.

Parameters:
NameTypeDescription
tripletobject

sRGB triplet as {r,g,b}.

Returns:

CIE XYZ triplet as {x,y,z}.

Type: 
object

(static) startsWith(str, search, rawPos) → {boolean}

Check if a string starts with the input element.

Parameters:
NameTypeDescription
strstring

The input string.

searchstring

The searched start.

rawPosnumber

The position in this string at which to begin searching for searchString. Defaults to 0.

Returns:

True if the input string starts with the searched string.

Type: 
boolean

(static) stringToUint8Array(str) → {Uint8Array}

Convert a string to a Uint8Array.

Parameters:
NameTypeDescription
strstring

The string to convert.

Returns:

The Uint8Array.

Type: 
Uint8Array

(static) uint8ArrayToString(arr) → {string}

Convert a Uint8Array to a string.

Parameters:
NameTypeDescription
arrUint8Array

The array to convert.

Returns:

The array as string.

Type: 
string

(static) uintLabToLab(triplet) → {object}

Unsigned int CIE LAB value ([0, 65535]) to CIE LAB value (L: [0, 100], a: [-128, 127], b: [-128, 127]).

Parameters:
NameTypeDescription
tripletobject

CIE LAB triplet as {l,a,b} with unsigned range.

Returns:

CIE LAB triplet as {l,a,b} with CIE LAB range.

Type: 
object

(static) ybrToRgb(y, cb, cr) → {object}

Convert YBR to RGB.

Parameters:
NameTypeDescription
ynumber

The Y component.

cbnumber

The Cb component.

crnumber

The Cr component.

Returns:

RGB equivalent as {r,g,b}.

Type: 
object