| Methods |
|---|
new DataTypeConverter()
Class that orchestrates automated data types conversion. Do not instantiate
this class, use OpenSeadragon.converter - a global instance, instead.
Types are defined to closely describe the data type, e.g. "url" is insufficient,
because url can point to many different data types. Another bad example is 'canvas'
as canvas can have different underlying rendering implementations and thus differ
in behavior. The following data types supported by
OpenSeadragon core are:
- "image" - HTMLImageElement, an object
- "context2d" - HtmlRenderingContext2D, a 2D canvas context
- "rasterBlob" - Blob, a binary file-like object carrying image data
- "imageBitmap" - an ImageBitmap object
The system uses these to deliver desired data from TileSource (which implements fetching logics)
through plugins to the renderer with preserving data type compatibility. Typical example is:
TiledImage downloads and creates Image object with type 'image'. It submits
to the system object of data type 'image'. The system runs this object through
possible plugins integrated into the invalidation routine (by default none),
and finishes by conversion for the WebGL renderer, which would most likely be "image"
object, because the conversion in this case is not even necessary, as the drawer publishes
the image type as one of its supported ones.
If some plugin required context2d type, the pipeline would deliver this type and used
it also for WebGL, as texture loading function accepts canvas object as well as image.
- Source:
Methods
convert(tile, data, from, …to) → {OpenSeadragon.Promise.<?>}
Convert data item x of type 'from' to any of the 'to' types, chosen is the cheapest known conversion.
Data is destroyed upon conversion. For different behavior, implement your conversion using the
path rules obtained from getConversionPath().
Note: conversion DOES NOT COPY data if [to] contains type 'from' (e.g., the cheapest conversion is no conversion).
It automatically calls destructor on immediate types, but NOT on the x and the result. You should call these
manually if these should be destroyed.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
tile |
OpenSeadragon.Tile | ||
data |
any | data item to convert | |
from |
string | data item type | |
to |
string |
<repeatable> |
desired type(s) |
- Source:
Returns:
promise resolution with type 'to', or rejection if conversion failed.
- Type
- OpenSeadragon.Promise.<?>
copy(tile, data, type) → {OpenSeadragon.Promise.<?>|undefined}
Copy the data item given.
Parameters:
| Name | Type | Description |
|---|---|---|
tile |
OpenSeadragon.Tile | |
data |
any | data item to convert |
type |
string | data type |
- Source:
Returns:
promise resolution with data passed from constructor
- Type
- OpenSeadragon.Promise.<?> | undefined
destroy(type, data) → {OpenSeadragon.Promise.<any>|undefined}
Destroy the data item given.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | data type |
data |
any |
- Source:
Returns:
promise resolution with data passed from constructor, or undefined
if not such conversion exists
- Type
- OpenSeadragon.Promise.<any> | undefined
existsType(type) → {boolean}
Check whether given type is known to the converter
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | type to test |
- Source:
Returns:
- Type
- boolean
getConversionPath(from, to) → {Array.<ConversionStep>|undefined}
Get possible system type conversions and cache result.
Parameters:
| Name | Type | Description |
|---|---|---|
from |
string | data item type |
to |
string | Array.<string> | array of accepted types |
- Source:
Returns:
array of required conversions (returns empty array
for from===to), or undefined if the system cannot convert between given types.
Each object has 'transform' function that converts between neighbouring types, such
that x = arr[i].transform(x) is valid input for converter arr[i+1].transform(), e.g.
arr[i+1].transform(arr[i].transform( ... )) is a valid conversion procedure.
Note: if a function is returned, it is a callback called once the data is ready.
- Type
- Array.<ConversionStep> | undefined
getConversionPathFinalType(path) → {undefined|string}
Get the final type of the conversion path.
Parameters:
| Name | Type | Description |
|---|---|---|
path |
Array.<ConversionStep> |
- Source:
Returns:
undefined if invalid path
- Type
- undefined | string
getKnownTypes() → {Array.<string>}
Return a list of known conversion types
- Source:
Returns:
- Type
- Array.<string>
learn(from, to, callback, costPoweropt, costMultiplieropt)
Teach the system to convert data type 'from' -> 'to'
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
from |
string | unique ID of the data item 'from' | ||
to |
string | unique ID of the data item 'to' | ||
callback |
OpenSeadragon.TypeConverter | converter that takes two arguments: a tile reference, and a data object of a type 'from'; and converts this data object to type 'to'. It can return also the value wrapped in a Promise (returned in resolve) or it can be async function. | ||
costPower |
Number |
<optional> |
0 | positive cost class of the conversion, smaller or equal than 7. Should reflect the actual cost of the conversion: - if nothing must be done and only reference is retrieved (or a constant operation done), return 0 (default) - if a linear amount of work is necessary, return 1 ... and so on, basically the number in O() complexity power exponent (for simplification) |
costMultiplier |
Number |
<optional> |
1 | multiplier of the cost class, e.g. O(3n^2) would use costPower=2, costMultiplier=3; can be between 1 and 10^5 |
- Source:
learnDestroy(type, callback)
Teach the system to destroy data type 'type'
for example, textures loaded to GPU have to be also manually removed when not needed anymore.
Needs to be defined only when the created object has extra deletion process.
Parameters:
| Name | Type | Description |
|---|---|---|
type |
string | |
callback |
OpenSeadragon.TypeDestructor | destructor, receives the object created, it is basically a type conversion to 'undefined' - thus the type. |
- Source: