In the browser
All conversion happens on the client, so files are never uploaded.
From URLs
A non-2xx response rejects the promise with an error that includes the status code.
The PDS archives do not always send CORS headers. If a direct fetch fails, download the files first, serve them from your own origin, or let users pick them with a file input.
From file inputs
Use two inputs, one for the label and one for the image data. This is what the playground does.
loadPDS3ImageByFile(img, lbl?) takes the image first because the label is optional: a PDS3 file with an attached label is loaded with loadPDS3ImageByFile(img). loadPDS4ImageByFile(xml, img) takes the label first, like loadPDS4ImageByUrl.
From a directory (File System Access API)
In browsers that support showDirectoryPicker, you can let the user pick a folder and detect the product automatically:
The directory is searched (not recursively) for:
- an
.IMGfile with a.LBLfile of the same name → PDS3, otherwise - an
.xmllabel whosefile_nameexists in the directory → PDS4.
loadPDSImageArrayBufferFromDirectory does the same and returns the decoded Float32Array pixel buffer instead of the image object.
Show a preview
Browsers can display 16-bit grayscale PNGs directly:
Save the result
With the File System Access API you can ask the user where to save:
Working with raw pixels
Every image implements the PDSImage interface, so you can process calibrated values yourself. For example, you can draw them on a canvas with your own contrast stretch: